Example #1
0
        public Boolean TryAddSource(String sourceName, PDBSource source)
        {
            ArgumentValidator.ValidateNotNull("Source", source);
            var result = !this._sources.ContainsKey(sourceName);

            if (result)
            {
                this._sources.Add(sourceName, source);
            }
            return(result);
        }
Example #2
0
        private static IDictionary <Int32, PDBSource> LoadSourcesAndLinesFromModuleStream(
            StreamInfo stream,
            Int32 pageSize,
            Int32[][] streamPages,
            Int32[] streamSizes,
            Byte[] array,
            Int32 idx,
            Int32 max,
            IDictionary <String, Int32> streamNameIndices,
            IDictionary <Int32, String> nameIndex,
            PDBInstance instance,
            List <PDBFunctionInfo> functions
            )
        {
            var sourcesLocal = new Dictionary <Int32, PDBSource>();
            var lines        = new List <Tuple <Int32, PDBLine> > [functions.Count];

            while (idx < max)
            {
                var sym      = array.ReadInt32LEFromBytes(ref idx);
                var size     = array.ReadInt32LEFromBytes(ref idx);
                var startIdx = idx;
                var endIdx   = idx + size;
                switch (sym)
                {
                case SYM_DEBUG_SOURCE_INFO:
                    while (idx < endIdx)
                    {
                        var curSrcFileIdx = idx - startIdx;
                        var nameIdx       = array.ReadInt32LEFromBytes(ref idx);
                        var thisLen       = array.ReadByteFromBytes(ref idx);
                        /*var kind = */
                        array.ReadByteFromBytes(ref idx);

                        var       name = nameIndex[nameIdx];
                        PDBSource pdbSource;
                        if (!instance.TryGetSource(name, out pdbSource))
                        {
                            pdbSource = new PDBSource(name);
                            Int32 sourceStreamIdx;
                            if (streamNameIndices.TryGetValue(SOURCE_FILE_PREFIX + name, out sourceStreamIdx))
                            {
                                var sourceBytes = stream.ReadPagedData(pageSize, streamPages[sourceStreamIdx], streamSizes[sourceStreamIdx]);
                                var tmpIdx      = 0;
                                pdbSource.Language      = sourceBytes.ReadGUIDFromBytes(ref tmpIdx);
                                pdbSource.Vendor        = sourceBytes.ReadGUIDFromBytes(ref tmpIdx);
                                pdbSource.DocumentType  = sourceBytes.ReadGUIDFromBytes(ref tmpIdx);
                                pdbSource.HashAlgorithm = sourceBytes.ReadGUIDFromBytes(ref tmpIdx);
                                pdbSource.Hash          = sourceBytes.CreateAndBlockCopyTo(ref tmpIdx, sourceBytes.Length - tmpIdx);
                            }
                            instance.AddSource(pdbSource);
                        }
                        ;

                        sourcesLocal.Add(curSrcFileIdx, pdbSource);
#if DEBUG
                        if (thisLen != 0)
                        {
                            throw new PDBException("Debyyg");
                        }
#endif
                        idx += thisLen;
                        Align4(ref idx);
                    }
                    break;

                case SYM_DEBUG_LINE_INFO:

                    var addr    = array.ReadInt32LEFromBytes(ref idx);
                    var section = array.ReadUInt16LEFromBytes(ref idx);
                    var flags   = array.ReadUInt16LEFromBytes(ref idx);
                    /*var cod = */
                    array.ReadUInt32LEFromBytes(ref idx);
                    var funcIdx = functions.BinarySearchDeferredEqualityDetection(new PDBFunctionInfo(null, addr, section, -1), PDB_FUNC_ADDRESS_AND_TOKEN_BASED);
                    if (funcIdx >= 0)
                    {
                        // Skip the functions that already have lines
                        while (funcIdx < lines.Length && lines[funcIdx] != null && functions[funcIdx].segment == section && functions[funcIdx].address == addr)
                        {
                            ++funcIdx;
                        }
                        if (funcIdx < lines.Length && functions[funcIdx].segment == section && functions[funcIdx].address == addr)
                        {
                            // We found the correct function index
                            var thisLines = new List <Tuple <Int32, PDBLine> >();
                            // Read line data
                            while (idx < endIdx)
                            {
                                var srcIdx    = array.ReadInt32LEFromBytes(ref idx);
                                var lineCount = array.ReadInt32LEFromBytes(ref idx);
                                // Skip size information
                                idx += INT_SIZE;
                                // Save line and column start indices
                                var lineStartIdx   = idx;
                                var columnStartIdx = idx + 8 * lineCount; // Each line is 2 integers
                                // Iterate each line
                                for (var i = 0; i < lineCount; ++i)
                                {
                                    // Reset index after possible column read
                                    idx = lineStartIdx + LINE_MULTIPLIER * i;
                                    var offset    = array.ReadInt32LEFromBytes(ref idx);
                                    var line      = new PDBLine(offset);
                                    var lineFlags = array.ReadUInt32LEFromBytes(ref idx);
                                    line.LineStart   = (Int32)(lineFlags & 0x00ffffffu);                          // Lower 3 bytes are start line of statement/expression
                                    line.LineEnd     = line.LineStart + (Int32)((lineFlags & 0x7f000000u) >> 24); // High seven bits is delta of line
                                    line.IsStatement = (lineFlags & 0x80000000u) == 0;                            // Highest bit is whether the line is statement
                                    if ((flags & 1) != 0)
                                    {
                                        // Column info present
                                        idx = columnStartIdx + COLUMN_MULTIPLIER * i; // Each column info is two shorts
                                        line.ColumnStart = array.ReadUInt16LEFromBytes(ref idx);
                                        line.ColumnEnd   = array.ReadUInt16LEFromBytes(ref idx);
                                    }
                                    thisLines.Add(Tuple.Create(srcIdx, line));
                                }
                            }
                            lines[funcIdx] = thisLines;
                        }
#if DEBUG
                        else
                        {
                            throw new PDBException("Debyyg");
                        }
#endif
                    }
#if DEBUG
                    else
                    {
                        throw new PDBException("Debyyg");
                    }
#endif
                    break;

                default:
#if DEBUG
                    throw new PDBException("Debyyg");
#else
                    break;
#endif
                }
                idx = endIdx;
            }

            // Postprocess line infos
            for (var i = 0; i < lines.Length; ++i)
            {
                var lineList = lines[i];
                if (lineList != null)
                {
                    foreach (var line in lineList)
                    {
                        functions[i].function.Lines.GetOrAdd_NotThreadSafe(sourcesLocal[line.Item1].Name, ni => new List <PDBLine>())
                        .Add(line.Item2);
                    }
                }
            }
            return(sourcesLocal);
        }
Example #3
0
 public void AddSource(PDBSource source)
 {
     ArgumentValidator.ValidateNotNull("Source", source);
     this._sources.Add(source.Name, source);
 }
Example #4
0
 public Boolean TryGetSource(String sourceName, out PDBSource source)
 {
     return(this._sources.TryGetValue(sourceName, out source));
 }