Segment error segment fault positioning, that is, the core dump file and GDB location

Source: Internet
Author: User
Tags assert

Use C + + development systems sometimes have a segment error, which is Segment Fault . This kind of error program crashes directly, usually without any useful information output, it is difficult to locate the bug, so it is impossible to solve the problem. Today we present the core dump file and debug it using gdb to locate the segment error problem. This article is also used for memo.

First, Core Dump

core dump also known as core dump file call it file.

system does not generate by default Core Dump file, you can use Ulimit command to view and set.

view. Useulimit-corulimit-acommands to viewCore Dumpfile size, ifCore File Sizeto be0,indicates that the system is not automatically generated at this timeCore Dumpdocuments, specific circumstances1is shown.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/A7/wKioL1RtUgegqo2HAAJYCKi5u3o680.jpg "title=" 1.png " Width= "height=" 282 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px;height:282px; "alt=" Wkiol1rtugegqo2haajycki5u3o680.jpg "/>

Figure 1

set. We can pass command, core file size unlimited file, specific operation

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/A7/wKioL1RtUkGTLdz6AAJp9V510AI777.jpg "title=" 2.png " Width= "height=" 325 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px;height:325px; "alt=" Wkiol1rtukgtldz6aajp9v510ai777.jpg "/>

Figure 2

Second, paragraph error procedure

We write a simple section error program and name it Core_test.cpp , the code is as follows. Compile and run, the system automatically produces the core file,3 .

#include <assert.h> int main () {assert (0); return 0;}

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/A7/wKioL1RtUwWh4T3JAAFTbrm8PuU480.jpg "title=" 3.png " alt= "Wkiol1rtuwwh4t3jaaftbrm8puu480.jpg"/>

Figure 3

Third, core file naming

core dump core Specify more information when naming the file.

the process number. The following settings allow you to make the core dump file a core.pid form. as shown in 4, the system automatically generates the core.3430 file.

echo "1" >/proc/sys/kernel/core_uses_pid


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/AA/wKiom1RtUsnBtOR-AALfUI2n0aI075.jpg "title=" 4.png " alt= "Wkiom1rtusnbtor-aalfui2n0ai075.jpg"/>

Figure 4

more information. The following settings allow you to make the core dump file a core-exe-pid-time form. as shown in 4, the system automatically generates the core-core_test-3465-1416037828 file.

echo "/coredir/core-%e-%p-%t" >/proc/sys/kernel/core_pattern/

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/A7/wKioL1RtU4nS6Vo-AANcYWoLp7E883.jpg "title=" 5. PNG "alt=" wkiol1rtu4ns6vo-aancywolp7e883.jpg "/> figure 5

if we want to make further reservations , Core The name of the file can be set according to the information in table 1.

Table 1

%% single % character

%p Process ID

%u Process Actual user ID

%g actual group of processes ID

%s core dump

%t Core Dump the time stamp ( number of seconds from 1970 year 1 months 1 days )

%h Host name

%eprogram file name


Iv. using GDB to locate the core dump error

gdb–c core and command location error. Perhaps because of the configuration, I actually found that if I use the gdb–c core

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/AA/wKiom1RtU42zZY7WAARpO1hwGAo597.jpg "title=" 6.png " Width= "height=" 321 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:321px; "alt=" Wkiom1rtu42zzy7waarpo1hwgao597.jpg "/>

Figure 6

in the end, I usegdb Core_test CoreCommand (wherecore_testis happeningDumpthe executable program,Coreis aCore File), entergdbafter that, then usewherecommand that can be positioned to occurDumpthe code location, and has good readability, the specific7is shown.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/A8/wKioL1RtVC_Qz0RGAAd1b_ZMjqA244.jpg "title=" 7.png " Width= "height=" 337 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:600PX;HEIGHT:337PX; "alt=" wkiol1rtvc_ Qz0rgaad1b_zmjqa244.jpg "/>

Figure 7


Reference

http://blog.csdn.net/ithomer/article/details/5945152




This article is from the "Talking Cabbage" blog, please be sure to keep this source http://speakingbaicai.blog.51cto.com/5667326/1579966

Segment error segment fault positioning, that is, the core dump file and GDB location

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.