1

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).

enter image description here

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

asked Oct 28, 2015 at 15:51

1 Answer 1

1

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

answered Oct 29, 2015 at 19:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.