Android coredump

1. enable the CONFIG_MAGIC_SYSRQ

We have to enable theCONFIG_MAGIC_SYSRQ from the  “arch/arm64/configs/.config” whenconfiguring the Kernel and try to get the coredump. As a result you’ll see /proc/sysrq-trigger and/proc/sys/kernel/sysrq in /proc file system.

Here is the list of possible values in /proc/sys/kernel/sysrq:
   0 - disable sysrq completely
   1 - enable all functions of sysrq
  >1 - bitmask of allowed sysrq functions (see below for detailed function
       description):
          2 =   0x2 - enable control of console logging level
          4 =   0x4 - enable control of keyboard (SAK, unraw)
          8 =   0x8 - enable debugging dumps of processes etc.
         16 =  0x10 - enable sync command
         32 =  0x20 - enable remount read-only
         64 =  0x40 - enable signalling of processes (term, kill, oom-kill)
        128 =  0x80 - allow reboot/poweroff
        256 = 0x100 - allow nicing of all RT tasks

You can set the value in the file by the following command:
    echo "number" >/proc/sys/kernel/sysrq

or you can add the  “CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE must always be written in hexadecimal” in defconfig file.
Eg: CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x8 for debugging dumps

Then write a character to /proc/sysrq-trigger.  e.g.:

               echo c > /proc/sysrq-trigger----- to put the device kernel in panic.

2. Set coredump file size

關於Android上要使用coredump 來觀察process crash的遺跡 首先必須要設定coredump file size以及路徑
在Android上可以直接改init.rc (以下說明的是系統開發人員的作法, 也就是你必須要有辦法修改init.rc)

在init.rc內加入

init.rc
# set coredump size to unlimlited

setrlimit 4 -1 -1
# write coredump to /var/log

write /proc/sys/kernel/core_pattern /var/log/core.%e.%p.%t

設定好後 重新開機 設定就applied了
這時候打 ulimit -a or ulimit -c你可以查看coredump size的設定
然後透過 cat /proc/sys/kernel/core_pattern 來查看coredump path

以上這樣就算在Android開啟coredump了

接下來是當發生crash然後產生coredump後, 怎麼去看可能crash在哪個地方
首先將coredump file抓下來放到與你的程式(含debug symbol)同一個地方
然後打
gdb program-with-debug-symbol core-dump-file
之後打backtrace
這樣應該就會秀出最後發生crash的code stack


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值