예제 #1
0
 internal Document(PdbSource source) : this()
 {
     this.Name           = source.name;
     this.Language       = source.language;
     this.LanguageVendor = source.vendor;
     this.DocumentType   = source.doctype;
 }
예제 #2
0
 private static void AssertFiles(PdbSource originalFile, PdbSource file)
 {
     Assert.AreEqual(originalFile.name, file.name);
     Assert.AreEqual(originalFile.language, file.language);
     Assert.AreEqual(originalFile.vendor, file.vendor);
     Assert.AreEqual(originalFile.doctype, file.doctype);
 }
        private IEnumerable <IPrimarySourceLocation> MapMethodBodyLocationToSourceLocations(IILLocation mbLocation)
        {
            PdbFunction pdbFunction = null;
            var         doc         = mbLocation.Document as MethodBodyDocument;

            if (doc == null || !this.pdbFunctionMap.TryGetValue(doc.MethodToken, out pdbFunction))
            {
                yield break;
            }

            if (pdbFunction.lines == null)
            {
                yield break;
            }

            foreach (PdbLines pdbLines in pdbFunction.lines)
            {
                foreach (var pdbLine in pdbLines.lines)
                {
                    PdbSource pdbSourceFile = pdbLines.file;
                    if (pdbSourceFile == null)
                    {
                        continue;
                    }


                    PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(pdbSourceFile);
                    yield return(new PdbSourceLineLocation(psDoc, (int)pdbLine.lineBegin, pdbLine.colBegin, (int)pdbLine.lineEnd, pdbLine.colEnd));
                }
            }
        }
        private IPrimarySourceLocation /*?*/ MapMethodBodyLocationToSourceLocation(IILLocation mbLocation, bool exact)
        {
            PdbFunction pdbFunction;
            var         doc = mbLocation.Document as MethodBodyDocument;

            if (doc == null || !this.pdbFunctionMap.TryGetValue(doc.MethodToken, out pdbFunction))
            {
                return(null);
            }
            if (pdbFunction.lines == null)
            {
                return(null);
            }
            foreach (PdbLines pdbLines in pdbFunction.lines)
            {
                PdbSource pdbSourceFile = pdbLines.file;
                if (pdbSourceFile == null)
                {
                    return(null);
                }

                PdbLine[] array    = pdbLines.lines;
                int       minIndex = 0;
                int       maxIndex = array.Length - 1;

                uint desiredOffset = mbLocation.Offset;

                while (minIndex <= maxIndex)
                {
                    int     midPointIndex = (minIndex + maxIndex) >> 1;
                    PdbLine mid           = array[midPointIndex];
                    if (midPointIndex == maxIndex ||
                        (mid.offset <= desiredOffset && desiredOffset < array[midPointIndex + 1].offset))
                    {
                        if (exact && desiredOffset != mid.offset)
                        {
                            return(null);
                        }
                        PdbLine           line  = mid;
                        PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(pdbSourceFile);

                        return(new PdbSourceLineLocation(psDoc, (int)line.lineBegin, line.colBegin, (int)line.lineEnd, line.colEnd));
                    }
                    if (mid.offset < desiredOffset)
                    {
                        minIndex = midPointIndex + 1;
                    }
                    else
                    {
                        maxIndex = midPointIndex - 1;
                    }
                }
            }
            return(null);
        }
예제 #5
0
        Document GetDocument(PdbSource source)
        {
            string   name = source.name;
            Document document;

            if (documents.TryGetValue(name, out document))
            {
                return(document);
            }

            document                = new Document(name);
            document.Language       = source.language;
            document.LanguageVendor = source.vendor;
            document.Type           = source.doctype;
            documents.Add(name, document);
            return(document);
        }
예제 #6
0
        Document GetDocument(PdbSource source)
        {
            string   name = source.name;
            Document document;

            if (documents.TryGetValue(name, out document))
            {
                return(document);
            }

            document = new Document(name)
            {
                Language       = source.language.ToLanguage(),
                LanguageVendor = source.vendor.ToVendor(),
                Type           = source.doctype.ToType(),
            };
            documents.Add(name, document);
            return(document);
        }
