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

Andrew Burgess via Gdb-patches
2023-04-28T23:37:10Z

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 46287da5f87..e6940bc9671 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9026,6 +9026,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.

--
2.25.4