Re: Starting DDD programmatically

Michael Eager <[email protected]> Fri, 26 Aug 2011 11:46:17 -0700
Newsgroups gmane.comp.debugging.ddd.general
Message-ID <[email protected]>
On 08/26/2011 09:14 AM, [email protected] wrote:
>
> I'm writing CGI scripts using the C language. I'd like to know if DDD can help me debug these
> programs (scripts).
>
> CGI scripts are programs that get executed by a web server (ex: Apache). Scripts don't run
> continuously. They are executed by the web server when the user of a web browser "submits" a web
> page that contains an HTML form. The script (C program) runs long enough to process the information
> on the form. The script then terminates. Consequently, there is no continously running program for
> DDD to attach to. Is there a way that the script (or the web server) can start or attach to DDD when
> the script executes?

You might add code to your script to save the PID for the
CGI process and then sleep for a while to allow you to attach
with gdb/ddd.  Something like the following:

void wait_for_gdb (void)
{
   pid_t pid = getpid();
   FILE pidfd = fopen ("/tmp/cgipid", "w")
   fprintf (pidfd, "%d", pid);
   fclose (pidfd);

   sleep (15);
}

or perhaps wait for you to set a flag before continuing:

   while (fopen ("/tmp/goddd", "r") != 0) sleep (1);


-- 
Michael Eager	 [email protected]
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077