How to debug core files in Linux

Source: Internet
Author: User

When a program unexpectedly exits, the kernel will generate a core file (a memory image with debugging information added) in the current working directory ). You can use gdb to view the core file and indicate the file and number of lines of code that cause program errors. 1. core File generation switch and size limit 1) Use the ulimit-c command to view the core file generation switch. If the result is 0, this function is disabled and core files are not generated. 2) use the ulimit-c filesize command to limit the size of the core file (The unit of filesize is kbyte ). If ulimit-c unlimited is used, the size of the core file is not limited. If the generated information exceeds this size, it will be cropped to generate an incomplete core file. When debugging this core file, gdb will prompt an error. 2. core File Name and generation path core file generation path: Enter the same path as the executable file running command. If the core file generated by the system does not contain any other extension names, it is all named core. The new core file will overwrite the original core file. Www.2cto.com 1)/proc/sys/kernel/core_uses_pid can control whether pid is added to the file name of the core file as an extension. If the file content is 1, the pid is added as the extension, and the generated core file format is core. xxxx. If it is 0, the generated core file is named core. Run the following command to modify this file: echo "1">/proc/sys/kernel/core_uses_pid 2) proc/sys/kernel/core_pattern to control the core file storage location and file name format. You can run the following command to modify this file: echo "/corefile/core-% e-% p-% t"> core_pattern. The core file can be generated in the/corefile directory, the generated file name is core-command name-pid-timestamp. The following is a list of parameters: % p-insert pid into filename add pid % u-insert current uid into filename add current uid % g-insert current gid into filename add current gid % s-insert signal that caused the coredump add into the filename to generate the core signal % t-insert UNIX time that the coredump occurred into filename to add the unix when the core file is generated Time % h-insert hostname where the coredump happened into filename add host name % e-insert coredumping executable name into filename add command name 3. view the core file using gdb. Gdb./a. out core-file core. xxxx use the bt command to see where the program went wrong. The following two command methods have the same effect, but they do not take effect in some environments. Therefore, we recommend that you use the preceding command. 1) gdb-core = core. xxxxfile. /. outbt 2) gdb-c core. xxxxfile. /. outbt 4. use core File debugging on the development board. If the operating system of the Development Board is linux, the core debugging method is still applicable. If gdb is not supported on the Development Board, you can copy the Development Board environment (dependent libraries), executable files, and core files to linux on the PC. To debug the core file generated on the Development Board on a PC, you must use the gdb that comes with the cross compiler, in addition, you must specify the solib-absolute-prefix and solib-search-path variables in gdb to ensure that gdb can find the dependent LIBRARY path of the executable program. There is a way to create a configuration file. You do not need to configure the above variables every time you start gdb, that is, create. gdbinit in the path to be run gdb. Content of the configuration file www.2cto.com: set solib-absolute-prefix YOUR_CROSS_COMPILE_PATHset solib-search-path route SIG32 nostop noprint pass. Note: executable file to be debugged, during compilation, you must add-g to the core file to Display Error information normally! Sometimes the core information is too large to exceed the size limit of the Development Board. The generated core information is incomplete and cannot be used. You can avoid this by attaching it to a PC. From Xiao Wei's column

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.