gdb:记录一些东西而不是破坏? [英] gdb: logging something instead of breaking?

查看:126
本文介绍了gdb:记录一些东西而不是破坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能让gdb将日志记录到终端而不是打断它?例如,我想在某些方法上设置一个断点,并在每次调用该方法时使gdb自我打印以及参数。基本上我想在没有实际重新编译的情况下将打印语句插入任意位置。



感谢您的任何建议




这就是我所拥有的到目前为止,在这些有用的评论之后:

  define logFoo 
b fooMethod
命令
po self
end
end

虽然GDB似乎并不喜欢嵌套的结束语句。任何想法?

解决方案

您可以使用断点命令列表。例如,如何使用
断点命令打印数值,如下所示:
$ b


$ x $ b $ x在进入foo时,x是
正值。

  break foo if x> 0 
命令
silent
printfx is%d \\\
,x
cont
end



Is it possible to have gdb log something to the terminal instead of breaking on it? For example I would like to set a 'breakpoint' on some method and have gdb print self as well as the parameters each time the method is invoked. Basically I want to insert print statements into arbitrary places without actually recompiling.

thanks for any suggestions


This is what i have so far after these helpful comments:

define logFoo
b fooMethod
commands
po self
end
end

GDB doesn't seem to like the nested end statements though. any thoughts?

解决方案

You can use Breakpoint Command Lists. There is an example how to do it.

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

这篇关于gdb:记录一些东西而不是破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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