How to use the Break and BreakPoint functions in the ICorDebugManagedCallback interface
Now I want to write a .NET Debugger using CLR debugging API cordebug.tlb.When I implement the ICorDebugManagedCallback interface,I find I am not clearly about the Break and BreakPoint events.
When meeting with a breakpoint,the debugger needs to judge if the breakpoint address is at the entry or at the return of a function.If it is a breakpoint at entry,we log the function name,param value,otherwise log the breakpoint information at the return site.
In c++,there is a structure named DEBUG_EVENT,we can do this when the ExceptionCode is EXCEPTION_BREAKPOINT.But I don't know corresponding event in the CLR API.
By the way,there is a Exception in my program.
ICorDebug m_pICorDebug;
int size;
NativeApi.GetCORVersion(null, 0, out size);
Debug.Assert(size > 0);
StringBuilder sb = new StringBuilder(size);
int hr = NativeApi.GetCORVersion(sb, sb.Capacity, out size);
Marshal.ThrowExceptionForHR(hr);
string debuggerVersion = sb.ToString();if (debuggerVersion.StartsWith("v1"))
{
throw new ArgumentException("Can't debug a version 1 CLR process (\"" + debuggerVersion +"\"). Run application in a version 2 CLR, or use a version 1 debugger instead.");
}NativeApi.CreateDebuggingInterfaceFromVersion((int)NativeApi.CorDebuggerVersion.Whidbey, debuggerVersion, out m_pICorDebug);
Debug.Assert(m_pICorDebug != null);
if (m_pICorDebug == null)
throw new ArgumentException("Cannot be null.", "m_pICorDebug");
ManagedEventHander m_pManagedCallback = new ManagedEventHander(this);
m_pICorDebug.Initialize();
if (m_pManagedCallback != null)
{
m_pICorDebug.SetManagedHandler((ICorDebugManagedCallback )m_pManagedCallback);
}
System.InvalidCastException:Specified cast is not valid.
at CORDBLib.ICorDebug.SetManagedHander<ICorDebugManagedCallback pCallback>
'CMonitor.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CMonitor.exe' (Managed): Loaded 'E:\CMonitor\CMonitor\bin\Debug\CMonitor.exe', Symbols loaded.
'CMonitor.exe' (Managed): Loaded 'E:\CMonitor\CMonitor\bin\Debug\CORDBLib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CMonitor.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CMonitor.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CMonitor.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CMonitor.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CMonitor.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[1832] CMonitor.exe: Managed' has exited with code -1073741510 (0xc000013a).
I don't know what's wrong with my program .Can somebody help me?
Thank you! And Best Wishes!- PřesunutýGuo Surfer 9. března 2009 6:53 (Moved from Visual C# General to Building Development and Diagnostic Tools for .Net)
Odpovědi
The invalid cast exception is probably an STA / MTA thing. ICorDebug can't be accessed on the STA.
See for details: http://blogs.msdn.com/jmstall/archive/2005/09/15/icordebug_mta_sta.aspxThe native DEBUG_EVENT structure are for native debugging (although we have some managed wrappers in Mdbg, alluded to here: http://blogs.msdn.com/jmstall/archive/2006/07/05/managed-wrappers-for-native-debug-api.aspx )
For CLR debugging, use the ICorDebugBreakpoint API. Check out the "break" command in the Mdbg sources for an example.
Basically, IcorDebug APIs for debugging managed code are at a higher abstraction API then the APIs for debugging native code.
http://blogs.msdn.com/jmstall- Označen jako odpověďJon LangdonMSFT, Vlastník9. června 2009 18:11
Všechny reakce
The invalid cast exception is probably an STA / MTA thing. ICorDebug can't be accessed on the STA.
See for details: http://blogs.msdn.com/jmstall/archive/2005/09/15/icordebug_mta_sta.aspxThe native DEBUG_EVENT structure are for native debugging (although we have some managed wrappers in Mdbg, alluded to here: http://blogs.msdn.com/jmstall/archive/2006/07/05/managed-wrappers-for-native-debug-api.aspx )
For CLR debugging, use the ICorDebugBreakpoint API. Check out the "break" command in the Mdbg sources for an example.
Basically, IcorDebug APIs for debugging managed code are at a higher abstraction API then the APIs for debugging native code.
http://blogs.msdn.com/jmstall- Označen jako odpověďJon LangdonMSFT, Vlastník9. června 2009 18:11

