private bool EnumSymbolsCallback(ref NativeMethods.SYMBOL_INFO symInfo, uint symbolSize, IntPtr contextZero) { var si = new SymbolInfo() { Address = symInfo.Address, FileName = "", LineNumber = 0, Name = symInfo.Name }; // get the line NativeMethods.IMAGEHLP_LINE64 line = new NativeMethods.IMAGEHLP_LINE64(); line.SizeOfStruct = (uint)Marshal.SizeOf(line); ulong addr = si.Address; uint disp32; if (NativeMethods.SymGetLineFromAddr64(_libHandle, addr, 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); } si.FileName = fn.ToString(); si.LineNumber = (int)line.LineNumber; _symbolCache.Add(si); } else { si.FileName = "(no source)"; } return true; }
public bool LookupSymbol(string name, out SymbolInfo symbolInfo) { LastErrorMessage = string.Empty; symbolInfo = new SymbolInfo(); if ((_symbolCache == null) || (_symbolCache.Count == 0)) { if (!EnumerateAllSymbols()) return false; } var symbols = _symbolCache.Where(s => s.Name.Contains(name)); if (!symbols.Any()) { return false; } symbolInfo = symbols.OrderBy(s => s.Address).First(); return true; }
/// <summary> /// Determines whether or not ths symbol has source information. /// </summary> /// <param name="symbol">The symbol to test for source/line information.</param> /// <returns>true if the provided symbol has source/line information; false otherwise.</returns> private static bool HasSourceInformation(SymbolInfo symbol) { return (symbol.LineNumber != _noLineNumber); }
/// <summary> /// Update the provided symbol with source/line information. /// </summary> /// <param name="symbol">The symbol to update.</param> private void UpdateLineInformation(SymbolInfo symbol) { // get the line NativeMethods.IMAGEHLP_LINE64 line = new NativeMethods.IMAGEHLP_LINE64(); line.SizeOfStruct = (uint)Marshal.SizeOf(line); uint disp32; if (NativeMethods.SymGetLineFromAddr64(_libHandle, symbol.Address, out disp32, ref line)) { symbol.FileName = Marshal.PtrToStringAnsi(line.FileName); symbol.LineNumber = (int)line.LineNumber; } }
private bool EnumSymbolsCallback(ref NativeMethods.SYMBOL_INFO symInfo, uint symbolSize, IntPtr contextZero) { var si = new SymbolInfo() { Address = symInfo.Address, FileName = _fileNameNoSource, LineNumber = _noLineNumber, Name = symInfo.Name }; _symbolCache[si.Name] = si; return true; }