Cause and position analysis of segmentation fault (core dumped) _GCC

Source: Internet
Author: User
Tags gdb debugger
One segmentation fault (core dumped) reason segmentation fault (core dumped) is caused by improper memory operations. Null pointer, wild pointer read and write operation, array access, destroy constants, etc. As in the recent potential energy map code of the linked list operations, the list of additions and releases including assignment, and so on, such as improper operation may cause program crashes. Initializing each pointer to null is a good way to avoid this problem. The best way to troubleshoot this problem is to debug. Two solution 1, use GDB to view the core file in the program after the crash in the directory will produce core.xxxx files, the core file contains error messages. If there is no core file, it is because the system has a core file size of 0. Ulimit-a can be queried by command. The core file size is unrestricted after the Ulimit-c Unlimited command has been executed. The core.xxxx file appears in the directory after you run the program again. Use GDB./file core.xxxx to see the line information for the error. Where file is the original executed program name. 2, using the GDB debugger, such as the above process can not solve the problem, the following can be used to step into the GDB program. Recompile the program and add-G to the compilation command. Such as: 
	Gcc-lm-o3-g file.c-o File
Then use the GDB command
	GDB file
Start the debugging process.

Enter start causes the program to run to the first line in main to run the code. Next or N to execute the next line of program, until xx execution to XX line, print or p can output variable value, b xx used to set breakpoints in XX line, run or R to execute program to the next breakpoint, D xx delete xx line breakpoint. We can run the program first, when it prompts for error line information. Then until to the first 5 lines of the error line, alternately executing next and print, outputting the value of the variable or pointer associated with the error row variable. Which line is the underlying operation of the final positioning error. Modify the Can.

This conflict bug was debugged for a whole day, and finally found fault. The new node pointer to the chain1 is given to chain2 after the new footer is added to the two list. A malloc function error occurred while causing the second loop. Be sure to change the name of the variable when copy repeats the code--.

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.