From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Always fetch Ada "main" name from the executable
Date: Thu, 30 Jul 2026 11:03:36 -0600 [thread overview]
Message-ID: <20260730170336.2547536-1-tromey@adacore.com> (raw)
The gdb.ada/file-then-restart.exp test was failing with gnat-llvm. I
tracked this down to the "main" name not being stored in a readonly
section, meaning that the code in ada_main_name using trust_readonly
did not work.
However, it seems to me that gdb should always prefer the data from
the executable in this particular case. So, rather than relying on
trust_readonly, this patch changes gdb to do this directly.
---
gdb/ada-lang.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3c6c9af488f..906c5cd3465 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -775,8 +775,6 @@ ada_get_decoded_type (struct type *type)
const char *
ada_main_name ()
{
- static gdb::unique_xmalloc_ptr<char> main_program_name;
-
/* For Ada, the name of the main procedure is stored in a specific
string constant, generated by the binder. Look for that symbol,
extract its address, and then read that string. If we didn't find
@@ -786,21 +784,31 @@ ada_main_name ()
= lookup_minimal_symbol (current_program_space,
ADA_MAIN_PROGRAM_SYMBOL_NAME);
- if (msym.minsym != NULL)
+ if (msym.minsym != nullptr)
{
+ static gdb_byte main_program_name[1024];
+
CORE_ADDR main_program_name_addr = msym.value_address ();
if (main_program_name_addr == 0)
error (_("Invalid address for Ada main program name."));
- /* Force trust_readonly, because we always want to fetch this
- string from the executable, not from inferior memory. If the
- user changes the exec-file and invokes "start", we want to
- pick the "main" from the new executable, not one that may
- come from the still-live inferior. */
- scoped_restore save_trust_readonly
- = make_scoped_restore (&trust_readonly, true);
- main_program_name = target_read_string (main_program_name_addr, 1024);
- return main_program_name.get ();
+ /* We always want to fetch this string from the executable, not
+ from inferior memory. If the user changes the exec-file and
+ invokes "start", we want to pick the "main" from the new
+ executable, not one that may come from the still-live
+ inferior. */
+ ULONGEST xferred = 0;
+ const auto §ions = current_program_space->target_sections ();
+ if ((section_table_xfer_memory_partial (main_program_name, nullptr,
+ main_program_name_addr,
+ sizeof (main_program_name),
+ &xferred,
+ sections)
+ == TARGET_XFER_OK)
+ && xferred > 0
+ && (strnlen ((char *) main_program_name, sizeof (main_program_name))
+ < sizeof (main_program_name)))
+ return (char *) main_program_name;
}
/* The main procedure doesn't seem to be in Ada. */
base-commit: 6d1be0b90e837e4c82eaaf6f9e8c7da7227902e1
--
2.55.0
next reply other threads:[~2026-07-30 17:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 17:03 Tom Tromey [this message]
2026-07-31 10:48 ` Pedro Alves
2026-08-05 17:07 ` Andrew Burgess
2026-08-07 13:55 ` Tom Tromey
2026-08-07 15:03 ` Andrew Burgess
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=20260730170336.2547536-1-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.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