Search code examples
debugginggdbsamba

How Should I Debug Samba with GDB


I'm not good at English, and I'm sorry about that. Now, There is a question about when I debug samba with GDB.

    # gdb /usr/local/samba/sbin/smbd
    GNU gdb Red Hat Linux (5.2.1-4)
    Copyright 2002 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"...
    (gdb) r
    Starting program: /usr/local/samba/sbin/smbd 
    Program exited normally.
    (gdb) info program

The program being debugged is not being run. So, How should I debug samba with GDB?

ps: Version of Samba 3.0.5 I install samba from source code.


Solution

    1. Download samba source code from http://www.samba.org and compile it (without source code, it will be impossible to do symbolic debugging).
    2. Stop or kill any other samba instances.
    3. Start samba under gdb:

      gdb <path/to/compiled/smbd>
      
    4. Specify smbd parameters:

      set args -i -M single
      

    Parameters -i -M single force smbd to start as single process, do not daemonize and print all messages and errors to stdout/stderr.

    Now, you can set breakpoints and trace your source code as you normally would with any other program.

    Note: instead of using gdb, you might find more convenient to use gdb-tui (gdb text user interface), or use other debuggers like ddd.