Coredump introduction and how to enable and use it in Android to analyze Crash and other issues, coredumpandroid

Source: Internet
Author: User

Coredump introduction and how to enable and use it in Android to analyze Crash and other issues, coredumpandroid

Article directory:

Introduction and use of Coredump... 1

Directory... 2

1. What is Coredump. 3

Ii. Reasons for Coredump... 3

3. How to control the generation of Coredump. 4

4. Preparations for using Coredump... 4

5. Start Using Coredump. 5


1. What is Coredump?

Some C/C ++ programs or APK programs that call C/C ++ through JNI can be compiled, but errors may occur during runtime, for example, the common signal 11 (SIGSEGV), such programs can be compiled, in addition, such errors generally do not tell you that there is a problem in the code line like a compilation error, so debugging is difficult and troublesome.

Because the above debugging is difficult, a coredump mechanism (Many operating systems support this mechanism, which is not exclusive to Linux, nor dedicated to Android.), When the system (or standard library) detects an abnormal exit of a program error, it will dump the state of the entire process at that time and generate a coredump file,Usually, coredump contains the memory, register status, stack pointer, and memory management information when the program is running. It is lucky to store the current state of the program into a file, we now use the Android system based on the Linux kernel, which is supported by the Linux kernel native.

Ii. Causes of Coredump

There are many reasons for coredump. Here we will summarize the reasons based on previous experience:

1. Memory Access out of bounds

A) array access out of bounds due to incorrect subscript
B) when searching for a string, the string Terminator is used to determine whether the string ends. However, the string does not use the terminator normally.
C) use strcpy, strcat, sprintf, strcmp, strcasecmp, and other string operation functions to read/write the target string. Functions such as strncpy, strlcpy, strncat, strlcat, snprintf, strncmp, and strncasecmp should be used to prevent read/write from being out of bounds.

2. multi-threaded programs use functions that are not thread-safe.

Class 1st: functions that do not protect shared Variables

Class 2: State functions that span multiple calls

Class 3rd: returns a function pointing to a static variable pointer.

Class 2: functions that call functions with unsafe threads

3. data read/write with multiple threads is not locked

Scheduling occurs when one thread completes the condition judgment and preparation. If another thread releases it and sets it null or modifies the content, the program execution flow may be disordered or the pointer may be abnormal, or another exception occurs when the status is disordered.

4. Invalid Pointer

A) Use a null pointer.

B) Use Pointer conversion at will. A pointer pointing to a memory segment, unless it is determined that the memory is originally allocated to a structure or type, or an array of this structure or type, otherwise, instead of converting it to a pointer of this structure or type, you should copy this memory to a structure or type and then access this structure or type. This is because if the starting address of the memory segment is not aligned according to this structure or type, it is easy to access it because of bus error and core dump.

C) use a wild pointer that is not initialized, released, or in unknown state

5. Stack Overflow

Do not use large local variables (because all local variables are allocated on the stack). This can easily cause stack overflow and damage the stack and stack structure of the system, leading to inexplicable errors.

3. How to control the generation of Coredump

Directly modify the init. rc (system/core/rootdir) file and add it after setrlimit13 40 40:

Setrlimit 4-1-1

Mkdir/data/coredump 0777 system

Write/proc/sys/kernel/core_pattern/data/coredump/core. % e. % p

Write/proc/sys/fs/suid_dumpable 1

These commands aim to change the size of RLIMIT_CORE to unlimited. For details, see do_setrlimit function in keywords. h. RLIMIT_CORE is defined in Resource. h. Create a coredump folder in the data directory and grant the system the readable and writable permissions. Rewrite the storage path of the coredump file. Enable the program that calls seteuid ()/setegid () to generate coredump. By default, the system does not generate Coredump for these processes. You need to set suid_dumpable to 1.

Despite the above actions, coredump can only be generated for native programs. coredump is not generated for the apk process of zygotefork, zygote ignores the Linux configuration during initialization. By default, the coredump configuration is not generated. The system server is also composed of zygote fork, so coredump is not generated, therefore, it may be a headache to restart the system server due to thread crash. You need to generate coredump for the system server configuration, if other apk processes need to generate coredump, they also need to make special settings for zygote during startup initialization.

The special setting is to apply the rlimit configuration in the startup parameters of zygote, and the same is true for system server.

4. Preparations for using Coredump

By setting coredump when a problem occurs, we will use this coredump to analyze the specific problem. To do this, you must first sharpen the tool. First, you must prepare the environment and tools for parsing coredump.

1. GDB: because we are analyzing the coredump generated under the embedded linux kernel, we need a dedicated cross-compilation tool chain named arm-linux-androideabi-gdb. The approximate position is as follows:

Prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gdb

2. With GDB, it is not enough. We need a more user-friendly and easy-to-use graphical tool-Eclipse + CDT to view coredump

How to obtain:

A,Eclipse C/C ++ IDE for Luna SR2. Click to download bundle package.

B. Update your CDT plug-in ADT. help-install newsoftware-type url:Http://download.eclipse.org/tools/cdt/releases/8.6

3. Prepare the source code environment corresponding to the coredump version. It is best to keep the path consistent with the compiled version to locate the specific code.

4. Prepare the symbols corresponding to the coredump version.

5. Start to use Coredump. This section contains a large number of pictures to guide the configuration of the environment. Please download the document: introduction and use of Coredump.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.