[Techtalk] GDB and C question

Zohar Itai Itai.Zohar at comverse.com
Wed Oct 23 14:04:41 EST 2002


I'm not too good of a programmer, but perhaps this will help. Assuming file1
is the pointer generated by
file1 = fopen ("...","w");
In response to "p *file1" gdb returns:
(gdb) p *file1
$6 = {_flags = -72539000, _IO_read_ptr = 0x0, _IO_read_end = 0x0,
  _IO_read_base = 0x0, _IO_write_base = 0x0, _IO_write_ptr = 0x0,
  _IO_write_end = 0x0, _IO_buf_base = 0x0, _IO_buf_end = 0x0,
  _IO_save_base = 0x0, _IO_backup_base = 0x0, _IO_save_end = 0x0,
  _markers = 0x0, _chain = 0x401419c0, _fileno = 5, _blksize = 0,
  _old_offset = 0, _cur_column = 0, _vtable_offset = 0 '\000', _shortbuf =
"",
  _lock = 0x80498c0, _offset = -1, __pad1 = 0x0, __pad2 = 0x80498d8,
  _mode = -1, _unused2 = '\000' <repeats 51 times>}
(gdb)

Note that _fileno = 5.

Using ps I found my process and went to /proc/<proc_id>/fd, and typed ls -l
5:
lr-x------    1 izohar   tech           64 Oct 23 13:53 5 -> /tmp/itai

And /tmp/itai was indeed the open file.

Perhaps this would work for you too.

Itai.
-----Original Message-----
From: bsweeney at physics.ucsb.edu [mailto:bsweeney at physics.ucsb.edu]
Sent: Wednesday, October 23, 2002 9:26 AM
To: techtalk at linuxchix.org
Subject: [Techtalk] GDB and C question


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
_______________________________________________
Techtalk mailing list
Techtalk at linuxchix.org
http://mailman.linuxchix.org/mailman/listinfo/techtalk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://linuxchix.org/pipermail/techtalk/attachments/20021023/c0ec3068/attachment.xhtml


More information about the Techtalk mailing list