Notify observer of breakpoint auto-disabling
authorPatrick Monnerat <patrick@monnerat.net>
Mon, 16 Aug 2021 12:44:20 +0000 (14:44 +0200)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 16 Aug 2021 15:10:19 +0000 (11:10 -0400)
As breakpoint_modified observer is currently notified upon breakpoint stop
before handling auto-disabling when enable count is reached, the observer
is never notified of the disabling.

The problem affects:
- The MI interpreter enabled= value when reporting =breakpoint-modified
- A Python event handler for breakpoint_modified using the "enabled"
  member of its parameter
- insight: breakpoint GUI window is not properly updated upon auto-disable

This patch moves the observer notification after the auto-disabling
code and implements corresponding tests for the MI and Python cases.

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

Change-Id: I0c50df4789334071e5390cb46b3ca0d4a7f83c61

gdb/breakpoint.c
gdb/testsuite/gdb.mi/mi-breakpoint-changed.exp
gdb/testsuite/gdb.python/py-breakpoint.exp

index 89af44ee4c6b8dfdca3d07c61fc4e73b2cc04f01..feca224ccf425fe4490f8f9a58c2b19720167580 100644 (file)
@@ -5491,7 +5491,6 @@ bpstat_stop_status (const address_space *aspace,
          if (bs->stop)
            {
              ++(b->hit_count);
-             gdb::observers::breakpoint_modified.notify (b);
 
              /* We will stop here.  */
              if (b->disposition == disp_disable)
@@ -5501,6 +5500,7 @@ bpstat_stop_status (const address_space *aspace,
                    b->enable_state = bp_disabled;
                  removed_any = 1;
                }
+             gdb::observers::breakpoint_modified.notify (b);
              if (b->silent)
                bs->print = 0;
              bs->commands = b->commands;
index 3f7ef8a79b6635af883a78dfda3d86ff076a27f0..d068a25b9f4886f269ee903ea13588761fec1d94 100644 (file)
@@ -257,3 +257,44 @@ proc test_pending_resolved { } {
 with_test_prefix "test_pending_resolved" {
     test_pending_resolved
 }
+
+# Test auto-disable is effective when notifying breakpoint-modified.
+
+proc test_auto_disable { } {
+    global mi_gdb_prompt
+    global lib_sl1 lib_sl2
+    global binfile
+
+    mi_clean_restart $binfile
+
+    mi_load_shlibs $lib_sl1 $lib_sl2
+
+    mi_runto_main
+
+    # Set the breakpoint.
+    mi_gdb_test "-break-insert -f pendfunc1" \
+       {(&.*)*.*~"Breakpoint 2 at.*\\n".*=breakpoint-created,bkpt=\{number="2",type="breakpoint".*\}.*\n\^done}
+
+    # Enable for one shot only.
+    mi_gdb_test "-break-enable count 1 2" \
+       {=breakpoint-modified,bkpt=\{number="2",type="breakpoint",disp="dis",enabled="y".*\}.*\n\^done}
+
+    mi_send_resuming_command "exec-continue" "continuing execution to breakpoint"
+
+    set test "breakpoint auto-disabling after enable count reached"
+    gdb_expect {
+       -re ".*=breakpoint-modified,bkpt=\{number=\"2\".*enabled=\"n\"" {
+           pass $test
+       }
+       -re ".*${mi_gdb_prompt}$" {
+           fail $test
+       }
+       timeout {
+           fail "$test (timeout)"
+       }
+    }
+}
+
+with_test_prefix "test_auto_disable" {
+    test_auto_disable
+}
index e2ffe8cbe468692212985f9821a598ad832a8ad5..857480d4b618c4ade8e40453ad129c6c9c45665b 100644 (file)
@@ -799,6 +799,28 @@ proc_with_prefix test_catchpoints {} {
     gdb_test "continue" "Stopped at catchpoint event: ${num}"
 }
 
+# Test auto-disable is effective when notifying breakpoint_modified.
+
+proc_with_prefix test_bkpt_auto_disable { } {
+    global srcfile testfile hex decimal
+
+    # Start with a fresh gdb.
+    clean_restart ${testfile}
+
+    if ![runto_main] then {
+       fail "cannot run to main."
+       return 0
+    }
+    delete_breakpoints
+
+    set mult_line [gdb_get_line_number "Break at multiply."]
+    gdb_breakpoint ${mult_line}
+    gdb_test_no_output "enable count 1 2" "one shot enable"
+    gdb_test_no_output "python gdb.events.breakpoint_modified.connect(lambda bp: print(bp.enabled))" \
+       "trap breakpoint_modified event"
+    gdb_test "continue" "False.*" "auto-disabling after enable count reached"
+}
+
 test_bkpt_basic
 test_bkpt_deletion
 test_bkpt_cond_and_cmds
@@ -815,3 +837,4 @@ test_bkpt_events
 test_bkpt_explicit_loc
 test_bkpt_qualified
 test_bkpt_probe
+test_bkpt_auto_disable