Exemple #1
0
        private IEnumerable <SourceFile> CreateSourceFileIteratorImpl(IDiaSymbol inObjectModule)
        {
            IDiaEnumSourceFiles sourceFilesEnum = null;

            try
            {
                _session.findFile(inObjectModule, null, 0, out sourceFilesEnum);

                while (true)
                {
                    uint           celt;
                    IDiaSourceFile sourceFile = null;
                    sourceFilesEnum.Next(1, out sourceFile, out celt);
                    if (celt != 1)
                    {
                        break;
                    }

                    yield return(new SourceFile(sourceFile));
                }
            }
            finally
            {
                if (sourceFilesEnum != null)
                {
                    Marshal.ReleaseComObject(sourceFilesEnum);
                }
            }
        }
Exemple #2
0
        private DiaNavigationData GetSymbolNavigationData(IDiaSymbol symbol)
        {
            ValidateArg.NotNull(symbol, "symbol");

            DiaNavigationData navigationData = new DiaNavigationData(null, int.MaxValue, int.MinValue);

            IDiaEnumLineNumbers lines = null;

            try
            {
                this.session.findLinesByAddr(symbol.addressSection, symbol.addressOffset, (uint)symbol.length, out lines);

                uint           celt;
                IDiaLineNumber lineNumber;

                while (true)
                {
                    lines.Next(1, out lineNumber, out celt);

                    if (celt != 1)
                    {
                        break;
                    }

                    IDiaSourceFile sourceFile = null;
                    try
                    {
                        sourceFile = lineNumber.sourceFile;

                        // The magic hex constant below works around weird data reported from GetSequencePoints.
                        // The constant comes from ILDASM's source code, which performs essentially the same test.
                        const uint Magic = 0xFEEFEE;
                        if (lineNumber.lineNumber >= Magic || lineNumber.lineNumberEnd >= Magic)
                        {
                            continue;
                        }

                        navigationData.FileName      = sourceFile.fileName;
                        navigationData.MinLineNumber = Math.Min(navigationData.MinLineNumber, (int)lineNumber.lineNumber);
                        navigationData.MaxLineNumber = Math.Max(navigationData.MaxLineNumber, (int)lineNumber.lineNumberEnd);
                    }
                    finally
                    {
                        ReleaseComObject(ref sourceFile);
                        ReleaseComObject(ref lineNumber);
                    }
                }
            }
            finally
            {
                ReleaseComObject(ref lines);
            }

            return(navigationData);
        }
Exemple #3
0
 /// <summary>
 /// Constructs a wrapper object around an <see cref="IDiaSourceFile"/> instance.
 /// </summary>
 /// <param name="source">The COM RCW for the IDiaSourceFile. This instance takes ownership of the
 /// RCW.</param>
 public SourceFile(IDiaSourceFile source)
 {
     _hashBytes = new Lazy<byte[]>(GetHash);
     _sourceFile = source;
 }
Exemple #4
0
        unsafe internal SourceFile(SymbolModule module, IDiaSourceFile sourceFile)
        {
            _symbolModule = module;
            BuildTimeFilePath = sourceFile.fileName;

            // 0 No checksum present.
            // 1 CALG_MD5 checksum generated with the MD5 hashing algorithm.
            // 2 CALG_SHA1 checksum generated with the SHA1 hashing algorithm.
            _hashType = sourceFile.checksumType;
            if (_hashType != 1 && _hashType != 0)
            {
                // TODO does anyone use SHA1?   
                Debug.Assert(false, "Unknown hash type");
                _hashType = 0;
            }
            if (_hashType != 0)
            {
                // MD5 is 16 bytes
                // SHA1 is 20 bytes  
                _hash = new byte[16];

                uint bytesFetched;
                fixed (byte* bufferPtr = _hash)
                    sourceFile.get_checksum((uint)_hash.Length, out bytesFetched, out *bufferPtr);
                Debug.Assert(bytesFetched == 16);
            }
        }
