Ignore:
Timestamp:
Nov 20, 2000, 10:52:37 AM (25 years ago)
Author:
sandervl
Message:

MN: Updates + fixes for debug api functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/oslibdebug.cpp

    r4387 r4648  
    1 /* $Id: oslibdebug.cpp,v 1.4 2000-10-02 18:39:35 sandervl Exp $ */
     1/* $Id: oslibdebug.cpp,v 1.5 2000-11-20 09:52:37 sandervl Exp $ */
    22
    33/*
    44 * OS/2 debug apis
    55 *
    6  * Copyright 1999 Edgar Buerkle
     6 * Copyright 2000 Sander van Leeuwen
     7 * Copyright 2000 Edgar Buerkle
     8 * Copyright 2000 Michal Necasek
    79 *
    810 * Project Odin Software License can be found in LICENSE.TXT
     
    3638VOID _Optlink DebugThread(VOID *argpid)
    3739{
    38   CHAR   QueueName[30]=DEBUG_QUEUENAME;
    39   CHAR   SemName[30]=DEBUG_SEMNAME;
    40   CHAR   QSemName[30]=DEBUG_QSEMNAME;
    41   HQUEUE QueueHandle=0;
    42   HEV    hevSem=0, hevQSem=0;
     40  BOOL   fTerminate    = FALSE;
     41  CHAR   QueueName[30] = DEBUG_QUEUENAME;
     42  CHAR   SemName[30]   = DEBUG_SEMNAME;
     43  CHAR   QSemName[30]  = DEBUG_QSEMNAME;
     44  HQUEUE QueueHandle   = 0;
     45  HEV    hevSem        = 0,
     46         hevQSem       = 0;
     47  uDB_t  DbgBuf        = {0};
    4348  int    rc;
    44   uDB_t  DbgBuf={0};
    4549  char   path[CCHMAXPATH];
    4650  Win32DllBase *winmod;
    4751  LPDEBUG_EVENT lpde;
    4852  ULONG  *pid = (ULONG*)argpid;
     53  ULONG  staticPid = *pid;
    4954  char   tmp[12];
    5055
     
    9196  }
    9297
    93   while(rc == 0)
     98  while (rc == 0)
    9499  {
    95100    DosWaitEventSem(hevSem, SEM_INDEFINITE_WAIT);
     
    104109      dprintf(("DosDebug error: rc = %d", rc));
    105110
     111    if (fTerminate) // break out of the while loop
     112       break;
     113
    106114    switch (DbgBuf.Cmd)
    107115    {
     
    109117        dprintf(("DosDebug: GO ok"));
    110118        goto DosDebug_GO;
     119
    111120      case DBG_N_Error:
    112121        dprintf(("DosDebug: Error %d", DbgBuf.Value));
     
    118127        }
    119128        break;    // end thread !!!
     129
    120130      case DBG_N_ProcTerm:
    121         dprintf(("DosDebug: Process terminated with rc %d\n",DbgBuf.Value));
     131        dprintf(("DosDebug: Process terminated with rc %d\n", DbgBuf.Value));
    122132        lpde = (LPDEBUG_EVENT) malloc(sizeof(DEBUG_EVENT));
    123133        lpde->dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT_W;
     
    126136        lpde->u.ExitThread.dwExitCode = DbgBuf.Value;
    127137        DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
    128         break;
     138        // We should now fire final DBG_C_Go and end processing. We shouldn't
     139        // get any more debug events.
     140        fTerminate = TRUE;
     141        // goto DosDebug_GO; *pid is invalid?!?
     142        DbgBuf.Cmd = DBG_C_Go;
     143        DbgBuf.Pid = staticPid;
     144        goto DebugApi;
     145        break;
     146
    129147      case DBG_N_Exception:
    130148        dprintf(("DosDebug: Exception"));
     
    136154        DbgBuf.Value = XCPT_CONTINUE_SEARCH;
    137155        goto DebugApi;
     156
    138157      case DBG_N_ModuleLoad:
    139158        DosQueryModuleName(DbgBuf.Value, CCHMAXPATH, path);
     
    161180        DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
    162181        break;
     182
    163183      case DBG_N_CoError:
    164184        dprintf(("DosDebug: Coprocessor Error"));
     
    166186        goto DosDebug_GO;
    167187        break;
     188
    168189      case DBG_N_ThreadTerm:
    169190        dprintf(("DosDebug: Thread %d terminated with rc %d", DbgBuf.Tid,DbgBuf.Value));
     
    175196        DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
    176197        break;
     198
    177199      case DBG_N_AsyncStop:
    178200        dprintf(("DosDebug: Async stop"));
    179201        goto DosDebug_GO;
    180202        break;
     203
    181204      case DBG_N_NewProc:
    182205        dprintf(("DosDebug: Debuggee started new Pid %d",DbgBuf.Value));
     
    198221        DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
    199222        break;
     223
    200224      case DBG_N_AliasFree:
    201225        dprintf(("DosDebug: AliasFree"));
    202226        goto DosDebug_GO;
    203227        break;
     228
    204229      case DBG_N_Watchpoint:
    205230        dprintf(("DosDebug: WatchPoint"));
    206231        goto DosDebug_GO;
    207232        break;
     233
    208234      case DBG_N_ThreadCreate:
     235        // Note: Win32 debuggers expect a process creation event first!
    209236        dprintf(("DosDebug: Thread %d created",DbgBuf.Tid));
     237
     238        if (DbgBuf.Tid == 1) { // Is this the first thread of a process?
     239            // If so, fake a process creation event
     240            dprintf(("DosDebug: Faking process creation event"));
     241            lpde = (LPDEBUG_EVENT) malloc(sizeof(DEBUG_EVENT));
     242            lpde->dwDebugEventCode = CREATE_PROCESS_DEBUG_EVENT_W;
     243            lpde->dwProcessId = *pid;
     244            lpde->dwThreadId = 0;
     245            //TODO: fill union
     246            lpde->u.CreateProcessInfo.hFile = 0;
     247            lpde->u.CreateProcessInfo.hProcess = 0;
     248            lpde->u.CreateProcessInfo.hThread = 0;
     249            lpde->u.CreateProcessInfo.lpBaseOfImage = NULL;
     250            lpde->u.CreateProcessInfo.dwDebugInfoFileOffset = 0;
     251            lpde->u.CreateProcessInfo.nDebugInfoSize = 0;
     252            lpde->u.CreateProcessInfo.lpThreadLocalBase = NULL;
     253            lpde->u.CreateProcessInfo.lpStartAddress = NULL;
     254            lpde->u.CreateProcessInfo.lpImageName = NULL;
     255            lpde->u.CreateProcessInfo.fUnicode = FALSE;
     256            DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
     257        }
    210258        lpde = (LPDEBUG_EVENT) malloc(sizeof(DEBUG_EVENT));
    211259        lpde->dwDebugEventCode = CREATE_THREAD_DEBUG_EVENT_W;
     
    218266        DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
    219267        break;
     268
    220269      case DBG_N_ModuleFree:
    221270        DosQueryModuleName(DbgBuf.Value, CCHMAXPATH, path);
     
    235284        DosWriteQueue(QueueHandle, 0, sizeof(DEBUG_EVENT), lpde, 0);
    236285        break;
     286
    237287      case DBG_N_RangeStep:
    238288        dprintf(("DosDebug: RangeStep"));
    239289        goto DosDebug_GO;
    240290        break;
     291
    241292      default:
    242293        dprintf(("DosDebug: Unkown Notify %d", DbgBuf.Cmd));
     
    246297  }
    247298
     299  dprintf(("DosDebug - ending the service thread"));
    248300  DosCloseQueue(QueueHandle);
    249301  DosCloseEventSem(hevSem);
    250302  DosCloseEventSem(hevQSem);
    251   *pid = 0;
    252 
     303//  *pid = 0;  No can do - for some reason *pid is invalid by now
    253304}
     305
    254306//******************************************************************************
    255307//******************************************************************************
     
    389441
    390442   tid = _beginthread(DebugThread, NULL, 1024, (PVOID) pid);
    391    if(tid == 0)
     443   if (tid == 0)
    392444   {
    393       dprintf(("OSLibStartDebugger: Could create debug thread"));
     445      dprintf(("OSLibStartDebugger: Could not create debug thread!"));
    394446      SetFS(sel);
    395447      return;
Note: See TracChangeset for help on using the changeset viewer.