[prog] Re: [Techtalk] GDB and C question
Sujita Purushothaman
sujita at mimos.my
Wed Oct 23 16:13:30 EST 2002
bsweeney at physics.ucsb.edu wrote:
> Hey all you C gurus-
>
I'm no C guru, but I like tracing segfaults. :-)
> 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,
Compile with Electric Fence ftp://ftp.perens.com/pub/ElectricFence/ to make sure
that gdb stops at the exact line the segfault occurs; Otherwise it may or may not.
> 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.
>
AFAIK, parm_fp is a pointer to the file, not pointer to path/name of file. So
it makes sense that it doesn't print out the file name.
> Any way to get the filename from the pointer or address?
Can't help you with this, sorry. But don't worry, I'm sure someone else here
will be able to :-)
> 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?
Because then they wouldn't be a problem ;-) !
Best of Luck!
Sujita
More information about the Programming
mailing list