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

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

Commit Message

Andrew Burgess May 30, 2023, 8:46 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 a94277f0c6c..fe92893863d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9000,6 +9000,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 709d27fa4db..331c908ecbc 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1589,6 +1589,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.