Exemple #1
0
        /// <summary>
        /// Converts <see cref="IDiaEnumLineNumbers"/> container to <see cref="IEnumerable{IDiaLineNumber}"/>.
        /// </summary>
        /// <param name="container">The container.</param>
        public static IEnumerable <IDiaLineNumber> Enum(this IDiaEnumLineNumbers container)
        {
            IDiaLineNumber[] tempLineNumbers = new IDiaLineNumber[1];
            container.Reset();
            while (true)
            {
                uint count;

                container.Next((uint)tempLineNumbers.Length, tempLineNumbers, out count);
                if (count == 0)
                {
                    break;
                }
                yield return(tempLineNumbers[0]);
            }
        }
Exemple #2
0
 internal SourceLocation(IDiaLineNumber source)
 {
     _source = source;
 }
Exemple #3
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());
        }