Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set conditional breakpoint for certain thread only in Xcode/LLDB

Tags:

xcode

llvm

lldb

I am using some GCD code which dispatches a bunch of similar async blocks. I would like to debug one of these blocks by stepping through it so I've set a breakpoint somewhere near the top of the block, but the debugger hits the breakpoint every time a new block is submitted and so I never manage to step through the block, I just get swapped around different threads on the same line.

My question is how do I set a breakpoint so that its conditional upon a certain thread? i.e. it should only trigger if executed on thread 4?

EDIT

I should add that my block's code is very time intensive, so the scheduler swaps onto another thread before the next line inside the block can be executed, and another freshly scheduled GCD block gets its turn, triggering the same breakpoint.

like image 550
lmirosevic Avatar asked Jan 18 '13 12:01

lmirosevic


People also ask

How do you set a breakpoint in LLDB?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )

How do I set a conditional breakpoint in Xcode?

You can set a conditional break point in Xcode by setting the breakpoint normally, then control-click on it and select Edit Breakpoint (choose Run -> Show -> Breakpoints). In the breakpoint entry, there is a Condition column.

How do you set a breakpoint in a thread?

Use the qualifier ' thread thread-id ' with a breakpoint command to specify that you only want GDB to stop the program when a particular thread reaches this breakpoint. The thread-id specifier is one of the thread identifiers assigned by GDB, shown in the first column of the ' info threads ' display.


1 Answers

I don't think this is exposed through the Xcode Breakpoints UI but in lldb you can modify a breakpoint so it only fires when a (1) thread name matches, (2) dispatch queue name matches, (3) thread ID matches, or (4) thread index number matches. You can specify these criteria when you create the breakpoint (breakpoint set) or you can add these criteria to an existing breakpoint with breakpoint modify. See help breakpoint modify in the Debugger console window for a list of the allowed arguments.

like image 75
Jason Molenda Avatar answered Nov 15 '22 08:11

Jason Molenda