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 unlimlitedsetrlimit 4 -1 -1# write coredump to /var/logwrite /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


更多相关文章

  1. Android使用FrameLayout应该注意的地方
  2. Android 项目导入eclipse中报错但找不到错误地方的解决方法
  3. android 使用TextView/EditText应该注意的地方
  4. 使用ListView应该注意的地方
  5. 分享到某个地方
  6. Android中对NFC的实现代码分布在如下几个地方:
  7. Elasticsearch是什么?Elasticsearch 能够被用在什么地方?
  8. 在一个C语言程序中,main函数可以在任何地方出现么

随机推荐

  1. Android(安卓)AdbCommandRejectedExcepti
  2. 【ERROR】java java.lang.NoClassDefFoun
  3. android 底部Dialog里面的EditText点击软
  4. 2019 Android开发工程师面经
  5. [置顶] Android的AlertDialog详解
  6. Android(安卓)Debug Tools
  7. 2018 I/O Android(安卓)详解
  8. Android中Listview通过适配器设置Item的
  9. Android工程中配置OpenCV
  10. 自动化测试 Appium之Python运行环境搭建