android下是否生成coredump的设置

1,全局设置方法一,在device下面自己相应目录的init.rc中设置,一般在on boot下面设置,增加:

on boot

# set coredump

    setrlimit 4 -1 -1

setrlimit 是这是进程资源限制的

#define RLIMIT_CORE 4 /* max core file size */

# define RLIM_INFINITY (~0UL)

 

所以setrlimit 4 -1 -1实际就是setrlimit RLIMIT_CORE RLIM_INFINITY  RLIM_INFINITY

表示coredump文件大小没有限制

 

2,全局设置方法二,在系统代码中,dalvik_system_Zygote.cpp中:

static void enableDebugFeatures(u4 debugFlags)

{

.

.

.

#ifdef HAVE_ANDROID_OS

    if ((debugFlags & DEBUG_ENABLE_DEBUGGER) != 0) {

        /* To let a non-privileged gdbserver attach to this

         * process, we must set its dumpable bit flag. However

         * we are not interested in generating a coredump in

         * case of a crash, so also set the coredump size to 0

         * to disable that

         */

        if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {

            ALOGE("could not set dumpable bit flag for pid %d: %s",

                 getpid(), strerror(errno));

        } else {

            struct rlimit rl;

            rl.rlim_cur = 0;

            rl.rlim_max = RLIM_INFINITY;

            if (setrlimit(RLIMIT_CORE, &rl) < 0) {

                ALOGE("could not disable core file generation for pid %d: %s",

                    getpid(), strerror(errno));

            }

        }

    }

#endif

}

把上面的rl.rlim_cur = 0;改为rl.rlim_cur = RLIM_INFINITY;即可

 

3,应用自己设置,对于bin应用,一般在main函数的开始位置设置:

    struct rlimit rl;

    rl.rlim_cur = RLIM_INFINITY;

    rl.rlim_max = RLIM_INFINITY;

    if (setrlimit(RLIMIT_CORE, &rl) < 0)

    {

        __android_log_print(ANDROID_LOG_DEBUG, TAG, "setrlimit fail.");

    }

需要#include <sys/resource.h>

 

4,应用自己设置,对于apk应用,如果有使用jni调用到so库,那么在so中起始调用的地方设置:

    struct rlimit rl;

    rl.rlim_cur = RLIM_INFINITY;

    rl.rlim_max = RLIM_INFINITY;

    if (setrlimit(RLIMIT_CORE, &rl) < 0)

    {

        __android_log_print(ANDROID_LOG_DEBUG, TAG, "setrlimit fail.");

    }

需要#include <sys/resource.h>

 

5,需要说明的是,3/4两种情况因为调用 setrlimit是在1/2的后面,所以优先级高于1/2;2是在1后面调用的,所以优先级高于1。

 

6,在mstar平台上,在set_config中的bootargs环境变量中有个CORE_DUMP_PATH,是设置coredump生成到哪里的,linux系统是在 /etc/profile 里。

 

7,对于应用来说,要有访问coredump文件的权限,比如非platform权限的apk只能访问/data/data/packages,所以测试某个apk时,可以把coredump的地址设置为/data/data/packages,本来想可以设置为/mnt/sdcard/目录下,但是试验发现,可以创建文件,但是不能写入core信息。

 

8,kernel中关于coredump的代码

base.c中

static const struct limit_names lnames[RLIM_NLIMITS] = {

 [RLIMIT_CPU] = {"Max cpu time", "seconds"},

 [RLIMIT_FSIZE] = {"Max file size", "bytes"},

 [RLIMIT_DATA] = {"Max data size", "bytes"},

 [RLIMIT_STACK] = {"Max stack size", "bytes"},

 [RLIMIT_CORE] = {"Max core file size", "bytes"},

 [RLIMIT_RSS] = {"Max resident set", "bytes"},

 [RLIMIT_NPROC] = {"Max processes", "processes"},

 [RLIMIT_NOFILE] = {"Max open files", "files"},

 [RLIMIT_MEMLOCK] = {"Max locked memory", "bytes"},

 [RLIMIT_AS] = {"Max address space", "bytes"},

 [RLIMIT_LOCKS] = {"Max file locks", "locks"},

 [RLIMIT_SIGPENDING] = {"Max pending signals", "signals"},

 [RLIMIT_MSGQUEUE] = {"Max msgqueue size", "bytes"},

 [RLIMIT_NICE] = {"Max nice priority", NULL},

 [RLIMIT_RTPRIO] = {"Max realtime priority", NULL},

 [RLIMIT_RTTIME] = {"Max realtime timeout", "us"},

};

exec.c中

void do_coredump(long signr, int exit_code, struct pt_regs *regs)

#if (MP_DEBUG_TOOL_COREDUMP_PATH==1)

        cprm.file = filp_open(cn.corename, O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag, 0600);

        if (!IS_ERR(cprm.file))

        {

            printk(KERN_ALERT "***** Create coredump file to %s ******\n", cn.corename);

        }

        else

        {

            printk(KERN_ALERT "***** Coredump Fail... can't create corefile to %s \n", cn.corename);

        }

#else

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值