libunwind-dynamic.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2002-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. /* This file defines the runtime-support routines for dynamically
  22. generated code. Even though it is implemented as part of libunwind,
  23. it is logically separate from the interface to perform the actual
  24. unwinding. In particular, this interface is always used in the
  25. context of the unwind target, whereas the rest of the unwind API is
  26. used in context of the process that is doing the unwind (which may be
  27. a debugger running on another machine, for example).
  28. Note that the data-structures declared here server a dual purpose:
  29. when a program registers a dynamically generated procedure, it uses
  30. these structures directly. On the other hand, with remote-unwinding,
  31. the data-structures are read from the remote process's memory and
  32. translated into internalized versions. To facilitate remote-access,
  33. the following rules should be followed in declaring these structures:
  34. (1) Declare a member as a pointer only if the the information the
  35. member points to needs to be internalized as well (e.g., a
  36. string representing a procedure name should be declared as
  37. "const char *", but the instruction pointer should be declared
  38. as unw_word_t).
  39. (2) Provide sufficient padding to ensure that no implicit padding
  40. will be needed on any of the supported target architectures. For
  41. the time being, padding data structures with the assumption that
  42. sizeof (unw_word_t) == 8 should be sufficient. (Note: it's not
  43. impossible to internalize structures with internal padding, but
  44. it does make the process a bit harder).
  45. (3) Don't declare members that contain bitfields or floating-point
  46. values.
  47. (4) Don't declare members with enumeration types. Declare them as
  48. int32_t instead. */
  49. typedef enum
  50. {
  51. UNW_DYN_STOP = 0, /* end-of-unwind-info marker */
  52. UNW_DYN_SAVE_REG, /* save register to another register */
  53. UNW_DYN_SPILL_FP_REL, /* frame-pointer-relative register spill */
  54. UNW_DYN_SPILL_SP_REL, /* stack-pointer-relative register spill */
  55. UNW_DYN_ADD, /* add constant value to a register */
  56. UNW_DYN_POP_FRAMES, /* drop one or more stack frames */
  57. UNW_DYN_LABEL_STATE, /* name the current state */
  58. UNW_DYN_COPY_STATE, /* set the region's entry-state */
  59. UNW_DYN_ALIAS /* get unwind info from an alias */
  60. }
  61. unw_dyn_operation_t;
  62. typedef enum
  63. {
  64. UNW_INFO_FORMAT_DYNAMIC, /* unw_dyn_proc_info_t */
  65. UNW_INFO_FORMAT_TABLE, /* unw_dyn_table_t */
  66. UNW_INFO_FORMAT_REMOTE_TABLE, /* unw_dyn_remote_table_t */
  67. UNW_INFO_FORMAT_ARM_EXIDX /* ARM specific unwind info */
  68. }
  69. unw_dyn_info_format_t;
  70. typedef struct unw_dyn_op
  71. {
  72. int8_t tag; /* what operation? */
  73. int8_t qp; /* qualifying predicate register */
  74. int16_t reg; /* what register */
  75. int32_t when; /* when does it take effect? */
  76. unw_word_t val; /* auxiliary value */
  77. }
  78. unw_dyn_op_t;
  79. typedef struct unw_dyn_region_info
  80. {
  81. struct unw_dyn_region_info *next; /* linked list of regions */
  82. int32_t insn_count; /* region length (# of instructions) */
  83. uint32_t op_count; /* length of op-array */
  84. unw_dyn_op_t op[1]; /* variable-length op-array */
  85. }
  86. unw_dyn_region_info_t;
  87. typedef struct unw_dyn_proc_info
  88. {
  89. unw_word_t name_ptr; /* address of human-readable procedure name */
  90. unw_word_t handler; /* address of personality routine */
  91. uint32_t flags;
  92. int32_t pad0;
  93. unw_dyn_region_info_t *regions;
  94. }
  95. unw_dyn_proc_info_t;
  96. typedef struct unw_dyn_table_info
  97. {
  98. unw_word_t name_ptr; /* addr. of table name (e.g., library name) */
  99. unw_word_t segbase; /* segment base */
  100. unw_word_t table_len; /* must be a multiple of sizeof(unw_word_t)! */
  101. unw_word_t *table_data;
  102. }
  103. unw_dyn_table_info_t;
  104. typedef struct unw_dyn_remote_table_info
  105. {
  106. unw_word_t name_ptr; /* addr. of table name (e.g., library name) */
  107. unw_word_t segbase; /* segment base */
  108. unw_word_t table_len; /* must be a multiple of sizeof(unw_word_t)! */
  109. unw_word_t table_data;
  110. }
  111. unw_dyn_remote_table_info_t;
  112. typedef struct unw_dyn_info
  113. {
  114. /* doubly-linked list of dyn-info structures: */
  115. struct unw_dyn_info *next;
  116. struct unw_dyn_info *prev;
  117. unw_word_t start_ip; /* first IP covered by this entry */
  118. unw_word_t end_ip; /* first IP NOT covered by this entry */
  119. unw_word_t gp; /* global-pointer in effect for this entry */
  120. int32_t format; /* real type: unw_dyn_info_format_t */
  121. int32_t pad;
  122. union
  123. {
  124. unw_dyn_proc_info_t pi;
  125. unw_dyn_table_info_t ti;
  126. unw_dyn_remote_table_info_t rti;
  127. }
  128. u;
  129. }
  130. unw_dyn_info_t;
  131. typedef struct unw_dyn_info_list
  132. {
  133. uint32_t version;
  134. uint32_t generation;
  135. unw_dyn_info_t *first;
  136. }
  137. unw_dyn_info_list_t;
  138. /* Return the size (in bytes) of an unw_dyn_region_info_t structure that can
  139. hold OP_COUNT ops. */
  140. #define _U_dyn_region_info_size(op_count) \
  141. ((char *) (((unw_dyn_region_info_t *) NULL)->op + (op_count)) \
  142. - (char *) NULL)
  143. /* Register the unwind info for a single procedure.
  144. This routine is NOT signal-safe. */
  145. extern void _U_dyn_register (unw_dyn_info_t *);
  146. /* Cancel the unwind info for a single procedure.
  147. This routine is NOT signal-safe. */
  148. extern void _U_dyn_cancel (unw_dyn_info_t *);
  149. /* Convenience routines. */
  150. #define _U_dyn_op(_tag, _qp, _when, _reg, _val) \
  151. ((unw_dyn_op_t) { (_tag), (_qp), (_reg), (_when), (_val) })
  152. #define _U_dyn_op_save_reg(op, qp, when, reg, dst) \
  153. (*(op) = _U_dyn_op (UNW_DYN_SAVE_REG, (qp), (when), (reg), (dst)))
  154. #define _U_dyn_op_spill_fp_rel(op, qp, when, reg, offset) \
  155. (*(op) = _U_dyn_op (UNW_DYN_SPILL_FP_REL, (qp), (when), (reg), \
  156. (offset)))
  157. #define _U_dyn_op_spill_sp_rel(op, qp, when, reg, offset) \
  158. (*(op) = _U_dyn_op (UNW_DYN_SPILL_SP_REL, (qp), (when), (reg), \
  159. (offset)))
  160. #define _U_dyn_op_add(op, qp, when, reg, value) \
  161. (*(op) = _U_dyn_op (UNW_DYN_ADD, (qp), (when), (reg), (value)))
  162. #define _U_dyn_op_pop_frames(op, qp, when, num_frames) \
  163. (*(op) = _U_dyn_op (UNW_DYN_POP_FRAMES, (qp), (when), 0, (num_frames)))
  164. #define _U_dyn_op_label_state(op, label) \
  165. (*(op) = _U_dyn_op (UNW_DYN_LABEL_STATE, _U_QP_TRUE, -1, 0, (label)))
  166. #define _U_dyn_op_copy_state(op, label) \
  167. (*(op) = _U_dyn_op (UNW_DYN_COPY_STATE, _U_QP_TRUE, -1, 0, (label)))
  168. #define _U_dyn_op_alias(op, qp, when, addr) \
  169. (*(op) = _U_dyn_op (UNW_DYN_ALIAS, (qp), (when), 0, (addr)))
  170. #define _U_dyn_op_stop(op) \
  171. (*(op) = _U_dyn_op (UNW_DYN_STOP, _U_QP_TRUE, -1, 0, 0))
  172. /* The target-dependent qualifying predicate which is always TRUE. On
  173. IA-64, that's p0 (0), on non-predicated architectures, the value is
  174. ignored. */
  175. #define _U_QP_TRUE _U_TDEP_QP_TRUE