SlideShare a Scribd company logo
1 of 16
Core dump
How to: Generate and Use a Core
File
Linux vs Solaris Example

Stacy Watts
10/24/2012
CS 201 Fall 2012
Portland State University
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.
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.
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
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
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.
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
Identical source program code: linux left, solaris right
Generated using gcc –s fileName.c
Linux vs Solaris example
Not apples to apples – different machines means
different arch, also different gcc versions.
Commands we will use:
     gdb executableName coreFile
         Starts gdb with the corefile loaded
      info locals
      print
      info args
      list
      backtrace
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.
Running process example:
   Core File Creation
 gdb 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)
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:
...

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;
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.
Questions?
References list:
   http://www.ibm.com/developerworks/library/l-gdb/
   http://prefetch.net/blog/index.php/2006/12/21/generati
   ng-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

More Related Content

Viewers also liked

BGP Advance Technique by Steven & James
BGP Advance Technique by Steven & JamesBGP Advance Technique by Steven & James
BGP Advance Technique by Steven & James
Febrian ‎
 

Viewers also liked (19)

DDD
DDDDDD
DDD
 
Aag c45 697761
Aag c45 697761Aag c45 697761
Aag c45 697761
 
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
Reverse, Multi-Process and Non-Stop Debugging come to the CDTReverse, Multi-Process and Non-Stop Debugging come to the CDT
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
 
Real time debugging: using non-intrusive tracepoints to debug live systems
Real time debugging: using non-intrusive tracepoints to debug live systemsReal time debugging: using non-intrusive tracepoints to debug live systems
Real time debugging: using non-intrusive tracepoints to debug live systems
 
Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!
 
리눅스 커널 디버거 KGDB/KDB
리눅스 커널 디버거 KGDB/KDB리눅스 커널 디버거 KGDB/KDB
리눅스 커널 디버거 KGDB/KDB
 
Udev
UdevUdev
Udev
 
Linux booting process!!
Linux booting process!!Linux booting process!!
Linux booting process!!
 
Vim Rocks!
Vim Rocks!Vim Rocks!
Vim Rocks!
 
Linux booting Process
Linux booting ProcessLinux booting Process
Linux booting Process
 
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
 
Linux installation and booting process
Linux installation and booting processLinux installation and booting process
Linux installation and booting process
 
Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack
 
Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)
 
BGP Advance Technique by Steven & James
BGP Advance Technique by Steven & JamesBGP Advance Technique by Steven & James
BGP Advance Technique by Steven & James
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
BGP Traffic Engineering / Routing Optimisation
BGP Traffic Engineering / Routing OptimisationBGP Traffic Engineering / Routing Optimisation
BGP Traffic Engineering / Routing Optimisation
 
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platform
 

Core dump presentation

  • 1. Core dump How to: Generate and Use a Core File Linux vs Solaris Example Stacy Watts 10/24/2012 CS 201 Fall 2012 Portland 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 coreFile Starts 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 Creation gdb 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.
  • 16. References list: http://www.ibm.com/developerworks/library/l-gdb/ http://prefetch.net/blog/index.php/2006/12/21/generati ng-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