[gdb/cli] Add ignore-errors command While trying to reproduce a failing test-case from the testsuite on the command line using a gdb command script, I ran into the problem that a command failed which stopped script execution. I could work around this by splitting the script at each error, but I realized it would be nice if I could tell gdb to ignore the error. A python workaround ignore-errors exists, mentioned here ( https://sourceware.org/legacy-ml/gdb/2010-06/msg00100.html ). This also mentions a bugzilla entry that adds "exception handling to the gdb command language" but I was not able to find that. This patch adds native ignore-errors support (so no python needed). So with this script: ... $ cat script.gdb ignore-errors run echo here ... we have: ... $ gdb -q -batch -x script.gdb here$ ... We could also implement this as first-class command, like so: ... static void ignore_errors_command (const char *args, int from_tty) { try { execute_command (args, from_tty); } catch (const gdb_exception_error &ex) { async_enable_stdin (); } } ... and: ... add_cmd ("ignore-errors", class_support, ignore_errors_command, source_help_text, &cmdlist); ... but that means we go twice through execute_command. This seems cleaner, at least in that aspect. --- gdb/event-top.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 002a7dc95e0..9d36b550dda 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -583,13 +583,38 @@ command_handler (const char *command) /* Do not execute commented lines. */ for (c = command; *c == ' ' || *c == '\t'; c++) ; - if (c[0] != '#') + if (c[0] == '#') + return; + + /* Detect and skip "ignore-errors". */ + const char * s = "ignore-errors"; + const size_t s_len = strlen (s); + bool ignore_errors_p + = (strncmp (c, s, s_len) == 0 + && strlen (c) > s_len + && (c[s_len] == ' ' || c[s_len] == '\t')); + if (ignore_errors_p) { - execute_command (command, ui->instream == ui->stdin_stream); + c += s_len; + for (; *c == ' ' || *c == '\t'; c++) + ; + } + + try + { + execute_command (c, ui->instream == ui->stdin_stream); /* Do any commands attached to breakpoint we stopped at. */ bpstat_do_actions (); } + catch (const gdb_exception_error &ex) + { + if (!ignore_errors_p) + throw; + + /* See also execute_gdb_command. */ + async_enable_stdin (); + } } /* Append RL, an input line returned by readline or one of its