From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>,
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFC][gdb/cli] Ignore error in gdb command script
Date: Tue, 18 May 2021 17:16:11 +0200 [thread overview]
Message-ID: <b2e233ef-c508-842b-1476-23c5ca098abf@suse.de> (raw)
In-Reply-To: <87im3g14ss.fsf@tromey.com>
[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]
On 5/18/21 4:42 PM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Simon> That sounds useful. I think that "ignore-errors" is a good initial
> Simon> name, because it's clear and self-describing. We can always find and
> Simon> add a short alias later.
>
> Fedora has shipped a Python implementation of exactly this for a while now.
> So, +1 for this name and approach from me.
>
> One question is whether it should catch 'quit'. I tend to think not but
> it should be considered.
>
> There is some other prior art too:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=8487
>
> ignore-errors covers all the uses I've ever wanted personally, though,
> so I think it would be fine to just go with that. However if someone is
> feeling more maximal, try-catch would also be an ok addition.
[ Thanks all for the feedback. Replying to latest email, CC-ing Andrew. ]
Changes:
- now a proper command
- added error reporting
- added completion
- mention try-catch patch
- mention pre-existing implementation on distros
- mention quit behaviour.
I'm doing a build & reg-test now.
Thanks,
- Tom
[-- Attachment #2: 0001-gdb-cli-Add-ignore-errors-command.patch --]
[-- Type: text/x-patch, Size: 3159 bytes --]
[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 ), which is
already supplied by distros like Fedora and openSUSE.
FTR, a more elaborate try-catch solution was posted here (
https://sourceware.org/bugzilla/show_bug.cgi?id=8487 ).
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
No executable file specified.
Use the "file" or "exec-file" command.
here$
...
Note that quit is not caught:
...
$ gdb.sh -q
(gdb) ignore-errors quit
$
...
which is the same behaviour as with the python implementation.
gdb/ChangeLog:
2021-05-18 Tom de Vries <tdevries@suse.de>
* cli/cli-cmds.c (ignore_errors_command_completer)
(ignore_errors_command): New function.
(_initialize_cli_cmds): Add "ignore-errors" cmd.
---
gdb/cli/cli-cmds.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 0bf418e510e..c2c3ee49eb3 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -39,6 +39,7 @@
#include "gdbsupport/filestuff.h"
#include "location.h"
#include "block.h"
+#include "event-top.h"
#include "ui-out.h"
#include "interps.h"
@@ -2249,6 +2250,34 @@ gdb_maint_setting_str_internal_fn (struct gdbarch *gdbarch,
gdbarch);
}
+/* Completer for "ignore-errors". */
+
+static void
+ignore_errors_command_completer (cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char * /*word*/)
+{
+ complete_nested_command_line (tracker, text);
+}
+
+/* Implementation of the ignore-errors command. */
+
+static void
+ignore_errors_command (const char *args, int from_tty)
+{
+ try
+ {
+ execute_command (args, from_tty);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ exception_print (gdb_stderr, ex);
+
+ /* See also execute_gdb_command. */
+ async_enable_stdin ();
+ }
+}
+
void _initialize_cli_cmds ();
void
_initialize_cli_cmds ()
@@ -2618,4 +2647,12 @@ when GDB is started."), GDBINIT);
c = add_cmd ("source", class_support, source_command,
source_help_text, &cmdlist);
set_cmd_completer (c, filename_completer);
+
+ const char *ignore_errors_help_text
+ = ("Execute a single command, ignoring all errors.\n"
+ "Only one-line commands are supported.\n"
+ "This is primarily useful in scripts.");
+ c = add_cmd ("ignore-errors", class_support, ignore_errors_command,
+ ignore_errors_help_text, &cmdlist);
+ set_cmd_completer (c, ignore_errors_command_completer);
}
next prev parent reply other threads:[~2021-05-18 15:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 9:59 Tom de Vries
2021-05-18 11:12 ` Marco Barisione
2021-05-18 13:57 ` Tom de Vries
2021-05-18 14:10 ` Simon Marchi
2021-05-18 14:42 ` Tom Tromey
2021-05-18 15:16 ` Tom de Vries [this message]
2021-05-18 15:32 ` Tom Tromey
2021-05-19 6:25 ` [PATCH][gdb/cli] Add ignore-errors command Tom de Vries
2021-05-19 7:32 ` Andreas Schwab
2021-05-19 7:36 ` Tom de Vries
2021-05-18 19:16 ` [RFC][gdb/cli] Ignore error in gdb command script Philippe Waroquiers
2021-05-18 21:59 ` Tom de Vries
2021-05-20 8:02 ` Philippe Waroquiers
2021-05-20 15:01 ` Simon Marchi
2021-05-18 14:23 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b2e233ef-c508-842b-1476-23c5ca098abf@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).