【问题标题】:WinDbg, SOS, how to dump all strings on stackWinDbg,SOS,如何将所有字符串转储到堆栈上
【发布时间】:2012-08-02 14:34:13
【问题描述】:

如何在当前线程的 clrstack 上打印所有 System.String 对象的字符串值?

我想做的伪代码:

foreach ($string in !dso -type System.String) !do $string

或者更好

foreach ($string in !dso -type System.String) !printstring $string

更好

foreach (distinct $string in !dso -type System.String) !printstring $string

谢谢!

【问题讨论】:

    标签: .net debugging windbg sos


    【解决方案1】:

    最新的 SOSEX 扩展 (v4) 具有 !mdso 命令,该命令具有类型过滤选项 /t

    SOSEX - Copyright 2007-2012 by Steve Johnson - http://www.stevestechspot.com/
    To report bugs or offer feedback about SOSEX, please email sjjohnson@pobox.com
    
    mdso
    Usage: !sosex.mdso [Options]
    
    Dumps object references on the stack and in CPU registers in the current context
    
    Options:
    
    /t:typeFilter - Limits the output to objects whose type name matches the filter expression specified by "typeFilter".
                     Cannot be combined with the /mt option.
    

    所以!mdso /t:System.String 的命令应该可以工作。

    【讨论】:

    • 谢谢,这很好用,因为 mdso 已经打印了字符串内容
    【解决方案2】:

    使用 !sex.strings。此命令将允许您查看所有字符串的值,或按大小、内容或 GC 生成过滤它们。

    【讨论】:

    • 谢谢。但是,这失去了与我感兴趣的特定堆栈的关系。有时我发现查看调用堆栈中的前 N ​​个字符串很有用,因此我希望有一个仅转储这些字符串的命令。
    • 我很抱歉。我将您的问题误读为堆而不是堆栈。
    • 看起来你的 sosex 仍然是一个非常好的解决方案,使用 jcopenha 建议的 !mdso /t:System.String
    【解决方案3】:

    我的想法是在堆栈地址中查找字符串对象引用。例如,我们知道栈底地址(0x000000001821CEF0)和栈顶地址(000000001821E3F0)。我们可以遍历这个范围内的所有地址(w/ 8 bytes step)并输出对象详细信息。

    .for (r $t0=0x000000001821CEF0;@$t0<000000001821E3F0;r $t0=@$t0+0x8){ !do poi(@$t0) }
    

    【讨论】:

    • !dso 命令没有-type(也没有-short)标志。
    • 谢谢,但这并没有真正起作用。正如布赖恩所说,没有类型标志(我认为也没有 -short 标志)
    • 谢谢。如果我能做 .foreach ( ico {!dso -short}) {!do ico } 我可以 grep 查找所有字符串,但没有 -short 标志,这根本不能正常工作......
    • 谢谢,第二个建议效果很好,如果输出到文本文件,然后用greping“字符串:”
    • @BenSchwehn 我希望有一种方法可以使用 .if 语句按类型过滤对象。不幸的是,如果堆栈上的地址错误,我会遇到问题。一旦找到合适的解决方案,我会更新答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 2010-11-12
    相关资源
    最近更新 更多