aboutsummaryrefslogtreecommitdiff
path: root/gdb/contrib/dwarf-to-dwarf-assembler.py
AgeCommit message (Collapse)AuthorFilesLines
2025-10-30gdb/contrib/dwarf-to-dwarf-assembler.py: remove unused importsSimon Marchi1-2/+0
Remove imports reported as unused by flake8. Change-Id: I1a1e5edab6ecd6ee774cb4bd20bf22b8952898aa Approved-By: Tom Tromey <tom@tromey.com>
2025-10-28Emit language and encoding names from dwarf-to-dwarf-assemblerTom Tromey1-4/+15
This changes dwarf-to-dwarf-assembler to emit DW_LANG_* and DW_ATE_* names when decoding the appropriate attributes. This makes the output a little more readable and a little closer to something we'd check in. Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-10-28Update "usage" line in dwarf-to-dwarf-assemblerTom Tromey1-1/+1
This changes the "usage" text in dwarf-to-dwarf-assembler to be a bit more GNU-like. It also fixes the name used in the message. Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-10-28Fix formatting of attributes in dwarf-to-dwarf-assembler outputTom Tromey1-3/+2
This updates dwarf-to-dwarf-assembler.py to reflect the changes made to how attributes are parsed; see commit c44edec047d (Make location expressions be code in DWARF assembler). Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-10-22[gdb/contrib] Handle unknown attribute in dwarf-to-dwarf-assembler.pyTom de Vries1-1/+5
I ran gdb/contrib/dwarf-to-dwarf-assembler.py on a hello world compiled with gcc 15, and ran into: ... Traceback (most recent call last): File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 642, in <module> main(sys.argv) ~~~~^^^^^^^^^^ File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 638, in main generator.generate() ~~~~~~~~~~~~~~~~~~^^ File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 610, in generate self.generate_die(die, indent_count) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 589, in generate_die die_lines = die.format(self.dwarf_parser.offset_to_die, indent_count) File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 279, in format return "\n".join(self.format_lines(offset_die_lookup, indent_count)) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 376, in format_lines inner_lines = super().format_lines(offset_die_lookup, indent_count + 1) File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 251, in format_lines attr_line = attr.format( offset_die_lookup, indent_count=indent_count + 1 ) File "/data/vries/gdb/./src/gdb/contrib/dwarf-to-dwarf-assembler.py", line 199, in format s += self.name + " " ~~~~~~~~~~^~~~~ TypeError: unsupported operand type(s) for +: 'int' and 'str' ... because of trying to print DWARF v6 attributes DW_AT_language_name (0x90) and DW_AT_language_version (0x91). Fix this by printing the number if the name is not known: ... {DW_AT_0x90 3 DW_FORM_data1} {DW_AT_0x91 202311 DW_FORM_data4} ...
2025-10-22[gdb/contrib] Fix errno.EOPNOTSUP in dwarf-to-dwarf-assembler.pyTom de Vries1-1/+1
When running dwarf-to-dwarf-assembler.py without arguments, I run into: ... $ ./gdb/contrib/dwarf-to-dwarf-assembler.py Usage: python ./asm_to_dwarf_assembler.py <path/to/elf/file> Traceback (most recent call last): File "/data/vries/gdb/binutils-gdb.git/./gdb/contrib/dwarf-to-dwarf-assembler.py", line 621, in main filename = argv[1] ~~~~^^^ IndexError: list index out of range During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/data/vries/gdb/binutils-gdb.git/./gdb/contrib/dwarf-to-dwarf-assembler.py", line 642, in <module> main(sys.argv) ~~~~^^^^^^^^^^ File "/data/vries/gdb/binutils-gdb.git/./gdb/contrib/dwarf-to-dwarf-assembler.py", line 625, in main sys.exit(errno.EOPNOTSUP) ^^^^^^^^^^^^^^^ AttributeError: module 'errno' has no attribute 'EOPNOTSUP'. Did you mean: 'EOPNOTSUPP'? ... Fix this by using errno.EOPNOTSUPP.
2025-10-21Create script to convert old tests into Dwarf::assemble calls.William Ferreira1-0/+642
PR testsuite/32261 requests a script that could convert old .S-based tests (that were made before dwarf.exp existed) into the new Dwarf::assemble calls in Tcl. This commit is an initial implementation of such a script. Python was chosen for convenience, and only relies on a single external library. Usage: the script operates not on .S files, but on ELF files with DWARF information. To convert an old test, one must run said test via `make check-gdb TESTS=testname` in their build directory. This will produce, as a side effect, an ELF file the test used as an inferior, at gdb/testsuite/outputs/testname/testname. This ELF file is this script's input. Reliability: not counting the limitations listed below, the script seems functional enough to be worthy of discussion in the mailing list. I have been testing it with different tests that already use Dwarf::assemble, to see if the script can produce a similar call to it. Indeed, in most cases that I've tested (including some more complex ones, marked with an asterisk below) it is able to produce comparable output to the original exp file. Of course, it can't reproduce the complex code *before* the Dwarf::assemble call. Values calculated then are simply inlined. The following .exp files have been tried in this way and their outputs highly resemble the original: - gdb.dwarf2/dynarr-ptr - gdb.dwarf2/void-type - gdb.dwarf2/ada-thick-pointer - gdb.dwarf2/atomic-type - gdb.dwarf2/dw2-entry-points (*) - gdb.dwarf2/main-subprogram The following .exp files work, with caveats addressed in the limitations section below. - gdb.dwarf2/cpp-linkage-name - Works correctly except for one attribute of the form SPECIAL_expr. - gdb.dwarf2/dw2-unusual-field-names - Same as above, with two instances of SPECIAL_expr. - gdb.dwarf2/implptr-optimized-out - Same as above, with two instances of SPECIAL_expr. - gdb.dwarf2/negative-data-member-location - Same as above, with one instance of SPECIAL_expr. The following .exp files FAIL, but that is expected: - gdb.dwarf2/staticvirtual.exp - high_pc and low_pc of subprogram "~S" are hardcoded in the original .exp file, but they get replaced with a get_func_info call. Since the function S::~S is not present in the original, get_func_info will fail. The following .exp files DO NOT WORK with this script: - gdb.dwarf2/cu-no-addrs - `aranges` not supported. - Compile unit high_pc and low_pc hardcoded, prone to user error due to forgetting to replace with variables. - gdb.dwarf2/dw2-inline-stepping - Same as above. - gdb.dwarf2/fission-relative-dwo - `fission` not supported. - gdb.dwarf2/dw2-prologue-end and gdb.dwarf2/dw2-prologue-end-2 - Line tables not supported. Currently the script has the following known limitations: - It does not support line tables. - It does not use $srcfile and other variables in the call to Dwarf::assemble (since it can't know where it is safe to substitute). - It does not support "fission" type DWARFs (in fact I still have no clue what those are). - It does not support cu {label LABEL} {} CUs, mostly because I couldn't find the information using pyelftools. - It sometimes outputs empty CUs at the start and end of the call. This might be a problem with my machine, but I've checked with DWARF dumps and they are indeed in the input ELF files generated by `make check-gdb`. - It does not support attributes with the forms DW_FORM_block* and DW_FORM_exprloc. This is mostly not a concern of the difficulty of the implementation, but of it being an incomplete feature and, thus, more susceptible to users forgetting to correct its mistakes or unfinished values (please see discussion started by Guinevere at comment 23 https://sourceware.org/bugzilla/show_bug.cgi?id=32261#c23). The incompleteness of this feature is easy to demonstrate: any call to gdb_target_symbol, a common tool used in these attributes, needs a symbol name that is erased after compilation. There is no way to guess where that address being referenced in a DW_OP_addr comes from, and it can't be hard coded since it can change depending on the machine compiling it. Please bring up any further shortcomings this script may have with your expectations. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32261 Approved-By: Tom Tromey <tom@tromey.com>