gdb/dwarf: dump cooked index contents in cooked_index_functions::dump
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 30 Jan 2023 16:03:37 +0000 (11:03 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 30 Jan 2023 20:04:44 +0000 (15:04 -0500)
commit7d82b08e9e0a7a22943b843972cd1b8ae1328884
treeea4adf1e7c05ee4d87f4eca46aa4c48c0b9fec73
parent8c4f70ffe7980fe8654660d84592807da2e6f8bc
gdb/dwarf: dump cooked index contents in cooked_index_functions::dump

As I am investigating a crash I see with the cooked index, I thought it
would be useful to have a way to dump the index contents.  For those not
too familiar with it (that includes me), it can help get a feel of what
it contains and how it is structured.

The cooked_index_functions::dump function is called as part of the
"maintenance print objfiles" command.  I tried to make the output
well structured and indented to help readability, as this prints a lot
of text.

The dump function first dumps all cooked index entries, like this:

    [25] ((cooked_index_entry *) 0x621000121220)
    name:       __ioinit
    canonical:  __ioinit
    DWARF tag:  DW_TAG_variable
    flags:      0x2 [IS_STATIC]
    DIE offset: 0x21a4
    parent:     ((cooked_index_entry *) 0x6210000f9610) [std]

Then the information about the main symbol:

    main: ((cooked_index_entry *) 0x621000123b40) [main]

And finally the address map contents:

    [1] ((addrmap *) 0x6210000f7910)

      [0x0] ((dwarf2_per_cu_data *) 0)
      [0x118a] ((dwarf2_per_cu_data *) 0x60c000007f00)
      [0x1cc7] ((dwarf2_per_cu_data *) 0)
      [0x1cc8] ((dwarf2_per_cu_data *) 0x60c000007f00)
      [0x1cdf] ((dwarf2_per_cu_data *) 0)
      [0x1ce0] ((dwarf2_per_cu_data *) 0x60c000007f00)

The display of address maps above could probably be improved, to show it
more as ranges, but I think this is a reasonable start.

Note that this patch depends on Pedro Alves' patch "enum_flags
to_string" [1].  If my patch is to be merged before Pedro's series, I
will cherry-pick this patch from his series and merge it before mine.

[1] https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-8-pedro@palves.net/

Change-Id: Ida13e479fd4c8d21102ddd732241778bc3b6904a
gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h
gdb/dwarf2/read.c