【问题标题】:lldb memory read with count from variable使用变量计数读取 lldb 内存
【发布时间】:2023-02-02 06:15:37
【问题描述】:

是否可以在“内存读取”lldb 命令中使用变量作为计数?

一个最小的例子:在以下 C 程序的返回语句处有一个断点

#include <stdio.h>
#include <string.h>

int main(int argc, const char * argv[]) {
    char *str = "Hello";
    size_t len = strlen(str);

    return 0; // <-- Breakpoint here
}

我可以转储字符串变量的内容

(lldb) memory read --count 5 str
0x100000fae: 48 65 6c 6c 6f                                   Hello

但不是与

(lldb) memory read --count len str
error: invalid uint64_t string value: 'len'

如何使用len 变量的值作为“内存读取”命令的计数?

【问题讨论】:

    标签: debugging lldb


    【解决方案1】:

    lldb 的命令行没有太多语法,但它确实有一个有用的位是,如果你用反引号括起一个参数或选项值,反引号内的字符串将传递给表达式解析器,并且表达式评估的结果在传递给命令之前替换反引号值。所以你想这样做:

    (lldb) memory read --count `len` str
    

    【讨论】:

      猜你喜欢
      • 2015-08-11
      • 1970-01-01
      • 2014-12-06
      • 2014-08-06
      • 2017-01-08
      • 2017-05-09
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多