예제 #7
0
        Document GetDocument(PdbSource source)
        {
            string   name = source.name;
            Document document;

            if (documents.TryGetValue(name, out document))
            {
                return(document);
            }

            document = new Document(name)
            {
                LanguageGuid       = source.language,
                LanguageVendorGuid = source.vendor,
                TypeGuid           = source.doctype,
                HashAlgorithmGuid  = source.checksumAlgorithm,
                Hash = source.checksum,
            };
            documents.Add(name, document);
            return(document);
        }
예제 #8
0
        private PdbSourceDocument GetPrimarySourceDocumentFor(PdbSource pdbSourceFile)
        {
            PdbSourceDocument /*?*/ result = null;

            if (this.documentCache.TryGetValue(pdbSourceFile, out result))
            {
                return(result);
            }
            IName name = this.host.NameTable.GetNameFor(Path.GetFileName(pdbSourceFile.name));

            if (File.Exists(pdbSourceFile.name))
            {
                var sourceFileReader = new StreamReader(pdbSourceFile.name);
                this.sourceFilesOpenedByReader.Add(sourceFileReader);
                result = new PdbSourceDocument(name, pdbSourceFile, sourceFileReader);
            }
            else
            {
                result = new PdbSourceDocument(name, pdbSourceFile);
            }
            this.documentCache.Add(pdbSourceFile, result);
            return(result);
        }
예제 #9
0
 internal PdbLines(PdbSource file, uint count)
 {
     this.file = file;
       this.lines = new PdbLine[count];
 }
예제 #10
0
 /// <summary>
 /// Allocates an object that represents a source document, such as file, which is parsed according to the rules of a particular langauge,
 /// such as C#, to produce an object model.
 /// </summary>
 /// <param name="name">The name of the document. Used to identify the document in user interaction.</param>
 /// <param name="pdbSourceFile">Information about the document, such as its location.</param>
 internal PdbSourceDocument(IName name, PdbSource pdbSourceFile)
     : base(name, pdbSourceFile.name, "")
 {
     this.pdbSourceFile = pdbSourceFile;
 }
예제 #11
0
 /// <summary>
 /// Allocates an object that represents a source document, such as file, which is parsed according to the rules of a particular langauge,
 /// such as C#, to produce an object model.
 /// </summary>
 /// <param name="name">The name of the document. Used to identify the document in user interaction.</param>
 /// <param name="pdbSourceFile">Information about the document, such as its location.</param>
 /// <param name="streamReader">A StreamReader instance whose BaseStream produces the contents of the document.</param>
 internal PdbSourceDocument(IName name, PdbSource pdbSourceFile, StreamReader streamReader)
     : base(name, pdbSourceFile.name, streamReader)
 {
     this.pdbSourceFile = pdbSourceFile;
 }
예제 #12
0
        public static void Dump(PdbSource s, int indent)
        {
            string pad = new String(' ', indent);

            Console.WriteLine("            {0}[{1}] : {2}", pad, s.name, s.index);
        }
예제 #13
0
 internal PdbSequencePointCollection(PdbSource file, uint count)
 {
     File  = file;
     Lines = new PdbSequencePoint[count];
 }
 /// <summary>
 /// Allocates an object that represents a source document, such as file, which is parsed according to the rules of a particular langauge, 
 /// such as C#, to produce an object model.
 /// </summary>
 /// <param name="name">The name of the document. Used to identify the document in user interaction.</param>
 /// <param name="pdbSourceFile">Information about the document, such as its location.</param>
 internal PdbSourceDocument(IName name, PdbSource pdbSourceFile)
     : base(name, pdbSourceFile.name, "")
 {
     this.pdbSourceFile = pdbSourceFile;
 }
 /// <summary>
 /// Allocates an object that represents a source document, such as file, which is parsed according to the rules of a particular langauge, 
 /// such as C#, to produce an object model.
 /// </summary>
 /// <param name="name">The name of the document. Used to identify the document in user interaction.</param>
 /// <param name="pdbSourceFile">Information about the document, such as its location.</param>
 /// <param name="streamReader">A StreamReader instance whose BaseStream produces the contents of the document.</param>
 internal PdbSourceDocument(IName name, PdbSource pdbSourceFile, StreamReader streamReader)
     : base(name, pdbSourceFile.name, streamReader)
 {
     this.pdbSourceFile = pdbSourceFile;
 }
