From: O'Donnell, T. (S. US) <tom...@si...> - 2011-07-12 13:03:05
|
Sergey, Thank you for this fix. I have a bigger concern, however: gdb does not appear to be accepting indirection. Or, more likely, I'm doing something wrong. I created the following toy program, test.c: ////////////////////////////////////////////////////////////////////////// #include "stdio.h" #include "stdlib.h" int main(int argc, char *argv[]) { int number; scanf("%d", &number); printf("Just read %d\n", number); return 0; } //////////////////////////////////////////////////////////////////////////////// I compiled it and ran it. The program asked for input from the console and I provided it. $ gcc -g -o gdbtest test.c $ gdbtest 9 Just read 9 Then I created a file infile.txt below: //////////////////////////////////////////////////////// 67 ///////////////////////////////////////////// When I funnel infile.txt into gdbtest the results are as expected. $ gdbtest < infile.txt Just read 67 However, when I try this in gdb it hangs, waiting for the input from stdin. If I type in 5, as I did below, it prints it out. $ gdb gdbtest GNU gdb (GDB) 7.2 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-cygwin". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/odonnell/indirection/gdbtest...done. (gdb) run < infile.txt Starting program: /home/odonnell/indirection/gdbtest < infile.txt [New Thread 2368.0x540] [New Thread 2368.0xd0c] 5 Just read 5 Program exited normally. (gdb) What am I doing wrong? What debuggers are others using? I am not wed to gdb. Thanks! Tom -----Original Message----- From: Sergey Fomel [mailto:ser...@gm...] Sent: Monday, July 11, 2011 10:20 PM To: O'Donnell, Thomas (SCR US) Cc: rsf...@li... Subject: Re: [rsf-user] Debugging using gdb with I/O redirection Tom, Thank you for reporting this problem. Here is a possible fix for the bug that you experienced: http://rsf.svn.sourceforge.net/viewvc/rsf/trunk/system/seismic/Msegyheader.c?r1=4796&r2=7379 In general, there should be no problem with running gdb on Madagascar programs the way you did it. It might help to set breakpoints to narrow down the problem. If a segmentation fault error dumps core, you can also run gdb on the core file. Note that if you run "scons" inside program directories (such as RSFSRC/system/seismic), it will compile local versions of the programs with proper debugging flags. SF On Mon, Jul 11, 2011 at 2:23 PM, O'Donnell, Thomas (SCR US) <tom...@si...> wrote: > Dear All, > > I am trying to debug a simple program, sfsegyheader, using gdb (I > recompiled Madagascar using gcc with the -g option) > > gdb sfsegyheader < plane.rsf tracl=tracl.rsf > tfile.rsf > > $ gdb sfsegyheader > (gdb) run < filter.rsf tracl=tracl.rsf > tfile.rsf > > Starting program: /usr/local/rsf/bin/bin/sfsegyheader < filter.rsf > tracl=tracl.r sf > tfile.rsf [New Thread 3360.0x17ac] [New Thread > 3360.0x1668] > > And it hangs.... > > If I run it from the console I get: > $ sfsegyheader < filter.rsf tracl=tracl.rsf > tfile.rsf > sfsegyheader: Need filesize=1Segmentation fault (core dumped) > > Different results. > > > I think the problem is that gdb is not recognizing the stdin > redirection to filter.rsf. It thinks that stdin is still stdin. > > Specifically, in simtab.c > void sf_simtab_input (sf_simtab table, FILE* fp, FILE* out) /*< > extract parameters from a file >*/ { > char line[LINELEN], word[LINELEN], *cl, *cw; > int c; > enum {START, INAWORD, STRING} state; > > while (NULL != fgets(line,4,fp)) { > > It seems to be waiting here for input from the console. > > > > What am I doing wrong? Or alternatively, how do people debug these programs? > > Thanks, > Tom |