This message was discovered on microsoft.public.dotnet.framework.clr.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Aniskevich Sergey via .NET 247 (VIP) |
I am have problem with Debugging API under C# (Framework 2.0). A am run Debugged process as follows:
int size; GetCORVersion(null, 0, out size); Debug.Assert(size > 0); StringBuilder sb = new StringBuilder(size); int hr = GetCORVersion(sb, sb.Capacity, out size);
CreateDebuggingInterfaceFromVersion(3, sb.ToString(), out m_ICorDebug); Debug.Assert(m_ICorDebug != null);
m_ICorDebug.Initialize(); CManagedCallback _mc = new CManagedCallback(this); m_ICorDebug.SetManagedHandler(_mc);
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
STARTUPINFO si = new STARTUPINFO(); si.cb = Marshal.SizeOf(si);
// initialize safe handles si.hStdInput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false); si.hStdOutput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false); si.hStdError = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
//constrained execution region (CER) System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions(); string commandLine = "WindowsApplication1.exe"; string applicationName = null; int flags = 0; string currentDirectory = "."; IntPtr environment = new IntPtr(0);
m_ICorDebug.CreateProcess( applicationName, commandLine, null, null, 1, (uint)flags, environment, currentDirectory, si, pi, CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS, out m_ICorDebugProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hProcess);
But one function of a class (CManagedCallbck : ICorDebugManagedCallback) is not callback. In what a problem?
Best regards
----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>SOeem8tB8UWHhvFHTwmSdA==</Id>
|
|
|
| |
|
|
| |
| |
| Jan Stranik (VIP) |
Hello Aniskevich, from your code snippet I cannot determine why is your code not working. Generally it is possible to write a debugger in managed code. We have a complete sample of managed debugger written in C#, feel free to refer to it for your needs, The sample is located at: http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28- 80ce-c55645ab1310&displaylang=en.
Regards /jan
-------------------- [Original message clipped]
8.phx.gbl!TK2MSFTNGP14.phx.gbl [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Sergey |
Thanks for your answer. I studied before your example (http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28-80ce-c55645ab1310&displaylang=en" target="_blank">http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28-80ce-c55645ab1310&displaylang=en), however it very complex and I has got confused.
If it is possible, send, please, the simple example in which occurs creation ICorDebug, ICorDebugManagedCallback and calling method CreateProcess.
Beforehand thanks. e-mail: Click here to reveal e-mail address
Click here to reveal e-mail address (Jan Stranik) wrote in message news:<Click here to reveal e-mail address>... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Jan Stranik (VIP) |
Hello Aniskevich, I understand the reading (and also writing) debugger code is non-trivial. The API is pretty complicated. On the other hand you need to expect non-trivial API for anything that is doing so powerfull operation as enabling debugging.
I recommend you studying code in the corapi\debug directory first in the sample. Also, please refer to CorDebug.idl header file that describes what individual API do.
If you want to learn more about the debugger, and would like to get to some more simplistic code, I would recommand, that you start with the mentioned sample and keep removing parts that you don't need.
/jan
-------------------- | From: Click here to reveal e-mail address (Sergey) | Newsgroups: microsoft.public.dotnet.framework.clr | Subject: Re: Debugger API | Date: 13 Sep 2004 23:00:17 -0700 | Organization: http://groups.google.com | Lines: 115 | Message-ID: <Click here to reveal e-mail address> | References: <#Click here to reveal e-mail address> <Click here to reveal e-mail address> | NNTP-Posting-Host: 195.225.130.127 | Content-Type: text/plain; charset=ISO-8859-1 | Content-Transfer-Encoding: 8bit | X-Trace: posting.google.com 1095141617 7566 127.0.0.1 (14 Sep 2004 06:00:17 GMT) | X-Complaints-To: Click here to reveal e-mail address | NNTP-Posting-Date: Tue, 14 Sep 2004 06:00:17 +0000 (UTC) | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin e.de!news.glorb.com!postnews2.google.com!not-for-mail | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.clr:11802 | X-Tomcat-NG: microsoft.public.dotnet.framework.clr | | Thanks for your answer. | I studied before your example | (http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28 -80ce-c55645ab1310&displaylang=en), | however it very complex and I has got confused. | | If it is possible, send, please, the simple example in which occurs | creation ICorDebug, ICorDebugManagedCallback and calling method | CreateProcess. | | | Beforehand thanks. | e-mail: Click here to reveal e-mail address | | Click here to reveal e-mail address (Jan Stranik) wrote in message news:<Click here to reveal e-mail address>... | > Hello Aniskevich, | > from your code snippet I cannot determine why is your code not working. | > Generally it is possible to write a debugger in managed code. | > We have a complete sample of managed debugger written in C#, feel free to | > refer to it for your needs, | > The sample is located at: | > http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28- | > 80ce-c55645ab1310&displaylang=en. | > | > Regards | > /jan | > | > -------------------- | > >From: Aniskevich Sergey via .NET 247 <Click here to reveal e-mail address> | > >X-Newsreader: AspNNTP 1.50 (Matthew Reynolds Consulting) | > >Subject: Debugger API | > >Mime-Version: 1.0 | > >Content-Type: text/plain; charset="us-ascii" | > >Content-Transfer-Encoding: 7bit | > >Message-ID: <#Click here to reveal e-mail address> | > >Newsgroups: microsoft.public.dotnet.framework.clr | > >Date: Fri, 03 Sep 2004 02:58:52 -0700 | > >NNTP-Posting-Host: 81-86-69-114.dsl.pipex.com 81.86.69.114 | > >Lines: 1 | > >Path: | > cpmsftngxa10.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP0 | > 8.phx.gbl!TK2MSFTNGP14.phx.gbl | > >Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.clr:11779 | > >X-Tomcat-NG: microsoft.public.dotnet.framework.clr | > > | > >I am have problem with Debugging API under C# (Framework 2.0). A am run | > Debugged process as follows: | > > | > >int size; | > > GetCORVersion(null, 0, out size); | > > Debug.Assert(size > 0); | > > StringBuilder sb = new StringBuilder(size); | > > int hr = GetCORVersion(sb, sb.Capacity, out size); | > > | > > CreateDebuggingInterfaceFromVersion(3, sb.ToString(), out | > m_ICorDebug); | > > Debug.Assert(m_ICorDebug != null); | > > | > > m_ICorDebug.Initialize(); | > > CManagedCallback _mc = new CManagedCallback(this); | > > m_ICorDebug.SetManagedHandler(_mc); | > > | > > | > > PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); | > > | > > STARTUPINFO si = new STARTUPINFO(); | > > si.cb = Marshal.SizeOf(si); | > > | > > // initialize safe handles | > > si.hStdInput = new | > Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false); | > > si.hStdOutput = new | > Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false); | > > si.hStdError = new | > Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false); | > > | > > //constrained execution region (CER) | > > | > System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions(); | > > string commandLine = "WindowsApplication1.exe"; | > > string applicationName = null; | > > int flags = 0; | > > string currentDirectory = "."; | > > IntPtr environment = new IntPtr(0); | > > | > > m_ICorDebug.CreateProcess( | > > applicationName, | > > commandLine, | > > null, | > > null, | > > 1, | > > (uint)flags, | > > environment, | > > currentDirectory, | > > si, | > > pi, | > > | > CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS, | > > out m_ICorDebugProcess); | > > | > > CloseHandle(pi.hThread); | > > CloseHandle(pi.hProcess); | > > | > > | > > | > >But one function of a class (CManagedCallbck : ICorDebugManagedCallback) | > is not callback. | > >In what a problem? | > > | > >Best regards | > > | > >----------------------- | > >Posted by a user from .NET 247 (http://www.dotnet247.com/) | > > | > ><Id>SOeem8tB8UWHhvFHTwmSdA==</Id> | > > |
|
|
|
| |
|
|
| |
| |
| Sergey |
It is another code. The programm crash on CreateProcess, give error frame "WindowsApplication1.exe - Application Error": The application failed to initialize properly (0xc0000005). Click on Ok to terminate the application. In what a problem?
CorDebug cordbg = new CorDebug(); ICorDebug Icordbg = (ICorDebug) cordbg; Icordbg.Initialize();
CManagedCallback callback = new CManagedCallback(); Icordbg.SetManagedHandler((ICorDebugManagedCallback)callback); STARTUPINFO si = new STARTUPINFO(); PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); si.cb = Marshal.SizeOf(si); System.String lpApplicationName = "C:\\WindowsApplication1.exe"; System.String lpCommandLine = ""; CORDBLib._SECURITY_ATTRIBUTES lpProcessAttributes = new _SECURITY_ATTRIBUTES(); CORDBLib._SECURITY_ATTRIBUTES lpThreadAttributes = new _SECURITY_ATTRIBUTES(); System.Int32 bInheritHandles = 0; System.UInt32 dwCreationFlags = 0; System.IntPtr lpEnvironment = IntPtr.Zero; System.String lpCurrentDirectory ="."; IntPtr gch_si =(IntPtr) GCHandle.Alloc( si ); IntPtr gch_pi =(IntPtr) GCHandle.Alloc( pi ); System.UInt32 lpStartupInfo = (UInt32) gch_si; System.UInt32 lpProcessInformation = (UInt32) gch_pi; CORDBLib.CorDebugCreateProcessFlags debuggingFlags ; ICorDebugProcess ppProcess = null;
Icordbg.CreateProcess ( lpApplicationName, lpCommandLine, ref lpProcessAttributes, ref lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, CORDBLib.CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS, out ppProcess); }
|
|
|
| |
|
| |
|
| |
| Sergey |
It is another code that crash in Icordbg.CreateProcess: "The application failed to initialize properly (0xc0000005)."
CorDebug cordbg = new CorDebug(); ICorDebug Icordbg = (ICorDebug) cordbg; Icordbg.Initialize();
CManagedCallback callback = new CManagedCallback(); Icordbg.SetManagedHandler((ICorDebugManagedCallback)callback); STARTUPINFO si = new STARTUPINFO(); PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); si.cb = Marshal.SizeOf(si); System.String lpApplicationName = "C:\\WindowsApplication1.exe"; System.String lpCommandLine = ""; CORDBLib._SECURITY_ATTRIBUTES lpProcessAttributes = new _SECURITY_ATTRIBUTES(); CORDBLib._SECURITY_ATTRIBUTES lpThreadAttributes = new _SECURITY_ATTRIBUTES(); System.Int32 bInheritHandles = 0; System.UInt32 dwCreationFlags = 0x0020; System.IntPtr lpEnvironment = IntPtr.Zero; System.String lpCurrentDirectory ="."; IntPtr gch_si =(IntPtr) GCHandle.Alloc( si ); IntPtr gch_pi =(IntPtr) GCHandle.Alloc( pi ); System.UInt32 lpStartupInfo = (UInt32) gch_si; System.UInt32 lpProcessInformation = (UInt32) gch_pi; CORDBLib.CorDebugCreateProcessFlags debuggingFlags ; ICorDebugProcess ppProcess = null;
Icordbg.CreateProcess ( lpApplicationName, lpCommandLine, ref lpProcessAttributes, ref lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, CORDBLib.CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS, out ppProcess); } }
[StructLayout(LayoutKind.Sequential)] internal struct STARTUPINFO { internal int cb; [MarshalAs(UnmanagedType.LPTStr)] internal string lpReserved; [MarshalAs(UnmanagedType.LPTStr)] internal string lpDesktop; [MarshalAs(UnmanagedType.LPTStr)] internal string lpTitle; internal int dwX; internal int dwY; internal int dwXSize; internal int dwYSize; internal int dwXCountChars; internal int dwYCountChars; internal int dwFillAttribute; internal int dwFlags; internal short wShowWindow; internal short cbReserved2; internal IntPtr lpReserved2; internal IntPtr hStdInput; internal IntPtr hStdOutput; internal IntPtr hStdError; }
[StructLayout(LayoutKind.Sequential)] internal struct PROCESS_INFORMATION { internal IntPtr hProcess; internal IntPtr hThread; internal int dwProcessId; internal int dwThreadId; }
|
|
|
| |
|
|
| |
| |
| Jan Stranik (VIP) |
Aniskevich, I don't know why is your code not working. From the code snippet you have attached, I cannot tell the problem. Please refer to the working mdbg sample. /jan
-------------------- | From: Click here to reveal e-mail address (Sergey) | Newsgroups: microsoft.public.dotnet.framework.clr | Subject: Re: Debugger API | Date: 17 Sep 2004 02:05:44 -0700 | Organization: http://groups.google.com | Lines: 91 | Message-ID: <Click here to reveal e-mail address> | References: <#Click here to reveal e-mail address> <Click here to reveal e-mail address> <Click here to reveal e-mail address> <Click here to reveal e-mail address> | NNTP-Posting-Host: 195.225.130.127 | Content-Type: text/plain; charset=ISO-8859-1 | Content-Transfer-Encoding: 8bit | X-Trace: posting.google.com 1095411945 21965 127.0.0.1 (17 Sep 2004 09:05:45 GMT) | X-Complaints-To: Click here to reveal e-mail address | NNTP-Posting-Date: Fri, 17 Sep 2004 09:05:45 +0000 (UTC) | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP0 8.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!news.glorb.com!postnews2.go ogle.com!not-for-mail | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.clr:11838 | X-Tomcat-NG: microsoft.public.dotnet.framework.clr | | It is another code that crash in Icordbg.CreateProcess: | "The application failed to initialize properly (0xc0000005)." | | CorDebug cordbg = new CorDebug(); | ICorDebug Icordbg = (ICorDebug) cordbg; | Icordbg.Initialize(); | | CManagedCallback callback = new CManagedCallback(); | Icordbg.SetManagedHandler((ICorDebugManagedCallback)callback); | | STARTUPINFO si = new STARTUPINFO(); | PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); | | si.cb = Marshal.SizeOf(si); | | | | | | System.String lpApplicationName = "C:\\WindowsApplication1.exe"; | System.String lpCommandLine = ""; | CORDBLib._SECURITY_ATTRIBUTES lpProcessAttributes = new _SECURITY_ATTRIBUTES(); | CORDBLib._SECURITY_ATTRIBUTES lpThreadAttributes = new _SECURITY_ATTRIBUTES(); | System.Int32 bInheritHandles = 0; | | System.UInt32 dwCreationFlags = 0x0020; | System.IntPtr lpEnvironment = IntPtr.Zero; | System.String lpCurrentDirectory ="."; | | IntPtr gch_si =(IntPtr) GCHandle.Alloc( si ); | IntPtr gch_pi =(IntPtr) GCHandle.Alloc( pi ); | | | System.UInt32 lpStartupInfo = (UInt32) gch_si; | System.UInt32 lpProcessInformation = (UInt32) gch_pi; | | CORDBLib.CorDebugCreateProcessFlags debuggingFlags ; | ICorDebugProcess ppProcess = null; | | | Icordbg.CreateProcess ( | lpApplicationName, | lpCommandLine, | ref lpProcessAttributes, | ref lpThreadAttributes, | bInheritHandles, | dwCreationFlags, | lpEnvironment, | lpCurrentDirectory, | lpStartupInfo, | lpProcessInformation, | CORDBLib.CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS, | out ppProcess); | | } | } | | [StructLayout(LayoutKind.Sequential)] | internal struct STARTUPINFO | { | internal int cb; | [MarshalAs(UnmanagedType.LPTStr)] | internal string lpReserved; | [MarshalAs(UnmanagedType.LPTStr)] | internal string lpDesktop; | [MarshalAs(UnmanagedType.LPTStr)] | internal string lpTitle; | internal int dwX; | internal int dwY; | internal int dwXSize; | internal int dwYSize; | internal int dwXCountChars; | internal int dwYCountChars; | internal int dwFillAttribute; | internal int dwFlags; | internal short wShowWindow; | internal short cbReserved2; | internal IntPtr lpReserved2; | internal IntPtr hStdInput; | internal IntPtr hStdOutput; | internal IntPtr hStdError; | } | | [StructLayout(LayoutKind.Sequential)] | internal struct PROCESS_INFORMATION | { | internal IntPtr hProcess; | internal IntPtr hThread; | internal int dwProcessId; | internal int dwThreadId; | } |
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
|