From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Tom de Vries <tdevries@suse.de>
Cc: Marco Barisione <mbarisione@undo.io>, Tom Tromey <tom@tromey.com>,
GDB patches mailing list <gdb-patches@sourceware.org>
Subject: Re: [RFC][gdb/cli] Ignore error in gdb command script
Date: Tue, 18 May 2021 15:23:46 +0100 [thread overview]
Message-ID: <20210518142346.GS3067949@embecosm.com> (raw)
In-Reply-To: <eac69a98-953d-2458-8db1-9ebdafd4cbae@suse.de>
* Tom de Vries <tdevries@suse.de> [2021-05-18 15:57:42 +0200]:
> On 5/18/21 1:12 PM, Marco Barisione wrote:
> > On 18 May 2021, at 10:59, Tom de Vries <tdevries@suse.de> wrote:
> >> Hi,
> >>
> >> 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.
> >>
> >> Inspired by make, I chose the '-' prefix.
> >
> > As MI commands are prefixed by “-“, isn’t there a risk of confusion?
> >
>
> Ah, right, I tend to forget about MI, good point.
>
> > There’s also a “-” command (see tui/tui-win.c) which will stop working with
> > your patch.
>
> I see, that's:
> ...
> $ gdb -q -batch -ex "help -"
> Scroll window backward.
> Usage: - [N] [WIN]
> Scroll window WIN N lines backwards. Both WIN and N are optional, N
> defaults to 1, and WIN defaults to the currently focused window.
> ...
>
> FWIW, did not find any documentation for this command.
>
> Anyway, the '-' prefix seems a poor choice.
>
> I've updated the patch to implement the ignore-errors idiom natively (so
> it also works without python).
>
> Also, I've managed to fix the hang, by copying some code from
> execute_gdb_command.
>
> Thanks,
> - Tom
>
> [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.
The benefit of implementing as a first class command is that we can
also get command completion on the second-level command. See, for
example, the existing "with" command, so I can do:
(gdb) with prin<TAB>
and get:
(gdb) with print
It would be great it we got this for ignore-errors too.
Thanks,
Andrew
>
> ---
> 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
prev parent reply other threads:[~2021-05-18 14:23 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
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 [this message]
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=20210518142346.GS3067949@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=mbarisione@undo.io \
--cc=tdevries@suse.de \
--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).