srv_dbg_stack

Description

Display the call stack of a thread.

Syntax

CS_RETCODE srv_dbg_stack(spp, depth, funcp)
SRV_PROC          *spp;
CS_INT                 depth;
CS_RETCODE     (*funcp)();

Parameters

spp

A pointer to an internal thread control structure.

depth

The maximum number of call stack levels to display. If depth is -1, all levels are displayed.

funcp

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

Table 3-29: Return values (srv_dbg_stack)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#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);
}

Usage

See also

srv_capability, srv_dbg_switch