如何使用CLion调试分叉子进程

时间:2022-11-03 17:01:09

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?

我正在使用CLion的内部调试器(Linux上的gdb)调试Linux C程序。该程序分叉了一个子进程,该进程本应在我设置的断点处暂停。但即使我在gdb面板中输入了set follow-fork-mode子节点,调试器也没有停在那里。那么我怎么能用CLion来实现呢?

2 个解决方案

#1


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:

我按照@MarkusParker发布的回答,但没有设置auto-load safe-path /我使用set detach-on-fork off来防止与子进程断开连接。这条指令对我有用:

  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.

    转到clion中的调试器控制台(带有标签gdb的选项卡),然后输入set follow-fork-mode child并设置detach-on-fork off。

  4. Continue debugging.

    继续调试。

#2


0  

Ensure that you set set follow-fork-mode child before the fork.

确保在fork之前设置set follow-fork-mode子。

#1


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:

我按照@MarkusParker发布的回答,但没有设置auto-load safe-path /我使用set detach-on-fork off来防止与子进程断开连接。这条指令对我有用:

  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.

    转到clion中的调试器控制台(带有标签gdb的选项卡),然后输入set follow-fork-mode child并设置detach-on-fork off。

  4. Continue debugging.

    继续调试。

#2


0  

Ensure that you set set follow-fork-mode child before the fork.

确保在fork之前设置set follow-fork-mode子。