Coredump introduction and how to open and use in Android to analyze problems such as crash

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:24px;color:#009900;"><strong></strong></span></p></p><span style="color: rgb(0, 176, 80);"><span style="color: rgb(0, 176, 80);">article directory:</span></span><p><p></p></p> <p><p><strong><span style="font-size:24px;">Coredump Introduction and use <span style="color: windowtext;">...</span> <span style="color: windowtext;">1</span></span></strong></p></p> <p><p><strong><span style="font-size:24px;">Directory <span style="color: windowtext;">...</span> <span style="color: windowtext;">2</span></span></strong></p></p> <p><p><strong><span style="font-size:24px;">first, what is Coredump<span style="color: windowtext;">.</span> <span style="color: windowtext;">3</span></span></strong></p></p> <p><p><strong><span style="font-size:24px;">second, the cause of Coredump <span style="color: windowtext;"></span> ... <span style="color: windowtext;">3</span></span></strong></p></p> <p><p><strong><span style="font-size:24px;">third, how to control the generation of Coredump<span style="color: windowtext;">.</span> <span style="color: windowtext;">4</span></span></strong></p></p> <p><p><strong><span style="font-size:24px;">Iv. preparation for use of Coredump <span style="color: windowtext;"></span> ... <span style="color: windowtext;">4</span></span></strong></p></p> <p><p><strong><span style="font-size:24px;">V. Start using Coredump<span style="color: windowtext;">.</span> <span style="color: windowtext;">5</span></span></strong></p></p><p><p><span style="font-size:24px;"><span style="color:windowtext;"><br></span></span></p></p><p><p><span style="font-size:24px;"></span></p></p><span style="color:#00B050;"><span style="color:#00B050;">first, What is</span></span><span style="color:#00B050;"><span style="color:#00B050;">Coredump</span></span><br><p><p></p></p><p style="color: windowtext;"><p style="color:windowtext;"><span style="font-size:14px;"> some C + + programs or the APK program that calls C + + via JNI can be compiled, but errors occur at run Time. such as common signal one (SIGSEGV), such a program can be compiled, and such errors generally do not like a compilation error to tell you the specific line in the code is problematic, so debugging is more difficult and trouble. </span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Because of this difficult debug situation above, so the coredump this mechanism ( <strong> <span style="color:red;">Many operating systems support this mechanism, not</span> <span style="color:red;"></span> <span style="color:red;">unique to Linux, nor specifically for</span> <span style="color:red;">Android </span> <span style="color:red;"></span> </strong> ), the system (or standard Library) will dump the state of the process at the time of the abnormal exit of the program, generating a coredump file, <strong> <span style="color:#0070C0;">usually</span> <span style="color:#0070C0;"> Coredump</span> <span style="color:#0070C0;">contains the memory of the program runtime, register state, stack pointers, memory management information, etc., can be understood as the current state of the program work to store a file, fortunately, we now use</span> <span style="color:#0070C0;">Android</span> <span style="color:#0070C0;">system is based on</span> <span style="color:#0070C0;">Linux</span> <span style="color:#0070C0;">kernel,</span> <span style="color:#0070C0;">Linux</span> <span style="color:#0070C0;">The kernel natively supports this MECHANISM. </span></strong></span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:24px;"><span style="color:windowtext;"></span></span></p></p><span style="color:#00B050;"><span style="color:#00B050;">second, Coredump</span></span><span style="color:#00B050;"><span style="color:#00B050;">cause of the production</span></span><span style="color: rgb(0, 176, 80);"><span style="color: rgb(0, 176, 80);"></span></span><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">There are many reasons for the coredump of the program, and here is a summary based on previous experience:</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">1. <span style="color:rgb(0, 112, 192);">Memory Access</span> is out of bounds</span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">A) array access is out of bounds due to the use of the wrong subscript<br>B) when searching for a string, rely on the string terminator to determine whether the string ends, but the string does not have a normal use terminator<br>C) use strcpy,strcat, sprintf, strcmp, strcasecmp and other string manipulation functions to read/write the target string. You should use strncpy,strlcpy, strncat, strlcat, snprintf, strncmp, strncasecmp and other functions to prevent read and write out of BOUNDS.</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">2 <span style="color:rgb(0, 112, 192);">. Multithreaded programs use a thread unsafe function</span></span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">Class 1th: functions that do not protect shared variables</span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">Class 2nd: maintaining state functions that span multiple calls</span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">Class 3rd: returns a function that points to a static variable pointer</span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">Class 4th: functions that invoke thread unsafe functions</span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">3, <span style="color:rgb(0, 112, 192);">multi-threaded Read and write data is not locked protection</span></span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">A thread completes a condition to determine when a schedule is ready to be used, another thread releases it, or modifies the content, causing the program to run out of flow, or the pointer is abnormal, or the state is confused with another exception</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">4. <span style="color:rgb(0, 112, 192);">Illegal pointers</span></span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">A) use a null pointer</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">B) feel free to use pointer conversions. A pointer to a piece of memory, unless it is determined that the memory was originally assigned to a struct or type, or to an array of this structure or type, do not convert it to a pointer of this structure or type, but should copy the memory into one such structure or type, and then access the structure or type. This is because if the start address of this memory is not aligned with this structure or type, then it is easy to access it because the bus error and core dump</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">C) use a wild pointer that has not been initialized or has been released or is in an unknown state</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;">5. <span style="color:rgb(0, 112, 192);">Stack Overflow</span></span></strong></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Do not use large local variables (because local variables are allocated on the stack), which can easily cause stack overflow, destroy the stack and heap structure of the system, resulting in inexplicable errors</span></p></p><span style="color:#00B050;"><span style="color:#00B050;">third, How to control the production</span></span><span style="color:#00B050;"><span style="color:#00B050;">Coredump</span></span><br><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Directly modify the Init.rc (system/core/rootdir) file and add it after setrlimit13 40 40:</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Setrlimit 4-1-1</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Mkdir/data/coredump 0777 System System</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Write/proc/sys/kernel/core_pattern/data/coredump/core.%e.%p</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Write/proc/sys/fs/suid_dumpable 1</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">The purpose of these commands is to modify the size of the Rlimit_core to unlimited, as described in Keywords.h do_setrlimit functions. Where Rlimit_core is defined in RESOURCE.H. Create the Coredump folder under the Data directory and give the system readable writable permissions. Overwrite the storage path of the Coredump File. Enables programs that call Seteuid ()/setegid () to generate coredump, and by default the system does not generate coredump for those processes, which requires a setting of suid_dumpable of 1.</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">Although the above actions are done, but still only for the native program to generate coredump, for the zygotefork apk process will not generate coredump, because zygote in the initialization of the time will ignore the Linux configuration, With a configuration that does not generate Coredump by default, system server is also zygote fork, so it does not produce coredump, so it can be a headache if a restart occurs because of the thread crash of system Server. You need to build Coredump for system server configuration, and if other apk processes need to produce coredump also need to make special settings for zygote when booting up.</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><strong><span style="font-size:14px;"><span style="color:#0070C0;">the so-called special setting is the</span> <span style="color:#0070C0;">zygote</span> <span style="color:#0070C0;">application in the startup parameters</span> <span style="color:#0070C0;">Rlimit</span> <span style="color:#0070C0;">the configuration,</span> <span style="color:#0070C0;">System Server</span> <span style="color:#0070C0;">is the Same. </span></span></strong></p></p><span style="color:#00B050;"><span style="color:#00B050;">Iv. Use of</span></span><span style="color:#00B050;"><span style="color:#00B050;">Coredump</span></span><span style="color:#00B050;"><span style="color:#00B050;">the preparation</span></span><br><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">By setting the Coredump in the case of a problem, we will then use this coredump to analyze the specific problem for Us. 工欲善其事 its prerequisite, we first have to be ready to parse coredump's environment and Tools.</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">1, GDB, because we are analysis of embedded Linux kernel generated coredump, so we need specialized cross-compiler tool chain in the arm-linux-androideabi-gdb, approximate location:</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="color:red;"><span style="font-size:14px;">Prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gdb</span></span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">2, with GDB is not enough, we need a more user-friendly, Easy-to-use graphical tools-eclipse+cdt to view Coredump</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">How to Get:</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">a,<strong><span style="color:rgb(112, 54, 190);">Eclipse C + + IDE for Luna SR2</span></strong>. Click-to-download bundle Package.</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">B. Update your CDT plugin in adt, help-"install newsoftware-" type url:<strong><span style="color:rgb(112, 54, 190);">http://download.eclipse.org/tools/cdt/releases/8.6 </span></strong></span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">3. Prepare the source code environment corresponding to the Coredump version, preferably consistent with the path of the compiled version, in order to locate the specific code</span></p></p><p style="color: windowtext;"><p style="color: windowtext;"><span style="font-size:14px;">4. Prepare the symbols corresponding to the Coredump version</span></p></p><p><p></p></p><span style="color:#00B050;"><span style="color:#00B050;">v. Start using</span></span><span style="color:#00B050;"><span style="color:#00B050;">Coredump</span></span><span style="color: rgb(0, 176, 80);"><span style="color: rgb(0, 176, 80);"></span></span><span style="font-size:14px;"><span style="font-size:14px;">This section contains a large number of images that guide the configuration environment, please download the documentation directly from the required students:</span></span>Coredump Introduction and use<br><p><p></p></p><p><p>Coredump introduction and how to open and use in Android to analyze problems such as crash</p></p></span>

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.