Skip to content

Commit

Permalink
Remove some code
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Jan 12, 2019
1 parent b6feb78 commit 1ff7c7b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 79 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ You should have received a copy of the GNU General Public License
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using dnlib.DotNet;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.DotNet.Code;
using dnSpy.Contracts.Debugger.DotNet.Metadata;
Expand All @@ -33,6 +32,10 @@ You should have received a copy of the GNU General Public License
using dnSpy.Debugger.DotNet.UI;

namespace dnSpy.Debugger.DotNet.Code {
abstract class DbgDotNetDebugInfoService {
public abstract Task<MethodDebugInfoResult> GetMethodDebugInfoAsync(DbgModule module, uint token);
}

[Export(typeof(DbgDotNetDebugInfoService))]
sealed class DbgDotNetDebugInfoServiceImpl : DbgDotNetDebugInfoService {
readonly UIDispatcher uiDispatcher;
Expand All @@ -54,26 +57,26 @@ sealed class DbgDotNetDebugInfoServiceImpl : DbgDotNetDebugInfoService {

void UI(Action callback) => uiDispatcher.UI(callback);

public override Task<GetMethodDebugInfoResult> GetMethodDebugInfoAsync(DbgModule module, uint token, uint offset) {
public override Task<MethodDebugInfoResult> GetMethodDebugInfoAsync(DbgModule module, uint token) {
if (module == null)
throw new ArgumentNullException(nameof(module));
var tcs = new TaskCompletionSource<GetMethodDebugInfoResult>();
UI(() => GetMethodDebugInfo_UI(module, token, offset, tcs));
var tcs = new TaskCompletionSource<MethodDebugInfoResult>();
UI(() => GetMethodDebugInfo_UI(module, token, tcs));
return tcs.Task;
}

void GetMethodDebugInfo_UI(DbgModule module, uint token, uint offset, TaskCompletionSource<GetMethodDebugInfoResult> tcs) {
void GetMethodDebugInfo_UI(DbgModule module, uint token, TaskCompletionSource<MethodDebugInfoResult> tcs) {
uiDispatcher.VerifyAccess();
try {
var info = TryGetMethodDebugInfo_UI(module, token, offset);
var info = TryGetMethodDebugInfo_UI(module, token);
tcs.SetResult(info);
}
catch (Exception ex) {
tcs.SetException(ex);
}
}

GetMethodDebugInfoResult TryGetMethodDebugInfo_UI(DbgModule module, uint token, uint offset) {
MethodDebugInfoResult TryGetMethodDebugInfo_UI(DbgModule module, uint token) {
uiDispatcher.VerifyAccess();
var tab = documentTabService.Value.GetOrCreateActiveTab();
var documentViewer = tab.TryGetDocumentViewer();
Expand All @@ -82,36 +85,24 @@ GetMethodDebugInfoResult TryGetMethodDebugInfo_UI(DbgModule module, uint token,
if (moduleId == null)
return default;

uint refNavOffset;
if (offset == DbgDotNetInstructionOffsetConstants.EPILOG) {
refNavOffset = DotNetReferenceNavigator.EPILOG;
var mod = dbgMetadataService.TryGetMetadata(module, DbgLoadModuleOptions.AutoLoaded);
if (mod?.ResolveToken(token) is MethodDef md && md.Body != null && md.Body.Instructions.Count > 0)
offset = md.Body.Instructions[md.Body.Instructions.Count - 1].Offset;
else
return default;
}
else if (offset == DbgDotNetInstructionOffsetConstants.PROLOG) {
refNavOffset = DotNetReferenceNavigator.PROLOG;
offset = 0;
}
else
refNavOffset = offset;

var key = new ModuleTokenId(moduleId.Value, token);
var decompilerDebugInfo = methodDebugService.TryGetMethodDebugInfo(key);
DbgMethodDebugInfo debugInfo;
DbgMethodDebugInfo stateMachineDebugInfoOrNull = null;
if (decompilerDebugInfo != null)
int methodVersion;
if (decompilerDebugInfo != null) {
methodVersion = 1;
debugInfo = DbgMethodDebugInfoUtils.ToDbgMethodDebugInfo(decompilerDebugInfo);
}
else {
var cancellationToken = CancellationToken.None;
var result = dbgMethodDebugInfoProvider.Value.GetMethodDebugInfo(decompilerService.Value.Decompiler, module, token, cancellationToken);
methodVersion = result.MethodVersion;
debugInfo = result.DebugInfoOrNull;
stateMachineDebugInfoOrNull = result.StateMachineDebugInfoOrNull;
}

return new GetMethodDebugInfoResult(debugInfo, stateMachineDebugInfoOrNull);
return new MethodDebugInfoResult(methodVersion, debugInfo, stateMachineDebugInfoOrNull);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ You should have received a copy of the GNU General Public License
using dnSpy.Decompiler.Utils;

namespace dnSpy.Debugger.DotNet.Code {
struct MethodDebugInfoResult {
readonly struct MethodDebugInfoResult {
public int MethodVersion { get; }
public DbgMethodDebugInfo DebugInfoOrNull { get; }
public DbgMethodDebugInfo StateMachineDebugInfoOrNull { get; }
public uint LocalVarSigTok { get; }
public MethodDebugInfoResult(DbgMethodDebugInfo debugInfo, DbgMethodDebugInfo stateMachineDebugInfoOrNull, uint localVarSigTok) {
public MethodDebugInfoResult(int methodVersion, DbgMethodDebugInfo debugInfo, DbgMethodDebugInfo stateMachineDebugInfoOrNull) {
if (methodVersion < 1)
throw new ArgumentOutOfRangeException(nameof(methodVersion));
MethodVersion = methodVersion;
DebugInfoOrNull = debugInfo;
StateMachineDebugInfoOrNull = stateMachineDebugInfoOrNull;
LocalVarSigTok = localVarSigTok;
}
}

Expand Down Expand Up @@ -157,19 +159,17 @@ MethodDebugInfoResult GetMethodDebugInfoNonCached(IDecompiler decompiler, Module
if (!StateMachineHelpers.TryGetKickoffMethod(method, out var containingMethod))
containingMethod = method;

uint localVarSigTok = method.Body?.LocalVarSigTok ?? 0;

var decContext = new DecompilationContext {
CancellationToken = cancellationToken,
CalculateILSpans = true,
// This is only needed when decompiling more than one body
AsyncMethodBodyDecompilation = false,
};
var info = TryCompileAndGetDebugInfo(decompiler, containingMethod, token, decContext, cancellationToken);
var info = TryDecompileAndGetDebugInfo(decompiler, containingMethod, token, decContext, cancellationToken);
if (info.debugInfo == null && containingMethod != method) {
// The decompiler can't decompile the iterator / async method, try again,
// but only decompile the MoveNext method
info = TryCompileAndGetDebugInfo(decompiler, method, token, decContext, cancellationToken);
info = TryDecompileAndGetDebugInfo(decompiler, method, token, decContext, cancellationToken);
}
if (info.debugInfo == null && method.Body == null) {
var scope = new DbgMethodDebugScope(new DbgILSpan(0, 0), Array.Empty<DbgMethodDebugScope>(), Array.Empty<DbgLocal>(), Array.Empty<DbgImportInfo>());
Expand All @@ -178,7 +178,9 @@ MethodDebugInfoResult GetMethodDebugInfoNonCached(IDecompiler decompiler, Module
if (info.debugInfo == null)
return default;

return new MethodDebugInfoResult(info.debugInfo, info.stateMachineDebugInfoOrNull, localVarSigTok);
// We don't support EnC so the version is always 1
const int methodVersion = 1;
return new MethodDebugInfoResult(methodVersion, info.debugInfo, info.stateMachineDebugInfoOrNull);
}

static class DecompilerOutputImplCache {
Expand All @@ -192,7 +194,7 @@ public static void Free(ref DecompilerOutputImpl inst) {
}
}

(DbgMethodDebugInfo debugInfo, DbgMethodDebugInfo stateMachineDebugInfoOrNull) TryCompileAndGetDebugInfo(IDecompiler decompiler, MethodDef method, uint methodToken, DecompilationContext decContext, CancellationToken cancellationToken) {
(DbgMethodDebugInfo debugInfo, DbgMethodDebugInfo stateMachineDebugInfoOrNull) TryDecompileAndGetDebugInfo(IDecompiler decompiler, MethodDef method, uint methodToken, DecompilationContext decContext, CancellationToken cancellationToken) {
var output = DecompilerOutputImplCache.Alloc();
output.Initialize(methodToken);
decompiler.Decompile(method, output, decContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ sealed class DbgEngineLanguageImpl : DbgEngineLanguage {
public override DbgEngineValueNodeFactory ValueNodeFactory { get; }

readonly DbgMethodDebugInfoProvider dbgMethodDebugInfoProvider;
readonly DbgDotNetExpressionCompiler expressionCompiler;
readonly IDecompiler decompiler;

readonly DbgDotNetExpressionCompiler expressionCompiler;
readonly IDebuggerDisplayAttributeEvaluator debuggerDisplayAttributeEvaluator;

public DbgEngineLanguageImpl(DbgModuleReferenceProvider dbgModuleReferenceProvider, string name, string displayName, DbgDotNetExpressionCompiler expressionCompiler, DbgMethodDebugInfoProvider dbgMethodDebugInfoProvider, IDecompiler decompiler, DbgDotNetFormatter formatter, DbgDotNetEngineValueNodeFactory valueNodeFactory, DbgDotNetILInterpreter dnILInterpreter, DbgAliasProvider dbgAliasProvider, IPredefinedEvaluationErrorMessagesHelper predefinedEvaluationErrorMessagesHelper) {
Expand Down Expand Up @@ -174,12 +175,10 @@ DbgLanguageDebugInfo CreateDebugInfo(DbgEvaluationContext context, IDbgDotNetCod
var runtime = context.Runtime.GetDotNetRuntime();
if (location.DbgModule == null || !runtime.TryGetMethodToken(location.DbgModule, (int)location.Token, out int methodToken, out int localVarSigTok)) {
methodToken = (int)location.Token;
localVarSigTok = (int)result.LocalVarSigTok;
localVarSigTok = (int)((result.StateMachineDebugInfoOrNull ?? result.DebugInfoOrNull)?.Method.Body?.LocalVarSigTok ?? 0);
}

// We don't support EnC so the version is always 1
const int methodVersion = 1;
return new DbgLanguageDebugInfo(result.DebugInfoOrNull, methodToken, localVarSigTok, methodVersion, location.Offset);
return new DbgLanguageDebugInfo(result.DebugInfoOrNull, methodToken, localVarSigTok, result.MethodVersion, location.Offset);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ async Task<GetStepRangesAsyncResult> GetStepRangesAsync(DbgDotNetEngineStepperFr
throw new StepErrorException("Internal error");

uint continueCounter = stepper.ContinueCounter;
var info = await dbgDotNetDebugInfoService.GetMethodDebugInfoAsync(module, token, offset);
var info = await dbgDotNetDebugInfoService.GetMethodDebugInfoAsync(module, token);
if (continueCounter != stepper.ContinueCounter)
throw new StepErrorException("Internal error");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public interface IX86DisassemblySettings : INotifyPropertyChanged {
bool SmallHexNumbersInDecimal { get; set; }

/// <summary>
/// Add a leading zero to numbers if there's no prefix and the number begins with hex digits A-F, eg. Ah vs 0Ah
/// Add a leading zero to numbers if there's no prefix and the number starts with hex digits A-F, eg. Ah vs 0Ah
/// </summary>
bool AddLeadingZeroToHexNumbers { get; set; }

Expand Down

0 comments on commit 1ff7c7b

Please sign in to comment.