core dump presentation

Post on 01-Dec-2014

2.766 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Presentation to the class on how to use and create core dump files. also superficially covers the differences.

TRANSCRIPT

Core dumpHow to: Generate and Use a

Core File

Linux vs Solaris Example

Stacy Watts10/24/2012CS 201 Fall 2012Portland State University

2

About these slides

These slides are geared towards the students in CS 201 at Portland State University.  

For folks outside our class I am assuming you:

Have some programming experience

Haven't yet explored the idea of a core dump in detail.

My habit for filenames is camelCase as you will see in these slides. Your habit might_be_different.

3

coredump vs segfault

Programming we get to see both of these messages.

segfault is an access violation.  You went somewhere in memory you didn't have permission to go!

coredump refers both to the action of taking a complete snapshot of the memory and registers, and the file generated by that action.  

4

What is a core dump?

“A core dump consists of the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed).[1] In practice, other key pieces of program state are usually dumped at the same time, including the processor registers, which may include the program counter and stack pointer, memory management information, and other processor and operating system flags and information. The name comes from the once-standard core memory technology. Core dumps are often used to diagnose or debug errors in computer programs.”

http://wiki.answers.com/Q/What_is_a_core_dump

5

How can you get one?

(…and why would I want one?)

You can get a core dump fairly easily by doing something programmatically you aren't allowed to do.  

All you need are one of the following conditions:Is the memory you're trying to change yours?  

Am I expecting an explicit type conversion?

Did I do something horribly wrong?

You also need the command-line value of “ulimit –c” to not be 0

A value greater than 0 will generate a corefile

6

On multi-user systems like the linux or unix systems on campus you are not guaranteed a file is generated. ulimit –c is often set to 0.

To remove the corefile size limit: ulimit –c unlimited

On Ubuntu, even with this set, if you are not root, you may not get a core file. It is easiest to generate it through gdb.

You are now ready to generate a core file. That file can be read by gdb provided you compiled it on the same machine.  

to read in an existing file use:gdb program corefile

where program is your compiled program and corefile is the file that was dumped.

We can get all sorts of information back out.

7

When a program dumps core, the entire imprint of what was happening at that point in program execution is sent to a file.  This includes:

recorded memory state

processor registers

program counter

stack pointer

memory management information

any other flags and information that system includes

8

Identical source program code: linux left, solaris right

Generated using gcc –s fileName.c

9

Linux vs Solaris example

Not apples to apples – different machines means different arch, also different gcc versions.

Commands we will use:

gdb executableName coreFileStarts gdb with the corefile loaded

info locals

print

info args

list

backtrace

10

Show Linux example using

gcc –g file

gdb file

gdb commands

backtrace, etc

Show Solaris example

gcc –g file

a.out

gdb commands

backtrace, etc.

Show differences in even the machine code.

11

Running process example: Core File

Creationgdb has a “generate-core-file” command to create a core file(this example is off a running process):

gdb -q – 1597 

Generates a core file of the currently running program.

This is great for infinite loops

Also great for hung programs (due to infinite loops or not)

12

Using a core file

To use a core file once generated, these slides will use gdb

To start gdb with a core file, issue the system specific command from the shell:

gdb eg1 core

gdb eg1 -c coreFile

Gdb will load up the core file, eg1's program listing, show how the program terminated and present a message very much like we've just run the program under gdb:

13

...

Core was generated by `./eg1'.

Program terminated with signal 8, Floating point exception.

...

#0  0x80483ea in wib (no1=8, no2=8) at eg1.c:7

7         result = no1 / diff;

14

While we see there are differences linux to unix on the details of the corefile generated, once we are using gdb as our interface to that file, we won’t notice the differences in our basic usage of the corefile.

Gdb does the symbol parsing and interpretation for us, making it a very handy tool.

The file on its own passed to a system it wasn’t compiled on won’t do you much good. You won’t have the references to the symbols used in the program.

Thus, a corefile on its own is interesting, but not as useful as a corefile passed in with the program you compiled.

15

Questions?

16

References list:

http://www.ibm.com/developerworks/library/l-gdb/

http://prefetch.net/blog/index.php/2006/12/21/generating-core-files-from-gdb/

http://docs.oracle.com/cd/E23823_01/html/816-5174/core-4.html

http://stackoverflow.com/questions/17965/generate-a-core-dump-in-linux

http://docs.oracle.com/cd/E23823_01/html/816-5165/gcore-1.html#REFMAN1gcore-1

http://wiki.answers.com/Q/What_is_a_core_dump

top related