Debuggers and Capturing Error Messages
Hint: Capturing Compilation Errors From Command Line
- Sometimes it is useful to send all error messages into a file
- The obvious way to do this is to redirect the output into a file
called
errorOut
, like this:
gnatmake sayhi > errorOut
However, this does not capture the error output stream; the
normal output stream (which in this case is empty)
goes into the file, but the error stream still
goes to the console.
To capture the error output stream to the file
errorOut
do the following:
gnatmake sayhi >&! errorOut
The bang (ie the character '!') is not strictly necessary. It
allows the command to overwrite the existing file
errOut
.
This only works under linux (and unix); I don't know how to do
it in a windows cmd window
Debuggers
- A debugger will let you
- step through a program while it executes,
- examine variable values during execution,
- find what statement in your program caused an exception.
-
This rest of this page gives some information on how to use the Gnu debugger called gdb.
- It explains how to use GDB with three different environments: AdaGIDE, command line, and GPS.
Using GDB with AdaGIDE
Below are three options for an environment for creating, compiling, and running
programs:
- In the Tools/Project settings (not Global settings) window,
set or unset the following:
- Set: Debug info, Trace-back
- Unset: Strip all symbols
- Build the program (if it's already up to date, force the
recompilation by modifying, saving, then recompiling the file)
- Press Debug
- In the debugger window, do the following:
- enter "break exception"
- enter "r" (ignore the error messages that occur
- when program crashes, enter "backtrace" (or "bt")
- read down the list of routines until you
find the routines from your program. Since this is a stack, routines are
listed in most recently called order
Using GDB from the command line
- Instructions for using GDB from the command line are here
Using GDB from GPS
- Make sure the Debug option is set
- Make sure the delete symbols is NOT set
- Build your program
- Select Debug/Initialize/yourFileName
- Select Debug/Run
- Exit the debugger with Debug/Terminate