libunwind_i.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2008 CodeSourcery
  3. This file is part of libunwind.
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. "Software"), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  20. #ifndef ARM_LIBUNWIND_I_H
  21. #define ARM_LIBUNWIND_I_H
  22. /* Target-dependent definitions that are internal to libunwind but need
  23. to be shared with target-independent code. */
  24. #include <stdlib.h>
  25. #include <libunwind.h>
  26. #include "elf32.h"
  27. #include "mempool.h"
  28. #include "dwarf.h"
  29. #include "ex_tables.h"
  30. typedef struct
  31. {
  32. /* no arm-specific fast trace */
  33. }
  34. unw_tdep_frame_t;
  35. struct unw_addr_space
  36. {
  37. struct unw_accessors acc;
  38. int big_endian;
  39. unw_caching_policy_t caching_policy;
  40. #ifdef HAVE_ATOMIC_OPS_H
  41. AO_t cache_generation;
  42. #else
  43. uint32_t cache_generation;
  44. #endif
  45. unw_word_t dyn_generation; /* see dyn-common.h */
  46. unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
  47. struct dwarf_rs_cache global_cache;
  48. struct unw_debug_frame_list *debug_frames;
  49. };
  50. struct cursor
  51. {
  52. struct dwarf_cursor dwarf; /* must be first */
  53. enum
  54. {
  55. ARM_SCF_NONE, /* no signal frame */
  56. ARM_SCF_LINUX_SIGFRAME, /* non-RT signal frame, kernel >=2.6.18 */
  57. ARM_SCF_LINUX_RT_SIGFRAME, /* RT signal frame, kernel >=2.6.18 */
  58. ARM_SCF_LINUX_OLD_SIGFRAME, /* non-RT signal frame, kernel < 2.6.18 */
  59. ARM_SCF_LINUX_OLD_RT_SIGFRAME /* RT signal frame, kernel < 2.6.18 */
  60. }
  61. sigcontext_format;
  62. unw_word_t sigcontext_addr;
  63. unw_word_t sigcontext_sp;
  64. unw_word_t sigcontext_pc;
  65. };
  66. #define DWARF_GET_LOC(l) ((l).val)
  67. #ifdef UNW_LOCAL_ONLY
  68. # define DWARF_NULL_LOC DWARF_LOC (0, 0)
  69. # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
  70. # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
  71. # define DWARF_IS_REG_LOC(l) 0
  72. # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  73. tdep_uc_addr((c)->as_arg, (r)), 0))
  74. # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
  75. # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  76. tdep_uc_addr((c)->as_arg, (r)), 0))
  77. static inline int
  78. dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
  79. {
  80. if (!DWARF_GET_LOC (loc))
  81. return -1;
  82. *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
  83. return 0;
  84. }
  85. static inline int
  86. dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
  87. {
  88. if (!DWARF_GET_LOC (loc))
  89. return -1;
  90. *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
  91. return 0;
  92. }
  93. static inline int
  94. dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
  95. {
  96. if (!DWARF_GET_LOC (loc))
  97. return -1;
  98. *val = *(unw_word_t *) DWARF_GET_LOC (loc);
  99. return 0;
  100. }
  101. static inline int
  102. dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
  103. {
  104. if (!DWARF_GET_LOC (loc))
  105. return -1;
  106. *(unw_word_t *) DWARF_GET_LOC (loc) = val;
  107. return 0;
  108. }
  109. #else /* !UNW_LOCAL_ONLY */
  110. # define DWARF_LOC_TYPE_FP (1 << 0)
  111. # define DWARF_LOC_TYPE_REG (1 << 1)
  112. # define DWARF_NULL_LOC DWARF_LOC (0, 0)
  113. # define DWARF_IS_NULL_LOC(l) \
  114. ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
  115. # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
  116. # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
  117. # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
  118. # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
  119. # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
  120. # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
  121. | DWARF_LOC_TYPE_FP))
  122. static inline int
  123. dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
  124. {
  125. char *valp = (char *) &val;
  126. unw_word_t addr;
  127. int ret;
  128. if (DWARF_IS_NULL_LOC (loc))
  129. return -UNW_EBADREG;
  130. if (DWARF_IS_REG_LOC (loc))
  131. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  132. val, 0, c->as_arg);
  133. addr = DWARF_GET_LOC (loc);
  134. if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
  135. 0, c->as_arg)) < 0)
  136. return ret;
  137. return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0,
  138. c->as_arg);
  139. }
  140. static inline int
  141. dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
  142. {
  143. char *valp = (char *) &val;
  144. unw_word_t addr;
  145. int ret;
  146. if (DWARF_IS_NULL_LOC (loc))
  147. return -UNW_EBADREG;
  148. if (DWARF_IS_REG_LOC (loc))
  149. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  150. &val, 1, c->as_arg);
  151. addr = DWARF_GET_LOC (loc);
  152. if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
  153. 1, c->as_arg)) < 0)
  154. return ret;
  155. return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1,
  156. 1, c->as_arg);
  157. }
  158. static inline int
  159. dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
  160. {
  161. if (DWARF_IS_NULL_LOC (loc))
  162. return -UNW_EBADREG;
  163. /* If a code-generator were to save a value of type unw_word_t in a
  164. floating-point register, we would have to support this case. I
  165. suppose it could happen with MMX registers, but does it really
  166. happen? */
  167. assert (!DWARF_IS_FP_LOC (loc));
  168. if (DWARF_IS_REG_LOC (loc))
  169. return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
  170. 0, c->as_arg);
  171. else
  172. return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
  173. 0, c->as_arg);
  174. }
  175. static inline int
  176. dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
  177. {
  178. if (DWARF_IS_NULL_LOC (loc))
  179. return -UNW_EBADREG;
  180. /* If a code-generator were to save a value of type unw_word_t in a
  181. floating-point register, we would have to support this case. I
  182. suppose it could happen with MMX registers, but does it really
  183. happen? */
  184. assert (!DWARF_IS_FP_LOC (loc));
  185. if (DWARF_IS_REG_LOC (loc))
  186. return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
  187. 1, c->as_arg);
  188. else
  189. return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
  190. 1, c->as_arg);
  191. }
  192. #endif /* !UNW_LOCAL_ONLY */
  193. #define tdep_getcontext_trace unw_getcontext
  194. #define tdep_needs_initialization UNW_OBJ(needs_initialization)
  195. #define tdep_init UNW_OBJ(init)
  196. #define arm_find_proc_info UNW_OBJ(find_proc_info)
  197. #define arm_put_unwind_info UNW_OBJ(put_unwind_info)
  198. /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
  199. tdep_search_unwind_table. */
  200. #define tdep_search_unwind_table UNW_OBJ(search_unwind_table)
  201. #define tdep_find_unwind_table dwarf_find_unwind_table
  202. #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
  203. #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
  204. #define tdep_access_reg UNW_OBJ(access_reg)
  205. #define tdep_access_fpreg UNW_OBJ(access_fpreg)
  206. #define tdep_fetch_frame(c,ip,n) do {} while(0)
  207. #define tdep_cache_frame(c,rs) do {} while(0)
  208. #define tdep_reuse_frame(c,rs) do {} while(0)
  209. #define tdep_stash_frame(c,rs) do {} while(0)
  210. #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
  211. #ifdef UNW_LOCAL_ONLY
  212. # define tdep_find_proc_info(c,ip,n) \
  213. arm_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
  214. (c)->as_arg)
  215. # define tdep_put_unwind_info(as,pi,arg) \
  216. arm_put_unwind_info((as), (pi), (arg))
  217. #else
  218. # define tdep_find_proc_info(c,ip,n) \
  219. (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
  220. (c)->as_arg)
  221. # define tdep_put_unwind_info(as,pi,arg) \
  222. (*(as)->acc.put_unwind_info)((as), (pi), (arg))
  223. #endif
  224. #define tdep_get_as(c) ((c)->dwarf.as)
  225. #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
  226. #define tdep_get_ip(c) ((c)->dwarf.ip)
  227. #define tdep_big_endian(as) ((as)->big_endian)
  228. extern int tdep_needs_initialization;
  229. extern void tdep_init (void);
  230. extern int arm_find_proc_info (unw_addr_space_t as, unw_word_t ip,
  231. unw_proc_info_t *pi, int need_unwind_info,
  232. void *arg);
  233. extern void arm_put_unwind_info (unw_addr_space_t as,
  234. unw_proc_info_t *pi, void *arg);
  235. extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
  236. unw_dyn_info_t *di, unw_proc_info_t *pi,
  237. int need_unwind_info, void *arg);
  238. extern void *tdep_uc_addr (unw_tdep_context_t *uc, int reg);
  239. extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
  240. unsigned long *segbase, unsigned long *mapoff,
  241. char *path, size_t pathlen);
  242. extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
  243. unw_word_t *valp, int write);
  244. extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
  245. unw_fpreg_t *valp, int write);
  246. /* unwinding method selection support */
  247. #define UNW_ARM_METHOD_ALL 0xFF
  248. #define UNW_ARM_METHOD_DWARF 0x01
  249. #define UNW_ARM_METHOD_FRAME 0x02
  250. #define UNW_ARM_METHOD_EXIDX 0x04
  251. #define unwi_unwind_method UNW_OBJ(unwind_method)
  252. extern int unwi_unwind_method;
  253. #define UNW_TRY_METHOD(x) (unwi_unwind_method & x)
  254. #endif /* ARM_LIBUNWIND_I_H */