Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@igalia.com>
To: Doug Evans <xdje42@gmail.com>
Cc: gdb-patches <gdb-patches@sourceware.org>,
	 Alexander Smundak <asmundak@google.com>,
	 Pedro Alves <palves@redhat.com>
Subject: Re: Frame sniffers in Python/Guile/*
Date: Mon, 09 Mar 2015 08:27:00 -0000	[thread overview]
Message-ID: <87d24itw2y.fsf@igalia.com> (raw)
In-Reply-To: <m3ioebz27y.fsf@sspiff.org> (Doug Evans's message of "Sun, 08 Mar	2015 13:03:13 -0700")

On Sun 08 Mar 2015 21:03, Doug Evans <xdje42@gmail.com> writes:

> Andy Wingo <wingo@igalia.com> writes:
>> [...]
>>
>> And so on.  From what I can tell, all of this is because there is no
>> selected frame.  I recognize that this situation reflects reality in
>> some way -- we're still building the selected frame -- but is there any
>> way that we could have GDB be in a more "normal" state while the unwind
>> callback is running?
>
> I think one gets into trouble if one tries to
> apply the word "normal" to gdb. :-)

:-)

> I don't have any simple suggestions. Maybe others will.
> A lot of times improving/fixing gdb requires first
> improving/fixing several other parts first.
> Welcome to gdb. :-)

Hehe OK :)

In this case I came up with what can only be considered a hack, but one
which does solve the issue for me.  The root of the issue is described
in another mail, which I quote:

  1. The Guile unwinder's sniffer is called on the innermost frame.
     That sniffer calls out to Guile.

  2. Many actions, for example looking up a symbol without specifying a
     block. will request the selected frame.

  3. get_selected_frame() sees there is no selected frame, and goes to
     get_current_frame() and will select that.

  4. get_current_frame creates a sentinel frame and unwinds that to
     produce the innermost frame.

  5. After unwinding saved registers from the sentinel, frame.c finishes
     constructing the innermost frame by doing a compute_frame_id() on
     the frame.

  6. compute_frame_id() goes to compute the unwinder for the innermost
     frame, in order to call the this_id() method, which leads us back to
     the beginning.

  http://article.gmane.org/gmane.comp.gdb.patches/105431

The same thing could happen in python on the innermost frame.  My
terrible solution is somewhat hidden in this patch:

  http://article.gmane.org/gmane.comp.gdb.patches/105473

The idea is that frame_unwind_find_by_frame detects recursion and
signals an error, at least for the innermost frame.  (Actually, it
should probably error on recursion for any frame; unwinding is
iterative, not recursive.)

Then get_prev_frame uses the frame_unwind_is_unwinding_innermost_frame()
interface to avoid re-unwinding the sentinel frame, and instead returns
NULL.  Terrible, right?  But it does cause get_current_frame to the
sentinel frame, allowing get_selected_frame() to succeed, which is at
least useful to get the current architecture.  Yuck!

What does the nice solution look like here?  The situation is, no
selected frame, we're unwinding the innermost frame, then via
Guile/Python/etc something indirectly calls get_selected_frame() in
order to get some data from the frame, like the architecture.  Do we
change all of these to use get_selected_frame_if_set, then fall back to
get_current_frame_or_sentinel() ?

Andy


  reply	other threads:[~2015-03-09  8:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 13:28 Andy Wingo
2015-03-08 20:04 ` Doug Evans
2015-03-09  8:27   ` Andy Wingo [this message]
2015-03-09 15:39 ` Pedro Alves
2015-03-09 19:19   ` Andy Wingo
2015-03-10 16:36     ` Pedro Alves
2015-03-10 17:36       ` Andy Wingo

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=87d24itw2y.fsf@igalia.com \
    --to=wingo@igalia.com \
    --cc=asmundak@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=xdje42@gmail.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