Kaki
Kaki

Reputation: 33

Use "data breakpoint" on Xcode

On Xcode, is it possible to set a breakpoint on an attribute value ? (stop if attr==nil for example) I know it is set to nil, but I can't find where and by whom.

Upvotes: 0

Views: 2048

Answers (3)

ravron
ravron

Reputation: 11221

If you don't use a setter to access the variable in question, you'll have to drop down to using LLDB (Xcode's debugger) directly to do what you want.

Set a normal breakpoint in a context where the variable you're interested in is in scope, and before it has been written by your mystery writer. Then, access the debugger pane, and enter the following command:

watchpoint set variable -w write <variable-name>

where <variable-name> is the name of the variable you'd like to watch – perhaps attr in this case. This will set a hardware watchpoint which will trigger when your variable is changed.

If you want to explore LLDB a little more, try help commands in the debugger. For example, you could type:

help watchpoint set variable

to see the help entry for the command I've recommended.

EDIT: Apparently you can also set such watchpoints from the Xcode GUI. Who knew?

Upvotes: 1

l0gg3r
l0gg3r

Reputation: 8954

1) Set breakpoint in the method
2) Right click on the breakpoint, and select "Edit Breakpoint"
enter image description here

3) Add Condition attr == nil enter image description here

4) Click somewhere in Xcode.

You are ready to go, breakpoint will stop whenever attr == nil

Upvotes: 0

Logan
Logan

Reputation: 53142

Open Xcode.

Open the 'Breakpoint Navigator' (cmd+7)

In lower left, click the + button

Select 'Add Symbolic Breakpoint..'

In 'Symbol' add: [YourObject setYourAttribute:]

In 'Condition' add: yourAttribute == nil

This will get called anytime yourAttribute on YourObject is set to nil. You can then look at the trace to see what sequence of events led to that call. I'm pretty sure that's what you're asking.

Upvotes: 2

Related Questions