Home > Enterprise >  lldb memory read with count from variable
lldb memory read with count from variable

Time:02-03

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?

CodePudding user response:

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
  • Related