Wednesday, February 9, 2011

Debugging Core dump in Solaris - Bus Error, Segmentaiton Fault

Solaris normally throws following types of errors and dumps the core for a program/application:
1. Bus Error: Bus Error (core dumped)

Bus error thrown due to misalignment of the data in your application. Solaris mandates the data type to be aligned to the boundary corresponds to its size. 
Eg: an integer type to be aligned to 32 bit word boundary. Your application miserably fails if an integer type tries to access a memory location that is not aligned to 4 bye boundary. Take a look @ following code block :

/// declare a structure of character array
typedef struct {
    char chr_arr[4096];
} myBuf_T;

/// a structure with integer member variables
typedef struct {
   int type;
   int val;
} header_T;

myBuf_T myBuf; // This doesn't guarantee the starting address of myBuf to be aligned to certain boundary!!
void extract_header()
{
    header_T *header = (header_T *)myBuf;
    int myVal = header->val; ///////////// CAUTION!!! This instruction will cause your application to crash in Solaris env. if my buf starts at address not aligned to 4 byte boundary. Eg ( 0x00EA. ie. addr % 4 =2 )
}
Such issues can be avoided with the use of unions aligned 4 bye word boundary. OR you can instead use your existing structure with required aligned attribute. Read more about different attributes of variables.


2. Segmentation Fault:  Segmentation Fault (core dumped)
This error is seen if your applications fails to allocate required memory OR tries to access inadvertent memory location

3. Abort: Abort (core dumped)
This is most likely to due to assert instructions introduced by application.
 
                                

                                HAPPY DEBUGGING!!!

No comments:

Post a Comment