public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec
@ 2020-04-10 16:33 vries at gcc dot gnu.org
  2023-04-19 18:40 ` [Bug ada/25811] " tromey at sourceware dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-04-10 16:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25811

            Bug ID: 25811
           Summary: [ada] start attempts to set breakpoint on main of
                    previous exec
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ada
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider the execs first and second from test-case gdb.ada/exec_changed.exp.

If we load first, and start it, and then subsequently load and start second:
...
$ gdb -ex "file first" -ex start -ex "file second" -ex start
Reading symbols from first...
Temporary breakpoint 1 at 0x401f88: file exec_changed/first.adb, line 16.
Starting program: /data/gdb_versions/devel/first 

Temporary breakpoint 1, first ()
    at exec_changed/first.adb:16
16      procedure First is
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Load new symbol table from "second"? (y or n) y
Reading symbols from second...
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Function "_ada_first" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Temporary breakpoint 2 (-qualified _ada_first) pending.
Starting program: /data/gdb_versions/devel/second 
[Inferior 1 (process 1069) exited normally]
...
the second start attempts to set a breakpoint on the main of first, which
fails, after we don't stop at main but just run to exit.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ada/25811] [ada] start attempts to set breakpoint on main of previous exec
  2020-04-10 16:33 [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec vries at gcc dot gnu.org
@ 2023-04-19 18:40 ` tromey at sourceware dot org
  2023-08-21 15:41 ` tromey at sourceware dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2023-04-19 18:40 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25811

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
The bug here is that ada_main_name reads memory to find
the name:

      main_program_name = target_read_string (main_program_name_addr, 1024);

The symbol is correctly found in the new executable:

(top-gdb) p msym.objfile.original_name
$19 = 0x3424020
"/home/tromey/gdb/build/gdb/testsuite/outputs/gdb.ada/exec_changed/./common"

... but the memory comes from the running inferior.

If I "kill" the inferior first, it works:

(gdb) kill
Kill the program being debugged? (y or n) y
[Inferior 1 (process 2209503) killed]
(gdb) file ./common 
Load new symbol table from "./common"? (y or n) y
Reading symbols from ./common...
(gdb) info main
_ada_second


I'm not really sure what we want to do about this case.

Another way to make it work is "set trust-readonly-sections on".
Perhaps ada_main_name could do this temporarily.  I can't tell
if I think that would be a hack or not.  Actually... instead of
modifying the flag, it might be better to just dig through
the BFD section data by hand.  (Not sure.)

A better solution would be to modify the compiler to emit
DW_AT_main_subprogram, but I am not sure how hard that would be.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ada/25811] [ada] start attempts to set breakpoint on main of previous exec
  2020-04-10 16:33 [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec vries at gcc dot gnu.org
  2023-04-19 18:40 ` [Bug ada/25811] " tromey at sourceware dot org
@ 2023-08-21 15:41 ` tromey at sourceware dot org
  2023-08-23 17:12 ` tromey at sourceware dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2023-08-21 15:41 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25811

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |tromey at sourceware dot org

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
I looked into the compiler and it seems somewhat difficult to
switch to DW_AT_main_subprogram.  The issue is that this decision
is made by "bindgen" and it just writes an Ada program.  So, we'd
need a new Pragma or something along those lines.

I'm testing a patch to temporarily change trust_readonly, instead.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ada/25811] [ada] start attempts to set breakpoint on main of previous exec
  2020-04-10 16:33 [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec vries at gcc dot gnu.org
  2023-04-19 18:40 ` [Bug ada/25811] " tromey at sourceware dot org
  2023-08-21 15:41 ` tromey at sourceware dot org
@ 2023-08-23 17:12 ` tromey at sourceware dot org
  2023-09-05 16:05 ` cvs-commit at gcc dot gnu.org
  2023-09-05 16:06 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2023-08-23 17:12 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25811

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
https://sourceware.org/pipermail/gdb-patches/2023-August/201838.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ada/25811] [ada] start attempts to set breakpoint on main of previous exec
  2020-04-10 16:33 [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-08-23 17:12 ` tromey at sourceware dot org
@ 2023-09-05 16:05 ` cvs-commit at gcc dot gnu.org
  2023-09-05 16:06 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-05 16:05 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25811

--- Comment #4 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=358be6e72d464349e5146095bdb04b96be5734c1

commit 358be6e72d464349e5146095bdb04b96be5734c1
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Aug 21 09:55:14 2023 -0600

    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

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ada/25811] [ada] start attempts to set breakpoint on main of previous exec
  2020-04-10 16:33 [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-09-05 16:05 ` cvs-commit at gcc dot gnu.org
@ 2023-09-05 16:06 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2023-09-05 16:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25811

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.1
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #5 from Tom Tromey <tromey at sourceware dot org> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-05 16:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-10 16:33 [Bug ada/25811] New: [ada] start attempts to set breakpoint on main of previous exec vries at gcc dot gnu.org
2023-04-19 18:40 ` [Bug ada/25811] " tromey at sourceware dot org
2023-08-21 15:41 ` tromey at sourceware dot org
2023-08-23 17:12 ` tromey at sourceware dot org
2023-09-05 16:05 ` cvs-commit at gcc dot gnu.org
2023-09-05 16:06 ` tromey at sourceware dot org

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).