GDB 不会在没有 step-mode=on 的情况下单步执行函数

Posted

技术标签:

【中文标题】GDB 不会在没有 step-mode=on 的情况下单步执行函数【英文标题】:GDB does not step-into functions without step-mode=on 【发布时间】:2017-09-07 09:55:55 【问题描述】:

我有一个与.so 文件动态链接的可执行文件,两者都使用调试符号编译。

现在,当我使用 gdb 启动进程并跳过它时 - step 命令不会进入函数(在 .so 中定义),除非我设置了 step-mode on

资源是可用的,gdb 肯定可以找到它们。

为什么会这样?

这是通过set debug infrun 1启用的相应调试输出:

34          assert_se(calendar_spec_from_string(input, &c) >= 0);
infrun: infrun_async(0)
(gdb) s
infrun: clear_proceed_status_thread (Thread 0x7ffff7fb3900 (LWP 7009))
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: proceed: resuming Thread 0x7ffff7fb3900 (LWP 7009)
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e0d
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e11
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e11
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e15
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e15
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e18
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e18
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e1b
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e1b
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000c08
infrun: stepped into subroutine
infrun: inserting step-resume breakpoint at 0x100000e20
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000c08
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e20
infrun: BPSTAT_WHAT_STEP_RESUME
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e20
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e23
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e23
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e26
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e26
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e29
infrun: stepping inside range [0x100000e0d-0x100000e4f]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e29
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e4f
infrun: stepped to a different line
infrun: stop_waiting
infrun: clear_step_over_info
infrun: stop_all_threads
infrun: stop_all_threads, pass=0, iterations=0
infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing
infrun: stop_all_threads, pass=1, iterations=1
infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing
infrun: stop_all_threads done
36          assert_se(calendar_spec_to_string(c, &p) >= 0);
infrun: infrun_async(0)
(gdb) s
infrun: clear_proceed_status_thread (Thread 0x7ffff7fb3900 (LWP 7009))
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: proceed: resuming Thread 0x7ffff7fb3900 (LWP 7009)
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e4f
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e53
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e53
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e57
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e57
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e5a
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e5a
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e5d
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e5d
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000c48
infrun: stepped into subroutine
infrun: inserting step-resume breakpoint at 0x100000e62
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000c48
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e62
infrun: BPSTAT_WHAT_STEP_RESUME
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e62
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e65
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e65
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e68
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e68
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e6b
infrun: stepping inside range [0x100000e4f-0x100000e91]
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fb3900 (LWP 7009)] at 0x100000e6b
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   7009.7009.0 [Thread 0x7ffff7fb3900 (LWP 7009)],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x100000e91
infrun: stepped to a different line
infrun: stop_waiting
infrun: clear_step_over_info
infrun: stop_all_threads
infrun: stop_all_threads, pass=0, iterations=0
infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing
infrun: stop_all_threads, pass=1, iterations=1
infrun:   Thread 0x7ffff7fb3900 (LWP 7009) not executing
infrun: stop_all_threads done
37          printf("\"%s\" → \"%s\"\n", input, p);
infrun: infrun_async(0)

【问题讨论】:

@Gaurav Pathak: nm --debug-syms 返回调试符号。 那么可能有问题。任何退伍军人都可以提供帮助。 @GauravPathak 是的,我不会问这是否微不足道 ????:-) gdb --versiongcc --version 的输出可能会有所帮助。 set debug infrun 1 的输出也是如此。 您的.gdbinit 文件中有什么内容? 【参考方案1】:

似乎与链接器的“-Wl,-z,now”选项有关。

手册页说:

现在 - 在生成可执行文件或共享库时,标记它以告诉动态链接器在程序启动时解析所有符号,或者在使用 dlopen 链接到共享库时,而不是将函数调用分辨率推迟到函数第一次调用时。

当您设置step-mode on 并调试与此选项链接的可执行文件时,您可能会注意到您并没有直接进入共享库中的函数,而是首先进入类似的地方

(gdb) s
0x0000555555554638 in ?? ()

不能确切地说,它是什么。

【讨论】:

奖励赏金,因为没有更好的候选人 :-) 谢谢)但如果有帮助,你什么也没说。您是否尝试关闭 -Wl,-z,now 标志? 它是一个相当复杂的构建系统的一部分(它是一个systemd 项目)我不确定在这一点上我可能会花时间弄清楚如何在数千个中更改编译标志-line 构建配置 :-)

以上是关于GDB 不会在没有 step-mode=on 的情况下单步执行函数的主要内容,如果未能解决你的问题,请参考以下文章

mdb与gdb转化会不会影响图形

GDB:断点没有被命中

gdb 使用

GDB 防止错误

GDB 不会在断点处停止并继续

当我从 Docker 容器中运行 gdb 时,它没有遇到任何断点