Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode breakpoint should suspend only current thread

I need to debug a multithreading bug. So to have the condition that generates the crash I need to stop one thread at a specific point in my code and wait for another thread to reach a second breakpoint.

The problem I have now is that if one thread hits a breakpoint, all other threads are suspended. Is there a way to only stop one thread and let the others run until they hit the second breakpoint?

like image 228
Stefan Arn Avatar asked Apr 01 '14 08:04

Stefan Arn


People also ask

Does a breakpoint pause all threads?

Upon reaching a breakpoint, by default, GDB pauses all threads until the user types cont . The user can change the behavior to request that GDB only pause the threads that hit a breakpoint, allowing other threads to continue executing.

Why breakpoint is not working in Xcode?

You might be pushing "Run" instead of "Debug" in which case your program is not running with the help of gdb, in which case you cannot expect breakpoints to work! In Xcode 6.4, there is now only a Run button and whether it runs a debug configuration or not depends on the currently selected scheme settings.

What does a dotted breakpoint mean in Xcode?

New in Xcode 13, if a breakpoint is not resolved to any location by LLDB, Xcode will show you a dashed icon. There is a myriad of reasons why a breakpoint is not resolved but there are some common explanations. If you hover over the unresolved breakpoint icon, we have a tooltip that can help you out.


1 Answers

I know two ways: If you run into the first breakpoint you should see the debug navigator on the left side of xcode with a list of currently running threads. The thread you are currently on should be expanded. Right click on this thread and select 'suspend thread'. This is it.

If you later want to continue it, you can just click on resume. (In order to see the threads the execution has to be pause so you either have to be in a break point to do this or pause the app yourself! )

Other more fun option:

When you hit the first breakpoint, you could go into console and write

po [NSThread sleepForTimeInterval:3600]

that should pause the thread in the current context at that breakpoint for one hour.

Then resume the execution in Xcode.

like image 70
Nils Ziehn Avatar answered Oct 24 '22 12:10

Nils Ziehn