GDB is a powerful text (command-line) debugger for those of us without programming environments. There's fine linux-style (dense) documentation on line; a reference manual from the Gnu people, for instance. GDB runs from Emacs quite smoothly -- I think you type (meta-X gdb) to invoke -- so you can seamlessly debug, edit etc. You must specify the -g option to CC in your make file or compile line to make your symbol table available to gdb. Once in gdb there is Matlab-style command-line help. Just to give a flavour, here is a C program that gives the helpful "segmentation fault" error message. Often you've followed a garbage or null pointer. Often you're somewhere in a complex program. And it used to be that printfs didn't always help since the output was buffered and the program died before flushing the buffer. That doesn't happen here, so maybe that problem is fixed. Anyway, you can copy and run this program to get an error. Makefile: /**********klip***********/ OBJS = gdbtest.o # set debugging FLAGS = -g prlist: $(OBJS) gcc -o prlist $(OBJS) gdbtest.o: gdbtest.c $(INCS) gcc -c $(FLAGS) gdbtest.c # gmake will change the above gcc to $(CC), which is normally cc. clean: rm *.o /**********klip***********/ gdbtest.c /**********klip***********/ #include #include #include #define true 1 typedef struct node { int value; struct node * next; } *node_t; node_t make_list (int n) { node_t head; node_t newnode; int i; head = NULL; for (i = n; i>0; i--) { newnode = (node_t) malloc (sizeof (struct node)); newnode -> value = i; newnode -> next = head; head = newnode; } return (head); } void print_list (node_t alist, int n) { node_t ptr; int i; printf("\n"); for (i = 1; i <= n; i++) { printf(" %d", alist -> value); alist = alist-> next; } /* fflush(stdout); if in doubt you can flush the buffer yourself*/ } int main() { int j; node_t mylist; int maxj; maxj = 10; mylist = make_list(8); for (j = 1; j<= maxj; j++) { print_list (mylist,j); } } /************ klip ****************/ I do: % make -or- % cc -g gdbtest.c // compile with debugging, link and put executable in a.out % mv a.out prlist // rename executable Then the big moment: % ./prlist 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 Segmentation fault Dang. Luckily, using gdb is simple: Here's a transcript invoking the debugger on the executable, moving up and down the execution stack, listing the code around the problem statement, printing out variable values (which reveals your problem trying to follow the null pointer 0x0.). You can of course set breakpoints, do single stepping, etc. Type help for meta-help. Onward: % gdb prlist GNU gdb Red Hat Linux (6.6-16.fc7rh) Copyright (C) 2006 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 "i386-redhat-linux-gnu"... Using host libthread_db library "/lib/libthread_db.so.1". (gdb) run Starting program: /home/vax1/u25/brown/Ceg/prlist 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 Program received signal SIGSEGV, Segmentation fault. 0x080484bc in print_list (alist=0x0, n=9) at gdbtest.c:38 38 printf(" %d", alist -> value); (gdb) up #1 0x08048534 in main () at gdbtest.c:53 53 print_list (mylist,j); (gdb) up Initial frame selected; you cannot go up. (gdb) down #0 0x080484bc in print_list (alist=0x0, n=9) at gdbtest.c:38 38 printf(" %d", alist -> value); (gdb) list 33 node_t ptr; 34 int i; 35 printf("\n"); 36 for (i = 1; i <= n; i++) 37 { 38 printf(" %d", alist -> value); 39 alist = alist-> next; 40 } 41 fflush(stdout); 42 } (gdb) print ptr $1 = (node_t) 0x9964078 (gdb) print alist $2 = (node_t) 0x0 (gdb) quit