Tracking variable or memory change in Xcode?

醉酒当歌 提交于 2019-11-28 06:55:20
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.

This is 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 this related post.

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.

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).

It will print somehting like 0x12345678.

  • With gdb: type watch *(int *)0x12345678.

  • With lldb: watch set expression (int *)0x12345678 (or w s e (int *)0x12345678)

This assumes your variable is an int. It will create an hardware watchpoint on this address.


Hope this helps.

Yes.

Under the Run menu there is "Debugger" which provides a visual frontend to 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.

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!