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

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   findexec.c                                                              */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  Routines to backup one stack frame.                                      */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  12. /*                                                                           */
  13. /*...16->32 port.                                                            */
  14. /*...                                                                        */
  15. /*... 02/08/91  100   Philip    port to 32 bit.                              */
  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. /*    08/13/81  224   srinivas  call stack blowing up if there are 10 funcs  */
  23. /**Includes*******************************************************************/
  24.  
  25. #include "all.h"                        /* SD86 include files                */
  26.  
  27. extern uint        NActFrames;
  28. extern uint        ActFaddrs[];                                         /*107*/
  29. extern uint        ActFlines[MAXAFRAMES][2];                            /*107*/
  30.  
  31. #define MIDCOL 0                                                        /*224*/
  32. #define LNOCOL 1                                                        /*224*/
  33.  
  34.     AFILE *
  35. FindExecLine(AFILE *fp,uint lno)
  36. {
  37.     uint n;
  38.     AFILE *p;
  39.  
  40.     if( (fp == GetExecfp()) && (lno == GetExecLno()) ){
  41.         if( NActFrames == 0 )
  42.             return( NULL );
  43.         n = 0;  /* return 0th active frame */
  44.         goto ReturnNthFrame;
  45.     }
  46.     if( (NActFrames > 0)
  47.      && (n = IndexOfMidLnoForFrames( fp->mid, lno )) /* see if mid/lno match */
  48.         < NActFrames-1 )
  49.     {                                   /*   up w/some frame 107*/
  50.         n+=1;                           /* return n+1th frame             107*/
  51.         goto ReturnNthFrame;
  52.     }
  53.     p = findfp(GetExecAddr());                                          /*101*/
  54.     if( p )                                                             /*101*/
  55.         p->flags |= AF_ZOOM;
  56.     return( p );
  57.  
  58.     ReturnNthFrame:
  59.  
  60.     p = findfp(ActFaddrs[n]);
  61.     if( p )
  62.     {
  63.         p->flags |= AF_ZOOM;
  64.         /* We update ActFlines because findfp may have added an AFILE */
  65.         ActFlines[n][MIDCOL] = p->mid;
  66.         ActFlines[n][LNOCOL] = p->hotline + p->Nbias;
  67.     }
  68.     return( p );
  69. }
  70.  
  71.     AFILE *
  72. FindExecAddr(AFILE *fp,uint addr)
  73. {
  74.     uint n;                             /* was register.                  112*/
  75.     AFILE *p;
  76.  
  77.     if( (fp == GetExecfp()) && (addr == GetExecAddr() ) ){                    /*101*/
  78.         if( NActFrames == 0 )
  79.             return( NULL );
  80.         n = 0;                          /* return 0th active frame           */
  81.         goto ReturnNthFrame;
  82.     }
  83.  
  84.     if( (NActFrames > 0) )
  85.     {
  86.      n = lindex(ActFaddrs, NActFrames-1, (ulong)addr);
  87.      if( n < (NActFrames-1) )
  88.      {
  89.       n += 1;                         /* return (n+1)th active frame       */
  90.       goto ReturnNthFrame;
  91.      }
  92.     }
  93.  
  94.     p = findfp(GetExecAddr());                                          /*101*/
  95.     if( p )                                                             /*101*/
  96.         p->flags |= AF_ZOOM;
  97.     return( p );
  98.  
  99.     ReturnNthFrame:
  100.  
  101.     p = findfp(ActFaddrs[n]);
  102.     if( p )
  103.     {
  104.         p->flags |= AF_ZOOM;
  105.         /* We update ActFlines because findfp may have added an AFILE */
  106.         ActFlines[n][MIDCOL] = p->mid;
  107.         ActFlines[n][LNOCOL] = p->hotline + p->Nbias;
  108.     }
  109.     return( p );
  110. }
  111.  
  112. /*****************************************************************************/
  113. /* IndexOfMidLnoForFrames                                                    */
  114. /*                                                                           */
  115. /* Description:                                                              */
  116. /*                                                                           */
  117. /*  Looks to match up the current mid and lno with those in ActFlines[][].   */
  118. /*                                                                           */
  119. /* Parameters:                                                               */
  120. /*                                                                           */
  121. /*  mid   -   module id of interest.                                         */
  122. /*  lno   -   line number of interest.                                       */
  123. /*                                                                           */
  124. /* Return:                                                                   */
  125. /*                                                                           */
  126. /*  n     -   row index into ActFlines where the match was found.  If the    */
  127. /*            mid/lno pair were not found, n == NActFrames => failure.       */
  128. /*                                                                        107*/
  129. /*****************************************************************************/
  130.     uint
  131. IndexOfMidLnoForFrames(uint mid,uint lno)
  132. {
  133.     uint n;
  134.  
  135.     for ( n = 0; n < NActFrames; n++ )       /* try to match mid/lno         */
  136.     {
  137.       if ( ActFlines[n][MIDCOL] == mid  &&   /* mid matches and              */
  138.            ActFlines[n][LNOCOL] == lno     ) /*   lno matches ?              */
  139.         break;                               /* stop with n at proper index  */
  140.     }
  141.     return( n );
  142. }
  143.