跟踪 Xcode 中的变量或内存变化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4801175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tracking variable or memory change in Xcode?
提问by SeniorLee
Is there any way to track variable changes or memory changes in Xcode? I'm looking for functionality like Visual Studio's data breakpoint.
有没有办法跟踪 Xcode 中的变量更改或内存更改?我正在寻找像 Visual Studio 的数据断点这样的功能。
I want to know where my object's view frame is being changed. I want to set a breakpoint at a member variable and run it. Then I could determine where it's changed.
我想知道我的对象的视图框架在哪里被改变。我想在成员变量上设置断点并运行它。然后我可以确定它在哪里改变了。
回答by Sedate Alien
Xcode uses gdb
(or lldb
, but that's another story) to implement its debugging functionality. gdb
has the ability to set hardware watchpoints and hence so does Xcode.
Xcode 使用gdb
(或lldb
,但那是另一回事)来实现其调试功能。gdb
具有设置硬件观察点的能力,因此 Xcode 也是如此。
Thisis a useful page for generic debugging of memory errors. Xcode's debugging console window is really just a gdb
shell, you can type in commands as you please. The ever-helpful Quinn Taylor explains how to do so in thisrelated post.
这是用于一般性调试内存错误的有用页面。Xcode 的调试控制台窗口实际上只是一个gdb
shell,您可以随意输入命令。乐于助人的 Quinn Taylor 在这篇相关文章中解释了如何做到这一点。
If you'd rather avoid interacting with gdb
directly, you can right-click a variable in Xcode's debugging window and select "Watch Variable". Xcode will then alert you whenever your variable's value has been changed.
如果你不想gdb
直接交互,你可以在 Xcode 的调试窗口中右键单击一个变量,然后选择“观察变量”。每当您的变量值发生更改时,Xcode 都会提醒您。
回答by Kevin MOLCARD
You can use hardware watchpoints.
您可以使用硬件观察点。
You have to get the address of the variable you want to track (type p &my_var
in gdb prompt).
您必须获得要跟踪的变量的地址(p &my_var
在 gdb 提示符下键入)。
It will print somehting like 0x12345678
.
它会打印类似0x12345678
.
With gdb: type
watch *(int *)0x12345678
.With lldb:
watch set expression (int *)0x12345678
(orw s e (int *)0x12345678
)
使用 gdb:键入
watch *(int *)0x12345678
.使用 lldb:(
watch set expression (int *)0x12345678
或w s e (int *)0x12345678
)
This assumes your variable is an int
. It will create an hardware watchpoint on this address.
这假设您的变量是int
. 它将在此地址上创建一个硬件观察点。
Hope this helps.
希望这可以帮助。
回答by aqua
Yes.
是的。
Under the Run menu there is "Debugger" which provides a visual frontend to gdb.
在运行菜单下有“调试器”,它为 gdb 提供了一个可视化的前端。
Also, there is a breakpoint button next to the Build and Run button. You can click that and manage your breakpoints under Run > Manage Breakpoints.
此外,Build and Run 按钮旁边还有一个断点按钮。您可以单击它并在 Run > Manage Breakpoints 下管理您的断点。
回答by DrMad
I know this post is old but in case you are still wondering I posted a detailed answer here: In XCode 6 how can you set a watchpoint without stopping execution?
我知道这篇文章很旧,但如果你仍然想知道我在这里发布了一个详细的答案:在 XCode 6 中,你如何设置一个观察点而不停止执行?