<commit_before>
dwarfexport
===========

`dwarfexport` is an IDA Pro plugin that allows the user to export `dwarf` debug
information. This can then be imported in to gdb and other tools, allowing
you to debug using info you have recovered in IDA even when you cannot connect
the IDA debugger.

Usage
-----

Pre-compiled copies of `dwarfexport` are available in the `bin` folder of this
project. Just add these files to your IDA `plugins` folder (plx and plx64 for linux,
plw and p64 for windows) and you will have a new option
"Edit->Plugins->Export Dwarf Debug Info". Click this and select a folder for the
output.

The plugin will generate two files in the output directory. One will be a `.c` file
with the decompiled functions from the Hexrays decompiler. The other is a `.dbg`
file that contains the debug information. *Note that because the plugin performs
decompilation on every function in the binary, it can take a while to run.*

Move these to the device you want to debug on and load gdb (e.x, `gdb a.out`).
You will have full debug information, like normal gdb with source (shown below
using TUI mode):

![debugging in gdb](/resources/screenshot.png)

*Note: You may need to run `list` to get the source file loaded.*

Options
-------

The following options are available from the plugin GUI

`Use Decompiler`: On architectures where the decompiler is available, opt out of
using it.

`Attach Debug Info`: When checked, a `.dbg` file is created with the debug information.
However, this will only work if the target is an ELF file. When the target is not an ELF
file, uncheck this option to create a group of binary files (one for reach ELF section that
would have been created).

Building On Linux
-----------------

`dwarfexport` depends on the IDA SDK as well as a `libdwarf`. Once you have these
available (a statically compiled copy of `libdwarf` is provided), you can set the
environment variables IDASDK\_PATH and IDA\_PATH to the SDK path and your IDA
folder location respectively. Then build the plugin using `make`.

Building On Windows
-------------------

No instructions are currently provided. I'm using a series of hacks that I will
clean up and document at some point.

License
-------<commit_msg>Add docs for adding new architectures<commit_after>
dwarfexport
===========

`dwarfexport` is an IDA Pro plugin that allows the user to export `dwarf` debug
information. This can then be imported in to gdb and other tools, allowing
you to debug using info you have recovered in IDA even when you cannot connect
the IDA debugger.

Usage
-----

Pre-compiled copies of `dwarfexport` are available in the `bin` folder of this
project. Just add these files to your IDA `plugins` folder (plx and plx64 for linux,
plw and p64 for windows) and you will have a new option
"Edit->Plugins->Export Dwarf Debug Info". Click this and select a folder for the
output.

The plugin will generate two files in the output directory. One will be a `.c` file
with the decompiled functions from the Hexrays decompiler. The other is a `.dbg`
file that contains the debug information. *Note that because the plugin performs
decompilation on every function in the binary, it can take a while to run.*

Move these to the device you want to debug on and load gdb (e.x, `gdb a.out`).
You will have full debug information, like normal gdb with source (shown below
using TUI mode):

![debugging in gdb](/resources/screenshot.png)

*Note: You may need to run `list` to get the source file loaded.*

Options
-------

The following options are available from the plugin GUI

`Use Decompiler`: On architectures where the decompiler is available, opt out of
using it.

`Attach Debug Info`: When checked, a `.dbg` file is created with the debug information.
However, this will only work if the target is an ELF file. When the target is not an ELF
file, uncheck this option to create a group of binary files (one for reach ELF section that
would have been created).

Building On Linux
-----------------

`dwarfexport` depends on the IDA SDK as well as a `libdwarf`. Once you have these
available (a statically compiled copy of `libdwarf` is provided), you can set the
environment variables IDASDK\_PATH and IDA\_PATH to the SDK path and your IDA
folder location respectively. Then build the plugin using `make`.

Building On Windows
-------------------

No instructions are currently provided. I'm using a series of hacks that I will
clean up and document at some point.

Adding Support for Other Architectures
--------------------------------------

There are three functions that need to be modified to add support for a new
architectures. They are all located in `platform.cpp`:

`translate_register_num`: Translates from IDA register numbers to DWARF numbers.
The IDA register numbering can be found by running `idaapi.ph_get_regnames()`.
The index of a register in the returned list is its 'IDA register number'. A variety
of resources exist to find the DWARF mapping for a given architecture. For example,
[wine](https://source.winehq.org/source/dlls/dbghelp/cpu_x86_64.c) has the numbers
for some architectures (see `x86_64_map_dwarf_register`).

`disassembler_lvar_reg_and_offset`: This function should set the `reg` and `offset`
parameters to a dwarf register and the offset from that register that should be
used to read from a stack variable 'member'. So `reg` will typically be a register
containing a pointer to the top or bottom of the stack (so `DW_OP_breg5` is register 5
which is EBP on x86), and the offset will then be the offset from the bottom or top
of the stack.

`decompiler_lvar_reg_and_offset`: On architectures supporting the decompiler, this
function should be modified to perform the same work as the above function, but with
a `lvar_t` from the Hexrays decompiler. Note that it may be acceptable to reuse the
disassembler logic.

License
-------
{'fraction_non_alphanumeric': 0.0764244285226885, 'fraction_numerical': 0.0034118048447628795, 'mean_word_length': 3.8696013289036544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1130800', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1551, 'n_words': 922}