Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Core dump presentation

3.593 Aufrufe

Veröffentlicht am

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

  • Als Erste(r) kommentieren

Core dump presentation

  1. 1. Core dumpHow to: Generate and Use a CoreFileLinux vs Solaris ExampleStacy Watts10/24/2012CS 201 Fall 2012Portland State University
  2. 2. About these slidesThese slides are geared towards the students inCS 201 at Portland State University.For folks outside our class I am assuming you: Have some programming experience Havent yet explored the idea of a core dump in detail.My habit for filenames is camelCase as you willsee in these slides. Your habitmight_be_different.
  3. 3. coredump vs segfaultProgramming we get to see both of thesemessages. segfault is an access violation. You went somewhere in memory you didnt 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. 4. What is a core dump?“A core dump consists of the recorded state of theworking memory of a computer program at a specifictime, generally when the program has terminatedabnormally (crashed).[1] In practice, other key pieces ofprogram state are usually dumped at the same time,including the processor registers, which may includethe program counter and stack pointer, memorymanagement information, and other processor andoperating system flags and information. The namecomes from the once-standard core memory technology.Core dumps are often used to diagnose or debug errorsin computer programs.” http://wiki.answers.com/Q/What_is_a_core_dump
  5. 5. How can you get one? (…and why would I want one?)You can get a core dump fairly easily by doingsomething programmatically you arent allowed todo.All you need are one of the following conditions: Is the memory youre 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 0A value greater than 0 will generate a corefile
  6. 6. On multi-user systems like the linux or unix systemson campus you are not guaranteed a file isgenerated. 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 filecan be read by gdb provided you compiled it on thesame 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. 7. When a program dumps core, the entire imprint ofwhat was happening at that point in programexecution 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. 8. Identical source program code: linux left, solaris rightGenerated using gcc –s fileName.c
  9. 9. Linux vs Solaris exampleNot apples to apples – different machines meansdifferent 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. 10. Show Linux example using gcc –g file gdb file gdb commands backtrace, etcShow Solaris example gcc –g file a.out gdb commands backtrace, etc.Show differences in even the machine code.
  11. 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. 12. Using a core fileTo use a core file once generated, these slideswill use gdbTo start gdb with a core file, issue the systemspecific command from the shell: gdb eg1 core gdb eg1 -c coreFileGdb will load up the core file, eg1s programlisting, show how the program terminated andpresent a message very much like weve just runthe program under gdb:
  13. 13. ...Core was generated by `./eg1.Program terminated with signal 8, Floating pointexception....#0 0x80483ea in wib (no1=8, no2=8) at eg1.c:77 result = no1 / diff;
  14. 14. While we see there are differences linux to unixon the details of the corefile generated, once weare using gdb as our interface to that file, wewon’t notice the differences in our basic usage ofthe corefile.Gdb does the symbol parsing and interpretationfor us, making it a very handy tool.The file on its own passed to a system it wasn’tcompiled on won’t do you much good. You won’thave the references to the symbols used in theprogram.Thus, a corefile on its own is interesting, but notas useful as a corefile passed in with theprogram you compiled.
  15. 15. Questions?
  16. 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