Exemplo n.º 1
0
        public string GetSymbolNameFromAddress(UInt32 address)
        {
            if (AddressIsInRange(address))
            {
                IDiaSymbol diaSymbol;
                m_session.findSymbolByVA(address, SymTagEnum.SymTagFunction, out diaSymbol);

                IDiaEnumLineNumbers lineNumbers;
                m_session.findLinesByVA(address, 4, out lineNumbers);

                IDiaLineNumber lineNum;
                uint           celt;
                lineNumbers.Next(1, out lineNum, out celt);

                if (celt == 1)
                {
                    string baseFilename = lineNum.sourceFile.fileName.Substring(lineNum.sourceFile.fileName.LastIndexOf('\\') + 1);
                    return(diaSymbol.name + " (" + baseFilename + ":" + lineNum.lineNumber + ")");
                }
                else
                {
                    return(diaSymbol.name);
                }
            }
            else
            {
                return("<address out of range>");
            }
        }
Exemplo n.º 2
0
        public CallStackItem GetSymbolNameFromAddress(UInt32 address)
        {
            CallStackItem result = new CallStackItem();

            if (AddressIsInRange(address))
            {
                IDiaSymbol diaSymbol;
                session.findSymbolByVA(address, SymTagEnum.SymTagFunction, out diaSymbol);

                result.Description = diaSymbol.name + "()";

                IDiaEnumLineNumbers lineNumbers;
                session.findLinesByVA(address, 4, out lineNumbers);

                IDiaLineNumber lineNum;
                uint           celt;
                lineNumbers.Next(1, out lineNum, out celt);

                if (celt == 1)
                {
                    string baseFilename = lineNum.sourceFile.fileName.Substring(lineNum.sourceFile.fileName.LastIndexOf('\\') + 1);
                    result.Source = baseFilename;
                    result.Line   = (int)lineNum.lineNumber;
                }
            }
            else
            {
                result.Description = "<address out of range>";
            }
            return(result);
        }
Exemplo n.º 3
0
Arquivo: Sym.cs Projeto: wflk/EhTrace
        public List <MinSym> EnumSymsInFileWithVAOrder(string arg, ulong BaseVA, ulong Length)
        {
            IDiaSymbol Master = null;
            var        rv     = new List <MinSym>();

            var foo = new Dia2Lib.DiaSource();

            foo.loadDataForExe(arg, SymPath, null);
            foo.openSession(out Session);

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

            Session.loadAddress = BaseVA;

            var    CurrVA = BaseVA;
            var    End    = BaseVA + Length;
            MinSym last   = null;

            do
            {
                Session.findSymbolByVA(CurrVA, SymTagEnum.SymTagNull, out Master);
                var len = Master.length > 0 ? Master.length : 8;


                var s = new MinSym()
                {
                    Address = CurrVA,
                    Length  = len,
                    Name    = Master.name,
                    ID      = Master.symIndexId,
                    UDName  = (!string.IsNullOrWhiteSpace(Master.undecoratedName) && Master.name != Master.undecoratedName) ? Master.undecoratedName : string.Empty,
                };


                if (last != null
                    &&
                    // if the ID is the same
                    ((last.ID == s.ID)
                     ||
                     // also if the name and the last name are empty even if the ID is diff, treat them as the same
                     (string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(last.Name))))
                {
                    // grow the length if the most recent symbol in the list
                    last.Length += s.Length;
                }
                else
                {
                    // otherwise add the new thing to the list
                    rv.Add(s);
                    last = s;
                }

                CurrVA += len;

#if DEBUGGING_STUFF
                /* DEBUGGING
                 * ForegroundColor = ConsoleColor.Cyan;
                 *
                 * Write($"Name: [{Master.name}] Address: [{CurrVA:X}] Length: [{Master.length}] ");
                 * if (string.IsNullOrWhiteSpace(Master.name) && Master.name != Master.undecoratedName)
                 * {
                 *  ForegroundColor = ConsoleColor.White;
                 *  WriteLine($"UDName: [{Master.undecoratedName}]");
                 * }
                 * else
                 *  WriteLine(String.Empty);
                 */
                //foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
                //    WriteLine($"{pr.Name} = {pr.GetValue(Master)}");

                /*
                 * Session.findChildren(Master, SymTagEnum.SymTagNull, null, 0, out EnumSymbols);
                 * if (EnumSymbols == null)
                 *  continue;
                 *
                 * var tot1 = EnumSymbols.count;
                 * int cnt = 0;
                 *
                 * ForegroundColor = ConsoleColor.White;
                 *
                 * do {
                 *  cnt++;
                 *  EnumSymbols.Next(1, out Sub, out compileFetched);
                 *  if (Sub == null)
                 *      continue;
                 *
                 *  WriteLine($"Name: [{Sub.name}] UName: [{Sub.undecoratedName}] Length: [{Sub.length}]");
                 *
                 *  foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
                 *      WriteLine($"{pr.Name} = {pr.GetValue(Sub)}");
                 *  foreach (var fn in typeof(IDiaSymbol).LinqPublicFunctions())
                 *  {
                 *     if (fn.Name.Contains("get"))
                 *      WriteLine($"{fn.Name} = {fn.Invoke(Sub, null)}");
                 *  }
                 * } while (cnt < tot1);
                 */
#endif
            } while (CurrVA < End);

            return(rv);
        }