【问题标题】:How to set earliest possible breakpoint如何设置最早的断点
【发布时间】:2014-04-24 16:09:13
【问题描述】:

我试图在模块加载到 gdb 后立即停止。假设二进制完全去掉了所有符号信息,所以没有main。

理想情况下,我会在入口点设置断点,但这个想法由于重定位而失效:

(gdb) info target
Symbols from "./application".
Local exec file:
    `./application', file type elf64-x86-64.
    Entry point: 0xc154
...
(gdb) break *0xc154
Breakpoint 1 at 0xc154
(gdb) r
Starting program: ./application 
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0xc154: Input/output error.

(gdb) info target
Symbols from "./application".
Unix child process:
    Using the running image of child process 22835.
    While running this, GDB does not access memory from...
Local exec file:
    `./application', file type elf64-x86-64.
    Entry point: 0x555555560154

即使这种方法有效(我可以在新地址上设置一个新断点并禁用原始地址),它也不能通过 gdb 脚本/批处理模式轻松执行,因为它中间有一条失败的指令。

有没有办法做到这一点?理想情况下,像“运行单指令”而不是“运行”这样的东西会很有用。

【问题讨论】:

    标签: gdb breakpoints


    【解决方案1】:

    更新:

    GDB-8.1 实现了starti 命令,这使得这很容易。


    入口点:0xc154

    这是一个动态链接的、与位置无关的 (PIE) 二进制文件。

    您希望在该二进制文件加载并重定位之后,但在它执行任何操作之前停止动态链接器。

    (gdb) set stop-on-solib-events 1
    (gdb) run
    Starting program: /tmp/a.out 
    Stopped due to shared library event (no libraries added or removed)
    (gdb) info target
    Symbols from "/tmp/a.out".
    Unix child process:
            Using the running image of child process 13746.
            While running this, GDB does not access memory from...
    Local exec file:
            `/tmp/a.out', file type elf64-x86-64.
            Entry point: 0x5555555545f0
            ...
    
    (gdb) bt
    #0  __GI__dl_debug_state () at dl-debug.c:77
    #1  0x00007ffff7ddd488 in dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=0x7ffff7ffe870) at rtld.c:1678
    #2  0x00007ffff7defb24 in _dl_sysdep_start (start_argptr=<optimized out>, dl_main=0x7ffff7ddc6e0 <dl_main>) at ../elf/dl-sysdep.c:244
    #3  0x00007ffff7ddf365 in _dl_start_final (arg=0x7fffffffe440) at rtld.c:338
    #4  _dl_start (arg=0x7fffffffe440) at rtld.c:564
    #5  0x00007ffff7ddb6b8 in _start () from /lib64/ld-linux-x86-64.so.2
    

    【讨论】:

    • 完美,正是我所需要的
    • 这不适用于与位置无关的可执行文件。
    • @ZachRiggle 上面的答案包含为 PIE二进制文件收集的GDB命令的痕迹,它显然确实工作。如果它不适合你,也许你有旧的/错误的 GDB,或者没有使用 GLIBC,或者......
    • 对不起,你是对的。我的意思是说这不适用于 静态链接 与位置无关的可执行文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 2015-12-28
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    相关资源
    最近更新 更多