Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I manually generate a core dump (or equivalent) in lldb attached to iOS

Tags:

xcode

ios

lldb

Sometimes I'm trying to track down a really rare bug in an iOS app. I'll hit it in the debugger after hours of trying to repro only to have xcode or lldb crash on me while I'm debugging (usually if I'm stepping through C++ code). This is beyond infuriating.

With gdb you can use generate-core-dump to create a core dump of the file so that I can re-load it in gdb and at least look at all of the memory. What I want is the ability to do something similar in lldb so that when xcode crashes (as it always tends to do at the worst times) I can recover my debugging session without having to reproduce the crash.

The app is running on a non-jailbroken iPhone, so I don't have much access to the OS to do something like dump the memory from there.

One possible answer is to just use gdb instead of lldb, but I think that causes some other problems that I'm not remembering at the moment, plus it doesn't have some of the features that are useful in lldb.

like image 627
stokastic Avatar asked Jul 26 '13 04:07

stokastic


People also ask

What generates a core dump?

A core dump or a crash dump is a memory snapshot of a running process. A core dump can be automatically created by the operating system when a fatal or unhandled error (for example, signal or system exception) occurs. Alternatively, a core dump can be forced by means of system-provided command-line utilities.

Is core dump a debugging technique?

When an application crashes, you can arrange for its state to be saved to disk, in a core dump file, which can indicate where the error occurred in the source code, the contents of memory at the time of the error, and the values of any variables and expressions set at the time.

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

UPDATE: Xcode 6, released fall of 2014, includes a new process save-core command in lldb -- lldb can now generate a coredump of a user process. e.g. (lldb) process save-core /tmp/corefile and wait a little bit.

The original answer for Xcode 5 and earlier lldb's, was:

This feature isn't implemented in lldb yet. This feature isn't implemented in the Apple version of gdb, either, for that matter.

While not a commonly requested feature, it is something other people have said would be useful as well. Hopefully someone will be sufficiently motivated to add that capability to lldb. I'm not sure how well it would work on an iOS device because it's going to involve gigantic amounts of data being transferred up to the Mac over a protocol that isn't very efficient for large data transfers - I expect it would be remarkably slow.

The core file can be opened with lldb -c /tmp/corefile

like image 110
Jason Molenda Avatar answered Sep 20 '22 10:09

Jason Molenda


It's worth noting that the process explorer tool for iOS can generate core dumps of any PID (assuming you have root or it's the same UID as you), without impacting the process.

like image 34
Technologeeks Avatar answered Sep 21 '22 10:09

Technologeeks