public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script
@ 2014-10-30 18:23 brobecker at gnat dot com
  2014-10-30 18:37 ` [Bug gdb/17525] " brobecker at gnat dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: brobecker at gnat dot com @ 2014-10-30 18:23 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 17525
           Summary: target-async: breakpoint commands not executed when
                    program run from -x script
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: brobecker at gnat dot com

We stumbled onto a regression that is making me think we should be making a GDB
7.8.2 release, after all.

On x86_64-linux, with current HEAD or 7.8, consider the following C program:

% cat foo.c
int
increment (int i)
{
  return i + 1;
}

#define N_INCR 20

int
main (void)
{
  int val = 1;
  int j;

  for (j = 0; j < N_INCR; j++)
    val = increment (val);
  return val == N_INCR;
}

And the following GDB script:

% cat cmds.gdb
file foo
break increment
commands
   cont
end
run

The script inserts a breakpoint on a function that gets called repetitively,
and adds a commands-list to that breakpoint that just "cont"s (until we reach
the end of the program).

However, trying to execute that script by passing it as a -x argument on the
command line yields the following behavior:

% /t.a/brobecke/bld/gdb-public/gdb/gdb -q -x cmds.gdb

Breakpoint 1 at 0x40049d: file foo.c, line 4.
Breakpoint 1, increment (i=1) at foo.c:4
4      return i + 1;

Breakpoint 1, increment (i=2) at foo.c:4
4      return i + 1;
(gdb)

Adding "maintenance set target-async off" makes the problem disappear.

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
@ 2014-10-30 18:37 ` brobecker at gnat dot com
  2015-01-13 17:57 ` palves at redhat dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: brobecker at gnat dot com @ 2014-10-30 18:37 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Joel Brobecker <brobecker at gnat dot com> ---
The script works fine when sourced from the GDB prompt, Eg:

    (gdb) source cmds.gdb
    [program runs to completion after hitting breakpoints 20 times]

It also works when the script is piped to GDB's stdin:

    % cat cmds.gdb | gdb

I think the difference is that the script is then executed as part of GDB's
global main loop, which calls bpstat_do_actions at the end of each command's
execution, whereas "-x cmds.gdb" just results in source_script being called.
The latter ends up executing the "run" command from our script, with the
associated call to bpstat_do_actions, which explains why the commands-list
gets executed once, but then that's it.

Adding bogus commands such as...

   echo
   echo
   echo
   echo

... each cause additional commands to be executed which themselves trigger
bpstat_do_actions to be executed, thus each giving us back one of the missing
iterations.

But what we need is to be able to loop-until-we're-done after having sourced
the script.

One thing thats' interesting which might indicate that I'm missing something is
the fact that after the debugger stops (too early), my prompt is not the one I
would expect (through .gdbinit). At this point, if:

 - I press ctrl-d, then my normal prompt appears;
 - I type "bogus" as a command, GDB does:

    (gdb) bogus
    Undefined command: "bogus".  Try "help".

 - I type a valid command, the command gets executed, and my program then
resumes once:

    (gdb) print 1
    $1 = 1

    Breakpoint 1, increment (i=7) at foo.c:4
    4      return i + 1;

I have clearly missed something.

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
  2014-10-30 18:37 ` [Bug gdb/17525] " brobecker at gnat dot com
@ 2015-01-13 17:57 ` palves at redhat dot com
  2015-01-13 19:01 ` palves at redhat dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: palves at redhat dot com @ 2015-01-13 17:57 UTC (permalink / raw)
  To: gdb-prs

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

Pedro Alves <palves at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |palves at redhat dot com
           Assignee|unassigned at sourceware dot org   |palves at redhat dot com

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
  2014-10-30 18:37 ` [Bug gdb/17525] " brobecker at gnat dot com
  2015-01-13 17:57 ` palves at redhat dot com
@ 2015-01-13 19:01 ` palves at redhat dot com
  2015-01-13 21:03 ` dje at google dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: palves at redhat dot com @ 2015-01-13 19:01 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Pedro Alves <palves at redhat dot com> ---
Patch sent:
 https://sourceware.org/ml/gdb-patches/2015-01/msg00353.html

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
                   ` (2 preceding siblings ...)
  2015-01-13 19:01 ` palves at redhat dot com
