GDB tutorial
One of the things I have always struggled with in C programming is
knowing what to do when my program crashes, and inevitably, my
programs will crash. I long got over the fact that everything I
write will be bug laden and eventually crash given the right
situation. I even accept that. It's a little hurdle you have to get
over I think, and knowing that everything has bugs is the first
step to understanding why it has bugs and what to do about
bugs.
Most times
GCC does
a pretty good job of letting you know what the error is, but
sometimes I know its something a bit less obvious and I get that
sinking feeling that I have to fire up
GDB and investigate.
I have always hated GDB, it seemed cryptic to me , especially the
part where your looking at stuff like:
(gdb) n
0xb7d5fea8 in __libc_start_main () from /lib/tls/libc.so.6
(gdb) n
I think basically hexadecimal numbers make me want to run away
screaming. I searched around for some tutorials, and there are
plenty out there to be sure, but most of them tend to ignore the
fact that if you have no idea what the stack is or what frames are,
your going to spend a lot of time spinning your wheels. I found one
tutorial however that starts from the start, it's called
Peter's GDB Tutorial and
it's the best one I have found so far. It starts out with a really
good introduction to virtual memory and how memory is allocated in
Linux, and oddly enough, many of my bugs are memory bugs. One other
little plus for this tutorial is a section on debugging ncurses
which is very handy as I quite like ncurses and expect I will be
fiddling with it for a while yet before taking on something like
GTK, and then LISP, then maybe Python, oh and C++....Sigh.
I still don't look forward to using GDB, as having to use GDB means
I have done something horribly wrong, but I like it a lot more
now.