Ejemplo n.º 1
0
    internal void SetupDebugReader(string filename, string pdbSearchPath){
#if UseSingularityPDB
      string pdbFileName = BetterPath.ChangeExtension(filename, "pdb");
      this.getDebugSymbolsFailed = true;
      //TODO: use search path
      if (System.IO.File.Exists(pdbFileName)) {
        using (System.IO.FileStream inputStream = new System.IO.FileStream(pdbFileName,
                 System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) {
          this.pdbFunctions = PdbFile.LoadFunctions(inputStream, true);
          this.getDebugSymbolsFailed = false;
        }
      }
#elif !ROTOR
      if (filename == null) return;
      CorSymBinder binderObj1 = null;
      CorSymBinder2 binderObj2 = null;
      getDebugSymbolsFailed = false;
      object importer = null;
      try{
        int hresult = 0;
        try{
          binderObj2 = new CorSymBinder2();
          ISymUnmanagedBinder2 binder2 = (ISymUnmanagedBinder2)binderObj2;
#if !NoWriter          
            importer = new Ir2md(new Module());
#else
            importer = new EmptyImporter();
#endif
          hresult = binder2.GetReaderForFile(importer, filename, pdbSearchPath, out this.debugReader);
        }
        catch (COMException e){
          // could not instantiate ISymUnmanagedBinder2, fall back to ISymUnmanagedBinder
          if ((uint)e.ErrorCode == 0x80040111){
            binderObj1 = new CorSymBinder();
            ISymUnmanagedBinder binder = (ISymUnmanagedBinder)binderObj1;
            hresult = binder.GetReaderForFile(importer, filename, null, out this.debugReader);
          }else{
            throw;
          }
        }
        switch ((uint)hresult){
          case 0x0: break; 
          case 0x806d0005:  // EC_NOT_FOUND
          case 0x806d0014 : // EC_INVALID_EXE_TIMESTAMP
#if FxCop
            this.getDebugSymbols = false;
            this.getDebugSymbolsFailed = true;
#else
            // Sometimes GetReaderForFile erroneously reports missing pdb files as being "out of date", 
            // so we check if the file actually exists before reporting the error.
            // The mere absence of a pdb file is not an error. If not present, do not report.
            if (System.IO.File.Exists(System.IO.Path.ChangeExtension(filename, ".pdb")))
              throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExceptionStrings.PdbAssociatedWithFileIsOutOfDate, filename));
#endif            
            break;
          default:
            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, 
              ExceptionStrings.GetReaderForFileReturnedUnexpectedHResult, hresult.ToString("X")));
        }
#if !FxCop
      }catch (Exception e){
        this.getDebugSymbols = false;
        this.getDebugSymbolsFailed = true;
        if (this.module.MetadataImportErrors == null) this.module.MetadataImportErrors = new ArrayList();
        this.module.MetadataImportErrors.Add(e);
#endif
      }finally{
        if (binderObj1 != null) Marshal.ReleaseComObject(binderObj1);
        if (binderObj2 != null) Marshal.ReleaseComObject(binderObj2);
      }
#endif // !ROTOR
    }
Ejemplo n.º 2
0
        internal void SetupDebugReader(string filename, string pdbSearchPath)
        {
            if (filename == null) return;
            CorSymBinder binderObj1 = null;
            CorSymBinder2 binderObj2 = null;
            getDebugSymbolsFailed = false;
            object importer = null;
            try
            {
                int hresult = 0;
                try
                {
                    binderObj2 = new CorSymBinder2();
                    ISymUnmanagedBinder2 binder2 = (ISymUnmanagedBinder2)binderObj2;

                    importer = new EmptyImporter();
                    hresult = binder2.GetReaderForFile(importer, filename, pdbSearchPath, out this.debugReader);
                }
                catch (COMException e)
                {
                    // could not instantiate ISymUnmanagedBinder2, fall back to ISymUnmanagedBinder
                    if ((uint)e.ErrorCode == 0x80040111)
                    {
                        binderObj1 = new CorSymBinder();
                        ISymUnmanagedBinder binder = (ISymUnmanagedBinder)binderObj1;
                        hresult = binder.GetReaderForFile(importer, filename, null, out this.debugReader);
                    }
                    else
                    {
                        throw;
                    }
                }
                switch ((uint)hresult)
                {
                    case 0x0: break;
                    case 0x806d0005:  // EC_NOT_FOUND
                    case 0x806d0014: // EC_INVALID_EXE_TIMESTAMP
                        // Sometimes GetReaderForFile erroneously reports missing pdb files as being "out of date", 
                        // so we check if the file actually exists before reporting the error.
                        // The mere absence of a pdb file is not an error. If not present, do not report.
                        if (System.IO.File.Exists(System.IO.Path.ChangeExtension(filename, ".pdb")))
                            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExceptionStrings.PdbAssociatedWithFileIsOutOfDate, filename));
                        break;
                    default:
                        throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                          ExceptionStrings.GetReaderForFileReturnedUnexpectedHResult, hresult.ToString("X")));
                }
            }
            catch (Exception e)
            {
                this.getDebugSymbols = false;
                this.getDebugSymbolsFailed = true;
                if (this.module.MetadataImportErrors == null) this.module.MetadataImportErrors = new ArrayList();
                this.module.MetadataImportErrors.Add(e);
            }
            finally
            {
                if (binderObj1 != null) Marshal.ReleaseComObject(binderObj1);
                if (binderObj2 != null) Marshal.ReleaseComObject(binderObj2);
            }
        }