Recently one of our partners requested for some help in capturing the values of all the registers at the time of a process crash. Their idea is to get all the information that is necessary for a crash dump analysis, programmatically.

It is no surprise to hear such an idea, as majority of the customers may not be interested in installing and running a long list of commands under a debugger whenever there is a process crash. If the application can gather as much information as it can about the state of the process (context of the process in OS terminology) before it goes down, customers can simply send that information back to the software vendor along with their bug report(s).

Since it is a native application, I gave them the following C code that tries to print the values of all global (g0 - g7) and output (o0 - o7) registers of SPARC, just the way dbx does with regs command. Also it prints the values of program counter (PC) and next program counter (nPC). Note that this program is not complete - it does not print the values of local (l0 - l7), input (i0 - i7) registers. Also the values of multiply/divide register (y), processor state register (psr) and the single-precision & double-precision floating-point registers (f0 - f31) are missing. I will try to enhance this code later to include all the missing pieces. However this sample program gave them some idea on how to proceed with their actual plan.

Programming example:

The following example demonstrates the process crash with SIGSEGV in 32- and 64-bit code. Correctness of this code can be verified by comparing the output of the C program with the output of regs command in dbx environment.

Note:You might have noticed that the value of global register, g0, is hard coded to 0. The primary reason being the first global register (g0 on SPARC) is the assembly language equivalent of /dev/null. No matter what you try to put into this register, the value always remain zero.

To DO://

Enhance the above code to include input, local, floating-point registers. Also print the actual instructions of program counter (PC) and next program counter (nPC)