1 PSTACK_ITER(3PROC)     Process Control Library Functions    PSTACK_ITER(3PROC)
   2 
   3 NAME
   4      Pstack_iter - iterate process stack frames
   5 
   6 LIBRARY
   7      Process Control Library (libproc, -lproc)
   8 
   9 SYNOPSIS
  10      #include <libproc.h>
  11 
  12      int
  13      Pstack_iter(struct ps_prochandle *P, const prgregset_t regs,
  14          proc_stack_f *func, void *data);
  15 
  16 DESCRIPTION
  17      The Pstack_iter() function iterates over the stack frames in the process
  18      P starting at the point defined by regs.
  19 
  20      For each valid stack frame encountered, the callback function func is
  21      invoked with data passed as argument.  The full signature of proc_stack_f
  22      is defined in libproc(3LIB).  With each callback, a register set,
  23      argument set, and argument count will be provided.  In that register set,
  24      only a subset of the registers will be valid, which include the frame
  25      pointer, program counter, and on SPARC systems, the next program counter.
  26      These registers can be accessed with the constants R_FP, R_PC, and R_nPC
  27      respectively.  These correspond to the registers %ebp and %eip on i386,
  28      %rbp and %rip on amd64, %fp, %pc, and %npc on both SPARC and SPARCv9.
  29 
  30      Callers will receive a callback for the first stack frame indicated by
  31      regs and then will receive a subsequent callback for each caller of that
  32      frame until no such frame can be found.  Stack frames that logically come
  33      after the frame indicated by regs will not receive callbacks.
  34 
  35      The compiler can either facilitate or stymie the iteration of the stack.
  36      Programs that have been compiled in such a way as to omit the frame
  37      pointer will result in truncated stacks.  Similarly, if the initial set
  38      of registers passed in via regs is invalid, then the ability to iterate
  39      the stack will be limited.  The return value of func controls whether or
  40      not iteration continues.  If func returns 0 then iteration continues.
  41      However, if func returns non-zero, then iteration will halt and that
  42      value will be used as the return value of the Pstack_iter() function.
  43      Because Pstack_iter() returns -1 on internal failure it is recommended
  44      the callback function not return -1 to indicate an error.  Thus the
  45      caller may distinguish between the failure of the callback function and
  46      the failure of the Pstack_iter() function.
  47 
  48 RETURN VALUES
  49      Upon successful completion, the Pstack_iter() function returns 0. If
  50      there was an internal error then -1 is returned.  Otherwise, if the
  51      callback function func returns non-zero, then its return value will be
  52      returned instead.
  53 
  54 INTERFACE STABILITY
  55      Uncommitted
  56 
  57 MT-LEVEL
  58      See LOCKING in libproc(3LIB).
  59 
  60 SEE ALSO
  61      libproc(3LIB), proc(4)
  62 
  63 illumos                          May 11, 2016                          illumos