macOS Xcode debugging: can I single-step just one thread while another thread runs free?

This seems like a very basic question but I couldn't find an answer to this yet:

I have a simple C++ command-line application which has its main() thread and from this it forks a service pthread (BSD thread). This service thread performs the I/O on the console. When I just let it run, it works as expected.

The question is: I would like to pause and single-step only the main() thread while the service thread continues to run free in the background, but so far the Xcode debugger insists on always pausing or resuming all threads at the same time, apparently (regardless whether the pause was due to clicking the pause icon or hitting a breakpoint in either thread).

Have I overlooked something or is it in fact impossible in Xcode to pause and single-step only one of the threads in a Mac application?

(I'm not questioning that in most cases the observed behaviour is the desired and most practical one, I'd just need single-thread debugging right now.)

Accepted Reply

I don’t think you can do this from the Xcode GUI but in LLDB you can use the -m option to determine whether other threads will run. In the LLDB prompt, type help thread step-in (or help thread step-over) for more info.

This should work at the LLDB prompt in Xcode’s console panel.

Be aware that many parts of macOS are multi-threaded and so the this-thread option may well hang if you call into framework code.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • It's good to know that I hadn't just been overlooking such an option.

    In this particular case I'm not using any system frameworks apart from basic POSIX system calls and some basic (and thread-safe) C++ standard library, but I see how macOS frameworks could complicate things.

    The LLDB tip is interesting; I'll have to see if I can make that work for me.

    Thanks a lot!

Add a Comment

Replies

I don’t think you can do this from the Xcode GUI but in LLDB you can use the -m option to determine whether other threads will run. In the LLDB prompt, type help thread step-in (or help thread step-over) for more info.

This should work at the LLDB prompt in Xcode’s console panel.

Be aware that many parts of macOS are multi-threaded and so the this-thread option may well hang if you call into framework code.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • It's good to know that I hadn't just been overlooking such an option.

    In this particular case I'm not using any system frameworks apart from basic POSIX system calls and some basic (and thread-safe) C++ standard library, but I see how macOS frameworks could complicate things.

    The LLDB tip is interesting; I'll have to see if I can make that work for me.

    Thanks a lot!

Add a Comment