How to produce core under Linux, Debug core

Source: Internet
Author: User

how to produce core under Linux, Debug core

Excerpt from: Http://blog.163.com/[email protected]/blog/static/19554784201131791239753/

When an unusual program exits, the kernel generates a core file (a memory image, plus debugging information) in the current working directory. Using GDB to view the core file, you can indicate the number of files and rows in the code that caused the program to fail.


1.core file generation switch and size limit
1) Use the ULIMIT-C command to view the build switch for the core file. If the result is 0, this feature is turned off and the core file is not generated.
2) using the ulimit-c filesize command, you can limit the size of the core file (FileSize is KByte). If Ulimit-c Unlimited, the core file size is not restricted. If the generated information exceeds this size, it will be cropped, resulting in an incomplete core file. GDB will prompt for errors while debugging this core file.


The name and build path of the 2.core file
Core file generation Path:
Enter the executable file under the same path to run the command.
If the system-generated core file does not have any other extension names, it is all named Core. The new core file generation will overwrite the original core file.

1)/proc/sys/kernel/core_uses_pid can control whether a PID is added as an extension in the file name of the core file. The file content is 1, which means adding a PID as the extension, the resulting core file format is core.xxxx, and 0 means that the resulting core file is named Core.
You can modify this file by using the following command:
echo "1" >/proc/sys/kernel/core_uses_pid

2) Proc/sys/kernel/core_pattern can control where the core file is saved and the file name format. The
can modify this file by using the following command:
echo "/corefile/core-%e-%p-%t" > Core_pattern, you can unify the core file into the/corefile directory, The resulting 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 to add present UID
   %g-insert current GID into filename to add present GID
 &N bsp; %s-insert signal that caused the coredump into the filename adds a signal that leads to core generation
   %t-insert U NIX time that the coredump occurred to filename add a core file when you build Unix times
   %h-insert hostname where the Coredump happened into filename add host name
   %e-insert coredumping executable name into filename add command name


Viewing of 3.core files
The core file needs to be viewed using GDB.
GdB./a.out
Core-file core.xxxx
Use the BT command to see where the program went wrong.
The following two command modes have the same effect but do not take effect in some environments, so it is recommended to use the above command.
1) gdb-core=core.xxxx
File./a.out
Bt
2) Gdb-c core.xxxx
File./a.out
Bt


4. Debugging on the board using core files
If the operating system of the board is also linux,core the Debug method still applies. If GDB is not supported on the board, you can copy the Development Board's environment (dependent libraries), executable files, and core files to the PC's Linux.
Debugging the core file generated on the board on the PC requires using the cross-compiler's own gdb, And you need to specify the Solib-absolute-prefix and Solib-search-path two variables in gdb to ensure that GDB can find the dependent library path to the executable program. There is a way to create a configuration file that does not require each time you start gdb to configure the above variables, namely: Set up under the path of GDB to run. Gdbinit.
Configuration file Contents:
Set Solib-absolute-prefix Your_cross_compile_path
Set Solib-search-path Your_cross_compile_path
Set Solib-search-path Your_developer_tools_lib_path
Handle SIG32 nostop Noprint Pass


Note: The executable file to be debugged, at compile time need to add-g,core file to display error message normally! Sometimes the core information is large, beyond the space limits of the Development Board, the resulting core information is incomplete and unusable, can be mounted to the PC way to circumvent this.

How to produce core under Linux, Debug core

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.