From: "Maciej W. Rozycki" <macro@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Richard Bunt <richard.bunt@linaro.org>
Subject: [PATCH 2/3] GDB: Bring back the handling of DW_CC_program
Date: Tue, 28 Mar 2023 17:06:50 +0100 (BST) [thread overview]
Message-ID: <alpine.DEB.2.20.2303281613120.15477@tpp.orcam.me.uk> (raw)
In-Reply-To: <alpine.DEB.2.20.2303281539110.15477@tpp.orcam.me.uk>
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.
---
NB this was discovered with and is covered by the test case included with
3/3; it has been verified to trigger with GCC 4.4.7 and will likely also
with other configurations.
---
gdb/dwarf2/read.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
gdb-main-name-dw-cc-program.diff
Index: src/gdb/dwarf2/read.c
===================================================================
--- src.orig/gdb/dwarf2/read.c
+++ src/gdb/dwarf2/read.c
@@ -9994,6 +9994,18 @@ inherit_abstract_dies (struct die_info *
compute_delayed_physnames (origin_cu);
}
+/* Return TRUE if the given DIE is the program's "main". */
+
+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 +10096,7 @@ read_func_scope (struct die_info *die, s
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 ());
@@ -16141,6 +16153,11 @@ cooked_indexer::scan_attributes (dwarf2_
*flags |= IS_MAIN;
break;
+ 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;
next prev parent reply other threads:[~2023-03-28 16:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 16:06 [PATCH 0/3] Fixes and improvements for the starting function Maciej W. Rozycki
2023-03-28 16:06 ` [PATCH 1/3] GDB: Favor full symbol main name for backtrace stop Maciej W. Rozycki
2023-03-28 16:06 ` Maciej W. Rozycki [this message]
2023-03-28 16:07 ` [PATCH 3/3] GDB: Add `info main' command Maciej W. Rozycki
2023-03-28 17:04 ` [PATCH 0/3] Fixes and improvements for the starting function Eli Zaretskii
2023-03-28 17:27 ` Maciej W. Rozycki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.2303281613120.15477@tpp.orcam.me.uk \
--to=macro@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=richard.bunt@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).