]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
1c79356b A |
25 | /* |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
30 | * Permission to use, copy, modify and distribute this software and its | |
31 | * documentation is hereby granted, provided that both the copyright | |
32 | * notice and this permission notice appear in all copies of the | |
33 | * software, derivative works or modified versions, and any portions | |
34 | * thereof, and that both notices appear in supporting documentation. | |
35 | * | |
36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * Author: Alessandro Forin, Carnegie Mellon University | |
54 | * Date: 8/90 | |
55 | */ | |
56 | ||
57 | #ifndef _DDB_DB_SYM_H_ | |
58 | #define _DDB_DB_SYM_H_ | |
59 | ||
60 | #include <mach/boolean.h> | |
61 | #include <mach/machine/vm_types.h> | |
62 | #include <machine/db_machdep.h> | |
63 | #include <kern/task.h> | |
64 | ||
65 | /* | |
66 | * This module can handle multiple symbol tables, | |
67 | * of multiple types, at the same time | |
68 | */ | |
69 | #define SYMTAB_NAME_LEN 32 | |
70 | ||
71 | typedef struct { | |
72 | int type; | |
73 | #define SYMTAB_AOUT 0 | |
74 | #define SYMTAB_COFF 1 | |
75 | #define SYMTAB_MACHDEP 2 | |
76 | char *start; /* symtab location */ | |
77 | char *end; | |
78 | char *private; /* optional machdep pointer */ | |
79 | char *map_pointer; /* symbols are for this map only, | |
80 | if not null */ | |
81 | char name[SYMTAB_NAME_LEN]; | |
82 | /* symtab name */ | |
83 | unsigned long minsym; /* lowest symbol value */ | |
84 | unsigned long maxsym; /* highest symbol value */ | |
85 | boolean_t sorted; /* is this table sorted ? */ | |
86 | } db_symtab_t; | |
87 | ||
88 | extern db_symtab_t *db_last_symtab; /* where last symbol was found */ | |
89 | ||
90 | /* | |
91 | * Symbol representation is specific to the symtab style: | |
92 | * BSD compilers use dbx' nlist, other compilers might use | |
93 | * a different one | |
94 | */ | |
95 | typedef void * db_sym_t; /* opaque handle on symbols */ | |
96 | #define DB_SYM_NULL ((db_sym_t)0) | |
97 | ||
98 | /* | |
99 | * Non-stripped symbol tables will have duplicates, for instance | |
100 | * the same string could match a parameter name, a local var, a | |
101 | * global var, etc. | |
102 | * We are most concern with the following matches. | |
103 | */ | |
104 | typedef int db_strategy_t; /* search strategy */ | |
105 | ||
106 | #define DB_STGY_ANY 0 /* anything goes */ | |
107 | #define DB_STGY_XTRN 1 /* only external symbols */ | |
108 | #define DB_STGY_PROC 2 /* only procedures */ | |
109 | ||
110 | extern boolean_t db_qualify_ambiguous_names; | |
111 | /* if TRUE, check across symbol tables | |
112 | * for multiple occurrences of a name. | |
113 | * Might slow down quite a bit */ | |
114 | ||
115 | extern unsigned long db_maxoff; | |
116 | ||
117 | /* Prototypes for functions exported by this module. | |
118 | */ | |
119 | extern boolean_t db_add_symbol_table( | |
120 | int type, | |
121 | char *start, | |
122 | char *end, | |
123 | char *name, | |
124 | char *ref, | |
125 | char *map_pointer, | |
126 | unsigned long minsym, | |
127 | unsigned long maxsym, | |
128 | boolean_t sorted); | |
129 | ||
130 | extern void db_install_inks( | |
131 | vm_offset_t base); | |
132 | ||
133 | extern boolean_t db_value_of_name( | |
134 | char *name, | |
135 | db_expr_t *valuep); | |
136 | ||
137 | extern db_sym_t db_lookup(char *symstr); | |
138 | ||
139 | extern char * db_get_sym( | |
140 | db_expr_t * off); | |
141 | ||
142 | extern db_sym_t db_sym_parse_and_lookup( | |
143 | int (*func)(db_symtab_t *, | |
144 | char *, | |
145 | char *, | |
146 | int, | |
147 | db_sym_t*, | |
148 | char **, | |
149 | int *), | |
150 | db_symtab_t *symtab, | |
151 | char *symstr); | |
152 | ||
153 | extern int db_sym_parse_and_lookup_incomplete( | |
154 | int (*func)(db_symtab_t *, | |
155 | char *, | |
156 | char *, | |
157 | int, | |
158 | db_sym_t*, | |
159 | char **, | |
160 | int *), | |
161 | db_symtab_t *symtab, | |
162 | char *symstr, | |
163 | char **name, | |
164 | int *len, | |
165 | int *toadd); | |
166 | ||
167 | extern int db_sym_parse_and_print_completion( | |
168 | int (*func)(db_symtab_t *, | |
169 | char *), | |
170 | db_symtab_t *symtab, | |
171 | char *symstr); | |
172 | ||
173 | extern db_sym_t db_search_task_symbol( | |
174 | db_addr_t val, | |
175 | db_strategy_t strategy, | |
176 | db_addr_t *offp, | |
177 | task_t task); | |
178 | ||
179 | extern db_sym_t db_search_task_symbol_and_line( | |
180 | db_addr_t val, | |
181 | db_strategy_t strategy, | |
182 | db_expr_t *offp, | |
183 | char **filenamep, | |
184 | int *linenump, | |
185 | task_t task, | |
186 | int *argsp); | |
187 | ||
188 | extern void db_symbol_values( | |
189 | db_symtab_t *stab, | |
190 | db_sym_t sym, | |
191 | char **namep, | |
192 | db_expr_t *valuep); | |
193 | ||
194 | extern void db_task_printsym( | |
195 | db_expr_t off, | |
196 | db_strategy_t strategy, | |
197 | task_t task); | |
198 | ||
199 | extern void db_printsym( | |
200 | db_expr_t off, | |
201 | db_strategy_t strategy); | |
202 | ||
203 | extern boolean_t db_line_at_pc( | |
204 | db_sym_t sym, | |
205 | char **filename, | |
206 | int *linenum, | |
207 | db_expr_t pc); | |
208 | ||
209 | extern void db_qsort( | |
210 | char *table, | |
211 | int nbelts, | |
212 | int eltsize, | |
213 | int (*compfun)(char *, char *)); | |
214 | ||
215 | extern void db_qsort_limit_search( | |
216 | char *target, | |
217 | char **start, | |
218 | char **end, | |
219 | int eltsize, | |
220 | int (*compfun)(char *, char *)); | |
221 | ||
222 | extern void db_sym_print_completion( | |
223 | db_symtab_t *stab, | |
224 | char *name, | |
225 | int function, | |
226 | char *fname, | |
227 | int line); | |
228 | ||
229 | extern void db_print_completion( | |
230 | char *symstr); | |
231 | ||
232 | extern int db_lookup_incomplete( | |
233 | char *symstr, | |
234 | int symlen); | |
235 | ||
236 | extern void ddb_init(void); | |
237 | ||
238 | extern void db_machdep_init(void); | |
239 | ||
240 | extern void db_clone_symtabXXX(char *, char *, vm_offset_t); | |
241 | ||
242 | extern db_symtab_t *db_symtab_cloneeXXX(char *); | |
243 | ||
91447636 | 244 | extern int db_task_getlinenum( db_expr_t, task_t); |
1c79356b A |
245 | |
246 | /* Some convenience macros. | |
247 | */ | |
248 | #define db_find_sym_and_offset(val,namep,offp) \ | |
249 | db_symbol_values(0, db_search_symbol(val,DB_STGY_ANY,offp),namep,0) | |
250 | /* find name&value given approx val */ | |
251 | ||
252 | #define db_find_xtrn_sym_and_offset(val,namep,offp) \ | |
253 | db_symbol_values(0, db_search_symbol(val,DB_STGY_XTRN,offp),namep,0) | |
254 | /* ditto, but no locals */ | |
255 | ||
256 | #define db_find_task_sym_and_offset(val,namep,offp,task) \ | |
257 | db_symbol_values(0, db_search_task_symbol(val,DB_STGY_ANY,offp,task), \ | |
258 | namep, 0) /* find name&value given approx val */ | |
259 | ||
260 | #define db_find_xtrn_task_sym_and_offset(val,namep,offp,task) \ | |
261 | db_symbol_values(0, db_search_task_symbol(val,DB_STGY_XTRN,offp,task), \ | |
262 | namep,0) /* ditto, but no locals */ | |
263 | ||
264 | #define db_search_symbol(val,strgy,offp) \ | |
265 | db_search_task_symbol(val,strgy,offp,0) | |
266 | /* find symbol in current task */ | |
267 | ||
268 | /* | |
269 | * Symbol table switch, defines the interface | |
270 | * to symbol-table specific routines. | |
271 | */ | |
272 | ||
273 | extern struct db_sym_switch { | |
274 | ||
275 | void (*init)(void); | |
276 | ||
277 | boolean_t (*sym_init)( | |
278 | char *start, | |
279 | char *end, | |
280 | char *name, | |
281 | char *task_addr | |
282 | ); | |
283 | ||
284 | db_sym_t (*lookup)( | |
285 | db_symtab_t *stab, | |
286 | char *symstr | |
287 | ); | |
288 | db_sym_t (*search_symbol)( | |
289 | db_symtab_t *stab, | |
290 | db_addr_t off, | |
291 | db_strategy_t strategy, | |
292 | db_expr_t *diffp | |
293 | ); | |
294 | ||
295 | boolean_t (*line_at_pc)( | |
296 | db_symtab_t *stab, | |
297 | db_sym_t sym, | |
298 | char **file, | |
299 | int *line, | |
300 | db_expr_t pc | |
301 | ); | |
302 | ||
303 | void (*symbol_values)( | |
304 | db_sym_t sym, | |
305 | char **namep, | |
306 | db_expr_t *valuep | |
307 | ); | |
308 | db_sym_t (*search_by_addr)( | |
309 | db_symtab_t *stab, | |
310 | db_addr_t off, | |
311 | char **file, | |
312 | char **func, | |
313 | int *line, | |
314 | db_expr_t *diffp, | |
315 | int *args | |
316 | ); | |
317 | ||
318 | int (*print_completion)( | |
319 | db_symtab_t *stab, | |
320 | char *symstr | |
321 | ); | |
322 | ||
323 | int (*lookup_incomplete)( | |
324 | db_symtab_t *stab, | |
325 | char *symstr, | |
326 | char **name, | |
327 | int *len, | |
328 | int *toadd | |
329 | ); | |
330 | } x_db[]; | |
331 | ||
332 | #ifndef symtab_type | |
333 | #define symtab_type(s) SYMTAB_AOUT | |
334 | #endif | |
335 | ||
336 | #define X_db_init() x_db[symtab_type(s)].init() | |
337 | #define X_db_sym_init(s,e,n,t) x_db[symtab_type(s)].sym_init(s,e,n,t) | |
338 | #define X_db_lookup(s,n) x_db[(s)->type].lookup(s,n) | |
339 | #define X_db_search_symbol(s,o,t,d) x_db[(s)->type].search_symbol(s,o,t,d) | |
340 | #define X_db_line_at_pc(s,p,f,l,a) x_db[(s)->type].line_at_pc(s,p,f,l,a) | |
341 | #define X_db_symbol_values(s,p,n,v) x_db[(s)->type].symbol_values(p,n,v) | |
342 | #define X_db_search_by_addr(s,a,f,c,l,d,r) \ | |
343 | x_db[(s)->type].search_by_addr(s,a,f,c,l,d,r) | |
344 | #define X_db_print_completion(s,p) x_db[(s)->type].print_completion(s,p) | |
345 | #define X_db_lookup_incomplete(s,p,n,l,t) \ | |
346 | x_db[(s)->type].lookup_incomplete(s,p,n,l,t) | |
347 | ||
348 | #endif /* !_DDB_DB_SYM_H_ */ |