GDB不显示完整的回溯

时间:2017-02-13 00:29:38

标签: c++ gdb chip-8

我正在用C ++编写带有SDL2的CHIP-8解释器。源代码位于https://github.com/robbie0630/Chip8Emu。存在this ROM导致分段错误的问题。我尝试用GDB调试问题,但是当我键入bt时,它显示一个不完整的堆栈跟踪,只显示前两个函数,使我无法有效地诊断问题。如何获得完整且有用的堆栈跟踪?

编辑:当我运行bt时,GDB会显示:

#0  0x0000000101411a14 in ?? ()
#1  0x0000000000406956 in Chip8_CPU::doCycle (this=0x7fffffffc7b0) at /my/home/code/Chip8Emu/src/cpu.cpp:223
#2  0x0000000000402080 in main (argc=2, argv=0x7fffffffe108) at /my/home/code/Chip8Emu/src/main.cpp:152

这是没用的,因为??没有表示任何内容,cpu.cpp的第223行是函数调用。

编辑2:我在程序上运行了valgrind,这是输出:

==11791== Conditional jump or move depends on uninitialised value(s)
==11791==    at 0x406BA0: Chip8_CPU::doCycle() (cpu.cpp:215)
==11791==    by 0x4020EF: main (main.cpp:152)
==11791== 
==11791== Jump to the invalid address stated on the next line
==11791==    at 0x101411A74: ???
==11791==    by 0x4020EF: main (main.cpp:152)
==11791==  Address 0x101411a74 is not stack'd, malloc'd or (recently) free'd
==11791== 
==11791== 
==11791== Process terminating with default action of signal 11 (SIGSEGV)
==11791==  Access not within mapped region at address 0x101411A74
==11791==    at 0x101411A74: ???
==11791==    by 0x4020EF: main (main.cpp:152)
==11791==  If you believe this happened as a result of a stack
==11791==  overflow in your program's main thread (unlikely but
==11791==  possible), you can try to increase the size of the
==11791==  main thread stack using the --main-stacksize= flag.
==11791==  The main thread stack size used in this run was 8388608.
==11791== 
==11791== HEAP SUMMARY:
==11791==     in use at exit: 7,827,602 bytes in 41,498 blocks
==11791==   total heap usage: 169,848 allocs, 128,350 frees, 94,139,303 bytes allocated
==11791== 
==11791== LEAK SUMMARY:
==11791==    definitely lost: 0 bytes in 0 blocks
==11791==    indirectly lost: 0 bytes in 0 blocks
==11791==      possibly lost: 4,056,685 bytes in 36,878 blocks
==11791==    still reachable: 3,770,917 bytes in 4,620 blocks
==11791==         suppressed: 0 bytes in 0 blocks
==11791== Rerun with --leak-check=full to see details of leaked memory
==11791== 
==11791== For counts of detected and suppressed errors, rerun with: -v
==11791== Use --track-origins=yes to see where uninitialised values come from
==11791== ERROR SUMMARY: 12 errors from 3 contexts (suppressed: 0 from 0)
Killed

编辑3:我再次运行GDB,这次看GfxDraw,我注意到这发生了:

Old value = (void (*)(array2d)) 0x1411bc4
New value = (void (*)(array2d)) 0x101411bc4
Chip8_CPU::doCycle (this=0x7fffffffc7a0) at /home/robbie/code/Chip8Emu/src/cpu.cpp:213
(gdb) cont
Continuing.

Thread 1 "Chip8Emu" received signal SIGSEGV, Segmentation fault.
0x0000000101411bc4 in ?? ()

所以某种程度上GfxDraw被修改为无效的函数指针。但是,我无法弄清楚它被修改的位置。

1 个答案:

答案 0 :(得分:0)

几个月后,我终于确定了问题所在。一些讨厌的CHIP-8程序会对图形内存进行非法内存访问,这些访问超出了数组的范围和CPU的损坏属性(例如GfxDraw)。我通过使用at访问图形内存并忽略std::out_of_range错误来解决此问题。它现在似乎有效,所以我宣布它是解决方案。