In a perfect world we wouldn't need this chapter. In a realistic world, however, one has to take into account possible errors. While every care has taken to make the framework of the MSR as error-free as possible, there still are bugs left. For sure. But usually they are difficult to find. So, if your module doesn't work, chances are big that you don't use the framework as it's supposed to be. This chapter will help you finding where the bug is. It is then up to you to find how it has to be fixed.
While running either a test-case or a radio in user-space, it is quite simple to debug it, as all other radios can be stopped during the debugging session. This is of course not possible to do in real-time...
The first thing to do when a module doesn't run and stops with a segmentation fault is to use make debug instead of make user. This will call the GNU-debugger, run the module and stop on the offending instruction. The most common commands after this are:
It's gdb. So it's an extremly powerful environment but sometimes difficult to use. Always try the help command and read everything that is on the screen.
For better debugging, for example if your module doesn't crash, but doesn't do what you expect it to do, you can use ddd. To start it, you go to the same directory where usually you type make user and type make ddd. After this, you have to type break main.c:36 and press F3 to start the program. Once it stops on the breakpoint, all necessary libraries have been loaded and also the modules you want to debug (given that you didn't make any errors in setting up the Makefile).
Now you can enter the name of a function to debug on top in the white box and press on lookup to the right of the box. Clicking with the right mouse-button on a line you can set a breakpoint. Repeat this procedure as often as necessary, then click on cont and watch what happens. next, step, right-clicking on variables are other nice options to take. Try it, break it. Debugging is an art!
On mandrake-linux, libpthreads is badly compiled, so that you can't use ddd in this distribution. Sorry. Install a debian or something...
DO NOT type run in the command-line of ddd. This runs the program without any command-line options that have been carefully crafted to work with ddd. Do use the run-button or the menu Program->Run Again. Optionally you can use the F3-key.
Linus Gasser 2004-04-14