tags:

views:

49

answers:

3

Hi, I am busy writing an app and I have noticed that it sometimes crashes, and when it does and I get back to my computer then I only have the stack trace.

Is there a way for me to take a memory dump of the app at crash time?

Thanks

+1  A: 

Not a memory dump but ACRA, http://code.google.com/p/acra/, (Application Crash Report for Android) is pretty good at recording info about what's going on. With the most detailed info being a stack trace.

The debugging info on it's own might not be super helpful, but you could modify their code to do and send a logcat when your application crashes so you would get some more details about what's going on. I think they don't do this by default for privacy/security reasons but it's a bit more useful to see the logcat around the crash.

Other than that you'd need to debug it with the debugger.

William
thanks I will check app on this tool looks nice
Jason
+1  A: 

Is there a way for me to take a memory dump of the app at crash time?

Not that I am aware of -- sorry!

CommonsWare
Yes I couldn't find anything on the matter. It's a good thing to add to the SDK, maybe 3.0 :P
Jason
+1  A: 

If you call android.os.Debug.dumpHprofData(String fileName), you can capture an HPROF dump that can be viewed with jhat or MAT. You'll need to trap the exception somehow (either try/catch or specify your own global default exception handler), and if you want to write to /sdcard you'll need the WRITE_EXTERNAL_STORAGE permission.

See also Dalvik Heap Profiling.

fadden
Thanks this should be useful althogh not a memory dump :)
Jason
You can view strings, the values of fields in objects, and so on. What did you want that isn't provided?
fadden
It's close to a full Dump however you could not do things like load it into memory and continue running it. (unless I am mistaken)
Jason
Ah. That'd require saving the full state of the Linux process, since the app might be depending on resources allocated from native code, or interacting with a thread that isn't attached to the VM. There would also need to be a way to reattach the process to the app framework IPC, re-allocate any system resources, etc. You'd need to dump more than memory to be able to restart it. You can get most of the way by calling android.os.Debug.waitForDebugger() at crash time, and then attach a debugger later. (This might set off the ANR detector though.)
fadden