DBX
HomeSCJP | SCWCD | SCEA | SCSA
dbx is an interactive, source-level, command-line debugging tool. You can use it to run a program in a controlled manner and to inspect the state of a stopped program. dbx gives you complete control of the dynamic execution of a program, includingcollecting performance and memory usage data, monitoring memory access, and detecting memory leaks.

Avalilability of dbx:
http://www.sun.com/forte/cplusplus/buy.html

gcore: If you want to dump core of a live process and run stack trace procedures at a later convenient time. Do the following
/usr/bin/gcore [-o filename] process-id
Ex: /usr/bin/gcore - pid_of_process or kill -8 pid_of_process
where pid is the process id for identification.

gcore creates a core image of  the specified  process. 
By default, the name of the core image file will be core.process-id. 
For e.g. core.11594 Change the permissions of the core file & verified it.
Run the strings command on the core file.Example :  /bin/strings core.11594 | more

How to run dbx on Core
dbx - <executable> core

How to run dbx on process
dbx - pid

DBX PROMPT :Before getting it to dbx prompt, it will read all the libraries i.e. .so files.

Debugging a core file run the following command at dbx prompt:
debug -c <full path of the core filename> <executable path of that appln>
It will read the core header file

Getting a stack trace from the core file
write the shell script called as dbx.stacks, change permissions to executable in a  any  directory
(for e.g save it as  /home/dbx.stacks).
At the dbx prompt type:
source /home/dbx.stacks > /home/file.pid.date

How to read the stack trace?
At dbx prompt, running the source on dbx.stacks, will generate the stack trace file.
Open the file in vi editor, it will displays the no. of threads running

Core dump error messages :
Bus Error
Memory Fault
Segmentation Fault
Floating Exception
Trace/BPT Trap
IOT Trap
Illegal Instruction

Bus Error
Types of arguments and parameters don't match.
I/O problems - reading past EOF, reading a closed file, bad file pointers, etc.
Arrays improperly dimensioned.Ex.attempting to
    - access a word starting at an odd address.
    - Referencing a non-existent bus device.
    - NULL or unitialized pointer, subscript out of   range.

Memory Fault
Subscripting arrays past the memory allocation for  your program.
NULL or unitialized pointer, subscript out of range.
Attempts to reference data outside valid address space
Parity errors in address space
Recursion (try making your own routines
"read" and "write"  and then call "scanf" or "printf" and watch what happens).

Segmentation Fault
Subscript out of range.
Handing "printf", etc. a string which is not NULL  terminated.

Floating Exception
Invalid floating point operation:
overflow
underflow
divide by zero
log of negative number
float-to-int conversion overflow