Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GDB不显示完全回溯 我用C++编写了一个用C++编写的CIP-8解释器。源代码位于。有一个问题,它得到了一个分段错误。我试图用GDB调试这个问题,但当我键入bt时,它会显示一个不完整的堆栈跟踪,只显示前两个函数,使我无法有效地诊断问题。如何获得完整且有用的堆栈跟踪_C++_Gdb_Chip 8 - Fatal编程技术网

GDB不显示完全回溯 我用C++编写了一个用C++编写的CIP-8解释器。源代码位于。有一个问题,它得到了一个分段错误。我试图用GDB调试这个问题,但当我键入bt时,它会显示一个不完整的堆栈跟踪,只显示前两个函数,使我无法有效地诊断问题。如何获得完整且有用的堆栈跟踪

GDB不显示完全回溯 我用C++编写了一个用C++编写的CIP-8解释器。源代码位于。有一个问题,它得到了一个分段错误。我试图用GDB调试这个问题,但当我键入bt时,它会显示一个不完整的堆栈跟踪,只显示前两个函数,使我无法有效地诊断问题。如何获得完整且有用的堆栈跟踪,c++,gdb,chip-8,C++,Gdb,Chip 8,编辑:当我运行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/

编辑:当我运行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
被修改为无效的函数指针。但是,我不知道它在哪里被修改。

几个月后,我终于发现了问题。一些令人讨厌的CHIP-8程序对图形内存进行非法内存访问,这些访问超出了阵列的界限,并损坏了CPU的属性(例如
GfxDraw
)。我通过使用
at
访问图形内存并忽略
std::out\u of_range
错误,解决了这个问题。现在它似乎可以工作了,所以我宣布它是解决方案。

您介意给我们看一个GDB输出的复制粘贴(作为文本)吗?顶部框架中的
表示堆栈问题。您可能有一些缓冲区溢出,导致未定义的行为和堆栈崩溃。使用调试器一步一步地检查代码,并使用内存调试器来帮助您找到问题的根源。@Someprogrammerdude我不知道该如何处理。在cpu.cpp中的第223行,您有一个对
DrawGfx
的调用,该调用未显示在调用堆栈中,因此问题可能就在那里。在该调用上设置断点,并逐步执行
DrawGfx
函数可能会有所帮助。但如果你真的尝试使用Valgrind,它会准确地告诉你在什么时候、什么地方对内存做了不好的事情。@Someprogrammerdude我按照你的要求运行了Valgrind,并在中编辑了输出。