Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/*
 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
 *
 * @APPLE_LICENSE_HEADER_START@
 * 
 * The contents of this file constitute Original Code as defined in and
 * are subject to the Apple Public Source License Version 1.1 (the
 * "License").  You may not use this file except in compliance with the
 * License.  Please obtain a copy of the License at
 * http://www.apple.com/publicsource and read it before using this file.
 * 
 * This Original Code and all software distributed under the License are
 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * @APPLE_LICENSE_HEADER_END@
 */
/*
 * @OSF_COPYRIGHT@
 */
/*
 * HISTORY
 * 
 * Revision 1.1.1.1  1998/09/22 21:05:48  wsanchez
 * Import of Mac OS X kernel (~semeria)
 *
 * Revision 1.1.1.1  1998/03/07 02:26:09  wsanchez
 * Import of OSF Mach kernel (~mburg)
 *
 * Revision 1.2.20.6  1996/01/09  19:16:22  devrcs
 * 	Add proto for db_task_getlinenum().
 * 	[1995/12/01  21:42:34  jfraser]
 *
 * Revision 1.2.20.5  1995/02/28  01:58:53  dwm
 * 	Merged with changes from 1.2.20.4
 * 	[1995/02/28  01:53:54  dwm]
 * 
 * 	mk6 CR1120 - Merge mk6pro_shared into cnmk_shared
 * 	[1995/02/28  01:12:57  dwm]
 * 
 * Revision 1.2.20.4  1995/02/23  21:43:48  alanl
 * 	Prepend a "db_" to qsort and qsort_limit_search
 * 	(collisions with the real qsort in stdlib.h)
 * 	[95/02/14            travos]
 * 
 * 	Expanded db_sym_switch structure to make ddb object format dependent;
 * 	this allows us to remove all of the aout dependencies.
 * 	[95/01/24            sjs]
 * 
 * Revision 1.2.23.4  1994/12/22  20:36:20  bolinger
 * 	Fix ri-osc CR881:  Fixed glitch in use of symtab cloning hack.
 * 	[1994/12/22  20:35:17  bolinger]
 * 
 * Revision 1.2.23.3  1994/11/02  18:36:07  dwm
 * 	mk6 CR668 - 1.3b26 merge
 * 	64bit cleanup, prototypes
 * 	fix X_db_search_by_addr macro to match prototype
 * 	[1994/11/02  18:16:20  dwm]
 * 
 * Revision 1.2.20.4  1995/02/23  21:43:48  alanl
 * 	Prepend a "db_" to qsort and qsort_limit_search
 * 	(collisions with the real qsort in stdlib.h)
 * 	[95/02/14            travos]
 * 
 * 	Expanded db_sym_switch structure to make ddb object format dependent;
 * 	this allows us to remove all of the aout dependencies.
 * 	[95/01/24            sjs]
 * 
 * Revision 1.2.23.4  1994/12/22  20:36:20  bolinger
 * 	Fix ri-osc CR881:  Fixed glitch in use of symtab cloning hack.
 * 	[1994/12/22  20:35:17  bolinger]
 * 
 * Revision 1.2.23.3  1994/11/02  18:36:07  dwm
 * 	mk6 CR668 - 1.3b26 merge
 * 	64bit cleanup, prototypes
 * 	fix X_db_search_by_addr macro to match prototype
 * 	[1994/11/02  18:16:20  dwm]
 * 
 * Revision 1.2.20.2  1994/09/23  01:21:51  ezf
 * 	change marker to not FREE
 * 	[1994/09/22  21:11:04  ezf]
 * 
 * Revision 1.2.20.1  1994/06/11  21:12:25  bolinger
 * 	Merge up to NMK17.2.
 * 	[1994/06/11  20:04:14  bolinger]
 * 
 * Revision 1.2.14.1  1994/02/08  10:58:56  bernadat
 * 	Added db_sym_print_completion
 * 	      db_sym_parse_and_lookup_incomplete
 * 	      db_sym_parse_and_print_completion
 * 	      db_print_completion
 * 	      db_lookup_incomplete
 * 	      ddb_init
 * 	prototypes
 * 
 * 	Changed func type to db_sym_parse_and_lookup prototype
 * 
 * 	Added definition of db_maxoff.
 * 	[93/08/12            paire]
 * 	[94/02/07            bernadat]
 * 
 * Revision 1.2.18.1  1994/06/08  19:11:28  dswartz
 * 	Preemption merge.
 * 	[1994/06/08  19:10:27  dswartz]
 * 
 * Revision 1.2.17.2  1994/06/01  21:34:50  klj
 * 	Initial preemption code base merge
 * 
 * Revision 1.2.4.3  1993/07/27  18:28:12  elliston
 * 	Add ANSI prototypes.  CR #9523.
 * 	[1993/07/27  18:13:02  elliston]
 * 
 * Revision 1.2.4.2  1993/06/09  02:20:56  gm
 * 	Added to OSF/1 R1.3 from NMK15.0.
 * 	[1993/06/02  20:57:18  jeffc]
 * 
 * Revision 1.2  1993/04/19  16:03:18  devrcs
 * 	Added 3 new fields in db_symtab_t for sorting.
 * 	[barbou@gr.osf.org]
 * 	[92/12/03            bernadat]
 * 
 * Revision 1.1  1992/09/30  02:24:22  robert
 * 	Initial revision
 * 
 * $EndLog$
 */
