This is a mirror of official site: http://jasper-net.blogspot.com/

Writing a .net debugger (part 2) – handling events and creating wrappers

| Sunday, October 24, 2010
In this part I will describe which events the debugger has to deal with and how it should respond to them. Additionally we will create few COM wrappers for ICorDebug* interfaces. Let’s first examine the ICorDebugManagedCallback interface (imported from COM object – more in part 1). You may notice that each event handler has its own set of parameters, but the first parameter is always of type either ICorDebugAppDomain or ICorDebugProcess. Both ICorDebugAppDomain and ICorDebugProcess implement ICorDebugController which allows you to control the debuggee.

In part 1 we ended with an application that could start a new process or attach to the running one and then stop it. We will now find a way to make the process running and log all events coming from it. Let’s introduce a simple HandleEvent method which will be called from all other event handlers (except ICorDebugManagedCallback.ExitProcess):

void HandleEvent(ICorDebugController controller)
{
   Console.WriteLine("event received");
   controller.Continue(0);
}

All events handlers bodies (except ICorDebugManagedCallback.ExitProcess) will now look as follows:

{
   HandleEvent(pAppDomain); // or HandleEvent(pProcess) if first parameter is pProcess
}

If we now execute our application it will print few “event received” messages and then stop. Under the debugger we will see that the debugging API throws a COM exception:

System.Runtime.InteropServices.COMException crossed a native/managed boundary
 Message=Unrecoverable API error. (Exception from HRESULT: 0x80131300)
 Source=mindbg
 ErrorCode=-2146233600
 StackTrace:
      at MinDbg.NativeApi.ICorDebugController.Continue(Int32 fIsOutOfBand)
      at ...


Read more: Low Level Design

Posted via email from .NET Info

1 comments:

Anonymous said...

Отличная статья! большое спасибо автору за интересный материал. Удачи в развитии!!! :)
--
http://www.miriadafilms.ru/
[url=http://mpeg4.com.ru/index.shtml]Документальные скачать[/url]