WinDbg 和 SoS,如何打印/转储大字符串?
我正在使用带有 SoS 扩展的 WinDbg 调试来自生产服务器的hangdump。
其中一个堆栈中有一个字符串参数,我需要知道它的值。但是,它是一个相当大的字符串,当我使用 DumpObj
时,WinDbg 不会打印它。这是 DumpObj
的输出:
0:036> !do 00000001b30d8668
Name: System.String
MethodTable: 0000064278436728
EEClass: 000006427803e520
Size: 5125300(0x4e34b4) bytes
(C:\WINDOWS\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String: <String is invalid or too large to print>
Fields:
MT Field Offset Type VT Attr Value Name
000006427843d998 4000096 8 System.Int32 1 instance 2562638 m_arrayLength
000006427843d998 4000097 c System.Int32 1 instance 2562637 m_stringLength
0000064278438170 4000098 10 System.Char 1 instance 3c m_firstChar
0000064278436728 4000099 20 System.String 0 shared static Empty
>> Domain:Value 0000000000163260:000000007fff0370 00000000001a6760:000000007fff0370 <<
0000064278438020 400009a 28 System.Char[] 0 shared static WhitespaceChars
>> Domain:Value 0000000000163260:000000007fff0b60 00000000001a6760:000000007fff89f0 <<
如何获取此字符串实例的值?最好转储到文件中。
I am debugging a hangdump coming from a production server using WinDbg with the SoS extension.
There is a string parameter in one of the stacks, that I need to know the value of. However, it is a rather large string, and WinDbg won't print it when I am using DumpObj
. This is the output from DumpObj
:
0:036> !do 00000001b30d8668
Name: System.String
MethodTable: 0000064278436728
EEClass: 000006427803e520
Size: 5125300(0x4e34b4) bytes
(C:\WINDOWS\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String: <String is invalid or too large to print>
Fields:
MT Field Offset Type VT Attr Value Name
000006427843d998 4000096 8 System.Int32 1 instance 2562638 m_arrayLength
000006427843d998 4000097 c System.Int32 1 instance 2562637 m_stringLength
0000064278438170 4000098 10 System.Char 1 instance 3c m_firstChar
0000064278436728 4000099 20 System.String 0 shared static Empty
>> Domain:Value 0000000000163260:000000007fff0370 00000000001a6760:000000007fff0370 <<
0000064278438020 400009a 28 System.Char[] 0 shared static WhitespaceChars
>> Domain:Value 0000000000163260:000000007fff0b60 00000000001a6760:000000007fff89f0 <<
How can I get the value of this string instance ? Preferably dumped to a file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我编写的一个脚本,用于将字符串转储到 Windbg 中的文件中。
这就是它的使用方式
$$>a<”c:\temp\dumpstringtofolder.txt” 6544f9ac 5000 c:\temp\stringtest
转储的内容将采用 Unicode 格式并查看它的内容使用类似这样的东西
Console.WriteLine(ASCIIEncoding.Unicode.GetString(File.ReadAllBytes(@"c:\temp\stringtest03575270.txt")));
HTH
Here is a script I wrote to dump strings to a file within windbg.
and this is how it can be used
$$>a<”c:\temp\dumpstringtofolder.txt” 6544f9ac 5000 c:\temp\stringtest
The dumped contents would be in Unicode format and to view its contents use something like this
Console.WriteLine(ASCIIEncoding.Unicode.GetString(File.ReadAllBytes(@"c:\temp\stringtest03575270.txt")));
HTH
在转储 2562638 个字符的文本之前,我会三思而后行,但如果您确实想要,文本将存储在字符串实例的字段之后,因此您可以执行 du
; <结束地址> 转储字符串的实际文本。输出将如下所示:通过将会话输出记录到文件中,您可以轻松捕获输出并执行所需的任何后处理。
I would think twice before dumping 2562638 characters worth of text, but if you really want to, the text is stored following the fields of the string instance, so you can do a
du <address+offset> <end address>
to dump the actual text of the string. The output will look something like this:By logging the session output to a file, you can easily capture the output and do whatever post-processing you need.
我已经修改了 @Naveen 的脚本以在 x64 平台上工作。
顺便说一句,很棒的剧本!
I have modified @Naveen's script to work on x64 platforms.
Great script btw!
如果您赶时间,请在 WinDbg 中启用日志后运行 !do。在日志文件中,您将获得整个字符串。
在WinDbg菜单中,转到Edit->打开/关闭日志文件,设置日志文件路径。
If you are in a hurry, run the !do after enabling logs in WinDbg. In the log file, you will get the entire string.
In WinDbg menu, go to Edit-> Open/Close log file, to set log file path.