aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/NEWS6
-rw-r--r--gdb/doc/gdb.texinfo5
-rw-r--r--gdb/mi/mi-cmd-break.c2
-rw-r--r--gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp68
4 files changed, 67 insertions, 14 deletions
diff --git a/gdb/NEWS b/gdb/NEWS
index 54b5da2..e3c095d 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -113,6 +113,12 @@ info main
without a thread restriction. The same is also true for the 'task'
field of an Ada task-specific breakpoint.
+** It is no longer possible to create a thread-specific breakpoint for
+ a thread that doesn't exist using '-break-insert -p ID'. Creating
+ breakpoints for non-existent threads is not allowed when using the
+ CLI, that the MI allowed it was a long standing bug, which has now
+ been fixed.
+
* Python API
** The gdb.unwinder.Unwinder.name attribute is now read-only.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 2dad3ef..b21823d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -32215,7 +32215,10 @@ all of the breakpoint locations.
Initialize the @var{ignore-count}.
@item -p @var{thread-id}
Restrict the breakpoint to the thread with the specified global
-@var{thread-id}.
+@var{thread-id}. @var{thread-id} must be a valid thread-id at the
+time the breakpoint is requested. Breakpoints created with a
+@var{thread-id} will automatically be deleted when the corresponding
+thread exits.
@item --qualified
This option makes @value{GDBN} interpret a function name specified as
a complete fully-qualified name.
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index 75957b7..e5432d5 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -243,6 +243,8 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
break;
case THREAD_OPT:
thread = atol (oarg);
+ if (!valid_global_thread_id (thread))
+ error (_("Unknown thread %d."), thread);
break;
case PENDING_OPT:
pending = 1;
diff --git a/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp b/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp
index 4586fa4..9c04d6f 100644
--- a/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp
+++ b/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp
@@ -29,21 +29,63 @@ if [build_executable ${testfile}.exp ${binfile} ${srcfile}] {
return -1
}
-if {[mi_clean_restart $binfile]} {
- return -1
-}
-
-mi_create_breakpoint "-p 1 bar" "thread-specific b/p on bar" \
- -thread "1"
-
proc make_loc {num} {
return [mi_make_breakpoint_loc -thread "1" -number "$::decimal\\.$num"]
}
-set loc1 [make_loc 1]
-set loc2 [make_loc 2]
-set loc3 [make_loc 3]
+foreach_mi_ui_mode mode {
+
+ if {$mode == "separate"} {
+ set start_ops "separate-mi-tty"
+ } else {
+ set start_ops ""
+ }
+
+ if {[mi_clean_restart $binfile $start_ops]} {
+ return -1
+ }
+
+ # Ensure we get an error when placing a b/p for thread 1 at a point
+ # where thread 1 doesn't exist.
+ mi_gdb_test "-break-insert -p 1 bar" \
+ "\\^error,msg=\"Unknown thread 1\\.\""
-mi_create_breakpoint_multi "-p 1 foo" "thread-specific b/p on foo" \
- -thread "1" \
- -locations "\\\[$loc1,$loc2,$loc3\\\]"
+ # If we have a separate CLI UI then run the 'info breakpoints'
+ # command. There was a time when the previous breakpoint request
+ # would succeed, and then 'info breakpoint' on the CLI would
+ # trigger an assertion.
+ if {$mode eq "separate"} {
+ with_spawn_id $gdb_main_spawn_id {
+ gdb_test "info breakpoints" "No breakpoints or watchpoints\\." \
+ "check CLI 'info breakpoints' when there are no breakpoints"
+ }
+ }
+
+ if {[mi_runto_main] == -1} {
+ return -1
+ }
+
+ # Ensure we get an error when placing a b/p for a thread that doesn't
+ # exist (when other threads do exist).
+ mi_gdb_test "-break-insert -p 999 bar" \
+ "\\^error,msg=\"Unknown thread 999\\.\""
+
+ mi_create_breakpoint "-p 1 bar" "thread-specific b/p on bar" \
+ -thread "1"
+
+ set loc1 [make_loc 1]
+ set loc2 [make_loc 2]
+ set loc3 [make_loc 3]
+
+ mi_create_breakpoint_multi "-p 1 foo" "thread-specific b/p on foo" \
+ -thread "1" \
+ -locations "\\\[$loc1,$loc2,$loc3\\\]"
+
+ # Check that 'info breakpoints' on the CLI succeeds.
+ if {$mode eq "separate"} {
+ with_spawn_id $gdb_main_spawn_id {
+ gdb_test "info breakpoints" ".*" \
+ "check CLI 'info breakpoints' when there are some breakpoints"
+ }
+ }
+}