Linux coredump debugging

Source: Internet
Author: User

Linux coredump debugging 1) how to generate a coredump file? Log on to the LINUX server and enter echo "ulimit-c 1024">/etc/profile at any location to log out of LINUX and log on to LINUX again. Type ulimit-c. If 1024 is displayed, coredump is enabled. 1024 the size of the core file cannot exceed kb. You can use the unlimited parameter to cancel the limit ulimit-c unlimited2 ). A Brief Introduction to core files when a program crashes, it generally generates a core file under a specified directory. The core file is only a memory image (with debugging information added) and is mainly used for debugging. 3 ). to enable or disable the generation of core files, run the following command to prevent the system from generating core files: ulimit-c 0 to check whether the option for generating core files is Enabled: ulimit-a this command will display all user customization, where option-a represents "all ". You can also modify the system file to adjust the core option. in/etc/profile, this statement is usually used to prohibit the generation of core files. This setting is generally reasonable: # No core files by defaultulimit-S-c 0>/dev/null 2> & 1 but sometimes for debugging problems during development, you still need to open the settings generated by the core file in a specific user environment. In the user's ~ /. Add ulimit-c unlimited to the bash_profile so that specific users can generate core files. If ulimit-c 0 is used, core files are not allowed to be generated, while ulimit-c 1024 limits the size of the generated core files to kb4 ). set the Core Dump file directory and naming rules for core Dump./proc/sys/kernel/core_uses_pid can be used to control whether pid is added to the file name of the generated Core file as an extension, if it is added, the file content is 1; otherwise, it is 0 proc/sys/kernel/core_pattern. You can set the location or file name of the formatted core file, for example, if the original file content is core-% e, you can modify it as follows: echo "/corefile/core-% e-% p-% t"> core_pattern controls the generated core files to be stored in the/corefile directory, the generated file name is core-command name-pid-timestamp. The following is the parameter list: % p-inser T 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 into the filename add the signal % t-insert UNIX time that causes the core to be generated that the coredump occurred into filename is added to the unix time when the core file is generated % h-insert hostname where the coredump happened into filename is added to the host name % e-insert coredumping executable name into f Ilename add command name 5 ). use the core file and enter gdb-c core in the directory where the core file is located. It starts the GNU Debugger to debug the core file and displays the program name that generates the core file, abort the program signal and so on. You need to associate the program file that generates the core file for debugging. Use the file command in gdb to associate the program file. If you already know which program generates the core file, for example, if MyServer crashes to generate core.12345, use this command to debug: gdb-c core MyServer6 ). run the command kill-s SIGSEGV $7 in a small way to test and generate a core file ). use core File debugging on the development board ------------------------- if the Development Board's operating system is also linux, the core debugging method is still applicable. If gdb is not supported on the Development Board, you can copy the Development Board environment (header files, libraries), executable files, and core files to linux on the PC and run relevant commands. Note: The executable file to be debugged must be added to-g during compilation so that the core file can display error information normally! Note: 8). In Linux, ensure that Coredump is generated when the program crashes: 1. Ensure that the directory where Coredump is stored exists and that the process has the write permission on the directory. The directory that stores Coredump is the current directory of the process, which is generally the directory where the command was issued to start the process. However, if the script is started, the script may modify the current directory, and the current directory of the process will be different from the directory where the script was originally executed. In this case, you can view the target of the "/proc/process pid>/cwd" symbolic link to determine the real current directory address of the process. You can also view the processes started by the system service in this way. 2. If the program calls seteuid ()/setegid () to change the valid user or group of the process, the system will not generate Coredump for these processes by default. Many service programs call seteuid (), such as MySQL. No matter which user you use to run mysqld_safe to start MySQL, the effective user of mysqld is always the msyql user. If you run A program with user A, but the user who sees the program in ps is B, then these processes call seteuid. To enable these processes to generate coredump, you need to change the content of the/proc/sys/fs/suid_dumpable file to 1 (usually 0 by default ). 3. This is generally known as setting a large enough Core file size limit. The Core file size generated when the program crashes is the memory size occupied by the program running. However, when a program crashes, the behavior cannot be estimated as usual. For example, errors such as buffer overflow may cause the stack to be destroyed. Therefore, the value of a variable is often changed to a mess, then the program uses this size to apply for memory, which may cause the program to occupy more memory than usual. Therefore, no matter how little memory is occupied during normal running of the program, make sure to generate the Core file or set the size limit to unlimited.

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.