Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gdb

cmake

clion

I have Linux system, and I writing program use Clion IDE which using CMake. I have a part my in program where I would like to debug child process I read a few topic from this forum, but I still doesn't know how or where just I can turn on this function:

gdb debugging child process after fork (follow-fork-mode child configured)

How do I debug the child process after fork() in gdb?

I just have tryed to setup flag CMAKE_CXX_FLAGS_DEBUG as set follow-fork-mode child but CMake give me error. Below screenshot with all flags which are uses to compile and dbug my program. So what and where I must set this function.

enter image description here

..::EDIT::..

I believe that is good way. I think Your tip was useful, but I have some next problem. After using Your instructions my code is crash on line

pid_t newProcessForClient = fork();

Statement is:

(gdb) set follow-fork-mode child [New process 31667] warning: File "/lib32/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. [Switching to process 31667] Continuing with signal SIGABRT.

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

like image 302
Mbded Avatar asked Dec 06 '15 19:12

Mbded


1 Answers

The debugging settings have nothing to do with cmake. CMAKE_CXX_FLAGS_DEBUG states the debug flags for the compiler. However, you need to tell set follow-fork-mode child to the debugger. To do this, you need the following steps:

  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 auto-load safe-path /
  4. Continue debugging

The command set auto-load safe-path / is supposed to switch of the auto-load restrictions according to the documentation of gdb.

like image 163
MarkusParker Avatar answered Oct 20 '22 04:10

MarkusParker