PDA

View Full Version : [C Lang] how does fprintf to a debug file solve a core dump?


Darren
02-08-2010, 11:55 PM
Ok, first... I'm stumped. I wrote and maintain a set of programs in C (originally written in 1998). Recently I made some minor changes. Nothing above basic difficulty, but the program is now core dumping. I add some debug (printf) statements to determine where the core dump is occurring and the core dumping disappears--the program runs fine. I removed the debug statements one-by-one until the core dumping came back. I put that one debug line back and removed all the others so that there is just one line difference between a program that runs fine and one that core dumps. Here's the one line:

snippet #1 (debug output sent to stderr)fprintf( stderr, "%s, %s\n", g->name, g->value );

snippet #2 (debug output sent to a file)fprintf( debug, "%s, %s\n", g->name, g->value );

snippet #1 core dumps.
snippet #2 runs fine (the entire program runs and produces accurate output).
The program also core dumps if I just remove the line.

The program itself does not redirect stderr... but it does run as a cgi program on an apache web server which captures all stderr to a log file. For 12 years, this has worked fine.

This is a real head-scratcher for me. Any ideas how this is possible? Any at all?

Darren

oracleguy
02-09-2010, 12:02 AM
Does this program use threads or multiple processes or anything like that?

Darren
02-09-2010, 12:38 AM
I would answer no. I do not use fork() or anything like that. The web page that calls the cgi will make up to 8 calls to this same cgi (each one requesting different information). The calls are supposed to be sequential... in that the 2nd call is not sent prior to receiving a reply to the 1st call. During my attempts to debug this I have seen some tests run through 1-3 calls successfully before core dumping on a subsequent call. The current debug setup is core dumping on the very first call.

oracleguy
02-09-2010, 02:44 AM
Well if the program reads or writes to some common data source, my guess would be some sort of race condition between the difference instances of the program. You do have my sympathy, these types of bugs can be difficult to fix. So when it core dumps, what does the stack trace say? That might get you pointed in the right direction.