简体   繁体   English

C ++和Valgrind调试

[英]C++ and Valgrind Debugging

I have a memory issue with a SEGFAULT error on a ARM processor running C++. 我在运行C ++的ARM处理器上遇到SEGFAULT错误的内存问题。

I run valgrind and it gives me this info: 我运行valgrind,它给了我这个信息:

==7298== Thread 6:
==7298== Mismatched free() / delete / delete []
==7298==    at 0x482C80C: free (in /usr/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==7298==  Address 0x58186d8 is 0 bytes inside a block of size 29 alloc'd
==7298==    at 0x482CC94: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==7298== 

I go into gdb and run "info symbol" on 0x482CC94, 0x58186d8 and 0x482C80C and the debugger says "No symbol matches". 我进入gdb并在0x482CC94、0x58186d8和0x482C80C上运行“信息符号”,调试器说“没有符号匹配”。

I have so many threads running in the program that I can't figure out where to start. 我的程序中运行着很多线程,以至于我不知道从哪里开始。 I tired to put printf in the most likely threads to see if that would help but there does not seem to be any correlation between the printf statments and the valgrind output. 我厌倦了将printf放在最可能的线程中,以查看是否有帮助,但在printf语句和valgrind输出之间似乎没有任何关联。

How can I debug this problem? 如何调试此问题? Is there some way to name threads in my code so that Valgrind can show something besides "Thread 6". 有什么方法可以在我的代码中命名线程,以便Valgrind可以显示“线程6”以外的内容。 Any guidance would be appreciated. 任何指导将不胜感激。

It might be that the allocation/deallocation is happening during program startup. 可能是在程序启动期间发生了分配/取消分配。 Try the "--show-below-main" option: 尝试“ --show-below-main”选项:

--show-below-main= [default: no] --show-below-main = [默认:否]

"By default, stack traces for errors do not show any functions that appear beneath main because most of the time it's uninteresting C library stuff and/or gobbledygook. Alternatively, if main is not present in the stack trace, stack traces will not show any functions below main-like functions such as glibc's __libc_start_main. Furthermore, if main-like functions are present in the trace, they are normalised as (below main), in order to make the output more deterministic. “默认情况下,错误的堆栈跟踪不会显示任何出现在main下面的函数,因为大多数情况下,它们都不是有趣的C库内容和/或gobbledygook。或者,如果堆栈跟踪中不存在main,则堆栈跟踪将不会显示任何内容类似于main函数的函数(例如glibc的__libc_start_main),此外,如果在跟踪中存在类似于main函数,则将它们归一化为(在main之下),以使输出更具确定性。

If this option is enabled, all stack trace entries will be shown and main-like functions will not be normalised." 如果启用此选项,将显示所有堆栈跟踪条目,并且不会对类似main的函数进行规范化。”

You may also want to look at "--read-var-info" 您可能还需要查看“ --read-var-info”

--read-var-info= [default: no] --read-var-info = [默认:否]

When enabled, Valgrind will read information about variable types and locations from DWARF3 debug info. 启用后,Valgrind将从DWARF3调试信息中读取有关变量类型和位置的信息。 This slows Valgrind startup significantly and makes it use significantly more memory, but for the tools that can take advantage of it (Memcheck, Helgrind, DRD) it can result in more precise error messages. 这会极大地减慢Valgrind的启动速度,并大大占用更多内存,但是对于可以利用它的工具(Memcheck,Helgrind,DRD),它可以导致更精确的错误消息。

There are other valgrind options you can try. 您可以尝试其他valgrind选项。 The manual is here: 手册在这里:

http://valgrind.org/docs/manual/manual.html http://valgrind.org/docs/manual/manual.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM