如何使用 WinDbg 在托管核心转储中找到 N 个最大的字符串?

How to find N largest strings in a managed core dump using WinDbg?

我有一个包含 26GB 字符串的转储 - 超过 350 万个字符串。大对象堆只有 18 个占用略多于 2.5MB - 使用 !sosex.dumpgen 命令检查。

第 2 代拥有其中大部分。除了将它们全部放入日志文件然后在 WinDbg 之外对其进行分析外,我怎样才能获得最大的 N?

sosex has !strings command which has a switch where we can specify min length.

抱歉,我不在可以尝试 sosex 的机器附近。但它应该像例如!strings -m 1000 。您可以尝试 soshelp 命令并获取此 !sosex.help strings 这将打印所有仅大于 1000.Like 的字符串,我曾尝试提供较大的值喜欢 10000 并获得大字符串。

我认为 Netext 是可行的,但它只接近 SOSEx' !strings,因此需要更多脚本

0:000> .load F:\...\netext.0.1.5580\x86\NetExt.dll
NetExt version 2.0.1.5580 Aug  3 2015
License and usage can be seen here: !whelp license
Check Latest version: !wupdate
For help, type !whelp (or in WinDBG run: '.browse !whelp')
Questions and Feedback: http://netext.codeplex.com/discussions 
Copyright (c) 2014-2015 Rodney Viana (http://blogs.msdn.com/b/rodneyviana) 
Type: !windex -tree or ~*e!wstack to get started

0:000> !windex
Starting indexing at 20:55:54
Indexing finished at 20:55:54
30,707 Bytes in 343 Objects
Index took 00:00:00

0:000> !wfrom /nofield /type System.String where (m_stringLength>50) select m_stringLength
0n100
0n137
0n130
0n100
...

要去掉 0n 前缀,我们使用 $substr(m_stringLength,2,100)

这样我们就可以大致了解字符串的长度。这个列表需要一些排序,所以让我们使用 .shell 和 DOS sort /R 命令:

!! -ci "!wfrom /nospace /nofield /type System.String where (m_stringLength>50) select $substr(m_stringLength,2,100)" sort /R

根据结果,让我们使用循环并跳过一些项目来获取前 N 项。将 0n2 替换为您想要的项目数减 1。

.foreach /pS 0n2 /ps 999999 (length {!! -ci "!wfrom /nospace /nofield /type System.String where (m_stringLength>50) select $substr(m_stringLength,2,100)" sort /R}) {.echo length}

现在我们知道了前 N 个字符串的最小长度,我们可以再次将其应用于原始 !wfrom 命令。

嘿,这不是很容易吗?有时输出到文本文件是一个很好的解决方案...