Beispiel #1
0
        public bool LookupSymbol(ulong address, out SymbolInfo sym)
        {
            sym.FileName   = "";
            sym.LineNumber = 0;
            sym.Symbol     = "";
            sym.Address    = address;

            DbgHelpNative.SYMBOL_INFO data = new DbgHelpNative.SYMBOL_INFO();
            data.SizeOfStruct = (uint)Marshal.SizeOf(data) - 1024;
            data.MaxNameLen   = 1024;

            ulong displacement;

            if (DbgHelpNative.SymFromAddr(m_Handle, address, out displacement, ref data))
            {
                sym.Symbol = data.Name;
            }
            else
            {
                return(false);
            }

            DbgHelpNative.IMAGEHLP_LINE64 line = new DbgHelpNative.IMAGEHLP_LINE64();
            line.SizeOfStruct = (uint)Marshal.SizeOf(line);

            uint disp32;

            if (DbgHelpNative.SymGetLineFromAddr64(m_Handle, address, out disp32, ref line))
            {
                StringBuilder fn = new StringBuilder(128);
                for (int i = 0; ; ++i)
                {
                    byte b = Marshal.ReadByte(IntPtr.Add(line.FileName, i));
                    if (0 == b)
                    {
                        break;
                    }
                    fn.Append((char)b);
                }

                sym.FileName   = fn.ToString();
                sym.LineNumber = (int)line.LineNumber;
            }
            else
            {
                sym.FileName = "(no source)";
            }

            return(true);
        }
Beispiel #2
0
    public bool LookupSymbol(ulong address, out SymbolInfo sym)
    {
      sym.FileName = "";
      sym.LineNumber = 0;
      sym.Symbol = "";
      sym.Address = address;

      DbgHelpNative.SYMBOL_INFO data = new DbgHelpNative.SYMBOL_INFO();
      data.SizeOfStruct = (uint) Marshal.SizeOf(data) - 1024;
      data.MaxNameLen = 1024;

      ulong displacement;
      if (DbgHelpNative.SymFromAddr(m_Handle, address, out displacement, ref data))
      {
        sym.Symbol = data.Name;
      }
      else
      {
        return false;
      }

      DbgHelpNative.IMAGEHLP_LINE64 line = new DbgHelpNative.IMAGEHLP_LINE64();
      line.SizeOfStruct = (uint) Marshal.SizeOf(line);

      uint disp32;

      if (DbgHelpNative.SymGetLineFromAddr64(m_Handle, address, out disp32, ref line))
      {
        StringBuilder fn = new StringBuilder(128);
        for (int i = 0; ; ++i)
        {
          byte b = Marshal.ReadByte(IntPtr.Add(line.FileName, i));
          if (0 == b)
            break;
          fn.Append((char)b);
        }

        sym.FileName = fn.ToString();
        sym.LineNumber = (int) line.LineNumber;
      }
      else
      {
        sym.FileName = "(no source)";
      }

      return true;
    }