diff options
author | Tom Tromey <tromey@adacore.com> | 2023-08-21 09:55:14 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-09-05 09:54:53 -0600 |
commit | 358be6e72d464349e5146095bdb04b96be5734c1 (patch) | |
tree | be414ce7ecbcc1f7e738d5db274503babe1c2dd3 /gdb/ada-lang.c | |
parent | 655e4e52ef44c1670a3b6f979b85534279c9f6c1 (diff) | |
download | gdb-358be6e72d464349e5146095bdb04b96be5734c1.zip gdb-358be6e72d464349e5146095bdb04b96be5734c1.tar.gz gdb-358be6e72d464349e5146095bdb04b96be5734c1.tar.bz2 |
Read Ada main name from executable, not inferior
An upstream bug report points out this bug: if the user switches from
one Ada executable to another without "kill"ing the inferior, then the
"start" command will fail.
What happens here is that the Ada "main" name is found in a constant
string in the executable. But, if the inferior is running, then the
process_stratum target reads from the inferior memory.
This patch fixes the problem by changing the main name code to set
trust-readonly-sections, causing the target stack to read from the
executable instead.
I looked briefly at changing GNAT to emit DW_AT_main_subprogram
instead, but this looks to be pretty involved.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25811
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r-- | gdb/ada-lang.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index cc64e09..f6a623d 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -814,6 +814,13 @@ ada_main_name () 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 (); } |