* [patch/rfa] allow unwinding "past main" for dummy frames
@ 2004-12-06 3:31 Randolph Chung
2004-12-06 3:45 ` Daniel Jacobowitz
0 siblings, 1 reply; 9+ messages in thread
From: Randolph Chung @ 2004-12-06 3:31 UTC (permalink / raw)
To: gdb-patches
On hpux, we push a small bit of code on the stack to implement function
calls from gdb. The stack trampoline contains a return address that
points back to the current function. this is needed to properly restore
the space registers (see hppa_hpux_push_dummy_code in hppa-hpux-tdep.c
for a much more detailed explanation). The upshot of all of this is
that when we do a backtrace from a gdb-called function, a backtrace can
be prematurely truncated at a dummy frame. Since it doesn't make sense
anyway to stop unwinding at dummy frames, this patch skips the "main
function" detection logic for dummy frames. The same logic is already
there for checking against the entry function a bit farther down in
get_prev_frame ().
ok?
randolph
2004-12-05 Randolph Chung <tausq@debian.org>
* frame.c (get_prev_frame): Don't terminate unwinding at main if we
are unwinding through a dummy frame.
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.195
diff -u -p -r1.195 frame.c
--- frame.c 10 Nov 2004 23:26:33 -0000 1.195
+++ frame.c 6 Dec 2004 03:19:46 -0000
@@ -1200,6 +1200,7 @@ get_prev_frame (struct frame_info *this_
gdb_assert (this_frame != NULL);
if (this_frame->level >= 0
+ && get_frame_type (this_frame) != DUMMY_FRAME
&& !backtrace_past_main
&& inside_main_func (this_frame))
/* Don't unwind past main(). Note, this is done _before_ the
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 3:31 [patch/rfa] allow unwinding "past main" for dummy frames Randolph Chung
@ 2004-12-06 3:45 ` Daniel Jacobowitz
2004-12-06 4:27 ` Randolph Chung
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2004-12-06 3:45 UTC (permalink / raw)
To: Randolph Chung; +Cc: gdb-patches
On Sun, Dec 05, 2004 at 07:27:26PM -0800, Randolph Chung wrote:
> On hpux, we push a small bit of code on the stack to implement function
> calls from gdb. The stack trampoline contains a return address that
> points back to the current function. this is needed to properly restore
> the space registers (see hppa_hpux_push_dummy_code in hppa-hpux-tdep.c
> for a much more detailed explanation). The upshot of all of this is
> that when we do a backtrace from a gdb-called function, a backtrace can
> be prematurely truncated at a dummy frame. Since it doesn't make sense
> anyway to stop unwinding at dummy frames, this patch skips the "main
> function" detection logic for dummy frames. The same logic is already
> there for checking against the entry function a bit farther down in
> get_prev_frame ().
>
> ok?
Could you explain to me how inside_main_func is returning true for a
dummy frame?
The code is there for inside_entry_func because we used to use the
actual entry point as a location for the dummy frame.
--
Daniel Jacobowitz
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 3:45 ` Daniel Jacobowitz
@ 2004-12-06 4:27 ` Randolph Chung
2004-12-06 4:59 ` Daniel Jacobowitz
0 siblings, 1 reply; 9+ messages in thread
From: Randolph Chung @ 2004-12-06 4:27 UTC (permalink / raw)
To: gdb-patches
> Could you explain to me how inside_main_func is returning true for a
> dummy frame?
>
> The code is there for inside_entry_func because we used to use the
> actual entry point as a location for the dummy frame.
it's very twisted :)
this is what it says in hppa-hpux-tdep.c:
On HPUX, functions in the main executable and in libraries can be located
in different spaces. In order for us to be able to select the right
space for the function call, we need to go through an instruction seqeunce
to select the right space for the target function, call it, and then
restore the space on return.
There are two helper routines that can be used for this task -- if
an application is linked with gcc, it will contain a __gcc_plt_call
helper function. __gcc_plt_call, when passed the entry point of an
import stub, will do the necessary space setting/restoration for the
target function.
so, in a function called by gdb, we have the following frames on the
stack:
#0 callee
#1 __gcc_plt_call
#2 <dummy frame>
#3 current function when user called "callee" from gdb (main in this case)
so, what happens is that we call __gcc_plt_call using a stack trampoline
which tells __gcc_plt_call to return to "current function". after
__gcc_plt_call calls the callee function, it looks up the return address
("current function") and restores the space registers to the correct
value for that address. ergo, <dummy frame> actually has a frame pc that
belongs to "current function", and if that's main, dummy frame will
trigger the inside_main_func check.
does this make sense?
randolph
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 4:27 ` Randolph Chung
@ 2004-12-06 4:59 ` Daniel Jacobowitz
2004-12-06 6:22 ` Randolph Chung
2004-12-06 14:11 ` Randolph Chung
0 siblings, 2 replies; 9+ messages in thread
From: Daniel Jacobowitz @ 2004-12-06 4:59 UTC (permalink / raw)
To: Randolph Chung; +Cc: gdb-patches
On Sun, Dec 05, 2004 at 08:14:58PM -0800, Randolph Chung wrote:
> so, what happens is that we call __gcc_plt_call using a stack trampoline
> which tells __gcc_plt_call to return to "current function". after
> __gcc_plt_call calls the callee function, it looks up the return address
> ("current function") and restores the space registers to the correct
> value for that address. ergo, <dummy frame> actually has a frame pc that
> belongs to "current function", and if that's main, dummy frame will
> trigger the inside_main_func check.
>
> does this make sense?
Some sense, but not good sense.
Can we edit the space registers ourselves? If so, why don't we rely on
that? I'm not talking about the call, just the return. So generate a
call to __gcc_plt_call with a return address anywhere you please, and
after the dummy call when we restore the saved regcache the space
registers will be right again. So you could just use _start.
--
Daniel Jacobowitz
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 4:59 ` Daniel Jacobowitz
@ 2004-12-06 6:22 ` Randolph Chung
2004-12-06 15:35 ` Daniel Jacobowitz
2004-12-06 14:11 ` Randolph Chung
1 sibling, 1 reply; 9+ messages in thread
From: Randolph Chung @ 2004-12-06 6:22 UTC (permalink / raw)
To: gdb-patches
> Some sense, but not good sense.
>
> Can we edit the space registers ourselves? If so, why don't we rely on
> that? I'm not talking about the call, just the return. So generate a
> call to __gcc_plt_call with a return address anywhere you please, and
> after the dummy call when we restore the saved regcache the space
> registers will be right again. So you could just use _start.
the problem is precisely that ... the register that we need to restore
(pcsqh/pcsqt) cannot be written to by gdb :(
randolph
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 4:59 ` Daniel Jacobowitz
2004-12-06 6:22 ` Randolph Chung
@ 2004-12-06 14:11 ` Randolph Chung
1 sibling, 0 replies; 9+ messages in thread
From: Randolph Chung @ 2004-12-06 14:11 UTC (permalink / raw)
To: gdb-patches
> Can we edit the space registers ourselves? If so, why don't we rely on
> that? I'm not talking about the call, just the return. So generate a
> call to __gcc_plt_call with a return address anywhere you please, and
> after the dummy call when we restore the saved regcache the space
> registers will be right again. So you could just use _start.
i can rewrite the stack trampoline so that we don't need to change
frame.c, i think. i'll give that a try tomorrow if you think that's a
better way to go; but i think making us not stop unwinding at dummy
frames, wherever they point, seems reasonable too...
randolph
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 6:22 ` Randolph Chung
@ 2004-12-06 15:35 ` Daniel Jacobowitz
2004-12-06 16:54 ` Randolph Chung
2004-12-08 3:27 ` Randolph Chung
0 siblings, 2 replies; 9+ messages in thread
From: Daniel Jacobowitz @ 2004-12-06 15:35 UTC (permalink / raw)
To: Randolph Chung; +Cc: gdb-patches
On Sun, Dec 05, 2004 at 08:59:33PM -0800, Randolph Chung wrote:
> > Some sense, but not good sense.
> >
> > Can we edit the space registers ourselves? If so, why don't we rely on
> > that? I'm not talking about the call, just the return. So generate a
> > call to __gcc_plt_call with a return address anywhere you please, and
> > after the dummy call when we restore the saved regcache the space
> > registers will be right again. So you could just use _start.
>
> the problem is precisely that ... the register that we need to restore
> (pcsqh/pcsqt) cannot be written to by gdb :(
"can not" is a funny thing. Can it be written by userspace? If so,
you could synthesize an update onto the stack and execute that, but I
agree that's unnecessarily messy.
Patch is OK, but definitely needs a comment. And the comment should
mention HP/UX specifically.
--
Daniel Jacobowitz
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 15:35 ` Daniel Jacobowitz
@ 2004-12-06 16:54 ` Randolph Chung
2004-12-08 3:27 ` Randolph Chung
1 sibling, 0 replies; 9+ messages in thread
From: Randolph Chung @ 2004-12-06 16:54 UTC (permalink / raw)
To: gdb-patches
> "can not" is a funny thing. Can it be written by userspace? If so,
> you could synthesize an update onto the stack and execute that, but I
> agree that's unnecessarily messy.
it can be written only indirectly, but doing a branch to the destination
space (i.e. branch(space, some address) will set pcsqh to space)
> Patch is OK, but definitely needs a comment. And the comment should
> mention HP/UX specifically.
ok, will do.
randolph
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch/rfa] allow unwinding "past main" for dummy frames
2004-12-06 15:35 ` Daniel Jacobowitz
2004-12-06 16:54 ` Randolph Chung
@ 2004-12-08 3:27 ` Randolph Chung
1 sibling, 0 replies; 9+ messages in thread
From: Randolph Chung @ 2004-12-08 3:27 UTC (permalink / raw)
To: gdb-patches
> Patch is OK, but definitely needs a comment. And the comment should
> mention HP/UX specifically.
i've checked this in:
2004-12-07 Randolph Chung <tausq@debian.org>
* frame.c (get_prev_frame): Don't terminate unwinding at main if we
are unwinding through a dummy frame.
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.195
diff -u -p -r1.195 frame.c
--- frame.c 10 Nov 2004 23:26:33 -0000 1.195
+++ frame.c 8 Dec 2004 01:54:47 -0000
@@ -1199,7 +1199,18 @@ get_prev_frame (struct frame_info *this_
get_current_frame(). */
gdb_assert (this_frame != NULL);
+ /* tausq/2004-12-07: Dummy frames are skipped because it doesn't make much
+ sense to stop unwinding at a dummy frame. One place where a dummy
+ frame may have an address "inside_main_func" is on HPUX. On HPUX, the
+ pcsqh register (space register for the instruction at the head of the
+ instruction queue) cannot be written directly; the only way to set it
+ is to branch to code that is in the target space. In order to implement
+ frame dummies on HPUX, the called function is made to jump back to where
+ the inferior was when the user function was called. If gdb was inside
+ the main function when we created the dummy frame, the dummy frame will
+ point inside the main function. */
if (this_frame->level >= 0
+ && get_frame_type (this_frame) != DUMMY_FRAME
&& !backtrace_past_main
&& inside_main_func (this_frame))
/* Don't unwind past main(). Note, this is done _before_ the
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-12-08 1:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-06 3:31 [patch/rfa] allow unwinding "past main" for dummy frames Randolph Chung
2004-12-06 3:45 ` Daniel Jacobowitz
2004-12-06 4:27 ` Randolph Chung
2004-12-06 4:59 ` Daniel Jacobowitz
2004-12-06 6:22 ` Randolph Chung
2004-12-06 15:35 ` Daniel Jacobowitz
2004-12-06 16:54 ` Randolph Chung
2004-12-08 3:27 ` Randolph Chung
2004-12-06 14:11 ` Randolph Chung
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox