[RFC][gdb/symtab] Add DW_IDX_GNU_main_subprogram

Tom de Vries tdevries@suse.de
Tue Mar 2 06:49:53 GMT 2021


On 3/2/21 2:44 AM, Tom Tromey wrote:
> Tom> Fix this by adding a GNU extension DW_IDX_GNU_main_subprogram to the name
> Tom> index attributes, encoded using a number in the DW_IDX_lo_user-DW_IDX_hi_user
> Tom> range.
> 
> I had a hilarious idea for this tonight, which is to stuff the main name
> into the augmentation string.  Right now the augmentation string is just
> "GDB", but we could do something like "GDB:name_of_main"; then extract
> that when reading.

That's a fun idea indeed.

I wonder though about backward compatibility.

We have:
...
/* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension.  */
static const gdb_byte dwarf5_augmentation[] = { 'G', 'D', 'B', 0 };

...

  /* augmentation_string_size - The size in bytes of the augmentation

     string.  This value is rounded up to a multiple of 4.  */
  uint32_t augmentation_string_size = read_4_bytes (abfd, addr);
  addr += 4;
  map.augmentation_is_gdb
    = ((augmentation_string_size
        == sizeof (dwarf5_augmentation))
       && memcmp (addr, dwarf5_augmentation,
                  sizeof (dwarf5_augmentation)) == 0);
...

So as soon as we use this idea, the augmentation_string_size will be
bigger, and the index will no longer be recognized by older gdb as being
a gdb index, so DW_IDX_GNU_internal/external will be ignored. [ There's
also a use in create_cus_from_debug_names_list, but that doesn't look
like any functionality will be broken. ]

One might say though that this is an actual gdb bug.  The dwarf standard
says that the "string _begins_ with a 4-character vendor ID".  So the
code should not check for augmentation_string_size == sizeof
(dwarf5_augmentation).

Anyway, to support any older reader that does the right thing, we'd need
to use "GDB\0name_of_main" or some such.

For future extensibility, we might consider encoding the type of data
using a char, like so "GDB\0M:name_of_main".

Thanks,
- Tom


More information about the Gdb-patches mailing list