(编辑:根据当前"第三个答案;#34;似乎正在使用Atom处理器。但我希望一些gdb专家可以回答这是否是一个基本限制,或者是否添加支持其他处理器在路线图上?)
反向执行似乎在我的环境中正常工作:我可以反向继续,查看合理的记录日志,并在其中移动:
(gdb) start
...Temporary breakpoint 5 at 0x8048460: file bang.cpp, line 13.
Starting program: /home/thomasg/temp/./bang
Temporary breakpoint 5, main () at bang.cpp:13
13 f(1000);
(gdb) record
(gdb) continue
Continuing.
Breakpoint 3, f (d=900) at bang.cpp:5
5 if(d) {
(gdb) info record
Active record target: record-full
Record mode:
Lowest recorded instruction number is 1.
Highest recorded instruction number is 1005.
Log contains 1005 instructions.
Max logged instructions is 200000.
(gdb) reverse-continue
Continuing.
Breakpoint 3, f (d=901) at bang.cpp:5
5 if(d) {
(gdb) record goto end
Go forward to insn number 1005
#0 f (d=900) at bang.cpp:5
5 if(d) {
然而,指令和功能历史不可用:
(gdb) record instruction-history
You can't do that when your target is `record-full'
(gdb) record function-call-history
You can't do that when your target is `record-full'
唯一可用的目标类型是完整的,另一个记录类型" btrace"失败," Target不支持分支跟踪。"
很可能它只是不支持这个目标,但因为它是主流的现代目标(gdb 7.6.1-ubuntu,amd64 Linux Mint" Petra"运行"英特尔(R)Core(TM)i5-3570")我希望我忽略了关键步骤或配置?
答案 0 :(得分:6)
似乎除了支持它的CPU之外没有其他解决方案。
更准确地说,您的内核必须支持英特尔处理器跟踪(英特尔PT)。可以在Linux中使用以下命令检查:
grep intel_pt /proc/cpuinfo
另请参阅:https://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean
这些命令仅适用于record btrace
模式。
在GDB源代码提交beab5d9
中,nat/linux-btrace.c:kernel_supports_pt
检查我们是否可以输入btrace
。进行以下检查:
/sys/bus/event_source/devices/intel_pt/type
是否存在并阅读type
syscall (SYS_perf_event_open, &attr, child, -1, -1, 0);
执行type
,看看它是否返回>=0
。 TODO:为什么不使用C包装器?第一次检查对我失败:文件不存在。
内核方面
cd进入内核4.1源代码并且:
git grep '"intel_pt"'
我们找到设置该文件的arch/x86/kernel/cpu/perf_event_intel_pt.c
。特别是,它确实:
if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
goto fail;
所以intel_pt
是先决条件。
我如何找到kernel_supports_pt
首先是grep:
git grep 'Target does not support branch tracing.'
引导我们btrace.c:btrace_enable
。经过快速调试后:
gdb -q -ex start -ex 'b btrace_enable' -ex c --args /home/ciro/git/binutils-gdb/install/bin/gdb --batch -ex start -ex 'record btrace' ./hello_world.out
虚拟框也不支持它:Extract execution log from gdb record in a VirtualBox VM
英特尔SDE
Intel SDE 7.21已经有了这个CPU功能,请查看:
./sde64 -- cpuid | grep 'Intel processor trace'
但我不确定是否可以在其上运行Linux内核:https://superuser.com/questions/950992/how-to-run-the-linux-kernel-on-intel-software-development-emulator-sde
其他GDB方法
更通用的问题,软件解决方案效率较低:
答案 1 :(得分:1)
至少部分答案(对于“我做错了”方面) - 来自gdb-7.6.50.20140108/gdb/NEWS
* A new record target "record-btrace" has been added. The new target uses hardware support to record the control-flow of a process. It does not support replaying the execution, but it implements the below new commands for investigating the recorded execution log. This new recording method can be enabled using: record btrace The "record-btrace" target is only available on Intel Atom processors and requires a Linux kernel 2.6.32 or later. * Two new commands have been added for record/replay to give information about the recorded execution without having to replay the execution. The commands are only supported by "record btrace". record instruction-history prints the execution history at instruction granularity record function-call-history prints the execution history at function granularity
我常常羡慕Atom处理器的所有者;-)
我将编辑问题以重新关注解决方案或未来支持计划的问题。