/* CMU_HIST */
/*
 * Revision 2.6  91/10/09  16:02:45  af
 * 	 Revision 2.5.1.1  91/10/05  13:07:39  jeffreyh
 * 	 	Added macro definitions of db_find_task_sym_and_offset(),
 * 	 	  db_find_xtrn_task_sym_and_offset(), db_search_symbol().
 * 	 	[91/08/29            tak]
 * 
 * Revision 2.5.1.1  91/10/05  13:07:39  jeffreyh
 * 	Added macro definitions of db_find_task_sym_and_offset(),
 * 	  db_find_xtrn_task_sym_and_offset(), db_search_symbol().
 * 	[91/08/29            tak]
 * 
 * Revision 2.5  91/07/31  17:31:49  dbg
 * 	Add map pointer and storage for name to db_symtab_t.
 * 	[91/07/30  16:45:08  dbg]
 * 
 * Revision 2.4  91/05/14  15:36:08  mrt
 * 	Correcting copyright
 * 
 * Revision 2.3  91/02/05  17:07:12  mrt
 * 	Changed to new Mach copyright
 * 	[91/01/31  16:19:27  mrt]
 * 
 * Revision 2.2  90/08/27  21:52:39  dbg
 * 	Changed type of db_sym_t to char * - it's a better type for an
 * 	opaque pointer.
 * 	[90/08/22            dbg]
 * 
 * 	Created.
 * 	[90/08/19            af]
 * 
 */
/* CMU_ENDHIST */
/* 
 * Mach Operating System
 * Copyright (c) 1991,1990 Carnegie Mellon University
 * All Rights Reserved.
 * 
 * Permission to use, copy, modify and distribute this software and its
 * documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 * 
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 * 
 * Carnegie Mellon requests users of this software to return to
 * 
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 * 
 * any improvements or extensions that they make and grant Carnegie Mellon
 * the rights to redistribute these changes.
 */
/*
 */
/*
 * 	Author: Alessandro Forin, Carnegie Mellon University
 *	Date:	8/90
 */

#ifndef	_DDB_DB_SYM_H_
#define	_DDB_DB_SYM_H_

#include <mach/boolean.h>
#include <mach/machine/vm_types.h>
#include <machine/db_machdep.h>
#include <kern/task.h>

/*
 * This module can handle multiple symbol tables,
 * of multiple types, at the same time
 */
#define	SYMTAB_NAME_LEN	32

