How to detect core dump by using dbx tool in solaris system :

core dump segmentation fault debugging tool

Hi friends as a software developer i have faced so many difficulties while debugging the core dump issue with my application. Finally i got some ideas to find core dump issue. So i would like to share those tips. I hope this may help your debugging. If its not upto your expectation i m apologies you.

coreTest.cpp

==========

#include <stdio.h>

#include <string.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

typedef struct myStruct

{

char name[20];

int id;

}myObj;

int main()

{

myObj *obj=new myObj;

char *myName=NULL;

myName=(char*) malloc (sizeof(char) *20);

strcpy(myName,”Jey”);

strcpy(obj->name,myName);

printf(“My name is : %s\n”,obj->name);

obj->id=3338;

printf(“My Emp Id is : %d\n”,obj->id);

printf(“Appln going to crash….\n”);

obj=NULL;

if(obj->id==3338) // It should crash here

printf(“Its not crashed 🙂 \n”);

return 0;

}

 

compile the above code

g++ coreTest.cpp –o coreTest –g

Here coreTest is the binary name and –g is the debugging symbol. then run the code. it should dump core file.

output :

[jayamaran]$ ./coreTest

My name is : Jey

My Emp Id is : 3338

Appln going to crash….

Segmentation Fault (core dumped)

Finding core is the difficult one for programmers. But by using dbx tool we can easily identified the core dump with exact line number.

Step 1 :

dbx <Binary Name> <core file>

Then it will read the library files. We can check core dump in RTC ( Run time Check )

Step 2 :

(dbx) run

 Just give the command for run then the binary will be started running. And generate core dump.

step 3 :

(dbx) where

It will display exact place where the application dump the core.

Example :

[jayamaran]$ dbx a.out core

For information about new features see `help changes’

To remove this message, put `dbxenv suppress_startup_message 7.5′ in your .dbxrc

Reading a.out

core file header read successfully

Reading ld.so.1

Reading libstdc++.so.6

Reading libm.so.2

Reading libgcc_s.so.1

Reading libc.so.1

Reading libc_psr.so.1

program terminated by signal SEGV (no mapping at the fault address)

Current function is main

(dbx) run

Running: a.out

(process id 1342)

My name is : Jey

My Emp Id is : 3338

Appln going to crash….

signal SEGV (no mapping at the fault address) in main at line 22 in file “coreTest.cpp”

22      if(obj->id==3338) // It should crash here

(dbx) where

=>[1] main(), line 22 in “coreTest.cpp”