home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / DBSEGS.C < prev    next >
Text File  |  1996-03-15  |  44KB  |  692 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   dbsegs.c                                                                */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*   Interface functions for segments.                                       */
  7. /*                                                                           */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*...16->32 port.                                                            */
  12. /*...                                                                        */
  13. /*... 02/08/91  101   Joe       port to 32 bit.                              */
  14. /*                                                                           */
  15. /*...Release 1.00 (Pre-release 1)                                            */
  16. /*...                                                                        */
  17. /*... 07/31/91  215   Christina Add support for HLL format                   */
  18. /*... 09/11/91  237   Srinivas  Proper initialization of debug format flags. */
  19. /*                                                                           */
  20. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  21. /*...                                                                        */
  22. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  23. /*...                                                                        */
  24. /*... 01/26/93  809   Selwyn    HLL Level 2 support.                         */
  25. /*...                                                                        */
  26. /*... 03/22/93  815   Selwyn - Workaround for compiler bug. 0:32 should be   */
  27. /*                             16:16.                                        */
  28. /*...                                                                        */
  29. /*... 04/13/93  803   Selwyn    Resolving imports.                           */
  30. /**Includes*******************************************************************/
  31.  
  32. #include "all.h"                        /* SD86 include files                */
  33. #include "mapsyms.h"
  34.  
  35. extern CmdParms cmd;                                                    /*803*/
  36. void PrtHLSym(UCHAR *, UCHAR *);
  37. void PrtHLType( UCHAR *, UCHAR *);
  38.  
  39. /*****************************************************************************/
  40. /* DBSymSeg                                                                  */
  41. /*                                                                           */
  42. /* Description:                                                              */
  43. /*   Get pointer to a module's symbol area and give this area's length.      */
  44. /*                                                                           */
  45. /* Parameters:                                                               */
  46. /*   mid        module id.                                                   */
  47. /*   lenptr     points to module's symbol area length.                       */
  48. /*   pdf        pointer to debug file structure.                             */
  49. /*                                                                           */
  50. /* Return:                                                                   */
  51. /*   symptr     points to module's symbol area.                              */
  52. /*   NULL       no pointer to symbol area.                                   */
  53. /*                                                                           */
  54. /*****************************************************************************/
  55. SSRec *DBSymSeg( uint mid, ULONG *lenptr, DEBFILE *pdf )
  56.                                         /* module id in question             */
  57.                                         /* ->mid's symbol area length        */
  58.                                         /* -> to debug file structure        */
  59. {                                       /* begin DBSymSeg                    */
  60.  
  61.   SYMNODE      *sptr;                   /* to cruise through ring of pointers*/
  62.   uchar        *RawTable;               /* -> Raw symbol table.           809*/
  63.   uchar        *symend;                 /* ->end of symbol area unused.      */
  64.   MODULE       *mptr;                   /* pointer to the EXE module info    */
  65.   ulong         seekpos;                /* position in file to seek          */
  66.   SSVar        *sp;                     /* -> static symbol record.          */
  67.   uchar         SymbolType, SymbolFlag;                                 /*809*/
  68.   int           IntTableSize;           /* Internal symbol table size.    809*/
  69.   SSRec        *IntSymTable;            /* -> internal symbol table.      809*/
  70.   uchar        *symptr, *EndPtr;                                        /*809*/
  71.   ushort        RecordLength = 0;                                       /*809*/
  72.   ushort        Adjust = 0;                                             /*809*/
  73.   uchar         RecordType;                                             /*809*/
  74.  
  75.   if( (mid == 0) || (pdf == NULL) )
  76.    return( NULL );
  77.  
  78.   /***************************************************************************/
  79.   /* Scan through the symbol table linked list to see if the symbol table of */
  80.   /* the module has already been loaded. If so return the pointer to the     */
  81.   /* symbol table.                                                           */
  82.   /***************************************************************************/
  83.   for( sptr = pdf->psyms; sptr != NULL; sptr = sptr->next )
  84.   {
  85.     if( sptr->mid == mid )
  86.     {
  87.       *lenptr = sptr->symlen;
  88.       return( sptr->symptr );
  89.     }
  90.   }
  91.  
  92.   /***************************************************************************/
  93.   /* If the symbol table has not been loaded, check to see whether a module  */
  94.   /* entry is present and the module has a symbol table. If any one of the   */
  95.   /* above condition fails, return a NULL symbol pointer and a zero length.  */
  96.   /***************************************************************************/
  97.   symptr = NULL;                                                        /*809*/
  98.   *lenptr = 0;                                                          /*809*/
  99.  
  100.   mptr = pdf->MidAnchor;                                                /*809*/
  101.   for( ; mptr && mptr->mid != mid; mptr = mptr->NextMod ){;}            /*809*/
  102.  
  103.   if( !mptr || !mptr->Symbols )                                         /*809*/
  104.     {return( NULL );}                                                   /*809*/
  105.  
  106.   SymbolFlag = mptr->DbgFormatFlags.Syms;                               /*809*/
  107.  
  108.   /***************************************************************************/
  109.   /* - Allocate memory for the raw symbol table.                             */
  110.   /* - Read the raw symbol table for the module into the buffer.             */
  111.   /***************************************************************************/
  112.   RawTable = Talloc( mptr->SymLen );                                    /*809*/
  113.   seekpos = pdf->DebugOff + mptr->Symbols;                              /*809*/
  114.   seekf( pdf, seekpos );                                                /*809*/
  115.   readf( RawTable, mptr->SymLen, pdf );                                 /*809*/
  116.  
  117.   /***************************************************************************/
  118.   /* We have to calculate the size of the internal symbol table. For this we */
  119.   /* scan through the raw symbol table, add allowance for each type of symbol*/
  120.   /* record  to calculate the total size of the internal symbol table.       */
  121.   /***************************************************************************/
  122.   IntTableSize = 0;                                                     /*809*/
  123.   symptr = RawTable;                                                    /*809*/
  124.   EndPtr = symptr + mptr->SymLen;                                       /*809*/
  125.   /***************************************************************************/
  126.   /* Scan through the raw table.                                             */
  127.   /***************************************************************************/
  128.   for( ; symptr < EndPtr; symptr += (RecordLength + Adjust) )           /*809*/
  129.   {                                                                     /*809*/
  130.     /*************************************************************************/
  131.     /* - Calculate the record length (Encoded incase of HLL Level 3).        */
  132.     /* - Get the type of the symbol record.                                  */
  133.     /* - Set Adjust so that is skips the length field. ( 2 incase of Level 3 */
  134.     /*   encoded length or else it is 1 ).                                   */
  135.     /*************************************************************************/
  136.     RecordLength = GetRecordLength( symptr, mptr );                     /*809*/
  137.     RecordType   = GetRecordType( symptr, mptr );                       /*809*/
  138.  
  139.     Adjust = 1;
  140.     if( TestBit( *symptr, 7 ) && ((SymbolFlag == TYPE104_HL03) ||
  141.                                   (SymbolFlag == TYPE104_HL04)
  142.                                  )
  143.       )
  144.       Adjust = 2;                                                       /*809*/
  145.  
  146.     switch( RecordType )                                                /*809*/
  147.     {                                                                   /*809*/
  148.       /***********************************************************************/
  149.       /* No name field is involved for begin records, so the size of the     */
  150.       /* begin records are constant.                                         */
  151.       /***********************************************************************/
  152.       case SSBEGIN:                                                     /*809*/
  153.       case SSBEGIN32:                                                   /*809*/
  154.         IntTableSize += sizeof( SSBegin );                              /*809*/
  155.         break;                                                          /*809*/
  156.  
  157.       case SSPROC:                                                      /*809*/
  158.       case SSENTRY:                                                     /*809*/
  159.       case SSPROC32:                                                    /*809*/
  160.       case SSMEMFUNC:                                                   /*809*/
  161.       case SSPROCCPP:                                                   /*809*/
  162.       {                                                                 /*809*/
  163.         switch( SymbolFlag )                                            /*809*/
  164.         {                                                               /*809*/
  165.           case TYPE104_C211:                                            /*809*/
  166.           case TYPE104_C600:                                            /*809*/
  167.             /*****************************************************************/
  168.             /* Difference in 16 bit MSC 6.0/C211 proc record  and internal   */
  169.             /* symbol record lengths                                         */
  170.             /*   - Record length        2                                    */
  171.             /*   - Flags                1                                    */
  172.             /*   - Proc offset          2                                    */
  173.             /*   - Proc length          2                                    */
  174.             /*   - Debug end            2                                    */
  175.             /*   - Name length          1                                    */
  176.             /*        Total  ====>     10                                    */
  177.             /*****************************************************************/
  178.             IntTableSize += (RecordLength + 10);                        /*809*/
  179.             break;                                                      /*809*/
  180.  
  181.           case TYPE104_CL386:                                           /*809*/
  182.             /*****************************************************************/
  183.             /* Difference in 32 bit CL386 proc record  and internal symbol   */
  184.             /* record lengths                                                */
  185.             /*   - Record length        2                                    */
  186.             /*   - Flags                1                                    */
  187.             /*   - Proc length          2                                    */
  188.             /*   - Debug end            2                                    */
  189.             /*   - Name length          1                                    */
  190.             /*        Total  ====>      8                                    */
  191.             /*****************************************************************/
  192.             IntTableSize += (RecordLength + 8);                         /*809*/
  193.             break;                                                      /*809*/
  194.  
  195.           case TYPE104_HL01:                                            /*809*/
  196.           case TYPE104_HL02:                                            /*809*/
  197.           case TYPE104_HL03:                                            /*809*/
  198.           case TYPE104_HL04:                                            /*809*/
  199.             /*****************************************************************/
  200.             /* Difference in HLL proc record and internal symbol record      */
  201.             /* lengths                                                       */
  202.             /*   - Record length        2                                    */
  203.             /*   - Flags                1                                    */
  204.             /*   - Name length          1                                    */
  205.             /*        Total  ====>      4                                    */
  206.             /*****************************************************************/
  207.             IntTableSize += (RecordLength + 4);                         /*809*/
  208.             break;                                                      /*809*/
  209.         }                                                               /*809*/
  210.         break;                                                          /*809*/
  211.       }                                                                 /*809*/
  212.  
  213.       case SSDEF:                                                       /*809*/
  214.       case SSDEF32:                                                     /*809*/
  215.       {                                                                 /*809*/
  216.         switch( SymbolFlag )                                            /*809*/
  217.         {                                                               /*809*/
  218.           case TYPE104_C211:                                            /*809*/
  219.           case TYPE104_C600:                                            /*809*/
  220.             /*****************************************************************/
  221.             /* Difference in 16 bit MSC 6.0/C211 def  record  and internal   */
  222.             /* symbol record lengths                                         */
  223.             /*   - Record length        2                                    */
  224.             /*   - Frame offset         2                                    */
  225.             /*   - Name length          1                                    */
  226.             /*        Total  ====>      5                                    */
  227.             /*****************************************************************/
  228.             IntTableSize += (RecordLength + 5);                         /*809*/
  229.             break;                                                      /*809*/
  230.  
  231.           case TYPE104_CL386:                                           /*809*/
  232.           case TYPE104_HL01:                                            /*809*/
  233.           case TYPE104_HL02:                                            /*809*/
  234.           case TYPE104_HL03:                                            /*809*/
  235.           case TYPE104_HL04:                                            /*809*/
  236.             /*****************************************************************/
  237.             /* Difference in 32 bit CL386/HLL def record and internal symbol */
  238.             /* record lengths                                                */
  239.             /*   - Record length        2                                    */
  240.             /*   - Name length          1                                    */
  241.             /*        Total  ====>      3                                    */
  242.             /*****************************************************************/
  243.             IntTableSize += (RecordLength + 3);                         /*809*/
  244.             break;                                                      /*809*/
  245.         }                                                               /*809*/
  246.         break;                                                          /*809*/
  247.       }                                                                 /*809*/
  248.  
  249.       case SSVAR:                                                       /*809*/
  250.       case SSVAR32:                                                     /*809*/
  251.       case SSVARCPP:                                                    /*809*/
  252.       {                                                                 /*809*/
  253.         switch( SymbolFlag )                                            /*809*/
  254.         {                                                               /*809*/
  255.           case TYPE104_C211:                                            /*809*/
  256.           case TYPE104_C600:                                            /*809*/
  257.             /*****************************************************************/
  258.             /* Difference in 16 bit MSC 6.0/C211 var  record  and internal   */
  259.             /* symbol record lengths                                         */
  260.             /*   - Record length        2                                    */
  261.             /*   - Flags                1                                    */
  262.             /*   - Offset               2                                    */
  263.             /*   - Name length          1                                    */
  264.             /*        Total  ====>      6                                    */
  265.             /*****************************************************************/
  266.             IntTableSize += (RecordLength + 6);                         /*809*/
  267.             break;                                                      /*809*/
  268.  
  269.           case TYPE104_CL386:                                           /*809*/
  270.           case TYPE104_HL01:                                            /*809*/
  271.           case TYPE104_HL02:                                            /*809*/
  272.           case TYPE104_HL03:                                            /*809*/
  273.           case TYPE104_HL04:                                            /*809*/
  274.             /*****************************************************************/
  275.             /* Difference in 32 bit CL386/HLL var record and internal symbol */
  276.             /* record lengths                                                */
  277.             /*   - Record length        2                                    */
  278.             /*   - Flags                1                                    */
  279.             /*   - Name length          1                                    */
  280.             /*        Total  ====>      4                                    */
  281.             /*****************************************************************/
  282.             IntTableSize += (RecordLength + 4);                         /*809*/
  283.             break;                                                      /*809*/
  284.         }                                                               /*809*/
  285.         break;                                                          /*809*/
  286.       }                                                                 /*809*/
  287.  
  288.       case SSEND:                                                       /*809*/
  289.       case SSEND32:                                                     /*809*/
  290.       /***********************************************************************/
  291.       /* No name field is involved for end records, so the size of the end   */
  292.       /* records are constant.                                               */
  293.       /***********************************************************************/
  294.         IntTableSize += sizeof( SSEnd );                                /*809*/
  295.         break;                                                          /*809*/
  296.  
  297.       case SSREG:                                                       /*809*/
  298.       case SSREG32:                                                     /*809*/
  299.       /***********************************************************************/
  300.       /* The size of the reg records are the same for all formats, so the    */
  301.       /* difference in lengths is                                            */
  302.       /*   - Record length        2                                          */
  303.       /*   - Name length          1                                          */
  304.       /*        Total  ====>      3                                          */
  305.       /***********************************************************************/
  306.         IntTableSize += (RecordLength + 3);                             /*809*/
  307.         break;                                                          /*809*/
  308.  
  309.       case SSCHGDEF:                                                    /*809*/
  310.       /***********************************************************************/
  311.       /* ChgDefSeg records are supported in HL01 & HL02 formats, and since   */
  312.       /* no name field is involved the length is constant.                   */
  313.       /***********************************************************************/
  314.         IntTableSize += sizeof( SSChgDef );                             /*809*/
  315.         break;                                                          /*809*/
  316.  
  317.       case SSUSERDEF:                                                   /*809*/
  318.       /***********************************************************************/
  319.       /* The size of the User def records are the same for all formats, so   */
  320.       /* the difference in lengths is                                        */
  321.       /*   - Record length        2                                          */
  322.       /*   - Name length          1                                          */
  323.       /*        Total  ====>      3                                          */
  324.       /***********************************************************************/
  325.         IntTableSize += (RecordLength + 3);                             /*809*/
  326.         break;                                                          /*809*/
  327.  
  328.       default:                                                          /*809*/
  329.       /***********************************************************************/
  330.       /* For the record types which are supported by SD386, no entries are   */
  331.       /* present in the internal table, so blow past those records.          */
  332.       /***********************************************************************/
  333.         break;                                                          /*809*/
  334.     }                                                                   /*809*/
  335.   }                                                                     /*809*/
  336.  
  337.   /***************************************************************************/
  338.   /* If there was no symbol info, then return a NULL pointer.                */
  339.   /***************************************************************************/
  340.   if( !IntTableSize )                                                   /*809*/
  341.     return( NULL );                                                     /*809*/
  342.  
  343.   /***************************************************************************/
  344.   /* - Allocate memory for the internal symbol table.                        */
  345.   /* - Depending on the the symbol type call the respective mapping function */
  346.   /*   to map the raw symbol table to our internal symbol table.             */
  347.   /* - Free the memory allocated for the raw table.                          */
  348.   /***************************************************************************/
  349.   IntSymTable = Talloc( IntTableSize );                                 /*809*/
  350.   switch( SymbolFlag )                                                  /*809*/
  351.   {                                                                     /*809*/
  352.     case TYPE104_C211:                                                  /*809*/
  353.     case TYPE104_C600:                                                  /*809*/
  354.       MapMS16Syms( RawTable, IntSymTable, mptr->SymLen );               /*809*/
  355.       break;                                                            /*809*/
  356.  
  357.     case TYPE104_CL386:                                                 /*809*/
  358.       MapMS32Syms( RawTable, IntSymTable, mptr->SymLen );               /*809*/
  359.       break;                                                            /*809*/
  360.  
  361.     case TYPE104_HL01:                                                  /*809*/
  362.     case TYPE104_HL02:                                                  /*809*/
  363.     case TYPE104_HL03:                                                  /*809*/
  364.     case TYPE104_HL04:
  365.       MapHLLSyms( RawTable, IntSymTable, mptr );                        /*809*/
  366.       break;                                                            /*809*/
  367.   }                                                                     /*809*/
  368.   Tfree( RawTable );                                                     /*809*/
  369.  
  370. #if 0
  371.   PrtHLSym( (UCHAR *)IntSymTable, ((UCHAR *)IntSymTable + IntTableSize) );
  372. #endif
  373.  
  374.   mptr->SymLen = IntTableSize;                                          /*809*/
  375.   if( SymbolFlag == TYPE104_C211 || SymbolFlag == TYPE104_C600 )        /*809*/
  376.     SymbolType = BIT16;                                                 /*809*/
  377.   else                                                                  /*809*/
  378.     SymbolType = BIT32;                                                 /*809*/
  379.  
  380.   /***************************************************************************/
  381.   /* Add the symbol table to the linked list of symbol tables.               */
  382.   /***************************************************************************/
  383.   sptr = Talloc( sizeof( SYMNODE ) );   /* grab heap space for SYMNODE    521*/
  384.   sptr->next = pdf->psyms;              /* link in newest structure          */
  385.   sptr->mid = mid;                      /* put in mid stamp                  */
  386.   sptr->symptr = IntSymTable;           /* set up pointer to symbols area    */
  387.   sptr->symlen = mptr->SymLen;          /* put in symbol area length         */
  388.   *lenptr = mptr->SymLen;               /* set symbol area length for caller */
  389.   pdf->psyms=sptr;                      /* reset root ptr to top of chain    */
  390.  
  391.   /***************************************************************************/
  392.   /* At this point, the new node has been built. sptr points to the new node.*/
  393.   /* We want to convert segment numbers to selectors for all SSVar records.  */
  394.   /* If the SSVar record has a 0 segment number, then the variable is an     */
  395.   /* import.                                                                 */
  396.   /***************************************************************************/
  397.   for( symend = (uchar *)IntSymTable + sptr->symlen;
  398.        (uchar *)IntSymTable < symend;
  399.        IntSymTable = NextSSrec(IntSymTable) )
  400.   {
  401.    switch( IntSymTable->RecType )       /* we are only interested in the     */
  402.    {                                    /* SSvar records.                    */
  403.     case SSVAR:                         /*                                   */
  404.                                         /*                                   */
  405.      sp = (SSVar * )IntSymTable;        /* define a static symbol rec ptr.   */
  406.                                         /*                                   */
  407.      if( sp->ObjectNum )                /* if this is an import,then         */
  408.      {                                  /* if statically resolved at         */
  409.        sp->Offset += GetLoadAddr(pdf->mte,sp->ObjectNum);               /*822*/
  410.      }                                  /* the symbol record.                */
  411.      else
  412.      /************************************************************************/
  413.      /* If the Object number is zero, it could be an imported variable. So   */
  414.      /* resolve the import only if the user had invoked with /m option.      */
  415.      /************************************************************************/
  416.      if( cmd.ResolveImports == TRUE )                                   /*803*/
  417.      {
  418.        uchar *SymbolName = Talloc( strlen( sp->Name ) + 2 );            /*809*/
  419.  
  420.        sprintf( SymbolName, "%c%s", sp->NameLen, sp->Name );            /*809*/
  421.        if( SymbolType == BIT32 )
  422.        {                                                                /*815*/
  423.          uchar  ExpModuleType;                                          /*815*/
  424.  
  425.          sp->Offset = ResolveImport32( SymbolName, pdf,                 /*815*/
  426.                                        &ExpModuleType );                /*815*/
  427.          if( ExpModuleType == BIT16 )                                   /*815*/
  428.          {                                                              /*815*/
  429.            if( (sp->TypeIndex & 0xF0) == 0xA0 || sp->TypeIndex == 0xB7 )/*815*/
  430.            {                                                            /*815*/
  431.              sp->TypeIndex &= 0x9F;                                     /*815*/
  432.              sp->TypeIndex |= 0x40;                                     /*815*/
  433.            }                                                            /*815*/
  434.          }                                                              /*815*/
  435.        }                                                                /*815*/
  436.        else
  437.          sp->Offset = ResolveImport( SymbolName, pdf );
  438.        Tfree( SymbolName );                                              /*809*/
  439.      }                                  /*                                   */
  440.      break;                             /*                                   */
  441. /*****************************************************************************/
  442. /*                                                                           */
  443. /*****************************************************************************/
  444.     default:                            /* let all other records pass thro   */
  445.      break;                             /*                                   */
  446.    }                                    /* end of switch                     */
  447.   }                                     /* end of SSvar processing           */
  448.   return ( sptr->symptr );              /* return pointer to symbol area     */
  449. }                                       /* end DBSymSeg                      */
  450. /*****************************************************************************/
  451. /* DBTypSeg                                                                  */
  452. /*                                                                           */
  453. /* Description:                                                              */
  454. /*   get pointer and length for module's type area. Build type area linked   */
  455. /*   list if not already built.                                              */
  456. /*                                                                           */
  457. /* Parameters:                                                               */
  458. /*   mid        module id.                                                   */
  459. /*   lenptr     points to module's type area length.                         */
  460. /*   pdf        pointer to debug file structure.                             */
  461. /*                                                                           */
  462. /* Return:                                                                   */
  463. /*   typptr     points to module's type area.                                */
  464. /*                                                                           */
  465. /*****************************************************************************/
  466.  
  467.  
  468.  uchar *
  469. DBTypSeg(uint mid,uint *lenptr,DEBFILE *pdf)
  470. {                                       /* begin DBTypSeg                    */
  471.   TYPENODE *tptr;                       /* type info node pointer            */
  472.  
  473.  
  474.   for(
  475.       tptr = pdf->ptyps;                /* point to start of typ area ring   */
  476.       tptr != NULL;                     /* while ring members exist...       */
  477.       tptr = tptr->next                 /*   ...traverse typ area ring       */
  478.      )
  479.    {                                    /* begin scan of type info ring      */
  480.      if ( tptr->mid == mid )            /* find mid in existing ring ?       */
  481.      {                                  /* then we are done searching        */
  482.        *lenptr = tptr->typlen;          /* set # of bytes in type area       */
  483.        return ( tptr->typptr );         /*   and return ptr to type area     */
  484.      }                                  /* end we are done searching         */
  485.    }                                    /* end scan of module list           */
  486.  
  487. /*****************************************************************************/
  488. /* If we get here, then the type info does not exist for the mid specified.  */
  489. /* We need to cruise thru the module ring to find the mid's type area        */
  490. /* pointer in the debug file. Then we can allocate space for the types and   */
  491. /* save for future use.                                                      */
  492. /*****************************************************************************/
  493.   {
  494.    MODULE   *mptr;                      /* pointer to the module info        */
  495.    uchar    *areaptr = NULL;            /* pointer to raw type data          */
  496.  
  497.    *lenptr = 0;                         /*   mid does not have type area     */
  498.  
  499.    for(
  500.         mptr = pdf->MidAnchor;          /* point to start of Mid list        */
  501.         mptr != NULL;                   /* scan to the end of the list       */
  502.         mptr = mptr->NextMod            /* next module                       */
  503.       )
  504.     {                                   /* begin scan of module list         */
  505.       if ( mptr->mid == mid )           /* found the mid specified ?         */
  506.       {                                 /* yes, we found the module id       */
  507.         if ( mptr->TypeDefs )           /* does module have a type info ?    */
  508.         {                               /* module does have a type info      */
  509.           areaptr=Talloc(mptr->TypeLen);/* grab heap space.               521*/
  510.  
  511.           seekf( pdf,                   /* seek the type info                */
  512.                  pdf->DebugOff +        /*                                   */
  513.                  mptr->TypeDefs);       /*                                   */
  514.  
  515.           readf( areaptr,               /* read the type info                */
  516.                  mptr->TypeLen,         /*                                   */
  517.                  pdf);
  518.                    /* if HLL format, map type records to MS 32 bit format 215*/
  519.           switch( mptr->DbgFormatFlags.Typs )
  520.           {
  521.             case TYPE103_HL01:
  522.             case TYPE103_HL02:
  523.             case TYPE103_HL03:
  524.             case TYPE103_HL04:
  525.               areaptr = MapHLLTypes(areaptr,mptr);
  526.               break;
  527.  
  528.             case TYPE103_C600:
  529.             case TYPE103_C211:
  530.             case TYPE103_CL386:
  531.               areaptr = MapMSTypes(areaptr,mptr);
  532. #if 0
  533.               PrtHLType( areaptr, areaptr + mptr->TypeLen);
  534. #endif
  535.               break;
  536.           }
  537.         }
  538.         break;                          /* we are done searching for the mid */
  539.       }                                 /* end found the mid specified       */
  540.     }                                   /* end scan of module list           */
  541.  
  542.    if ( areaptr )                       /* mid and type info found ?         */
  543.     {                                   /* set up a new type node in list    */
  544.  
  545.       tptr = Talloc(sizeof(TYPENODE));  /*grab heap space for the node    521*/
  546.       tptr->next = pdf->ptyps;          /* link it into the ring             */
  547.       tptr->mid = mid;                  /* put in mid stamp                  */
  548.       tptr->typptr = ( areaptr );       /* set up pointer to raw type data   */
  549.       tptr->typlen = mptr->TypeLen;     /* put in length of raw type data    */
  550.       *lenptr = mptr->TypeLen;          /* set type   area length for caller */
  551.       pdf->ptyps = tptr;                /* reset root pointer to top of chain*/
  552.       return ( tptr->typptr );          /* ->type   area in heap for caller  */
  553.     }                                   /* end set up a new type node        */
  554.    return ( NULL );                     /* mid or type info not found        */
  555.   }                                     /* end of build type ring            */
  556. }                                       /* end DBTypSeg                      */
  557.  
  558. /*****************************************************************************/
  559. /* DBPubSeg                                                                  */
  560. /*                                                                           */
  561. /* Description:                                                              */
  562. /*   get pointer and length for module's Public area. Build public area      */
  563. /*   linked list if not already built.                                       */
  564. /*                                                                           */
  565. /* Parameters:                                                               */
  566. /*   mid        module id.                                                   */
  567. /*   lenptr     points to module's public area length.                       */
  568. /*   pdf        pointer to debug file structure.                             */
  569. /*                                                                           */
  570. /* Return:                                                                   */
  571. /*   pubptr     points to module's public area.                              */
  572. /*                                                                           */
  573. /* Assumptions;                                                              */
  574. /*                                                                           */
  575. /*  none.                                                                    */
  576. /*****************************************************************************/
  577.  uchar *
  578. DBPubSeg( uint mid, uint *lenptr , DEBFILE *pdf)
  579. {
  580.  PUBNODE      *pptr;
  581.  MODULE       *mptr;
  582.  uchar        *areaptr = NULL;
  583.  PUBREC32     *precptr;
  584.  PUBREC16     *precptr16;
  585.  uchar        *pubend;
  586. /*****************************************************************************/
  587. /*                                                                           */
  588. /* If we get here, then the pub  info does not exist for the mid specified.  */
  589. /* We need to cruise thru the module ring to find the mid's pub  area        */
  590. /* pointer in the .EXE file.  Then we can allocate space for the pub   and   */
  591. /* put the .EXE information in heap storage for future calls. If we are      */
  592. /* debugging without debug info , no /CO linker option, there will not be    */
  593. /* any public info.                                                          */
  594. /*                                                                           */
  595. /* 1. First, test for a valid mid.                                           */
  596. /* 2. Get a ptr to the public segment in the ring of currently loaded        */
  597. /*    public segments and return it.                                         */
  598. /* 3. If the publics are not loaded yet, then load them.                     */
  599. /* 4. Add them to the ring of public segments.                               */
  600. /* 5. Convert public record objnums:offsets to flat addresses.               */
  601. /* 6. Return the pointer to the public segment.                              */
  602. /*                                                                           */
  603. /*****************************************************************************/
  604.  
  605.  if ( !mid )
  606.   return(NULL);
  607.  *lenptr = 0;
  608.  for( pptr = pdf->ppubs; pptr != NULL; pptr=pptr->next )
  609.  {
  610.   if ( pptr->mid == mid )
  611.   {
  612.    *lenptr = pptr->publen;
  613.    return ( pptr->pubptr );
  614.   }
  615.  }
  616.  
  617.  /****************************************************************************/
  618.  /* publics not loaded so load them.                                         */
  619.  /****************************************************************************/
  620.  for( mptr = pdf->MidAnchor; mptr != NULL; mptr = mptr->NextMod )
  621.  {
  622.   if ( mptr->mid == mid )
  623.   {
  624.    if ( mptr->Publics )
  625.    {
  626.     areaptr=Talloc(mptr->PubLen);                                       /*521*/
  627.     seekf( pdf, pdf->DebugOff + mptr->Publics);
  628.     readf( areaptr, mptr->PubLen, pdf);
  629.     break;
  630.    }
  631.    return( NULL );
  632.   }
  633.  }
  634.  
  635.  /****************************************************************************/
  636.  /* add the public segment read to the ring of public segments.              */
  637.  /****************************************************************************/
  638.  if ( areaptr )
  639.  {
  640.   pptr = Talloc(sizeof(PUBNODE));                                       /*521*/
  641.   pptr->next = pdf->ppubs;
  642.   pptr->mid = mid;
  643.   pptr->pubptr = ( areaptr );
  644.   pptr->publen = mptr->PubLen;
  645.   *lenptr = mptr->PubLen;
  646.   pdf->ppubs = pptr;
  647.  }
  648.  
  649.  /****************************************************************************/
  650.  /* scan public records and convert obj:offsets to flat addresses.           */
  651.  /****************************************************************************/
  652.  precptr = ( PUBREC32 *)areaptr;
  653.  precptr16 = ( PUBREC16 *)areaptr;
  654.  
  655.  switch( mptr->DbgFormatFlags.Pubs )
  656.  {
  657.   case TYPE_PUB_32:
  658.    if ( precptr != NULL )
  659.    {
  660.     pubend = (uchar *)precptr + pptr->publen;
  661.     for( ; ( uchar *)precptr < pubend; )
  662.     {
  663.      precptr->Offset += GetLoadAddr(pdf->mte,precptr->ObjNum);         /*822*/
  664.      precptr = (PUBREC32 *)NextPubRec32(precptr);
  665.     }
  666.    }
  667.    break;
  668.  
  669.   case TYPE_PUB_16:                                                     /*237*/
  670.    if ( precptr16 != NULL)
  671.    {
  672.     pubend = (uchar *)precptr16 + pptr->publen;
  673.     for( ; ( uchar *)precptr16 < pubend; )
  674.     {
  675.  
  676.      int loadaddr;                                                     /*822*/
  677.                                                                        /*822*/
  678.      loadaddr=GetLoadAddr(pdf->mte,                                    /*822*/
  679.                           precptr16->Pub16Addr.RawAddr.ObjNum);        /*822*/
  680.                                                                        /*822*/
  681.      precptr16->Pub16Addr.FlatAddr = loadaddr +                        /*822*/
  682.                                    precptr16->Pub16Addr.RawAddr.Offset;/*822*/
  683.  
  684.      precptr16 = (PUBREC16 *)NextPubRec16(precptr16);
  685.     }
  686.    }
  687.    break;
  688.  }
  689.  return ( pptr->pubptr );
  690. }                                       /* end DBPubSeg                      */
  691.  
  692.