简体   繁体   中英

lldb memory read with count from variable

Is it possible to use a variable as the count in a "memory read" lldb command?

A minimal example: With a breakpoint at the return statement of the following C program

#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?

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. So you want to do:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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