예제 #16
0
        /// <summary>
        /// </summary>
        /// <param name="funcs">
        /// </param>
        /// <param name="names">
        /// </param>
        /// <param name="bits">
        /// </param>
        /// <param name="dir">
        /// </param>
        /// <param name="nameIndex">
        /// </param>
        /// <param name="reader">
        /// </param>
        /// <param name="limit">
        /// </param>
        private static void LoadManagedLines(
            PdbFunction[] funcs, IntHashTable names, BitAccess bits, MsfDirectory dir, Dictionary<string, int> nameIndex, PdbReader reader, uint limit)
        {
            Array.Sort(funcs, PdbFunction.byAddress);
            var checks = new IntHashTable();

            // Read the files first
            var begin = bits.Position;
            while (bits.Position < limit)
            {
                int sig;
                int siz;
                bits.ReadInt32(out sig);
                bits.ReadInt32(out siz);
                var place = bits.Position;
                var endSym = bits.Position + siz;

                switch ((DEBUG_S_SUBSECTION)sig)
                {
                    case DEBUG_S_SUBSECTION.FILECHKSMS:
                        while (bits.Position < endSym)
                        {
                            CV_FileCheckSum chk;

                            var ni = bits.Position - place;
                            bits.ReadUInt32(out chk.name);
                            bits.ReadUInt8(out chk.len);
                            bits.ReadUInt8(out chk.type);

                            var name = (string)names[(int)chk.name];
                            int guidStream;
                            var doctypeGuid = SymDocumentType.Text;
                            var languageGuid = SymLanguageType.CSharp;
                            var vendorGuid = SymLanguageVendor.Microsoft;
                            if (nameIndex.TryGetValue("/src/files/" + name, out guidStream))
                            {
                                var guidBits = new BitAccess(0x100);
                                dir.streams[guidStream].Read(reader, guidBits);
                                LoadGuidStream(guidBits, out doctypeGuid, out languageGuid, out vendorGuid);
                            }

                            var src = new PdbSource((uint)ni, name, doctypeGuid, languageGuid, vendorGuid);
                            checks.Add(ni, src);
                            bits.Position += chk.len;
                            bits.Align(4);
                        }

                        bits.Position = endSym;
                        break;

                    default:
                        bits.Position = endSym;
                        break;
                }
            }

            // Read the lines next.
            bits.Position = begin;
            while (bits.Position < limit)
            {
                int sig;
                int siz;
                bits.ReadInt32(out sig);
                bits.ReadInt32(out siz);
                var endSym = bits.Position + siz;

                switch ((DEBUG_S_SUBSECTION)sig)
                {
                    case DEBUG_S_SUBSECTION.LINES:
                        {
                            CV_LineSection sec;

                            bits.ReadUInt32(out sec.off);
                            bits.ReadUInt16(out sec.sec);
                            bits.ReadUInt16(out sec.flags);
                            bits.ReadUInt32(out sec.cod);
                            var func = FindFunction(funcs, sec.sec, sec.off);
                            if (func == null)
                            {
                                break;
                            }

                            // Count the line blocks.
                            var begSym = bits.Position;
                            var blocks = 0;
                            while (bits.Position < endSym)
                            {
                                CV_SourceFile file;
                                bits.ReadUInt32(out file.index);
                                bits.ReadUInt32(out file.count);
                                bits.ReadUInt32(out file.linsiz); // Size of payload.
                                var linsiz = (int)file.count * (8 + ((sec.flags & 1) != 0 ? 4 : 0));
                                bits.Position += linsiz;
                                blocks++;
                            }

                            func.lines = new PdbLines[blocks];
                            var block = 0;

                            bits.Position = begSym;
                            while (bits.Position < endSym)
                            {
                                CV_SourceFile file;
                                bits.ReadUInt32(out file.index);
                                bits.ReadUInt32(out file.count);
                                bits.ReadUInt32(out file.linsiz); // Size of payload.

                                var src = (PdbSource)checks[(int)file.index];
                                var tmp = new PdbLines(src, file.count);
                                func.lines[block++] = tmp;
                                var lines = tmp.lines;

                                var plin = bits.Position;
                                var pcol = bits.Position + 8 * (int)file.count;

                                for (var i = 0; i < file.count; i++)
                                {
                                    CV_Line line;
                                    var column = new CV_Column();

                                    bits.Position = plin + 8 * i;
                                    bits.ReadUInt32(out line.offset);
                                    bits.ReadUInt32(out line.flags);

                                    var lineBegin = line.flags & (uint)CV_Line_Flags.linenumStart;
                                    var delta = (line.flags & (uint)CV_Line_Flags.deltaLineEnd) >> 24;
                                    var statement = (line.flags & (uint)CV_Line_Flags.fStatement) == 0;
                                    if ((sec.flags & 1) != 0)
                                    {
                                        bits.Position = pcol + 4 * i;
                                        bits.ReadUInt16(out column.offColumnStart);
                                        bits.ReadUInt16(out column.offColumnEnd);
                                    }

                                    lines[i] = new PdbLine(line.offset, lineBegin, column.offColumnStart, lineBegin + delta, column.offColumnEnd);
                                }
                            }

                            break;
                        }
                }

                bits.Position = endSym;
            }
        }
