Next Previous Contents

## 28. SDCDB - Source level debugger.

SDCC is distributed with a source level debugger. The debugger uses a command line interface, the command repertoire of the debugger has been kept as close to gdb ( the GNU debugger) as possible. The configuration and build process of the compiler see Installation also builds and installs the debugger in the target directory specified during configuration. The debugger allows you debug BOTH at the C source and at the ASM source level.

## 28.1 Compiling for debugging.

The --debug option must be specified for all files for which debug information is to be generated. The complier generates a .cdb file for each of these files. The linker updates the .cdb file with the address information. This .cdb is used by the debugger .

## 28.2 How the debugger works.

When the --debug option is specified the compiler generates extra symbol information some of which are put into the the assembler source and some are put into the .cdb file, the linker updates the .cdb file with the address information for the symbols. The debugger reads the symbolic information generated by the compiler & the address information generated by the linker. It uses the SIMULATOR (Daniel's S51) to execute the program, the program execution is controlled by the debugger. When a command is issued for the debugger, it translates it into appropriate commands for the simulator .

## 28.3 Starting the debugger.

The debugger can be started using the following command line. (Assume the file you are debugging has

the file name foo).

    >sdcdb foo

The debugger will look for the following files.

1. foo.c - the source file.
2. foo.cdb - the debugger symbol information file.
3. foo.ihx - the intel hex format object file.

## 28.4 Command line options.

- --directory=<source file directory> this option can used to specify the directory search list. The debugger will look into the directory list specified for source , cdb & ihx files. The items in the directory list must be separated by ':' , e.g. if the source files can be in the directories /home/src1 and /home/src2, the --directory option should be --directory=/home/src1:/home/src2 . Note there can be no spaces in the option.
- -cd <directory> - change to the <directory>.
- -fullname - used by GUI front ends.
- -cpu <cpu-type> - this argument is passed to the simulator please see the simulator docs for details.
- -X <Clock frequency > this options is passed to the simulator please see simulator docs for details.
- -s <serial port file> passed to simulator see simulator docs for details.
- -S <serial in,out> passed to simulator see simulator docs for details.

## 28.5 Debugger Commands.

As mention earlier the command interface for the debugger has been deliberately kept as close the GNU debugger gdb , as possible, this will help int integration with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing for the GNU debugger.

### break [line | file:line | function | file:function]

Set breakpoint at specified line or function.

    sdcdb>break 100
    sdcdb>break foo.c:100
    sdcdb>break funcfoo
    sdcdb>break
     foo.c:funcfoo

### clear [line | file:line | function | file:function ]

Clear breakpoint at specified line or function.

    sdcdb>clear 100
    sdcdb>clear foo.c:100
    sdcdb>clear funcfoo
    sdcdb>clear
     foo.c:funcfoo

### continue

Continue program being debugged, after breakpoint.

### finish

Execute till the end of the current function.

### delete [n]

Delete breakpoint number 'n'. If used without any option clear ALL user defined break points.

### info [break | stack | frame | registers ]

- info break - list all breakpoints
- info stack - show the function call stack.
- info frame - show information about the current execution frame.
- info registers - show content of all registers.

### step

Step program until it reaches a different source line.

### next

Step program, proceeding through subroutine calls.

### run

Start debugged program.

### ptype variable

Print type information of the variable.

### print variable

print value of variable.

### file filename

load the given file name. Note this is an alternate method of loading file for debugging.

### frame

print information about current frame.

### set srcmode

Toggle between C source & assembly source.

### ! simulator command

Send the string following '!' to the simulator, the simulator response is displayed. Note the debugger does not interpret the command being sent to the simulator, so if a command like 'go' is sent the debugger can loose its execution context and may display incorrect values.

### quit.

"Watch me now. Iam going Down. My name is Bobby Brown"

## 28.6 Interfacing with XEmacs.

Two files are (in emacs lisp) are provided for the interfacing with XEmacs, sdcdb.el and sdcdbsrc.el. These two files can be found in the $(prefix)/bin directory after the installation is complete. These files need to be loaded into XEmacs for the interface to work, this can be done at XEmacs startup time by inserting the following into your '.xemacs' file (which can be found in your HOME directory) (load-file sdcdbsrc.el) [ .xemacs is a lisp file so the () around the command is REQUIRED), the files can also be loaded dynamically while XEmacs is running, set the environment variable 'EMACSLOADPATH' to the installation bin directory [$(prefix)/bin], then enter the following command ESC-x load-file sdcdbsrc . To start the interface enter the following command ESC-x sdcdbsrc , you will prompted to enter the file name to be debugged.

The command line options that are passed to the simulator directly are bound to default values in the file sdcdbsrc.el the variables are listed below these values maybe changed as required.

- sdcdbsrc-cpu-type '51
- sdcdbsrc-frequency '11059200
- sdcdbsrc-serial nil

The following is a list of key mapping for the debugger interface.

    ;; Current Listing ::
    ;;key               binding                      Comment

    ;;---               -------                      -------
    ;;
    ;; n
     sdcdb-next-from-src          SDCDB next command
    ;; b               sdcdb-back-from-src          SDCDB
     back command
    ;; c               sdcdb-cont-from-src          SDCDB continue
     command
    ;; s               sdcdb-step-from-src          SDCDB step command

    ;; ?               sdcdb-whatis-c-sexp          SDCDB ptypecommand for data
     at
    ;;                                           buffer point
    ;; x
     sdcdbsrc-delete              SDCDB Delete all breakpoints if no arg
    ;;                                              given
     or delete arg (C-u arg x)
    ;; m               sdcdbsrc-frame               SDCDB
     Display current frame if no arg,
    ;;                                              given
     or display frame arg
    ;;                                             buffer
     point
    ;; !               sdcdbsrc-goto-sdcdb          Goto the SDCDB output
     buffer
    ;; p               sdcdb-print-c-sexp           SDCDB print command
     for data at
    ;;                                           buffer point
    ;;
     g               sdcdbsrc-goto-sdcdb          Goto the SDCDB output buffer
    ;;
     t               sdcdbsrc-mode                Toggles Sdcdbsrc mode (turns it
     off)
    ;;
    ;; C-c C-f         sdcdb-finish-from-src        SDCDB finish command

    ;;
    ;; C-x SPC         sdcdb-break                  Set break for line with
     point
    ;; ESC t           sdcdbsrc-mode                Toggle Sdcdbsrc mode

    ;; ESC m           sdcdbsrc-srcmode             Toggle list mode
    ;;

Next Previous Contents