[Lldb-commits] [PATCH] D64993: Fix PC adjustment in StackFrame::GetSymbolContext

Joseph Tremoulet via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 30 18:27:25 PDT 2019


JosephTremoulet added a comment.

@jasonmolenda @clayborg ping.  To clarify, the issue this fixes is, using test functionalities/signal/handle-abrt as an example:

  #include <signal.h>
  #include <stdio.h>
  #include <stdlib.h>
  
  void handler(int sig)
  {
      printf("Set a breakpoint here.\n");
      exit(0);
  }
  
  void abort_caller() {
      abort();
  }
  
  int main()
  {
      if (signal(SIGABRT, handler) == SIG_ERR)
      {
          perror("signal");
          return 1;
      }
  
      abort_caller();
      return 2;
  }

When stopped at the breakpoint in "handler", backtrace currently gives this:

  (lldb) bt
  * thread #1, name = 'sigtest', stop reason = breakpoint 1.1
    * frame #0: 0x0000000000400651 sigtest`handler(sig=6) at main.c:7
      frame #1: 0x00007ffff7a424b0 libc.so.6`___lldb_unnamed_symbol1$$libc.so.6 + 1    <----- the symbol context of this frame is the issue
      frame #2: 0x00007ffff7a42428 libc.so.6`__GI_raise(sig=6) at raise.c:54
      frame #3: 0x00007ffff7a4402a libc.so.6`__GI_abort at abort.c:89
      frame #4: 0x000000000040066e sigtest`abort_caller() at main.c:12
      frame #5: 0x00000000004006a2 sigtest`main at main.c:23
      frame #6: 0x00007ffff7a2d830 libc.so.6`__libc_start_main(main=(sigtest`main at main.c:16), argc=1, argv=0x00007fffffffe328, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe318) at libc-start.c:291
      frame #7: 0x0000000000400579 sigtest`_start + 41

the pc of frame 1 is actually on the first byte of the relevant function, not following a call:

  (lldb) frame select 1
  frame #1: 0x00007ffff7a424b0 libc.so.6`___lldb_unnamed_symbol1$$libc.so.6 + 1
  libc.so.6`__restore_rt:
  ->  0x7ffff7a424b0 <+0>: movq   $0xf, %rax
      0x7ffff7a424b7 <+7>: syscall 
      0x7ffff7a424b9 <+9>: nopl   (%rax)
  
  libc.so.6`__GI___libc_sigaction:
      0x7ffff7a424c0 <+0>: subq   $0xd0, %rsp
  (lldb) disassemble -s '$pc - 2'
      0x7ffff7a424ae:       addb   %al, (%rax)
  libc.so.6`__restore_rt:
  ->  0x7ffff7a424b0 <+0>:  movq   $0xf, %rax
      0x7ffff7a424b7 <+7>:  syscall 
      0x7ffff7a424b9 <+9>:  nopl   (%rax)
  
  libc.so.6`__GI___libc_sigaction:
      0x7ffff7a424c0 <+0>:  subq   $0xd0, %rsp
      0x7ffff7a424c7 <+7>:  testq  %rsi, %rsi
      0x7ffff7a424ca <+10>: movq   %rdx, %r8

With this fix, we instead get this backtrace:

  (lldb) bt
  * thread #1, name = 'sigtest', stop reason = breakpoint 1.1
    * frame #0: 0x0000000000400651 sigtest`handler(sig=6) at main.c:7
      frame #1: 0x00007ffff7a424b0 libc.so.6`__restore_rt                <-------------- correct symbol context here
      frame #2: 0x00007ffff7a42428 libc.so.6`__GI_raise(sig=6) at raise.c:54
      frame #3: 0x00007ffff7a4402a libc.so.6`__GI_abort at abort.c:89
      frame #4: 0x000000000040066e sigtest`abort_caller() at main.c:12
      frame #5: 0x00000000004006a2 sigtest`main at main.c:23
      frame #6: 0x00007ffff7a2d830 libc.so.6`__libc_start_main(main=(sigtest`main at main.c:16), argc=1, argv=0x00007fffffffe328, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe318) at libc-start.c:291
      frame #7: 0x0000000000400579 sigtest`_start + 41


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64993/new/

https://reviews.llvm.org/D64993





More information about the lldb-commits mailing list