public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Handle dprintf argument evaluation errors better (PR gdb/16551)
Date: Thu, 23 Aug 2018 09:44:00 -0000	[thread overview]
Message-ID: <18c7ed55-b7e7-680c-2112-a16bc070240b@redhat.com> (raw)
In-Reply-To: <1528920116-26170-1-git-send-email-simon.marchi@ericsson.com>

On 06/13/2018 09:01 PM, Simon Marchi wrote:
> The current behavior when GDB fails to evaluate the arguments of a
> dynamic printf is not very good.
> 
> There was a previous attempt at fixing this here, but it did not went
> through:
>   https://sourceware.org/ml/gdb-patches/2015-02/msg00258.html
> 
> The issue can be reproduced by setting a dprintf referring to a variable
> that doesn't exist or that triggers a memory error:
> 
>   dprintf hello, "hello %d\n", *((int*)0)
>   dprintf hello, "hello %d\n", doesnt_exist
> 
> When an evaluation error occurs, an error is thrown at the stack trace
> shown below and is caught in start_event_loop.  This leaves things in a
> relatively bad shape:
> 
> - Printing the error in start_event_loop causes GDB to receive a SIGTTOU
>   signal, because the terminal is still owned by the inferior at that
>   point.
> - There is an error message (e.g. No symbol "foo" in current context)
>   and you are back to the GDB prompt, but nothing gives a clue about the
>   context of the error.
> - The thread that hit the dprintf is stopped.  If in all-stop mode on an
>   all-stop-on-top-of-non-stop target, you end up with a single thread
>   stopped and the others running, which is not good.
> - With MI, the thread(s) is/are stopped but no *stopped event is sent,
>   so frontends still show it as running.
> 
> I actually think it is nice that the program stops if there is an
> error, so you can notice the problem and fix it.  It just needs to be
> handled better.  

I'm not so sure about that.  Consider a dprintf like this:

  int *some_int_global;

  dprintf funct, "some_int_global: %d\n", *some_int_global

and during most of the run, some_int_global points somewhere
valid (or some more complex expression involving pointers,
like a->b->c->d, you get the idea).  However, at some point, maybe
after days of a long running hard-to-collect-data debug session,
the pointer points to NULL or to garbage.

If I understood correctly, that makes the dprintf stop the thread.
That doesn't seem desirable to me.

Also, if that dprintf is handled on the target side, then GDB is
not notified of the error either, and no thread stops, right?

It would seem to me better, in terms of the spirit of the
command (non-intrusive dynamic logging), to catch the error,
print something like "<error: xxxxx>" and let the thread/program
run.

Thanks,
Pedro Alves

      parent reply	other threads:[~2018-08-23  9:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-13 20:02 Simon Marchi
2018-06-27 14:32 ` Simon Marchi
2018-08-23  0:03   ` Simon Marchi
2018-08-23  2:42     ` Eli Zaretskii
2018-08-23  9:44 ` Pedro Alves [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=18c7ed55-b7e7-680c-2112-a16bc070240b@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.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).