GDB回溯没有显示正确的信息

时间:2017-10-06 13:59:57

标签: c++ debugging gdb

我正在学习如何在我的mac上使用gdb进行调试,在找到分段错误后我想用它来学习。 我正在使用自制的gdb 8.0.1和gcc 7.2.0,我正在使用-ggdb进行编译,并通过Error: (SystemJS) Unexpected value 'undefined' exported by the module 'PlunkerMaterialModule' Error: Unexpected value 'undefined' exported by the module 'PlunkerMaterialModule' at d (https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.7.2/zone.min.js:1:10303) at syntaxError (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:1729:34) at eval (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15596:40) at Array.forEach (<anonymous>) at CompileMetadataResolver.getNgModuleMetadata (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15594:49) at CompileMetadataResolver.getNgModuleSummary (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15507:52) at eval (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15580:72) at Array.forEach (<anonymous>) at CompileMetadataResolver.getNgModuleMetadata (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15565:49) at JitCompiler._loadModules (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:27000:70) at JitCompiler._compileModuleAndComponents (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:26973:36) at JitCompiler.compileModuleAsync (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:26902:37) at PlatformRef_._bootstrapModuleWithZone (https://unpkg.com/@angular/core/bundles/core.umd.js:4568:25) at PlatformRef_.bootstrapModule (https://unpkg.com/@angular/core/bundles/core.umd.js:4554:21) at execute (https://run.plnkr.co/preview/cj8fyb96l00063c5srholji8p/main.ts!transpiled:108:65) Error loading https://run.plnkr.co/preview/cj8fyb96l00063c5srholji8p/main.ts at d (https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.7.2/zone.min.js:1:10303) at syntaxError (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:1729:34) at eval (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15596:40) at Array.forEach (<anonymous>) at CompileMetadataResolver.getNgModuleMetadata (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15594:49) at CompileMetadataResolver.getNgModuleSummary (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15507:52) at eval (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15580:72) at Array.forEach (<anonymous>) at CompileMetadataResolver.getNgModuleMetadata (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:15565:49) at JitCompiler._loadModules (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:27000:70) at JitCompiler._compileModuleAndComponents (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:26973:36) at JitCompiler.compileModuleAsync (https://unpkg.com/@angular/compiler/bundles/compiler.umd.js:26902:37) at PlatformRef_._bootstrapModuleWithZone (https://unpkg.com/@angular/core/bundles/core.umd.js:4568:25) at PlatformRef_.bootstrapModule (https://unpkg.com/@angular/core/bundles/core.umd.js:4554:21) at execute (https://run.plnkr.co/preview/cj8fyb96l00063c5srholji8p/main.ts!transpiled:108:65) Error loading https://run.plnkr.co/preview/cj8fyb96l00063c5srholji8p/main.ts 直接从我的makefile运行gdb。

我打开游戏,在其中打开一个菜单,当我尝试关闭它时崩溃,因为我在gdb -ex run ./main执行此操作:

WindowsObject.cpp

Gdb说:

WindowObject_CraftingGrid::~WindowObject_CraftingGrid(){
   for (unsigned i = 0; i < gridSlots_.size(); i++) {
      for (unsigned j = 0; j < gridSlots_[0].size(); i++) { //i++ instead of j++, this leads to the crash
         delete gridSlots_[i][j];
      }
   }
}

这是完全错误的,因为它没有解决错误的任何用处,因为它没有指向正确的对象和行。

我在Windows机器上的visual studio中发现了这个错误,因为那里的调用堆栈很清楚:

(gdb) bt
#0  0x0000000100023a80 in WindowObject_Image::Draw (this=0x300000000) at src/WindowObjects.cpp:620
#1  0x0000000100023ae2 in WindowObject_Image::setImage (this=0x100a9e980, img=0x0) at src/WindowObjects.cpp:629
#2  0x000000010001d5f7 in WindowMain::AddSection (this=0x100a04ce0, n=28672) at src/Window.cpp:263
#3  0x0000000100033765 in LoadLibrary () at src/main.cpp:781
#4  0x0000000100030b25 in DrawGUI () at src/main.cpp:465
#5  0x0000000100031534 in DrawGUI () at src/main.cpp:501
#6  0x00000001006eae27 in ?? ()
#7  0x0000700001875ef0 in ?? ()
#8  0x00007fff40b796d8 in ?? ()
#9  0x0000000000000000 in ?? ()

1 个答案:

答案 0 :(得分:2)

  

这是完全错误的

不,它不是:您的应用实际在此平台上崩溃的位置。

  

因为它对解决错误没有任何帮助

你有一个堆腐败错误。堆损坏错误 是这样的:在任意位置堆损坏后,您的应用程序可能会在崩溃一段时间后崩溃。

此外,堆栈跟踪无用:它会告诉您this == 0x300000000,这不是this的合理值,因此您正在查看某些内容堆腐败。

调试类似问题的方法有很多种:debug mallocAddress SanitizerValgrind

使用-D_GLIBCXX_DEBUG构建在GCC STL中启用debugging mode,并且可能还会直接指出错误。