diff options
author | Tom de Vries <tdevries@suse.de> | 2024-10-18 00:15:57 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-10-18 00:15:57 +0200 |
commit | 3e0c29b24a9adfbbce211c81b3748c197661a63f (patch) | |
tree | 28b4d40ff4f5d182a94c0fa336c0613d85a5c41d | |
parent | aaa4688f9dbbfb0ff887a15703a657180924334d (diff) | |
download | binutils-3e0c29b24a9adfbbce211c81b3748c197661a63f.zip binutils-3e0c29b24a9adfbbce211c81b3748c197661a63f.tar.gz binutils-3e0c29b24a9adfbbce211c81b3748c197661a63f.tar.bz2 |
[gdb/symtab] Fix qualified name for cooked index dump
While looking at the cooked index entry for local variable l4 of function test
in test-case gdb.fortran/logical.exp:
...
$ gdb -q -batch outputs/gdb.fortran/logical/logical \
-ex "maint print objfiles"
...
[9] ((cooked_index_entry *) 0x7fc6e0003010)
name: l4
canonical: l4
qualified: l4
DWARF tag: DW_TAG_variable
flags: 0x2 [IS_STATIC]
DIE offset: 0x17c
parent: ((cooked_index_entry *) 0x7fc6e0002f20) [test]
...
I noticed that while the entry does have a parent, that's not reflected in the
qualified name.
This makes it harder to write test-cases that check the parent of a cooked
index entry.
This is due to the implementation of full_name, which skips printing
parents if the language does not specify an appropriate separator.
Fix this by using "::" as default separator, getting us instead:
...
[9] ((cooked_index_entry *) 0x7f94ec0040c0)
name: l4
canonical: l4
qualified: test::l4
DWARF tag: DW_TAG_variable
flags: 0x2 [IS_STATIC]
DIE offset: 0x17c
parent: ((cooked_index_entry *) 0x7f94ec003fd0) [test]
...
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r-- | gdb/dwarf2/cooked-index.c | 12 | ||||
-rw-r--r-- | gdb/dwarf2/cooked-index.h | 7 |
2 files changed, 13 insertions, 6 deletions
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 4073c92..46b1c2d 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -215,14 +215,15 @@ cooked_index_entry::matches (domain_search_flags kind) const /* See cooked-index.h. */ const char * -cooked_index_entry::full_name (struct obstack *storage, bool for_main) const +cooked_index_entry::full_name (struct obstack *storage, bool for_main, + const char *default_sep) const { const char *local_name = for_main ? name : canonical; if ((flags & IS_LINKAGE) != 0 || get_parent () == nullptr) return local_name; - const char *sep = nullptr; + const char *sep = default_sep; switch (lang) { case language_cplus: @@ -237,7 +238,9 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main) const break; default: - return local_name; + if (sep == nullptr) + return local_name; + break; } get_parent ()->write_scope (storage, sep, for_main); @@ -799,7 +802,8 @@ cooked_index::dump (gdbarch *arch) gdb_printf (" [%zu] ((cooked_index_entry *) %p)\n", i++, entry); gdb_printf (" name: %s\n", entry->name); gdb_printf (" canonical: %s\n", entry->canonical); - gdb_printf (" qualified: %s\n", entry->full_name (&temp_storage, false)); + gdb_printf (" qualified: %s\n", + entry->full_name (&temp_storage, false, "::")); gdb_printf (" DWARF tag: %s\n", dwarf_tag_name (entry->tag)); gdb_printf (" flags: %s\n", to_string (entry->flags).c_str ()); gdb_printf (" DIE offset: %s\n", sect_offset_str (entry->die_offset)); diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 0873e7d..2807f5c 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -140,8 +140,11 @@ struct cooked_index_entry : public allocate_on_obstack<cooked_index_entry> STORAGE. FOR_MAIN is true if we are computing the name of the "main" entry -- one marked DW_AT_main_subprogram. This matters for avoiding name canonicalization and also a related race (if - "main" computation is done during finalization). */ - const char *full_name (struct obstack *storage, bool for_main = false) const; + "main" computation is done during finalization). If the language + doesn't prescribe a separator, one can be specified using + DEFAULT_SEP. */ + const char *full_name (struct obstack *storage, bool for_main = false, + const char *default_sep = nullptr) const; /* Comparison modes for the 'compare' function. See the function for a description. */ |