예제 #17
0
    static void LoadManagedLines(PdbFunction[] funcs,
                                 IntHashTable names,
                                 BitAccess bits,
                                 MsfDirectory dir,
                                 Dictionary<string, int> nameIndex,
                                 PdbReader reader,
                                 uint limit) {
      Array.Sort(funcs, PdbFunction.byAddress);
      IntHashTable checks = new IntHashTable();

      // Read the files first
      int begin = bits.Position;
      while (bits.Position < limit) {
        int sig;
        int siz;
        bits.ReadInt32(out sig);
        bits.ReadInt32(out siz);
        int place = bits.Position;
        int endSym = bits.Position + siz;

        switch ((DEBUG_S_SUBSECTION)sig) {
          case DEBUG_S_SUBSECTION.FILECHKSMS:
            while (bits.Position < endSym) {
              CV_FileCheckSum chk;

              int ni = bits.Position - place;
              bits.ReadUInt32(out chk.name);
              bits.ReadUInt8(out chk.len);
              bits.ReadUInt8(out chk.type);

              string name = (string)names[(int)chk.name];
              int guidStream;
              Guid doctypeGuid = new Guid("5a869d0b-6611-11d3-bd2a-0000f80849bd");
              Guid languageGuid = new Guid("3f5162f8-07c6-11d3-9053-00c04fa302a1");
              Guid vendorGuid = new Guid("994b45c4-e6e9-11d2-903f-00c04fa302a1");
              if (nameIndex.TryGetValue("/src/files/"+name, out guidStream)) {
                var guidBits = new BitAccess(0x100);
                dir.streams[guidStream].Read(reader, guidBits);
                LoadGuidStream(guidBits, out doctypeGuid, out languageGuid, out vendorGuid);
              }

              PdbSource src = new PdbSource((uint)ni, name, doctypeGuid, languageGuid, vendorGuid);
              checks.Add(ni, src);
              bits.Position += chk.len;
              bits.Align(4);
            }
            bits.Position = endSym;
            break;

          default:
            bits.Position = endSym;
            break;
        }
      }

      // Read the lines next.
      bits.Position = begin;
      while (bits.Position < limit) {
        int sig;
        int siz;
        bits.ReadInt32(out sig);
        bits.ReadInt32(out siz);
        int endSym = bits.Position + siz;

        switch ((DEBUG_S_SUBSECTION)sig) {
          case DEBUG_S_SUBSECTION.LINES: {
              CV_LineSection sec;

              bits.ReadUInt32(out sec.off);
              bits.ReadUInt16(out sec.sec);
              bits.ReadUInt16(out sec.flags);
              bits.ReadUInt32(out sec.cod);
              PdbFunction func = FindFunction(funcs, sec.sec, sec.off);
              if (func == null) break;

              // Count the line blocks.
              int begSym = bits.Position;
              int blocks = 0;
              while (bits.Position < endSym) {
                CV_SourceFile file;
                bits.ReadUInt32(out file.index);
                bits.ReadUInt32(out file.count);
                bits.ReadUInt32(out file.linsiz);   // Size of payload.
                int linsiz = (int)file.count * (8 + ((sec.flags & 1) != 0 ? 4 : 0));
                bits.Position += linsiz;
                blocks++;
              }

              func.lines = new PdbLines[blocks];
              int block = 0;

              bits.Position = begSym;
              while (bits.Position < endSym) {
                CV_SourceFile file;
                bits.ReadUInt32(out file.index);
                bits.ReadUInt32(out file.count);
                bits.ReadUInt32(out file.linsiz);   // Size of payload.

                PdbSource src = (PdbSource)checks[(int)file.index];
                PdbLines tmp = new PdbLines(src, file.count);
                func.lines[block++] = tmp;
                PdbLine[] lines = tmp.lines;

                int plin = bits.Position;
                int pcol = bits.Position + 8 * (int)file.count;

                for (int i = 0; i < file.count; i++) {
                  CV_Line line;
                  CV_Column column = new CV_Column();

                  bits.Position = plin + 8 * i;
                  bits.ReadUInt32(out line.offset);
                  bits.ReadUInt32(out line.flags);

                  uint lineBegin = line.flags & (uint)CV_Line_Flags.linenumStart;
                  uint delta = (line.flags & (uint)CV_Line_Flags.deltaLineEnd) >> 24;
                  bool statement = ((line.flags & (uint)CV_Line_Flags.fStatement) == 0);
                  if ((sec.flags & 1) != 0) {
                    bits.Position = pcol + 4 * i;
                    bits.ReadUInt16(out column.offColumnStart);
                    bits.ReadUInt16(out column.offColumnEnd);
                  }

                  lines[i] = new PdbLine(line.offset,
                                         lineBegin,
                                         column.offColumnStart,
                                         lineBegin+delta,
                                         column.offColumnEnd);
                }
              }
              break;
            }
        }
        bits.Position = endSym;
      }
    }
