Access violation and WinDBG

 

This month, I have written an article about debugging under Windows for french magazine Programmez.

The main topic talks about how to prepare your code for advanced debugging techniques. Take a routine:


public bool InitSession()

{

try

{

Log.Instance.Info("InitSession...");

//

// Do some work ...

//

return true;

}

catch (Exception ex)

{

Log.Instance.Error("InitSession failed", ex);

return false;

}

}

Because there are logging informations and exception handling and a return value for the function, it is easy to make debugging with this kind of stuff.

If your code does not contain logging informations, your last option is to use a system debugger : WinDBG.

WinDBG is redistributed under the Windows SDK or Windows DDK. Start WInDBG and attach the process you want to debug. The debugger attaches the process and put it in pause.

Launch the command go (g) and wait for it to be in an unhandled access violation case.

Load the “Son Of Strike” DLL which is SOS.DLL : .load C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll

When your exception comes, ask for the stack dump using this command: !DumpStack

And the miracle is coming : the name of the fault routine is the first line of the dump:

In my case, the faulting routine is SDRM.Services.Svc.CallReutersWSForGrid1().

Debugging is easy (or not so complicated) when you have the right tools.

Enjoy !

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: