Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print the contents of a memory address using LLDB?

Tags:

xcode

lldb

I am using LLDB and wondering how to print the contents of a specific memory address, for example 0xb0987654.

like image 580
Adam Lee Avatar asked Nov 03 '13 01:11

Adam Lee


People also ask

What is GDB LLDB?

GDB is debugger part of the GNU project created to work along the GNU compiler. LLDB is debugger part of the LLVM project created to work along LLVM compiler.

How do you create a breakpoint in LLDB?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )

Does Xcode use LLDB?

Xcode uses the LLDB as the default debugging tool. The full form of LLDB is Low-level debugger. Breakpoints help a developer to stop the execution of the program at any point.


2 Answers

To complement Michael's answer.

I tend to use:

memory read -s1 -fu -c10000 0xb0987654 --force 

That will print in the debugger.

  1. -s for bytes grouping so use 1 for uint8 for example and 4 for int
  2. -f for format. I inherently forget the right symbol. Just put the statement with -f and it will snap back at you and give you the list of all the options
  3. -c is for count of bytes
  4. if you are printing more than 1024 bytes, append with --force

Hope this helps.

like image 129
Khaled Barazi Avatar answered Sep 20 '22 21:09

Khaled Barazi


Xcode has a very nice Memory Browser window, which will very nicely display the contents of memory addresses. It also lets you control byte grouping and number of bytes displayed, and move back or forward a memory page:

enter image description here

You can access it by pressing ⌘^⌥⇧M. After entering it, press enter to open the memory browser in the main editor.

or

Debug --> Debug Workflow --> View Memory

Notice the field on its bottom left corner where you can paste the memory address you want to inspect!

Documentation here: https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/viewing_memory.html

Related answer here: How do I open the memory browser in Xcode 4?

like image 28
Eric Avatar answered Sep 16 '22 21:09

Eric