GDB:创建局部变量? [英] GDB: Create local variable?

查看:114
本文介绍了GDB:创建局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode的调试器.在断点处停止时,是否可以在GDB命令提示符下键入命令以创建局部变量?如果是这样,怎么办?请提供示例.

I'm using Xcode's debugger. While stopped at a breakpoint, is there a command I can type in the GDB command prompt to create a local variable? If so, how? Please provide an example.

我知道我可以在代码中做到这一点,然后重新编译程序,但是我正在寻找一种更快的方法.

I know I can do it in the code and then recompile the program, but I'm looking for a faster way.

推荐答案

注释中提到了它,但没有作为答案:如果您不需要在代码中引用变量,而只想做一些广告,进行专门调查,您可以使用便捷变量以<代码> $ :

It's mentioned in the comments, but not as an answer: if you don't need to reference the variable in your code but just want to do some ad-hoc investigation, you can use Convenience Variables Start your variable with a $:

(gdb) set $foo = method_that_makes_something()
(gdb) set $bar = 15
(gdb) p $bar
$4 = 15

打印时,您会注意到它带有数字变量的前缀-您以后也可以使用它们来引用该值:

You'll notice when you print things it's prefixed with a numeric variable - you can use these to refer to that value later as well:

(gdb) p $4
$5 = 15

要重申:这实际上并不会影响程序的堆栈或其他任何东西,因为这会破坏很多东西,但是如果您只需要本地游乐场,一些循环变量等,则很有用.

To reiterate: this doesn't actually affect the program's stack or anything, as that would break a lot of things, but it's useful if you just need a local playground, some loop variables, etc.

这篇关于GDB:创建局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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