【问题标题】:Windbg - How can I Dump Strings which match a given filterWindbg - 我如何转储与给定过滤器匹配的字符串
【发布时间】:2012-09-12 03:23:24
【问题描述】:

可以使用以下命令转储所有字符串 !dumpheap -type System.string

如何只转储或打印那些以特定“字符串”开头或包含特定“字符串”的字符串

示例。我只想查看包含“/my/app/request”的字符串

【问题讨论】:

    标签: windbg sos


    【解决方案1】:

    为此使用 sosex 而不是 sos。它有一个!strings 命令,允许您使用/m:<filter> 选项过滤字符串。

    【讨论】:

      【解决方案2】:

      使用 !sex.strings。有关根据内容和/或长度过滤字符串的选项,请参见 !sosex.help。

      【讨论】:

        【解决方案3】:

        不确定 !dumpheap 是否支持。您始终可以使用 .logopen 将输出重定向到文件并对其进行后处理。对于更优雅(因此也更复杂)的解决方案,您还可以使用 .shell 将命令输出重定向到 shell 进程进行解析。这是一个例子:

        http://blogs.msdn.com/b/baleixo/archive/2008/09/06/using-shell-to-search-text.aspx

        您还可以查看 .shell 文档了解更多详细信息:

        http://msdn.microsoft.com/en-us/library/windows/hardware/ff565339(v=vs.85).aspx

        【讨论】:

        • 我希望看看我们是否可以使用 .foreach 形式 !DumpHeap 输出,并且仅在字符串包含指定字符串时打印出来。
        • 我尝试使用 .shell,它适用于短字符串。在长字符串上,它会受到!do 命令的有限字符串输出或du 命令的换行符的影响。请参阅我的答案以获得没有 SOSEX 的解决方案。这是我的 .shell 命令:.shell -ci".foreach (string {!dumpheap -short -type System.String}) { du /c80 ${string}+c L80 }" find "mySearchTerm"
        【解决方案4】:

        如果你真的想不用 SOSEX,那就试试

        .foreach (string {!dumpheap -short -type System.String}) { .foreach (search {s -u ${string}+c ${string}+c+2*poi(${string}+8) "mySearchTerm"}) { du /c80 ${string}+c }}
        

        它使用

        • !dumpheap 获取 .NET 堆上的所有字符串
        • .foreach 迭代它们
        • s 搜索子字符串
        • .foreach 再次查看是否发现了什么
        • 一些偏移量计算得到字符串的第一个字符 (+c) 和字符串长度 (+8)(乘以 2 得到字节而不是字符)。这些需要在 64 位应用程序的情况下进行调整

        /c80 只是为了更好的输出。如果您喜欢字符串的 .NET 详细信息,也可以使用 !do ${string} 而不是 du /c80 ${string}+c

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-02-22
          • 2016-05-16
          • 1970-01-01
          • 1970-01-01
          • 2021-10-08
          • 2021-08-30
          • 2018-11-27
          • 1970-01-01
          相关资源
          最近更新 更多