typedef struct {
	int		type;
#define	SYMTAB_AOUT	0
#define	SYMTAB_COFF	1
#define	SYMTAB_MACHDEP	2
	char		*start;		/* symtab location */
	char		*end;
	char		*private;	/* optional machdep pointer */
	char		*map_pointer;	/* symbols are for this map only,
					   if not null */
	char		name[SYMTAB_NAME_LEN];
					/* symtab name */
	unsigned long	minsym;		/* lowest symbol value */
	unsigned long	maxsym;		/* highest symbol value */
	boolean_t	sorted;		/* is this table sorted ? */
} db_symtab_t;

extern db_symtab_t	*db_last_symtab; /* where last symbol was found */

/*
 * Symbol representation is specific to the symtab style:
 * BSD compilers use dbx' nlist, other compilers might use
 * a different one
 */
typedef	void *		db_sym_t;	/* opaque handle on symbols */
#define	DB_SYM_NULL	((db_sym_t)0)

/*
 * Non-stripped symbol tables will have duplicates, for instance
 * the same string could match a parameter name, a local var, a
 * global var, etc.
 * We are most concern with the following matches.
 */
typedef int		db_strategy_t;	/* search strategy */

#define	DB_STGY_ANY	0			/* anything goes */
#define DB_STGY_XTRN	1			/* only external symbols */
#define DB_STGY_PROC	2			/* only procedures */

extern boolean_t	db_qualify_ambiguous_names;
					/* if TRUE, check across symbol tables
					 * for multiple occurrences of a name.
					 * Might slow down quite a bit */

extern unsigned long	db_maxoff;

/* Prototypes for functions exported by this module.
 */
extern boolean_t db_add_symbol_table(
	int		type,
	char		*start,
	char		*end,
	char		*name,
	char		*ref,
	char		*map_pointer,
	unsigned long	minsym,
	unsigned long	maxsym,
	boolean_t	sorted);

extern void db_install_inks(
	vm_offset_t	base);

extern boolean_t db_value_of_name(
	char		*name,
	db_expr_t	*valuep);

extern db_sym_t db_lookup(char *symstr);

extern char * db_get_sym(
	db_expr_t	* off);

extern db_sym_t db_sym_parse_and_lookup(
	int	(*func)(db_symtab_t *,
			char *,
			char *,
			int,
			db_sym_t*,
			char **,
			int *),
	db_symtab_t	*symtab,
	char		*symstr);

extern int db_sym_parse_and_lookup_incomplete(
	int	(*func)(db_symtab_t *,
			char *,
			char *,
			int,
			db_sym_t*,
			char **,
			int *),
	db_symtab_t	*symtab,
	char		*symstr,
	char		**name,
	int		*len,
	int		*toadd);

extern int db_sym_parse_and_print_completion(
	int	(*func)(db_symtab_t *,
			char *),
	db_symtab_t	*symtab,
	char		*symstr);

extern db_sym_t db_search_task_symbol(
	db_addr_t		val,
	db_strategy_t		strategy,
	db_addr_t		*offp,
	task_t			task);

extern db_sym_t db_search_task_symbol_and_line(
	db_addr_t		val,
	db_strategy_t		strategy,
	db_expr_t		*offp,
	char			**filenamep,
	int			*linenump,
	task_t			task,
	int			*argsp);

extern void db_symbol_values(
	db_symtab_t	*stab,
	db_sym_t	sym,
	char		**namep,
	db_expr_t	*valuep);

extern void db_task_printsym(
	db_expr_t	off,
	db_strategy_t	strategy,
	task_t		task);

extern void db_printsym(
	db_expr_t	off,
	db_strategy_t	strategy);

extern boolean_t db_line_at_pc(
	db_sym_t	sym,
	char		**filename,
	int		*linenum,
	db_expr_t	pc);

extern void db_qsort(
	char	*table,
	int	nbelts,
	int	eltsize,
	int	(*compfun)(char *, char *));

extern void db_qsort_limit_search(
	char	*target,
	char	**start,
	char	**end,
	int	eltsize,
	int	(*compfun)(char *, char *));

extern void db_sym_print_completion(
	db_symtab_t *stab,
	char *name,
	int function,
	char *fname,
	int line);

