Debugging

How to Run Bacula Under the Debugger Manually?

If for some reason you cannot get the automatic traceback, or if you want to interactively examine the variable contents after a crash, you can run Bacula under the debugger. Assuming you want to run the Storage daemon under the debugger (the technique is the same for the other daemons, only the name changes), you would do the following:

  1. Start the Director and the File daemon. If the Storage daemon also starts, you will need to find its PID (ps fax | grep bacula-sd) and kill it with a command like the following:

    kill -15 PID
    

    where you replace PID by the actual value.

  2. At this point, the Director and the File daemon should be running but the Storage daemon should not.

  3. cd to the directory containing the Storage daemon

  4. Start the Storage daemon under the debugger:

    gdb ./bacula-sd
    
  5. Run the Storage daemon:

    run -s -f -c ./bacula-sd.conf
    

    You may replace the ./bacula-sd.conf with the full path to the Storage daemon’s configuration file.

  6. At this point, Bacula will be fully operational.

  7. In another shell command window, start the Console program and do what is necessary to cause Bacula to die.

  8. When Bacula crashes, the gdb shell window will become active and gdb will show you the error that occurred.

  9. To get a general traceback of all threads, issue the following command:

    thread apply all bt
    

After that you can issue any debugging command.

How to Get Debug Output from Bacula?

Each of the daemons normally has debug compiled into the program, but disabled. There are two ways to enable the debug output. One is to add the -d nnn option on the command line when starting the debugger. The nnn is the debug level, and generally anything between 50 and 200 is reasonable. The higher the number, the more output is produced. The output is written to standard output.

The second way of getting debug output is to dynamically turn it on using the Console using the setdebug command. The full syntax of the command is:

setdebug level=nnn client=client-name storage=storage-name dir

If none of the options are given, the command will prompt you. You can selectively turn on/off debugging in any or all the daemons (i.e. it is not necessary to specify all the components of the above command).

Go back to the Bacula Enterprise Troubleshooting chapter.