How to do multi-process debugging in CLION?
After calling fork() there's two processes, parent and child. Within CLion I can switch to the child process via executing the following in the gdb tab:
set follow-fork-mode child
set detach-on-fork off
However I cannot switch back to the parent process. And it wouldn't make sense to anyway since it will execute in the background.
Now from the CLI outside Clion, I can of course run two separate gdb instances and attach each to the same running debug process. Clion doesn't allow this functionality because it won't allow me to open two copies of the same project.
Why do I want to debug in clion? Because I like the environment in it in terms of setting breakpoints and viewing environment variables.
So then, how do I do multi-process debugging in Clion? This is basic functionality.
Thanks
Please sign in to leave a comment.
Actually there is a way to do this already, I wasn't aware of it due to my own ignorance. For anyone else interested here is how:
Simply set a breakpoint in the initial process somewhere after the child processes have been created but won't finish terminating (such as at some wait/block point). Then attach the pid of each desired child processes via Run > Attach to Process. Any number of child processes can be attached like this, and each will open its own separate debugging session with its own local variables and ability to step through it, all in separate tabs in the one IDE instance.
This is nice functionality I wasn't aware existed, so my original post can be ignored.
Also feel free to comment or upvote the related feature request: https://youtrack.jetbrains.com/issue/CPP-9476/debugger-Support-multi-process-targets. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.