home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / XBOX.C < prev    next >
C/C++ Source or Header  |  1995-04-20  |  69KB  |  1,332 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   xbox.c                                                               827*/
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   The x-box interface.                                                    */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   06/09/93 Created.                                                       */
  12. /*                                                                           */
  13. /*... 06/04/93  827   Joe       Add remote debug support.                    */
  14. /*... 03/29/94  917   Joe       Ctrl-Break handling for single process.      */
  15. /*...                                                                        */
  16. /*****************************************************************************/
  17. #include "all.h"
  18.  
  19. extern CmdParms cmd;
  20.  
  21. /*****************************************************************************/
  22. /* xFindExe()                                                                */
  23. /*                                                                           */
  24. /* Description:                                                              */
  25. /*                                                                           */
  26. /*   Find the EXE file from the server. Search in the following order:       */
  27. /*                                                                           */
  28. /*     1. Explicit program name including path reference.                    */
  29. /*     2. Current directory.                                                 */
  30. /*     3. SD386SRC environment variable.                                     */
  31. /*     4. PATH environment variable.                                         */
  32. /*                                                                           */
  33. /* Parameters:                                                               */
  34. /*                                                                           */
  35. /*   progname The EXE name plus optional path reference.                     */
  36. /*   pn       Pointer to the caller's buffer to receive fully qualified      */
  37. /*            filespec.                                                      */
  38. /*   pnlen    Length of the caller's buffer receiving filespec.              */
  39. /*                                                                           */
  40. /* Return:                                                                   */
  41. /*                                                                           */
  42. /*   rc       The return code from DosSearchPath().                          */
  43. /*                                                                           */
  44. /* Assumptions:                                                              */
  45. /*                                                                           */
  46. /*  The EXE extension has been added to the filespec.                        */
  47. /*                                                                           */
  48. /*****************************************************************************/
  49. APIRET xFindExe(char *progname,char *pn,UINT pnlen)
  50. {
  51.  APIRET rc;
  52.  
  53.  if(IsEspRemote())
  54.  {
  55.  
  56.   RequestSerialMutex();
  57.   rc = TxFindExe(progname,pn,pnlen);
  58.   ReleaseSerialMutex();
  59.  }
  60.  else
  61.  {
  62.   rc = XSrvFindExe(progname,pn,pnlen);
  63.  }
  64.  return(rc);
  65. }
  66.  
  67. /*****************************************************************************/
  68. /* xStartUser()                                                              */
  69. /*                                                                           */
  70. /* Description:                                                              */
  71. /*                                                                           */
  72. /*   Start the debuggee in the probe.                                        */
  73. /*                                                                           */
  74. /* Parameters:                                                               */
  75. /*                                                                           */
  76. /*   pUserEXE       -> fully qualified debuggee specification.               */
  77. /*   pUserParms     -> debuggee parms.                                       */
  78. /*   SessionType       user specified session type.                          */
  79. /*   pSessionID        receiver of the SessionID.                            */
  80. /*   pProcessID        receiver of the ProcessID..                           */
  81. /*   pProcessType      receiver of the Process type.                         */
  82. /*   MsgLen            length of the buffer to receive offending mod if error*/
  83. /*   pMsgBuf        -> buffer to receive offending module name.              */
  84. /*                                                                           */
  85. /* Return:                                                                   */
  86. /*                                                                           */
  87. /*   rc            return code from DosStartSession on the remote debuggee.  */
  88. /*                                                                           */
  89. /* Assumptions:                                                              */
  90. /*                                                                           */
  91. /*   pUserExe   != NULL                                                      */
  92. /*   pUserParms may be = NULL                                                */
  93. /*                                                                           */
  94. /*****************************************************************************/
  95. APIRET xStartUser(char   *pUserEXE,
  96.                   char   *pUserParms,
  97.                   USHORT  SessionType,
  98.                   ULONG  *pSessionID,
  99.                   ULONG  *pProcessID,
  100.                   ULONG  *pProcessType,
  101.                   ULONG   MsgLen,
  102.                   char   *pMsgBuf )
  103. {
  104.  APIRET rc;
  105.  
  106.  if(IsEspRemote())
  107.  {
  108.   RequestSerialMutex();
  109.   rc = TxStartUser( pUserEXE,
  110.                     pUserParms,
  111.                     SessionType,
  112.                     pSessionID,
  113.                     pProcessID,
  114.                     pProcessType,
  115.                     pMsgBuf );
  116.   ReleaseSerialMutex();
  117.  }
  118.  else
  119.  {
  120.   rc = EspStartUser( pUserEXE,
  121.                      pUserParms,
  122.                      SessionType,
  123.                      pSessionID,
  124.                      pProcessID,
  125.                      pProcessType,
  126.                      MsgLen,
  127.                      pMsgBuf );
  128.  }
  129.  return(rc);
  130. }
  131.  
  132. /*****************************************************************************/
  133. /* xGoInit()                                                                 */
  134. /*                                                                           */
  135. /* Description:                                                              */
  136. /*                                                                           */
  137. /*   Initialize a process for debugging.                                     */
  138. /*                                                                           */
  139. /* Parameters:                                                               */
  140. /*                                                                           */
  141. /*   pptb               -> to the ptrace buffer.                             */
  142. /*   ppModuleLoadTable  where to put a ptr to the ModuleLoadTable.           */
  143. /*   pModuleTableLength where to put the length of the ModuleLoadtable.      */
  144. /*                                                                           */
  145. /* Return:                                                                   */
  146. /*                                                                           */
  147. /*   rc           DosDebug return code.                                      */
  148. /*                                                                           */
  149. /* Assumptions:                                                              */
  150. /*                                                                           */
  151. /*   The Pid is contained in the ptrace buffer.                              */
  152. /*                                                                           */
  153. /*****************************************************************************/
  154. APIRET xGoInit( PtraceBuffer  *pptb,
  155.                 ULONG         *pExecAddr,
  156.                 UINT         **ppModuleLoadTable,
  157.                 int           *pModuleTableLength)
  158. {
  159.  APIRET rc;
  160.  
  161.  if(IsEspRemote())
  162.  {
  163.   RequestSerialMutex();
  164.   rc = TxGoInit(pptb,pExecAddr,ppModuleLoadTable,pModuleTableLength);
  165.   ReleaseSerialMutex();
  166.  }
  167.  else
  168.  {
  169.   rc = XSrvGoInit(pptb,pExecAddr,ppModuleLoadTable,pModuleTableLength);
  170.  }
  171.  return(rc);
  172. }
  173.  
  174. /*****************************************************************************/
  175. /* xGoEntry()                                                                */
  176. /*                                                                           */
  177. /* Description:                                                              */
  178. /*                                                                           */
  179. /*   Run to the initial entry point.                                         */
  180. /*                                                                           */
  181. /* Parameters:                                                               */
  182. /*                                                                           */
  183. /*   pptb               -> to the ptrace buffer.                             */
  184. /*   pExecAddr          where to put the exec address.                       */
  185. /*   ppModuleLoadTable  where to put a ptr to the ModuleLoadTable.           */
  186. /*   pModuleTableLength where to put the length of the ModuleLoadtable.      */
  187. /*   ExecAddr           current EIP.                                         */
  188. /*   ExecFlags          execution control flags such as RUNNING_DEFERRED or  */
  189. /*                      LOAD_MODULES.                                        */
  190. /*                                                                           */
  191. /* Return:                                                                   */
  192. /*                                                                           */
  193. /*   rc           trap code.                                                 */
  194. /*                                                                           */
  195. /* Assumptions:                                                              */
  196. /*                                                                           */
  197. /*   The Pid is contained in the ptrace buffer.                              */
  198. /*                                                                           */
  199. /*****************************************************************************/
  200. APIRET xGoEntry( PtraceBuffer  *pptb,
  201.                  ULONG         *pExecAddr,
  202.                  UINT         **ppModuleLoadTable,
  203.                  int           *pModuleTableLength,
  204.                  ULONG         ExecAddr,
  205.                  int           ExecFlags)
  206. {
  207.  APIRET rc;
  208.  
  209.  if(IsEspRemote())
  210.  {
  211.   RequestSerialMutex();
  212.   rc=TxGoEntry(pptb,
  213.                pExecAddr,
  214.                ppModuleLoadTable,
  215.                pModuleTableLength,
  216.                ExecAddr,
  217.                ExecFlags );
  218.   ReleaseSerialMutex();
  219.  }
  220.  else
  221.  {
  222.   rc=XSrvGoFast(pptb,
  223.                 pExecAddr,
  224.                 ppModuleLoadTable,
  225.                 pModuleTableLength,
  226.                 ExecAddr,
  227.                 ExecFlags);
  228.  }
  229.  return(rc);
  230. }
  231.  
  232. /*****************************************************************************/
  233. /* xGoStep()                                                                 */
  234. /*                                                                           */
  235. /* Description:                                                              */
  236. /*                                                                           */
  237. /*   Step debuggee at source or assembler level.                             */
  238. /*                                                                           */
  239. /* Parameters:                                                               */
  240. /*                                                                           */
  241. /*   pptb               -> to the ptrace buffer.                             */
  242. /*   pExecAddr          where to put the exec address.                       */
  243. /*   ppModuleLoadTable  where to put a ptr to the ModuleLoadTable.           */
  244. /*   pModuleTableLength where to put the length of the ModuleLoadtable.      */
  245. /*   ExecAddr           current EIP.                                         */
  246. /*   ExecAddrlo         start addr of the instructions for a source line.    */
  247. /*   ExecAddrhi         first addr past the instructions for a source line.  */
  248. /*   how                step qualifier such as OVERCALL or INTOCALL.         */
  249. /*   ExecFlags          execution control flags such as RUNNING_DEFERRED or  */
  250. /*                      LOAD_MODULES.                                        */
  251. /*                                                                           */
  252. /* Return:                                                                   */
  253. /*                                                                           */
  254. /*   rc           trap code.                                                 */
  255. /*                                                                           */
  256. /* Assumptions:                                                              */
  257. /*                                                                           */
  258. /*   The Pid is contained in the ptrace buffer.                              */
  259. /*                                                                           */
  260. /*****************************************************************************/
  261. APIRET xGoStep( PtraceBuffer  *pptb,
  262.                 ULONG         *pExecAddr,
  263.                 UINT         **ppModuleLoadTable,
  264.                 int           *pModuleTableLength,
  265.                 ULONG         ExecAddr,
  266.                 ULONG         ExecAddrlo,
  267.                 ULONG         ExecAddrhi,
  268.                 int           how,
  269.                 int           ExecFlags)
  270. {
  271.  APIRET rc;
  272.  
  273.  if(IsEspRemote())
  274.  {
  275.   RequestSerialMutex();
  276.   rc=TxGoStep(pptb,
  277.               pExecAddr,
  278.               ppModuleLoadTable,
  279.               pModuleTableLength,
  280.               ExecAddr,
  281.               ExecAddrlo,
  282.               ExecAddrhi,
  283.               how,
  284.               ExecFlags );
  285.  ReleaseSerialMutex();
  286.  }
  287.  else
  288.  {
  289.   rc=XSrvGoStep(pptb,
  290.                 pExecAddr,
  291.                 ppModuleLoadTable,
  292.                 pModuleTableLength,
  293.                 ExecAddr,
  294.                 ExecAddrlo,
  295.                 ExecAddrhi,
  296.                 how,
  297.                 ExecFlags );
  298.  }
  299.  return(rc);
  300. }
  301.  
  302. /*****************************************************************************/
  303. /* xGoFast()                                                                 */
  304. /*                                                                           */
  305. /* Description:                                                              */
  306. /*                                                                           */
  307. /*   Run the debuggee.                                                       */
  308. /*                                                                           */
  309. /* Parameters:                                                               */
  310. /*                                                                           */
  311. /*   pptb               -> to the ptrace buffer.                             */
  312. /*   pExecAddr          where to put the exec address.                       */
  313. /*   ppModuleLoadTable  where to put a ptr to the ModuleLoadTable.           */
  314. /*   pModuleTableLength where to put the length of the ModuleLoadtable.      */
  315. /*   ExecAddr           current EIP.                                         */
  316. /*   ExecFlags          execution control flags such as RUNNING_DEFERRED or  */
  317. /*                      LOAD_MODULES.                                        */
  318. /*                                                                           */
  319. /* Return:                                                                   */
  320. /*                                                                           */
  321. /*   rc           trap code.                                                 */
  322. /*                                                                           */
  323. /* Assumptions:                                                              */
  324. /*                                                                           */
  325. /*   The Pid is contained in the ptrace buffer.                              */
  326. /*                                                                           */
  327. /*****************************************************************************/
  328. APIRET xGoFast( PtraceBuffer  *pptb,
  329.                 ULONG         *pExecAddr,
  330.                 UINT         **ppModuleLoadTable,
  331.                 int           *pModuleTableLength,
  332.                 ULONG         ExecAddr,
  333.                 int           ExecFlags)
  334. {
  335.  APIRET rc;
  336.  
  337.  if(IsEspRemote())
  338.  {
  339.   RequestSerialMutex();
  340.   rc=TxGoFast(pptb,
  341.               pExecAddr,
  342.               ppModuleLoadTable,
  343.               pModuleTableLength,
  344.               ExecAddr,
  345.               ExecFlags );
  346.   ReleaseSerialMutex();
  347.  }
  348.  else
  349.  {
  350.   rc=XSrvGoFast(pptb,
  351.                 pExecAddr,
  352.                 ppModuleLoadTable,
  353.                 pModuleTableLength,
  354.                 ExecAddr,
  355.                 ExecFlags);
  356.  }
  357.  return(rc);
  358. }
  359.  
  360.  
  361. /*****************************************************************************/
  362. /* xDefBrk()                                                                 */
  363. /*                                                                           */
  364. /* Description:                                                              */
  365. /*                                                                           */
  366. /*   Define a break point in the probe.                                      */
  367. /*                                                                           */
  368. /* Parameters:                                                               */
  369. /*                                                                           */
  370. /*   where      addr where to set the break point.                           */
  371. /*                                                                           */
  372. /* Return:                                                                   */
  373. /*                                                                           */
  374. /* Assumptions:                                                              */
  375. /*                                                                           */
  376. /*****************************************************************************/
  377. void xDefBrk(ULONG where )
  378. {
  379.  if(IsEspRemote())
  380.  {
  381.   RequestSerialMutex();
  382.   TxDefBrk( where );
  383.   ReleaseSerialMutex();
  384.  }
  385.  else
  386.  {
  387.   XSrvDefBrk( where );
  388.  }
  389. }
  390.  
  391. /*****************************************************************************/
  392. /* xUndBrk()                                                                 */
  393. /*                                                                           */
  394. /* Description:                                                              */
  395. /*                                                                           */
  396. /*   UnDefine a break point in the probe.                                    */
  397. /*                                                                           */
  398. /* Parameters:                                                               */
  399. /*                                                                           */
  400. /*   where    addr of break point to undefine.                               */
  401. /*                                                                           */
  402. /* Return:                                                                   */
  403. /*                                                                           */
  404. /* Assumptions:                                                              */
  405. /*                                                                           */
  406. /*****************************************************************************/
  407. void xUndBrk( ULONG where )
  408. {
  409.  if(IsEspRemote())
  410.  {
  411.   RequestSerialMutex();
  412.   TxUndBrk( where );
  413.   ReleaseSerialMutex();
  414.  }
  415.  else
  416.  {
  417.   XSrvUndBrk( where );
  418.  }
  419. }
  420.  
  421. /*****************************************************************************/
  422. /* xPutInBrk()                                                               */
  423. /*                                                                           */
  424. /* Description:                                                              */
  425. /*                                                                           */
  426. /*   Put in a breakpoint.                                                    */
  427. /*                                                                           */
  428. /* Parameters:                                                               */
  429. /*                                                                           */
  430. /*   where      addr where to put in the break point.                        */
  431. /*                                                                           */
  432. /* Return:                                                                   */
  433. /*                                                                           */
  434. /* Assumptions:                                                              */
  435. /*                                                                           */
  436. /*****************************************************************************/
  437. void xPutInBrk(ULONG where )
  438. {
  439.  if(IsEspRemote())
  440.  {
  441.   RequestSerialMutex();
  442.   TxPutInBrk( where );
  443.   ReleaseSerialMutex();
  444.  }
  445.  else
  446.  {
  447.   XSrvPutInBrk( where );
  448.  }
  449. }
  450.  
  451. /*****************************************************************************/
  452. /* xPullOutBrk()                                                             */
  453. /*                                                                           */
  454. /* Description:                                                              */
  455. /*                                                                           */
  456. /*   Pull out a breakpoint.                                                  */
  457. /*                                                                           */
  458. /* Parameters:                                                               */
  459. /*                                                                           */
  460. /*   where      addr where to extact the break point.                        */
  461. /*                                                                           */
  462. /* Return:                                                                   */
  463. /*                                                                           */
  464. /* Assumptions:                                                              */
  465. /*                                                                           */
  466. /*****************************************************************************/
  467. void xPullOutBrk( ULONG where )
  468. {
  469.  if(IsEspRemote())
  470.  {
  471.   RequestSerialMutex();
  472.   TxPullOutBrk( where );
  473.   ReleaseSerialMutex();
  474.  }
  475.  else
  476.  {
  477.   XSrvPullOutBrk( where );
  478.  }
  479. }
  480.  
  481. /*****************************************************************************/
  482. /* xInsertAllBrk()                                                           */
  483. /*                                                                           */
  484. /* Description:                                                              */
  485. /*                                                                           */
  486. /*   Insert all the breakpoints.                                             */
  487. /*                                                                           */
  488. /* Parameters:                                                               */
  489. /*                                                                           */
  490. /* Return:                                                                   */
  491. /*                                                                           */
  492. /* Assumptions:                                                              */
  493. /*                                                                           */
  494. /*****************************************************************************/
  495. void xInsertAllBrk( void )
  496. {
  497.  
  498.  if(IsEspRemote())
  499.  {
  500.   RequestSerialMutex();
  501.   TxInsertAllBrk();
  502.   ReleaseSerialMutex();
  503.  }
  504.  else
  505.  {
  506.   XSrvInsertAllBrk();
  507.  }
  508.  return;
  509. }
  510.  
  511. /*****************************************************************************/
  512. /* xRemoveAllBrk()                                                           */
  513. /*                                                                           */
  514. /* Description:                                                              */
  515. /*                                                                           */
  516. /*   Remove all the breakpoints.                                             */
  517. /*                                                                           */
  518. /* Parameters:                                                               */
  519. /*                                                                           */
  520. /* Return:                                                                   */
  521. /*                                                                           */
  522. /* Assumptions:                                                              */
  523. /*                                                                           */
  524. /*****************************************************************************/
  525. void xRemoveAllBrk( void )
  526. {
  527.  
  528.  if(IsEspRemote())
  529.  {
  530.   RequestSerialMutex();
  531.   TxRemoveAllBrk();
  532.   ReleaseSerialMutex();
  533.  }
  534.  else
  535.  {
  536.   XSrvRemoveAllBrk();
  537.  }
  538.  return;
  539. }
  540.  
  541. /*****************************************************************************/
  542. /* xDosDebug()                                                               */
  543. /*                                                                           */
  544. /* Description:                                                              */
  545. /*                                                                           */
  546. /*   DosDebug API.                                                           */
  547. /*                                                                           */
  548. /* Parameters:                                                               */
  549. /*                                                                           */
  550. /*   pptb       -> to the DosDebug buffer.                                   */
  551. /*                                                                           */
  552. /* Return:                                                                   */
  553. /*                                                                           */
  554. /*   rc            rc from DosDebug.                                         */
  555. /*                                                                           */
  556. /* Assumptions:                                                              */
  557. /*                                                                           */
  558. /*   none.                                                                   */
  559. /*                                                                           */
  560. /*****************************************************************************/
  561. APIRET APIENTRY xDosDebug(PtraceBuffer *pptb)
  562. {
  563.  APIRET rc;
  564.  
  565.  if(IsEspRemote())
  566.  {
  567.   RequestSerialMutex();
  568.   rc = TxDosDebug(pptb);
  569.   ReleaseSerialMutex();
  570.  }
  571.  else
  572.  {
  573.   rc = DosDebug(pptb);
  574.  }
  575.  return(rc);
  576. }
  577.  
  578. /*****************************************************************************/
  579. /* xGetThreadInfo()                                                          */
  580. /*                                                                           */
  581. /* Description:                                                              */
  582. /*                                                                           */
  583. /*   Get the thread info for the debuggee.                                   */
  584. /*                                                                           */
  585. /* Parameters:                                                               */
  586. /*                                                                           */
  587. /*   pBuffer    -> to the buffer to receive the info.                        */
  588. /*                                                                           */
  589. /* Return:                                                                   */
  590. /*                                                                           */
  591. /*   ntids      the number of threads.                                       */
  592. /*                                                                           */
  593. /* Assumptions:                                                              */
  594. /*                                                                           */
  595. /*                                                                           */
  596. /*****************************************************************************/
  597. ULONG xGetThreadInfo(THREADINFO *pBuffer)
  598. {
  599.  ULONG ntids;
  600.  
  601.  if(IsEspRemote())
  602.  {
  603.   RequestSerialMutex();
  604.   ntids = TxGetThreadInfo(pBuffer);
  605.   ReleaseSerialMutex();
  606.  }
  607.  else
  608.  {
  609.   ntids = XSrvGetThreadInfo(pBuffer);
  610.  }
  611.  return(ntids);
  612. }
  613.  
  614. /*****************************************************************************/
  615. /* xFreezeThread()                                                           */
  616. /*                                                                           */
  617. /* Description:                                                              */
  618. /*                                                                           */
  619. /*   Freeze a thread.                                                        */
  620. /*                                                                           */
  621. /* Parameters:                                                               */
  622. /*                                                                           */
  623. /*   tid      thread id to freeze.                                           */
  624. /*                                                                           */
  625. /* Return:                                                                   */
  626. /*                                                                           */
  627. /* Assumptions:                                                              */
  628. /*                                                                           */
  629. /*****************************************************************************/
  630. void xFreezeThread( ULONG tid )
  631. {
  632.  if(IsEspRemote())
  633.  {
  634.   RequestSerialMutex();
  635.   TxFreezeThread( tid );
  636.   ReleaseSerialMutex();
  637.  }
  638.  else
  639.  {
  640.   XSrvFreezeThread( tid );
  641.  }
  642. }
  643.  
  644. /*****************************************************************************/
  645. /* xThawThread()                                                             */
  646. /*                                                                           */
  647. /* Description:                                                              */
  648. /*                                                                           */
  649. /*   Thaw a thread.                                                          */
  650. /*                                                                           */
  651. /* Parameters:                                                               */
  652. /*                                                                           */
  653. /*   tid      thread id to thaw.                                             */
  654. /*                                                                           */
  655. /* Return:                                                                   */
  656. /*                                                                           */
  657. /* Assumptions:                                                              */
  658. /*                                                                           */
  659. /*****************************************************************************/
  660. void xThawThread( ULONG tid )
  661. {
  662.  if(IsEspRemote())
  663.  {
  664.   RequestSerialMutex();
  665.   TxThawThread( tid );
  666.   ReleaseSerialMutex();
  667.  }
  668.  else
  669.  {
  670.   XSrvThawThread( tid );
  671.  }
  672. }
  673.  
  674. /*****************************************************************************/
  675. /* xGetCallStack()                                                           */
  676. /*                                                                           */
  677. /* Description:                                                              */
  678. /*                                                                           */
  679. /*   Establishes the following arrays for the current state of the user's    */
  680. /*   stack:                                                                  */
  681. /*                                                                           */
  682. /*    ActFaddrs[]   the CS:IP or EIP values for the stack frames.            */
  683. /*    ActCSAtrs[]   0 => 16-bit stack frame  1 => 32-bit stack frame.        */
  684. /*    ActFrames[]   offsets in the stack of the stack frames ( EBP values )  */
  685. /*                                                                           */
  686. /* Parameters:                                                               */
  687. /*                                                                           */
  688. /*   pparms        Stuff needed to boot the stack unwind.                    */
  689. /*   ppActCSAtrs   -> ActCSAtrs[].                                           */
  690. /*   ppActFrames   -> ActFrames[].                                           */
  691. /*   ppActFaddrs   -> ActFaddrs[].                                           */
  692. /*                                                                           */
  693. /* Return:                                                                   */
  694. /*                                                                           */
  695. /*   NActFrames     Number of active frames unwound.                         */
  696. /*                                                                           */
  697. /* Assumptions:                                                              */
  698. /*                                                                           */
  699. /*****************************************************************************/
  700. ULONG xGetCallStack(STACK_PARMS *pparms,
  701.                     UCHAR       **ppActCSAtrs,
  702.                     UINT        **ppActFrames,
  703.                     UINT        **ppActFaddrs )
  704. {
  705.  ULONG NActFrames;
  706.  
  707.  if(IsEspRemote())
  708.  {
  709.   RequestSerialMutex();
  710.   NActFrames = TxGetCallStack(pparms,ppActCSAtrs,ppActFrames,ppActFaddrs );
  711.   ReleaseSerialMutex();
  712.  }
  713.  else
  714.  {
  715.   NActFrames = XSrvGetCallStack(pparms,ppActCSAtrs,ppActFrames,ppActFaddrs );
  716.  }
  717.  return(NActFrames);
  718. }
  719.  
  720. /*****************************************************************************/
  721. /* TxGetExeOrDllEntryOrExitPt()                                              */
  722. /*                                                                           */
  723. /* Description:                                                              */
  724. /*                                                                           */
  725. /*   Get the entry point for a dll or exe.                                   */
  726. /*                                                                           */
  727. /* Parameters:                                                               */
  728. /*                                                                           */
  729. /*   mte        module table handle of exe/dll.                              */
  730. /*                                                                           */
  731. /* Return:                                                                   */
  732. /*                                                                           */
  733. /*   EntryExitAddr  the entry/exit address from the exe/dll header.          */
  734. /*                                                                           */
  735. /* Assumptions:                                                              */
  736. /*                                                                           */
  737. /*****************************************************************************/
  738. ULONG xGetExeOrDllEntryOrExitPt( UINT mte )
  739. {
  740.  ULONG EntryPtAddr = 0;
  741.  
  742.  if(IsEspRemote())
  743.  {
  744.   RequestSerialMutex();
  745.   EntryPtAddr = TxGetExeOrDllEntryOrExitPt( mte );
  746.   ReleaseSerialMutex();
  747.  }
  748.  else
  749.  {
  750.   EntryPtAddr = XSrvGetExeOrDllEntryOrExitPt( mte );
  751.  }
  752.  return(EntryPtAddr);
  753. }
  754.  
  755. /*****************************************************************************/
  756. /* xNormalQuit()                                                             */
  757. /*                                                                           */
  758. /* Description:                                                              */
  759. /*                                                                           */
  760. /*   Terminate the debuggee process.                                         */
  761. /*                                                                           */
  762. /* Parameters:                                                               */
  763. /*                                                                           */
  764. /*   AppTerminated  Flag indicating whether or not the app is terminated.    */
  765. /*   mte            module table handle of exe.                              */
  766. /*   EntryPt        exe entry point.                                         */
  767. /*                                                                           */
  768. /* Return:                                                                   */
  769. /*                                                                           */
  770. /*   rc             0 or 1                                                   */
  771. /*                                                                           */
  772. /* Assumptions:                                                              */
  773. /*                                                                           */
  774. /*   The application is either in the "DBG_N_ProcTerm" since the             */
  775. /*   app has executed a DosExit, or the state is unknown.                    */
  776. /*                                                                           */
  777. /*****************************************************************************/
  778. APIRET xNormalQuit( int AppTerminated, UINT mte, ULONG EntryPt )
  779. {
  780.  APIRET  rc;
  781.  
  782.  if(IsEspRemote())
  783.  {
  784.   RequestSerialMutex();
  785.   rc = TxNormalQuit( AppTerminated, mte, EntryPt );
  786.   ReleaseSerialMutex();
  787.  }
  788.  else
  789.  {
  790.   rc = XSrvNormalQuit( AppTerminated, mte, EntryPt );
  791.  }
  792.  return(rc);
  793. }
  794.  
  795. /*****************************************************************************/
  796. /* xSetExecAddr()                                                            */
  797. /*                                                                           */
  798. /* Description:                                                              */
  799. /*                                                                           */
  800. /*   Set the exec address for the current thread.                            */
  801. /*                                                                           */
  802. /* Parameters:                                                               */
  803. /*                                                                           */
  804. /*   ExecAddr   Eip where we want to execute.                                */
  805. /*                                                                           */
  806. /* Return:                                                                   */
  807. /*                                                                           */
  808. /*   rc             0 or 1                                                   */
  809. /*                                                                           */
  810. /* Assumptions:                                                              */
  811. /*                                                                           */
  812. /*****************************************************************************/
  813. APIRET xSetExecAddr(ULONG ExecAddr )
  814. {
  815.  APIRET rc = 0;
  816.  
  817.  if(IsEspRemote())
  818.  {
  819.   RequestSerialMutex();
  820.   rc = TxSetExecAddr( ExecAddr );
  821.   ReleaseSerialMutex();
  822.  }
  823.  else
  824.  {
  825.   rc = XSrvSetExecAddr( ExecAddr );
  826.  }
  827.  return(rc);
  828. }
  829.  
  830. /*****************************************************************************/
  831. /* xDefWps()                                                                 */
  832. /*                                                                           */
  833. /* Description:                                                              */
  834. /*                                                                           */
  835. /*   Define the watch points to the probe.                                   */
  836. /*                                                                           */
  837. /* Parameters:                                                               */
  838. /*                                                                           */
  839. /*   pRegs    -  ->array of watch point definitions.                         */
  840. /*   size     -  size of the block of debug register data.                   */
  841. /*                                                                           */
  842. /* Return:                                                                   */
  843. /*                                                                           */
  844. /* Assumptions:                                                              */
  845. /*                                                                           */
  846. /*****************************************************************************/
  847. void xDefWps( void *pRegs, int size )
  848. {
  849.  if(IsEspRemote())
  850.  {
  851.   RequestSerialMutex();
  852.   TxDefWps( pRegs,size );
  853.   ReleaseSerialMutex();
  854.  }
  855.  else
  856.  {
  857.   XSrvDefWps( pRegs,size);
  858.  }
  859. }
  860.  
  861. /*****************************************************************************/
  862. /* xPutInWps()                                                               */
  863. /*                                                                           */
  864. /* Description:                                                              */
  865. /*                                                                           */
  866. /*   Put in watch points.                                                    */
  867. /*                                                                           */
  868. /* Parameters:                                                               */
  869. /*                                                                           */
  870. /*   pIndexes -  ->array that will receive the watch point indexes.          */
  871. /*                                                                           */
  872. /* Return:                                                                   */
  873. /*                                                                           */
  874. /* Assumptions:                                                              */
  875. /*                                                                           */
  876. /*****************************************************************************/
  877. void xPutInWps( ULONG *pIndexes )
  878. {
  879.  if(IsEspRemote())
  880.  {
  881.   RequestSerialMutex();
  882.   TxPutInWps( pIndexes );
  883.   ReleaseSerialMutex();
  884.  }
  885.  else
  886.  {
  887.   XSrvPutInWps(pIndexes);
  888.  }
  889. }
  890.  
  891. /*****************************************************************************/
  892. /* xPullOutWps()                                                             */
  893. /*                                                                           */
  894. /* Description:                                                              */
  895. /*                                                                           */
  896. /*   Pull out watch points.                                                  */
  897. /*                                                                           */
  898. /* Parameters:                                                               */
  899. /*                                                                           */
  900. /* Return:                                                                   */
  901. /*                                                                           */
  902. /* Assumptions:                                                              */
  903. /*                                                                           */
  904. /*****************************************************************************/
  905. void xPullOutWps( void )
  906. {
  907.  if(IsEspRemote())
  908.  {
  909.   RequestSerialMutex();
  910.   TxPullOutWps( );
  911.   ReleaseSerialMutex();
  912.  }
  913.  else
  914.  {
  915.   XSrvPullOutWps();
  916.  }
  917. }
  918.  
  919. /*****************************************************************************/
  920. /* xGetMemoryBlock()                                                         */
  921. /*                                                                           */
  922. /* Description:                                                              */
  923. /*                                                                           */
  924. /*   Get a block of data.                                                    */
  925. /*                                                                           */
  926. /* Parameters:                                                               */
  927. /*                                                                           */
  928. /*   addr            pointer to address space in user's application.         */
  929. /*   BytesWanted     number of bytes to copy from the user's application.    */
  930. /*   pBytesObtained  pointer to number of bytes that were read in.           */
  931. /*                                                                           */
  932. /* Return:                                                                   */
  933. /*                                                                           */
  934. /*   pbytes          -> to block of bytes obtained.                          */
  935. /*                                                                           */
  936. /* Assumptions:                                                              */
  937. /*                                                                           */
  938. /*****************************************************************************/
  939. UCHAR *xGetMemoryBlock( ULONG addr , int BytesWanted, int *pBytesObtained )
  940. {
  941.  UCHAR *pbytes;
  942.  
  943.  if(IsEspRemote())
  944.  {
  945.   RequestSerialMutex();
  946.   pbytes = TxGetMemoryBlock( addr,BytesWanted, pBytesObtained );
  947.   ReleaseSerialMutex();
  948.   return( pbytes );
  949.  }
  950.  else
  951.  {
  952.   return( XSrvGetMemoryBlock( addr,BytesWanted, pBytesObtained ) );
  953.  }
  954. }
  955.  
  956. /*****************************************************************************/
  957. /* xGetMemoryBlocks()                                                        */
  958. /*                                                                           */
  959. /* Description:                                                              */
  960. /*                                                                           */
  961. /*   Get some blocks of memory.                                              */
  962. /*                                                                           */
  963. /* Parameters:                                                               */
  964. /*                                                                           */
  965. /*  pDefBlks         -> to an array of addresses and sizes of mem blocks.    */
  966. /*  LengthOfDefBlk      length of the block defining the addrs & sizes.      */
  967. /*                                                                           */
  968. /* Return:                                                                   */
  969. /*                                                                           */
  970. /*  pMemBlks            -> to memory blocks.                                 */
  971. /*                                                                           */
  972. /* Assumptions:                                                              */
  973. /*                                                                           */
  974. /*  caller frees the pMemBlks allocation.                                    */
  975. /*                                                                           */
  976. /*****************************************************************************/
  977. void *xGetMemoryBlocks(void *pDefBlks,int LengthOfDefBlk)
  978. {
  979.  int   junk;
  980.  void *pMemBlks;
  981.  
  982.  if(IsEspRemote())
  983.  {
  984.   RequestSerialMutex();
  985.   pMemBlks = TxGetMemoryBlocks( pDefBlks, LengthOfDefBlk );
  986.   ReleaseSerialMutex();
  987.   return( pMemBlks );
  988.  }
  989.  else
  990.  {
  991.   return( XSrvGetMemoryBlocks( pDefBlks,&junk ) );
  992.  }
  993.  
  994. }
  995.  
  996. /*****************************************************************************/
  997. /* xSetExceptions()                                                          */
  998. /*                                                                           */
  999. /* Description:                                                              */
  1000. /*                                                                           */
  1001. /*   Get some blocks of memory.                                              */
  1002. /*                                                                           */
  1003. /* Parameters:                                                               */
  1004. /*                                                                           */
  1005. /*  pExceptionMap    -> to an array of exception notify/nonotify specs.      */
  1006. /*  length              length of the map in bytes.                          */
  1007. /*                                                                           */
  1008. /* Return:                                                                   */
  1009. /*                                                                           */
  1010. /* Assumptions:                                                              */
  1011. /*                                                                           */
  1012. /*****************************************************************************/
  1013. void xSetExceptions( UCHAR *pExceptionMap, int length)
  1014. {
  1015.  
  1016.  if(IsEspRemote())
  1017.  {
  1018.   RequestSerialMutex();
  1019.   TxSetExceptions( pExceptionMap , length);
  1020.   ReleaseSerialMutex();
  1021.  }
  1022.  else
  1023.  {
  1024.   XSrvSetExceptions( pExceptionMap , length);
  1025.  }
  1026. }
  1027.  
  1028. /*****************************************************************************/
  1029. /* xSetExecThread()                                                          */
  1030. /*                                                                           */
  1031. /* Description:                                                              */
  1032. /*                                                                           */
  1033. /*   Set the execution context to another thread.                            */
  1034. /*                                                                           */
  1035. /* Parameters:                                                               */
  1036. /*                                                                           */
  1037. /*   pExecAddr -> to address that will receive the flat execution address.   */
  1038. /*   pptb      -> to the ptrace buffer that we will fill in for the caller.  */
  1039. /*   tid          the thread we're establishing context in.                  */
  1040. /*                                                                           */
  1041. /* Return:                                                                   */
  1042. /*                                                                           */
  1043. /*   rc        0=>success                                                    */
  1044. /*             1=>failure                                                    */
  1045. /*                                                                           */
  1046. /* Assumption:                                                               */
  1047. /*                                                                           */
  1048. /*****************************************************************************/
  1049. APIRET xSetExecThread(ULONG *pExecAddr,PtraceBuffer *pptb, UINT tid)
  1050. {
  1051.  APIRET rc;
  1052.  
  1053.  if(IsEspRemote())
  1054.  {
  1055.   RequestSerialMutex();
  1056.   rc = TxSetExecThread(pExecAddr,pptb, tid);
  1057.   ReleaseSerialMutex();
  1058.  }
  1059.  else
  1060.  {
  1061.   rc = XSrvSetExecThread(pExecAddr,pptb, tid);
  1062.  }
  1063.  return(rc);
  1064. }
  1065.  
  1066. /*****************************************************************************/
  1067. /* xWriteRegs()                                                              */
  1068. /*                                                                           */
  1069. /* Description:                                                              */
  1070. /*                                                                           */
  1071. /*   Write the registers to the application.                                 */
  1072. /*                                                                           */
  1073. /* Parameters:                                                               */
  1074. /*                                                                           */
  1075. /*   pExecAddr -> to address that will receive the flat execution address.   */
  1076. /*   pptb      -> to the ptrace buffer that we will fill in for the caller.  */
  1077. /*                                                                           */
  1078. /* Return:                                                                   */
  1079. /*                                                                           */
  1080. /*   rc        0=>success                                                    */
  1081. /*             1=>failure                                                    */
  1082. /*                                                                           */
  1083. /* Assumption:                                                               */
  1084. /*                                                                           */
  1085. /*****************************************************************************/
  1086. APIRET xWriteRegs(ULONG *pExecAddr,PtraceBuffer *pptb)
  1087. {
  1088.  APIRET rc;
  1089.  
  1090.  if(IsEspRemote())
  1091.  {
  1092.   RequestSerialMutex();
  1093.   rc = TxWriteRegs(pExecAddr,pptb);
  1094.   ReleaseSerialMutex();
  1095.  }
  1096.  else
  1097.  {
  1098.   rc = XSrvWriteRegs(pExecAddr,pptb);
  1099.  }
  1100.  return(rc);
  1101. }
  1102.  
  1103. /*****************************************************************************/
  1104. /* xGetCoRegs()                                                              */
  1105. /*                                                                           */
  1106. /* Description:                                                              */
  1107. /*                                                                           */
  1108. /*   Get the co-processor registers.                                         */
  1109. /*                                                                           */
  1110. /* Parameters:                                                               */
  1111. /*                                                                           */
  1112. /*   pExecAddr -> to address that will receive the flat execution address.   */
  1113. /*   pptb      -> to the ptrace buffer that we will fill in for the caller.  */
  1114. /*                                                                           */
  1115. /* Return:                                                                   */
  1116. /*                                                                           */
  1117. /*   rc        0=>success                                                    */
  1118. /*             1=>failure                                                    */
  1119. /*                                                                           */
  1120. /* Assumption:                                                               */
  1121. /*                                                                           */
  1122. /*****************************************************************************/
  1123. APIRET xGetCoRegs(void *pCoproc_regs)
  1124. {
  1125.  APIRET rc;
  1126.  
  1127.  if(IsEspRemote())
  1128.  {
  1129.   RequestSerialMutex();
  1130.   rc = TxGetCoRegs(pCoproc_regs);
  1131.   ReleaseSerialMutex();
  1132.  }
  1133.  else
  1134.  {
  1135.   rc = XSrvGetCoRegs(pCoproc_regs);
  1136.  }
  1137.  return(rc);
  1138. }
  1139.  
  1140. /*****************************************************************************/
  1141. /* xTerminateESP()                                                           */
  1142. /*                                                                           */
  1143. /* Description:                                                              */
  1144. /*                                                                           */
  1145. /*   Terminate the probe.                                                    */
  1146. /*                                                                           */
  1147. /* Parameters:                                                               */
  1148. /*                                                                           */
  1149. /* Return:                                                                   */
  1150. /*                                                                           */
  1151. /* Assumptions:                                                              */
  1152. /*                                                                           */
  1153. /*  The decision to terminate ESP has already been made.                     */
  1154. /*                                                                           */
  1155. /*****************************************************************************/
  1156. void xTerminateESP( void )
  1157. {
  1158.  
  1159.  RequestSerialMutex();
  1160.  TxTerminateESP();
  1161.  ReleaseSerialMutex();
  1162.  return;
  1163. }
  1164.  
  1165. /*****************************************************************************/
  1166. /* xSetEspRunOpts()                                                       919*/
  1167. /*                                                                           */
  1168. /* Description:                                                              */
  1169. /*                                                                           */
  1170. /*   Send run options to esp. Only called if probe is remote.                */
  1171. /*                                                                           */
  1172. /* Parameters:                                                               */
  1173. /*                                                                           */
  1174. /*  pEspRunOpts    ->to block of data containing flags and names             */
  1175. /*                                                                           */
  1176. /* Return:                                                                   */
  1177. /*                                                                           */
  1178. /* Assumptions:                                                              */
  1179. /*                                                                           */
  1180. /*                                                                           */
  1181. /*****************************************************************************/
  1182. void xSetEspRunOpts( ESP_RUN_OPTS *pEspRunOpts )
  1183. {
  1184.  RequestSerialMutex();
  1185.  TxSetEspRunOpts(pEspRunOpts);
  1186.  ReleaseSerialMutex();
  1187. }
  1188.  
  1189. /*****************************************************************************/
  1190. /* xSendCtrlBreak()                                                       917*/
  1191. /*                                                                           */
  1192. /* Description:                                                              */
  1193. /*                                                                           */
  1194. /*   Send a Ctrl-Break message to esp.                                       */
  1195. /*                                                                           */
  1196. /* Parameters:                                                               */
  1197. /*                                                                           */
  1198. /*   handle      the connection handle we're sending the ctrl_break to.      */
  1199. /*                                                                           */
  1200. /* Return:                                                                   */
  1201. /*                                                                           */
  1202. /* Assumptions:                                                              */
  1203. /*                                                                           */
  1204. /*  The queue will request/release the mutex during the ctrl-break           */
  1205. /*  handling.                                                                */
  1206. /*                                                                           */
  1207. /*****************************************************************************/
  1208. void xSendCtrlBreak( LHANDLE handle, USHORT pid )
  1209. {
  1210.  TxSendCtrlBreak( handle, pid );
  1211.  return;
  1212. }
  1213.  
  1214. /*****************************************************************************/
  1215. /* xStartQueListenThread()                                                919*/
  1216. /*                                                                           */
  1217. /* Description:                                                              */
  1218. /*                                                                           */
  1219. /*   Start a que listen thread in esp.                                       */
  1220. /*                                                                           */
  1221. /* Parameters:                                                               */
  1222. /*                                                                           */
  1223. /* Return:                                                                   */
  1224. /*                                                                           */
  1225. /* Assumptions:                                                              */
  1226. /*                                                                           */
  1227. /*                                                                           */
  1228. /*****************************************************************************/
  1229. void xStartQueListenThread( void )
  1230. {
  1231.  RequestSerialMutex();
  1232.  TxStartQueListenThread( );
  1233.  ReleaseSerialMutex();
  1234.  return;
  1235. }
  1236.  
  1237. /*****************************************************************************/
  1238. /* xStartEspQue()                                                         919*/
  1239. /*                                                                           */
  1240. /* Description:                                                              */
  1241. /*                                                                           */
  1242. /*   Start an esp que.                                                       */
  1243. /*                                                                           */
  1244. /* Parameters:                                                               */
  1245. /*                                                                           */
  1246. /* Return:                                                                   */
  1247. /*                                                                           */
  1248. /*   rc                                                                      */
  1249. /*                                                                           */
  1250. /* Assumptions:                                                              */
  1251. /*                                                                           */
  1252. /*****************************************************************************/
  1253. APIRET xStartEspQue( void )
  1254. {
  1255.  APIRET rc;
  1256.  
  1257.  RequestSerialMutex();
  1258.  rc = TxStartEspQue( );
  1259.  ReleaseSerialMutex();
  1260.  return(rc);
  1261. }
  1262.  
  1263. /*****************************************************************************/
  1264. /* xConnectEsp()                                                             */
  1265. /*                                                                           */
  1266. /* Description:                                                              */
  1267. /*                                                                           */
  1268. /*  Connect to the probe for the parameter pid and wait until we             */
  1269. /*  get verification that the message has been received and sent to          */
  1270. /*  the queue.                                                               */
  1271. /*                                                                           */
  1272. /* Parameters:                                                               */
  1273. /*                                                                           */
  1274. /*   handle   handle of the connection to the probe.                         */
  1275. /*   pid      process id of the probe.                                       */
  1276. /*                                                                           */
  1277. /* Return:                                                                   */
  1278. /*                                                                           */
  1279. /* Assumptions:                                                              */
  1280. /*                                                                           */
  1281. /*****************************************************************************/
  1282. void xConnectEsp( LHANDLE handle, USHORT pid )
  1283. {
  1284.  RequestSerialMutex();
  1285.  TxConnectEsp( handle, pid );
  1286.  ReleaseSerialMutex();
  1287. }
  1288.  
  1289. /*****************************************************************************/
  1290. /* xSendKillListen()                                                         */
  1291. /*                                                                           */
  1292. /* Description:                                                              */
  1293. /*                                                                           */
  1294. /*   Send a command to kill the listen thread when connected via a           */
  1295. /*   parallel connection.                                                    */
  1296. /*                                                                           */
  1297. /* Parameters:                                                               */
  1298. /*                                                                           */
  1299. /*   handle      the connection handle.                                      */
  1300. /*                                                                           */
  1301. /* Return:                                                                   */
  1302. /*                                                                           */
  1303. /* Assumptions:                                                              */
  1304. /*                                                                           */
  1305. /*****************************************************************************/
  1306. void xSendKillListen( LHANDLE handle )
  1307. {
  1308.  TxSendKillListen( handle );
  1309.  return;
  1310. }
  1311.  
  1312. /*****************************************************************************/
  1313. /* xSelectSession()                                                          */
  1314. /*                                                                           */
  1315. /* Description:                                                              */
  1316. /*                                                                           */
  1317. /*   Select the debuggee session.                                            */
  1318. /*                                                                           */
  1319. /* Parameters:                                                               */
  1320. /*                                                                           */
  1321. /* Return:                                                                   */
  1322. /*                                                                           */
  1323. /* Assumption:                                                               */
  1324. /*                                                                           */
  1325. /*****************************************************************************/
  1326. void xSelectSession( void )
  1327. {
  1328.  RequestSerialMutex();
  1329.  TxSelectSession();
  1330.  ReleaseSerialMutex();
  1331. }
  1332.