libunwind-common.h.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2001-2004 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #define UNW_VERSION_MAJOR @PKG_MAJOR@
  22. #define UNW_VERSION_MINOR @PKG_MINOR@
  23. #define UNW_VERSION_EXTRA @PKG_EXTRA@
  24. #define UNW_VERSION_CODE(maj,min) (((maj) << 16) | (min))
  25. #define UNW_VERSION UNW_VERSION_CODE(UNW_VERSION_MAJOR, UNW_VERSION_MINOR)
  26. #define UNW_PASTE2(x,y) x##y
  27. #define UNW_PASTE(x,y) UNW_PASTE2(x,y)
  28. #define UNW_OBJ(fn) UNW_PASTE(UNW_PREFIX, fn)
  29. #define UNW_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_), fn)
  30. #ifdef UNW_LOCAL_ONLY
  31. # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_UL,UNW_TARGET),_)
  32. #else /* !UNW_LOCAL_ONLY */
  33. # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
  34. #endif /* !UNW_LOCAL_ONLY */
  35. /* Error codes. The unwind routines return the *negated* values of
  36. these error codes on error and a non-negative value on success. */
  37. typedef enum
  38. {
  39. UNW_ESUCCESS = 0, /* no error */
  40. UNW_EUNSPEC, /* unspecified (general) error */
  41. UNW_ENOMEM, /* out of memory */
  42. UNW_EBADREG, /* bad register number */
  43. UNW_EREADONLYREG, /* attempt to write read-only register */
  44. UNW_ESTOPUNWIND, /* stop unwinding */
  45. UNW_EINVALIDIP, /* invalid IP */
  46. UNW_EBADFRAME, /* bad frame */
  47. UNW_EINVAL, /* unsupported operation or bad value */
  48. UNW_EBADVERSION, /* unwind info has unsupported version */
  49. UNW_ENOINFO /* no unwind info found */
  50. }
  51. unw_error_t;
  52. /* The following enum defines the indices for a couple of
  53. (pseudo-)registers which have the same meaning across all
  54. platforms. (RO) means read-only. (RW) means read-write. General
  55. registers (aka "integer registers") are expected to start with
  56. index 0. The number of such registers is architecture-dependent.
  57. The remaining indices can be used as an architecture sees fit. The
  58. last valid register index is given by UNW_REG_LAST. */
  59. typedef enum
  60. {
  61. UNW_REG_IP = UNW_TDEP_IP, /* (rw) instruction pointer (pc) */
  62. UNW_REG_SP = UNW_TDEP_SP, /* (ro) stack pointer */
  63. UNW_REG_EH = UNW_TDEP_EH, /* (rw) exception-handling reg base */
  64. UNW_REG_LAST = UNW_TDEP_LAST_REG
  65. }
  66. unw_frame_regnum_t;
  67. /* Number of exception-handler argument registers: */
  68. #define UNW_NUM_EH_REGS UNW_TDEP_NUM_EH_REGS
  69. typedef enum
  70. {
  71. UNW_CACHE_NONE, /* no caching */
  72. UNW_CACHE_GLOBAL, /* shared global cache */
  73. UNW_CACHE_PER_THREAD /* per-thread caching */
  74. }
  75. unw_caching_policy_t;
  76. typedef int unw_regnum_t;
  77. /* The unwind cursor starts at the youngest (most deeply nested) frame
  78. and is used to track the frame state as the unwinder steps from
  79. frame to frame. It is safe to make (shallow) copies of variables
  80. of this type. */
  81. typedef struct unw_cursor
  82. {
  83. unw_word_t opaque[UNW_TDEP_CURSOR_LEN];
  84. }
  85. unw_cursor_t;
  86. /* This type encapsulates the entire (preserved) machine-state. */
  87. typedef unw_tdep_context_t unw_context_t;
  88. /* unw_getcontext() fills the unw_context_t pointed to by UC with the
  89. machine state as it exists at the call-site. For implementation
  90. reasons, this needs to be a target-dependent macro. It's easiest
  91. to think of unw_getcontext() as being identical to getcontext(). */
  92. #define unw_getcontext(uc) unw_tdep_getcontext(uc)
  93. /* Return 1 if register number R is a floating-point register, zero
  94. otherwise.
  95. This routine is signal-safe. */
  96. #define unw_is_fpreg(r) unw_tdep_is_fpreg(r)
  97. typedef unw_tdep_fpreg_t unw_fpreg_t;
  98. typedef struct unw_addr_space *unw_addr_space_t;
  99. /* Each target may define it's own set of flags, but bits 0-15 are
  100. reserved for general libunwind-use. */
  101. #define UNW_PI_FLAG_FIRST_TDEP_BIT 16
  102. /* The information comes from a .debug_frame section. */
  103. #define UNW_PI_FLAG_DEBUG_FRAME 32
  104. typedef struct unw_proc_info
  105. {
  106. unw_word_t start_ip; /* first IP covered by this procedure */
  107. unw_word_t end_ip; /* first IP NOT covered by this procedure */
  108. unw_word_t lsda; /* address of lang.-spec. data area (if any) */
  109. unw_word_t handler; /* optional personality routine */
  110. unw_word_t gp; /* global-pointer value for this procedure */
  111. unw_word_t flags; /* misc. flags */
  112. int format; /* unwind-info format (arch-specific) */
  113. int unwind_info_size; /* size of the information (if applicable) */
  114. void *unwind_info; /* unwind-info (arch-specific) */
  115. unw_tdep_proc_info_t extra; /* target-dependent auxiliary proc-info */
  116. }
  117. unw_proc_info_t;
  118. /* These are backend callback routines that provide access to the
  119. state of a "remote" process. This can be used, for example, to
  120. unwind another process through the ptrace() interface. */
  121. typedef struct unw_accessors
  122. {
  123. /* Look up the unwind info associated with instruction-pointer IP.
  124. On success, the routine fills in the PROC_INFO structure. */
  125. int (*find_proc_info) (unw_addr_space_t, unw_word_t, unw_proc_info_t *,
  126. int, void *);
  127. /* Release any resources (e.g., memory) that were allocated for
  128. the unwind info returned in by a previous call to
  129. find_proc_info() with NEED_UNWIND_INFO set to 1. */
  130. void (*put_unwind_info) (unw_addr_space_t, unw_proc_info_t *, void *);
  131. /* Return the list-head of the dynamically registered unwind
  132. info. */
  133. int (*get_dyn_info_list_addr) (unw_addr_space_t, unw_word_t *, void *);
  134. /* Access aligned word at address ADDR. The value is returned
  135. according to the endianness of the host (e.g., if the host is
  136. little-endian and the target is big-endian, access_mem() needs
  137. to byte-swap the value before returning it). */
  138. int (*access_mem) (unw_addr_space_t, unw_word_t, unw_word_t *, int,
  139. void *);
  140. /* Access register number REG at address ADDR. */
  141. int (*access_reg) (unw_addr_space_t, unw_regnum_t, unw_word_t *, int,
  142. void *);
  143. /* Access register number REG at address ADDR. */
  144. int (*access_fpreg) (unw_addr_space_t, unw_regnum_t,
  145. unw_fpreg_t *, int, void *);
  146. int (*resume) (unw_addr_space_t, unw_cursor_t *, void *);
  147. /* Optional call back to obtain the name of a (static) procedure.
  148. Dynamically generated procedures are handled automatically by
  149. libunwind. This callback is optional and may be set to
  150. NULL. */
  151. int (*get_proc_name) (unw_addr_space_t, unw_word_t, char *, size_t,
  152. unw_word_t *, void *);
  153. }
  154. unw_accessors_t;
  155. typedef enum unw_save_loc_type
  156. {
  157. UNW_SLT_NONE, /* register is not saved ("not an l-value") */
  158. UNW_SLT_MEMORY, /* register has been saved in memory */
  159. UNW_SLT_REG /* register has been saved in (another) register */
  160. }
  161. unw_save_loc_type_t;
  162. typedef struct unw_save_loc
  163. {
  164. unw_save_loc_type_t type;
  165. union
  166. {
  167. unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */
  168. unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */
  169. }
  170. u;
  171. unw_tdep_save_loc_t extra; /* target-dependent additional information */
  172. }
  173. unw_save_loc_t;
  174. /* These routines work both for local and remote unwinding. */
  175. #define unw_local_addr_space UNW_OBJ(local_addr_space)
  176. #define unw_create_addr_space UNW_OBJ(create_addr_space)
  177. #define unw_destroy_addr_space UNW_OBJ(destroy_addr_space)
  178. #define unw_get_accessors UNW_ARCH_OBJ(get_accessors)
  179. #define unw_init_local UNW_OBJ(init_local)
  180. #define unw_init_remote UNW_OBJ(init_remote)
  181. #define unw_step UNW_OBJ(step)
  182. #define unw_resume UNW_OBJ(resume)
  183. #define unw_get_proc_info UNW_OBJ(get_proc_info)
  184. #define unw_get_proc_info_by_ip UNW_OBJ(get_proc_info_by_ip)
  185. #define unw_get_reg UNW_OBJ(get_reg)
  186. #define unw_set_reg UNW_OBJ(set_reg)
  187. #define unw_get_fpreg UNW_OBJ(get_fpreg)
  188. #define unw_set_fpreg UNW_OBJ(set_fpreg)
  189. #define unw_get_save_loc UNW_OBJ(get_save_loc)
  190. #define unw_is_signal_frame UNW_OBJ(is_signal_frame)
  191. #define unw_handle_signal_frame UNW_OBJ(handle_signal_frame)
  192. #define unw_get_proc_name UNW_OBJ(get_proc_name)
  193. #define unw_set_caching_policy UNW_OBJ(set_caching_policy)
  194. #define unw_regname UNW_ARCH_OBJ(regname)
  195. #define unw_flush_cache UNW_ARCH_OBJ(flush_cache)
  196. #define unw_strerror UNW_ARCH_OBJ(strerror)
  197. extern unw_addr_space_t unw_create_addr_space (unw_accessors_t *, int);
  198. extern void unw_destroy_addr_space (unw_addr_space_t);
  199. extern unw_accessors_t *unw_get_accessors (unw_addr_space_t);
  200. extern void unw_flush_cache (unw_addr_space_t, unw_word_t, unw_word_t);
  201. extern int unw_set_caching_policy (unw_addr_space_t, unw_caching_policy_t);
  202. extern const char *unw_regname (unw_regnum_t);
  203. extern int unw_init_local (unw_cursor_t *, unw_context_t *);
  204. extern int unw_init_remote (unw_cursor_t *, unw_addr_space_t, void *);
  205. extern int unw_step (unw_cursor_t *);
  206. extern int unw_resume (unw_cursor_t *);
  207. extern int unw_get_proc_info (unw_cursor_t *, unw_proc_info_t *);
  208. extern int unw_get_proc_info_by_ip (unw_addr_space_t, unw_word_t,
  209. unw_proc_info_t *, void *);
  210. extern int unw_get_reg (unw_cursor_t *, int, unw_word_t *);
  211. extern int unw_set_reg (unw_cursor_t *, int, unw_word_t);
  212. extern int unw_get_fpreg (unw_cursor_t *, int, unw_fpreg_t *);
  213. extern int unw_set_fpreg (unw_cursor_t *, int, unw_fpreg_t);
  214. extern int unw_get_save_loc (unw_cursor_t *, int, unw_save_loc_t *);
  215. extern int unw_is_signal_frame (unw_cursor_t *);
  216. extern int unw_handle_signal_frame (unw_cursor_t *);
  217. extern int unw_get_proc_name (unw_cursor_t *, char *, size_t, unw_word_t *);
  218. extern const char *unw_strerror (int);
  219. extern int unw_backtrace (void **, int);
  220. extern unw_addr_space_t unw_local_addr_space;