Core Dump generation and debugging

Source: Internet
Author: User

First, let's see what machine I use:

$ Uname-
Linux Dev 2.4.21-9.30 axsmp #1 SMP Wed May 26 23:37:09 EDT 2004
I686 i686 i386 GNU/Linux

Take a look at some default parameters. Note that the core file size is 0, and the core file will not be generated when a program error occurs.

$ Ulimit-
Core File size (blocks,-C)
0
Data seg size (Kbytes,-d) Unlimited
File size (blocks,-f)
Unlimited
Max locked memory (Kbytes,-l) 4
Max memory size (Kbytes,-m)
Unlimited
Open File (-N) 2048
Pipe size (512 bytes,-p) 8
Stack size
(Kbytes,-S) 10240
CPU time (seconds,-T) Unlimited
Max user processes
(-U) 7168
Virtual Memory (Kbytes,-v) Unlimited

Write a simple program to see if the core file is generated.

$ More Foo. c

# Include <stdio. h>

Static void sub (void );

Int main (void)
{
Sub ();
Return 0;
}

Static void sub (void)
{
Int * P = NULL;

/* Derefernce a null pointer, exact CT core dump.
*/
Printf ("% d", * P );
}

$ Gcc-wall-G Foo. c
$./A. Out
Segmentation
Fault

$ LS-L core .*
Ls: core. *: no such file or
Directory

The core file is not found. Modify the ulimit settings to generate the file. 1024 is random. If the core file contains more than 1024 blocks, it cannot be generated.

$ Ulimit-C 1024 (reporter Note: Using-C unlimited does not limit the core file size)

$ Ulimit-
Core File size (blocks,-C)
1024
Data seg size (Kbytes,-d) Unlimited
File size (blocks,-f)
Unlimited
Max locked memory (Kbytes,-l) 4
Max memory size (Kbytes,-m)
Unlimited
Open File (-N) 2048
Pipe size (512 bytes,-p) 8
Stack size
(Kbytes,-S) 10240
CPU time (seconds,-T) Unlimited
Max user processes
(-U) 7168
Virtual Memory (Kbytes,-v) Unlimited

$./A. Out
Segmentation fault (core dumped)
$
Ls-L core .*
-RW ------- 1 uniware 53248 Jun 30
17: 10 core.9128

Pay attention to the output information above. Multiple (Core
Dumped ). A core file is generated, and 9128 is the PID of the process. Let's use GDB to look at this core.

$ GDB -- core = core.9128 or GDB./test. Core
Gnu gdb Asianux
(6.0post-0.20040223.17.1ax)
Copyright 2004 Free Software Foundation,
Inc.
GDB is free software, covered by the GNU General Public License, and you
Are
Welcome to change it and/or distribute copies of it under certain
Conditions.
Type "show copying" to see the conditions.
There is absolutely
No warranty for GDB. Type "show warranty" for details.
This GDB was
Configured as "i386-asianux-linux-gnu ".
Core was generated
'./A. out '.
Program terminated with signal 11, segmentation fault.
#0
0x08048373 in ?? ()
(GDB) BT
#0 0x08048373 in ??
()
#1 0xbfffd8f8 in ?? ()
#2 0x0804839e in ?? ()
#3 0xb74cc6b3 in ??
()
#4 0x00000000 in ?? ()

At this time, you can't see backtrace with BT, that is, the call stack. It turns out that GDB does not know where the symbol information is. Let's tell it:

(GDB) file./A. Out
Reading symbols from
./A. Out... done.
Using host libthread_db Library
"/Lib/tls/libthread_db.so.1 ".
(GDB) BT
#0 0x08048373 in sub () at Foo. C: 17
#1 0x08048359 in main ()
Foo. C: 8

Now the backtrace is available.

(GDB) L
8
Sub ();
9 return 0;
10}
11
12 static void
Sub (void)
13 {
14 int * P = NULL;
15
16 /*
Derefernce a null pointer, exact CT core dump .*/
17
Printf ("% d", * P );

 

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.