} //Used for linking managed frame to native frame public UnifiedStackFrame(DEBUG_STACK_FRAME nativeFrame, IDebugSymbols2 debugSymbols) { Type = UnifiedStackFrameType.Native; InstructionPointer = nativeFrame.InstructionOffset; StackPointer = nativeFrame.StackOffset; FramePointer = nativeFrame.FrameOffset; uint moduleIndex; ulong dummy; if (0 != debugSymbols.GetModuleByOffset(InstructionPointer, 0, out moduleIndex, out dummy)) { //Some frames might not have modules associated with them, in which case this //will fail, and of course there is no function associated either. This happens //often with CLR JIT-compiled code. Module = "<Unknown>"; Method = "<Unknown>"; return; } StringBuilder methodName = new StringBuilder(1024); ulong displacement; uint dummy2; Util.VerifyHr(debugSymbols.GetNameByOffset(InstructionPointer, methodName, methodName.Capacity, out dummy2, out displacement)); string[] parts = methodName.ToString().Split('!'); Module = parts[0]; if (parts.Length > 1) { Method = parts[1]; } OffsetInMethod = displacement; uint sourceLine; ulong delta; StringBuilder sourceFile = new StringBuilder(1024); if (0 == debugSymbols.GetLineByOffset(InstructionPointer, out sourceLine, sourceFile, sourceFile.Capacity, out dummy2, out delta)) { SourceFileName = sourceFile.ToString(); SourceLineNumber = sourceLine; SourceLineNumberEnd = sourceLine; } }
public UnifiedStackFrame(DEBUG_STACK_FRAME nativeFrame, IDebugSymbols2 debugSymbols) { FrameOffset = nativeFrame.FrameOffset; Type = UnifiedStackFrameType.Native; InstructionPointer = nativeFrame.InstructionOffset; StackPointer = nativeFrame.StackOffset; uint moduleIndex; ulong dummy; if (0 != debugSymbols.GetModuleByOffset(InstructionPointer, 0, out moduleIndex, out dummy)) { //Some frames might not have modules associated with them, in which case this //will fail, and of course there is no function associated either. This happens //often with CLR JIT-compiled code. Module = "<Unknown>"; Method = "<Unknown>"; return; } StringBuilder methodName = new StringBuilder(1024); ulong displacement; uint dummy2; Util.VerifyHr(debugSymbols.GetNameByOffset(InstructionPointer, methodName, methodName.Capacity, out dummy2, out displacement)); string[] parts = methodName.ToString().Split('!'); Module = parts[0]; if (parts.Length > 1) { Method = parts[1]; } OffsetInMethod = displacement; uint sourceLine; ulong delta; StringBuilder sourceFile = new StringBuilder(1024); if (0 == debugSymbols.GetLineByOffset(InstructionPointer, out sourceLine, sourceFile, sourceFile.Capacity, out dummy2, out delta)) { SourceFileName = sourceFile.ToString(); SourceLineNumber = sourceLine; SourceLineNumberEnd = sourceLine; } }
internal DbgEngController(string dbgengPath, string dumpPath, string sosPath) { Trace.TraceInformation($"DbgEngController: {dbgengPath} {dumpPath} {sosPath}"); _converter = new CharToLineConverter((text) => { Trace.TraceInformation(text); }); IntPtr dbgengLibrary = DataTarget.PlatformFunctions.LoadLibrary(dbgengPath); var debugCreate = SOSHost.GetDelegateFunction <DebugCreateDelegate>(dbgengLibrary, "DebugCreate"); if (debugCreate == null) { throw new DiagnosticsException($"DebugCreate export not found"); } Guid iid = _iidClient; HResult hr = debugCreate(ref iid, out object client); if (hr != HResult.S_OK) { throw new DiagnosticsException($"DebugCreate FAILED {hr:X8}"); } Client = (IDebugClient)client; Control = (IDebugControl)client; Symbols = (IDebugSymbols2)client; hr = Client.SetOutputCallbacks(this); if (hr != HResult.S_OK) { throw new DiagnosticsException($"SetOutputCallbacks FAILED {hr:X8}"); } // Automatically enable/adjust symbol server support. Override the default cache path so // the cache isn't created in the debugger binaries .nuget package cache directory. string cachePath = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMDATA"), "dbg", "sym"); string sympath = $"{Path.GetDirectoryName(dumpPath)};cache*{cachePath};SRV*https://msdl.microsoft.com/download/symbols"; hr = Symbols.SetSymbolPath(sympath); if (hr != HResult.S_OK) { Trace.TraceError($"SetSymbolPath({sympath}) FAILED {hr:X8}"); } // Load dump file hr = Client.OpenDumpFile(dumpPath); if (hr != HResult.S_OK) { throw new DiagnosticsException($"OpenDumpFile({dumpPath} FAILED {hr:X8}"); } ProcessEvents(); // Load the sos extensions hr = Control.Execute(DEBUG_OUTCTL.ALL_CLIENTS, $".load {sosPath}", DEBUG_EXECUTE.DEFAULT); if (hr != HResult.S_OK) { throw new DiagnosticsException($"Loading {sosPath} FAILED {hr:X8}"); } // Initialize the extension host hr = HostServices.Initialize(sosPath); if (hr != HResult.S_OK) { throw new DiagnosticsException($"HostServices.Initialize({sosPath}) FAILED {hr:X8}"); } var symbolService = Host.Services.GetService <ISymbolService>(); Trace.TraceInformation($"SymbolService: {symbolService}"); }