How to set follow-fork mode as a child in a debugger using CMake

I have a Linux system and am writing a program using the Clion IDE that uses CMake . I have a part of my program in which I would like to debug a child process. I read several topics from this forum, but I still don’t know how and where I can enable this function:

gdb debug child process after fork (child mode configured in standby mode)

How to debug child process after fork () in gdb?

I just tried setting the CMAKE_CXX_FLAGS_DEBUG flag as set follow-fork-mode child , but CMake give me an error. Below is a screen shot of all the flags that are used to compile and dbug my program. So, what and where should I install this function.

enter image description here

.. :: EDIT :: ..

I think this is a good way. I think your advice is useful, but I have the following problem. After using your instructions, my code is disabled online

 pid_t newProcessForClient = fork(); 

Statement:

(gdb) set the child mode to the following mode [New process 31667]: File "/lib32/libthread_db-1.0.so" startup was rejected by your `auto-load safe-path 'set to" $ debugdir: $ datadir / auto-load " . warning: Could not find libthread_db corresponding to the library of the lower threads, the debug thread will not be available. [Go to Process 31667] Continued with SIGABRT.

Program terminated with SIGABRT signal, canceled. The program no longer works exists.

+5
c ++ cmake gdb clion
source share
1 answer

Debugging options have nothing to do with cmake. CMAKE_CXX_FLAGS_DEBUG indicates debug flags for the compiler. However, you need to tell the child module the child mode in the debugger. To do this, you need to follow these steps:

  • Set a breakpoint at the beginning of your program (i.e. the parent program, not the child program)

  • Run the program in the debugger.

  • Go to the debugger console (tab labeled gdb) in the client and enter the set-fork-mode child element and set the safe auto-download path /
  • Continue Debugging

The set auto-load safe-path / command should switch the auto-load limits according to the gdb documentation .

+3
source share

All Articles