public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Luis Machado <luis.machado@arm.com>, gdb-patches@sourceware.org
Cc: Bruno Larsen <blarsen@redhat.com>, Andrew Burgess <aburgess@redhat.com>
Subject: Re: [PATCH 3/4] [gdb/tdep, aarch64] Fix frame address of last insn in leaf function
Date: Mon, 23 Jan 2023 12:59:50 +0100	[thread overview]
Message-ID: <88c66a57-e69e-bd9f-7407-3b71fa9c6630@suse.de> (raw)
In-Reply-To: <bc99f6a8-9165-2ffd-6dce-a798c10cb003@arm.com>

On 1/23/23 11:07, Luis Machado wrote:
> On 1/19/23 10:46, Tom de Vries wrote:
>> Consider the test-case test.c, compiled without debug info:
>> ...
>> void
>> foo (const char *s)
>> {
>> }
>>
>> int
>> main (void)
>> {
>>    foo ("foo");
>>    return 0;
>> }
>> ...
>>
>> Disassembly of foo:
>> ...
>> 0000000000400564 <foo>:
>>    400564:       d10043ff        sub     sp, sp, #0x10
>>    400568:       f90007e0        str     x0, [sp, #8]
>>    40056c:       d503201f        nop
>>    400570:       910043ff        add     sp, sp, #0x10
>>    400574:       d65f03c0        ret
>> ...
>>
>> Now, let's do "info frame" at each insn in foo, as well as printing $sp
>> and $x29 (and strip the output of info frame to the first line, for 
>> brevity):
>> ...
>> $ gdb -q a.out
>> Reading symbols from a.out...
>> (gdb) b *foo
>> Breakpoint 1 at 0x400564
>> (gdb) r
>> Starting program: a.out
>>
>> Breakpoint 1, 0x0000000000400564 in foo ()
>> (gdb) display /x $sp
>> 1: /x $sp = 0xfffffffff3a0
>> (gdb) display /x $x29
>> 2: /x $x29 = 0xfffffffff3a0
>> (gdb) info frame
>> Stack level 0, frame at 0xfffffffff3a0:
>> (gdb) si
>> 0x0000000000400568 in foo ()
>> 1: /x $sp = 0xfffffffff390
>> 2: /x $x29 = 0xfffffffff3a0
>> (gdb) info frame
>> Stack level 0, frame at 0xfffffffff3a0:
>> (gdb) si
>> 0x000000000040056c in foo ()
>> 1: /x $sp = 0xfffffffff390
>> 2: /x $x29 = 0xfffffffff3a0
>> (gdb) info frame
>> Stack level 0, frame at 0xfffffffff3a0:
>> (gdb) si
>> 0x0000000000400570 in foo ()
>> 1: /x $sp = 0xfffffffff390
>> 2: /x $x29 = 0xfffffffff3a0
>> (gdb) info frame
>> Stack level 0, frame at 0xfffffffff3a0:
>> (gdb) si
>> 0x0000000000400574 in foo ()
>> 1: /x $sp = 0xfffffffff3a0
>> 2: /x $x29 = 0xfffffffff3a0
>> (gdb) info frame
>> Stack level 0, frame at 0xfffffffff3b0:
>>   pc = 0x400574 in foo; saved pc = 0x40058c
>> (gdb) si
>> 0x000000000040058c in main ()
>> 1: /x $sp = 0xfffffffff3a0
>> 2: /x $x29 = 0xfffffffff3a0
>> ...
>>
>> The "frame at" bit lists 0xfffffffff3a0 except at the last insn, where it
>> lists 0xfffffffff3b0.
>>
>> The frame address is calculated here in aarch64_make_prologue_cache_1:
>> ...
>>    unwound_fp = get_frame_register_unsigned (this_frame, 
>> cache->framereg);
>>    if (unwound_fp == 0)
>>      return;
>>
>>    cache->prev_sp = unwound_fp + cache->framesize;
>> ...
>>
>> For insns after the prologue, we have cache->framereg == sp and
>> cache->framesize == 16, so unwound_fp + cache->framesize gives the wrong
>> answer once sp has been restored to entry value by the before-last insn.
>>
>> Fix this by detecting the situation that the sp has been restored.
>>
>> This fixes PR tdep/30011.
>>
>> This also fixes the aarch64 FAILs in gdb.reverse/solib-precsave.exp and
>> gdb.reverse/solib-reverse.exp I reported in PR gdb/PR29721.
> 
> I still see failures for gdb.reverse/solib-precsave.exp and 
> gdb.reverse/solib-reverse.exp for both Ubuntu 22.04 and 20.04
> on aarch64-linux.
> 
> Running 
> /work/luimac01/work/builds/binutils-gdb-arm64-jammy/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.reverse/solib-prec
> save.exp ...
> FAIL: gdb.reverse/solib-precsave.exp: reverse-step into solib function one
> FAIL: gdb.reverse/solib-precsave.exp: reverse-step within solib function 
> one
> FAIL: gdb.reverse/solib-precsave.exp: reverse-step back to main one
> FAIL: gdb.reverse/solib-precsave.exp: reverse-step into solib function two
> FAIL: gdb.reverse/solib-precsave.exp: reverse-step within solib function 
> two
> 
> Running 
> /work/luimac01/work/builds/binutils-gdb-arm64-jammy/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.reverse/solib-reve
> rse.exp ...
> FAIL: gdb.reverse/solib-reverse.exp: reverse-step into solib function one
> FAIL: gdb.reverse/solib-reverse.exp: reverse-step within solib function one
> FAIL: gdb.reverse/solib-reverse.exp: reverse-step back to main one
> FAIL: gdb.reverse/solib-reverse.exp: reverse-step into solib function two
> FAIL: gdb.reverse/solib-reverse.exp: reverse-step within solib function two
> 
> Maybe it addresses a different issue, but what I'm seeing is possibly 
> something else (the linetable issue? I vaguely recall the situation for 
> that).
>>

Hi,

that is very well possible.  I'm not claiming to fix the test-case on 
aarch64 in general, I'm very specifically claiming to fix the FAILs I 
reported in a PR.

BTW the first FAIL in the PR is also different than the one you report 
above, which is usually a hint that there may be a different root cause.

I'll commit (using an updated commit message claiming both PRs 
tdep/30010 and tdep/30011) once I do another round of testing.

Thanks,
- Tom

>> Tested on aarch64-linux.
>> PR tdep/30011
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30011
>> ---
>>   gdb/aarch64-tdep.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
>> index b576d3b9d99..06349353716 100644
>> --- a/gdb/aarch64-tdep.c
>> +++ b/gdb/aarch64-tdep.c
>> @@ -996,7 +996,11 @@ aarch64_make_prologue_cache_1 (frame_info_ptr 
>> this_frame,
>>     if (unwound_fp == 0)
>>       return;
>> -  cache->prev_sp = unwound_fp + cache->framesize;
>> +  if (cache->framereg == AARCH64_SP_REGNUM
>> +      && get_frame_register_unsigned (this_frame, AARCH64_FP_REGNUM) 
>> == unwound_fp)
>> +    cache->prev_sp = unwound_fp;
>> +  else
>> +    cache->prev_sp = unwound_fp + cache->framesize;
>>     /* Calculate actual addresses of saved registers using offsets
>>        determined by aarch64_analyze_prologue.  */
> 

  reply	other threads:[~2023-01-23 11:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19 10:46 [PATCH 0/4] [gdb] Test-case gdb.base/unwind-on-each-insn.exp improvements Tom de Vries
2023-01-19 10:46 ` [PATCH 1/4] [gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.exp Tom de Vries
2023-01-23  9:36   ` Tom de Vries
2023-01-19 10:46 ` [PATCH 2/4] [gdb/testsuite] Improve gdb.base/unwind-on-each-insn.exp Tom de Vries
2023-01-23  9:55   ` Luis Machado
2023-01-19 10:46 ` [PATCH 3/4] [gdb/tdep, aarch64] Fix frame address of last insn in leaf function Tom de Vries
2023-01-20 10:25   ` Tom de Vries
2023-01-23 10:07   ` Luis Machado
2023-01-23 11:59     ` Tom de Vries [this message]
2023-01-23 12:09       ` Luis Machado
2023-01-19 10:46 ` [PATCH 4/4] [gdb/testsuite] Analyze non-leaf fn in gdb.base/unwind-on-each-insn.exp Tom de Vries
2023-01-23 10:18   ` Luis Machado
2023-01-25 12:32 ` [PATCH 0/4] [gdb] Test-case gdb.base/unwind-on-each-insn.exp improvements Tom de Vries

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=88c66a57-e69e-bd9f-7407-3b71fa9c6630@suse.de \
    --to=tdevries@suse.de \
    --cc=aburgess@redhat.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.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).