Exemple #5
0
        private DiaNavigationData GetSymbolNavigationData(IDiaSymbol symbol)
        {
            ValidateArg.NotNull(symbol, "symbol");

            DiaNavigationData navigationData = new DiaNavigationData(null, int.MaxValue, int.MinValue);

            IDiaEnumLineNumbers lines = null;

            try
            {
                // Get the address section
                if (HResult.Failed(symbol.GetAddressSection(out uint section)))
                {
                    return(navigationData);
                }

                // Get the address offset
                if (HResult.Failed(symbol.GetAddressOffset(out uint offset)))
                {
                    return(navigationData);
                }

                // Get the length of the symbol
                if (HResult.Failed(symbol.GetLength(out long length)))
                {
                    return(navigationData);
                }

                this.session.FindLinesByAddress(section, offset, (uint)length, out lines);

                while (true)
                {
                    lines.GetNext(1, out IDiaLineNumber lineNumber, out uint celt);

                    if (celt != 1)
                    {
                        break;
                    }

                    IDiaSourceFile sourceFile = null;
                    try
                    {
                        lineNumber.GetSourceFile(out sourceFile);

                        // Get startline
                        lineNumber.GetLineNumber(out uint startLine);

                        // Get endline
                        lineNumber.GetLineNumberEnd(out uint endLine);

                        // The magic hex constant below works around weird data reported from GetSequencePoints.
                        // The constant comes from ILDASM's source code, which performs essentially the same test.
                        const uint Magic = 0xFEEFEE;
                        if (startLine >= Magic || endLine >= Magic)
                        {
                            continue;
                        }

                        sourceFile.GetFilename(out var srcFileName);

                        navigationData.FileName      = srcFileName;
                        navigationData.MinLineNumber = Math.Min(navigationData.MinLineNumber, (int)startLine);
                        navigationData.MaxLineNumber = Math.Max(navigationData.MaxLineNumber, (int)endLine);
                    }
                    finally
                    {
                        ReleaseComObject(ref sourceFile);
                        ReleaseComObject(ref lineNumber);
                    }
                }
            }
            finally
            {
                ReleaseComObject(ref lines);
            }

            return(navigationData);
        }
Exemple #6
0
 /// <summary>
 /// Constructs a wrapper object around an <see cref="IDiaSourceFile"/> instance.
 /// </summary>
 /// <param name="source">The COM RCW for the IDiaSourceFile. This instance takes ownership of the
 /// RCW.</param>
 public SourceFile(IDiaSourceFile source)
 {
     this.hashBytes  = new Lazy <byte[]>(this.GetHash);
     this.sourceFile = source;
 }
Exemple #7
0
 /// <summary>
 /// Constructs a wrapper object around an <see cref="IDiaSourceFile"/> instance.
 /// </summary>
 /// <param name="source">The COM RCW for the IDiaSourceFile. This instance takes ownership of the
 /// RCW.</param>
 public SourceFile(IDiaSourceFile source)
 {
     _hashBytes  = new Lazy <byte[]>(GetHash);
     _sourceFile = source;
 }
Exemple #8
0
        public static string GetMethodName(IDiaSession pdbSession, uint rva)
        {
            IDiaSymbol funcSym;

            pdbSession.findSymbolByRVA(rva, SymTagEnum.SymTagFunction, out funcSym);
            if (funcSym == null)
            {
                pdbSession.findSymbolByRVA(rva, SymTagEnum.SymTagPublicSymbol, out funcSym);
            }

            if (funcSym == null)
            {
                return(null);
            }

            StringBuilder methodNameStr = new StringBuilder();

            // Append the method-name
            methodNameStr.Append(funcSym.GetUndecoratedNameEx(UndName.DebuggerInternal));

            // Append the offset of current instruction inside method
            methodNameStr.Append("+0x");
            methodNameStr.Append(Convert.ToString(rva - funcSym.GetRelativeVirtualAddress(), 16));

            // Append the source line
            IDiaEnumLineNumbers lines      = null;
            IDiaSourceFile      sourceFile = null;

            pdbSession.findLinesByRVA(rva, 1, out lines);
            int i;

            if (lines != null && lines.count == 1)
            {
                IDiaLineNumber line = lines.Item(0);
                if (line != null)
                {
                    sourceFile = line.SourceFile;
                    methodNameStr.Append(" (");
                    methodNameStr.Append(sourceFile.FileName);
                    methodNameStr.Append(", line ");
                    methodNameStr.Append(line.LineNumber);
                    methodNameStr.Append(")");

                    i = Marshal.ReleaseComObject(line);
                    if (i != 0)
                    {
                        Console.WriteLine("RefCount(funcSym) == {0}", i);
                    }
                }
            }
            i = Marshal.ReleaseComObject(funcSym);
            if (i != 0)
            {
                Console.WriteLine("RefCount(funcSym) == {0}", i);
            }
            if (lines != null)
            {
                if (sourceFile != null)
                {
                    i = Marshal.ReleaseComObject(sourceFile);
                    if (i != 0)
                    {
                        Console.WriteLine("RefCount(sourceFile) == {0}", i);
                    }
                }
                // line?
                i = Marshal.ReleaseComObject(lines);
                if (i != 0)
                {
                    Console.WriteLine("RefCount(lines) == {0}", i);
                }
            }

            //return funcSym.GetName();
            return(methodNameStr.ToString());
        }