How to capture the location of SIGSEGV in Linux-Linux general technology-Linux programming and kernel information. The following is a detailed description. In Linux programming (especially server programs), if the program is "illegal" due to memory out-of-bounds or other reasons, it will cause the program to die quietly. Beginners often do not know the cause of the program's death. I have suffered a long time from program death. In fact, in most cases, "invalid operations" are caused by "segment errors", that is, SIGSEGV. Find the position where the SIGSEGV signal is thrown, and find the cause of program death.
Some methods to capture SIGSEGV are listed below.
Assume that the program name is myprg, and its process ID (pid) is 2032.
Method 1:
#./Myprg // run the program
# Ps-ef | grep myprg // find the pid of myprg
# Gdb myprg 2032> debug. log // Let gdb take over the running of myprg
# (Gdb) continue
This method uses the gdb debugger to capture SIGSEGV. In the preceding example, the output information of gdb is saved to debug. log, and the terminal is closed. gdb does not exit and continues running until myprg exits due to an error. Gdb captures the error points.
Method 2:
#./Myprg // run the program
# Segment fault (core dumped) // The program is dead, and the system outputs "Segment fault"
# Gdb myprg core // use gdb to analyze the core File
This method uses core files for post-event analysis. However, the premise is that the system will generate core files.
How do I know if the system will generate a core file? Enter the following command:
# Ulimit-
Check the size limit of the current core file. If it is 0, change it to unlimited.
# Ulimit-S-c unlimited
Or modify/etc/profile, find unlimit-S-c 0, change 0 to unlimited, and restart the system.
In addition, if the program has installed the SIGSEGV exception handling function, the display of gdb myprg core is not a real error location. To see the actual error point, you must temporarily remove the exception handling function.
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