home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / XSRVWPS.C < prev    next >
Text File  |  1994-10-10  |  10KB  |  202 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   xsrvwps.c                                                               */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Allow user to define watch points and put in the watch points.          */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*...Release 1.00 (03/03/92)                                                 */
  12. /*...                                                                        */
  13. /*... 03/10/92  602   Srinivas  Hooking up watch points.                     */
  14. /*                                                                           */
  15. /*****************************************************************************/
  16.  
  17. #include "all.h"
  18.  
  19. static WP_REGISTER Db_Regs[NODEBUGREGS];/* hardware debug registers          */
  20.  
  21. /*****************************************************************************/
  22. /* XSrvDefWps()                                                              */
  23. /*                                                                           */
  24. /* Description:                                                              */
  25. /*                                                                           */
  26. /*    Defines the watch points in the x-server.                              */
  27. /*                                                                           */
  28. /* Parameters:                                                               */
  29. /*                                                                           */
  30. /*   pRegs    -  ->array of watch point definitions.                         */
  31. /*   size     -  size of the block of debug register data.                   */
  32. /*                                                                           */
  33. /* Return:                                                                   */
  34. /*                                                                           */
  35. /*   void                                                                    */
  36. /*****************************************************************************/
  37. void XSrvDefWps( void *pRegs , int size )
  38. {
  39.  /****************************************************************************/
  40.  /* clear any watch points currently set as well as any pending wp           */
  41.  /* notifications.                                                           */
  42.  /****************************************************************************/
  43.  XSrvPullOutWps( );
  44.  memcpy(Db_Regs,pRegs,size );
  45. }
  46.  
  47. /*****************************************************************************/
  48. /* XSrvPutInWps()                                                            */
  49. /*                                                                           */
  50. /* Description:                                                              */
  51. /*                                                                           */
  52. /*    Scans the debug registers and sets the watch points.                   */
  53. /*                                                                           */
  54. /* Parameters:                                                               */
  55. /*                                                                           */
  56. /*  pIndexes   ->to an array of watch point indexes.                         */
  57. /*                                                                           */
  58. /* Return:                                                                   */
  59. /*                                                                           */
  60. /*****************************************************************************/
  61. void  XSrvPutInWps( ULONG *pIndexes )
  62. {
  63.   PtraceBuffer ptb;
  64.   uint         i;
  65.   int          rc;
  66.  
  67.   for ( i = 0 ; i < NODEBUGREGS ; i++)
  68.   {
  69.      if( (Db_Regs[i].Address != 0) &&
  70.          (Db_Regs[i].Status == ENABLED) &&
  71.          (Db_Regs[i].IsSet  == FALSE) )
  72.      {
  73.         memset(&ptb,0,sizeof(ptb));
  74.         ptb.Pid   = GetEspProcessID();
  75.         ptb.Addr  = Db_Regs[i].Address;
  76.         ptb.Index = 0;
  77.         ptb.Tid   = 1;
  78.  
  79.         /*********************************************************************/
  80.         /* set the size of the watch point.                                  */
  81.         /*********************************************************************/
  82.         switch (Db_Regs[i].Size)
  83.         {
  84.            case 0:
  85.              ptb.Len = 1;
  86.              break;
  87.            case 1:
  88.              ptb.Len = 2;
  89.              break;
  90.            case 2:
  91.              ptb.Len = 4;
  92.              break;
  93.         }
  94.  
  95.         /*********************************************************************/
  96.         /* set the scope of the watch point.                                 */
  97.         /*********************************************************************/
  98.         switch (Db_Regs[i].Scope)
  99.         {
  100.            case WPS_LOCAL:
  101.              ptb.Value = DBG_W_Local;
  102.              break;
  103.            case WPS_GLOBAL:
  104.              ptb.Value = DBG_W_Global;
  105.              break;
  106.         }
  107.  
  108.         /*********************************************************************/
  109.         /* set the type of the watch point.                                  */
  110.         /*********************************************************************/
  111.         switch (Db_Regs[i].Type)
  112.         {
  113.            case READWRITE:
  114.              ptb.Value += DBG_W_ReadWrite;
  115.              break;
  116.            case WRITE:
  117.              ptb.Value += DBG_W_Write;
  118.              break;
  119.            case EXECUTE:
  120.              ptb.Value += DBG_W_Execute;
  121.              break;
  122.         }
  123.  
  124.         ptb.Cmd = DBG_C_SetWatch;
  125.         rc = DosDebug(&ptb);
  126.         if ( rc || (ptb.Cmd != DBG_N_Success) )
  127.            return;
  128.  
  129.         Db_Regs[i].IsSet   = TRUE;
  130.         Db_Regs[i].Wpindex = ptb.Index;
  131.      }
  132.   }
  133.   /***************************************************************************/
  134.   /* - give the assigned indexes back to the caller.                         */
  135.   /***************************************************************************/
  136.   for( i=0; i<NODEBUGREGS; i++ )
  137.    *pIndexes++ = Db_Regs[i].Wpindex;
  138.  
  139.   return;
  140. }
  141.  
  142. /*****************************************************************************/
  143. /* XSrvPullOutWps()                                                          */
  144. /*                                                                           */
  145. /* Description:                                                              */
  146. /*                                                                           */
  147. /*    Scans the debug registers and clears watch points that are currently   */
  148. /*    set. If a watch point was hit it has already been cleared.             */
  149. /*                                                                           */
  150. /* Parameters:                                                               */
  151. /*                                                                           */
  152. /* Return:                                                                   */
  153. /*                                                                           */
  154. /*****************************************************************************/
  155. void  XSrvPullOutWps( void )
  156. {
  157.   PtraceBuffer ptb;
  158.   uint         i;
  159.  
  160.   /***************************************************************************/
  161.   /* - Clear the watch points. If there are any pending notifications        */
  162.   /*   resulting from multiple watch point hits occurring at the             */
  163.   /*   same execution address, then these notifications will be lost         */
  164.   /*   into the ether. This could happen if you set all four watch points    */
  165.   /*   on the same variable.                                                 */
  166.   /***************************************************************************/
  167.   for ( i = 0 ; i < NODEBUGREGS ; i++)
  168.   {
  169.      if( Db_Regs[i].Status == ENABLED )
  170.      {
  171.         memset(&ptb,0,sizeof(ptb));
  172.         ptb.Pid   = GetEspProcessID();
  173.         ptb.Index = Db_Regs[i].Wpindex;
  174.         ptb.Cmd   = DBG_C_ClearWatch;
  175.         DosDebug(&ptb);
  176.      }
  177.   }
  178.   return;
  179. }
  180.  
  181. /*****************************************************************************/
  182. /* MarkWpNotSet()                                                            */
  183. /*                                                                           */
  184. /* Description:                                                              */
  185. /*                                                                           */
  186. /*    After a watch point is hit, then we mark it as not set.                */
  187. /*                                                                           */
  188. /* Parameters:                                                               */
  189. /*                                                                           */
  190. /*   wpindex   index of the watchpoint that got hit.                         */
  191. /*                                                                           */
  192. /* Return:                                                                   */
  193. /*****************************************************************************/
  194. void MarkWpNotSet( ULONG wpindex )
  195. {
  196.  int i;
  197.  
  198.  for(i=0;i < NODEBUGREGS; i++ )
  199.   if( Db_Regs[i].Wpindex == wpindex )
  200.    Db_Regs[i].IsSet = FALSE;
  201. }
  202.