Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » to debug multi processes app. (fork)
to debug multi processes app. (fork) [message #1738574] Thu, 21 July 2016 04:02 Go to next message
chen zero is currently offline chen zeroFriend
Messages: 9
Registered: July 2009
Junior Member
Hello,
a multi processes app, with fork()
#include <unistd.h>
#include <stdio.h>

int main(int argc, const char **argv)
{
	 int p;
	 int a = fork();
 	if (a>0) { // parent
		 p = getpid();
 		printf("parent ..: %d %d\n", p, a);
 	}
 	else if(a==0) { // child
 		p = getppid();
 		a = getpid();
 		printf("child ... :%d %d\n", p, a);
 	}
 	else {
 		printf("fork failed ..");
 		return -1;
 	}
 	return 0;
}


when running this app, with following both options are checked in Debugger tab of Debugger Configurations
1. Non-Stop mode
2. Automatically debug forked processes ,
only breakpoint in parent process is hit.

I added following lines in .gdbinit file, and specify the absolute path in
"GDB command file"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set follow-fork-mode child
set detach-on-fork off

I noticed in the eclipse Debug tab, two apps are attached, as before,
only parent process can step code.
the problem is, when I switch to another process(child), and press F6,
the app receives SIGHUP and terminated.

I tested this on the latest Eclipse-CDT Neno Release.
My GDB version:
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
OS: Ubuntu 14.04.

how to debug into forked processes ?

Thank you very much !
chenzero
Re: to debug multi processes app. (fork) [message #1738645 is a reply to message #1738574] Thu, 21 July 2016 15:54 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Hi,

I have Ubuntu 16.04 and your example worked for me with both system gdb, version 7.11 and my locally built gdb version 7.7.1. There must be some other differences between our setups. I did not use a gdbinit file at all.

I put breakpoints on the printfs, parent and child, and after continuing from main both processes stopped at their respective breakpoint and I was able to single step both of them.

I would be grateful if you can confirm gcc version (I am usgin 5.3.1, system default) perhaps and provide mitraces and then we can see what is different.

Jonah

[Updated on: Thu, 21 July 2016 15:59]

Report message to a moderator

Re: to debug multi processes app. (fork) [message #1738664 is a reply to message #1738645] Fri, 22 July 2016 01:17 Go to previous messageGo to next message
chen zero is currently offline chen zeroFriend
Messages: 9
Registered: July 2009
Junior Member
Hi,
My gcc version: gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
for mitrace, please see the mi-1.txt
for the whole Neon project, please see testdmp.zip.

perhaps what I described in previous post is confusing, I would rephrase here:
1. Not specify any .gdbinit file, just check
Non-Stop mode and Automatically debug forked processes ,
in Debug configurations,
only parent process can step code. the breakpoint in child process is hit, however,
can not step code.(when press F6, the process receives SIGHUP and terminated.
2. specify the .gdbinit with lines:
set follow-fork-mode child
set detach-on-fork off
same result as 1, seems .gdbinit is not effect.

Thanks!
chenzero
  • Attachment: mi-1.txt
    (Size: 56.05KB, Downloaded 248 times)
  • Attachment: testdmp.zip
    (Size: 3.92KB, Downloaded 204 times)
Re: to debug multi processes app. (fork) [message #1738696 is a reply to message #1738645] Fri, 22 July 2016 10:32 Go to previous message
chen zero is currently offline chen zeroFriend
Messages: 9
Registered: July 2009
Junior Member
Perhaps I found the reason of this problem.
gdb core dump when I manually debug the testdmp.zip
please see log in gdb-1.txt

Thanks.

  • Attachment: gdb-1.txt
    (Size: 2.22KB, Downloaded 266 times)
Previous Topic:repeated full c++ reindexing
Next Topic:RSEG1066 Failed to connect sshd Algorithm negotiation fail
Goto Forum:
  


Current Time: Tue Nov 05 22:55:17 GMT 2024

Powered by FUDForum. Page generated in 0.03044 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top