예제 #18
0
		Document GetDocument (PdbSource source)
		{
			string name = source.name;
			Document document;
			if (documents.TryGetValue (name, out document))
				return document;

			document = new Document (name) {
				Language = source.language.ToLanguage (),
				LanguageVendor = source.vendor.ToVendor (),
				Type = source.doctype.ToType (),
			};
			documents.Add (name, document);
			return document;
		}
예제 #19
0
        private static IntHashTable ReadSourceFileInfo(
            BitAccess bits, uint limit, IntHashTable names, MsfDirectory dir,
            Dictionary<string, int> nameIndex, PdbReader reader)
        {
            IntHashTable checks = new IntHashTable();

            int begin = bits.Position;
            while (bits.Position < limit)
            {
                int sig;
                int siz;
                bits.ReadInt32(out sig);
                bits.ReadInt32(out siz);
                int place = bits.Position;
                int endSym = bits.Position + siz;

                switch ((DEBUG_S_SUBSECTION)sig)
                {
                    case DEBUG_S_SUBSECTION.FILECHKSMS:
                        while (bits.Position < endSym)
                        {
                            CV_FileCheckSum chk;

                            int ni = bits.Position - place;
                            bits.ReadUInt32(out chk.name);
                            bits.ReadUInt8(out chk.len);
                            bits.ReadUInt8(out chk.type);

                            PdbSource src = new PdbSource(/*(uint)ni,*/ (string)names[(int)chk.name], SymDocumentType.Text, Guid.Empty, Guid.Empty);
                            checks.Add(ni, src);
                            bits.Position += chk.len;
                            bits.Align(4);
                        }
                        bits.Position = endSym;
                        break;

                    default:
                        bits.Position = endSym;
                        break;
                }
            }
            return checks;
        }
예제 #20
0
 /// <summary>
 /// </summary>
 /// <param name="file">
 /// </param>
 /// <param name="count">
 /// </param>
 internal PdbLines(PdbSource file, uint count)
 {
     this.file  = file;
     this.lines = new PdbLine[count];
 }