Skip to content

Commit 3e0c29b

Browse files
committed
[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 <[email protected]>
1 parent aaa4688 commit 3e0c29b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

gdb/dwarf2/cooked-index.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,15 @@ cooked_index_entry::matches (domain_search_flags kind) const
215215
/* See cooked-index.h. */
216216

217217
const char *
218-
cooked_index_entry::full_name (struct obstack *storage, bool for_main) const
218+
cooked_index_entry::full_name (struct obstack *storage, bool for_main,
219+
const char *default_sep) const
219220
{
220221
const char *local_name = for_main ? name : canonical;
221222

222223
if ((flags & IS_LINKAGE) != 0 || get_parent () == nullptr)
223224
return local_name;
224225

225-
const char *sep = nullptr;
226+
const char *sep = default_sep;
226227
switch (lang)
227228
{
228229
case language_cplus:
@@ -237,7 +238,9 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main) const
237238
break;
238239

239240
default:
240-
return local_name;
241+
if (sep == nullptr)
242+
return local_name;
243+
break;
241244
}
242245

243246
get_parent ()->write_scope (storage, sep, for_main);
@@ -799,7 +802,8 @@ cooked_index::dump (gdbarch *arch)
799802
gdb_printf (" [%zu] ((cooked_index_entry *) %p)\n", i++, entry);
800803
gdb_printf (" name: %s\n", entry->name);
801804
gdb_printf (" canonical: %s\n", entry->canonical);
802-
gdb_printf (" qualified: %s\n", entry->full_name (&temp_storage, false));
805+
gdb_printf (" qualified: %s\n",
806+
entry->full_name (&temp_storage, false, "::"));
803807
gdb_printf (" DWARF tag: %s\n", dwarf_tag_name (entry->tag));
804808
gdb_printf (" flags: %s\n", to_string (entry->flags).c_str ());
805809
gdb_printf (" DIE offset: %s\n", sect_offset_str (entry->die_offset));

gdb/dwarf2/cooked-index.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,11 @@ struct cooked_index_entry : public allocate_on_obstack<cooked_index_entry>
140140
STORAGE. FOR_MAIN is true if we are computing the name of the
141141
"main" entry -- one marked DW_AT_main_subprogram. This matters
142142
for avoiding name canonicalization and also a related race (if
143-
"main" computation is done during finalization). */
144-
const char *full_name (struct obstack *storage, bool for_main = false) const;
143+
"main" computation is done during finalization). If the language
144+
doesn't prescribe a separator, one can be specified using
145+
DEFAULT_SEP. */
146+
const char *full_name (struct obstack *storage, bool for_main = false,
147+
const char *default_sep = nullptr) const;
145148

146149
/* Comparison modes for the 'compare' function. See the function
147150
for a description. */

0 commit comments

Comments
 (0)