With LLDB version 8 I'm trying to dump the code bytes for a function "fh", using the memory read
command, using variables to calculate the length:
(lldb) expr unsigned $addr = (unsigned) fh
(lldb) expr unsigned $next_addr = (unsigned) fi
(lldb) expr unsigned $len = $next_addr - $addr
(lldb) p/x $addr
(unsigned int) $addr = 0x00000286
(lldb) p/x $next_addr
(unsigned int) $next_addr = 0x000002e4
(lldb) p/x $len
(unsigned int) $len = 0x0000005e
Passing $addr
as the address is correctly interpreted with a literal integer as the length:
(lldb) memory read --size 1 --format x --count 0x5e $addr
0x00000286: 0xc8 0x47 0202 0x48 0xc9 0x42 ...
but passing $len
as an argument to the count option fails:
(lldb) memory read --size 1 --format x --count $len $addr
error: invalid uint64_t string value: '$len'
This also happens with the breakpoint syntax, so it may be a general limitation with option parsing:
(lldb) breakpoint set -l $len
error: invalid line number: $len.
I also tried passing it through a command alias in the hope that substitution of the variable value would then happen earlier, but had similar results:
(lldb) command alias foop memory read --size 1 --format x --count %1 %2
(lldb) foop $len $addr
error: invalid uint64_t string value: '$len'
Is there some other syntax for evaluating a command with variables? I would prefer to avoid relying on the Python support as the toolchain I'm using doesn't reliably provide it.