libunwind_i.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2003-2005 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. #ifndef HPPA_LIBUNWIND_I_H
  22. #define HPPA_LIBUNWIND_I_H
  23. /* Target-dependent definitions that are internal to libunwind but need
  24. to be shared with target-independent code. */
  25. #include <stdlib.h>
  26. #include <libunwind.h>
  27. #include "elf32.h"
  28. #include "dwarf.h"
  29. typedef struct
  30. {
  31. /* no hppa-specific fast trace */
  32. }
  33. unw_tdep_frame_t;
  34. struct unw_addr_space
  35. {
  36. struct unw_accessors acc;
  37. unw_caching_policy_t caching_policy;
  38. #ifdef HAVE_ATOMIC_OPS_H
  39. AO_t cache_generation;
  40. #else
  41. uint32_t cache_generation;
  42. #endif
  43. unw_word_t dyn_generation; /* see dyn-common.h */
  44. unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
  45. struct unw_debug_frame_list *debug_frames;
  46. };
  47. struct cursor
  48. {
  49. struct dwarf_cursor dwarf; /* must be first */
  50. /* Format of sigcontext structure and address at which it is
  51. stored: */
  52. enum
  53. {
  54. HPPA_SCF_NONE, /* no signal frame encountered */
  55. HPPA_SCF_LINUX_RT_SIGFRAME /* POSIX ucontext_t */
  56. }
  57. sigcontext_format;
  58. unw_word_t sigcontext_addr;
  59. };
  60. #define DWARF_GET_LOC(l) ((l).val)
  61. #ifdef UNW_LOCAL_ONLY
  62. # define DWARF_NULL_LOC DWARF_LOC (0, 0)
  63. # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
  64. # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
  65. # define DWARF_IS_REG_LOC(l) 0
  66. # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  67. tdep_uc_addr((c)->as_arg, (r)), 0))
  68. # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
  69. # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  70. tdep_uc_addr((c)->as_arg, (r)), 0))
  71. static inline int
  72. dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
  73. {
  74. if (!DWARF_GET_LOC (loc))
  75. return -1;
  76. *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
  77. return 0;
  78. }
  79. static inline int
  80. dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
  81. {
  82. if (!DWARF_GET_LOC (loc))
  83. return -1;
  84. *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
  85. return 0;
  86. }
  87. static inline int
  88. dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
  89. {
  90. if (!DWARF_GET_LOC (loc))
  91. return -1;
  92. *val = *(unw_word_t *) DWARF_GET_LOC (loc);
  93. return 0;
  94. }
  95. static inline int
  96. dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
  97. {
  98. if (!DWARF_GET_LOC (loc))
  99. return -1;
  100. *(unw_word_t *) DWARF_GET_LOC (loc) = val;
  101. return 0;
  102. }
  103. #else /* !UNW_LOCAL_ONLY */
  104. # define DWARF_LOC_TYPE_FP (1 << 0)
  105. # define DWARF_LOC_TYPE_REG (1 << 1)
  106. # define DWARF_NULL_LOC DWARF_LOC (0, 0)
  107. # define DWARF_IS_NULL_LOC(l) \
  108. ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
  109. # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
  110. # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
  111. # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
  112. # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
  113. # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
  114. # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
  115. | DWARF_LOC_TYPE_FP))
  116. static inline int
  117. dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
  118. {
  119. char *valp = (char *) &val;
  120. unw_word_t addr;
  121. int ret;
  122. if (DWARF_IS_NULL_LOC (loc))
  123. return -UNW_EBADREG;
  124. if (DWARF_IS_REG_LOC (loc))
  125. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  126. val, 0, c->as_arg);
  127. addr = DWARF_GET_LOC (loc);
  128. if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
  129. 0, c->as_arg)) < 0)
  130. return ret;
  131. return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0,
  132. c->as_arg);
  133. }
  134. static inline int
  135. dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
  136. {
  137. char *valp = (char *) &val;
  138. unw_word_t addr;
  139. int ret;
  140. if (DWARF_IS_NULL_LOC (loc))
  141. return -UNW_EBADREG;
  142. if (DWARF_IS_REG_LOC (loc))
  143. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  144. &val, 1, c->as_arg);
  145. addr = DWARF_GET_LOC (loc);
  146. if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
  147. 1, c->as_arg)) < 0)
  148. return ret;
  149. return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1,
  150. 1, c->as_arg);
  151. }
  152. static inline int
  153. dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
  154. {
  155. if (DWARF_IS_NULL_LOC (loc))
  156. return -UNW_EBADREG;
  157. /* If a code-generator were to save a value of type unw_word_t in a
  158. floating-point register, we would have to support this case. I
  159. suppose it could happen with MMX registers, but does it really
  160. happen? */
  161. assert (!DWARF_IS_FP_LOC (loc));
  162. if (DWARF_IS_REG_LOC (loc))
  163. return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
  164. 0, c->as_arg);
  165. else
  166. return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
  167. 0, c->as_arg);
  168. }
  169. static inline int
  170. dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
  171. {
  172. if (DWARF_IS_NULL_LOC (loc))
  173. return -UNW_EBADREG;
  174. /* If a code-generator were to save a value of type unw_word_t in a
  175. floating-point register, we would have to support this case. I
  176. suppose it could happen with MMX registers, but does it really
  177. happen? */
  178. assert (!DWARF_IS_FP_LOC (loc));
  179. if (DWARF_IS_REG_LOC (loc))
  180. return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
  181. 1, c->as_arg);
  182. else
  183. return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
  184. 1, c->as_arg);
  185. }
  186. #endif /* !UNW_LOCAL_ONLY */
  187. #define tdep_getcontext_trace unw_getcontext
  188. #define tdep_needs_initialization UNW_OBJ(needs_initialization)
  189. #define tdep_init UNW_OBJ(init)
  190. /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
  191. tdep_search_unwind_table. */
  192. #define tdep_search_unwind_table dwarf_search_unwind_table
  193. #define tdep_find_unwind_table dwarf_find_unwind_table
  194. #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
  195. #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
  196. #define tdep_access_reg UNW_OBJ(access_reg)
  197. #define tdep_access_fpreg UNW_OBJ(access_fpreg)
  198. #define tdep_fetch_frame(c,ip,n) do {} while(0)
  199. #define tdep_cache_frame(c,rs) do {} while(0)
  200. #define tdep_reuse_frame(c,rs) do {} while(0)
  201. #define tdep_stash_frame(c,rs) do {} while(0)
  202. #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
  203. #ifdef UNW_LOCAL_ONLY
  204. # define tdep_find_proc_info(c,ip,n) \
  205. dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
  206. (c)->as_arg)
  207. # define tdep_put_unwind_info(c,pi) \
  208. dwarf_put_unwind_info((c)->as, (pi), (c)->as_arg)
  209. #else
  210. # define tdep_find_proc_info(c,ip,n) \
  211. (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
  212. (c)->as_arg)
  213. # define tdep_put_unwind_info(c,pi) \
  214. (*(c)->as->acc.put_unwind_info)((c)->as, (pi), (c)->as_arg)
  215. #endif
  216. #define tdep_get_as(c) ((c)->dwarf.as)
  217. #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
  218. #define tdep_get_ip(c) ((c)->dwarf.ip)
  219. #define tdep_big_endian(as) 1
  220. extern int tdep_needs_initialization;
  221. extern void tdep_init (void);
  222. extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
  223. unw_dyn_info_t *di, unw_proc_info_t *pi,
  224. int need_unwind_info, void *arg);
  225. extern void *tdep_uc_addr (ucontext_t *uc, int reg);
  226. extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
  227. unsigned long *segbase, unsigned long *mapoff,
  228. char *path, size_t pathlen);
  229. extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
  230. unw_word_t *valp, int write);
  231. extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
  232. unw_fpreg_t *valp, int write);
  233. #endif /* HPPA_LIBUNWIND_I_H */