Reputation: 20335
I am debugging my C project in Xcode. Basically, I have many nested arrays, whose values I wish to inspect. They are present in the console (not sure if it is the right name) in the form of starting memory address, like
a (0x0000000100300010)
|-- b (0x0000000100105750)
|-- c (0x0000000100108250)
I find it very hard to inspect the values of, say, array c
in lldb
. I've tried the po
command in lldb
, but no luck. So my first question is how do people usually do this inspection? I believe it is a common thing to do while debugging.
Then I read somewhere that one can achieve this by inspecting the memory contents at, say, 0x0000000100108250
, which I did (screenshot as below).
It appears to me that the memory content is displayed as binary. I understand that this is physically more realistic, but to my goal (inspecting variable values), this is quite counterintuitive. My second question: is there a way of inspecting these memory contents as natural decimal numbers? If not, what sequence should I following in reading these binary numbers (specifically, what is 01 00 00 00
)?
Upvotes: 1
Views: 741
Reputation: 3329
Imagine being stopped here:
int foo(int* ptr) {
return *ptr; // HERE
}
and you happen to know that ptr points to a 5 element int array
(lldb) memory read -t int -c 5 `ptr`
will produce the following output for you:
(int) 0x7fff5fbff920 = 1
(int) 0x7fff5fbff924 = 2
(int) 0x7fff5fbff928 = 3
(int) 0x7fff5fbff92c = 4
(int) 0x7fff5fbff930 = 5
"memory read" should be obvious
-t int means "print elements of type int"
-c 5 means "print 5 elements"
`ptr` means "evaluate the string ptr as an expression and replace the result in the command" - this is a general LLDB trick where backticks introduce inline expressions in commands
Upvotes: 1