如何调试自动生成的代码?
How to debug auto-generated code?
我正在尝试查看 IAsyncStateMachine 在运行时发生了什么,我迫切需要查看它有哪些变量以及它有什么 calls.I 知道您可以使用 ILSpy 查看代码 ...但是我需要调试它。
有什么方法吗?
我需要查看 IAsyncStateMachine MoveNext 方法内部发生了什么!
public sealed partial class MethodBuilder<T> : Errand.MethodBuilder {
public static new MethodBuilder<T> Create() => new MethodBuilder<T>();
public new void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {
this.myStateMachine = stateMachine;
this.Task = new Task<T>(this);
stateMachine.MoveNext(); //i have to see the properties of stateMachine and inside this method !!!!!
}
public new void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine machine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine {
}
public void SetResult(T result) {
this.Task.isCompleted = true;
this.Task.result = result;
}
public new void SetStateMachine(IAsyncStateMachine stateMachine) => base.SetStateMachine(stateMachine);
public new void SetException(Exception ex) => base.SetException(ex);
}
也许你可以使用 debugger.launch
一旦调试器启动 visual studio 将提示选择 vs 版本
internal class Program
{
public static void Main(string[] args)
{
System.Diagnostics.Debugger.Launch();
Console.WriteLine("crap");
}
}
来自 MSDN How to: Debug .NET Framework Source.
启用 .NET Framework 源代码调试
在“工具”菜单上,单击“选项”。
在“选项”对话框中,单击“调试”类别。
在“常规”框中,设置“启用 .NET Framework 源步进”。
如果您启用了“仅我的代码”,则会出现一个警告对话框告诉您
“仅我的代码”现已禁用。单击确定。
如果您没有设置符号缓存位置,另一个警告
对话框告诉您默认的符号缓存位置现在是
放。单击确定。
在“调试”类别下,单击“符号”。
如果要更改符号缓存位置:
打开左侧框中的Debugging节点
在“调试”节点下,单击“符号”。
编辑从符号服务器到缓存符号中的位置
目录或单击浏览选择一个位置。
如果要立即下载符号,请单击加载符号
使用以上位置。
此按钮在设计模式下不可用。
如果您现在不选择下载符号,符号将会
下次启动调试时自动下载
你的程序。
单击“确定”关闭“选项”对话框。
我正在尝试查看 IAsyncStateMachine 在运行时发生了什么,我迫切需要查看它有哪些变量以及它有什么 calls.I 知道您可以使用 ILSpy 查看代码 ...但是我需要调试它。
有什么方法吗? 我需要查看 IAsyncStateMachine MoveNext 方法内部发生了什么!
public sealed partial class MethodBuilder<T> : Errand.MethodBuilder {
public static new MethodBuilder<T> Create() => new MethodBuilder<T>();
public new void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {
this.myStateMachine = stateMachine;
this.Task = new Task<T>(this);
stateMachine.MoveNext(); //i have to see the properties of stateMachine and inside this method !!!!!
}
public new void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine machine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine {
}
public void SetResult(T result) {
this.Task.isCompleted = true;
this.Task.result = result;
}
public new void SetStateMachine(IAsyncStateMachine stateMachine) => base.SetStateMachine(stateMachine);
public new void SetException(Exception ex) => base.SetException(ex);
}
也许你可以使用 debugger.launch 一旦调试器启动 visual studio 将提示选择 vs 版本
internal class Program
{
public static void Main(string[] args)
{
System.Diagnostics.Debugger.Launch();
Console.WriteLine("crap");
}
}
来自 MSDN How to: Debug .NET Framework Source.
启用 .NET Framework 源代码调试
在“工具”菜单上,单击“选项”。
在“选项”对话框中,单击“调试”类别。
在“常规”框中,设置“启用 .NET Framework 源步进”。
如果您启用了“仅我的代码”,则会出现一个警告对话框告诉您 “仅我的代码”现已禁用。单击确定。
如果您没有设置符号缓存位置,另一个警告 对话框告诉您默认的符号缓存位置现在是 放。单击确定。
在“调试”类别下,单击“符号”。
如果要更改符号缓存位置:
打开左侧框中的Debugging节点
在“调试”节点下,单击“符号”。
编辑从符号服务器到缓存符号中的位置 目录或单击浏览选择一个位置。
如果要立即下载符号,请单击加载符号 使用以上位置。
此按钮在设计模式下不可用。
如果您现在不选择下载符号,符号将会 下次启动调试时自动下载 你的程序。
单击“确定”关闭“选项”对话框。