/// <summary> /// Constructor /// </summary> /// <param name="method">Method</param> /// <param name="locals">Locals or null</param> public MethodDebugInfoBuilder(MethodDef method, SourceLocal[] locals = null) { if (method == null) throw new ArgumentNullException(nameof(method)); this.method = method; statements = new List<SourceStatement>(); this.locals = locals ?? Array.Empty<SourceLocal>(); }
public void GetMethodInfo(ModuleTokenId key, out Parameter[] parameters, out Local[] locals, out SourceLocal[] decompilerLocals) { parameters = null; locals = null; decompilerLocals = null; foreach (var tab in documentTabService.VisibleFirstTabs) { if (parameters != null && decompilerLocals != null) break; var uiContext = tab.UIContext as IDocumentViewer; var methodDebugService = uiContext.TryGetMethodDebugService(); if (methodDebugService == null) continue; var info = methodDebugService.TryGetMethodDebugInfo(key); if (info == null) continue; var method = info.Method; if (info.Locals.Length != 0 && method.Body != null) { locals = method.Body.Variables.ToArray(); decompilerLocals = new SourceLocal[method.Body.Variables.Count]; foreach (var v in info.Locals) { if ((uint)v.Local.Index >= decompilerLocals.Length) continue; decompilerLocals[v.Local.Index] = v; } } parameters = method.Parameters.ToArray(); } }
/// <summary> /// Constructor /// </summary> /// <param name="method">Method</param> /// <param name="statements">Statements</param> /// <param name="locals">Locals</param> /// <param name="methodSpan">Method span or null to calculate it from <paramref name="statements"/></param> public MethodDebugInfo(MethodDef method, SourceStatement[] statements, SourceLocal[] locals, TextSpan? methodSpan) { if (method == null) throw new ArgumentNullException(nameof(method)); if (statements == null) throw new ArgumentNullException(nameof(statements)); if (locals == null) throw new ArgumentNullException(nameof(locals)); Method = method; if (statements.Length > 1) Array.Sort(statements, SourceStatement.SpanStartComparer); Statements = statements; Locals = locals; Span = methodSpan ?? CalculateMethodSpan(statements) ?? new TextSpan(0, 0); }