Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a string description of a Win32 crash while in Top level filter (I am looking for the address of the instruction at the top of the stack)

If I use a class/method like the one described here how can I get the description/address of the call at the top of the stack?

Basically I want some value I can use in a call to our bug tracking system. I want to "uniquely" identify based on the address of the instruction that caused the exception.

(It is usually something of the form of mydll.dll!1234ABDC())

EDIT:

Some background information:

I am creating a minidump to email to a defect tracking system (fogbugz). In order to reduce duplicates I am trying to come up with a reasonable "signature" for the crash. I know there is an xml PI for FB, but it requires a user logon and we are not sure yet that we can afford to have people sniffing our traffic and getting user information. Emailing is also simpler for now to implement. Later on we will use the XML API to submit minidumps.

like image 204
Tim Avatar asked Mar 01 '10 21:03

Tim


1 Answers

You need to put the code to do this in your exception filter, by the time you get to the exception handler much of the context information for the exception has been lost.

try 
{
  // whatever
}
except (MyExceptionFilter(GetExceptionInformation()))
{
}

Your filter will look something like this

LONG WINAPI MyExceptionFilter (
   EXCEPTION_POINTERS * pExcept,
   BOOL                 fPassOn)
{
   EXCEPTION_RECORD * pER = pExcept->ExceptionRecord;
   DWORD dwExceptionCode = pER->ExceptionCode;

   TCHAR szOut[MAX_PATH*4]; // exception output goes here.
   szOut[0] = 0;

   MEMORY_BASIC_INFORMATION mbi;
   DWORD cb = VirtualQuery (pER->ExceptionAddress, &mbi, sizeof(mbi));
   if (cb == sizeof(mbi))
      {
      TCHAR szModule[MAX_PATH];
      if (GetModuleFileName ((HMODULE)mbi.AllocationBase, szModule, MAX_PATH))
         {
         wsprintf(szOut, "Exception at '%s' + 0x%X", szModule, 
                  (ULONG_PTR)pER->ExceptionAddress - (ULONG_PTR)mbi.AllocationBase);
         }
      }

   return EXCEPTION_EXECUTE_HANDLER;
}

Of course, you will need to adjust your output a bit for 64 bit architectures, since the ExceptionAddress and AllocationBase will be 64 bit quantities in that case.

like image 160
John Knoeller Avatar answered Sep 28 '22 03:09

John Knoeller