如何使用 lldb "memory find" 命令?

How to use lldb "memory find" command?

根据 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 "5" -- ptr ptr+8191*256
Your data was not found within the range.

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

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