public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands
@ 2020-10-29 14:26 Tankut Baris Aktemur
  2020-11-12 15:23 ` Aktemur, Tankut Baris
  2020-11-20  9:45 ` [PATCH v2] " Tankut Baris Aktemur
  0 siblings, 2 replies; 5+ messages in thread
From: Tankut Baris Aktemur @ 2020-10-29 14:26 UTC (permalink / raw)
  To: gdb-patches

Suppose we have the script file below:

  break main
  commands
    print 123
  end
  run

If started with this script file, GDB executes the breakpoint command:

  $ gdb -q -x myscript --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.

  Breakpoint 1, main () at test.c:2
  2         return 0;
  $1 = 123
  (gdb)

However, if we remove the "run" line from the script and pass it with
the '-ex' option instead, the command is not executed:

  $ gdb -q -x myscript_no_run --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.
  Starting program: /path/to/test

  Breakpoint 1, main () at test.c:2
  2         return 0;
  (gdb)

If the user enters a command at this point, the breakpoint command
is executed, yielding weird output:

  $ gdb -q -x myscript_no_run --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.
  Starting program: /path/to/test

  Breakpoint 1, main () at test.c:2
  2         return 0;
  (gdb) print "a"
  $1 = "a"
  $2 = 123

When consuming script files, GDB runs bp actions after executing a
command.  See `command_handler` in event-top.c:

  if (c[0] != '#')
    {
      execute_command (command, ui->instream == ui->stdin_stream);

      /* Do any commands attached to breakpoint we stopped at.  */
      bpstat_do_actions ();
    }

However, for '-ex' commands, `bpstat_do_actions` is not invoked.
Hence, the misaligned output explained above occurs.  To fix the
problem, add a call to `bpstat_do_actions` after executing a command.

gdb/ChangeLog:
2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* main.c (catch_command_errors): Add a flag parameter; invoke
	`bpstat_do_actions` if the flag is set.
	(captured_main_1): Update the calls to `catch_command_errors`
	for the `execute_command` cases.

gdb/testsuite/ChangeLog:
2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.base/bp-cmds-run-with-ex.c: New file.
	* gdb.base/bp-cmds-run-with-ex.exp: New file.
	* gdb.base/bp-cmds-run-with-ex.gdb: New file.

Signed-off-by: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
---
 gdb/main.c                                    | 11 +++--
 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c  | 22 +++++++++
 .../gdb.base/bp-cmds-run-with-ex.exp          | 49 +++++++++++++++++++
 .../gdb.base/bp-cmds-run-with-ex.gdb          | 19 +++++++
 4 files changed, 98 insertions(+), 3 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
 create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
 create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb

diff --git a/gdb/main.c b/gdb/main.c
index 19bbb923889..78835b6079a 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -448,7 +448,8 @@ typedef void (catch_command_errors_const_ftype) (const char *, int);
 
 static int
 catch_command_errors (catch_command_errors_const_ftype command,
-		      const char *arg, int from_tty)
+		      const char *arg, int from_tty,
+		      bool do_bp_actions = false)
 {
   try
     {
@@ -457,6 +458,10 @@ catch_command_errors (catch_command_errors_const_ftype command,
       command (arg, from_tty);
 
       maybe_wait_sync_command_done (was_sync);
+
+      /* Do any commands attached to breakpoint we stopped at.  */
+      if (do_bp_actions)
+	bpstat_do_actions ();
     }
   catch (const gdb_exception &e)
     {
@@ -1090,7 +1095,7 @@ captured_main_1 (struct captured_main_args *context)
 	  break;
 	case CMDARG_INIT_COMMAND:
 	  ret = catch_command_errors (execute_command, cmdarg_p.string,
-				      !batch_flag);
+				      !batch_flag, true);
 	  break;
 	}
     }
@@ -1216,7 +1221,7 @@ captured_main_1 (struct captured_main_args *context)
 	  break;
 	case CMDARG_COMMAND:
 	  ret = catch_command_errors (execute_command, cmdarg_p.string,
-				      !batch_flag);
+				      !batch_flag, true);
 	  break;
 	}
     }
diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
new file mode 100644
index 00000000000..f4825c8a7c1
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
new file mode 100644
index 00000000000..447a3875f63
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
@@ -0,0 +1,49 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that breakpoint commands are taken into account when the
+# debuggee program is executed with a "run" command given through the
+# '-ex' option.
+
+standard_testfile
+
+if {[build_executable "failed to prepare" $testfile $srcfile]} {
+    return -1
+}
+
+set script_file $srcdir/$subdir/$testfile.gdb
+
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -x ${script_file}"
+    append GDBFLAGS " -ex run"
+    append GDBFLAGS " --args ${binfile}"
+
+    gdb_exit
+    if {[gdb_spawn] != 0} {
+	fail "spawn gdb"
+	return -1
+    }
+}
+
+gdb_test_multiple "" "execute bp commands" {
+    -re " = 123\r\n$gdb_prompt $" {
+	pass $gdb_test_name
+    }
+    -re "Don't know how to run.*$gdb_prompt $" {
+	unsupported $gdb_test_name
+    }
+}
diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
new file mode 100644
index 00000000000..c8da9d70251
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
@@ -0,0 +1,19 @@
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+break main
+commands
+  print 123
+end
-- 
2.17.1


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

* RE: [PATCH] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands
  2020-10-29 14:26 [PATCH] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands Tankut Baris Aktemur
@ 2020-11-12 15:23 ` Aktemur, Tankut Baris
  2020-11-20  9:45 ` [PATCH v2] " Tankut Baris Aktemur
  1 sibling, 0 replies; 5+ messages in thread
From: Aktemur, Tankut Baris @ 2020-11-12 15:23 UTC (permalink / raw)
  To: gdb-patches

Kindly pinging.

Thanks
-Baris


