简体   繁体   English

lldb memory 从变量中读取计数

[英]lldb memory read with count from variable

Is it possible to use a variable as the count in a "memory read" lldb command?是否可以在“内存读取”lldb 命令中使用变量作为计数?

A minimal example: With a breakpoint at the return statement of the following C program一个最小的例子:在以下 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
}

I can dump the contents of the string variable with我可以转储字符串变量的内容

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

but not with但不是与

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

How can I use the value of the len variable as the count of the "memory read" command?如何使用len变量的值作为“内存读取”命令的计数?

lldb's command line doesn't have much syntax, but one useful bit that it does have is that if you surround an argument or option value in backticks, the string inside the backticks gets passed to the expression parser, and the result of the expression evaluation gets substituted for the backtick value before being passed to the command. lldb 的命令行没有太多语法,但它确实有一个有用的位是,如果你用反引号括起一个参数或选项值,反引号内的字符串将传递给表达式解析器,并且表达式评估的结果在传递给命令之前替换反引号值。 So you want to do:所以你想这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM