如何使用lldb"内存查找"命令?

时间:2015-10-13 08:58:26

标签: xcode macos lldb

根据lldb在线帮助,memory find应该像这样工作:

Find a value in the memory of the process being debugged.

Syntax: memory find <cmd-options> <address> <value> [<value> [...]]

Command Options Usage:
  memory find <address> <value> [<value> [...]]
  memory find [-e <expr>] [-s <name>] [-c <count>] [-o <offset>] <address> <value> [<value> [...]]

       -c <count> ( --count <count> )
            How many times to perform the search.

       -e <expr> ( --expression <expr> )
            Evaluate an expression to obtain a byte pattern.

       -o <offset> ( --dump-offset <offset> )
            When dumping memory for a match, an offset from the match location
            to start dumping from.

       -s <name> ( --string <name> )
            Use text to find a byte pattern.

     This command takes options and free-form arguments.  If your arguments
     resemble option specifiers (i.e., they start with a - or --), you must use
     ' -- ' between the end of the command options and the beginning of the
     arguments.

我怀疑实现与帮助信息不匹配,因为我使用的任何语法似乎都会得到各种神秘错误消息之一,例如:

error: two addresses needed for memory find

error: do not know how to deal with larger than 8 byte result types. pass a string instead

error: please pass either a block of text, or an expression to evaluate.

我已经用Google搜索了一些用法示例,并且没有任何结果。如果有人有一个有效的例子我会感激不尽。特别是我想从指针标识的块的开头搜索给定的字节数,以找到特定(字节)值的第一次出现(在这种情况下为255)。

我在OS X上使用Xcode 7.0.1,而lldb版本是lldb-340.4.70

<小时/>

更新

我发现可以使-s选项有效,例如像这样:

(lldb) me fi -s "f" -- ptr ptr+8192*256
Your data was found at location: 0x11033e20c
0x11033e20c: 66 bb 58 07 d0 b7 32 7d ff 7f 00 00 66 5b e7 82  f.X...2}....f[..

可能只是-e选项(在本例中我需要的选项)被破坏,例如:

(lldb) me fi -e 255 -- ptr ptr+8191*256
error: expression evaluation failed. pass a string instead?

不幸的是,试图诱使-s选项接受转义的十六进制或十进制值似乎也不起作用:

(lldb) me fi -s "\xff" -- ptr ptr+8191*256
Your data was not found within the range.

(lldb) me fi -s "\255" -- ptr ptr+8191*256
Your data was not found within the range.

1 个答案:

答案 0 :(得分:1)

此问题已在开源LLDB中修复,修订版243893(http://llvm.org/viewvc/llvm-project?view=revision&revision=243893

我无法对Xcode中此修复程序的可用性发表任何评论,但您可以尝试的一件事是从源代码编译LLDB并使用手工构建的LLDB和修复程序来调试您的问题