@ 2015-01-13 21:03 ` dje at google dot com
  2015-01-14 12:38 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dje at google dot com @ 2015-01-13 21:03 UTC (permalink / raw)
  To: gdb-prs

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

dje at google dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dje at google dot com

--- Comment #3 from dje at google dot com ---
As a data point, see also https://sourceware.org/bugzilla/show_bug.cgi?id=17223

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
                   ` (3 preceding siblings ...)
  2015-01-13 21:03 ` dje at google dot com
@ 2015-01-14 12:38 ` cvs-commit at gcc dot gnu.org
  2015-01-14 12:43 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2015-01-14 12:38 UTC (permalink / raw)
  To: gdb-prs

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

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

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

commit 5589af0e6661abe07e9a997f6324988b4b87c72f
Author: Pedro Alves <palves@redhat.com>
Date:   Mon Jan 12 19:30:08 2015 +0000

    PR17525 - breakpoint commands not executed when program run from -x script

    Executing a gdb script that runs the inferior (from the command line
    with -x), and has it hit breakpoints with breakpoint commands that
    themselves run the target, is currently broken on async targets
    (Linux, remote).

    While we're executing a command list or a script, we force the
    interpreter to be sync, which results in some functions nesting an
    event loop and waiting for the target to stop, instead of returning
    immediately and having the top level event loop handle the stop.

    The issue with this bug is simply that bpstat_do_actions misses
    checking whether the interpreter is sync.  When we get here, in the
    case of executing a script (or, when the interpreter is sync), the
    program has already advanced to the next breakpoint, through
    maybe_wait_sync_command_done.  We need to process its breakpoints
    immediately, just like with a sync target.

    Tested on x86_64 Fedora 20.

    gdb/
    2015-01-14  Pedro Alves  <palves@redhat.com>

        PR gdb/17525
        * breakpoint.c: Include "interps.h".
        (bpstat_do_actions_1): Also check whether the interpreter is
        async.

    gdb/testsuite/
    2015-01-14  Pedro Alves  <palves@redhat.com>
            Joel Brobecker  <brobecker@adacore.com>

        PR gdb/17525
        * gdb.base/bp-cmds-execution-x-script.c: New file.
        * gdb.base/bp-cmds-execution-x-script.exp: New file.
        * gdb.base/bp-cmds-execution-x-script.gdb: New file.

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
                   ` (4 preceding siblings ...)
  2015-01-14 12:38 ` cvs-commit at gcc dot gnu.org
@ 2015-01-14 12:43 ` cvs-commit at gcc dot gnu.org
  2015-01-14 13:18 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2015-01-14 12:43 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The gdb-7.9-branch branch has been updated by Pedro Alves
<palves@sourceware.org>:

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

commit e18fc124cef918e6a7d9de89804850a6f8f765b4
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Jan 14 12:38:47 2015 +0000

    PR17525 - breakpoint commands not executed when program run from -x script

    Executing a gdb script that runs the inferior (from the command line
    with -x), and has it hit breakpoints with breakpoint commands that
    themselves run the target, is currently broken on async targets
    (Linux, remote).

    While we're executing a command list or a script, we force the
    interpreter to be sync, which results in some functions nesting an
    event loop and waiting for the target to stop, instead of returning
    immediately and having the top level event loop handle the stop.

    The issue with this bug is simply that bpstat_do_actions misses
    checking whether the interpreter is sync.  When we get here, in the
    case of executing a script (or, when the interpreter is sync), the
    program has already advanced to the next breakpoint, through
    maybe_wait_sync_command_done.  We need to process its breakpoints
    immediately, just like with a sync target.

    Tested on x86_64 Fedora 20.

    gdb/
    2015-01-14  Pedro Alves  <palves@redhat.com>

        PR gdb/17525
        * breakpoint.c: Include "interps.h".
        (bpstat_do_actions_1): Also check whether the interpreter is
        async.

    gdb/testsuite/
    2015-01-14  Pedro Alves  <palves@redhat.com>
            Joel Brobecker  <brobecker@adacore.com>

        PR gdb/17525
        * gdb.base/bp-cmds-execution-x-script.c: New file.
        * gdb.base/bp-cmds-execution-x-script.exp: New file.
        * gdb.base/bp-cmds-execution-x-script.gdb: New file.

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
                   ` (5 preceding siblings ...)
  2015-01-14 12:43 ` cvs-commit at gcc dot gnu.org
@ 2015-01-14 13:18 ` cvs-commit at gcc dot gnu.org
  2015-01-14 13:48 ` palves at redhat dot com
  2021-11-08  8:28 ` richardshodges7 at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2015-01-14 13:18 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #6 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The gdb-7.8-branch branch has been updated by Pedro Alves
