From aab26529b304aed62095e47248a6b5e1c7590fdc Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 3 Sep 2024 12:53:07 -0600 Subject: [PATCH] Add "Ada linkage" mode to cooked_index_entry::full_name Unfortunately, due to some details of how the Ada support in gdb currently works, the DWARF reader will still have to synthesize some "full name" entries after the cooked index has been constructed. You can see one particular finding related to this in: https://sourceware.org/bugzilla/show_bug.cgi?id=32142 This patch adds a new flag to cooked_index_entry::full_name to enable the construction of these names. I hope to redo this part of the Ada support eventually, so that this code can be removed and the full-name entries simply not created. --- gdb/dwarf2/cooked-index.c | 20 +++++++++++++++----- gdb/dwarf2/cooked-index.h | 16 +++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index f630d34b928..2ffa831f2b6 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -222,6 +222,7 @@ cooked_index_entry::matches (domain_search_flags kind) const const char * cooked_index_entry::full_name (struct obstack *storage, bool for_main, + bool for_ada_linkage, const char *default_sep) const { const char *local_name = for_main ? name : canonical; @@ -238,9 +239,15 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main, sep = "::"; break; + case language_ada: + if (for_ada_linkage) + { + sep = "__"; + break; + } + [[fallthrough]]; case language_go: case language_d: - case language_ada: sep = "."; break; @@ -250,7 +257,7 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main, break; } - get_parent ()->write_scope (storage, sep, for_main); + get_parent ()->write_scope (storage, sep, for_main, for_ada_linkage); obstack_grow0 (storage, local_name, strlen (local_name)); return (const char *) obstack_finish (storage); } @@ -260,11 +267,14 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main, void cooked_index_entry::write_scope (struct obstack *storage, const char *sep, - bool for_main) const + bool for_main, + bool for_ada_linkage) const { if (get_parent () != nullptr) - get_parent ()->write_scope (storage, sep, for_main); - const char *local_name = for_main ? name : canonical; + get_parent ()->write_scope (storage, sep, for_main, for_ada_linkage); + /* When computing the Ada linkage name, the entry might not have + been canonicalized yet, so use the 'name'. */ + const char *local_name = (for_main || for_ada_linkage) ? name : canonical; obstack_grow (storage, local_name, strlen (local_name)); obstack_grow (storage, sep, strlen (sep)); } diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index c47f84e7cc8..68407c84b9b 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -143,10 +143,15 @@ struct cooked_index_entry : public allocate_on_obstack 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). If the language + "main" computation is done during finalization). If + FOR_ADA_LINKAGE is true, then Ada-language symbols will have + their "linkage-style" name computed. The default is + source-style. 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 *full_name (struct obstack *storage, + bool for_main = false, + bool for_ada_linkage = false, const char *default_sep = nullptr) const; /* Comparison modes for the 'compare' function. See the function @@ -250,10 +255,11 @@ private: /* A helper method for full_name. Emits the full scope of this object, followed by the separator, to STORAGE. If this entry has - a parent, its write_scope method is called first. FOR_MAIN is - true when computing the name of 'main'; see full_name. */ + a parent, its write_scope method is called first. See full_name + for a description of the FOR_MAIN and FOR_ADA_LINKAGE + parameters. */ void write_scope (struct obstack *storage, const char *sep, - bool for_main) const; + bool for_main, bool for_ada_linkage) const; /* The parent entry. This is NULL for top-level entries. Otherwise, it points to the parent entry, such as a namespace or -- 2.39.5