[PATCHv2,1/9] gdb: create_breakpoint: assert for a valid thread-id

Message ID b532e0fde2bfeceee4d094fe6c1351251c0d9b4a.1684178710.git.aburgess@redhat.com
State New
Series thread-specific breakpoints in just some inferiors |

Commit Message

Andrew Burgess May 15, 2023, 7:27 p.m. UTC
  Add an assert into create_breakpoint (breakpoint.c) that the thread
argument is a valid thread-id; either a value greater than zero, or -1
to indicate any thread.

The thread is ignored if parse_extra is true though, so take that into
account too.

There should be no user visible changes after this commit.
 gdb/breakpoint.c | 4 ++++
 gdb/breakpoint.h | 6 ++++++
 2 files changed, 10 insertions(+)


diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fdb184ae81f..31448e0a895 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9027,6 +9027,10 @@  create_breakpoint (struct gdbarch *gdbarch,
   gdb_assert (ops != NULL);
+  /* If PARSE_EXTRA is true then the thread-id will be parsed from
+     EXTRA_STRING, otherwise, ensure THREAD is valid.  */
+  gdb_assert (parse_extra || thread == -1 || thread > 0);
   /* If extra_string isn't useful, set it to NULL.  */
   if (extra_string != NULL && *extra_string == '\0')
     extra_string = NULL;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 7c5cf3f2bef..e57dc2523fb 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1530,6 +1530,12 @@  enum breakpoint_create_flags
    the FORCE_CONDITION parameter is ignored and the corresponding argument
    is parsed from EXTRA_STRING.
+   The THREAD should be a global thread number, the created breakpoint will
+   only apply for that thread.  If the breakpoint should apply for all
+   threads then pass -1.  However, if PARSE_EXTRA is non-zero then the
+   THREAD parameter is ignored and an optional thread number will be parsed
+   from EXTRA_STRING.
    If INTERNAL is non-zero, the breakpoint number will be allocated
    from the internal breakpoint count.