GDB:观察给定范围内的变量 [英] GDB: Watch a variable in a given scope

查看:156
本文介绍了GDB:观察给定范围内的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于GDB,我可以观察我,以便在 i 变化时中断。问题是我有多个函数使用名称 i ,所以GDB打破了所有这些函数。



如果 i 发生变化,但只能在给定函数内部发生,那么是否有可能破坏它?

解决方案

我猜你是 正在观察一个全局变量 ,因此它会停止在所有这个变量被修改的函数中 ,这是逻辑的和预期的行为 即可。如果只在 i 更改时只打破给定函数内部,则不要为 i 设置断点。而是为所需的功能设置断点。当这个断点被击中时,现在设置 i 的手表,以便确保在<$ c $时点击下一个断点c> i 在所需的函数中被修改(忽略可能的递归等)

我猜你可能不会看局部变量在每一个具有相同名称的函数中,因为 不能在局部变量上设置断点,直到您处于该特定函数的范围内。

With GDB I can watch i, to break whenever i changes. The problem is that I have multiple functions using the name i, so GDB breaks inside of all those functions.

Is it possible to break whenever i changes, but only inside a given function?

解决方案

I guess you are watching a global variable and hence it stops in all functions where this variable is modified which is the logical and expected behaviour. If you want to break only inside a given function whenever i changes, dont set the breakpoint for i. Instead set a breakpoint for the desired function. When this breakpoint is hit, now set the watch for i so that you know for sure that the next breakpoint will be hit when i is modified in the desired function (Ignoring possible recursions and the like)

I guessed that you may not be watching a local variable inside every function with the same name because you cannot set a breakpoint on a local variable until you are in the scope of that particular function.

这篇关于GDB:观察给定范围内的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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