extern void db_print_completion(
	char *symstr);

extern int db_lookup_incomplete(
	char *symstr,
	int symlen);

extern void ddb_init(void);

extern void db_machdep_init(void);

extern void db_clone_symtabXXX(char *, char *, vm_offset_t);

extern db_symtab_t *db_symtab_cloneeXXX(char *);

extern db_task_getlinenum( db_expr_t, task_t);

/* Some convenience macros.
 */
#define db_find_sym_and_offset(val,namep,offp)	\
	db_symbol_values(0, db_search_symbol(val,DB_STGY_ANY,offp),namep,0)
					/* find name&value given approx val */

#define db_find_xtrn_sym_and_offset(val,namep,offp)	\
	db_symbol_values(0, db_search_symbol(val,DB_STGY_XTRN,offp),namep,0)
					/* ditto, but no locals */

#define db_find_task_sym_and_offset(val,namep,offp,task)	\
	db_symbol_values(0, db_search_task_symbol(val,DB_STGY_ANY,offp,task),  \
			 namep, 0)	/* find name&value given approx val */

#define db_find_xtrn_task_sym_and_offset(val,namep,offp,task)	\
	db_symbol_values(0, db_search_task_symbol(val,DB_STGY_XTRN,offp,task), \
			 namep,0)	/* ditto, but no locals */

#define db_search_symbol(val,strgy,offp)	\
	db_search_task_symbol(val,strgy,offp,0)
					/* find symbol in current task */

/*
 * Symbol table switch, defines the interface
 * to symbol-table specific routines.
 */

extern struct db_sym_switch {

	void		(*init)(void);

	boolean_t	(*sym_init)(
				char *start,
				char *end,
				char *name,
				char *task_addr
				);

	db_sym_t	(*lookup)(
				db_symtab_t *stab,
				char *symstr
				);
	db_sym_t	(*search_symbol)(
				db_symtab_t *stab,
				db_addr_t off,
				db_strategy_t strategy,
				db_expr_t *diffp
				);

	boolean_t	(*line_at_pc)(
				db_symtab_t	*stab,
				db_sym_t	sym,
				char		**file,
				int		*line,
				db_expr_t	pc
				);

	void		(*symbol_values)(
				db_sym_t	sym,
				char		**namep,
				db_expr_t	*valuep
				);
	db_sym_t	(*search_by_addr)(
				db_symtab_t	*stab,
				db_addr_t	off,
				char		**file,
				char		**func,
				int		*line,
				db_expr_t	*diffp,
				int		*args
				);

	int		(*print_completion)(
				db_symtab_t	*stab,
				char		*symstr
				);

	int		(*lookup_incomplete)(
				db_symtab_t	*stab,
				char		*symstr,
				char		**name,
				int		*len,
				int		*toadd
				);
} x_db[];

#ifndef	symtab_type
#define	symtab_type(s)		SYMTAB_AOUT
#endif

#define	X_db_init()			x_db[symtab_type(s)].init()
#define	X_db_sym_init(s,e,n,t)		x_db[symtab_type(s)].sym_init(s,e,n,t)
#define	X_db_lookup(s,n)		x_db[(s)->type].lookup(s,n)
#define	X_db_search_symbol(s,o,t,d)	x_db[(s)->type].search_symbol(s,o,t,d)
#define	X_db_line_at_pc(s,p,f,l,a)	x_db[(s)->type].line_at_pc(s,p,f,l,a)
#define	X_db_symbol_values(s,p,n,v)	x_db[(s)->type].symbol_values(p,n,v)
#define X_db_search_by_addr(s,a,f,c,l,d,r) \
			x_db[(s)->type].search_by_addr(s,a,f,c,l,d,r)
#define	X_db_print_completion(s,p)	x_db[(s)->type].print_completion(s,p)
#define	X_db_lookup_incomplete(s,p,n,l,t)	\
			x_db[(s)->type].lookup_incomplete(s,p,n,l,t)

#endif	/* !_DDB_DB_SYM_H_ */