Display the call stack of a thread.
CS_RETCODE srv_dbg_stack(spp, depth, funcp)
SRV_PROC *spp; CS_INT depth; CS_RETCODE (*funcp)();
A pointer to an internal thread control structure.
The maximum number of call stack levels to display. If depth is -1, all levels are displayed.
A pointer to a function that you provide to process each line of the call stack display. Your function is called with a pointer to a null terminated string and an integer that is the length of the string. The string contains the program counter and the routine’s parameters formatted in hexadecimal. If your function returns CS_FAIL, the stack trace is terminated. If it returns anything else, the stack trace continues until all of the routines on the call stack are processed or until depth stack frames are processed. If funcp is NULL, Open Server writes the call stack contents to stderr.
The following is a typical implementation for a function:
CS_RETCODE callstack_display(linebuf, length)
CS_CHAR *linebuf;
CS_INT length;
{
/*
** Output each line of the stack trace to stderr.
*/
fprintf(stderr,"%s\n", linebuf);
return(CS_SUCCEED);
}
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
/*
** Local prototype.
*/
CS_RETCODE ex_srv_dbg_stack PROTOTYPE((
SRV_PROC *spp
));
/*
** EX_SRV_DBG_STACK
**
** Example routine to display the call stack of a thread.
**
** Arguments:
** spp - A pointer to an internal thread control structure.
**
** Returns:
** CS_SUCCEED Call stack successfully displayed.
** CS_FAIL An error was detected.
**
*/
CS_RETCODE ex_srv_dbg_stack(spp)
SRV_PROC *spp;
{
CS_RETCODE retval;
retval = srv_dbg_stack(spp, -1, (CS_RETCODE(*)())NULL);
return (retval);
}
srv_dbg_stack is not available on all platforms. Use srv_capability to determine if it is available on the current platform.
srv_dbg_stack allows you to examine the call stack of a thread during debugging or when handling execution errors. It can be called from a debugger or from the running application.
A typical use for srv_dbg_stack is to record the stack frame in the error log when a serious error occurs.
Each routine on the call stack is formatted into a string consisting of the program counter, in hexadecimal, followed by each parameter, also in hexadecimal. You will need a load map of the executable to translate the program counter to a function name.
If called to display the stack of the currently running thread, srv_dbg_stack and the routines it calls appear at the top of the stack.