shu*_*alo 16 debugging valgrind
我的程序处理大错误,在开发过程中会在控制台上产生大量输出.它遭受内存损坏,我尝试使用valgrind来定位错误.
不幸的是,我无法在输出行中找到错误消息,并且当它们弹出时它们会快速刷新以取消执行.它们必须在那里才能找到错误(哪个元素确实会导致错误等等).然后在我的程序中重定向不起作用,就像管道输出只重定向程序输出,而不是valgrind输出.
你能给我一个如何解决这个问题的提示吗?
Emp*_*ian 22
除了将程序和Valgrind输出重定向到文件(如已建议的那样)之外,您还可以使用--db-attach=yesflag,这将导致程序在出错时在调试器中停止.
这样做的好处是,除了查看程序生成的日志外,还可以查看其他程序状态(您没有记录日志).
Yan*_*uth 13
如果您希望它在控制台中停止(不在文件中),可以使用以下方法:
使用参数: --gen-suppressions=yes
当你调试它会像这样停止:
==949== Thread 2:
==949== Invalid read of size 4
==949== at 0x7B62DC0: wcslen (wcslen.S:24)
==949== by 0x7B62D7D: wcsdup (wcsdup.c:29)
==949== by 0x52D0476: de_strdup(wchar_t*) (de_string.cpp:1442)
==949== by 0x437629: void de_format<>(c_de_string&, wchar_t*) (de_string.h:368)
==949== by 0x45F4FB: int db_select_group<>(s_db*, s_pqexec_param*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, int, wchar_t*) (in /corto/goinfre/code2/cortod.repo/bin/x64/Debug/cortod)
==949== by 0x45EA96: check_oldgeom(c_cartod*) (cartod_funcs.cpp:114)
==949== by 0x45EBF8: armserv_update_geom(c_cartod*) (cartod_funcs.cpp:149)
==949== by 0x455EF9: c_cortosrv_thread::on_timeout() (cartod.cpp:163)
==949== by 0x52FE500: c_de_thread::loop() (de_thread.cpp:35)
==949== by 0x52FEE97: thread_loop(void*) (de_thread_priv_linux.cpp:85)
==949== by 0x506E181: start_thread (pthread_create.c:312)
==949== by 0x7BBA47C: clone (clone.S:111)
==949== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==949==
==949==
==949== ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----
Run Code Online (Sandbox Code Playgroud)
然后你可以去下一个继续所有等.
此参数的正常用途是通过打印可以添加到文件中的抑制并使用以下参数将其传递给valgrind来消除误报: --suppressions=<filename>
Valgrind 3.14.0 有这个选项:
ERROR-RELATED OPTIONS top
These options are used by all tools that can report errors, e.g.
Memcheck, but not Cachegrind.
...
--exit-on-first-error=<yes|no> [default: no]
If this option is enabled, Valgrind exits on the first error. A
nonzero exit value must be defined using --error-exitcode option.
Useful if you are running regression tests or have some other
automated test machinery.
Run Code Online (Sandbox Code Playgroud)
您可以要求valgrind将其输出保存到文件中:
valgrind --log-file=<filename>
Run Code Online (Sandbox Code Playgroud)
其中<filename>是输出的文件名。less稍后您可以使用文本编辑器查看该文件。
| 归档时间: |
|
| 查看次数: |
8425 次 |
| 最近记录: |