c# - WinDbg 从符号中获取所有函数的地址
问题描述
执行命令x ShittyProject!*
我得到这样的输出
<MSIL:00250014 > ShittyProject!Main (void)
<MSIL:00250098 > ShittyProject!.ctor (void)
<MSIL:00250037 > ShittyProject!.ctor (void)
<MSIL:002500ed > ShittyProject!get_Default (void)
<MSIL:002500a1 > ShittyProject!get_ResourceManager (void)
<MSIL:002500f8 > ShittyProject!.cctor (void)
<MSIL:0025002a > ShittyProject!Foo (void)
<MSIL:0025006e > ShittyProject!InitializeComponent (void)
<MSIL:00250000 > ShittyProject!InitializeComponent (void)
<MSIL:002500da > ShittyProject!get_Culture (void)
<MSIL:002500e5 > ShittyProject!set_Culture (void)
如果我理解正确MSIL:*
,它只是pdb
文件中的函数地址?是否有可能以某种方式获取函数的地址以在其上放置断点?
解决方案
托管代码不同于本机代码。要以“本机方式”( bp
) 设置断点,您需要等到该方法经过 JIT 编译,然后使用该方法的本机地址。
通常,人们不会这样做,而是使用 .NET 特定的等效项。有SOS (Microsoft docs) !bpmd
或SOSEX (可能不再维护) !mbm
。
给定代码
using System;
namespace JittyProject
{
class Program
{
static void Main()
{
Console.WriteLine("You want to stop before this shows up.");
Console.ReadLine();
}
}
}
您想在初始断点处停止并告诉它等到加载 .NET,例如
0:000> sxe ld clr
0:000> g
加载 .NET 运行时后,您可以为 .NET 特定调试命令加载 SOS 扩展。
0:000> .loadby sos clr
和 SOSEX 扩展:
0:000> .load c:\wherever\SOSEX.dll
然后添加一个断点:
0:000> !mbm JittyProject.Program.Main
使用常规g
,您最终会遇到断点:
0:000> g
ModLoad: 76650000 766e2000 C:\Windows\SysWOW64\OLEAUT32.dll
Breakpoint: JIT notification received for method JittyProject.Program.Main() in AppDomain 00960db0.
Breakpoint set at JittyProject.Program.Main() in AppDomain 00960db0.
Breakpoint 2 hit
0:000> !clrstack
OS Thread Id: 0x3ff8 (0)
Child SP IP Call Site
003eeda0 77601ffc [PrestubMethodFrame: 003eeda0] JittyProject.Program.Main() [C:\...\JittyProject\Program.cs @ 8]
003eef74 77601ffc [GCFrame: 003eef74]
推荐阅读
- java - JBehave - 在一个故事中不可能有多个结果?
- angular - 如何使用 javascript 从简单的 html 页面触发 Angular Web 组件(自定义元素)上的 Click 事件
- python - 查找具有最大数据的数据框
- java - 制作 java tic tac toe vs 计算机
- php - 正则表达式:拆分函数调用参数
- c# - 使用模型在 POST 期间 ASP.Net Cookie 身份验证到期
- common-lisp - 在 common lisp 中将整数格式化为字符
- asp.net - 验证当前密码的最佳方法是什么?
- android - Activity 和 Fragment 的共享元素过渡不同
- reporting-services - 本地报告处理期间发生错误有效值在“0”和“1”之间