Stability - Coredump - enable

Stability - Coredump - enable

1. Enable such feature from source code

Apply this patch, then we can turn on it by 'persist.debug.trace'.

diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index 9da44a4..2b3d10c 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -34,7 +34,9 @@
 #if defined(__linux__)
 #include 
 #endif
-
+#ifdef __ANDROID__
+#include 
+#endif
 #include 
 
 namespace art {
@@ -59,7 +61,18 @@ static void EnableDebugger() {
 #endif
   // We don't want core dumps, though, so set the core dump size to 0.
   rlimit rl;
+#ifdef __ANDROID__
+  char prop_value[PROPERTY_VALUE_MAX];
+  property_get("persist.debug.trace", prop_value, "0");
+  if (prop_value[0] == '1') {
+      LOG(INFO) << "setting RLIM to infinity for process " << getpid();
+      rl.rlim_cur = RLIM_INFINITY;
+  } else {
+      rl.rlim_cur = 0;
+  }
+#else
   rl.rlim_cur = 0;
+#endif
   rl.rlim_max = RLIM_INFINITY;
   if (setrlimit(RLIMIT_CORE, &rl) == -1) {
     PLOG(ERROR) << "setrlimit(RLIMIT_CORE) failed for pid " << getpid();

another:

diff --git a/init/property_service.cpp b/init/property_service.cpp
index 5c1ae79..991f8bc 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -468,6 +469,22 @@ static void load_override_properties() {
     }
 }
 
+static int check_rlim_action() {
+    std::string value ;
+    struct rlimit rl;
+    value = property_get("persist.debug.trace");
+    const char* pval = value.c_str();
+
+    if((strcmp(pval,"1") == 0)) {
+        rl.rlim_cur = RLIM_INFINITY;
+        rl.rlim_max = RLIM_INFINITY;
+        if (setrlimit(RLIMIT_CORE, &rl) < 0) {
+            ERROR("could not enable core file generation");
+        }
+    }
+    return 0;
+}
+
 /* When booting an encrypted system, /data is not mounted when the
  * property service is started, so any properties stored there are
  * not loaded.  Vold triggers init to load these properties once it
@@ -477,6 +494,8 @@ void load_persist_props(void) {
     load_override_properties();
     /* Read persistent properties after all default values have been loaded. */
     load_persistent_properties();
+    /*check for coredump*/
+    check_rlim_action();
 }
 
 void load_recovery_id_prop() {

 

2. Turn on such feature

 

2.1 setprop persist.debug.trace 1

adb root
adb shell setprop persist.debug.trace 1
adb reboot

2.2 disable selinux

2.2.1 adb shell

adb root
adb shell setenforce 0 
adb shell stop 
adb shell start

2.2.2 source code to disable it

diff --git a/system/core/init/init.cpp b/system/core/init/init.cpp
index 03ea924..cdc1df9 100644
--- a/init.cpp
+++ b/init.cpp
@@ -977,6 +977,7 @@ static void selinux_initialize(bool in_kernel_domain) {
         }
 
         bool is_enforcing = selinux_is_enforcing();
+  is_enforcing=0;
         security_setenforce(is_enforcing);
 
         if (write_file("/sys/fs/selinux/checkreqprot", "0") == -1) {

2.3 force crash

For excample , trace adbd:

#ps -A |grep adbd
#kill -11 

save the coredump file from '/data/core/!system!bin!adbd.*.adbd'

3 analysis coredump by gdb

3.1 get ndk

Download 'android-ndk-r10e'.

run gdb :

'android-ndk-r10e\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin\aarch64-linux-android-gdb.exe'

3.2 copy symbol file to local

save build product under 'out/target/product/msm89xx_64/symbols/'

if just trace adbd, you can just copy 'out/target/product/msm89xx_64/symbols/system/bin/adbd' here.

3.3 load the core dump

3.3.1 check the dump info

(gdb)file adbd
(gdb)core !system!bin!adbd.3358.adbd'
(gdb)info threads
(gdb)t 2
(gdb)bt
(gdb)f 5

3.3.2 set symbol files path.

gdb set solib-search-path symbol_files_path

example: set solib-search-path symbols/system/lib

3.3.3 others

gdb help command
gdb help set
gdb set print pretty on
gdb info
gdb info sharedlibrary
gdb info files
gdb info line 1820
gdb info registers
gdb info locals
 x/FMT ARDRESS

p *name@len
display *name@len
undisplay

 

 

 

 

 

 

你可能感兴趣的:(Stability)