On Mon, Sep 16, 2024 at 3:46 PM <devel-requ...@lists.crash-utility.osci.io>
wrote:

> Date: Mon, 16 Sep 2024 19:44:58 +1200
> From: Tao Liu <l...@redhat.com>
> Subject: [Crash-utility] [PATCH] x86_64: Fix the bug of getting
>         incorrect framesize
> To: devel@lists.crash-utility.osci.io
> Cc: mycomplexl...@gmail.com
> Message-ID: <20240916074458.105832-1-l...@redhat.com>
> Content-Type: text/plain; charset="US-ASCII"; x-default=true
>
> Previously, "retq" is used to determine the end of a function, so the end
> of framesize calculation. However "ret" might be outputted by gdb rather
> than "retq", as a result, the framesize is returned incorrectly, and bogus
> stack trace will be outputted.
>
> Without the patch:
>
>    $ crash -d 3 vmcore vmlinux
>    crash> bt
>    0xffffffff92da7545 <copy_process+5>: push   %rbp     [framesize: 8]
>    ...
>    0xffffffff92da7561 <copy_process+33>:        sub    $0x238,%rsp
> [framesize: 624]
>    ...
>    0xffffffff92da776a <copy_process+554>:       pop    %r15
>  [framesize: 8]
>    0xffffffff92da776c <copy_process+556>:       pop    %rbp
>  [framesize: 0]
>    0xffffffff92da776d <copy_process+557>:       ret
>
>    crash> bt -D dump
>    framesize_cache_entries:
>       ...
>       [  3]: ffffffff92dadcbd 0 CF (copy_process+26493)
>
>    crash> bt
>    ...
>    #9  [ffff888263157bc0] copy_process at ffffffff92dadcbd
>    #10 [ffff888263157d20] __mutex_init at ffffffff92ed8dd5
>    #11 [ffff888263157d38] __alloc_file at ffffffff93458397
>    #12 [ffff888263157d60] alloc_empty_file at ffffffff934585d2
>    #13 [ffff888263157da8] __alloc_fd at ffffffff934b5ead
>    #14 [ffff888263157e38] _do_fork at ffffffff92dae7a1
>    #15 [ffff888263157f28] do_syscall_64 at ffffffff92c085f4
>
> Stack #10 ~ #13 are bogus and misleading.
>
> With the patch:
>    ...
>    0xffffffff92da776d <copy_process+557>:       ret     [framesize
> restored to: 624]
>
>    crash> bt -D dump
>       ...
>       [  3]: ffffffff92dadcbd 624 CF (copy_process+26493)
>
>    crash> bt
>    ...
>    #9  [ffff888263157bc0] copy_process at ffffffff92dadcbd
>    #10 [ffff888263157e38] _do_fork at ffffffff92dae7a1
>    #11 [ffff888263157f28] do_syscall_64 at ffffffff92c085f4
>
> Signed-off-by: Tao Liu <l...@redhat.com>
> ---
>  x86_64.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/x86_64.c b/x86_64.c
> index 469d26b..7aa9430 100644
> --- a/x86_64.c
> +++ b/x86_64.c
> @@ -8781,7 +8781,8 @@ x86_64_get_framesize(struct bt_info *bt, ulong
> textaddr, ulong rsp, char *stack_
>                         if (CRASHDEBUG(2) || (bt->flags &
> BT_FRAMESIZE_DEBUG))
>                                 fprintf(fp, "%s\t[framesize: %d]\n",
>                                         strip_linefeeds(buf2), framesize);
> -               } else if (STRNEQ(arglist[instr], "retq")) {
> +               } else if (STRNEQ(arglist[instr], "retq") ||
> +                          STRNEQ(arglist[instr], "ret")) {
>

Thank you for the fix, Tao.

This looks good.  Applied:
https://github.com/crash-utility/crash/commit/0d2ad774532db3c4dad6cda05d51db74d0e3fa86


Lianbo

                        if (!exception) {
>                                 framesize = max;
>                                 if (CRASHDEBUG(2) || (bt->flags &
> BT_FRAMESIZE_DEBUG))
> --
> 2.40.1
>
--
Crash-utility mailing list -- devel@lists.crash-utility.osci.io
To unsubscribe send an email to devel-le...@lists.crash-utility.osci.io
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

Reply via email to