代码之家  ›  专栏  ›  技术社区  ›  Ruslan PiotrNycz

有没有什么不可知的方法可以获取SIGTRAP上的指令指针?

  •  3
  • Ruslan PiotrNycz  · 技术社区  · 7 年前

    ptrace 示踪剂。

    依赖于拱门的方法是使用 PTRACE_GETREGS EIP 在i386上, RIP PC 手臂等。。

    我试过使用 siginfo.si_addr 以及 siginfo.si_ptr 从…起 PTRACE_GETSIGINFO

    在Linux中,我还尝试使用 /proc/<pid>/task/<tid>/stat fs/proc/array.c:do_task_stat() KSTK_EIP(task) (尽管被命名为以x86为中心,但它似乎是为许多其他架构定义的)。但由于某种原因,在我的ARMv6 Linux 4.9.28+(Raspbian 8)上,程序计数器和堆栈指针都为零。

    那么,是否有任何独立于arch的方法来确定POSIX定义的当前/下一个地址,或者至少在Linux中可用?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Mark Segal    7 年前

    你可以使用 /proc/[pid]/syscall

    mark@ubuntu:~$ gdb python
    ...
    ...
    ... 
    Program received signal SIGINT, Interrupt.
    0x00007ffff78ed573 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:84
    84  ../sysdeps/unix/syscall-template.S: No such file or directory.
    (gdb) 
    
    mark@ubuntu:~/$ ps aux | grep python
    mark      77858  0.2  0.7  90216 37780 pts/2    S+   15:13   0:00 gdb python
    mark      77860  0.0  0.1  38416  6424 pts/2    t    15:13   0:00 /usr/bin/python
    

    77860 被跟踪- t

    mark@ubuntu:~/$ sudo cat /proc/77860/syscall
    23 0x1 0x7fffffffd980 0x0 0x0 0x0 0x7ffff7fdb700 0x7fffffffd958 0x7ffff78ed573
    

    0x7fffffffd958 sp 0x7ffff78ed573 是程序计数器。

    我找不到 ptrace

    http://man7.org/linux/man-pages/man5/proc.5.html

       /proc/[pid]/syscall (since Linux 2.6.27)
              This file exposes the system call number and argument regis‐
              ters for the system call currently being executed by the
              process, followed by the values of the stack pointer and pro‐
              gram counter registers.  The values of all six argument regis‐
              ters are exposed, although most system calls use fewer regis‐
              ters.
    
              If the process is blocked, but not in a system call, then the
              file displays -1 in place of the system call number, followed
              by just the values of the stack pointer and program counter.
              If process is not blocked, then the file contains just the
              string "running".