/// <summary> /// Returns source name, line numbers and IL offsets for given method token. Used by the GDBJIT support. /// </summary> /// <param name="assemblyPath">file path of the assembly</param> /// <param name="methodToken">method token</param> /// <param name="debugInfo">structure with debug information return</param> /// <returns>true if information is available</returns> /// <remarks>used by the gdb JIT support (not SOS). Does not support in-memory PEs or PDBs</remarks> internal static bool GetInfoForMethod(string assemblyPath, int methodToken, ref MethodDebugInfo debugInfo) { try { List <DebugInfo> points = null; List <LocalVarInfo> locals = null; if (!GetDebugInfoForMethod(assemblyPath, methodToken, out points)) { return(false); } if (!GetLocalsInfoForMethod(assemblyPath, methodToken, out locals)) { return(false); } var structSize = Marshal.SizeOf <DebugInfo>(); debugInfo.size = points.Count; var ptr = debugInfo.points; foreach (var info in points) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)(ptr.ToInt64() + structSize); } structSize = Marshal.SizeOf <LocalVarInfo>(); debugInfo.localsSize = locals.Count; ptr = debugInfo.locals; foreach (var info in locals) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)(ptr.ToInt64() + structSize); } return(true); } catch { } return(false); }
private EvaluationContext( MethodContextReuseConstraints?methodContextReuseConstraints, CSharpCompilation compilation, MethodSymbol currentFrame, ImmutableArray <LocalSymbol> locals, ImmutableSortedSet <int> inScopeHoistedLocalSlots, MethodDebugInfo <TypeSymbol, LocalSymbol> methodDebugInfo) { Debug.Assert(inScopeHoistedLocalSlots != null); Debug.Assert(methodDebugInfo != null); this.MethodContextReuseConstraints = methodContextReuseConstraints; this.Compilation = compilation; _currentFrame = currentFrame; _locals = locals; _inScopeHoistedLocalSlots = inScopeHoistedLocalSlots; _methodDebugInfo = methodDebugInfo; }
private EvaluationContext( MethodContextReuseConstraints?methodContextReuseConstraints, CSharpCompilation compilation, MetadataDecoder metadataDecoder, MethodSymbol currentFrame, ImmutableArray <LocalSymbol> locals, InScopeHoistedLocals inScopeHoistedLocals, MethodDebugInfo methodDebugInfo) { Debug.Assert(inScopeHoistedLocals != null); this.MethodContextReuseConstraints = methodContextReuseConstraints; this.Compilation = compilation; _metadataDecoder = metadataDecoder; _currentFrame = currentFrame; _locals = locals; _inScopeHoistedLocals = inScopeHoistedLocals; _methodDebugInfo = methodDebugInfo; }
private EvaluationContext( MethodContextReuseConstraints?methodContextReuseConstraints, CSharpCompilation compilation, MethodSymbol currentFrame, MethodSymbol?currentSourceMethod, ImmutableArray <LocalSymbol> locals, ImmutableSortedSet <int> inScopeHoistedLocalSlots, MethodDebugInfo <TypeSymbol, LocalSymbol> methodDebugInfo) { RoslynDebug.AssertNotNull(inScopeHoistedLocalSlots); RoslynDebug.AssertNotNull(methodDebugInfo); MethodContextReuseConstraints = methodContextReuseConstraints; Compilation = compilation; _currentFrame = currentFrame; _currentSourceMethod = currentSourceMethod; _locals = locals; _inScopeHoistedLocalSlots = inScopeHoistedLocalSlots; _methodDebugInfo = methodDebugInfo; }
/// <summary> /// Returns source name, line numbers and IL offsets for given method token. /// </summary> /// <param name="assemblyPath">file path of the assembly</param> /// <param name="methodToken">method token</param> /// <param name="debugInfo">structure with debug information return</param> /// <returns>true if information is available</returns> /// <remarks>used by the gdb JIT support (not SOS). Does not support in-memory PEs or PDBs</remarks> internal static bool GetInfoForMethod(string assemblyPath, int methodToken, ref MethodDebugInfo debugInfo) { try { List <DebugInfo> points = null; List <string> locals = null; if (!GetDebugInfoForMethod(assemblyPath, methodToken, out points)) { return(false); } if (!GetLocalsInfoForMethod(assemblyPath, methodToken, out locals)) { return(false); } var structSize = Marshal.SizeOf <DebugInfo>(); debugInfo.size = points.Count; var ptr = debugInfo.points; foreach (var info in points) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)(ptr.ToInt64() + structSize); } debugInfo.localsSize = locals.Count; debugInfo.locals = Marshal.AllocHGlobal(debugInfo.localsSize * Marshal.SizeOf <IntPtr>()); IntPtr ptrLocals = debugInfo.locals; foreach (string s in locals) { Marshal.WriteIntPtr(ptrLocals, Marshal.StringToHGlobalUni(s)); ptrLocals += Marshal.SizeOf <IntPtr>(); } return(true); } catch { } return(false); }
private EvaluationContext( ImmutableArray <MetadataBlock> metadataBlocks, MethodScope methodScope, CSharpCompilation compilation, MetadataDecoder metadataDecoder, MethodSymbol currentFrame, ImmutableArray <LocalSymbol> locals, ImmutableSortedSet <int> inScopeHoistedLocalIndices, MethodDebugInfo methodDebugInfo) { Debug.Assert(inScopeHoistedLocalIndices != null); this.MetadataBlocks = metadataBlocks; this.MethodScope = methodScope; this.Compilation = compilation; _metadataDecoder = metadataDecoder; _currentFrame = currentFrame; _locals = locals; _inScopeHoistedLocalIndices = inScopeHoistedLocalIndices; _methodDebugInfo = methodDebugInfo; }
void AddDebugInfo(MethodDebugInfo info) { if (info == null) { return; } if (methodSourceStatement == null) { return; } if (methodSourceStatement.Value.Method != reference) { return; } var stmt = info.GetSourceStatementByCodeOffset(methodSourceStatement.Value.Statement.BinSpan.Start); if (stmt == null) { return; } statementSpan = new Span(stmt.Value.TextSpan.Start, stmt.Value.TextSpan.Length); }
private void Initialize(ConstructorInfo ci, bool loadDebugInfo) { Module = ci.Module; Type = ci.DeclaringType; Method = ci; // todo. do we need to dispose the reader? var pdb = loadDebugInfo ? ci.GetSymReader() : null; if (pdb != null) { DebugInfo = new MethodDebugInfo(this, pdb); } Locals = ci.GetMethodBody().LocalVariables.Select(lv => new LocalVar(this, lv)).ToReadOnly(); Args = ci.GetParameters().ToReadOnly(); Ret = null; var body = ci.GetMethodBody(); ParseIL(body.GetILAsByteArray(), body.ExceptionHandlingClauses); }
/// <summary> /// Returns source name, line numbers and IL offsets for given method token. /// </summary> /// <param name="assemblyPath">file path of the assembly</param> /// <param name="methodToken">method token</param> /// <param name="debugInfo">structure with debug information return</param> /// <returns>true if information is available</returns> /// <remarks>used by the gdb JIT support (not SOS). Does not support in-memory PEs or PDBs</remarks> internal static bool GetInfoForMethod(string assemblyPath, int methodToken, ref MethodDebugInfo debugInfo) { try { List<DebugInfo> points = null; if (!GetDebugInfoForMethod(assemblyPath, methodToken, out points)) { return false; } var structSize = Marshal.SizeOf<DebugInfo>(); debugInfo.size = points.Count; var ptr = debugInfo.points; foreach (var info in points) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)(ptr.ToInt64() + structSize); } return true; } catch { } return false; }
public GetMethodDebugInfoResult(MethodDebugInfo debugInfo, MethodDebugInfo stateMachineDebugInfoOrNull) { DebugInfoOrNull = debugInfo; StateMachineDebugInfoOrNull = stateMachineDebugInfoOrNull; }
/// <summary> /// Returns source name, line numbers and IL offsets for given method token. /// </summary> /// <param name="assemblyFileName">file name of the assembly</param> /// <param name="methToken">method token</param> /// <param name="debugInfo">structure with debug information return</param> /// <returns> true if information is available</returns> public static bool GetInfoForMethod(string assemblyFileName, int methodToken, ref MethodDebugInfo debugInfo) { List <DebugInfo> points = null; if (!GetDebugInfoForMethod(assemblyFileName, methodToken, out points)) { return(false); } var structSize = Marshal.SizeOf <DebugInfo>(); debugInfo.size = points.Count; var ptr = debugInfo.points; foreach (var info in points) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)((int)ptr + structSize); } return(true); }
/// <summary> /// Returns source name, line numbers and IL offsets for given method token. /// </summary> /// <param name="assemblyPath">file path of the assembly</param> /// <param name="methodToken">method token</param> /// <param name="debugInfo">structure with debug information return</param> /// <returns>true if information is available</returns> /// <remarks>used by the gdb JIT support (not SOS). Does not support in-memory PEs or PDBs</remarks> internal static bool GetInfoForMethod(string assemblyPath, int methodToken, ref MethodDebugInfo debugInfo) { try { List<DebugInfo> points = null; List<string> locals = null; if (!GetDebugInfoForMethod(assemblyPath, methodToken, out points)) { return false; } if (!GetLocalsInfoForMethod(assemblyPath, methodToken, out locals)) { return false; } var structSize = Marshal.SizeOf<DebugInfo>(); debugInfo.size = points.Count; var ptr = debugInfo.points; foreach (var info in points) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)(ptr.ToInt64() + structSize); } debugInfo.localsSize = locals.Count; debugInfo.locals = Marshal.AllocHGlobal(debugInfo.localsSize * Marshal.SizeOf<IntPtr>()); IntPtr ptrLocals = debugInfo.locals; foreach (string s in locals) { Marshal.WriteIntPtr(ptrLocals, Marshal.StringToHGlobalUni(s)); ptrLocals += Marshal.SizeOf<IntPtr>(); } return true; } catch { } return false; }
public MethodDebugInfoResult(MethodDebugInfo debugInfo, MethodDebugInfo stateMachineDebugInfoOrNull, uint localVarSigTok) { DebugInfoOrNull = debugInfo; StateMachineDebugInfoOrNull = stateMachineDebugInfoOrNull; LocalVarSigTok = localVarSigTok; }
public static DbgMethodDebugInfo ToDbgMethodDebugInfo(MethodDebugInfo debugInfo) => new DbgMethodDebugInfo(ToCompiler(debugInfo.CompilerName), debugInfo.DecompilerSettingsVersion, debugInfo.Method, ToParameters(debugInfo.Parameters), ToSourceStatements(debugInfo.Statements), ToScope(debugInfo.Scope), ToAsyncMethodDebugInfo(debugInfo.AsyncInfo));
/// <summary> /// Returns source name, line numbers and IL offsets for given method token. /// </summary> /// <param name="assemblyFileName">file name of the assembly</param> /// <param name="methToken">method token</param> /// <param name="debugInfo">structure with debug information return</param> /// <returns> true if information is available</returns> public static bool GetInfoForMethod(string assemblyFileName, int methodToken, ref MethodDebugInfo debugInfo) { List<DebugInfo> points = null; if (!GetDebugInfoForMethod(assemblyFileName, methodToken, out points)) { return false; } var structSize = Marshal.SizeOf<DebugInfo>(); debugInfo.size = points.Count; var ptr = debugInfo.points; foreach (var info in points) { Marshal.StructureToPtr(info, ptr, false); ptr = (IntPtr)((int)ptr + structSize); } return true; }
DbgLanguageDebugInfo CreateDebugInfo(DbgEvaluationContext context, IDbgDotNetCodeLocation location, CancellationToken cancellationToken) { const DbgLoadModuleOptions options = DbgLoadModuleOptions.AutoLoaded; ModuleDef mdModule; if (location.DbgModule is DbgModule dbgModule) { mdModule = dbgMetadataService.TryGetMetadata(dbgModule, options); } else { dbgModule = null; mdModule = dbgMetadataService.TryGetMetadata(location.Module, options); } Debug.Assert(mdModule != null); if (mdModule == null) { return(null); } cancellationToken.ThrowIfCancellationRequested(); var method = mdModule.ResolveToken(location.Token) as MethodDef; // Could be null if it's a dynamic assembly. It will get refreshed later and we'll get called again. if (method == null) { return(null); } var runtime = context.Runtime.GetDotNetRuntime(); int methodToken, localVarSigTok; if (dbgModule == null || !runtime.TryGetMethodToken(dbgModule, method.MDToken.ToInt32(), out methodToken, out localVarSigTok)) { methodToken = method.MDToken.ToInt32(); localVarSigTok = (int)(method.Body?.LocalVarSigTok ?? 0); } var decContext = new DecompilationContext { CancellationToken = cancellationToken, CalculateBinSpans = true, }; var output = DecompilerOutputImplCache.Alloc(); output.Initialize(method.MDToken.Raw); //TODO: Whenever the decompiler options change, we need to invalidate our cache and every // single DbgLanguageDebugInfo instance. decompiler.Decompile(method, output, decContext); var methodDebugInfo = output.TryGetMethodDebugInfo(); DecompilerOutputImplCache.Free(ref output); cancellationToken.ThrowIfCancellationRequested(); if (methodDebugInfo == null && method.Body == null) { var scope = new MethodDebugScope(new BinSpan(0, 0), Array.Empty <MethodDebugScope>(), Array.Empty <SourceLocal>(), Array.Empty <ImportInfo>(), Array.Empty <MethodDebugConstant>()); methodDebugInfo = new MethodDebugInfo(-1, method, Array.Empty <SourceStatement>(), scope, null); } if (methodDebugInfo == null) { return(null); } // We don't support EnC so the version is always 1 const int methodVersion = 1; return(new DbgLanguageDebugInfo(methodDebugInfo, methodToken, localVarSigTok, methodVersion, location.Offset)); }
public ILSourceStatementProvider(string text, MethodDebugInfo debugInfo) { this.text = text ?? throw new ArgumentNullException(nameof(text)); this.debugInfo = debugInfo ?? throw new ArgumentNullException(nameof(debugInfo)); }