]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_sym.h
xnu-344.23.tar.gz
[apple/xnu.git] / osfmk / ddb / db_sym.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * HISTORY
27 *
28 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
29 * Import of Mac OS X kernel (~semeria)
30 *
31 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
32 * Import of OSF Mach kernel (~mburg)
33 *
34 * Revision 1.2.20.6 1996/01/09 19:16:22 devrcs
35 * Add proto for db_task_getlinenum().
36 * [1995/12/01 21:42:34 jfraser]
37 *
38 * Revision 1.2.20.5 1995/02/28 01:58:53 dwm
39 * Merged with changes from 1.2.20.4
40 * [1995/02/28 01:53:54 dwm]
41 *
42 * mk6 CR1120 - Merge mk6pro_shared into cnmk_shared
43 * [1995/02/28 01:12:57 dwm]
44 *
45 * Revision 1.2.20.4 1995/02/23 21:43:48 alanl
46 * Prepend a "db_" to qsort and qsort_limit_search
47 * (collisions with the real qsort in stdlib.h)
48 * [95/02/14 travos]
49 *
50 * Expanded db_sym_switch structure to make ddb object format dependent;
51 * this allows us to remove all of the aout dependencies.
52 * [95/01/24 sjs]
53 *
54 * Revision 1.2.23.4 1994/12/22 20:36:20 bolinger
55 * Fix ri-osc CR881: Fixed glitch in use of symtab cloning hack.
56 * [1994/12/22 20:35:17 bolinger]
57 *
58 * Revision 1.2.23.3 1994/11/02 18:36:07 dwm
59 * mk6 CR668 - 1.3b26 merge
60 * 64bit cleanup, prototypes
61 * fix X_db_search_by_addr macro to match prototype
62 * [1994/11/02 18:16:20 dwm]
63 *
64 * Revision 1.2.20.4 1995/02/23 21:43:48 alanl
65 * Prepend a "db_" to qsort and qsort_limit_search
66 * (collisions with the real qsort in stdlib.h)
67 * [95/02/14 travos]
68 *
69 * Expanded db_sym_switch structure to make ddb object format dependent;
70 * this allows us to remove all of the aout dependencies.
71 * [95/01/24 sjs]
72 *
73 * Revision 1.2.23.4 1994/12/22 20:36:20 bolinger
74 * Fix ri-osc CR881: Fixed glitch in use of symtab cloning hack.
75 * [1994/12/22 20:35:17 bolinger]
76 *
77 * Revision 1.2.23.3 1994/11/02 18:36:07 dwm
78 * mk6 CR668 - 1.3b26 merge
79 * 64bit cleanup, prototypes
80 * fix X_db_search_by_addr macro to match prototype
81 * [1994/11/02 18:16:20 dwm]
82 *
83 * Revision 1.2.20.2 1994/09/23 01:21:51 ezf
84 * change marker to not FREE
85 * [1994/09/22 21:11:04 ezf]
86 *
87 * Revision 1.2.20.1 1994/06/11 21:12:25 bolinger
88 * Merge up to NMK17.2.
89 * [1994/06/11 20:04:14 bolinger]
90 *
91 * Revision 1.2.14.1 1994/02/08 10:58:56 bernadat
92 * Added db_sym_print_completion
93 * db_sym_parse_and_lookup_incomplete
94 * db_sym_parse_and_print_completion
95 * db_print_completion
96 * db_lookup_incomplete
97 * ddb_init
98 * prototypes
99 *
100 * Changed func type to db_sym_parse_and_lookup prototype
101 *
102 * Added definition of db_maxoff.
103 * [93/08/12 paire]
104 * [94/02/07 bernadat]
105 *
106 * Revision 1.2.18.1 1994/06/08 19:11:28 dswartz
107 * Preemption merge.
108 * [1994/06/08 19:10:27 dswartz]
109 *
110 * Revision 1.2.17.2 1994/06/01 21:34:50 klj
111 * Initial preemption code base merge
112 *
113 * Revision 1.2.4.3 1993/07/27 18:28:12 elliston
114 * Add ANSI prototypes. CR #9523.
115 * [1993/07/27 18:13:02 elliston]
116 *
117 * Revision 1.2.4.2 1993/06/09 02:20:56 gm
118 * Added to OSF/1 R1.3 from NMK15.0.
119 * [1993/06/02 20:57:18 jeffc]
120 *
121 * Revision 1.2 1993/04/19 16:03:18 devrcs
122 * Added 3 new fields in db_symtab_t for sorting.
123 * [barbou@gr.osf.org]
124 * [92/12/03 bernadat]
125 *
126 * Revision 1.1 1992/09/30 02:24:22 robert
127 * Initial revision
128 *
129 * $EndLog$
130 */
131 /* CMU_HIST */
132 /*
133 * Revision 2.6 91/10/09 16:02:45 af
134 * Revision 2.5.1.1 91/10/05 13:07:39 jeffreyh
135 * Added macro definitions of db_find_task_sym_and_offset(),
136 * db_find_xtrn_task_sym_and_offset(), db_search_symbol().
137 * [91/08/29 tak]
138 *
139 * Revision 2.5.1.1 91/10/05 13:07:39 jeffreyh
140 * Added macro definitions of db_find_task_sym_and_offset(),
141 * db_find_xtrn_task_sym_and_offset(), db_search_symbol().
142 * [91/08/29 tak]
143 *
144 * Revision 2.5 91/07/31 17:31:49 dbg
145 * Add map pointer and storage for name to db_symtab_t.
146 * [91/07/30 16:45:08 dbg]
147 *
148 * Revision 2.4 91/05/14 15:36:08 mrt
149 * Correcting copyright
150 *
151 * Revision 2.3 91/02/05 17:07:12 mrt
152 * Changed to new Mach copyright
153 * [91/01/31 16:19:27 mrt]
154 *
155 * Revision 2.2 90/08/27 21:52:39 dbg
156 * Changed type of db_sym_t to char * - it's a better type for an
157 * opaque pointer.
158 * [90/08/22 dbg]
159 *
160 * Created.
161 * [90/08/19 af]
162 *
163 */
164 /* CMU_ENDHIST */
165 /*
166 * Mach Operating System
167 * Copyright (c) 1991,1990 Carnegie Mellon University
168 * All Rights Reserved.
169 *
170 * Permission to use, copy, modify and distribute this software and its
171 * documentation is hereby granted, provided that both the copyright
172 * notice and this permission notice appear in all copies of the
173 * software, derivative works or modified versions, and any portions
174 * thereof, and that both notices appear in supporting documentation.
175 *
176 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
177 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
178 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
179 *
180 * Carnegie Mellon requests users of this software to return to
181 *
182 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
183 * School of Computer Science
184 * Carnegie Mellon University
185 * Pittsburgh PA 15213-3890
186 *
187 * any improvements or extensions that they make and grant Carnegie Mellon
188 * the rights to redistribute these changes.
189 */
190 /*
191 */
192 /*
193 * Author: Alessandro Forin, Carnegie Mellon University
194 * Date: 8/90
195 */
196
197 #ifndef _DDB_DB_SYM_H_
198 #define _DDB_DB_SYM_H_
199
200 #include <mach/boolean.h>
201 #include <mach/machine/vm_types.h>
202 #include <machine/db_machdep.h>
203 #include <kern/task.h>
204
205 /*
206 * This module can handle multiple symbol tables,
207 * of multiple types, at the same time
208 */
209 #define SYMTAB_NAME_LEN 32
210
211 typedef struct {
212 int type;
213 #define SYMTAB_AOUT 0
214 #define SYMTAB_COFF 1
215 #define SYMTAB_MACHDEP 2
216 char *start; /* symtab location */
217 char *end;
218 char *private; /* optional machdep pointer */
219 char *map_pointer; /* symbols are for this map only,
220 if not null */
221 char name[SYMTAB_NAME_LEN];
222 /* symtab name */
223 unsigned long minsym; /* lowest symbol value */
224 unsigned long maxsym; /* highest symbol value */
225 boolean_t sorted; /* is this table sorted ? */
226 } db_symtab_t;
227
228 extern db_symtab_t *db_last_symtab; /* where last symbol was found */
229
230 /*
231 * Symbol representation is specific to the symtab style:
232 * BSD compilers use dbx' nlist, other compilers might use
233 * a different one
234 */
235 typedef void * db_sym_t; /* opaque handle on symbols */
236 #define DB_SYM_NULL ((db_sym_t)0)
237
238 /*
239 * Non-stripped symbol tables will have duplicates, for instance
240 * the same string could match a parameter name, a local var, a
241 * global var, etc.
242 * We are most concern with the following matches.
243 */
244 typedef int db_strategy_t; /* search strategy */
245
246 #define DB_STGY_ANY 0 /* anything goes */
247 #define DB_STGY_XTRN 1 /* only external symbols */
248 #define DB_STGY_PROC 2 /* only procedures */
249
250 extern boolean_t db_qualify_ambiguous_names;
251 /* if TRUE, check across symbol tables
252 * for multiple occurrences of a name.
253 * Might slow down quite a bit */
254
255 extern unsigned long db_maxoff;
256
257 /* Prototypes for functions exported by this module.
258 */
259 extern boolean_t db_add_symbol_table(
260 int type,
261 char *start,
262 char *end,
263 char *name,
264 char *ref,
265 char *map_pointer,
266 unsigned long minsym,
267 unsigned long maxsym,
268 boolean_t sorted);
269
270 extern void db_install_inks(
271 vm_offset_t base);
272
273 extern boolean_t db_value_of_name(
274 char *name,
275 db_expr_t *valuep);
276
277 extern db_sym_t db_lookup(char *symstr);
278
279 extern char * db_get_sym(
280 db_expr_t * off);
281
282 extern db_sym_t db_sym_parse_and_lookup(
283 int (*func)(db_symtab_t *,
284 char *,
285 char *,
286 int,
287 db_sym_t*,
288 char **,
289 int *),
290 db_symtab_t *symtab,
291 char *symstr);
292
293 extern int db_sym_parse_and_lookup_incomplete(
294 int (*func)(db_symtab_t *,
295 char *,
296 char *,
297 int,
298 db_sym_t*,
299 char **,
300 int *),
301 db_symtab_t *symtab,
302 char *symstr,
303 char **name,
304 int *len,
305 int *toadd);
306
307 extern int db_sym_parse_and_print_completion(
308 int (*func)(db_symtab_t *,
309 char *),
310 db_symtab_t *symtab,
311 char *symstr);
312
313 extern db_sym_t db_search_task_symbol(
314 db_addr_t val,
315 db_strategy_t strategy,
316 db_addr_t *offp,
317 task_t task);
318
319 extern db_sym_t db_search_task_symbol_and_line(
320 db_addr_t val,
321 db_strategy_t strategy,
322 db_expr_t *offp,
323 char **filenamep,
324 int *linenump,
325 task_t task,
326 int *argsp);
327
328 extern void db_symbol_values(
329 db_symtab_t *stab,
330 db_sym_t sym,
331 char **namep,
332 db_expr_t *valuep);
333
334 extern void db_task_printsym(
335 db_expr_t off,
336 db_strategy_t strategy,
337 task_t task);
338
339 extern void db_printsym(
340 db_expr_t off,
341 db_strategy_t strategy);
342
343 extern boolean_t db_line_at_pc(
344 db_sym_t sym,
345 char **filename,
346 int *linenum,
347 db_expr_t pc);
348
349 extern void db_qsort(
350 char *table,
351 int nbelts,
352 int eltsize,
353 int (*compfun)(char *, char *));
354
355 extern void db_qsort_limit_search(
356 char *target,
357 char **start,
358 char **end,
359 int eltsize,
360 int (*compfun)(char *, char *));
361
362 extern void db_sym_print_completion(
363 db_symtab_t *stab,
364 char *name,
365 int function,
366 char *fname,
367 int line);
368
369 extern void db_print_completion(
370 char *symstr);
371
372 extern int db_lookup_incomplete(
373 char *symstr,
374 int symlen);
375
376 extern void ddb_init(void);
377
378 extern void db_machdep_init(void);
379
380 extern void db_clone_symtabXXX(char *, char *, vm_offset_t);
381
382 extern db_symtab_t *db_symtab_cloneeXXX(char *);
383
384 extern db_task_getlinenum( db_expr_t, task_t);
385
386 /* Some convenience macros.
387 */
388 #define db_find_sym_and_offset(val,namep,offp) \
389 db_symbol_values(0, db_search_symbol(val,DB_STGY_ANY,offp),namep,0)
390 /* find name&value given approx val */
391
392 #define db_find_xtrn_sym_and_offset(val,namep,offp) \
393 db_symbol_values(0, db_search_symbol(val,DB_STGY_XTRN,offp),namep,0)
394 /* ditto, but no locals */
395
396 #define db_find_task_sym_and_offset(val,namep,offp,task) \
397 db_symbol_values(0, db_search_task_symbol(val,DB_STGY_ANY,offp,task), \
398 namep, 0) /* find name&value given approx val */
399
400 #define db_find_xtrn_task_sym_and_offset(val,namep,offp,task) \
401 db_symbol_values(0, db_search_task_symbol(val,DB_STGY_XTRN,offp,task), \
402 namep,0) /* ditto, but no locals */
403
404 #define db_search_symbol(val,strgy,offp) \
405 db_search_task_symbol(val,strgy,offp,0)
406 /* find symbol in current task */
407
408 /*
409 * Symbol table switch, defines the interface
410 * to symbol-table specific routines.
411 */
412
413 extern struct db_sym_switch {
414
415 void (*init)(void);
416
417 boolean_t (*sym_init)(
418 char *start,
419 char *end,
420 char *name,
421 char *task_addr
422 );
423
424 db_sym_t (*lookup)(
425 db_symtab_t *stab,
426 char *symstr
427 );
428 db_sym_t (*search_symbol)(
429 db_symtab_t *stab,
430 db_addr_t off,
431 db_strategy_t strategy,
432 db_expr_t *diffp
433 );
434
435 boolean_t (*line_at_pc)(
436 db_symtab_t *stab,
437 db_sym_t sym,
438 char **file,
439 int *line,
440 db_expr_t pc
441 );
442
443 void (*symbol_values)(
444 db_sym_t sym,
445 char **namep,
446 db_expr_t *valuep
447 );
448 db_sym_t (*search_by_addr)(
449 db_symtab_t *stab,
450 db_addr_t off,
451 char **file,
452 char **func,
453 int *line,
454 db_expr_t *diffp,
455 int *args
456 );
457
458 int (*print_completion)(
459 db_symtab_t *stab,
460 char *symstr
461 );
462
463 int (*lookup_incomplete)(
464 db_symtab_t *stab,
465 char *symstr,
466 char **name,
467 int *len,
468 int *toadd
469 );
470 } x_db[];
471
472 #ifndef symtab_type
473 #define symtab_type(s) SYMTAB_AOUT
474 #endif
475
476 #define X_db_init() x_db[symtab_type(s)].init()
477 #define X_db_sym_init(s,e,n,t) x_db[symtab_type(s)].sym_init(s,e,n,t)
478 #define X_db_lookup(s,n) x_db[(s)->type].lookup(s,n)
479 #define X_db_search_symbol(s,o,t,d) x_db[(s)->type].search_symbol(s,o,t,d)
480 #define X_db_line_at_pc(s,p,f,l,a) x_db[(s)->type].line_at_pc(s,p,f,l,a)
481 #define X_db_symbol_values(s,p,n,v) x_db[(s)->type].symbol_values(p,n,v)
482 #define X_db_search_by_addr(s,a,f,c,l,d,r) \
483 x_db[(s)->type].search_by_addr(s,a,f,c,l,d,r)
484 #define X_db_print_completion(s,p) x_db[(s)->type].print_completion(s,p)
485 #define X_db_lookup_incomplete(s,p,n,l,t) \
486 x_db[(s)->type].lookup_incomplete(s,p,n,l,t)
487
488 #endif /* !_DDB_DB_SYM_H_ */