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

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   dll.c                                                                   */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  DLL handling functions.                                                  */
  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. /*... 05/14/91  105   Christina port to 32 bit.                              */
  17. /*... 02/08/91  107   Dave      port to 32 bit.                              */
  18. /*... 02/08/91  110   Srinivas  port to 32 bit.                              */
  19. /*... 02/08/91  116   Joe       port to 32 bit.                              */
  20. /*...                                                                        */
  21. /*...Release 1.00 (Pre-release 105 10/10/91)                                 */
  22. /*...                                                                        */
  23. /*... 10/23/91  306   Srinivas  Handling multiple dll loads and dll frees.   */
  24. /*...                                                                        */
  25. /*...Release 1.08 (Pre-release 108 )       )                                 */
  26. /*...                                                                        */
  27. /*... 02/04/92  510   Srinivas  Not able to step into func at source level.  */
  28. /*...                           Too many modules in exe                      */
  29. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  30. /*... 01/26/93  809   Selwyn    HLL Level 2 support.                         */
  31. /*...                                                                        */
  32. /*...Release 1.04 (04/30/93)                                                 */
  33. /*...                                                                        */
  34. /*... 05/04/93  822   Joe       Add mte table handling.                      */
  35. /*...                                                                        */
  36. /**Includes*******************************************************************/
  37.  
  38. #include "all.h"                        /* SD86 include files                */
  39.  
  40. /**External definitions*******************************************************/
  41.  
  42. extern PROCESS_NODE *pnode;             /* -> to process list.               */
  43. extern char         *msg[];             /* message array.                    */
  44. extern CmdParms      cmd;               /* pointer to CmdParms structure     */
  45.  
  46. /*****************************************************************************/
  47. /* dllinit()                                                                 */
  48. /*                                                                           */
  49. /* Description:                                                              */
  50. /*                                                                           */
  51. /*   initialize a DLL.                                                       */
  52. /*                                                                           */
  53. /* Parameters:                                                               */
  54. /*                                                                           */
  55. /*   mte          - mte handle of the DLL.                                   */
  56. /*   pModuleName  - -> to dll name.                                          */
  57. /*   pObjectTable - -> to the object table for this dll.                     */
  58. /*                                                                           */
  59. /* Return:                                                                   */
  60. /*                                                                           */
  61. /* Assumptions:                                                              */
  62. /*                                                                           */
  63. /*   pnode -> to at least one node.                                          */
  64. /*   pModuleName -> to a fully qualified dll name.                        822*/
  65. /*                                                                           */
  66. /*****************************************************************************/
  67. APIRET dllinit( HMODULE mte , char *pModuleName, OBJTABLEENTRY *pObjectTable )
  68. {                                       /*                                   */
  69.  DEBFILE      *pdf;                     /* -> to debug file structure        */
  70.  HFILE         FileHandle;              /* ddl file FILE structure        105*/
  71.  MODULE       *mptr;                    /* -> to a module node               */
  72.  uint          rc=0;                    /* return code                       */
  73.  uint          midbias;                 /* bias for the module id            */
  74.  DEBFILE      *pdfx;                    /* -> to debug file structure        */
  75.  char          ImageExe[CCHMAXPATH];                                    /*827*/
  76.  char         *pFileName;                                               /*827*/
  77.  
  78. /*****************************************************************************/
  79. /* Scan to see of the dll is already loaded. If so, then return.             */
  80. /*****************************************************************************/
  81.  pdfx = pnode->ExeStruct->next;
  82.  for(; pdfx ; pdfx=pdfx->next)
  83.   if ( pdfx->mte == mte )
  84.      return (0);
  85.  
  86.  if( IsEspRemote() )
  87.  {
  88.   /***************************************************************************/
  89.   /* If debugging remote, then find the image of the load dll. If we can't   */
  90.   /* find an image, then use the name that we got from the target machine.   */
  91.   /* For system dlls, this should be no problem. If, however, we can't       */
  92.   /* find an image that the user DOES intend to debug, then he will default  */
  93.   /* to assembler level debugging.                                           */
  94.   /***************************************************************************/
  95.   pFileName = strrchr(pModuleName, '\\') + 1;
  96.   memset(ImageExe,0,sizeof(ImageExe) );
  97.   rc = XSrvFindExe(pFileName,ImageExe,sizeof(ImageExe));
  98.   if( rc == 0)
  99.    pModuleName = ImageExe;
  100.  }
  101.  
  102. /*****************************************************************************/
  103. /*                                                                           */
  104. /* We have to find a range to assign the the mids to.                        */
  105. /* To find a mid range, we scan the current EXE/DLL list and get             */
  106. /* the next range of available values for this DLL. The first node that      */
  107. /* we encounter that has source info, a MidAnchor != null, will be the       */
  108. /* last DLL initialized and will contain the highest range used so far.      */
  109. /* The midbias will be used later after debfileinit() to adjust the          */
  110. /* base range, 1 to n, defined by debfileinit().                             */
  111. /*                                                                           */
  112. /* NOTE:                                                                     */
  113. /* We could have assigned numbers continuously from one DLL to the next      */
  114. /* but primarily for convenience, we chose to associate a range with         */
  115. /* each DLL. This should not be restrictive since a mid range of 1000        */
  116. /* accomodates an application with 1000 linked modules.                      */
  117. /*                                                                           */
  118. /*****************************************************************************/
  119.  midbias = 0;                           /*                                   */
  120.  pdfx = pnode->ExeStruct->next;         /* scan the ring of pdf nodes.       */
  121.  for(; pdfx ; pdfx=pdfx->next)          /*                                   */
  122.  {                                      /*                                   */
  123.   if(pdfx->MidAnchor)                   /* stop at first node with debug     */
  124.   {                                     /* info. This will have the last     */
  125.    midbias = pdfx->MidAnchor->mid - 1;  /* range assigned.                   */
  126.    break;                               /*                                   */
  127.   }                                     /*                                   */
  128.  }                                      /*                                   */
  129.  midbias += 1000;                       /* define the mid adjustment.     510*/
  130.  if(midbias == 131000)                  /*                                510*/
  131.   return(ERR_DLL_TOO_MANY);             /*                                   */
  132. /*****************************************************************************/
  133. /* - allocate space for the DEBFILE structure.                            822*/
  134. /* - allocate space for the DEBFILE part of the MFILE structure.          822*/
  135. /* - allocate space for module name and copy it out of the module load    822*/
  136. /*   table. (The module load table will eventually be freed.)             822*/
  137. /*****************************************************************************/
  138.  pdf=(DEBFILE *)Talloc(sizeof(DEBFILE));                                /*822*/
  139.  pdf->DebFilePtr=(MFILE*)Talloc(sizeof(MFILE));                         /*822*/
  140.  {                                                                      /*822*/
  141.   char *ptemp;                                                          /*822*/
  142.   int   len;                                                            /*822*/
  143.                                                                         /*822*/
  144.   len = strlen( pModuleName );                                          /*822*/
  145.   ptemp = Talloc( len + 1 );                                            /*822*/
  146.                                                                         /*822*/
  147.   strcpy( ptemp , pModuleName );                                        /*822*/
  148.   pModuleName = ptemp;                                                  /*822*/
  149.  }                                                                      /*822*/
  150.  
  151. /*****************************************************************************/
  152. /* - Open the dll for read access.                                           */
  153. /*****************************************************************************/
  154.  FileHandle = 0;
  155.  rc = opendos(pModuleName,"rb",&FileHandle);
  156.  if( rc != 0 )
  157.  {
  158.   FileHandle = 0;
  159.  }
  160. /*****************************************************************************/
  161. /* Now, we can start building the node.                                      */
  162. /*****************************************************************************/
  163.  pdf->DebFilePtr->fn=pModuleName;       /* add the name to the structure  822*/
  164.  pdf->DebFilePtr->fh=FileHandle;        /* store the debug file handle    105*/
  165.  pdf->mte=mte;                          /* add the mte handle                */
  166.  pdf->SrcOrAsm=1;                       /* assume asm    level debug         */
  167.  pdf->MidAnchor = NULL;                 /* initialize the module chain anchor*/
  168.  pdf->pid = pnode->pid;                 /* we will need the pid.             */
  169.  pdf->CodeObjs = (UINT*)pObjectTable;                                   /*822*/
  170.  
  171. /*****************************************************************************/
  172. /* Now, we will get the debug format and offset of the debug info in the     */
  173. /* file. We will handle the return from FindDebugStart() as follows:         */
  174. /*                                                                           */
  175. /*                                                                           */
  176. /* rc  |  DebugOff    | Action.                                              */
  177. /* ----|--------------|-------------------------------------                 */
  178. /* 0   |   0          | Normal asm level. File not developed with /CO.       */
  179. /* 0   |   long value | Source level. File developed with /CO.               */
  180. /* 1   |   0          | Error in debug info. Default to asm level.           */
  181. /*                                                                           */
  182. /* If we have source level info but have problems initializing in            */
  183. /* debfileinit(), then we will drop back to the asm level.                   */
  184. /*                                                                           */
  185. /*****************************************************************************/
  186.  pdf->DebugOff = 0;
  187.  if( FileHandle != 0 )
  188.  {
  189.   int NBxxType;
  190.   int ExeType;
  191.  
  192.   rc = FindDebugStart(FileHandle,
  193.                       &pdf->DebugOff,
  194.                       &NBxxType,
  195.                       &ExeType);
  196.  
  197.   pdf->ExeFlags.NBxxType = NBxxType;
  198.   pdf->ExeFlags.ExeType  = ExeType;
  199.  
  200.   if( rc == 1 )
  201.    return(ERR_BAD_DEBUG_INFO);
  202.  }
  203.  
  204.  if( pdf->DebugOff != 0 )
  205.  {
  206.   /***************************************************************************/
  207.   /* - source level debug.                                                   */
  208.   /***************************************************************************/
  209.   pdf->SrcOrAsm = 0;
  210.   rc=debfileinit(pdf);
  211.   if(rc)
  212.    return(ERR_EXE_INIT);
  213.  }
  214.  else
  215.  {
  216.   /***************************************************************************/
  217.   /* - debug at asm level.                                                   */
  218.   /***************************************************************************/
  219.   pdf->SrcOrAsm = 1;
  220.   asminit(pdf);
  221.  }
  222.  
  223.  /****************************************************************************/
  224.  /* - adjust mid range.                                                      */
  225.  /****************************************************************************/
  226.  for(
  227.      mptr = pdf->MidAnchor;
  228.      mptr != NULL;
  229.      mptr = mptr->NextMod
  230.     )
  231.   mptr->mid += midbias;
  232.  
  233.  /****************************************************************************/
  234.  /* - get the entry point if dll has debug info.                             */
  235.  /*   This if for the /i option in case the user wants to debug an           */
  236.  /*   InitTerm routine.                                                      */
  237.  /****************************************************************************/
  238.  if( pdf->DebugOff != 0 )
  239.   pdf->EntryExitPt = xGetExeOrDllEntryOrExitPt( pdf->mte );
  240.  
  241.  /****************************************************************************/
  242.  /* - add the node to the front of the chain.                                */
  243.  /****************************************************************************/
  244.  pdf->next=pnode->ExeStruct->next;
  245.  pnode->ExeStruct->next = pdf;
  246.  
  247. /*****************************************************************************/
  248. /* At this point the file is initialized for assembler level or source       */
  249. /* level debug.                                                              */
  250. /*****************************************************************************/
  251.  rc = ConvertDefBrks(pnode,pdf , TRUE);
  252.  if( pdf->SrcOrAsm == 1 && FileHandle != 0)
  253.  {
  254.   closedos(FileHandle);
  255.   pdf->DebFilePtr->fh=0;
  256.  }
  257.  
  258.  return(rc);
  259. }
  260.