

Checking return codes and intro to gdb


openFile

	run ./openFileBroken NUM_FILE
	should work fine
	
	this is ready to turn in right?

	wrong
	
	try 
	
	./openFile 


	OR

	./openFile foo

	OR


	what is the problem?


Segmentation Fault

see core file



	find it using gdb


crux:~/public_html/cs450.fa2001/labs/debugging/openFile> gdb openFileBroken core
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.6"...
(gdb) run
Starting program: /afs/clarkson.edu/users/j/n/jnm/public_html/cs450.fa2001/labs/debugging/openFile/openFileBroken 
 
Program received signal SIGSEGV, Segmentation fault.
0xef6e6104 in _doscan () from /usr/lib/libc.so.1
(gdb) where
#0  0xef6e6104 in _doscan () from /usr/lib/libc.so.1
#1  0xef6ea84c in fscanf () from /usr/lib/libc.so.1
#2  0x10694 in main (argc=1, argv=0xeffff8a4) at openFileBroken.c:12
(gdb) f 2
#2  0x10694 in main (argc=1, argv=0xeffff8a4) at openFileBroken.c:12
12        fscanf(infile, "%d", &num);
(gdb) print infile
$1 = (FILE *) 0x0
(gdb) 



opening a null infile - well we didn't give it one
OR we gave it one that didn't exist

we should check that argv[1] is passed in

and than when we open a file it exists
______________________________________________________________


is this the only problem?

	./openFile  STRING_FILE

	./openFile EMPTY_FILE

	seem to give an answer is it right?


__________________________________________________________


gdb executbable core

gdb executable

run

break main

break  foo.c:line

info breakpoints 

where

frame n
(some variables only print when in a given frame)

delete <break number>

print num


print infile

print *infile 
	before fopen
	after fopen
	after fscanf

s vs n
	s steps in
	n steps over



--------------------------

show without -g get no symbol info







