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

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   exe.c                                                                   */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  EXE 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. /*... 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. /*... 02/08/91  105   Christina port to 32 bit.                              */
  20. /*                                                                           */
  21. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  22. /*...                                                                        */
  23. /*... 02/21/92  521   Srinivas  Port to C-Set/2.                             */
  24. /*...                                                                        */
  25. /*...Release 1.00 (03/03/92)                                                 */
  26. /*...                                                                        */
  27. /*... 03/26/92  609   Srinivas  Handle /Gp- calling convention for C-Set/2.  */
  28. /*...           609             (removed by joe)                             */
  29. /*... 01/26/93  809   Selwyn    HLL Level 2 support.                         */
  30. /*...                                                                        */
  31. /**Includes ******************************************************************/
  32.                                         /*                                   */
  33. #include "all.h"                        /* SD86 include files                */
  34.                                         /*                                   */
  35. /**Defines *******************************************************************/
  36.                                         /*                                   */
  37. /**External declararions******************************************************/
  38.                                         /*                                   */
  39. extern PROCESS_NODE *pnode;             /* -> to process list.            827*/
  40. extern CmdParms      cmd;               /* pointer to CmdParms structure     */
  41.                                         /*                                   */
  42. /**External definitions*******************************************************/
  43.                                         /*                                   */
  44. /**Static definitions ********************************************************/
  45.                                         /*                                   */
  46. /*****************************************************************************/
  47. /* exeinit()                                                                 */
  48. /*                                                                           */
  49. /* Description:                                                              */
  50. /*                                                                           */
  51. /*   initialize an EXE file and allocate space for a fake mid.               */
  52. /*                                                                           */
  53. /* Parameters:                                                               */
  54. /*   pdf        pointer to debug file structure.                             */
  55. /*                                                                           */
  56. /*                                                                           */
  57. /* Return:                                                                   */
  58. /*                                                                           */
  59. /*   rc                                                                      */
  60. /*                                                                           */
  61. /* Assumptions:                                                              */
  62. /*                                                                           */
  63. /*   pModuleName != NULL &&                                                  */
  64. /*   pModuleName -> fully qualified file name of the EXE.                    */
  65. /*                                                                           */
  66. /*****************************************************************************/
  67. ULONG exeinit( HMODULE mte,char *pModuleName,OBJTABLEENTRY *pObjectTable )
  68. {                                       /*                                   */
  69.  int           rc;                      /* return code                       */
  70.  MODULE       *mptr;                    /* -> to a module node               */
  71.  MODULE       *lptr;                    /* last pointer to a module          */
  72.  HFILE         FileHandle ;             /* -> to file structure           105*/
  73.  EXEFILE      *pdf;                     /* -> to debug file.                 */
  74.  char          ImageExe[CCHMAXPATH];
  75.  MFILE        *mfile;                   /* -> to MFILE file structure.       */
  76.  char         *fn;
  77.  
  78.  /****************************************************************************/
  79.  /* If debugging remote, then find the image of the load exe.                */
  80.  /****************************************************************************/
  81.  if( IsEspRemote() )
  82.  {
  83.   char *pFileName;
  84.   /***************************************************************************/
  85.   /* If debugging remote, then find the image of the load exe. If we can't   */
  86.   /* find an image, then use the name that we got from the target machine    */
  87.   /* and default to assembler level debugging.                               */
  88.   /***************************************************************************/
  89.   pFileName = strrchr(pModuleName, '\\') + 1;
  90.   memset(ImageExe,0,sizeof(ImageExe) );
  91.   rc = XSrvFindExe(pFileName,ImageExe,sizeof(ImageExe));
  92.   if( rc == 0)
  93.    pModuleName = ImageExe;
  94.  }
  95.  fn = Talloc(strlen(pModuleName)+1);
  96.  strcpy(fn,pModuleName);
  97.  
  98.  /****************************************************************************/
  99.  /* - At this point, fn points to the image of the exe. If not               */
  100.  /*   debugging remote, it's the same as the load exe.                       */
  101.  /****************************************************************************/
  102.  rc = opendos(fn,"rb",&FileHandle);
  103.  if( rc != 0 )
  104.   FileHandle = 0;
  105.  
  106.  /****************************************************************************/
  107.  /* Allocate and build the pdf structure for the EXE.                        */
  108.  /****************************************************************************/
  109.  pdf                 = (EXEFILE *)Talloc(sizeof(EXEFILE));
  110.  mfile               = (MFILE*)Talloc(sizeof(MFILE));
  111.  pdf->DebFilePtr     = mfile;
  112.  pdf->DebFilePtr->fh = FileHandle;
  113.  pdf->DebFilePtr->fn = fn;
  114.  pdf->pid            = pnode->pid;
  115.  pdf->mte            = mte;
  116.  pdf->CodeObjs       = (UINT*)pObjectTable;
  117.  
  118.  pnode->ExeStruct = pdf;
  119.  
  120.  /****************************************************************************/
  121.  /* - On ReStart(), convert deferred breakpoints.                            */
  122.  /****************************************************************************/
  123.  ConvertDefBrks(pnode,pdf , FALSE );
  124.  
  125. /*****************************************************************************/
  126. /* - Get the entry point for this exe.                                       */
  127. /* - We always want an EXE entry point in case we init for asm level debug.  */
  128. /*****************************************************************************/
  129.  pdf->EntryExitPt = xGetExeOrDllEntryOrExitPt( pdf->mte );              /*827*/
  130.  if(pdf->EntryExitPt == 0 )
  131.   return(ERR_EXE_INIT);
  132.  
  133. /*****************************************************************************/
  134. /* - Get the start of the debug info.                                        */
  135. /* - Come up in assembler if no debug info.                                  */
  136. /*****************************************************************************/
  137.  FileHandle = pdf->DebFilePtr->fh;
  138.  pdf->MidAnchor = NULL;
  139.  pdf->DebugOff = 0;
  140.  if( FileHandle != 0 )
  141.  {
  142.   int NBxxType;
  143.   int ExeType;
  144.  
  145.   rc = FindDebugStart(FileHandle,
  146.                       &pdf->DebugOff,
  147.                       &NBxxType,
  148.                       &ExeType);
  149.  
  150.   pdf->ExeFlags.NBxxType = NBxxType;
  151.   pdf->ExeFlags.ExeType  = ExeType;
  152.  
  153.   if( rc == 1 )
  154.    return(ERR_EXE_INIT);
  155.  }
  156.  
  157.  if( pdf->DebugOff != 0 )
  158.  {
  159.   /***************************************************************************/
  160.   /* - source level debug.                                                   */
  161.   /***************************************************************************/
  162.   pdf->SrcOrAsm = 0;
  163.   rc=debfileinit(pdf);
  164.   if(rc)
  165.    return(ERR_EXE_INIT);
  166.  }
  167.  else
  168.  {
  169.   /***************************************************************************/
  170.   /* - debug at asm level.                                                   */
  171.   /***************************************************************************/
  172.   pdf->SrcOrAsm = 1;
  173.   asminit(pdf);
  174.  }
  175.  
  176.  /****************************************************************************/
  177.  /* If we are debugging at asm level and the file was opened, then           */
  178.  /* close it.                                                                */
  179.  /****************************************************************************/
  180.  if( pdf->SrcOrAsm == 1 && FileHandle != 0)
  181.   closedos(FileHandle);
  182.  
  183. /*****************************************************************************/
  184. /* We are now going to append a fake mid to the end of the module chain.     */
  185. /* ( this code was moved to assure at least one fake node for asm level )    */
  186. /*****************************************************************************/
  187.  for(lptr = (MODULE *)&pdf->MidAnchor,  /* scan to end of mid list           */
  188.      mptr = pdf->MidAnchor;             /*                                   */
  189.      mptr != NULL;                      /*                                   */
  190.      lptr = mptr,                       /* hold this module pointer          */
  191.      mptr = mptr->NextMod               /*                                   */
  192.     ){;}                                /*                                   */
  193.  mptr=(MODULE *)Talloc(sizeof(MODULE)); /* allocate space for fake mid    521*/
  194.  mptr->NextMod = NULL;                  /* last node in the list so gnd it   */
  195.  lptr->NextMod = mptr;                  /* add it to the list                */
  196.  mptr->mid  = FAKEMID;                  /* assume this unique mid            */
  197.  return(0);                             /* assembly level is ok              */
  198. }                                       /* end of exeinit()                  */
  199.