Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!husc6!ogccse!blake!uw-beaver!ubc-cs!alberta!calgary!enme3!deraadt From: deraadt@enme3.ucalgary.ca (Theo Deraadt) Newsgroups: comp.unix.wizards Subject: Re: Debugging Child Processes. Message-ID: <1764@cs-spool.calgary.UUCP> Date: 27 Aug 89 07:50:12 GMT References: <6840004@hpcllcm.HP.COM> Sender: news@calgary.UUCP Reply-To: deraadt@enme3.UUCP (Theo Deraadt) Organization: U. of Calgary, Calgary, Alberta, Canada Lines: 55 In article <6840004@hpcllcm.HP.COM> pratap@hpcllcm.HP.COM (Pratap Subrahmanyam) writes: >I have been running into the following problem. I want to debug a child process >and all the debugger's that we have here cannot do that. Does anyone know where >such a debugger can be got ? > >main() { > ... > if((pid = fork()) == 0) { > /* How can you step into this area ???? */ > } >} Under SunOS4.0 I can suggest one trick that I use when I have a lot of weird things happening. It's only useful in a fork()ed child after you do an exec().. I have not figured out a neat trick for doing things there, although I guess I could start to look at ptrace().. char *args[10]; switch( (child=fork()) { case -1: perror("fork"); break; case 0: /* Sorry, I can't help you debug this part.... */ #if TRACE_DEBUG args[0] = "/bin/trace"; args[1] = "-o"; args[2] = "child.trace"; args[3] = "child"; args[4] = "child_argv[1]"; args[5] = NULL; #else args[0] = "child"; args[1] = "child_argv[1]"); args[2] = NULL; #endif execv("/path/child", args); _exit(0); break; default: break; } As the child runs (after the exec()), all the system calls it makes and their parameters will be deposited in child.trace. Oh yeah, if you need to get the value of a variable, do something stupid with it, like kill(-1, int); write(-1, string, strlen(string)); Then you can see what it is in the tracefile... Gad, I hope you have a Sun on you.. this debugging has proved incredibly usefull in writing code that played with weird stuff....