Finding Exception Locations

This page contains instructions on how to find out which statement caused an exception. This is particularly useful when a get routine caused the exception, because the information printed when the exception occurs only tells you that the get caused the exception. It does not tell you at what statement the get was called. The same is true if the exception occurs in some other library routine.

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.

Causing your program to print a traceback

To cause your program to print a traceback when an exception occurs, you need to do three things (as shown in this example):
  1. Include a With statement for the packages ada.exceptions and gnat.traceback.symbolic in your program.

  2. Include an exception handler that prints symbolic_traceback(E) where E is the exception parameter.

  3. Compile with certain options, like this:
           gnatmake -f -g myprog.adb -bargs -E
           

Introduction to using GDB on rucs to get a traceback

The GNU debugger gdb is used to find the statement that caused the exception. The debugger will also give you a list of the procedures that were executing when the instruction occurred. The instructions describe how to use gdb on rucs and when using AdaGIDE.

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.

Instructions for using GDB on rucs

Assume that you want to debug the file myprog.adb on rucs. Execute the commands listed below.
  1. gnatmake -g -f myprog

  2. gnatgdb myprog

  3. start

  4. break exception

  5. continue

  6. backtrace


Sample Run



Using GDB from AdaGIDE



GnatGDB Commands We've Seen



Some Other GDB Commands



Abbreviations



Using GDB from GPS