The following discusses two ways to find the source of an exception. Both ways involve getting a a traceback of the exception. A traceback is a list of the routines were currently executing when the exception occurred. The traceback will include more information than you need, and so you will have to know where to look to find the source of the exception.
The traceback can be printed directly from within your program, or it can be printed from within gnatgdb, which is the gnat debugger. Instructions on printing from your program are given first.
With statement for the packages
ada.exceptions and gnat.traceback.symbolic in your program. symbolic_traceback(E) where E is the exception parameter.
gnatmake -f -g myprog.adb -bargs -E
Immediately below are brief instructions on how to use gdb on rucs. The instructions may not work on other machines. Instructions for AdaGIDE follow the example below.
myprog.adb on rucs.
Execute the commands listed below.
gnatmake -g -f myprog gnatgdb myprog start start < datafile.txt
which will initialize your program and specify that standard input will read from datafile.txt break exception continue backtrace
with ada.integer_text_io; use ada.integer_text_io;
procedure demogdb is
procedure demo(result: out integer) is
x: integer;
begin
get(x); -- We will input 0
result := 3 / x; -- Exception here in line 7
end demo;
y: integer;
begin
demo(y); -- demo called here in line 12
end demogdb;
0
rucs@/home/nokie/public_html/classes/320 > gnatmake -g -f demogdb
gcc-4.0 -c -g demogdb.adb
gnatbind -x demogdb.ali
gnatlink demogdb.ali -g
rucs@/home/nokie/public_html/classes/320 > gnatgdb demogdb
GNU gdb 6.4 for GNAT GPL 2006 (20060605)
Copyright 2005 Free Software Foundation, Inc.
Ada Core Technologies version of GDB for GNAT GPL
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
See your support agreement for details of warranty and support.
If you do not have a current support agreement, then there is absolutely
no warranty for this version of GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library
"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) start < demogdb.dat
Breakpoint 1 at 0x80492ea: file demogdb.adb, line 12.
Starting program: /home/nokie/public_html/classes/320/demogdb < demogdb.dat
demogdb () at demogdb.adb:12
12 demo(y);
(gdb) break exception
Breakpoint 2 at 0xb7db5cf6
(gdb) continue
Continuing.
No definition of "e.full_name" in current context.
(gdb) backtrace
#0 0xb7db5cf6 in __gnat_raise_nodefer_with_msg () from /usr/local/gnu/lib/libgnat-4.0.so.1
#1 0xb7db5f12 in ada.exceptions.raise_with_location_and_msg () from
/usr/local/gnu/lib/libgnat-4.0.so.1
#2 0xb7db5cf2 in __gnat_raise_constraint_error_msg () from /usr/local/gnu/lib/libgnat-4.0.so.1
#3 0xb7db6037 in __gnat_rcheck_03 () from /usr/local/gnu/lib/libgnat-4.0.so.1
#4 0x08049323 in demogdb.demo () at demogdb.adb:7
#5 0x080492ef in demogdb () at demogdb.adb:12
(gdb) quit
The program is running. Exit anyway? (y or n) y
rucs@/home/nokie/public_html/classes/320 >
start.