Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Ulrich Weigand <uweigand@de.ibm.com>
Cc: gdb-patches@sourceware.org
Subject: entryval tail call frames $sp adjustment vs. gdbarches  [Re: New ARI warning Thu Oct 13 01:55:36 UTC 2011]
Date: Thu, 13 Oct 2011 21:15:00 -0000	[thread overview]
Message-ID: <20111013211526.GA5377@host1.jankratochvil.net> (raw)
In-Reply-To: <201110131459.p9DExbK9013317@d06av02.portsmouth.uk.ibm.com>

On Thu, 13 Oct 2011 16:59:37 +0200, Ulrich Weigand wrote:
> Generic code is not supposed to make the assumption that there *is*
> a single "sp" (or "pc") register;

The current code does everything in a "best effort" mode.  If anything fails
$sp in tail call frames is just not adjusted - it should not be such a problem.
So far I would set such behavior for all gdbarches anyway (*).

(*) I guess the correct approach is to set it only for gdbarches where one
    verifies it is correct.  Still if the code succeeds I believe the result is
    always correct - so what is the point of gdbarch in such case?


> For DWARF frames specifically, the convention is that ->stack_addr will
> equal the CFA.  So if you are in DWARF-specific code, and need the CFA,
> you can make use of that convention; but the best way to do that would
> probably be to call dwarf2_frame_cfa instead of get_frame_base.

I see now dwarf2_frame_cfa is more appropriate by its name.  The detection
code is based on CFA (CFA_REG_OFFSET, regs.cfa_reg etc.).
And dwarf2_frame_cfa in such case effectively just calls get_frame_base.

Unless you advice me differently I will change it this way.


> Note however, that even the CFA is not automatically equal to some "value
> of a SP register"; for example, on s390(x), the CFA is always biased by 96
> (or 160) bytes against the SP at function entry ...

On s390x the adjustment code in dwarf2_tailcall_prev_register_first (detected
inside dwarf2_frame_cache, from .debug_frame) gets into effect but in fact it
does not change the $sp value.  Which is correct, as "brasl" does not modify
$sp.


> I'm afraid I'm not sure exactly what all this SP manipulation code is intended
> to achieve; could you elaborate (or is there documentation somewhere that I
> missed)?

I dd not think it needs to be documented in the manual as it just simulates
the expected state of inferior.

In the x86_64 sample code below when we unwind function `f' the register set
there should be already the unwound one - the same like in the function
`main'.  `f' just stands on the jmp instruction so it does not have any its
own register state to unwind.

Just there is the exception $sp - in function `f' the value of $sp should not
be the same like in the function `main' as there is the return address there.
The two lines `XXX' - the real register state should match the later unwound
register state.


Thanks,
Jan


x86_64:

static __attribute__ ((noinline, noclone)) void g (void) { asm volatile (""); }
static __attribute__ ((noinline, noclone)) void f (void) { g (); }
int main (void) { f (); return 0; }

gcchead-root/bin/gcc -o tailcall4 tailcall4.c -Wall -g -O2

gdb -nx -x ~/.gdbinit ./tailcall4 -ex 'set disassemble-next-line on'  -ex start

3	int main (void) { f (); return 0; }
=> 0x0000000000400360 <main+0>:	e8 ab 00 00 00	callq  0x400410 <f>
   0x0000000000400365 <main+5>:	31 c0	xor    %eax,%eax
   0x0000000000400367 <main+7>:	c3	retq   
(gdb) display/x $sp
1: /x $sp = 0x7fffffffdb08
(gdb) stepi
f () at tailcall4.c:2
2	static __attribute__ ((noinline, noclone)) void f (void) { g (); }
=> 0x0000000000400410 <f+0>:	eb ee	jmp    0x400400 <g>
1: /x $sp = 0x7fffffffdb00
XXX         ^^^^^^^^^^^^^^
(gdb) stepi
g () at tailcall4.c:1
1	static __attribute__ ((noinline, noclone)) void g (void) { asm volatile (""); }
=> 0x0000000000400400 <g+0>:	c3	retq   
   0x0000000000400401:	66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00	data32 data32 data32 data32 data32 nopw %cs:0x0(%rax,%rax,1)
1: /x $sp = 0x7fffffffdb00
(gdb) bt
#0  g () at tailcall4.c:1
#1  0x0000000000400412 in f () at tailcall4.c:2
#2  0x0000000000400365 in main () at tailcall4.c:3
(gdb) up
#1  0x0000000000400412 in f () at tailcall4.c:2
2	static __attribute__ ((noinline, noclone)) void f (void) { g (); }
   0x0000000000400410 <f+0>:	eb ee	jmp    0x400400 <g>
(gdb) p/x $sp
$1 = 0x7fffffffdb00
XXX  ^^^^^^^^^^^^^^
(gdb) up
#2  0x0000000000400365 in main () at tailcall4.c:3
3	int main (void) { f (); return 0; }
   0x0000000000400360 <main+0>:	e8 ab 00 00 00	callq  0x400410 <f>
=> 0x0000000000400365 <main+5>:	31 c0	xor    %eax,%eax
   0x0000000000400367 <main+7>:	c3	retq   
(gdb) p/x $sp
$2 = 0x7fffffffdb08


  reply	other threads:[~2011-10-13 21:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-13  1:55 New ARI warning Thu Oct 13 01:55:36 UTC 2011 GDB Administrator
2011-10-13 13:54 ` Jan Kratochvil
2011-10-13 15:00   ` Ulrich Weigand
2011-10-13 21:15     ` Jan Kratochvil [this message]
2011-10-19 16:05       ` entryval tail call frames $sp adjustment vs. gdbarches [Re: New ARI warning Thu Oct 13 01:55:36 UTC 2011] Ulrich Weigand
2011-10-21  0:34         ` Jan Kratochvil
2011-10-21  0:45         ` Jan Kratochvil

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=20111013211526.GA5377@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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