home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / TERM.C < prev    next >
Text File  |  1995-10-04  |  11KB  |  222 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   term.c                                                                  */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*   Functions for terminating and restarting.                               */
  7. /*                                                                           */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  12. /*                                                                           */
  13. /*...16->32 port.                                                            */
  14. /*...                                                                        */
  15. /*... 02/08/91  110   Srinivas  port to 32 bit.                              */
  16. /*                                                                           */
  17. /*...Release 1.00 (Pre-release 1)                                            */
  18. /*...                                                                        */
  19. /*... 08/29/91  215   srinivas    Add support for HLL format                 */
  20. /*... 08/29/91  236   srinivas    blinking restart & other restart problems. */
  21. /*...                                                                        */
  22. /*...Release 1.00 (Pre-release 107 11/13/91)                                 */
  23. /*...                                                                        */
  24. /*... 11/18/91  401   Srinivas  Co processor Register Display.               */
  25. /*...                                                                        */
  26. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  27. /*...                                                                        */
  28. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  29. /*...                                                                        */
  30. /*...Release 1.00 (03/03/92)                                                 */
  31. /*...                                                                        */
  32. /*... 03/10/92  602   Srinivas  Hooking up watch points.                     */
  33. /*... 03/20/92  607   Srinivas  CRMA fixes.                                  */
  34. /*... 03/21/92  608   Srinivas  Restart Not Cleaning up the Session properly.*/
  35. /*...                                                                        */
  36. /*...Release 1.01 (04/03/92)                                                 */
  37. /*...                                                                        */
  38. /*... 10/15/92  710   Joe       Rewrite term.c to fix term/restart probs.    */
  39. /*...                                                                        */
  40. /*...Release 1.02 (10/22/92)                                                 */
  41. /*... 10/28/92  800   Joe       Add code to get exe stack size.              */
  42. /*...                           Use in quit/restart.                         */
  43. /**Includes*******************************************************************/
  44.  
  45. #include "all.h"                        /* SD86 include files                */
  46.  
  47. /**Defines *******************************************************************/
  48. extern PROCESS_NODE *pnode;             /* -> to process list.               */
  49. extern int          AppTerminated;      /* application terminated flag.      */
  50. extern uint         VideoRows;          /* # of rows per screen              */
  51. extern jmp_buf      RestartContext;     /* stack/registers for restart.      */
  52. extern CmdParms     cmd;
  53.  
  54.  int
  55. NormalQuit( int ExitDebug )
  56. {
  57.  APIRET   rc;
  58.  DEBFILE *pdf;
  59.  CSR      DosCsr;
  60.  ALLPIDS *p;
  61.  
  62.  pdf = pnode->ExeStruct;
  63.  
  64.  /****************************************************************************/
  65.  /* - Kill the listen/polling threads.                                       */
  66.  /****************************************************************************/
  67.  if( IsParent() && (ConnectType() != BOUND ) )
  68.  {
  69.   if( SerialParallel() == PARALLEL)
  70.    SendMsgToDbgQue(DBG_QMSG_KILL_LISTEN,NULL,0);
  71.   if( (SerialParallel() == SERIAL) && (SingleMultiple() == MULTIPLE) )
  72.   {
  73.    SetKillChk4Disconnect( TRUE );
  74.    SetPollingThreadFlag( THREAD_TERM );
  75.    while( GetPollingThreadFlag() != NOT_RUNNING ){ DosSleep(100) ;}
  76.   }
  77.   /**************************************************************************/
  78.   /* - Send a message to all of the child debuggers telling them that       */
  79.   /*   we're terminating their probes.                                      */
  80.   /**************************************************************************/
  81.   for( p = GetAllpids(); p ; p = p->next )
  82.   {
  83.    if( p->pid != DbgGetProcessID() )
  84.    {
  85.     DBG_QUE_ELEMENT Qelement;
  86.  
  87.     Qelement.pid = p->DbgPid;
  88.  
  89.     SendMsgToDbgTermQue(DBG_PROBE_TERM, &Qelement, sizeof(Qelement) );
  90.    }
  91.   }
  92.  }
  93.  /****************************************************************************/
  94.  /* - Thaw any threads that may be frozen.                                   */
  95.  /* - Call DosExit() in the apps address space.                              */
  96.  /****************************************************************************/
  97.  xThawThread( 0 );                                                      /*827*/
  98.  rc = xNormalQuit(AppTerminated,pdf->mte,pdf->EntryExitPt);
  99.  
  100.  /****************************************************************************/
  101.  /* - Clean up the resources used by the debugger:                           */
  102.  /*    - the queue...wait until the queue is terminated.                     */
  103.  /*    - the connect sema4 for serial connections.                           */
  104.  /****************************************************************************/
  105.  if( IsEspRemote() && IsParent() )
  106.  {
  107.   if( SingleMultiple() == MULTIPLE )
  108.   {
  109.    /**************************************************************************/
  110.    /* - send a message to the que to kill all the child debuggers            */
  111.    /* - then wait until they are all dead.                                   */
  112.    /**************************************************************************/
  113.    ResetAllDbgsAreDeadFlag();
  114.    SendMsgToDbgQue(DBG_QMSG_PARENT_TERM,NULL,0);
  115.    while( AllDbgsAreDead() == FALSE ){ DosSleep(100) ;}
  116.   }
  117.   SendMsgToDbgQue(DBG_QMSG_QUE_TERM,NULL,0);
  118.  }
  119.  CloseConnectSema4();
  120.  
  121.  /****************************************************************************/
  122.  /* - Send a return code back to restart.                                    */
  123.  /****************************************************************************/
  124.  if( ExitDebug == FALSE )
  125.   return(rc);
  126.  
  127.  /****************************************************************************/
  128.  /* - Ask the user if he wants to terminate the probe.                       */
  129.  /****************************************************************************/
  130.  {
  131. #if 0
  132.   uint key = 0;
  133.   if( IsEspRemote() )
  134.    key = MsgYorN(HELP_QUIT_ESP);
  135.   if( key == key_y || key == key_Y )
  136. #endif
  137.    xTerminateESP();
  138.  }
  139.  
  140.  /****************************************************************************/
  141.  /* - Now, close the connection and the serial mutex sema4 if there is one.  */
  142.  /****************************************************************************/
  143.  ConnectClose( DEFAULT_HANDLE );
  144.  CloseSerialMutex();
  145.  
  146.  if( IsParent() == FALSE )
  147.  {
  148.   DBG_QUE_ELEMENT Qelement;
  149.   memset( &Qelement, 0, sizeof(Qelement) );
  150.   Qelement.pid = DbgGetProcessID();
  151.  
  152.   SendMsgToDbgQue( DBG_QMSG_CHILD_TERM, &Qelement, sizeof(Qelement) );
  153.  }
  154.  
  155.  /****************************************************************************/
  156.  /* - disconnect the signal handler.                                         */
  157.  /****************************************************************************/
  158.  UnRegisterExceptionHandler( );
  159.  
  160.  /****************************************************************************/
  161.  /* - Toggle alt-esc and ctrl-esc back on.                                   */
  162.  /****************************************************************************/
  163.  if( IsHotKey() ) SetHotKey();
  164.  
  165.  ClrPhyScr( 0, VideoRows-1, vaClear );
  166.  DosCsr.col = 0;
  167.  DosCsr.row = ( uchar )(VideoRows-1);
  168.  PutCsr( &DosCsr );
  169.  /****************************************************************************/
  170.  /* - MSH may be waiting on the event semaphore. Post, then close.           */
  171.  /****************************************************************************/
  172. #if 0
  173.  CloseEventSemaphores();
  174. #endif
  175.  
  176.  KillEditorSession();
  177.  
  178.  exit(0);
  179.  return(0);                             /* keep the compiler happy.          */
  180. }                                       /* end NormalQuit()                  */
  181.  
  182. /*****************************************************************************/
  183. /* Restart()                                                                 */
  184. /*                                                                           */
  185. /* Description:                                                              */
  186. /*                                                                           */
  187. /*   Restart the debuggee.                                                   */
  188. /*                                                                           */
  189. /* Parameters:                                                               */
  190. /*                                                                           */
  191. /* Return:                                                                   */
  192. /*                                                                           */
  193. /* Assumptions:                                                              */
  194. /*                                                                           */
  195. /*****************************************************************************/
  196. void Restart()                          /* restart the debuggee.             */
  197. {                                       /*                                   */
  198.  int ExitDebug;
  199.  
  200.  char BadSessTerm[100] = "\r Your session may not have terminated properly\r\
  201.  Quit SD386 and start again.";
  202.  
  203.  /***************************************************************************/
  204.  /* Since BadSessTerm is a local variable and the string is copied afresh   */
  205.  /* everytime, we dont have to worry about showhelpbox modifying the message*/
  206.  /***************************************************************************/
  207.  
  208.  SayMsgBox3("Restarting...");           /* could be a delay.                 */
  209.  /****************************************************************************/
  210.  /*  prepare breakpoints for restart.                                        */
  211.  /****************************************************************************/
  212.  SaveBrks(pnode);
  213.  
  214.  ExitDebug = FALSE;
  215.  if( IsParent() == FALSE )
  216.   ExitDebug = TRUE;
  217.  
  218.  if( NormalQuit( ExitDebug ) )
  219.   CuaShowHelpBox( BadSessTerm );
  220.  longjmp( RestartContext, 1);
  221. }
  222.