<palves@sourceware.org>:

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

commit d2c8f4be20a4213ea64b0ede63c2fcde69c637a1
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Jan 14 12:38:47 2015 +0000

    PR17525 - breakpoint commands not executed when program run from -x script

    Executing a gdb script that runs the inferior (from the command line
    with -x), and has it hit breakpoints with breakpoint commands that
    themselves run the target, is currently broken on async targets
    (Linux, remote).

    While we're executing a command list or a script, we force the
    interpreter to be sync, which results in some functions nesting an
    event loop and waiting for the target to stop, instead of returning
    immediately and having the top level event loop handle the stop.

    The issue with this bug is simply that bpstat_do_actions misses
    checking whether the interpreter is sync.  When we get here, in the
    case of executing a script (or, when the interpreter is sync), the
    program has already advanced to the next breakpoint, through
    maybe_wait_sync_command_done.  We need to process its breakpoints
    immediately, just like with a sync target.

    Tested on x86_64 Fedora 20.

    gdb/
    2015-01-14  Pedro Alves  <palves@redhat.com>

        PR gdb/17525
        * breakpoint.c: Include "interps.h".
        (bpstat_do_actions_1): Also check whether the interpreter is
        async.

    gdb/testsuite/
    2015-01-14  Pedro Alves  <palves@redhat.com>
            Joel Brobecker  <brobecker@adacore.com>

        PR gdb/17525
        * gdb.base/bp-cmds-execution-x-script.c: New file.
        * gdb.base/bp-cmds-execution-x-script.exp: New file.
        * gdb.base/bp-cmds-execution-x-script.gdb: New file.

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
                   ` (6 preceding siblings ...)
  2015-01-14 13:18 ` cvs-commit at gcc dot gnu.org
@ 2015-01-14 13:48 ` palves at redhat dot com
  2021-11-08  8:28 ` richardshodges7 at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: palves at redhat dot com @ 2015-01-14 13:48 UTC (permalink / raw)
  To: gdb-prs

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

Pedro Alves <palves at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Pedro Alves <palves at redhat dot com> ---
Fixed in 7.8, 7.9 and master.

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


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

* [Bug gdb/17525] target-async: breakpoint commands not executed when program run from -x script
  2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
                   ` (7 preceding siblings ...)
  2015-01-14 13:48 ` palves at redhat dot com
@ 2021-11-08  8:28 ` richardshodges7 at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: richardshodges7 at gmail dot com @ 2021-11-08  8:28 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #8 from Kobi <richardshodges7 at gmail dot com> ---
The issue with this bug is simply that bpstat_do_actions misses
    checking whether the interpreter is sync.  When we get here, in the
    case of executing a script (or, when the interpreter is sync), the
    program has already advanced to the next breakpoint, through
    maybe_wait_sync_command_done. http://springfieldconcretesolutions.com

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

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

end of thread, other threads:[~2021-11-08  8:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-30 18:23 [Bug gdb/17525] New: target-async: breakpoint commands not executed when program run from -x script brobecker at gnat dot com
2014-10-30 18:37 ` [Bug gdb/17525] " brobecker at gnat dot com
2015-01-13 17:57 ` palves at redhat dot com
2015-01-13 19:01 ` palves at redhat dot com
2015-01-13 21:03 ` dje at google dot com
2015-01-14 12:38 ` cvs-commit at gcc dot gnu.org
2015-01-14 12:43 ` cvs-commit at gcc dot gnu.org
2015-01-14 13:18 ` cvs-commit at gcc dot gnu.org
2015-01-14 13:48 ` palves at redhat dot com
2021-11-08  8:28 ` richardshodges7 at gmail dot com

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