From: Pedro Alves Date: Wed, 9 Apr 2025 13:29:53 +0000 (+0100) Subject: Fix MI -break-insert assertion failure (submit separately) (WIP) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dcf67f0dae5f8f6cb387e253134d5634c7f0030;p=thirdparty%2Fbinutils-gdb.git Fix MI -break-insert assertion failure (submit separately) (WIP) TODO: - commit log - testcase This is exposed by some pre-existing test. Need to check which one it was. (gdb) interpreter-exec mi "222-break-insert -g i100 foo" &"../../src/gdb/breakpoint.c:9165: internal-error: find_program_space_for_breakpoint: Assertion `inf != nullptr' failed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable." &"\n" &"----- Backtrace -----\n" &"Backtrace unavailable\n" &"---------------------\n" ~"../../src/gdb/breakpoint.c:9165: internal-error: find_program_space_for_breakpoint: Assertion `inf != nullptr' failed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable.\nQuit this debugging session? (y or n) " From here: (top-gdb) bt #0 internal_error_loc (file=0x555556187e56 "../../src/gdb/breakpoint.c", line=9165, fmt=0x555556187bc8 "%s: Assertion `%s' failed.") at ../../src/gdbsupport/errors.cc:53 #1 0x0000555555791a55 in find_program_space_for_breakpoint (thread=-1, inferior=100) at ../../src/gdb/breakpoint.c:9165 #2 0x0000555555791f96 in create_breakpoint (gdbarch=0x5555568db900, locspec=0x5555567e7100, cond_string=0x0, thread=-1, inferior=100, extra_string=0x0, force_condition=false, parse_extra=0, tempflag=0, type_wanted=bp_breakpoint, ignore_count=0, pending_break_support=AUTO_BOOLEAN_FALSE, ops=0x555556642aa0 , from_tty=0, enabled=1, internal=0, flags=0) at ../../src/gdb/breakpoint.c:9275 #3 0x0000555555bb9d15 in mi_cmd_break_insert_1 (dprintf=0, command=0x5555567e6fd0 "break-insert", argv=0x5555567e7070, argc=3) at ../../src/gdb/mi/mi-cmd-break.c:366 #4 0x0000555555bb9e15 in mi_cmd_break_insert (command=0x5555567e6fd0 "break-insert", argv=0x5555567e7070, argc=3) at ../../src/gdb/mi/mi-cmd-break.c:383 ... Change-Id: Ibde0d4d098bf0b5d7b057e818a77a63c84806a3c --- diff --git a/gdb/inferior.c b/gdb/inferior.c index e8a28cd2a0e..29d1aee8974 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -397,6 +397,15 @@ find_inferior_id (int num) return NULL; } +/* See inferior.h. */ + +bool +valid_inferior_id (int num) +{ + inferior *inf = find_inferior_id (num); + return inf != nullptr; +} + struct inferior * find_inferior_pid (process_stratum_target *targ, int pid) { diff --git a/gdb/inferior.h b/gdb/inferior.h index 301a78f9ebb..71c7642286f 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -730,6 +730,9 @@ extern struct inferior *find_inferior_ptid (process_stratum_target *targ, /* Search function to lookup an inferior by GDB 'num'. */ extern struct inferior *find_inferior_id (int num); +/* Return true if inferior NUM exists, false otherwise. */ +extern bool valid_inferior_id (int num); + /* Find an inferior bound to PSPACE, giving preference to the current inferior. */ extern struct inferior * diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index e4cb2e7d335..0e17b45ddfa 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -30,6 +30,7 @@ #include "linespec.h" #include #include "tracepoint.h" +#include "inferior.h" enum { @@ -249,6 +250,8 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, break; case THREAD_GROUP_OPT: thread_group = mi_parse_thread_group_id (oarg); + if (!valid_inferior_id (thread_group)) + error (_("Non-existent thread-group id '%d'"), thread_group); break; case PENDING_OPT: pending = 1;