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