1 PSYMBOL_ITER(3PROC)    Process Control Library Functions   PSYMBOL_ITER(3PROC)
   2 
   3 NAME
   4      Psymbol_iter, Psymbol_iter_by_addr, Psymbol_iter_by_lmid,
   5      Psymbol_iter_by_name, Pxsymbol_iter - iterate symbols in a process
   6 
   7 LIBRARY
   8      Process Control Library (libproc, -lproc)
   9 
  10 SYNOPSIS
  11      #include <libproc.h>
  12 
  13      int
  14      Psymbol_iter(struct ps_prochandle *P, const char *object_name, int which,
  15          int mask, proc_sym_f *func, void *data);
  16 
  17      int
  18      Psymbol_iter_by_addr(struct ps_prochandle *P, const char *object_name,
  19          int which, int mask, proc_sym_f *func, void *data);
  20 
  21      int
  22      Psymbol_iter_by_lmid(struct ps_prochandle *P, Lmid_t lmid,
  23          const char *object_name, int which, int mask, proc_sym_f *func,
  24          void *data);
  25 
  26      int
  27      Psymbol_iter_by_name(struct ps_prochandle *P, const char *object_name,
  28          int which, int mask, proc_sym_f *func, void *data);
  29 
  30      int
  31      Pxsymbol_iter(struct ps_prochandle *P, Lmid_t lmid,
  32          const char *object_name, int which, int mask, proc_xsym_f *func,
  33          void *data);
  34 
  35 DESCRIPTION
  36      The Psymbol_iter(), Psymbol_iter_by_addr(), Psymbol_iter_by_lmid(),
  37      Psymbol_iter_by_name(), and Pxsymbol_iter() functions are used to iterate
  38      over the symbols present in the process referred to by the handle P.  For
  39      each symbol found, the callback function func will be called once and the
  40      argument data will be passed to it along with an ELF symbol entry in the
  41      form of the GElf_Sym along with the name of the symbol, if known.  In the
  42      case of the Pxsymbol_iter() function an additional prsyminfo_t argument
  43      will be provided to the callback.  The definitions of proc_sym_f,
  44      proc_xsym_f, and prsyminfo_t are found in libproc(3LIB).
  45 
  46      The object_name argument names the object that is a part of the
  47      controlled process which will be searched for symbols.  Only one object
  48      may be searched at any given time.  Valid object names may be obtained
  49      through the Pobjname(3PROC) and Pobject_iter(3PROC) functions, among
  50      others.  The system also has two special object names that may be passed
  51      in to refer to the objects of the executable file and for ld.so.1.  The
  52      symbol PR_OBJ_EXEC refers to the executables object and the symbol
  53      PR_OBJ_LDSO refers to the object ld.so.1.
  54 
  55      The which argument controls which of two possible symbol tables will be
  56      searched.  If the argument is PR_SYMTAB then the ELF symbol table will be
  57      searched.  Otherwise, if it is PR_DYNSYM then the symbol table associated
  58      with the dynamic section will be searched instead.  If any other value is
  59      specified for which, then an error will be returned.
  60 
  61      The mask argument controls which symbols will be included.  The mask
  62      argument allows for control over both the symbol's binding and the
  63      symbol's type.  These flags logically correspond to the various ELF
  64      symbol bindings and types.  The following values may be passed as a
  65      bitwise-inclusive-OR into the flags argument:
  66 
  67            BIND_LOCAL    The symbol is a local symbol.  Local symbols are not
  68                          visible outside of their object file.
  69 
  70            BIND_GLOBAL   The symbol is a global symbol.  Global symbols are
  71                          visible outside of their object file and may be
  72                          referred to by other ELF objects.
  73 
  74            BIND_WEAK     The symbol is a weak symbol.  Weak symbols are
  75                          visible outside of their object file, but another
  76                          definition of the symbol may be used instead.
  77 
  78            BIND_ANY      This is a combination of BIND_LOCAL, BIND_GLOBAL, and
  79                          BIND_WEAK.  Every symbol's binding will match this
  80                          value.
  81 
  82            TYPE_NOTYPE   The symbol's type is not specified.
  83 
  84            TYPE_OBJECT   The symbol refers to a data object.  For example,
  85                          variables.
  86 
  87            TYPE_FUNC     The symbol refers to a function.
  88 
  89            TYPE_SECTION  The symbol refers to an ELF section.
  90 
  91            TYPE_FILE     The symbol refers to the name of a source file
  92                          associated with an object file.
  93 
  94            TYPE_ANY      This is a combination of TYPE_NOTYPE, TYPE_OBJECT,
  95                          TYPE_FUNC, TYPE_SECTION, and TYPE_FILE.  Every
  96                          symbol's type will match this value.
  97 
  98      To obtain all of the symbols in an object, the caller would pass the
  99      expression BIND_ANY | TYPE_ANY in as the value of mask.
 100 
 101      The Psymbol_iter_by_lmid() and Pxsymbol_iter() functions allow for a
 102      link-map identifier to be specified in the lmid argument.  This will
 103      restrict the search for the object specified in object_name to the
 104      specified link-map.  There are three special link-map identifiers that
 105      may be passed in.  The symbol PR_LMID_EVERY indicates that every link-map
 106      should be searched.  The symbol LM_ID_BASE indicates that the base link-
 107      map, the one that is used for the executable should be searched.
 108      Finally, the symbol LM_ID_LDSO refers to the link-map that is used by the
 109      run-time link editor, ld.so.1.  The functions which do not allow a link-
 110      map identifier to be specified always search every link-map.
 111 
 112      By default, symbols are iterated based on the order of the symbol table
 113      being searched.  However, it is also possible to iterate based on the
 114      name of the symbol and based on the address of the symbol.  To iterate by
 115      name use the Psymbol_iter_by_name() function.  To iterate by address use
 116      the Psymbol_iter_by_addr() function.  The Psymbol_iter(),
 117      Psymbol_iter_by_lmid(), and Pxsymbol_iter() functions all sort based on
 118      the order of the symbol table.
 119 
 120      The return value of the callback function func determines whether or not
 121      iteration continues.  If func returns 0, then iteration will continue.
 122      However, if func returns non-zero, then iteration will halt and that
 123      value will be used as the return value of the Psymbol_iter(),
 124      Psymbol_iter_by_addr(), Psymbol_iter_by_lmid(), Psymbol_iter_by_name(),
 125      and Pxsymbol_iter() functions.  Because these functions return -1 on
 126      internal failure, it is recommended that the callback function not return
 127      -1 to indicate an error so that the caller may distinguish between the
 128      failure of the callback function and the failure of these functions.
 129 
 130 RETURN VALUES
 131      Upon successful completion, the Psymbol_iter(), Psymbol_iter_by_addr(),
 132      Psymbol_iter_by_lmid(), Psymbol_iter_by_name(), and Pxsymbol_iter()
 133      functions return 0.  If there was an internal error then -1 is returned.
 134      Otherwise, if the callback function func returns non-zero, then its
 135      return value will be returned instead.
 136 
 137 INTERFACE STABILITY
 138      Uncommitted
 139 
 140 MT-LEVEL
 141      See LOCKING in libproc(3LIB).
 142 
 143 SEE ALSO
 144      elf(3ELF), gelf(3ELF), libproc(3LIB), proc(4)
 145 
 146 illumos                          May 11, 2016                          illumos