blob: 42bef3db6791263405e7a38928be81c0dc49f90f [file] [log] [blame]
mostang.com!davidmbf070a92002-12-19 07:16:50 +00001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2001-2002 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
26#ifndef internal_h
27#define internal_h
28
29/* Platform-independent libunwind-internal declarations. */
30
31#include <assert.h>
32#include <pthread.h>
33#include <libunwind.h>
34
35#ifdef __GNUC__
36# define HIDDEN __attribute__((visibility ("hidden")))
37#else
38# define HIDDEN
39#endif
40
41#ifdef DEBUG
42# define UNW_DEBUG 1
43#endif
44
45#if UNW_DEBUG
46# include <stdio.h>
47# define debug(level,format...) \
48 do { if (tdep_debug_level > level) printf (format); } while (0)
49# define dprintf(format...) \
50 printf (format)
51# ifdef __GNUC__
52# define inline __attribute__ ((unused))
53# endif
54#else
55# define debug(level,format...)
56# define dprintf(format...)
57# ifdef __GNUC__
58# else
59# define inline /* nothing */
60# endif
61#endif
62
63/* Make it easy to write thread-safe code which may or may not be
64 linked against libpthread. The macros below can be used
65 unconditionally and if -lpthread is around, they'll call the
66 corresponding routines otherwise, they do nothing. */
67
68#pragma weak pthread_mutex_lock
69#pragma weak pthread_mutex_unlock
70
71#define mutex_lock(l) (pthread_mutex_lock ? pthread_mutex_lock (l) : 0)
72#define mutex_unlock(l) (pthread_mutex_unlock ? pthread_mutex_unlock (l) : 0)
73
74#define UNWI_OBJ(fn) UNW_PASTE(UNW_PREFIX,UNW_PASTE(I,fn))
75#define UNWI_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_UI,UNW_TARGET),_), fn)
76
77extern int UNWI_OBJ(find_dynamic_proc_info) (unw_addr_space_t as,
78 unw_word_t ip,
79 unw_proc_info_t *pi,
80 int need_unwind_info, void *arg);
81extern int UNWI_ARCH_OBJ(extract_dynamic_proc_info) (unw_addr_space_t as,
82 unw_word_t ip,
83 unw_proc_info_t *pi,
84 unw_dyn_info_t *di,
85 int need_unwind_info,
86 void *arg);
87extern void UNWI_OBJ(put_dynamic_unwind_info) (unw_addr_space_t as,
88 unw_proc_info_t *pi, void *arg);
89extern int UNWI_ARCH_OBJ(dyn_remote_find_proc_info) (unw_addr_space_t as,
90 unw_word_t ip,
91 unw_proc_info_t *pi,
92 unw_word_t *generation,
93 int need_unwind_info,
94 void *arg);
95extern void UNWI_ARCH_OBJ(dyn_remote_put_unwind_info) (unw_addr_space_t as,
96 unw_proc_info_t *pi,
97 void *arg);
98extern int UNWI_ARCH_OBJ(get_proc_name) (unw_addr_space_t as,
99 unw_word_t ip, int is_local,
100 char *buf, size_t buf_len, void *arg);
101
102#define unwi_find_dynamic_proc_info(as,ip,pi,n,arg) \
103 UNWI_OBJ(find_dynamic_proc_info)(as, ip, pi, n, arg)
104
105#define unwi_extract_dynamic_proc_info(as,ip,pi,di,n,arg) \
106 UNWI_ARCH_OBJ(extract_dynamic_proc_info)(as, ip, pi, di, n, arg)
107
108#define unwi_put_dynamic_unwind_info(as,pi,arg) \
109 UNWI_OBJ(put_dynamic_unwind_info)(as, pi, arg)
110
111/* These handle the remote (cross-address-space) case of accessing
112 dynamic unwind info. */
113
114#define unwi_dyn_remote_find_proc_info(as,i,p,g,n,arg) \
115 UNWI_ARCH_OBJ(dyn_remote_find_proc_info)(as, i, p, g, n, arg)
116
117#define unwi_dyn_remote_put_unwind_info(as,p,arg) \
118 UNWI_ARCH_OBJ(dyn_remote_put_unwind_info)(as, p, arg)
119
120#define unwi_get_proc_name(as,ip,l,b,s,arg) \
121 UNWI_ARCH_OBJ(get_proc_name)(as, ip, l, b, s, arg)
122
123extern unw_dyn_info_list_t _U_dyn_info_list;
124extern pthread_mutex_t _U_dyn_info_list_lock;
125
126#define WSIZE (sizeof (unw_word_t))
127
128static inline int
129fetch8 (unw_addr_space_t as, unw_accessors_t *a,
130 unw_word_t *addr, int8_t *valp, void *arg)
131{
132 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
133 int ret;
134
135 *addr += 1;
136
137 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
138
139#if __BYTE_ORDER == __LITTLE_ENDIAN
140 val >>= 8*off;
141#else
142 val >>= 8*(WSIZE - 1 - off);
143#endif
144 *valp = val & 0xff;
145 return ret;
146}
147
148static inline int
149fetch16 (unw_addr_space_t as, unw_accessors_t *a,
150 unw_word_t *addr, int16_t *valp, void *arg)
151{
152 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
153 int ret;
154
155 assert ((off & 0x1) == 0);
156
157 *addr += 2;
158
159 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
160
161#if __BYTE_ORDER == __LITTLE_ENDIAN
162 val >>= 8*off;
163#else
164 val >>= 8*(WSIZE - 2 - off);
165#endif
166 *valp = val & 0xffff;
167 return ret;
168}
169
170static inline int
171fetch32 (unw_addr_space_t as, unw_accessors_t *a,
172 unw_word_t *addr, int32_t *valp, void *arg)
173{
174 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
175 int ret;
176
177 assert ((off & 0x3) == 0);
178
179 *addr += 4;
180
181 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
182
183#if __BYTE_ORDER == __LITTLE_ENDIAN
184 val >>= 8*off;
185#else
186 val >>= 8*(WSIZE - 4 - off);
187#endif
188 *valp = val & 0xffffffff;
189 return ret;
190}
191
192static inline int
193fetchw (unw_addr_space_t as, unw_accessors_t *a,
194 unw_word_t *addr, unw_word_t *valp, void *arg)
195{
196 int ret;
197
198 ret = (*a->access_mem) (as, *addr, valp, 0, arg);
199 *addr += WSIZE;
200 return ret;
201}
202
203extern void mi_init (void); /* machine-independent initializations */
204
205#include <tdep.h>
206
207#endif /* internal_h */