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

12,401

Solution 1

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

Solution 2

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.

Share:
12,401
stokastic
Author by

stokastic

Updated on June 18, 2022

Comments

  • stokastic
    stokastic almost 2 years

    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.

    • borrrden
      borrrden almost 11 years
      Is image dump sections the command you are looking for? See this page
  • toasted_flakes
    toasted_flakes over 10 years
    Does this still hold true now?
  • Jason Molenda
    Jason Molenda over 10 years
    Yes, there's still no way to generate a user process coredump with lldb today (Feb 2014) and I don't know of anyone doing the work to implement this feature right now.
  • Jason Molenda
    Jason Molenda over 9 years
    Updated the answer to note that Xcode 6 can now save core files of user processes on Mac OS X.