2.5. Using the Debugger

Before we can make full use of the debugger, we must recompile hello.adb using the 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 m1750-coff-strip.

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

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

The debugger is m1750-coff-gdb. By default the debugger will run a M1750 program on the M1750 simulator. If you prefer to run and debug on a real M1750 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.7.

Example 2-5. Running under the Debugger

$ m1750-coff-gdb hello
XGC m1750-ada Version 1.7 (debugger)
Copyright (c) 1996, 2001, XGC Software.
Based on gdb version 4.17.gnat.3.11
Copyright (c) 1998 Free Software Foundation...
(gdb)break main
Breakpoint 1 at 0x408: file b~hello.adb, line 29.
(gdb)run
Starting program: /home/nettleto/xgc/m1750-ada/examples/hello 
Connected to the simulator.
Loading sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .init         000003fa  00000000  00000000  00001000  2**1
                  CONTENTS, ALLOC, LOAD, CODE
  1 .text         000005e6  000003fa  000003fa  000013fa  2**1
                  CONTENTS, ALLOC, LOAD, CODE
  2 .rdata        0000006c  000009e0  000009e0  000019e0  2**1
                  CONTENTS, ALLOC, LOAD, READONLY
  3 .data         000000d4  00010000  00000a4c  00002000  2**1
                  CONTENTS, ALLOC, LOAD, DATA
Start address 0x0
Transfer rate: 22784 bits in <1 sec.

Breakpoint 1, main () at b~hello.adb:29
29            adainit;
(gdb)continue
Continuing.
Hello World

Program exited normally.
(gdb)quit

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

Example 2-6. Dump of Debug Information

bash$ m1750-coff-objdump -G hello

hello:     file format coff-m1750

Contents of .stab section:

Symnum n_type n_othr n_desc n_value  n_strx String

-1     HdrSym 0      700    00001508 1     
0      SO     0      0      00000438 14     /home/opt/m1750-ada-1.7/m1750-coff/src/libada/rts/
1      SO     0      0      00000438 1      x-textio.adb
2      LSYM   0      0      00000000 66     long int:t1=r1;-32768;32767;
3      LSYM   0      0      00000000 95     unsigned char:t2=r2;0;65535;
4      LSYM   0      0      00000000 124    long integer:t3=r1;0020000000000;0017777777777;
...