Skip to content

Instantly share code, notes, and snippets.

@FiloSottile
Last active October 5, 2022 06:55
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiloSottile/6537875 to your computer and use it in GitHub Desktop.
Save FiloSottile/6537875 to your computer and use it in GitHub Desktop.
How to dump the iOS simulator memory

Dumping the iOS simulator memory

To audit memory or to debug with external tools it can be useful to get a dump of the running memory of an app.

To do so on a device you'll need a Jailbreak, SSH access, and gdb. See this or this.

If instead you're up to a simulated app, things are easier: apps running in the simulator are actually just native processes on your Mac OS X.

So, how to get a core dump of a Mac OS X process? Sadly gdb can't do so. Mac OS X Internals comes to the rescue with this article.

It is actually an interesting read, but if you are in a hurry, skip to downloading the code and compile it like this (screw the Makefile, it compiles also for PowerPC)

gcc -O2 -arch i386 -Wall -o gcore gcore.c
gcc -O2 -arch x86_64 -Wall -o gcore64 gcore.c

Then simply run your app, find the process id grep-ping ps -hax and run

sudo gcore 1234

And enjoy your core dump. (Bonus: you can load it up in gdb)

If you happen to want the dump happen at a particular moment, place a regular breakpoint in XCode, then dump the memory when the process is paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment