f



debugger problem

I've got a problem writing a debugger. The debugging process won't get 
notificated, and the debug process won't show up, although it is 
running in task-manager.
Any idea what I did wrong? BTW: I use mingw for the program and VS 
..net for the debugger program. But that's not a problem, is it?


// --------------------------------------------------------------- //
// This is the debugger code
// --------------------------------------------------------------- //
BOOL CSampleView::DebugProgram(LPCTSTR lpPathName, LPCTSTR lpComdLine)
{
DEBUG_EVENT DebugEv;
DWORD dwContinueStatus = DBG_CONTINUE;

PROCESS_INFORMATION pi;
STARTUPINFO   si = STARTUPINFO();
si.cb = sizeof(STARTUPINFO);
if (!::CreateProcess(prog, args, NULL, NULL, FALSE,
                     NORMAL_PRIORITY_CLASS,
                     NULL, NULL, &si, &pi))
                     return FALSE;

if(!DebugActiveProcess(pi.dwProcessId)) return FALSE;
for(;;)
{
  WaitForDebugEvent(&DebugEv, INFINITE);
  switch (DebugEv.dwDebugEventCode)
  {
   case EXCEPTION_DEBUG_EVENT:
     switch (DebugEv.u.Exception.ExceptionRecord.ExceptionCode)
     {
     case OUTPUT_DEBUG_STRING_EVENT:
        CString str(DebugEv.u.DebugString.lpDebugStringData,
                    DebugEv.u.DebugString.nDebugStringLength);
        AfxMessageBox(str);
     break;
  }
  ContinueDebugEvent(DebugEv.dwProcessId, DebugEv.dwThreadId, 
dwContinueStatus);
}

// ------------------------------------
// This is the debug-process code
// ------------------------------------

if (IsDebuggerPresent())
{
  OutputDebugStringA(s);
}






-- 
-Gernot
int main(int argc, char** argv) {printf 
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com


0
Gernot
1/14/2005 12:01:48 PM
comp.os.programmer.win32 14522 articles. 0 followers. Post Follow

1 Replies
472 Views

Similar Articles

[PageSpeed] 8

I suspect but am not sure, that your process is ending before you attach
to it.  It would remain in the system because you haven't closed the
handles you got in the PROCESS_INFORMATION structure, and I'm not sure
what happens if you do try to attach at that point.

Simple way to fix it is just specify the DEBUG_PROCESS flag in the
CreateProcess call...  that way the process will not do anything until you
start waiting for events.  Then you don't need to explicitly attach.  Bear
in mind that in addition to the normal debug events (create process,
create thread, load dll and so forth) you'll get a breakpoint right before
your program hits the PE file entry point if you do it this way.  You can
just continue on unless you think you want to do something at this
point...

David

Gernot Frisch wrote:

> I've got a problem writing a debugger. The debugging process won't get
> notificated, and the debug process won't show up, although it is
> running in task-manager.
> Any idea what I did wrong? BTW: I use mingw for the program and VS
> .net for the debugger program. But that's not a problem, is it?
>
> // --------------------------------------------------------------- //
> // This is the debugger code
> // --------------------------------------------------------------- //
> BOOL CSampleView::DebugProgram(LPCTSTR lpPathName, LPCTSTR lpComdLine)
> {
> DEBUG_EVENT DebugEv;
> DWORD dwContinueStatus = DBG_CONTINUE;
>
> PROCESS_INFORMATION pi;
> STARTUPINFO   si = STARTUPINFO();
> si.cb = sizeof(STARTUPINFO);
> if (!::CreateProcess(prog, args, NULL, NULL, FALSE,
>                      NORMAL_PRIORITY_CLASS,
>                      NULL, NULL, &si, &pi))
>                      return FALSE;
>
> if(!DebugActiveProcess(pi.dwProcessId)) return FALSE;
> for(;;)
> {
>   WaitForDebugEvent(&DebugEv, INFINITE);
>   switch (DebugEv.dwDebugEventCode)
>   {
>    case EXCEPTION_DEBUG_EVENT:
>      switch (DebugEv.u.Exception.ExceptionRecord.ExceptionCode)
>      {
>      case OUTPUT_DEBUG_STRING_EVENT:
>         CString str(DebugEv.u.DebugString.lpDebugStringData,
>                     DebugEv.u.DebugString.nDebugStringLength);
>         AfxMessageBox(str);
>      break;
>   }
>   ContinueDebugEvent(DebugEv.dwProcessId, DebugEv.dwThreadId,
> dwContinueStatus);
> }
>
> // ------------------------------------
> // This is the debug-process code
> // ------------------------------------
>
> if (IsDebuggerPresent())
> {
>   OutputDebugStringA(s);
> }
>
> --
> -Gernot
> int main(int argc, char** argv) {printf
> ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
>
> ________________________________________
> Looking for a good game? Do it yourself!
> GLBasic - you can do
> www.GLBasic.com
0
David
1/15/2005 8:51:46 PM
Reply: