Friday, April 9, 2010

Core Dump

You can make an application core dump if you use the Unix command:

ulimit -c unlimited

Will dump when an application seg faults. The default setting was '0'. A core file is basically a file which contains the complete state of the process when it crashed. To determine where the problem occurred, run gdb:

gdb

Then run

(gdb) core [app_name.]core

Then use the gdb command 'bt' to back trace.

Compiling with g++ version 4.1.1, and the -g switch I still didn't get anything very 'trace-able', so I had to bite the bullet and try running the application from within gdb. Easy you say, but this application takes its input from another application on STDIN. To do that with my application (called a4vmsim):


gdb a4vmsim
(gdb) run params ... < input.txt


And that did the trick! I got the following output:

Program received signal SIGSEGV, Segmentation fault.
0x0804c004 in Page::setReferenceFlag (this=0x80540b8) at page.h:23
23 void setReferenceFlag(void){ flags |= REF_BIT; }


Using back trace:

(gdb) bt
#0 0x0804c004 in Page::setReferenceFlag (this=0x80540b8) at page.h:23
#1 0x4804d57b in ?? ()
#2 0x0804a2ee in MemoryManagementUnit::referencePage (this=0x80540a8, page=158) at mmu.cpp:66
#3 0x080494d7 in Simulator::process (this=0xbffff33c, instruction=158) at sim.cpp:79
#4 0x0804945a in Simulator::runSimulation (this=0xbffff33c, in=...) at sim.cpp:58
#5 0x08049219 in main (argc=14, argv=0xbffff434) at app.cpp:27


1 comment:

  1. Also if you place the following code in your child code (assuming you have one):

    #ifdef DEBUG
    int PauseMode = 1;

    while (PauseMode)
    sleep(10); /* Wait until someone attaches to us */
    #endif

    Then ps for the pid of the child, attach to the process with gdb command attach pid#, then set PauseMode to 0 and step through the child's code.

    ReplyDelete