[1/5] Save breakpoints so they are automatically pending

Message ID 20230129162105.526266-2-tom@tromey.com
State New
Headers
Series Additions to "save" command |

Commit Message

Tom Tromey Jan. 29, 2023, 4:21 p.m. UTC
  PR breakpoints/18183 points out that breakpoints saved with the "save
breakpoints" command can be slightly inconvenient, depending on "set
breakpoint pending".

This patch makes use of the new "with" command to save breakpoints
such that they will automatically be made pending, if necessary, when
being restored.

Unfortunately, reloading a breakpoint saved this way will also print:

    No symbol table is loaded.  Use the "file" command.

This seems strange to me, and also a bit useless, but changing
create_breakpoint not to call exception_print in the AUTO_BOOLEAN_TRUE
case caused other regressions, so I've left it as-is for the time
being.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18183
---
 gdb/breakpoint.c                        |  1 +
 gdb/testsuite/gdb.base/catch-signal.exp | 10 +++++-----
 gdb/testsuite/gdb.base/save-bp.exp      | 20 ++++++++++++++++++++
 gdb/testsuite/gdb.base/ui-redirect.exp  |  7 ++++---
 4 files changed, 30 insertions(+), 8 deletions(-)
  

Comments

Alexandra Petlanova Hajkova Jan. 31, 2023, 3:14 p.m. UTC | #1
On Sun, Jan 29, 2023 at 5:21 PM Tom Tromey <tom@tromey.com> wrote:

> PR breakpoints/18183 points out that breakpoints saved with the "save
> breakpoints" command can be slightly inconvenient, depending on "set
> breakpoint pending".
>
> This patch makes use of the new "with" command to save breakpoints
> such that they will automatically be made pending, if necessary, when
> being restored.
>
> Unfortunately, reloading a breakpoint saved this way will also print:
>
>     No symbol table is loaded.  Use the "file" command.
>
> This seems strange to me, and also a bit useless, but changing
> create_breakpoint not to call exception_print in the AUTO_BOOLEAN_TRUE
> case caused other regressions, so I've left it as-is for the time
> being.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18183
>
> I've tried this out and I think it's very convenient and makes gdb more
user friendly.

Before this patch:
gdb]$ ./gdb -ex 'b write' /bin/ls
save breakpoints tbb

The pending breakpoint was not reloaded:
gdb]$ ./gdb /bin/ls
(gdb) source tbb
Function "write" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered
N; input not from terminal]
(gdb)

and after applying the patch pending breakpoint is there:
(gdb) source tbb
Function "write" not defined.
Breakpoint 1 (write) pending.
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 00cc2ab401c..bd11d26fca4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -14170,6 +14170,7 @@  save_breakpoints (const char *filename, int from_tty,
       if (filter && !filter (tp))
 	continue;
 
+      fp.puts ("with breakpoint pending on -- ");
       tp->print_recreate (&fp);
 
       /* Note, we can't rely on tp->number for anything, as we can't
diff --git a/gdb/testsuite/gdb.base/catch-signal.exp b/gdb/testsuite/gdb.base/catch-signal.exp
index 774eb8ee856..2e3160c2a33 100644
--- a/gdb/testsuite/gdb.base/catch-signal.exp
+++ b/gdb/testsuite/gdb.base/catch-signal.exp
@@ -128,10 +128,10 @@  foreach {arg desc} {"" "standard signals" \
     set data [split $file_data "\n"]
     close $fd
 
-    if {$arg == ""} {
-	set pattern "catch signal"
-    } else {
-	set pattern "catch signal $arg"
+    set prefix  "with breakpoint pending on -- "
+    set pattern "${prefix}catch signal"
+    if {$arg != ""} {
+	append pattern " $arg"
     }
     gdb_assert {[expr [llength $data] == 3]} \
 	"Number of lines of save breakpoints for '$arg'"
@@ -139,7 +139,7 @@  foreach {arg desc} {"" "standard signals" \
     gdb_assert {[string match $pattern [lindex $data 0]]} \
 	"1st line of save breakpoints for '$arg'"
     # Check the second line.
-    gdb_assert {[string match "break main" [lindex $data 1]]} \
+    gdb_assert {[string match "${prefix}break main" [lindex $data 1]]} \
         "2nd line of save breakpoints for '$arg'"
     # Check the trailing newline.
     gdb_assert {[string match "" [lindex $data 2]]} \
diff --git a/gdb/testsuite/gdb.base/save-bp.exp b/gdb/testsuite/gdb.base/save-bp.exp
index a39712c7f5c..daa7509ae8e 100644
--- a/gdb/testsuite/gdb.base/save-bp.exp
+++ b/gdb/testsuite/gdb.base/save-bp.exp
@@ -89,3 +89,23 @@  gdb_test_sequence "info break" "info break" [list				\
   "\[\r\n\]+\[ \t\]+printf"							\
   "\[\r\n\]+$disabled_row_start main at \[^\r\n\]*$srcfile:$loc_bp8"		\
 ]
+
+clean_restart
+gdb_test "source $bps" "" "source bps without symbol file"
+
+set pending "\[0-9\]+ +breakpoint +keep +y +<PENDING> +"
+set disabled_pending "\[0-9\]+ +breakpoint +keep +n +<PENDING> +"
+set dprintf_pending "\[0-9\]+ +dprintf +keep +y +<PENDING> +"
+gdb_test_sequence "info break" "info break without symbol file" \
+    [list							\
+	 "\[\r\n\]+Num +Type +Disp +Enb +Address +What"		\
+	 "\[\r\n\]+$pending break_me"				\
+	 "\[\r\n\]+$pending $srcfile:$loc_bp2"			\
+	 "\[\r\n\]+$pending $srcfile:$loc_bp3 +thread 1"	\
+	 "\[\r\n\]+$pending $srcfile:$loc_bp4"			\
+	 "\[\r\n\]+\[ \t\]+stop only if i == 1( \\((host|target) evals\\))?" \
+	 "\[\r\n\]+$pending $srcfile:$loc_bp5"			\
+	 "\[\r\n\]+\[ \t\]+silent"				\
+	 "\[\r\n\]+$dprintf_pending $srcfile:$loc_bp5,"		\
+	 "\[\r\n\]+$disabled_pending $srcfile:$loc_bp8"		\
+	]
diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index c0ba4f11809..a95e4fa6e90 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -42,13 +42,14 @@  gdb_test_no_output "end"
 gdb_breakpoint "foo"
 gdb_breakpoint "bar"
 
+set prefix  "with breakpoint pending on -- "
 set cmds [multi_line_input \
-	      "break -qualified main" \
+	      "${prefix}break -qualified main" \
 	      "  commands" \
 	      "    print 1" \
 	      "  end" \
-	      "break foo" \
-	      "break bar"]
+	      "${prefix}break foo" \
+	      "${prefix}break bar"]
 set cmds "$cmds\n"
 set outdir [standard_output_file {}]
 set cmds_file "$outdir/cmds.txt"