How to debug a forked child process using CLion

10,464

Solution 1

I followed answer posted by @MarkusParker, but instead of set auto-load safe-path / I used set detach-on-fork off to prevent disconnect from child process. This instruction works for me:

  1. Set a break point at the beginning of your program (ie. the parent program, not the child program).

  2. Start the program in the debugger.

  3. Go to the debugger console (tab with the label gdb) in clion and enter set follow-fork-mode child and set detach-on-fork off.

  4. Continue debugging.

Solution 2

Use the GDB tab of the debugger:

enter set follow-fork-mode child and set detach-on-fork off enter image description here

Share:
10,464

Related videos on Youtube

DYS
Author by

DYS

Hi folks. Nice to be met by you. I am currently looking for a position. If you think I am good fit. Please send me an email at [email protected].

Updated on June 04, 2022

Comments

  • DYS
    DYS almost 2 years

    I was debugging a Linux C program with CLion's internal debugger (which is gdb on Linux). The program forked a child process that was supposed to get suspended at the break point I set. But the debugger didn't stop there even if I had entered set follow-fork-mode child inside the gdb panel. So how can I make that happen with CLion?

  • DYS
    DYS over 7 years
    I confirmed this approach before and it didn't work. One can only debug through command line interface in this way instead of inside CLion.
  • Jaime Hablutzel
    Jaime Hablutzel about 6 years
    I'm experiencing that CLion disconnects remote debugging sessions when GDB follows the child process.
  • user7610
    user7610 almost 3 years
    @JaimeHablutzel In that case you also need to set detach-on-fork off.