[binutils-gdb] GDB: Bring back the handling of DW_CC_program
Maciej W. Rozycki
macro@sourceware.org
Fri Mar 31 14:33:35 GMT 2023
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5b2007ad26f51b244ce66ec65d13e7f71a7f22bc
commit 5b2007ad26f51b244ce66ec65d13e7f71a7f22bc
Author: Maciej W. Rozycki <macro@embecosm.com>
Date: Fri Mar 31 15:31:40 2023 +0100
GDB: Bring back the handling of DW_CC_program
Fix a functional regression and restore the handling of DW_CC_program
code of DW_AT_calling_convention attribute for determining the name of
the starting function of the program where the DW_AT_main_subprogram
attribute has not been provided, such as with Fortran code compiled with
GCC versions 4.5.4 and below, or where DWARF version 3 or below has been
requested. Without it "main" is considered the starting function. Cf.
GCC PR fortran/43414.
Original code was removed with commit 6209cde4ddb8 ("Delete DWARF
psymtab code"), and then an update to complement commit 81873cc81eff
("[gdb/symtab] Support DW_AT_main_subprogram with -readnow.") has also
been included here.
Diff:
---
gdb/dwarf2/read.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index c910be875a3..b362dfddb0c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9994,6 +9994,22 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
compute_delayed_physnames (origin_cu);
}
+/* Return TRUE if the given DIE is the program's "main". DWARF 4 has
+ defined a dedicated DW_AT_main_subprogram attribute to indicate the
+ starting function of the program, however with older versions the
+ DW_CC_program value of the DW_AT_calling_convention attribute was
+ used instead as the only means available. We handle both variants. */
+
+static bool
+dwarf2_func_is_main_p (struct die_info *die, struct dwarf2_cu *cu)
+{
+ if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
+ return true;
+ struct attribute *attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
+ return (attr != nullptr
+ && attr->constant_value (DW_CC_normal) == DW_CC_program);
+}
+
static void
read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
{
@@ -10084,7 +10100,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
newobj = cu->get_builder ()->push_context (0, lowpc);
newobj->name = new_symbol (die, read_type_die (die, cu), cu, templ_func);
- if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
+ if (dwarf2_func_is_main_p (die, cu))
set_objfile_main_name (objfile, newobj->name->linkage_name (),
cu->lang ());
@@ -16136,11 +16152,21 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
*linkage_name = attr.as_string ();
break;
+ /* DWARF 4 has defined a dedicated DW_AT_main_subprogram
+ attribute to indicate the starting function of the program... */
case DW_AT_main_subprogram:
if (attr.as_boolean ())
*flags |= IS_MAIN;
break;
+ /* ... however with older versions the DW_CC_program value of
+ the DW_AT_calling_convention attribute was used instead as
+ the only means available. We handle both variants then. */
+ case DW_AT_calling_convention:
+ if (attr.constant_value (DW_CC_normal) == DW_CC_program)
+ *flags |= IS_MAIN;
+ break;
+
case DW_AT_declaration:
is_declaration = attr.as_boolean ();
break;
More information about the Gdb-cvs
mailing list