2.6. Using the Debugger

Before we can make full use of the debugger, we must recompile hello.adb using the compiler's debug option. This option tells the compiler to include information about the source code, and the mapping of source code to generated code. Then the debugger can operate at source code level rather than at machine code level.

The debug information does not alter the generated code in any way but it does make object code files much bigger. Normally this is not a problem, but if you wish to remove the debug information from a file, then use the object code utility leon-coff-strip.

This is how we recompile hello.adb with the -g option. There are other debug options too. See the LEON Ada User's Guide for more information on debug options.

Example 2-13. Recompiling with the Debug Option

$ leon-coff-gnatmake -f -g hello
leon-coff-gcc -c -g hello.adb
leon-coff-gnatbind -x hello.ali
leon-coff-gnatlink -g hello.ali

The debugger is leon-coff-gdb. By default the debugger will run a LEON program on the LEON simulator. If you prefer to run and debug on a real LEON then you must arrange for your target to communicate with the host using the debugger's remote debug protocol. This is described in Section 2.8.

Example 2-14. Running under the Debugger

$ leon-coff-gdb hello
XGC leon-ada Version 1.8 (debugger)
Copyright (c) 1996, 2002, XGC Software.
Based on gdb version 5.1.1
Copyright (c) 1998 Free Software Foundation.
(gdb) br main
Breakpoint 1 at 0x20010b4: file b_hello.adb, line 17.
(gdb)run
Starting program: .../examples/hello
Connected to the simulator.

Breakpoint 1, main () at b~hello.adb:34
34            adainit;
(gdb)c
Continuing.
Hello world

Program exited normally.
(gdb)quit

You can view the debug information using the object dump utility, as follows:

Example 2-15. Dump of Debug Information

bash$ leon-coff-objdump -G hello

hello:     file format coff-erc

Contents of .stab section:

Symnum n_type n_othr n_desc n_value  n_strx String

-1     HdrSym 0      256    00000c46 1
0      SO     0      0      02001318 14     .../rts/
1      SO     0      0      02001318 61     x-textio.adb
2      LSYM   0      0      00000000 74     long int:t1=r1;-21.8483648;21.8483647;
3      LSYM   0      0      00000000 113    unsigned char:t2=r2;0;255;
4      LSYM   0      36     00000000 140    natural___XDLU_0__21.8483647:t3=r1;0;21.8483647;
5      LSYM   0      36     00000000 189    character:t4=r4;0;255;
6      LSYM   0      36     00000000 212    access_character:t5=*4
...