Android classical core dump

9,572 views
Skip to first unread message

cyrulos83

unread,
Dec 20, 2010, 7:58:23 AM12/20/10
to android-platform
Hello,

I am doing a research on post-mortem analysis for Android crashed
application (due to seg fault) that uses native C library.
I have already learned about Android tombstones but this won't do the
job right for me.
I am wondering whether it is possible to get a classical linux core
dump on Android emulator. I already tried logging to emulator (adb
shell) and setting ulimit -c option but that failed. For testing
purposes, I am using simple C application that I corss-compiled and
run on emulator form shell ( ./data/myapp).

Appreciate any kind of help.

Regards,
Lukasz

Bruce Beare

unread,
Dec 21, 2010, 11:28:33 PM12/21/10
to android-platform
Yes, you can get core dumps. Modify your init.rc file thusly:

# corefile limit
setrlimit 4 -1 -1


# Create the core file directory
mkdir /data/core
write /proc/sys/kernel/core_pattern /data/core/%e.%p

app_process started processes (i.e. dalvik applications) won't give
you core dumps because they specifically reset the rlimits.
There's a debug flag to get around that... if you can figure out how
to set it (I haven't!).

cyrulos83

unread,
Dec 22, 2010, 8:26:49 AM12/22/10
to android-platform
Hi,

a short update from me.

I managed to get a core dump for application that I run from android
shell (firs log with adb shell).
The difference is that I have to cd to /data and then run application
by typing /myapp - core dump is produced.

Now I am struggling to make core dump for app_process started
processes, that uses native C library.
I tried to set rlimits within my C library's code - this succeeds
without errors but still I am not able to produce core dumps.
Then, I tried forking. I put my faulty code (that causes seg fault)
into child process but it also did not produce a core dump for me.

I am on further studies right now, if anyone has some good ideas,
please don't hesitate to post them here.

cyrulos83

unread,
Dec 23, 2010, 9:25:58 AM12/23/10
to android-platform
Hello,

Short update from my side. Another idea that was tested came from
this:
http://android.git.kernel.org/?p=platform/bionic.git;a=blob;f=linker/debugger.c

There is a piece of code that redirects system signals (SIGSEGV and
else) to specific handlers:
void debugger_init()
{
signal(SIGILL, debugger_signal_handler);
signal(SIGABRT, debugger_signal_handler);
signal(SIGBUS, debugger_signal_handler);
signal(SIGFPE, debugger_signal_handler);
signal(SIGSEGV, debugger_signal_handler);
signal(SIGSTKFLT, debugger_signal_handler);
signal(SIGPIPE, debugger_signal_handler);
}

I kind of think that what actually happens and why core dump is not
produced when segmentation fault occurs is because
system does not know about SIGSEGV being sent. I think it is intercept
somehow by Android system and that is why
tombstone is produced instead of classic core dump.

I tried adding this to my native C code:
signal(SIGSEGV, SIG_DFL);

but unfortunately it did not help. If somebody has some knowledge
about Android system managing signals it would be a great help
to share it here.

Oh and one more thing. I modified /proc/sys/kernel/core_pattern for
Android emulator to make core files being produced in /data directory
where writing is available.

Hyoungho

unread,
Jul 29, 2013, 4:13:10 AM7/29/13
to android-...@googlegroups.com
Hello!
I'm Hyoungho Choi.

It might be too late.
I , however, saw this contents.
Even if you already got to know how to get core dump for app_process, I'm just writing the answer in here for any other people to wonder it.
All of processes forked with zygote call "setrlimit" syscall to disable to make core dump. 
So if you want to enable to make core dump for app_process, you can just remove that code like below:

// dalvik_system_Zygote.cpp
static void enableDebugFeatures(u4 debugFlags)
{
    . . .
    } else {
        /* if(setrlimit(RLIMIT_CORE, &rl) < 0) {
              . . .
        } */
    . . . 
}

Unfortunately, it's ,however, source code for dalvik VM, not for application. That is, it's a part of  SDK.
If you don't want to change SDK or to rebuild SDK, I'm not sure but you can do like below:

You can just make the application, for which you want to get core dump, run through Eclipse.
In this case, above code which I said "remove" might not be excuted.

Regards,
Hyoungho.

2010년 12월 20일 월요일 오후 9시 58분 23초 UTC+9, cyrulos83 님의 말:
Reply all
Reply to author
Forward
0 new messages