On Thursday, October 29, 2020 3:27 PM, Aktemur, Tankut Baris wrote:
> Suppose we have the script file below:
> 
>   break main
>   commands
>     print 123
>   end
>   run
> 
> If started with this script file, GDB executes the breakpoint command:
> 
>   $ gdb -q -x myscript --args ./test
>   Reading symbols from ./test...
>   Breakpoint 1 at 0x114e: file test.c, line 2.
> 
>   Breakpoint 1, main () at test.c:2
>   2         return 0;
>   $1 = 123
>   (gdb)
> 
> However, if we remove the "run" line from the script and pass it with
> the '-ex' option instead, the command is not executed:
> 
>   $ gdb -q -x myscript_no_run --args ./test
>   Reading symbols from ./test...
>   Breakpoint 1 at 0x114e: file test.c, line 2.
>   Starting program: /path/to/test
> 
>   Breakpoint 1, main () at test.c:2
>   2         return 0;
>   (gdb)
> 
> If the user enters a command at this point, the breakpoint command
> is executed, yielding weird output:
> 
>   $ gdb -q -x myscript_no_run --args ./test
>   Reading symbols from ./test...
>   Breakpoint 1 at 0x114e: file test.c, line 2.
>   Starting program: /path/to/test
> 
>   Breakpoint 1, main () at test.c:2
>   2         return 0;
>   (gdb) print "a"
>   $1 = "a"
>   $2 = 123
> 
> When consuming script files, GDB runs bp actions after executing a
> command.  See `command_handler` in event-top.c:
> 
>   if (c[0] != '#')
>     {
>       execute_command (command, ui->instream == ui->stdin_stream);
> 
>       /* Do any commands attached to breakpoint we stopped at.  */
>       bpstat_do_actions ();
>     }
> 
> However, for '-ex' commands, `bpstat_do_actions` is not invoked.
> Hence, the misaligned output explained above occurs.  To fix the
> problem, add a call to `bpstat_do_actions` after executing a command.
> 
> gdb/ChangeLog:
> 2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* main.c (catch_command_errors): Add a flag parameter; invoke
> 	`bpstat_do_actions` if the flag is set.
> 	(captured_main_1): Update the calls to `catch_command_errors`
> 	for the `execute_command` cases.
> 
> gdb/testsuite/ChangeLog:
> 2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* gdb.base/bp-cmds-run-with-ex.c: New file.
> 	* gdb.base/bp-cmds-run-with-ex.exp: New file.
> 	* gdb.base/bp-cmds-run-with-ex.gdb: New file.
> 
> Signed-off-by: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
> ---
>  gdb/main.c                                    | 11 +++--
>  gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c  | 22 +++++++++
>  .../gdb.base/bp-cmds-run-with-ex.exp          | 49 +++++++++++++++++++
>  .../gdb.base/bp-cmds-run-with-ex.gdb          | 19 +++++++
>  4 files changed, 98 insertions(+), 3 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
>  create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
>  create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
> 
> diff --git a/gdb/main.c b/gdb/main.c
> index 19bbb923889..78835b6079a 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -448,7 +448,8 @@ typedef void (catch_command_errors_const_ftype) (const char *, int);
> 
>  static int
>  catch_command_errors (catch_command_errors_const_ftype command,
> -		      const char *arg, int from_tty)
> +		      const char *arg, int from_tty,
> +		      bool do_bp_actions = false)
>  {
>    try
>      {
> @@ -457,6 +458,10 @@ catch_command_errors (catch_command_errors_const_ftype command,
>        command (arg, from_tty);
> 
>        maybe_wait_sync_command_done (was_sync);
> +
> +      /* Do any commands attached to breakpoint we stopped at.  */
> +      if (do_bp_actions)
> +	bpstat_do_actions ();
>      }
>    catch (const gdb_exception &e)
>      {
> @@ -1090,7 +1095,7 @@ captured_main_1 (struct captured_main_args *context)
>  	  break;
>  	case CMDARG_INIT_COMMAND:
>  	  ret = catch_command_errors (execute_command, cmdarg_p.string,
> -				      !batch_flag);
> +				      !batch_flag, true);
>  	  break;
>  	}
>      }
> @@ -1216,7 +1221,7 @@ captured_main_1 (struct captured_main_args *context)
>  	  break;
>  	case CMDARG_COMMAND:
>  	  ret = catch_command_errors (execute_command, cmdarg_p.string,
> -				      !batch_flag);
> +				      !batch_flag, true);
>  	  break;
>  	}
>      }
> diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c b/gdb/testsuite/gdb.base/bp-cmds-
> run-with-ex.c
> new file mode 100644
> index 00000000000..f4825c8a7c1
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
> @@ -0,0 +1,22 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2020 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +int
> +main ()
> +{
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp b/gdb/testsuite/gdb.base/bp-
> cmds-run-with-ex.exp
> new file mode 100644
> index 00000000000..447a3875f63
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
> @@ -0,0 +1,49 @@
> +# This testcase is part of GDB, the GNU debugger.
> +
> +# Copyright 2020 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test that breakpoint commands are taken into account when the
> +# debuggee program is executed with a "run" command given through the
> +# '-ex' option.
> +
> +standard_testfile
> +
> +if {[build_executable "failed to prepare" $testfile $srcfile]} {
> +    return -1
> +}
> +
> +set script_file $srcdir/$subdir/$testfile.gdb
> +
> +save_vars { GDBFLAGS } {
> +    append GDBFLAGS " -x ${script_file}"
> +    append GDBFLAGS " -ex run"
> +    append GDBFLAGS " --args ${binfile}"
> +
> +    gdb_exit
> +    if {[gdb_spawn] != 0} {
> +	fail "spawn gdb"
> +	return -1
> +    }
> +}
> +
> +gdb_test_multiple "" "execute bp commands" {
> +    -re " = 123\r\n$gdb_prompt $" {
> +	pass $gdb_test_name
> +    }
> +    -re "Don't know how to run.*$gdb_prompt $" {
> +	unsupported $gdb_test_name
> +    }
> +}
> diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb b/gdb/testsuite/gdb.base/bp-
> cmds-run-with-ex.gdb
> new file mode 100644
> index 00000000000..c8da9d70251
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
> @@ -0,0 +1,19 @@
> +# Copyright 2020 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +break main
> +commands
> +  print 123
> +end
> --
> 2.17.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

* [PATCH v2] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands
  2020-10-29 14:26 [PATCH] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands Tankut Baris Aktemur
  2020-11-12 15:23 ` Aktemur, Tankut Baris
@ 2020-11-20  9:45 ` Tankut Baris Aktemur
  2020-12-04 11:34   ` Aktemur, Tankut Baris
  2020-12-05 23:17   ` Pedro Alves
  1 sibling, 2 replies; 5+ messages in thread
From: Tankut Baris Aktemur @ 2020-11-20  9:45 UTC (permalink / raw)
  To: gdb-patches

This is both a ping and an update on the patch.  I noticed that two python
tests needed to be updated.

Thanks,
Baris



Suppose we have the script file below:

  break main
  commands
    print 123
  end
  run

If started with this script file, GDB executes the breakpoint command:

  $ gdb -q -x myscript --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.

  Breakpoint 1, main () at test.c:2
  2         return 0;
  $1 = 123
  (gdb)

However, if we remove the "run" line from the script and pass it with
the '-ex' option instead, the command is not executed:

  $ gdb -q -x myscript_no_run --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.
  Starting program: /path/to/test

  Breakpoint 1, main () at test.c:2
  2         return 0;
  (gdb)

If the user enters a command at this point, the breakpoint command
is executed, yielding weird output:

  $ gdb -q -x myscript_no_run --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.
  Starting program: /path/to/test

  Breakpoint 1, main () at test.c:2
  2         return 0;
  (gdb) print "a"
  $1 = "a"
  $2 = 123

When consuming script files, GDB runs bp actions after executing a
command.  See `command_handler` in event-top.c:

  if (c[0] != '#')
    {
      execute_command (command, ui->instream == ui->stdin_stream);

      /* Do any commands attached to breakpoint we stopped at.  */
      bpstat_do_actions ();
    }

However, for '-ex' commands, `bpstat_do_actions` is not invoked.
Hence, the misaligned output explained above occurs.  To fix the
problem, add a call to `bpstat_do_actions` after executing a command.

gdb/ChangeLog:
2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* main.c (catch_command_errors): Add a flag parameter; invoke
	`bpstat_do_actions` if the flag is set.
	(execute_cmdargs): Update a call to `catch_command_errors`.

gdb/testsuite/ChangeLog:
2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.base/bp-cmds-run-with-ex.c: New file.
	* gdb.base/bp-cmds-run-with-ex.exp: New file.
	* gdb.base/bp-cmds-run-with-ex.gdb: New file.
	* gdb.gdb/python-interrupts.exp: Update the call to
	'catch_command_errors' with the new argument.
	* gdb.gdb/python-selftest.exp: Ditto.
---
 gdb/main.c                                    |  9 +++-
 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c  | 22 +++++++++
 .../gdb.base/bp-cmds-run-with-ex.exp          | 49 +++++++++++++++++++
 .../gdb.base/bp-cmds-run-with-ex.gdb          | 19 +++++++
 gdb/testsuite/gdb.gdb/python-interrupts.exp   |  2 +-
 gdb/testsuite/gdb.gdb/python-selftest.exp     |  2 +-
 6 files changed, 99 insertions(+), 4 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
 create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
 create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb

diff --git a/gdb/main.c b/gdb/main.c
index d3a6637e8d4..9d0fad458c6 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -439,7 +439,8 @@ typedef void (catch_command_errors_const_ftype) (const char *, int);
 
 static int
 catch_command_errors (catch_command_errors_const_ftype command,
-		      const char *arg, int from_tty)
+		      const char *arg, int from_tty,
+		      bool do_bp_actions = false)
 {
   try
     {
@@ -448,6 +449,10 @@ catch_command_errors (catch_command_errors_const_ftype command,
       command (arg, from_tty);
 
       maybe_wait_sync_command_done (was_sync);
+
+      /* Do any commands attached to breakpoint we stopped at.  */
+      if (do_bp_actions)
+	bpstat_do_actions ();
     }
   catch (const gdb_exception &e)
     {
@@ -531,7 +536,7 @@ execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
 				     !batch_flag);
       else if (cmdarg_p.type == cmd_type)
 	*ret = catch_command_errors (execute_command, cmdarg_p.string,
-				     !batch_flag);
+				     !batch_flag, true);
     }
 }
 
diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
new file mode 100644
index 00000000000..f4825c8a7c1
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
new file mode 100644
index 00000000000..447a3875f63
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
@@ -0,0 +1,49 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that breakpoint commands are taken into account when the
+# debuggee program is executed with a "run" command given through the
+# '-ex' option.
+
+standard_testfile
+
+if {[build_executable "failed to prepare" $testfile $srcfile]} {
+    return -1
+}
+
+set script_file $srcdir/$subdir/$testfile.gdb
+
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -x ${script_file}"
+    append GDBFLAGS " -ex run"
+    append GDBFLAGS " --args ${binfile}"
+
+    gdb_exit
+    if {[gdb_spawn] != 0} {
+	fail "spawn gdb"
+	return -1
+    }
+}
+
+gdb_test_multiple "" "execute bp commands" {
+    -re " = 123\r\n$gdb_prompt $" {
+	pass $gdb_test_name
+    }
+    -re "Don't know how to run.*$gdb_prompt $" {
+	unsupported $gdb_test_name
+    }
+}
diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
new file mode 100644
index 00000000000..c8da9d70251
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
@@ -0,0 +1,19 @@
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+break main
+commands
+  print 123
+end
diff --git a/gdb/testsuite/gdb.gdb/python-interrupts.exp b/gdb/testsuite/gdb.gdb/python-interrupts.exp
index 6e5ce6ee48d..b99b23e481f 100644
--- a/gdb/testsuite/gdb.gdb/python-interrupts.exp
+++ b/gdb/testsuite/gdb.gdb/python-interrupts.exp
@@ -25,7 +25,7 @@ proc test_python_interrupts {} {
     }
 
     gdb_breakpoint set_active_ext_lang temporary
-    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0)" \
+    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0, true)" \
 	"Temporary breakpoint.*silently stop."
     gdb_test "signal SIGINT" \
 	"KeyboardInterrupt.*Error while executing Python code."
diff --git a/gdb/testsuite/gdb.gdb/python-selftest.exp b/gdb/testsuite/gdb.gdb/python-selftest.exp
index ee40245bc53..0c769f23483 100644
--- a/gdb/testsuite/gdb.gdb/python-selftest.exp
+++ b/gdb/testsuite/gdb.gdb/python-selftest.exp
@@ -22,7 +22,7 @@ proc selftest_python {} {
     }
 
     gdb_test_no_output "set variable gdb_python_initialized = 0"
-    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0)" \
+    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0, true)" \
 	"Python not initialized.* = 0"
     return 0
 }
-- 
2.17.1


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

* RE: [PATCH v2] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands
  2020-11-20  9:45 ` [PATCH v2] " Tankut Baris Aktemur
@ 2020-12-04 11:34   ` Aktemur, Tankut Baris
  2020-12-05 23:17   ` Pedro Alves
  1 sibling, 0 replies; 5+ messages in thread
From: Aktemur, Tankut Baris @ 2020-12-04 11:34 UTC (permalink / raw)
  To: gdb-patches

Ping.

Thanks
-Baris


On Friday, November 20, 2020 10:45 AM, Aktemur, Tankut Baris wrote:
> This is both a ping and an update on the patch.  I noticed that two python
> tests needed to be updated.
> 
> Thanks,
> Baris
> 
> 
> 
> Suppose we have the script file below:
> 
>   break main
>   commands
>     print 123
>   end
>   run
> 
> If started with this script file, GDB executes the breakpoint command:
> 
>   $ gdb -q -x myscript --args ./test
>   Reading symbols from ./test...
>   Breakpoint 1 at 0x114e: file test.c, line 2.
> 
>   Breakpoint 1, main () at test.c:2
>   2         return 0;
>   $1 = 123
>   (gdb)
> 
> However, if we remove the "run" line from the script and pass it with
> the '-ex' option instead, the command is not executed:
> 
>   $ gdb -q -x myscript_no_run --args ./test
>   Reading symbols from ./test...
>   Breakpoint 1 at 0x114e: file test.c, line 2.
>   Starting program: /path/to/test
> 
>   Breakpoint 1, main () at test.c:2
>   2         return 0;
>   (gdb)
> 
> If the user enters a command at this point, the breakpoint command
> is executed, yielding weird output:
> 
>   $ gdb -q -x myscript_no_run --args ./test
>   Reading symbols from ./test...
>   Breakpoint 1 at 0x114e: file test.c, line 2.
>   Starting program: /path/to/test
> 
>   Breakpoint 1, main () at test.c:2
>   2         return 0;
>   (gdb) print "a"
>   $1 = "a"
>   $2 = 123
> 
> When consuming script files, GDB runs bp actions after executing a
> command.  See `command_handler` in event-top.c:
> 
>   if (c[0] != '#')
>     {
>       execute_command (command, ui->instream == ui->stdin_stream);
> 
>       /* Do any commands attached to breakpoint we stopped at.  */
>       bpstat_do_actions ();
>     }
> 
> However, for '-ex' commands, `bpstat_do_actions` is not invoked.
> Hence, the misaligned output explained above occurs.  To fix the
> problem, add a call to `bpstat_do_actions` after executing a command.
> 
> gdb/ChangeLog:
> 2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* main.c (catch_command_errors): Add a flag parameter; invoke
> 	`bpstat_do_actions` if the flag is set.
> 	(execute_cmdargs): Update a call to `catch_command_errors`.
> 
> gdb/testsuite/ChangeLog:
> 2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* gdb.base/bp-cmds-run-with-ex.c: New file.
> 	* gdb.base/bp-cmds-run-with-ex.exp: New file.
> 	* gdb.base/bp-cmds-run-with-ex.gdb: New file.
> 	* gdb.gdb/python-interrupts.exp: Update the call to
> 	'catch_command_errors' with the new argument.
> 	* gdb.gdb/python-selftest.exp: Ditto.
> ---
>  gdb/main.c                                    |  9 +++-
>  gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c  | 22 +++++++++
>  .../gdb.base/bp-cmds-run-with-ex.exp          | 49 +++++++++++++++++++
>  .../gdb.base/bp-cmds-run-with-ex.gdb          | 19 +++++++
>  gdb/testsuite/gdb.gdb/python-interrupts.exp   |  2 +-
>  gdb/testsuite/gdb.gdb/python-selftest.exp     |  2 +-
>  6 files changed, 99 insertions(+), 4 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
>  create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
>  create mode 100644 gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
> 
> diff --git a/gdb/main.c b/gdb/main.c
> index d3a6637e8d4..9d0fad458c6 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -439,7 +439,8 @@ typedef void (catch_command_errors_const_ftype) (const char *, int);
> 
>  static int
>  catch_command_errors (catch_command_errors_const_ftype command,
> -		      const char *arg, int from_tty)
> +		      const char *arg, int from_tty,
> +		      bool do_bp_actions = false)
>  {
>    try
>      {
> @@ -448,6 +449,10 @@ catch_command_errors (catch_command_errors_const_ftype command,
>        command (arg, from_tty);
> 
>        maybe_wait_sync_command_done (was_sync);
> +
> +      /* Do any commands attached to breakpoint we stopped at.  */
> +      if (do_bp_actions)
> +	bpstat_do_actions ();
>      }
>    catch (const gdb_exception &e)
>      {
> @@ -531,7 +536,7 @@ execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
>  				     !batch_flag);
>        else if (cmdarg_p.type == cmd_type)
>  	*ret = catch_command_errors (execute_command, cmdarg_p.string,
> -				     !batch_flag);
> +				     !batch_flag, true);
>      }
>  }
> 
> diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c b/gdb/testsuite/gdb.base/bp-cmds-
> run-with-ex.c
> new file mode 100644
> index 00000000000..f4825c8a7c1
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.c
> @@ -0,0 +1,22 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2020 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +int
> +main ()
> +{
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp b/gdb/testsuite/gdb.base/bp-
> cmds-run-with-ex.exp
> new file mode 100644
> index 00000000000..447a3875f63
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.exp
> @@ -0,0 +1,49 @@
> +# This testcase is part of GDB, the GNU debugger.
> +
> +# Copyright 2020 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test that breakpoint commands are taken into account when the
> +# debuggee program is executed with a "run" command given through the
> +# '-ex' option.
> +
> +standard_testfile
> +
> +if {[build_executable "failed to prepare" $testfile $srcfile]} {
> +    return -1
> +}
> +
> +set script_file $srcdir/$subdir/$testfile.gdb
> +
> +save_vars { GDBFLAGS } {
> +    append GDBFLAGS " -x ${script_file}"
> +    append GDBFLAGS " -ex run"
> +    append GDBFLAGS " --args ${binfile}"
> +
> +    gdb_exit
> +    if {[gdb_spawn] != 0} {
> +	fail "spawn gdb"
> +	return -1
> +    }
> +}
> +
> +gdb_test_multiple "" "execute bp commands" {
> +    -re " = 123\r\n$gdb_prompt $" {
> +	pass $gdb_test_name
> +    }
> +    -re "Don't know how to run.*$gdb_prompt $" {
> +	unsupported $gdb_test_name
> +    }
> +}
> diff --git a/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb b/gdb/testsuite/gdb.base/bp-
> cmds-run-with-ex.gdb
> new file mode 100644
> index 00000000000..c8da9d70251
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-cmds-run-with-ex.gdb
> @@ -0,0 +1,19 @@
> +# Copyright 2020 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +break main
> +commands
> +  print 123
> +end
> diff --git a/gdb/testsuite/gdb.gdb/python-interrupts.exp b/gdb/testsuite/gdb.gdb/python-
> interrupts.exp
> index 6e5ce6ee48d..b99b23e481f 100644
> --- a/gdb/testsuite/gdb.gdb/python-interrupts.exp
> +++ b/gdb/testsuite/gdb.gdb/python-interrupts.exp
> @@ -25,7 +25,7 @@ proc test_python_interrupts {} {
>      }
> 
>      gdb_breakpoint set_active_ext_lang temporary
> -    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0)" \
> +    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0, true)" \
>  	"Temporary breakpoint.*silently stop."
>      gdb_test "signal SIGINT" \
>  	"KeyboardInterrupt.*Error while executing Python code."
> diff --git a/gdb/testsuite/gdb.gdb/python-selftest.exp b/gdb/testsuite/gdb.gdb/python-
> selftest.exp
> index ee40245bc53..0c769f23483 100644
> --- a/gdb/testsuite/gdb.gdb/python-selftest.exp
> +++ b/gdb/testsuite/gdb.gdb/python-selftest.exp
> @@ -22,7 +22,7 @@ proc selftest_python {} {
>      }
> 
>      gdb_test_no_output "set variable gdb_python_initialized = 0"
> -    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0)" \
> +    gdb_test "call catch_command_errors(execute_command, \"python print(5)\", 0, true)" \
>  	"Python not initialized.* = 0"
>      return 0
>  }
> --
> 2.17.1


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

* Re: [PATCH v2] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands
  2020-11-20  9:45 ` [PATCH v2] " Tankut Baris Aktemur
  2020-12-04 11:34   ` Aktemur, Tankut Baris
@ 2020-12-05 23:17   ` Pedro Alves
  1 sibling, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2020-12-05 23:17 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 11/20/20 9:45 AM, Tankut Baris Aktemur via Gdb-patches wrote:

> gdb/ChangeLog:
> 2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* main.c (catch_command_errors): Add a flag parameter; invoke
> 	`bpstat_do_actions` if the flag is set.
> 	(execute_cmdargs): Update a call to `catch_command_errors`.
> 
> gdb/testsuite/ChangeLog:
> 2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> 
> 	* gdb.base/bp-cmds-run-with-ex.c: New file.
> 	* gdb.base/bp-cmds-run-with-ex.exp: New file.
> 	* gdb.base/bp-cmds-run-with-ex.gdb: New file.
> 	* gdb.gdb/python-interrupts.exp: Update the call to
> 	'catch_command_errors' with the new argument.
> 	* gdb.gdb/python-selftest.exp: Ditto.

OK.

Thanks,
Pedro Alves

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

end of thread, other threads:[~2020-12-05 23:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 14:26 [PATCH] gdb/main: execute breakpoint commands for '-iex' and '-ex' commands Tankut Baris Aktemur
2020-11-12 15:23 ` Aktemur, Tankut Baris
2020-11-20  9:45 ` [PATCH v2] " Tankut Baris Aktemur
2020-12-04 11:34   ` Aktemur, Tankut Baris
2020-12-05 23:17   ` Pedro Alves

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