Skip to content

Commit

Permalink
x86_64: Fix the bug of getting incorrect framesize
Browse files Browse the repository at this point in the history
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
   ...
   crash-utility#9  [ffff888263157bc0] copy_process at ffffffff92dadcbd
   crash-utility#10 [ffff888263157d20] __mutex_init at ffffffff92ed8dd5
   crash-utility#11 [ffff888263157d38] __alloc_file at ffffffff93458397
   crash-utility#12 [ffff888263157d60] alloc_empty_file at ffffffff934585d2
   crash-utility#13 [ffff888263157da8] __alloc_fd at ffffffff934b5ead
   crash-utility#14 [ffff888263157e38] _do_fork at ffffffff92dae7a1
   crash-utility#15 [ffff888263157f28] do_syscall_64 at ffffffff92c085f4

Stack crash-utility#10 ~ crash-utility#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
   ...
   crash-utility#9  [ffff888263157bc0] copy_process at ffffffff92dadcbd
   crash-utility#10 [ffff888263157e38] _do_fork at ffffffff92dae7a1
   crash-utility#11 [ffff888263157f28] do_syscall_64 at ffffffff92c085f4

Signed-off-by: Tao Liu <[email protected]>
  • Loading branch information
liutgnu committed Dec 1, 2024
1 parent 0b09602 commit f09550e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
if (!exception) {
framesize = max;
if (CRASHDEBUG(2) || (bt->flags & BT_FRAMESIZE_DEBUG))
Expand Down

0 comments on commit f09550e

Please sign in to comment.