首页 > 解决方案 > 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文件中的函数地址?是否有可能以某种方式获取函数的地址以在其上放置断点?

标签: c#windbg

解决方案


托管代码不同于本机代码。要以“本机方式”( bp) 设置断点,您需要等到该方法经过 JIT 编译,然后使用该方法的本机地址。

通常,人们不会这样做,而是使用 .NET 特定的等效项。有SOS (Microsoft docs) !bpmdSOSEX (可能不再维护) !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] 

推荐阅读