0

I writing program as simply server. In this moment I want to debug child process, but happens something not understand for me, because if I want to debug child space (I set follow-fork-mode child )I always get statement:

[Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". (gdb) set follow-fork-mode child

[New process 24892] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [Switching to Thread 0xf7c61700 (LWP 24892)] Continuing with signal SIGABRT.

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

My program works as well if I just runing him, but if I want to debug not. Here is little part of my program. I want to show main loop server, because I think here is a main problem.

 while (loopFlag) {
        sin_size = sizeof infoAboutClientAddress;
        if ((newDS = accept(serverFileDescriptor, (struct sockaddr *) &infoAboutClient,
                                              &sin_size)) == -1) {
           // can not accept connection
            continue;
        }

        pid_t newProcessForClient = fork();
        if (!newProcessForClient) {
            // here a want to debug but always get above statement
            printf("Hello here is child");    
        } else if (newProcessForClient < 0) {
            // something is wrong with new proces
            close(newDS);
        } else if (newProcessForClient > 0) {
            // code for parent
            close(newDS);
        }
}

I read below topic, but I still don't know how ignore this signal, or what can I do so as he dosen't appears.

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

EDIT 1

Idea is for each client should be create separate process

EDIT 2

I have install GDB Debian 7.7.1

I run debug just from IDE nothing to write just Shift+F9. debug works as well if I moving into parent space.

Here is screen shot flags for debug

enter image description here

EDIT 3

Statements after command cmake -DCMAKE_BUILD_TYPE=Debug in direcytory with project

-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: 
Community
  • 1
  • 1
Mbded
  • 1,754
  • 4
  • 23
  • 43
  • Why do you want to debug the program in the first place? also how are you compiling it? and what flags do you pass to the compiler? One more thing, what kind of `sockaddr` is `infoAboutClientAddress`? – Iharob Al Asimi Dec 07 '15 at 18:52
  • Please post `// code for parent`. – Iharob Al Asimi Dec 07 '15 at 18:58
  • @ihrob. Sorry but I don't understand Your first question (however if I understood, child process will get specjal task in future). I compiled this via **CMake** using **Clion IDE**. I have set flags `-m=32` (because some shared ibrary this required) and `-std=c++11` . Structure sockaddr is `sockaddr_in`. Code for parent You see above, it only close no needs descriptor. – Mbded Dec 07 '15 at 19:15
  • 1. Why would you use `-std=c++11` for [tag:c] code. 2. There is no `-m=32` flag it's `-m32`. 3. What platform are you on? – Iharob Al Asimi Dec 07 '15 at 19:35
  • I write server which using function from C, but rest code it is in c++ that's way I decided on tag **C** nor **C++**, and I thought my problem is result working C library because `fork()` is a part C. About flag You have a right should be `-m32` (sorry I tyred because all day I will been sit at the code). My machine is x86 64bit, Debian. – Mbded Dec 07 '15 at 19:53
  • Did you install all the debug packages for your debian? Also, is `-g` in your `CMAKE_C_FLAGS_DEBUG` and are you invoking *cmake* like this `cmake -DCMAKE_BUILD_TYPE=Debug`? – Iharob Al Asimi Dec 07 '15 at 19:59
  • Could You look at **EDIT 2** ? – Mbded Dec 08 '15 at 05:24
  • Have you tried using the command line directly? IDES might have quirks with these things. – Iharob Al Asimi Dec 08 '15 at 05:57
  • I write command `cmake -DCMAKE_BUILD_TYPE=Debug` and ware generated 3 new files. `Makefile, cmake_install.cmake , CmakeCache.txt` I also give statement, they find in **EDIT 3**. Dobug child process still doesn't work... – Mbded Dec 08 '15 at 12:29

0 Answers0