home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / CBRK.C < prev    next >
Text File  |  1996-04-18  |  9KB  |  242 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   cbrk.c                                                                  */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*  complex and data breakpoint handling                                     */
  7. /*                                                                           */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  12. /*                                                                           */
  13. /*                                                                           */
  14. /*...16->32 port.                                                            */
  15. /*...                                                                        */
  16. /*... 02/08/91  101   Joe       port to 32 bit.                              */
  17. /*... 02/08/91  112   Joe       port to 32 bit.                              */
  18. /*                                                                           */
  19. /*...Release 1.00 (Pre-release 1)                                            */
  20. /*...                                                                        */
  21. /*... 07/09/91  206   srinivas  Hooking up of complex break points.          */
  22. /*...                                                                        */
  23. /*...Release 1.00 (03/03/92)                                                 */
  24. /*...                                                                        */
  25. /*... 03/12/92  604   Srinivas  Conditional break points failing on signed   */
  26. /*...                           variables.                                   */
  27. /*****************************************************************************/
  28. #include "all.h"
  29.  
  30. extern BRKCOND      DataBreak;
  31. extern uchar        IfDataBreak;
  32. extern uchar        IsAddrExpr;         /* Set by ParseExpr                  */
  33. extern uint         ExprAddr;           /* Set by ParseExpr               101*/
  34. extern uint         ExprMid;            /* Set by ParseExpr                  */
  35. extern uint         ExprTid;            /* Set by ParseExpr                  */
  36. extern PtraceBuffer AppPTB;
  37.  
  38. EvalCbrk(BRKCOND *p)
  39. {
  40.     union
  41.     {
  42.      char  _8;
  43.      short _16;                         /*                                206*/
  44.      long  _32;
  45.     }data;
  46.  
  47.     char  *charptr;
  48.     short   *wordptr;                   /*                                206*/
  49.     long  *longptr;
  50.     int    bytesread;
  51.  
  52.     uint target = p->opaddr;            /*                                206*/
  53.  
  54.     if( TestBit(target,STACKADDRBIT) )  /*                                206*/
  55.     {
  56.       if( TestBit(target,STACKADDRSIGN) == FALSE )                      /*206*/
  57.          ResetBit( target, STACKADDRBIT );                              /*206*/
  58.       target += AppPTB.EBP;
  59.       if( AppPTB.SSAtr == 0 )                                           /*206*/
  60.          target = Data_SelOff2Flat( AppPTB.SS, LoFlat(target) );
  61.     }                                   /*                                206*/
  62.  
  63.     switch( p->opsize ){
  64.  
  65.       case 2:
  66.  
  67.         data._32 = 0;
  68.         wordptr = (short *)DBGet(target, 2, (uint *)&bytesread );       /*206*/
  69.         if ( wordptr )
  70.         {
  71.          data._16 = *wordptr;
  72.          break;
  73.         }
  74.         goto failed;
  75.  
  76.       case -2:
  77.  
  78.         wordptr = (short *)DBGet(target, 2, (uint *)&bytesread );       /*206*/
  79.         if ( wordptr )
  80.         {
  81.          data._16 = *wordptr;
  82.          data._32 = data._16;
  83.          break;
  84.         }
  85.         goto failed;
  86.  
  87.       case 4:
  88.       case -4:
  89.         longptr = ( long *)DBGet(target, 4, (uint *)&bytesread );
  90.         if ( longptr )
  91.         {
  92.          data._32 = *longptr;
  93.          break;
  94.         }
  95.         goto failed;
  96.  
  97.       case 1:
  98.  
  99.         data._32 = 0;
  100.         charptr = ( char *)DBGet(target, 1, (uint *)&bytesread );
  101.         if ( charptr )
  102.         {
  103.          data._8 = *charptr;
  104.          break;
  105.         }
  106.         goto failed;
  107.  
  108.       case -1:
  109.  
  110.         charptr = ( char *)DBGet(target, 1, (uint *)&bytesread );
  111.         if ( charptr )
  112.         {
  113.          data._8 = *charptr;
  114.          data._32 = data._8;
  115.          break;
  116.         }
  117.         goto failed;
  118.  
  119.     }
  120.     switch( p->relation ){
  121.       case COND_NE:  return( data._32 != p->constant );
  122.       case COND_EQ:  return( data._32 == p->constant );
  123.       case COND_GT:  return( data._32 >  p->constant );
  124.       case COND_GE:  return( data._32 >= p->constant );
  125.       case COND_LT:  return( data._32 <  p->constant );
  126.       case COND_LE:  return( data._32 <= p->constant );
  127.       case COND_GTU: return( (ulong)data._32 >  (ulong)p->constant );
  128.       case COND_GEU: return( (ulong)data._32 >= (ulong)p->constant );
  129.       case COND_LTU: return( (ulong)data._32 <  (ulong)p->constant );
  130.       case COND_LEU: return( (ulong)data._32 <= (ulong)p->constant );
  131.     }
  132.     failed:
  133.       return( TRUE );
  134.  
  135. }
  136.  
  137. #define NRELOPS 7
  138. static  twoc relops[ NRELOPS ] = {
  139.   '>' + 256*' ',   /*0  >   */
  140.   '>' + 256*'=',   /*1  >=  */
  141.   '<' + 256*' ',   /*2  <   */
  142.   '<' + 256*'=',   /*3  <=  */
  143.   '!' + 256*'=',   /*4  !=  */
  144.   '=' + 256*'=',   /*5  ==  */
  145.   '=' + 256*' '    /*6  =   */
  146. };
  147. #define RELOP_NE 4
  148.  
  149. static  scondtab[ NRELOPS ] = {
  150.   COND_GT, COND_GE, COND_LT, COND_LE, COND_NE, COND_EQ, COND_EQ
  151. };/*  0        1        2        3        4        5        6  */
  152.  
  153. static  ucondtab[ NRELOPS ] = {
  154.   COND_GTU, COND_GEU, COND_LTU, COND_LEU, COND_NE, COND_EQ, COND_EQ
  155. };/*  0         1         2         3         4        5        6  */
  156.  
  157. #define NOKTYPES 6
  158. static  ushort oktypes[ NOKTYPES ] = {  /*                                101*/
  159.   TYPE_CHAR,  /*0*/                     /*                                101*/
  160.   TYPE_SHORT, /*1*/                     /*                                101*/
  161.   TYPE_LONG,  /*2*/                     /*                                101*/
  162.   TYPE_UCHAR, /*3*/                     /*                                101*/
  163.   TYPE_USHORT,/*4*/                     /*                                101*/
  164.   TYPE_ULONG  /*5*/                     /*                                101*/
  165. };
  166. static  uchar oktypesigned[ NOKTYPES ] = {
  167.   TRUE, TRUE, TRUE, FALSE, FALSE, FALSE
  168. };/*0     1     2     3      4      5  */
  169.  
  170. static  uchar term2msg[] = "Constant required after ==";
  171. #define T2MOP 24          /*0123456789012345678901234*/
  172. static  uchar relopmsg[] =
  173. "Syntax: var op const   (op is one of ==,!=,>=,<=,>,<";
  174.  
  175.  
  176.     uchar *
  177. ParseCbrk(BRKCOND *p,uint mid,uint lno, int sfi)
  178. {
  179.     uchar *cp;                          /* was register.                  112*/
  180.     uint opx, n, IsSigned;
  181.  
  182.  ULONG typeno;
  183.  
  184.     if( *(cp = p->pCondition) ){
  185.         if( !(cp = ParseExpr(cp,0x10,mid,lno, sfi)) || !IsAddrExpr )
  186.             return( "Incorrect variable name" );
  187.         if( (ExprAddr >> REGADDCHECKPOS) == REGISTERTYPEADDR )
  188.             return( "Can't use register variable" );
  189.         p->opaddr = ExprAddr;
  190.  
  191.         if( *cp ){
  192.             if( (opx = windex(relops, NRELOPS, *(twoc*)cp)) == NRELOPS )
  193.                 return( relopmsg );
  194.         }else
  195.             opx = RELOP_NE;
  196.  
  197.         /* Set the type of comparison based on the variable type and relop */
  198.         typeno = HandleUserDefs( mid, ExprTid );
  199.         if( typeno  ){
  200.             switch( QtypeGroup(ExprMid, typeno ) ){
  201.               case TG_SCALAR:
  202.                 if( (n = windex(oktypes, NOKTYPES, typeno )) == NOKTYPES )
  203.                     goto caseBadType;
  204.                 IsSigned = oktypesigned[n];  break;
  205.               case TG_POINTER:
  206.                 IsSigned = FALSE;  break;
  207.               default:
  208.               caseBadType:
  209.                 return( "Unsupported variable type" );
  210.             }
  211.             p->opsize = (signed char)QtypeSize(ExprMid, typeno );       /*604*/
  212.  
  213.         }else
  214.             p->opsize = (signed char)sizeof(uint);                      /*604*/
  215.  
  216.         if( IsSigned ){
  217.             p->opsize = (signed char)((signed char)0 - p->opsize);      /*604*/
  218.             p->relation = (uchar)scondtab[opx];
  219.         }else{
  220.             p->relation = (uchar)ucondtab[opx];
  221.         }
  222.  
  223.         /* Set the constant to compare the variable against */
  224.         if( *cp )
  225.         {
  226.          extern long CmplxBkptVal;
  227.          cp = ParseExpr(cp+2,0,0,0, sfi);
  228.          if( !cp )
  229.          {
  230.           *(twoc*)(term2msg+T2MOP) = relops[opx];
  231.           return( term2msg );
  232.          }
  233.          p->constant = CmplxBkptVal;
  234.         }else
  235.         {
  236.          return( "This feature not implemented yet!" );
  237.         }
  238.     }
  239.  
  240.     return( NULL );
  241. }
  242.