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