我是 Windbg 的新手,并试图了解一些关于价值和引用类型 .NET 的事情。这是我正在使用的代码
class Program
{
struct MyStruct
{
int x;
int y;
}
class MyClass
{
int x;
int y;
}
static void Main(string[] args)
{
MyStruct s ;
MyClass c = new MyClass();
Thread.Sleep(5 * 60 * 1000);
}
}
我把 sleep 放在这里的唯一原因是让我有时间将 Windbg 与正在运行的进程连接起来。我知道一个更好的方法可能是设置一个断点,但无论如何这是我的问题。
- 当 Windbg 附加到进程时,它会进入此线程 #3,但我可以看到没有托管 thead ID 为 3 的线程。该线程仅由调试器使用吗?是否有任何其他线程可能无法通过 !threads 命令显示?如果是这样,是否有任何命令可以给我所有线程?
0:003> !threads -special
ThreadCount: 2
UnstartedThread: 0
BackgroundThread: 1
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
PreEmptive Lock ID OSID ThreadOBJ State GC GC Alloc Context Domain Count APT Exception
0 1 BBC 000000000000190C50 200A
00000000000000/8020 0 MTA(终结器)启用00000000027F3CA8:00000000000000000000/20>>>>>>>>>>>>>>>>>>
OSID 特殊线程类型
1 e98 DbgHelper
2 106c 终结 器
0:003> !CLRStack
OS 线程 ID:0xe6c (3)
无法遍历托管堆栈。当前线程可能不是
托管线程。您可以运行的线程来获得在管理线程的列表!
进程
0:003> KB
RetAddr:参数以子:呼叫站点
00000000 77978778 : 00000000
00000000 00000000 00000000 00000000
00000000 00000000 776d466d:00000000 00000000 00000000 00000000:NTDLL DbgUiRemoteBreakin + 0x38
00000000 00000000 00000000 00000000 00000000 00000000:00000000 00000000 00000000 00000000:ntdll!RtlUserThreadStart+0x1d 00000000 : ntdll!DbgBreakPoint
0000000000000000 00000000
00000000 00000000
778d8791 : 00000000
00000000 00000000
00000000 : KERNEL32!BaseThreadInitThunk+0xd
0000000000000000 00000000
00000000 00000000
- 线程 0 看起来像是运行我的 Main 方法的线程。当我得到堆栈对象的转储时,它没有显示 MyStruct 并且由于某种原因显示 MyClass 两次。任何想法为什么?
0:000> !CLRStack
OS 线程 ID: 0xbbc (0)
Child-SP RetAddr 调用站点
000000000031edb0 000007fef6b32012 ConsoleApplication2.Program.Main(System.String[])
0:000> !DumpStackObjects
OS 线程 ID: 0xbbc (0)
RSP/ REG对象名称
000000000031edd8 00000000027f3c90 ConsoleApplication2.Program + MyClass
的000000000031ede8 00000000027f3c90 ConsoleApplication2.Program + MyClass
的000000000031ee00 00000000027f3c70 System.Object的[](System.String [])
000000000031ef88 00000000027f3c70 System.Object的[](System.String [])
000000000031f170 00000000027f3c70 System.Object的[] (System.String[])
000000000031f198 00000000027f3c70 System.Object[] (System.String[])
TIA