Debugging Core Files Using HP WDB

Example 1 SIGBUS Causes a Core Dump
$ cat a.c
#include <stdio.h>
int main()
{
char a[64], *b;
int *i;
b = a;
b++;
i = (int *)b;
printf("%i", *i);
return 0;
}
$ aCC a.c -o a
$ ./a
Memory fault(core dump)
$file core
core: core file from 'a' - received SIGBUS
In this example, the program attempts to load a data item at a non-aligned address, which
results in a SIGBUS signal.
The variable a is a local variable on the stack. The pointer b is set to point to the start of a.
The pointer b is set to increment such that it does not point to a word aligned address. The
value in pointer b is assigned to pointer i. When pointer i is de-referenced, a SIGBUS signal
is encountered.
SIGSEGV
A SIGSEGV signal is sent to a program when a segmentation violation occurs. A segmentation
violation occurs when a process attempts to access an address that is not in the currently
allocated address space of the process.
Example 2 illustrates how a SIGSEGV signal can cause a core dump.
Example 2 SIGSEGV Causes a Core Dump
$ cat a.c
int main()
{
int *i, j;
i = (int *)0x48000000;
j = *i;
return 0;
}
$ aCC a.c -o a
$ ./a
Memory fault(core dump)
$ file core
core: core file from 'a' - received SIGSEGV
In this example, the program de-references a nonexistent pointer address, and this results
in a SIGSEGV signal.
12