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