在 Visual Studio 中通过中间语言 (IL) 和 C# 同时调试

发布于 2024-10-21 21:37:48 字数 86 浏览 4 评论 0原文

我正在寻找 Visual Studio 的扩展,在调试模式下可以单步执行 C# 之外的中间语言。

我不是在寻找调试托管和非托管代码的解决方案。

I'm looking for an extension for Visual Studio where in debug mode it's possible to single step through the intermediate language beside C#.

I'm not looking for a solution to debug managed and unmanaged code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

溺孤伤于心 2024-10-28 21:37:48

你的目的是什么?您的 IL 是由 C# 编译器生成的还是在运行时动态生成的?如果是前一种,您可以使用通过 ilasm 重新编译二进制文件的技巧。

  1. 像平常一样编译 C# 代码。是否优化并不重要,但您必须指定编译选项以生成完整的 PDB 符号。
  2. 使用 ildasm 将二进制文件转换为 .il 文件。这是菜单中的“转储”选项。
  3. 重新编译 .il 文件以获得新的二进制文件(和新的符号)

    ilasm .il [/exe|/dll] /debug

  4. < p>现在,在调试特定程序集时,您将看到 IL 代码而不是 C# 代码。如果您在步骤 2 中选择适当的选项,您还将看到原始 C# 文件中的匹配行。

对于动态生成 IL 的情况,我只需使用 带有 SOS 扩展的 WinDbg。它可以转储 IL 并单步执行它,但需要一些时间来适应。

What is your purpose? Is your IL generated by C# compiler or dynamically produced at run time? If the former one, you can use a trick of re-compiling your binary through ilasm.

  1. Compile C# code as you normally would. It does not matter if it is optimized or not, but you have to specify compilation option to produce full PDB symbols.
  2. Use ildasm to convert your binary to .il file. It is option Dump in the menu.
  3. re-compile the .il file to get a new binary (and a new symbols)

    ilasm .il [/exe|/dll] /debug

  4. Now when debugging that specific assembly you will see IL code rather than C# code. You will also see a matching lines from original C# file if you select appropriate option in step 2.

For the case of dynamically generated IL, I would simply use WinDbg with SOS extension. It can dump IL and step through it, but it takes a bit to get used to.

极度宠爱 2024-10-28 21:37:48

虽然严格来说不是 OP 所要求的 Visual Studio 扩展,但现在可能有更好的方法使用 dnSpy,一个全面的、独立的、开源的.NET调试工具。该工具实际上不仅仅是调试;它还可以做更多的事情。例如,它允许直接编辑 .NET 和本机 (PEFile) 程序集、对它们进行反混淆、浏览和修改原始托管和本机标头、内容、资源、BAML 和元数据,以及我可能尚未发现的更多内容。

输入图片这里的描述

为了本页讨论的目的,请务必查看dnSpy 项目的IL 解释器部分。完全按照 OP 的要求,这是一个实现 IL 解释器的库,用于模拟 IL 代码的(假装)执行与调试器的(实际)本机指令单步执行并行,以便显示 IL 代码的状态(逻辑)IL 执行堆栈。我相信如果需要的话,调试器中还内置了一些出色的 x86/x64 反汇编渲染。感谢这个杰作应用程序的开发者。

Although not strictly a Visual Studio extension as the OP requested, there's now a maybe even better way to do this using dnSpy, a comprehensive, standalone, open-source .NET debugging tool. The tool actually does much more than just debugging; for example it allows direct editing of .NET and native (PEFile) assemblies, de-obfuscating them, browsing and modifying the raw managed and native headers, content, resources, BAML, and metadata, and more that I probably haven't discovered.

enter image description here

For the purposes of the discussion on this page, be sure to check out the IL interpreter section of the dnSpy project. Exactly as requested by the OP, this is the library that implements an IL interpreter for simulating the (pretend) execution of the IL code in parallel with the debugger's (actual) native instruction single-stepping, for the purposes of displaying the state of the (logical) IL execution stack. I believe there's some excellent x86/x64 disassembly rendering built-in to the debugger as well, if needed. Kudos to the developer of this tour-de-force app.

污味仙女 2024-10-28 21:37:48

我认为这里不需要外部反汇编程序。当您在 VS 2010(尽管不是 Express)中进行调试时,您可以右键单击代码窗口并选择“转到反汇编”来单步调试 IL 代码。这就是您要找的吗?阅读更多 这里

I don't think that an external disassembler is necessary here. When you're debugging in VS 2010 (though not Express) you can right-click on the code window and select "Go To Disassembly" to step through the IL code. Could that be what you're looking for? Read more here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文