home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / SHOWD.C < prev    next >
Text File  |  1996-05-16  |  48KB  |  685 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   showd.c                                                                 */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  data display routines.                                                   */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /* History:                                                                  */
  11. /*                                                                           */
  12. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  13. /*                                                                           */
  14. /*...16->32 port.                                                            */
  15. /*...                                                                        */
  16. /*... 02/08/91  101   Joe       port to 32 bit.                              */
  17. /*... 02/08/91  107   Dave      port to 32 bit.                              */
  18. /*... 02/08/91  112   Joe       port to 32 bit.                              */
  19. /*                                                                           */
  20. /*...Release 1.00 (Pre-release 1)                                            */
  21. /*...                                                                        */
  22. /*... 07/09/91  203   srinivas  ptr->ptr hangs in the data window            */
  23. /*                              (POINTERTEW testcase)                        */
  24. /*... 07/09/91  205   srinivas  Hooking up of register variables.            */
  25. /*... 07/15/91  212   srinivas  Bit Fields not being displayed.              */
  26. /*... 07/26/91  219   srinivas  handling near pointers.                      */
  27. /*... 08/05/91  221   srinivas  Hooking up registers and constants in data   */
  28. /*                              window.                                      */
  29. /*... 08/14/91  215   Christina add support for HLL format                   */
  30. /*... 08/21/91  233   Christina fix TYPEDEFs in HLL format                   */
  31. /*... 09/16/91  239   Srinivas  Void ptr handling for cl386 & Toroc.         */
  32. /*... 09/25/91  242   Srinivas  PLX bit fields not being shown properly.     */
  33. /*... 09/25/91  243   Srinivas  ISADDREXPR global flag problems.             */
  34. /*... 09/26/91  244   Srinivas  optimise calls to parse expr.                */
  35. /*...                                                                        */
  36. /*...Release 1.00 (Pre-release 105 10/10/91)                                 */
  37. /*...                                                                        */
  38. /*... 10/23/91  307   Srinivas  Trap when a pointer points to a long string  */
  39. /*...                                                                        */
  40. /*...Release 1.00 (Pre-release 1.08 10/10/91)                                */
  41. /*...                                                                        */
  42. /*... 12/27/91  502   Srinivas  Simple PL/X based vars display the name but  */
  43. /*...                           have no value associated with them.          */
  44. /*... 02/07/92  512   Srinivas  Handle Toronto "C" userdefs.                 */
  45. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  46. /*... 02/13/92  522   Srinivas  Size of bit fields in cl386 is not correct.  */
  47. /*... 02/13/92  523   Srinivas  Handle Toronto "C" Bitfields.                */
  48. /*...                                                                        */
  49. /*...Release 1.01 (04/03/92)                                                 */
  50. /*...                                                                        */
  51. /*... 05/08/92  701   Srinivas  Cua Interface.                               */
  52. /*...                                                                        */
  53. /*...Release 1.02 (10/22/92)                                                 */
  54. /*...                                                                        */
  55. /*... 01/26/93  809   Selwyn    HLL Level 2 support.                         */
  56. /*... 03/03/93  813   Joe       Revised types handling for HL03.             */
  57. /*...                           (Moved FormatdataItem to it's own file.)     */
  58. /*... 03/06/93  814   Joe       Signed 8 bit char not displaying correct     */
  59. /*...                           negative.                                    */
  60. /**Includes*******************************************************************/
  61.  
  62. #include "all.h"                        /* SD86 include files                */
  63.  
  64. /**Defines *******************************************************************/
  65.  
  66. #define SPCTAB 12                       /* space between dec & hex display   */
  67.  
  68. /**External declararions******************************************************/
  69.  
  70. extern uint        DataFileTop;         /* 1st rec shown of data file (0..N) */
  71. extern uint        DataFileBot;         /* last rec shown of data file (0..N)*/
  72. extern DFILE*      DataFileQ;           /*                                   */
  73. extern uint        ExprAddr;            /* Set by ParseExpr-Addr val of ex101*/
  74. extern SCOPE       ExprScope;           /* Set by ParseExpr-scope for expr   */
  75. extern uint        VioStartOffSet;      /* flag to tell were to start screen */
  76.                                         /* display.                       701*/
  77.  
  78. /**Static definitions ********************************************************/
  79.  
  80. static  struct {                        /*                                   */
  81.   uchar a;                              /*                                   */
  82.   uchar t[26];                          /*                                   */
  83. } CantEvalMsg =                         /* message issued when dfile expr    */
  84.             {Attrib(vaStgVal),          /* cannot be evaluated.              */
  85.              "Can't evaluate expression"/*                                   */
  86.             };                          /*                                   */
  87.                                         /*                                   */
  88. static  uchar BadAddrMsg[] =            /*                                   */
  89.             "Invalid Address";          /*                                   */
  90.  
  91.        uchar  Re_Parse_Data = FALSE;    /* flag to indicate wether all    244*/
  92.                                         /* variables in datawindow are to 244*/
  93.                                         /* be reparsed.                   244*/
  94.  
  95. /*****************************************************************************/
  96. /*  ShowData()                                                               */
  97. /*                                                                           */
  98. /* Description:                                                              */
  99. /*   display a variable.                                                     */
  100. /*                                                                           */
  101. /* Parameters:                                                               */
  102. /*   Nrows     the number  of rows available in the data window.             */
  103. /*                                                                           */
  104. /* Return:                                                                   */
  105. /*   void                                                                    */
  106. /*                                                                           */
  107. /* Assumptions:                                                              */
  108. /*                                                                           */
  109. /* Note: This code assumes "next" is the 1st field in the DFILE struct       */
  110. /*                                                                           */
  111. /*****************************************************************************/
  112.  void                                   /*                                   */
  113. ShowData( uint Nrows )                  /*                                   */
  114. {                                       /*                                   */
  115.  uint    n;                             /* just a integer.                   */
  116.  uint    rec;                           /* current data file record (0..N)   */
  117.  uint    row;                           /* current screen row (0..N)         */
  118.  uint    col;                           /* data window column.               */
  119.  int    incr = 0;                       /* # screen rows to used by the data */
  120.                                         /* object which is the same as the521*/
  121.                                         /* record consumed in the data file. */
  122.  DFILE *dfp;                            /* -> dfile node to display.         */
  123.  DFILE *dfpx;                           /* -> to lookahead dfile node.       */
  124.  DFILE *dfpfirst;                       /* -> to first dfile node to display.*/
  125.  uchar *cp;                             /* vestigial expr from ParseExpr.    */
  126.  uchar *msg;                            /* -> to a message buffer.           */
  127.  uchar  msgbuf[ MAXSYM+1 + 25 ];        /* the message buffer.               */
  128.  uchar  buffer[ MAXSYM+1 ];             /* another buffer for procedure name.*/
  129.  uint   maxdatarec;                     /* last rec of data file display(0-N)*/
  130.  uint   numnodes;                       /* number of nodes to display.       */
  131.  uint   nodecntr;                       /* display node index.               */
  132.  int    rc;                             /* return code.                      */
  133.  uchar *procname;                       /* procedure name.                   */
  134.  int    skip;                           /* # of items of data object to skip */
  135.                                         /* before the display.               */
  136. /*****************************************************************************/
  137. /* Let's handle some special cases first.                                    */
  138. /*  1. No dfile nodes and Nrows is not zero so init a data window and a file.*/
  139. /*     The data window will have Nrows display lines and the data file will  */
  140. /*     have Nrows data records.                                              */
  141. /*                                                                           */
  142. /*  2. some dfile nodes but Nrows is zero.                                   */
  143. /*****************************************************************************/
  144.  dfpfirst = (DFILE *)&DataFileQ;        /* ->to dfile ring pointer.          */
  145.  dfpx = dfpfirst->next;                 /* ->to lookahead node.              */
  146.  if( !dfpx )                            /* if empty dfile ring and           */
  147.  {                                      /*                                   */
  148.   if( Nrows - VioStartOffSet )          /* if a data window has not been  701*/
  149.   {                                     /* initialized, then initialize one. */
  150.    ClrScr(VioStartOffSet,Nrows-1,vaStgExp);                             /*701*/
  151.                                         /* window size = Nrows.              */
  152.    if(!DataFileTop)                     /*                                   */
  153.     DataFileBot = Nrows - 1;            /*                                   */
  154.   }                                     /*                                   */
  155.   Re_Parse_Data = FALSE;                /* Reset the parse var flag       244*/
  156.   return;                               /*                                   */
  157.  }                                      /*                                   */
  158.  else if( !Nrows )                      /* if dfile ring is not empty but    */
  159.  {                                      /*                                244*/
  160.   Re_Parse_Data = FALSE;                /* Reset the parse var flag       244*/
  161.   return;                               /* there is no data window, just ret.*/
  162.  }                                      /*                                244*/
  163. /*****************************************************************************/
  164. /* First we want to find the first node that falls in the data window.       */
  165. /* We know that there is at least one node in the dfile ring at this point   */
  166. /* and dfpx currently points to it.                                          */
  167. /*****************************************************************************/
  168.  for(;                                  /* scan ring beginning with 1st node.*/
  169.      dfpx;                              /* quit at the ground node.          */
  170.      dfpx = dfpx->next                  /* next node.                        */
  171.     )                                   /*                                   */
  172.  {                                      /*                                   */
  173.   if(dfpx->lrn <= DataFileTop)          /* if this node is before the data   */
  174.   {                                     /* window and there aren't any more  */
  175.    if(!dfpx->next)                      /* nodes then we're done.            */
  176.     break;                              /*                                   */
  177.    if(dfpx->next->lrn > DataFileTop)    /* if the next node is past the      */
  178.      break;                             /* start of the data window then     */
  179.   }                                     /* we're also done.                  */
  180.   else if(dfpx->lrn <= DataFileTop +    /* if the node falls inside the data */
  181.                       Nrows - 1 )       /* window then we're done.           */
  182.    break;                               /*                                   */
  183.  }                                      /* Otherwise, continue for loop.     */
  184. /*****************************************************************************/
  185. /* After we exit from this loop, we may have a null dfpfirst meaning that    */
  186. /* there are no nodes to display in the window.                              */
  187. /*****************************************************************************/
  188.  dfpfirst = dfpx;
  189.  if(!dfpfirst)                          /* if empty window then              */
  190.  {                                      /*                                   */
  191.   ClrScr(VioStartOffSet,Nrows-1,vaStgExp);/* clear the current window and 701*/
  192.   Re_Parse_Data = FALSE;                /* Reset the parse var flag       244*/
  193.   return;                               /* return.                           */
  194.  }                                      /*                                   */
  195. /*****************************************************************************/
  196. /* Now let's find the number of nodes to display info for. At this point,    */
  197. /* we know that there is a node in the dfile ring, but we don't know how     */
  198. /* many to display.                                                          */
  199. /*****************************************************************************/
  200.  numnodes = 0;                          /* one node for sure at this point.  */
  201.  maxdatarec = DataFileTop + Nrows - 1;  /* bottom of window in the data file.*/
  202.  for ( dfpx = dfpfirst;                 /* start at first node.   .          */
  203.        dfpx &&                          /*                                   */
  204.        dfpx->lrn <= maxdatarec;         /* done when lookahead out of window.*/
  205.        dfpx = dfpx->next,               /* update lookahead node.            */
  206.        numnodes++
  207.      ){;}
  208. /*****************************************************************************/
  209. /* Now let's display the data. Again, at this point, we know there is at     */
  210. /* least one node to display.                                                */
  211. /*                                                                           */
  212. /* NOTE:                                                                     */
  213. /* Each data object takes up incr lines in the data window and rec records in*/
  214. /* the data file.  This is a function of the difference between lrns of      */
  215. /* successive nodes. We have to remember that there may be gaps between nodes*/
  216. /* caused by ghost nodes of erase data objects.                              */
  217. /*                                                                           */
  218. /* NOTE:                                                                     */
  219. /* Normally the display row will be initialized to 0. However, this is not   */
  220. /* always the case as the user may enter an object anywhere in the window.   */
  221. /* Also, if the first node is erased then its ghost is left in the data file.*/
  222. /*                                                                           */
  223. /*****************************************************************************/
  224.  row = dfpfirst->lrn - DataFileTop;     /* compute first display row.        */
  225.  if((int)row < (int)VioStartOffSet)     /* can't be less than 0 though.   701*/
  226.   row = VioStartOffSet;                 /*                                701*/
  227.  if(row-VioStartOffSet)                 /* if it's not the first row,then 701*/
  228.   ClrScr(VioStartOffSet,row-1,vaStgExp);/* erase area prior to disp start 701*/
  229.  rec=DataFileTop + row;                 /* start at first data file record.  */
  230.  nodecntr = 1;                          /*                                   */
  231.  dfp = dfpfirst ;                       /* start at the first node.          */
  232.  for( ;                                 /*                                   */
  233.       nodecntr <= numnodes;             /* quit after all nodes processed.   */
  234.       nodecntr++,                       /* bump the node count.              */
  235.       row += incr,                      /* bump display row.                 */
  236.       rec += incr,                      /* bump data file row.               */
  237.       dfp = dfpx )                      /* -> to next node                   */
  238.  {                                      /*                                   */
  239. /*****************************************************************************/
  240. /* At this point we're going to display the node info, but we have to compute*/
  241. /* the increment of display for this node.                                   */
  242. /*****************************************************************************/
  243.   dfpx= dfp->next;                      /* -> to lookahead node.             */
  244.   incr = (dfpx)?dfpx->lrn - rec:MAXINT; /* compute the increment.            */
  245.   if( incr > (int)(Nrows - row) )       /* truncate increment if too big.    */
  246.    incr = Nrows - row;                  /*                                   */
  247.  
  248.  if (Re_Parse_Data)                     /*if flag is set reparse all vars 244*/
  249.  {                                      /*                                244*/
  250. /*****************************************************************************/
  251. /* Now we want to parse the expression and update the base address.          */
  252. /*****************************************************************************/
  253.   cp = ParseExpr(dfp->expr,             /* the node expression.              */
  254.                  0x10,                  /* use optional source line context. */
  255.                  dfp->mid,              /* module id.                        */
  256.                  dfp->lno,              /* source line number.               */
  257.                  dfp->sfi               /* source file index.                */
  258.                 );                      /*                                   */
  259.   if( !cp || *cp )                      /* if can't evaluate the expression, */
  260.   {                                     /*                                   */
  261.    msg = (uchar*) &CantEvalMsg;         /* then display a bad expression msg.*/
  262.    ClrScr(row,row+incr-1,vaStgExp);     /*                                   */
  263.    putrc( row, 0, dfp->expr );          /*                                   */
  264.    n = strlen(dfp->expr);               /*                                   */
  265.    col=(n > (STGCOL-1) ) ? n+2:STGCOL-1;/*                                   */
  266.    putrc( row, col , msg );             /*                                   */
  267.    continue;                            /*                                   */
  268.   }                                     /*                                   */
  269.   dfp->baseaddr = ExprAddr;             /* update -> to the data block.      */
  270.   dfp->scope    = ExprScope;            /* update -> to the data block.      */
  271.  }                                      /*                                244*/
  272.  
  273. /*****************************************************************************/
  274. /* Now we want to establish the stack frame of the expression if there is    */
  275. /* one.                                                                      */
  276. /*****************************************************************************/
  277.   dfp->sfx=StackFrameIndex(dfp->scope); /* get the stack frame index.        */
  278.   if( dfp->scope && !dfp->sfx )         /* if this is a stack variable but   */
  279.   {                                     /* it's not active, then display     */
  280.    msg = msgbuf;                        /* a " not active" message.          */
  281.    memset(buffer, 0, sizeof(buffer));
  282.    procname=CopyProcName(dfp->scope,    /*                                   */
  283.                          buffer,        /*                                   */
  284.                          sizeof(buffer) /*                                   */
  285.                         );              /*                                   */
  286.    sprintf( msg,                        /*                                521*/
  287.            "%c\"%s\" not active",       /*                                   */
  288.            Attrib(vaStgVal),            /*                                   */
  289.            procname                     /*                                   */
  290.          );                             /*                                   */
  291.    ClrScr(row,row+incr-1,vaStgExp);     /*                                   */
  292.    putrc( row, 0, dfp->expr );          /*                                   */
  293.    n = strlen(dfp->expr);               /*                                   */
  294.    col=(n > (STGCOL-1) ) ? n+2:STGCOL-1;/*                                   */
  295.    putrc( row, col , msg );             /*                                   */
  296.    continue;                            /*                                   */
  297.   }                                     /*                                   */
  298. /*****************************************************************************/
  299. /* Now display the node info.                                                */
  300. /*****************************************************************************/
  301.   skip = rec - dfp->lrn;
  302.   rc =(* dfp->shower) (dfp,             /* -> to dfile node.                 */
  303.                        row,             /* display row to start display.     */
  304.                        incr,            /* amount of rows to display.        */
  305.                        skip
  306.                       );                /*                                   */
  307.                                         /*                                   */
  308.   if( rc == FALSE )                     /* if can't show, then clear area.   */
  309.    ClrScr(row,row+incr-1,vaStgExp);     /*                                   */
  310.  }                                      /* end for loop.                     */
  311.  Re_Parse_Data = FALSE;                 /* Reset the parse var flag       244*/
  312. }                                       /* end ShowData().                   */
  313.  
  314. /*****************************************************************************/
  315. /*  DFILE *dfp;                                                              */
  316. /*  uint row;      screen row                                                */
  317. /*  uint rows;     # of screen rows                                          */
  318. /*  uint skip;     # of logical data file records to skip                    */
  319. /*                                                                           */
  320. /*****************************************************************************/
  321.  uint
  322. ShowScalar( DFILE *dfp, uint row, uint rows, uint skip )
  323. {
  324.   uchar buffer[DATALINESPAN];
  325.  
  326.   uint   baseaddr;                                                      /*101*/
  327.   baseaddr = dfp->baseaddr;
  328.  
  329.  
  330.     if( skip )
  331.         return( FALSE );
  332.     InitDataBuffer( buffer, sizeof(buffer), dfp );
  333.     FormatDataItem( buffer + STGCOL+1, baseaddr,
  334.         dfp->mid, dfp->showtype, dfp->sfx );
  335.     putrc( row, 0, buffer );
  336.     if( rows > 1 )
  337.         ClrScr( row + 1, row + rows - 1, vaStgExp );
  338.     return( TRUE );
  339. }
  340. /*****************************************************************************/
  341. /*  DFILE *dfp;                                                              */
  342. /*  uint row;      screen row                                                */
  343. /*  uint rows;     # of screen rows                                          */
  344. /*  uint skip;     # of logical data file records to skip                    */
  345. /*                                                                           */
  346. /*****************************************************************************/
  347.  uint
  348. ShowConstant( DFILE *dfp, uint row, uint rows, uint skip )
  349. {
  350.     uint n;                             /* was register.                  112*/
  351.     uchar buffer[DATALINESPAN];
  352.     uchar *cp = buffer + STGCOL+1;
  353.     static uchar ConstValueMsg[] = "  (Constant)";
  354.     uint addr;                          /*                                112*/
  355.     uint sfx;                           /* stack frame index.             112*/
  356.  
  357.     if( skip )
  358.         return( FALSE );
  359.  
  360.     InitDataBuffer( buffer, sizeof(buffer), dfp );
  361.     addr = dfp->baseaddr;
  362.     if(dfp->datatype == ADDRESS_CONSTANT)                               /*243*/
  363.     {                                                                   /*243*/
  364.      if( TestBit( addr , STACKADDRBIT) )                                /*112*/
  365.      {                                                                  /*112*/
  366.        sfx =  StackFrameIndex( dfp->scope );                            /*112*/
  367.        addr = StackBPRelToAddr( addr , sfx );                           /*112*/
  368.      }                                                                  /*112*/
  369.     }                                                                   /*243*/
  370.  
  371.     n = utoa( addr, cp );               /*                                221*/
  372.     *(cp+n) = ' ';                      /* remove the null terminator.    221*/
  373.     n = sprintf((cp+SPCTAB), "%#lx", addr) ;  /* print the val in hex     221*/
  374.     *(cp+SPCTAB+n) = ' ';               /* remove the null terminator.    221*/
  375.     n = 2 * SPCTAB ;                    /* calculate the new pointer.     221*/
  376.  
  377.     memcpy(cp+n, ConstValueMsg,  sizeof(ConstValueMsg)-1 );             /*101*/
  378.  
  379.     putrc( row, 0, buffer );
  380.     if( rows > 1 )
  381.         ClrScr( row + 1, row + rows - 1, vaStgExp );
  382.     return( TRUE );
  383. }
  384. /*****************************************************************************/
  385. /*  DFILE *dfp;                                                              */
  386. /*  uint row;      screen row                                                */
  387. /*  uint rows;     # of screen rows                                          */
  388. /*  uint skip;     # of logical data file records to skip                    */
  389. /*                                                                           */
  390. /*****************************************************************************/
  391.  uint
  392. ShowHexBytes( DFILE *dfp, uint row, uint rows, uint skip )
  393. {
  394.     uint    n;
  395.     uint    rr;
  396.     uchar  *cp;
  397.     uchar  *data;
  398.     uint    nbytes;
  399.     uint    limit=0;
  400.     uint    used;
  401.     uint    sfx = dfp->sfx;              /*                               101*/
  402.     uint    dp;                          /*                               101*/
  403.     uchar   buffer[DATALINESPAN];
  404.  
  405.  uint   baseaddr;                       /*  replaces ExprAddr             101*/
  406.  
  407.  baseaddr = dfp->baseaddr;              /*  replaces ExprAddr                */
  408.  
  409.     dp = baseaddr + 16*skip;            /*                                101*/
  410.  
  411.     if( !skip && ((GetAppData(baseaddr, 1, &nbytes, sfx) == NULL) ||
  412.                   nbytes == 0) )
  413.     {
  414.         InitDataBuffer( buffer, sizeof(buffer), dfp );
  415.         memcpy( buffer + STGCOL+1,BadAddrMsg , sizeof(BadAddrMsg)-1 );  /*101*/
  416.         putrc( row, 0, buffer );
  417.         rr = 1;
  418.     }else{
  419.         if( dfp->showtype )
  420.             limit = QtypeSize(dfp->mid, dfp->showtype);
  421.         if( skip )
  422.             dfp = NULL;
  423.         for( rr=0 ; rr < rows ; ){
  424.             n = 16;
  425.             if( limit && ((used = 16*(skip+rr+1)) > limit) )
  426.                 if( ((n = limit - (used-16)) == 0) || (n > limit) )
  427.                     break;
  428.             if( ( (data = GetAppData(dp, n, &nbytes, sfx)) == NULL ) ||
  429.                   nbytes == 0 )
  430.                 break;
  431.             InitDataBuffer( buffer, sizeof(buffer), dfp );  dfp = NULL;
  432.             for( n=0, cp = buffer + STGCOL+1; n < nbytes; ++n, cp += 3 ){
  433.                 utox2(data[n], cp);  if( (n & 3) == 3 )  cp += 1;  }
  434.  
  435.             for( n=0, cp = buffer + ASCIICOL+1; n < nbytes; ++n ){
  436.                 *cp++ = graphic(data[n]);  }
  437.             putrc( row + rr, 0, buffer );
  438.             rr += 1;
  439.             if( OffOf(dp) > MAXUINT-16 )
  440.                 break;
  441.             dp += 16;
  442.     }   }
  443.     if( rr < rows )
  444.         ClrScr( row + rr, row + rows - 1, vaStgExp );
  445.     return( TRUE );
  446. }
  447.     uchar
  448. graphic( uchar c )
  449. {
  450.  if ( c == 0 )
  451.   return( ACHAR_NULL );
  452.  
  453.  if ( c < 0x20 || c > 0x7F )
  454.   return( ACHAR_NONA );
  455.  
  456.  return( c );
  457. }
  458.  
  459. /*****************************************************************************/
  460. /* InitDataBuffer()                                                          */
  461. /*                                                                           */
  462. /* Description:                                                              */
  463. /*   Initialize a line data buffer for the data window.                      */
  464. /*                                                                           */
  465. /* Parameters:                                                               */
  466. /*   cp        input - pointer to data buffer.                               */
  467. /*   sizecp    input - size of the data buffer.                              */
  468. /*   dfp       input - pointer to dfile node.                                */
  469. /*                                                                           */
  470. /* Return:                                                                   */
  471. /*   TRUE                                                                    */
  472. /*   FALSE                                                                   */
  473. /*                                                                           */
  474. /*****************************************************************************/
  475.  void
  476. InitDataBuffer(uchar *cp,uint sizecp,DFILE *dfp)
  477.                                         /* -> to the buffer to initialize.   */
  478.                                         /* size of the buffer.               */
  479.                                         /* -> to the dfile node.             */
  480. {                                       /*                                   */
  481.  uint n;                                /* just a number.                    */
  482.                                         /*                                   */
  483.  memset( cp, ' ' ,sizecp );             /* fill the buffe with blanks.    101*/
  484.  if( dfp )                              /*                                   */
  485.  {                                      /*                                   */
  486.   n = strlen(dfp->expr);                /* compute length of expression.     */
  487.   if( n > SHORTX )                      /* truncate to allocated field width.*/
  488.   {                                     /*                                   */
  489.    n=SHORTX;                            /*                                   */
  490.    cp[n+1] = SXCHAR;                    /*                                   */
  491.   }                                     /*                                   */
  492.   memcpy( cp+1,dfp->expr, n );          /* copy expr/truncated expr to buffer*/
  493.  }                                      /*                                   */
  494.  cp[0] = Attrib(vaStgExp);              /* set expression attribute.         */
  495.  cp[STGCOL] = Attrib(vaStgVal);         /* set data display attribute.       */
  496.  cp[sizecp-1] = 0;                      /* put \0 at end of buffer           */
  497. }                                       /* end initdatabuffer().             */
  498.  
  499. /*****************************************************************************/
  500. /* GetAppData()                                                           112*/
  501. /*                                                                        112*/
  502. /* Description:                                                           112*/
  503. /*   Gets data from the user's address space.                             112*/
  504. /*                                                                        112*/
  505. /* Parameters:                                                            112*/
  506. /*   addr        input - -> into user space where we want the data from.  112*/
  507. /*   nbytes      input - -> number of bytes to get.                       112*/
  508. /*   pused       output     number of bytes actually read.                112*/
  509. /*   sfx         input - stack frame index for a stack variable.          112*/
  510. /*                                                                        112*/
  511. /* Return:                                                                112*/
  512. /*   PtrToData   -> to buffer of data maintained by DBGet().              112*/
  513. /*               DBGet allocates and frees the buffer on each get.        112*/
  514. /* Assumptions:                                                           112*/
  515. /*                                                                        112*/
  516. /*   addr is flat.                                                        112*/
  517. /*                                                                        112*/
  518. /* Notes:                                                                 112*/
  519. /*   Since the buffer allocated by DBGet() is in dynamic memory we can    112*/
  520. /*   return a NULL  pointer to indicate failure.                          112*/
  521. /*                                                                        112*/
  522. /*****************************************************************************/
  523.  uchar *                                                                /*112*/
  524. GetAppData( uint addr, uint nbytes, uint *pused, uint sfx )             /*112*/
  525. {                                                                       /*112*/
  526.  uint bad_reg_add = 0;                 /* flag to indicate invalid reg var205*/
  527.                                                                         /*112*/
  528.                                                                         /*112*/
  529.  if( TestBit(addr,STACKADDRBIT) )                                       /*112*/
  530.  {                                                                      /*112*/
  531.   addr = StackBPRelToAddr( addr , sfx );                                /*112*/
  532.   if( addr == NULL )                                                    /*112*/
  533.    goto BadAddr;                                                        /*112*/
  534.                                                                         /*112*/
  535.  }else if( (addr >> REGADDCHECKPOS) == REGISTERTYPEADDR ){              /*205*/
  536.      if( sfx != 1 )   /* If not in the executing frame */               /*112*/
  537.      {
  538.          bad_reg_add = 1;               /* set up the flag to indicate    205*/
  539.          goto BadAddr;                  /* unable to remember reg vars    205*/
  540.      }
  541.  }                                                                      /*112*/
  542.                                                                         /*112*/
  543.  return( DBGet(addr, nbytes, pused) );                                  /*112*/
  544.                                                                         /*112*/
  545.  BadAddr:                                                               /*112*/
  546.      if( pused )                                                        /*112*/
  547.        if (bad_reg_add )                /* if unable to remember reg vars 205*/
  548.           *pused = 0xFFFFFFFF;          /* put a NULLF in bytes read,this 205*/
  549.        else                             /* value is checked while putting 205*/
  550.           *pused = 0;                   /* out error message in calling   205*/
  551.      return( NULL );                    /* routine.                       205*/
  552. }                                       /* end GetAppData().              112*/
  553. /*****************************************************************************/
  554. /* StackBPRelToAddr()                                                     112*/
  555. /*                                                                        112*/
  556. /* Description:                                                           112*/
  557. /*   Get the "real" address for a stack bp relative address.              112*/
  558. /*                                                                        112*/
  559. /* Parameters:                                                            112*/
  560. /*   StackBPRelAddr input -> The BP relative address we want the addr for.112*/
  561. /*   sfx            input - stack frame index for a stack variable.       112*/
  562. /*                                                                        112*/
  563. /* Return:                                                                112*/
  564. /*   addr           the "real" address.                                   112*/
  565. /*                                                                        112*/
  566. /* Assumptions:                                                           112*/
  567. /*                                                                        112*/
  568. /*                                                                        112*/
  569. /* Notes:                                                                 112*/
  570. /*                                                                        112*/
  571. /*****************************************************************************/
  572.  uint                                                                   /*112*/
  573. StackBPRelToAddr( uint StackBPRelAddr, uint sfx )                       /*112*/
  574. {                                                                       /*112*/
  575.  uint FrameOffset;                                                      /*112*/
  576.  uint FrameAddr;                                                        /*112*/
  577.  uint addr;                                                             /*112*/
  578.                                                                         /*112*/
  579.  if( TestBit(StackBPRelAddr,STACKADDRSIGN) == FALSE )                   /*112*/
  580.   ResetBit( StackBPRelAddr, STACKADDRBIT );                             /*112*/
  581.  FrameOffset = StackBPRelAddr;                                          /*112*/
  582.  FrameAddr   = StackFrameAddress(sfx);                                  /*112*/
  583.                                                                         /*112*/
  584.  if( FrameAddr == NULL )                                                /*112*/
  585.   return( NULL );                                                       /*112*/
  586.                                                                         /*112*/
  587.  addr = FrameAddr + FrameOffset;                                        /*112*/
  588.  return( addr );                                                        /*112*/
  589.                                                                         /*112*/
  590. }                                                                       /*112*/
  591.  
  592. /*****************************************************************************/
  593. /* BytesToValue()                                                         523*/
  594. /*                                                                        523*/
  595. /* Description:                                                           523*/
  596. /*   Finds out the value of a bitfield which spans across bytes           523*/
  597. /*                                                                        523*/
  598. /* Parameters:                                                            523*/
  599. /*   Addr        input - -> into user space where we want the data from.  523*/
  600. /*   OffSet      input - -> Starting offset into the fisrt byte.          523*/
  601. /*   Length      input - -> length of the bitfield in terms of bits.      523*/
  602. /*   sfx         input - -> stack frame index for a stack variable.       523*/
  603. /*   Value       output  -> pointer to calculated bitfield value.         523*/
  604. /*                                                                        523*/
  605. /* Return:                                                                523*/
  606. /*   True or False                                                        523*/
  607. /*                                                                        523*/
  608. /* Assumptions:                                                           523*/
  609. /*****************************************************************************/
  610. uint   BytesToValue(uint Addr,uint OffSet,uint Length,uint sfx,uint *Value)
  611. {
  612.    uint  ReturnValue;                   /* Holds bit field value in hex   523*/
  613.    uchar ByteValue;                     /* Byte read from users space     523*/
  614.    uchar ByteMask;                      /* mask to check if a bit is on   523*/
  615.    uint  i;                             /*                                523*/
  616.    uint  WorkOffset;                    /* -> offset into each byte       523*/
  617.    uint  read;                          /* no of bytes read               523*/
  618.    uint  Mask;                          /* mask to cal return value.      523*/
  619.    uchar *dp;                           /* -> returned by get app data.   523*/
  620.  
  621.  
  622.    /**************************************************************************/
  623.    /*  Example:                                                           523*/
  624.    /*                                                                     523*/
  625.    /*    A Bit field value can span across bytes. We need to extract      523*/
  626.    /*    bits from these bytes to get the value of bit field in hex.      523*/
  627.    /*                                                                     523*/
  628.    /*    As example if we have a bit field which is 12 bits and spanning  523*/
  629.    /*    across 3 bytes. The memory lay out is given below. We need to    523*/
  630.    /*    get the hex value of this bit field.                             523*/
  631.    /*                                                                     523*/
  632.    /*   ┌─┬─┬─┬─┬─┬─┬─┬─┐    ┌─┬─┬─┬─┬─┬─┬─┬─┐     ┌─┬─┬─┬─┬─┬─┬─┬─┐      523*/
  633.    /*   │ │ │ │ │ │ │ │ │    │ │ │ │ │ │ │ │ │     │ │ │ │ │ │ │ │ │      523*/
  634.    /*   │2│1│ │ │ │ │ │ │    │1│9│8│7│6│5│4│3│     │ │ │ │ │ │ │1│1│      523*/
  635.    /*   │ │ │ │ │ │ │ │ │    │0│ │ │ │ │ │ │ │     │ │ │ │ │ │ │2│1│      523*/
  636.    /*   └─┴─┴─┴─┴─┴─┴─┴─┘    └─┴─┴─┴─┴─┴─┴─┴─┘     └─┴─┴─┴─┴─┴─┴─┴─┘      523*/
  637.    /*    7 6 5 4 3 2 1 0      7 6 5 4 3 2 1 0       7 6 5 4 3 2 1 0       523*/
  638.    /*                                                                     523*/
  639.    /*                  |                    |                     |       523*/
  640.    /*     Address X ---      Address X+1 ---       Address X+2 ---        523*/
  641.    /*                                                                     523*/
  642.    /*    The numbers in the boxes indicates the bit nos of the bitfield.  523*/
  643.    /*                                                                     523*/
  644.    /*    In the above example the input paramters to this func will be:   523*/
  645.    /*       Addr    :  X                                                  523*/
  646.    /*       OffSet  :  6                                                  523*/
  647.    /*       Length  :  12                                                 523*/
  648.    /*                                                                     523*/
  649.    /**************************************************************************/
  650.    ReturnValue = 0;                                                     /*523*/
  651.    ByteMask = 1;                                                        /*523*/
  652.    Mask = 1;                                                            /*523*/
  653.    /**************************************************************************/
  654.    /* Read the byte value at the address given if not able to read return 523*/
  655.    /* back with a failure.                                                523*/
  656.    /**************************************************************************/
  657.    dp = GetAppData(Addr,1,&read,sfx);                                   /*523*/
  658.    if (!dp)                                                             /*523*/
  659.      return(FALSE);                                                     /*523*/
  660.    ByteValue = *dp;                                                     /*523*/
  661.    WorkOffset = OffSet;                                                 /*523*/
  662.    /**************************************************************************/
  663.    /* - Loop for the number of bits in the bit field.                     523*/
  664.    /* - If the bitfield bit is set then increment the return value.       523*/
  665.    /* - If we complete processing a byte read then read next byte.        523*/
  666.    /**************************************************************************/
  667.    for (i = 0 ; i < Length ; i++)                                       /*523*/
  668.    {                                                                    /*523*/
  669.       if ( ByteValue & (uchar)(ByteMask << WorkOffset) )                /*523*/
  670.          ReturnValue |= (Mask << i);                                    /*523*/
  671.       WorkOffset++;                                                     /*523*/
  672.       if (WorkOffset == 8)                                              /*523*/
  673.       {                                                                 /*523*/
  674.         WorkOffset = 0;                                                 /*523*/
  675.         Addr++;                                                         /*523*/
  676.         dp = GetAppData(Addr,1,&read,sfx);                              /*523*/
  677.         if (!dp)                                                        /*523*/
  678.           return(FALSE);                                                /*523*/
  679.         ByteValue = *dp;                                                /*523*/
  680.       }                                                                 /*523*/
  681.    }                                                                    /*523*/
  682.    *Value = ReturnValue;                                                /*523*/
  683.    return(TRUE);                                                        /*523*/
  684. }                                                                       /*523*/
  685.