Friday, May 16, 2014

How to debug unknown exception in AIX system using dbx?

dbx is the equivalent of gdb debugger in Linux.
Let's assume you have an issue with an application which terminates with an exception in the AIX system.
You don't know where this exception is thrown in the code and the exception message is not very clear to you. The first thing to you need to know is where this exception gets thrown in the code so you can fix the issue. Here is the trick:

>dbx  myprogram

(dbx) stop in __ThrowV6  //break at any exception, __ThrowV6 is the exception handler. All exceptions will go to this exception handler. If you stop here and view the stack you will know exactly where the exception is being thrown.
(dbx) r -c arguments   //run the program with specific arguments


This trick above is handy if you don't know where to set a break point in the program since the exception can be thrown in many places in the code. Some code does handle the exception, but it would just print out a generic message which is useless. It is a good idea to handle the exception and print out the real message.

#include <exception>
using namespace std;
try
{
....
}
catch(exceptio& e)
{
cout << e.what() << endl; //this will print out the actually error causing the exception.
}

No comments: