PATCH: Add support for decoding .debug_ranges to readelf
Nick Clifton
nickc@redhat.com
Wed Nov 3 10:43:00 GMT 2004
Hi Guys,
I am applying the attached patch to add the ability to decode the
contents of .debug_ranges sections to readelf. This takes two
forms. The decoding is done automatically for a specific range when
a DW_AT_range attribute is encountered and the entire contents of a
.debug_ranges section can be displayed via the --debug-dump=Ranges
command line switch. (Short form: -wR).
I have included code that should work with 64bit ranges but I have
not test this yet.
In the course of developing this patch I also encountered a couple
of bugs. One was that the dump_sects array was not being correctly
reinitialised for each object file that was dumped. There was code
in main() to reinitialise the array for each object file specified
on the command line, but this did not take into account the
possibility that an archive was being dumped. Since archives can
contain multiple object file it is necessary to reinitialise the
dump_sects array before dumping every single binary
Another bug was the debug_apply_rela_addends() function warning
about relocations against STT_OBJECT type symbols. These can occur
in good code (eg the _clz.o binary in libgcc.a), and so should be
allowed.
I have included fixes for both of these bugs.
I also tidied up the parsing of the --debug-dump switch so that it
uses a table structure rather than a long switch statement. I also
added a streq() and strneq() macro to tidy up string comparison
expressions.
binutils/ChangeLog
2004-11-03 Nick Clifton <nickc@redhat.com>
* readelf.c (do_debug_ranges): New variable.
(usage): Document new switch: -wR or --debug-dump=Ranges.
(parse_args): Handle new switch. Replace switch statement for the
long options with a more compact table structure.
(process_section_headers): Allow the dumping of .debug_ranges
sections if so requested.
(debug_displays): Likewise.
(load_debug_range): New function: Grabs the contents of a
.debug_ranges section.
(free_debug_range): New function: Releases the grabbed
.debug_ranges section.
(decode_64bit_range): New function: Displays a 64-bit range in a
.debug_ranges section.
(decode_range): New function: Displays a 32-bit range in a
.debug_ranges section.
(read_and_display_attr_value): Record the value of DW_AT_low_pc
attributes. Use decode_ranges() to display a DW_AT_ranges
attribute.
(display_debug_info): Use load_debug_range() and
free_debug_range().
(display_64bit_debug_ranges): New function. Displays the contents
of a 64-bit format .debug_ranges section.
(display_debug_ranges): New function: Displays the contents of a
32-bit .debug_ranges section.
(main): Move cmdline_dump_sects and num_cmdline_dump_sects into the
global scope.
(process_object): Initialise the dump_sects array from the
cmdline_dump_sects array before processing each object file.
(streq, strneq): New macros. Use them to replace occurrences of
strcmp() and strncmp().
(debug_information): New structure array to replace
debug_line_pointer_sizes array.
(num_debug_info_entries): New variable to replace
num_debug_line_pointers.
(get_pointer_size_of_comp_unit): New function: Returns the pointer
size of a given compilation unit.
(get_debug_info): New function to replace
get_debug_line_pointer_sizes.
(display_debug_lines): Use the new functions.
(display_debug_loc): Likewise.
(disassemble_section): Change return type to int.
(display_debug_lines): Move local variables to their
innermost scope.
(display_debug_section): Likewise. Also record the return value
of functions called and pass this back to the parent. Also only
warn about undumped sections when the user explicitly requested
their dumping.
(debug_apply_rela_addends): Allow relocations against STT_OBJECT
types as well.
* NEWS: Mention the support for decoding .debug_ranges sections.
* doc/binutils.texi: Document the new command line switch to
readelf.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: readelf.ranges.patch
Type: text/x-patch
Size: 38444 bytes
Desc: Add support for .debug_ranges section to readelf
URL: <https://sourceware.org/pipermail/binutils/attachments/20041103/d76ea486/attachment.bin>
More information about the Binutils
mailing list