使用 gdb 调试时干净地退出 valgrind [英] Quit valgrind cleanly when debugging with gdb

查看:169
本文介绍了使用 gdb 调试时干净地退出 valgrind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 valgrind 和 gdb 调试程序.然而,我以一种野蛮的方式终止了那些调试会话……这真的是应该如何完成的吗?

I am debugging a program using valgrind and gdb. However I terminate those debugging sessions in a barbaric way… Is it really how it is meant to be done ?

遵循官方的说明valgrind 网站我执行以下操作来运行程序:

Following the instructions from the official valgrind website I do the following to run the program :

  1. 我通过输入运行 valgrind

  1. I run valgrind by entering

valgrind --tool=memcheck --vgdb=yes --vgdb-error=0 ./prgm.run 

  • 在另一个终端会话中,我使用

  • From another terminal session, I run gdb using

    gdb ./prgm.run
    

  • 我将 gdb 连接到 valgrind

  • I connect gdb to valgrind

    (gdb) target remote | vgdb
    

  • 我从 gdb CLI 运行程序

  • I run the program from gdb CLI

    (gdb) c
    

  • 到目前为止一切顺利:程序在两个终端中运行(一个用于 valgrind,另一个用于 gdb).然后 valgrind 发现错误,例如无效读取,程序暂停执行.

    So far so good : the program runs in both terminals (the one used for valgrind and the one used for gdb). Then valgrind finds an error, for instance an invalid read, and the program execution is paused.

    那时,我想摆弄我的代码:也许从程序的源代码中修复某些内容或注释/取消注释内容.因此,程序需要重新编译.生成一个新的二进制文件.之后,我想停止正在进行的 valgrind 和 gdb 会话(使用旧二进制文件)并启动将使用新二进制文件的新 valgrind 和 gdb 会话.

    At that point, I want to fiddle with my code : perhaps fix something or comment/uncomment stuff from the program's source. As a consequence, the program needs to be compiled anew. A new binary is generated. Following that, I want to stop the on-going valgrind and gdb sessions (that were using the old binary) and start new valgrind and gdb sessions that will use the new binary.

    为了停止正在进行的会话,我退出了 gdb

    To stop an on-going session, I quit gdb

    (gdb) q
    

    有时 valgrind 会注意到 gdb 不再存在并退出.但是其他时候 valgrind 会继续运行,即使不再存在 gdb 进程......

    Sometimes valgrind notices that gdb is no longer there and quits too. But other times valgrind keeps going even-though no gdb process exist anymore…

    在这种情况下,我会终止与我的 valgrind 会话相对应的memcheck-amd64-"进程.该进程的编号在 valgrind 消息中指示,例如16195 in ==16195== Invalid read of size 8).

    In that case I kill the "memcheck-amd64-" process corresponding to my valgrind session. The number of that process is indicated in the valgrind messages e.g. 16195 in ==16195== Invalid read of size 8).

    kill -9 16195
    

    常规杀死是不够的:我需要使用 -9 选项.

    A regular kill is not enough : I need to use the -9 option.

    我不认为调用 kill -9 是应该这样做的......我错过了什么吗?

    I don't think invoking kill -9 is how it is meant to be done… Am I missing something ?

    valgrind 版本:3.10.1

    valgrind version : 3.10.1

    gdb 版本:7.7.1

    gdb version : 7.7.1

    推荐答案

    你也可以使用命令

    (gdb)monitor v.kill
    

    它列在 gdb 的监视器帮助中.

    it was listed on monitor help on gdb.

    这篇关于使用 gdb 调试时干净地退出 valgrind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