20

Is there any way to track variable changes or memory changes in Xcode? I'm looking for functionality like Visual Studio's data breakpoint.

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.

4 Answers 4

21

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Appreciate for the detail answer! I'll try!
Never thought to right click on the variables in the watch window! Now to hope it actually hits it ;) Seems ropey enough just displaying variable values — telling me local vars are out of scope is really not helpful
@LaceySnr: check my answer. I have the same problem with XCode watch. That's why I am using gdb watchpoint.
"watchpoints not supported" is what I get when trying this on Xcode 5.
tl;dr right-click variable and click "Watch Variable"
|
13

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.

Comments

1

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.

2 Comments

I'm not sure this is what he's looking for. You are talking about standard breakpoints, but he is talking about breaking when data stored at a location in memory changes. More like a watchpoint than a breakpoint.
Got it. Yeah, I don't know if there are any "triggers" like that. However, through the Debugger and use of standard breakpoints you can see the data changing. Probably not as smooth as Visual Studio.
0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.