libtool: Debugging executables

1 
1 3.4 Debugging executables
1 =========================
1 
1 If 'hell' was a complicated program, you would certainly want to test
1 and debug it before installing it on your system.  In the above section,
1 you saw how the libtool wrapper script makes it possible to run the
1 program directly, but unfortunately, this mechanism interferes with the
1 debugger:
1 
1      burger$ gdb hell
1      GDB is free software and you are welcome to distribute copies of it
1       under certain conditions; type "show copying" to see the conditions.
1      There is no warranty for GDB; type "show warranty" for details.
1      GDB 4.16 (i386-unknown-netbsd), (C) 1996 Free Software Foundation, Inc.
1 
1      "hell": not in executable format: File format not recognized
1 
1      (gdb) quit
1      burger$
1 
1    Sad.  It doesn't work because GDB doesn't know where the executable
1 lives.  So, let's try again, by invoking GDB directly on the executable:
1 
1      burger$ gdb .libs/hell
1      GNU gdb 5.3 (i386-unknown-netbsd)
1      Copyright 2002 Free Software Foundation, Inc.
1      GDB is free software, covered by the GNU General Public License,
1      and you are welcome to change it and/or distribute copies of it
1      under certain conditions.  Type "show copying" to see the conditions.
1      There is no warranty for GDB.  Type "show warranty" for details.
1      (gdb) break main
1      Breakpoint 1 at 0x8048547: file main.c, line 29.
1      (gdb) run
1      Starting program: /home/src/libtool/demo/.libs/hell
1      /home/src/libtool/demo/.libs/hell: can't load library 'libhello.so.0'
1 
1      Program exited with code 020.
1      (gdb) quit
1      burger$
1 
1    Argh.  Now GDB complains because it cannot find the shared library
1 that 'hell' is linked against.  So, we must use libtool to properly set
1 the library path and run the debugger.  Fortunately, we can forget all
1 about the '.libs' directory, and just run it on the executable wrapper
1 (⇒Execute mode):
1 
1      burger$ libtool --mode=execute gdb hell
1      GNU gdb 5.3 (i386-unknown-netbsd)
1      Copyright 2002 Free Software Foundation, Inc.
1      GDB is free software, covered by the GNU General Public License,
1      and you are welcome to change it and/or distribute copies of it
1      under certain conditions.  Type "show copying" to see the conditions.
1      There is no warranty for GDB.  Type "show warranty" for details.
1      (gdb) break main
1      Breakpoint 1 at 0x8048547: file main.c, line 29.
1      (gdb) run
1      Starting program: /home/src/libtool/demo/.libs/hell
1 
1      Breakpoint 1, main (argc=1, argv=0xbffffc40) at main.c:29
1      29        printf ("Welcome to GNU Hell!\n");
1      (gdb) quit
1      The program is running.  Quit anyway (and kill it)? (y or n) y
1      burger$
1