做特定的动作时,在一定的gdb命中断点 [英] Do specific action when certain breakpoint hits in gdb

查看:207
本文介绍了做特定的动作时,在一定的gdb命中断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个方式做一些动作,当一个特定的破发点中的GDB命中。

I am looking for a way to do some action when a particular break point hits in gdb.

基本上我有我的一些程序memleak。当malloc和free函数打,我要进入功能(步骤),并收集像addr和大小的一些基本信息(基本打印有值)。一旦完成恢复我的程序。

Basically I have some memleak in my program. When malloc and free function hits, I need to enter into the function (step) and collect some basic information like the addr and size (basically print there values). Once done resume my program.

我们有什么好的办法做到这一点?

Do we have any good way to do this?

推荐答案

例如,这里是你如何使用断点命令在进入打印x的值给foo每当x为正。

For example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.

break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end

如果您在命令列表中指定的第一个命令是无声,就不会打印在断点处停止通常的消息。这可能是可取的断点是要打印的特定消息,然后继续。如果没有剩余命令的打印任何东西,你看到任何迹象表明断点到达。沉默是有意义的只在断点命令列表的开始。

If the first command you specify in a command list is silent, the usual message about stopping at a breakpoint is not printed. This may be desirable for breakpoints that are to print a specific message and then continue. If none of the remaining commands print anything, you see no sign that the breakpoint was reached. silent is meaningful only at the beginning of a breakpoint command list.

有关断点命令的一个应用是弥补一次错误,所以你可以测试另一个。把一个断点只是code的错误路线后,给它来检测其中一些错误已经完成的情况下的条件,并给它命令正确的值分配给需要它们的任何变量。与继续命令结束,这样你的程序不停止,所以没有产生输出用无声的命令启动。下面是一个例子:

One application for breakpoint commands is to compensate for one bug so you can test for another. Put a breakpoint just after the erroneous line of code, give it a condition to detect the case in which something erroneous has been done, and give it commands to assign correct values to any variables that need them. End with the continue command so that your program does not stop, and start with the silent command so that no output is produced. Here is an example:

break 403
commands
silent
set x = y + 4
cont
end

这篇关于做特定的动作时,在一定的gdb命中断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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