Read Ada main name from executable, not inferior
authorTom Tromey <tromey@adacore.com>
Mon, 21 Aug 2023 15:55:14 +0000 (09:55 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 5 Sep 2023 15:54:53 +0000 (09:54 -0600)
commit358be6e72d464349e5146095bdb04b96be5734c1
treebe414ce7ecbcc1f7e738d5db274503babe1c2dd3
parent655e4e52ef44c1670a3b6f979b85534279c9f6c1
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
gdb/ada-lang.c
gdb/target.c
gdb/target.h
gdb/testsuite/gdb.ada/file-then-restart.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/file-then-restart/first.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/file-then-restart/second.adb [new file with mode: 0644]