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
        public void Write(string str, bool emitNullTerminator)
        {
            if (str == null)
            {
                Debug.Assert(!emitNullTerminator);
                this.Write((byte)0xff);
                return;
            }
            int n = str.Length;

            if (!emitNullTerminator)
            {
                if (this.UTF8)
                {
                    Ir2md.WriteCompressedInt(this, GetUTF8ByteCount(str));
                }
                else
                {
                    Ir2md.WriteCompressedInt(this, n * 2);
                }
            }
            MemoryStream m = this.BaseStream;
            int          i = m.Position;

            if (this.UTF8)
            {
                m.Position = i + n;
                byte[] buffer = m.Buffer;
                for (int j = 0; j < n; j++)
                {
                    char ch = str[j];
                    if (ch >= 0x80)
                    {
                        goto writeUTF8;
                    }
                    buffer[i++] = (byte)ch;
                }
                if (emitNullTerminator)
                {
                    m.Position = i + 1;
                    buffer     = m.Buffer;
                    buffer[i]  = 0;
                }
                return;

writeUTF8:
                int ch32 = 0;
                for (int j = n - (m.Position - i); j < n; j++)
                {
                    char ch = str[j];
                    if (ch < 0x80)
                    {
                        m.Position  = i + 1;
                        buffer      = m.Buffer;
                        buffer[i++] = (byte)ch;
                    }
                    else if (ch < 0x800)
                    {
                        m.Position  = i + 2;
                        buffer      = m.Buffer;
                        buffer[i++] = (byte)(((ch >> 6) & 0x1F) | 0xC0);
                        buffer[i++] = (byte)((ch & 0x3F) | 0x80);
                    }
                    else if (0xD800 <= ch && ch <= 0xDBFF)
                    {
                        ch32 = (ch & 0x3FF) << 10;
                    }
                    else if (0xDC00 <= ch && ch <= 0xDFFF)
                    {
                        ch32       |= ch & 0x3FF;
                        m.Position  = i + 4;
                        buffer      = m.Buffer;
                        buffer[i++] = (byte)(((ch32 >> 18) & 0x7) | 0xF0);
                        buffer[i++] = (byte)(((ch32 >> 12) & 0x3F) | 0x80);
                        buffer[i++] = (byte)(((ch32 >> 6) & 0x3F) | 0x80);
                        buffer[i++] = (byte)((ch32 & 0x3F) | 0x80);
                    }
                    else
                    {
                        m.Position  = i + 3;
                        buffer      = m.Buffer;
                        buffer[i++] = (byte)(((ch >> 12) & 0xF) | 0xE0);
                        buffer[i++] = (byte)(((ch >> 6) & 0x3F) | 0x80);
                        buffer[i++] = (byte)((ch & 0x3F) | 0x80);
                    }
                }
                if (emitNullTerminator)
                {
                    m.Position = i + 1;
                    buffer     = m.Buffer;
                    buffer[i]  = 0;
                }
            }
            else
            {
                m.Position = i + n * 2;
                byte[] buffer = m.Buffer;
                for (int j = 0; j < n; j++)
                {
                    char ch = str[j];
                    buffer[i++] = (byte)ch;
                    buffer[i++] = (byte)(ch >> 8);
                }
                if (emitNullTerminator)
                {
                    m.Position  = i + 2;
                    buffer      = m.Buffer;
                    buffer[i++] = 0;
                    buffer[i]   = 0;
                }
            }
        }