1. (EDIT: per the first answer below the current "trick" seems to be using an Atom processor.
    But I hope some gdb guru can answer if this is a fundamental limitation, or whether there adding support for other processors is on the roadmap?)
  2.  
  3. Reverse execution seems to be working in my environment: I can reverse-continue, see a plausible record log, and move around within it:
  4.  
  5. (gdb) start
  6. ...Temporary breakpoint at 0x8048460: file bang.cpp, line .
  7. Starting program: /home/thomasg/temp/./bang
  8.  
  9. Temporary breakpoint , main () at bang.cpp:
  10. f();
  11. (gdb) record
  12. (gdb) continue
  13. Continuing.
  14.  
  15. Breakpoint , f (d=) at bang.cpp:
  16. if(d) {
  17. (gdb) info record
  18. Active record target: record-full
  19. Record mode:
  20. Lowest recorded instruction number is .
  21. Highest recorded instruction number is .
  22. Log contains instructions.
  23. Max logged instructions is .
  24. (gdb) reverse-continue
  25. Continuing.
  26.  
  27. Breakpoint , f (d=) at bang.cpp:
  28. if(d) {
  29. (gdb) record goto end
  30. Go forward to insn number
  31. # f (d=) at bang.cpp:
  32. if(d) {
  33. However the instruction and function histories aren't available:
  34.  
  35. (gdb) record instruction-history
  36. You can't do that when your target is `record-full'
  37. (gdb) record function-call-history
  38. You can't do that when your target is `record-full'
  39. And the only target type available is full, the other documented type "btrace" fails with "Target does not support branch tracing."
  40.  
  41. So quite possibly it just isn't supported for this target, but as it's a mainstream modern one
    (gdb 7.6.-ubuntu, on amd64 Linux Mint "Petra" running an "Intel(R) Core(TM) i5-3570") I'm hoping that I've overlooked a crucial step or config?
  1. t seems that there is no other solution except a CPU that supports it.
  2.  
  3. More precisely, your kernel has to support Intel Processor Tracing (Intel PT). This can be checked in Linux with:
  4.  
  5. grep intel_pt /proc/cpuinfo
  6. See also: http://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean
  7.  
  8. The commands only works in record btrace mode.
  9.  
  10. In the GDB source commit beab5d9, it is nat/linux-btrace.c:kernel_supports_pt that checks if we can enter btrace. The following checks are carried out:
  11.  
  12. check if /sys/bus/event_source/devices/intel_pt/type exists and read the type
  13. do a syscall (SYS_perf_event_open, &attr, child, -, -, ); with the read type, and see if it returns >=. TODO: why not use the C wrapper?
  14. The first check fails for me: the file does not exist.
  15.  
  16. Kernel side
  17.  
  18. cd into the kernel 4.1 source and:
  19.  
  20. git grep '"intel_pt"'
  21. we find arch/x86/kernel/cpu/perf_event_intel_pt.c which sets up that file. In particular, it does:
  22.  
  23. if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
  24. goto fail;
  25. so intel_pt is a pre-requisite.
  26.  
  27. How I've found kernel_supports_pt
  28.  
  29. First grep for:
  30.  
  31. git grep 'Target does not support branch tracing.'
  32. which leads us to btrace.c:btrace_enable. After a quick debug with:
  33.  
  34. 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
  35. Virtual box does not support it either: Extract execution log from gdb record in a VirtualBox VM
  36.  
  37. Intel SDE
  38.  
  39. Intel SDE 7.21 already has this CPU feature, checked with:
  40.  
  41. ./sde64 -- cpuid | grep 'Intel processor trace'
  42. But I'm not sure if the Linux kernel can be run on it:
    http://superuser.com/questions/950992/how-to-run-the-linux-kernel-on-intel-software-development-emulator-sde
  43.  
  44. Other GDB methods
  45.  
  46. See: gdb - list of all function calls made in an application
  1. At least a partial answer (for the "am I doing it wrong" aspect) - from gdb-7.6.50.20140108/gdb/NEWS
  2.  
  3. * A new record target "record-btrace" has been added. The new target
  4. uses hardware support to record the control-flow of a process. It
  5. does not support replaying the execution, but it implements the
  6. below new commands for investigating the recorded execution log.
  7. This new recording method can be enabled using:
  8.  
  9. record btrace
  10.  
  11. The "record-btrace" target is only available on Intel Atom processors
  12. and requires a Linux kernel 2.6. or later.
  13.  
  14. * Two new commands have been added for record/replay to give information
  15. about the recorded execution without having to replay the execution.
  16. The commands are only supported by "record btrace".
  17.  
  18. record instruction-history prints the execution history at
  19. instruction granularity
  20.  
  21. record function-call-history prints the execution history at
  22. function granularity
  23. It's not often that I envy the owner of an Atom processor ;-)
  24.  
  25. I'll edit the question to refocus upon the question of workarounds or plans for future support.

在GDB 中如何记录 instruction-history and function-call-history的更多相关文章

  1. 新手如何在gdb中存活

    网络上已经有很多gdb调试的文章了,为什么我还要写这篇文章呢,因为本文是写给gdb新手的,目的就是通过一个简单的例子来让新手很快上手.一旦上手入门了,其他的问题就可以自己去搜索搞定了.右边是gdb的L ...

  2. GDB中汇编调试

    GDB中汇编调试 1.输入代码 2.使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,时遇到问题使用-m32指令报错,参考卢肖明同学博客知道这是 ...

  3. history 清空历史记录 或 history不记录历史命令

    # vi ~/.bash_history 清空里面的记录,并退出当前shell # exit(一定要退出当前shell) # history 1 vi ~/.bash_history 2 histor ...

  4. MYSQL操作数据表中的记录

    36:操作数据表中的记录插入记录   INSERT INTO 表名  VALUES();   或者INSERT 表名  VALUES();  UPDATE更新记录(单表更新)  DELETE删除记录( ...

  5. GDB中应该知道的几个调试方法 来自陈皓

    GDB中应该知道的几个调试方法 2011年2月10日陈皓发表评论阅读评论62,325 人阅读   七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询 ...

  6. Oracle数据库中有关记录个数的查询

    一.查询表中全部的记录个数 可用两种方法,一种是在oracle的系统表中统计,另一种需要写存储过程统计,方法分别如下. 1.系统表中统计: SELECT sum(num_rows) FROM user ...

  7. GDB中应该知道的几个调试方法

    七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询问我关于GDB的问题,一直到今天,还有人在问GDB的相关问题.这么多年来,有一些问题是大家反复在问 ...

  8. 《转》GDB中应该知道的几个调试方法

    原文:http://coolshell.cn/articles/3643.html 七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询问我关于GDB ...

  9. 【转贴】gdb中的信号(signal)相关调试技巧

    一篇不错的帖子,讲的是gdb中的信号(signal)相关调试技巧 转自Magic C++论坛  http://www.magicunix.com/index_ch.html  http://www.m ...

随机推荐

  1. SOSEx ReadMe

    Quick Ref:--------------------------------------------------bhi [filename] BuildHeapIndex - Builds a ...

  2. MyEclipse10

    1.配置tomcat Windows->Preferences->My Eclipse->Servers->Tomcat,对于64位操作系统而言,Tomcat home dir ...

  3. 单元测试unit test,集成测试integration test和功能测试functional test的区别

    以下内容转自 https://codeutopia.net/blog/2015/04/11/what-are-unit-testing-integration-testing-and-function ...

  4. 完全卸载mysql 停止服务、卸载相关程序、删除注册表

    本节主要介绍了完全卸载mysql的具体步骤包括停止服务.卸载相关程序.删除注册表等等   1. 停止服务MySQL 2. 卸载mysql相关的程序 3. 删除注册表(运行->regedit),m ...

  5. bzoj 1045: [HAOI2008] 糖果传递 贪心

    1045: [HAOI2008] 糖果传递 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1812  Solved: 846[Submit][Stat ...

  6. 【andorid】Attribute is missing the Android namespac

    初学安卓,错误颇多 出现这个问题,是因为xml节点属性单词拼写错了,比如android我写成了adnorid,当然就错误了.

  7. Gradle在大型Java项目上的应用

    在Java构建工具的世界里,先有了Ant,然后有了Maven.Maven的CoC[1].依赖管理以及项目构建规则重用性等特点,让Maven几乎成为Java构建工具的事实标准.然而,冗余的依赖管理配置. ...

  8. IndexedDB

    http://www.tfan.org/indexeddb/ http://fnvfox.appspot.com/thankyou.html http://www.tfan.org/wechat-on ...

  9. jsp分页技术

    1.以下为分页类: import java.io.Serializable;  import java.util.List;    import org.apache.commons.lang.bui ...

  10. C++ Virtual详解(注意函数被隐藏的问题)

    Virtual是C++ OO机制中很重要的一个关键字.只要是学过C++的人都知道在类Base中加了Virtual关键字的函数就是虚拟函数(例如函数print),于是在Base的派生类Derived中就 ...