[Techtalk] GDB and C question
bsweeney at physics.ucsb.edu
bsweeney at physics.ucsb.edu
Wed Oct 23 00:26:28 EST 2002
Hey all you C gurus-
I, being a miserable programmer, am stuck debugging a problem with a rather old
piece of in-house software written in C. It's segfaulting to be precise, with
(shocker) no good error messages being generated. I've run the program through
gdb, and from what I can see from the stack trace it looks like the segfault's
happening when it tries to open a file. Makes sense; the error gdb originally
reported was a no such file or directory error in some low-level library. I
have narrowed the function call down generating the error, and it's a fprintf
statement with a file and a bunch of strings as characters. My question is, if
I know the name of the file pointer (in this case parm_fp), is it possible to
get the name of the file associated with that pointer? I know that gdb will
let me print out the value of variables; I've already had it print out integer
variables with great success. But of course when I say:
gdb> p parm_fp
I get a memory address back. Using p/a gave the same results. I'm not
terribly familiar with gdb, so I'm not sure what else to try.
Any way to get the filename from the pointer or address? I realize the best
way would probably be to go through the source code and find the original fopen
command for the file in question, but the code is massive and hard to follow.
Any advice would be appreciated. Unfortunately, it's part of our financial
software and (shock again) the finance stuff needs to get generated by the end
of the week. *sigh*, why doesn't anyone ever find problems when they DON'T
matter?
Thanks in advance,
Brian
More information about the Techtalk
mailing list