是否可以反映正在运行的 .NET 进程?

发布于 2024-08-03 16:17:46 字数 210 浏览 11 评论 0原文

我有一个在运行时发出动态类型的应用程序。为了检查生成的 .NET 代码,我们保存动态生成的程序集并使用 Reflector。

我想知道是否有一种方法可以在相应进程运行时以反射器方式反映它们,而不必保存动态程序集?换句话说,反射器中有一种“附加到进程...”按钮。

谢谢。

编辑:该功能的唯一存在理由是反映动态生成的程序集。

I have an application with dynamic types emitted at run-time. In order to inspect the generated .NET code, we save the dynamically generated assemblies and use the Reflector.

I am wondering whether there is a way to reflect them the Reflector way while the respective process is running, without having to save the dynamic assemblies? In other words to have sort of "Attach to process ..." button in Reflector.

Thanks.

EDIT: The only raison d'etre for the feature is to reflect on dynamically generated assemblies.

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

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

发布评论

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

评论(2

冷︶言冷语的世界 2024-08-10 16:17:46

我知道您可能正在寻找来自动态程序集的 C# 代码,并且这个问题已经很老了,但是...

您可以使用 Visual Studio 立即窗口< 获取正在运行的动态程序集的 IL /strong> 或使用 WinDbg。 (如果您正在调试 64 位进程,则必须使用 WinDbg,因为 Visual Studio 仍然是 32 位产品。)

  1. 附加到进程
    • WinDbg:如果已附加另一个进程作为调试器,则需要“非侵入式”完成此操作。如果 VS 已附加,请按 F6(或选择“文件”->“附加到进程”)并选择“非侵入式”选项。
    • Visual Studio:当您选择“开始调试”或按 F5 时,VS 会自动执行此操作,但也可以通过在调试菜单中选择“附加到进程”来手动完成。
  2. 使用命令!load SOS.dll加载SOS.dll或简单地!load SOS
    • WinDbg:在非侵入模式下,WinDbg 需要 SOS.dll 的完整路径。对于 .NET 4,路径类似于 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll
  3. 中断执行并选择线程。
    您可以在调试器中通过设置断点自动执行此操作,也可以在 VS 中通过弹出异常帮助程序自动执行此操作。

    • WinDbg:在非侵入模式下,您需要使用~命令和~n s命令手动选择线程。使用~列出所有线程,使用~n s命令进行切换。例如,使用 ~12 s 切换到线程号 12。
  4. 获取堆栈跟踪以及指令指针。命令:!clrstack
  5. 抓取IP并找到指向哪个方法。命令:!ip2md [地址]
    • 例如,如果您要转储的方法的 IP 为 0123456,您将发出命令 !ip2md 0123456
  6. 转储该方法的 IL。命令:!dumpil [方法描述符]
    • 例如,如果 IP2MD 命令将“0A1B2C3D”列为方法描述符的地址,您将发出命令!dumpil 0A1B2C3D`。

这应该可以让您了解动态程序集,尽管是在 IL 程序集中。

I know that you are probably looking for C# code to come out of Dynamic Assemblies, and that this question is quite old, however...

You can get at the IL of a running dynamic assembly using the Visual Studio Immediate window or using WinDbg. (You must use WinDbg if you are debugging a 64-bit process, since Visual Studio is still a 32-bit product.)

  1. Attach to the process.
    • WinDbg: This needs to be done "noninvasively" if another process is already attached as the debugger. Hit F6 (or choose File -> Attach to Process) and select the "Noninvasive" option if VS is already attached.
    • Visual Studio: VS does this automatically when you choose "Start Debugging" or hit F5, but can be done manually by choosing 'Attach to Process' in the debug menu.
  2. Load SOS.dll using the command !load SOS.dll or simply !load SOS.
    • WinDbg: In noninvasive mode, WinDbg needs the full path of SOS.dll. For .NET 4 the path is something like C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll
  3. Break execution and selet your thread.
    You can do this automatically in the either debugger by setting a breakpoint, or in VS by having the exception helper pop up.

    • WinDbg: In non-invasive mode, you will need to select the thread manually using the ~ command and the ~n s command. Use ~ to list all threads and use ~n s command to switch. For example, use ~12 s to switch to thread number 12.
  4. Get the stack trace, along with instruction pointers. Command: !clrstack
  5. Grab the IP and find which method that points to. Command: !ip2md [address]
    • For example, if the IP for the method you want to dump is 0123456, you would issue the command !ip2md 0123456.
  6. Dump the IL for the method. Command: !dumpil [method descriptor]
    • For example, if the IP2MD command listed '0A1B2C3Das the address of the method descriptor, you would issue the command!dumpil 0A1B2C3D`.

That should allow you to see into the Dynamic Assembly, albeit in IL assembly.

真心难拥有 2024-08-10 16:17:46

Reflector 有一个正在运行的程序集插件 (http://weblogs.asp.net /kdente/articles/438539.aspx)。但是,我怀疑它只是帮助检索正在运行的程序集的路径,随后由 Reflector 从磁盘加载程序集。不过,这可能值得一试。此外,创建反射器加载项并不是那么困难,因此您也许能够扩展正在运行的程序集加载项方法,以自动将程序集保存到磁盘,以便可以通过反射器加载它(假设现有的加载项还没有这样做。)

There is a running assembly add-in for Reflector (http://weblogs.asp.net/kdente/articles/438539.aspx). However, I suspect that it simply helps retrieve paths for running assemblies, with the assemblies subsequently loaded from disk by Reflector. However, it's probably worth a try. Also, creating reflector add-ins isn't all that difficult, so you might be able to extend the running assembly add-in approach to automatically save the assembly to disk so that it can be loaded by Reflector (assuming the existing add-in doesn't already do this.)

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