xref: /openbsd-src/sys/ddb/db_sym.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$NetBSD: db_sym.h,v 1.13 2000/05/25 19:57:36 jhawk Exp $	*/
2 
3 /*
4  * Mach Operating System
5  * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
6  * All Rights Reserved.
7  *
8  * Permission to use, copy, modify and distribute this software and its
9  * documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  *
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie Mellon
26  * the rights to redistribute these changes.
27  *
28  * 	Author: Alessandro Forin, Carnegie Mellon University
29  *	Date:	8/90
30  */
31 
32 #ifndef _DDB_DB_SYM_H_
33 #define _DDB_DB_SYM_H_
34 
35 #include <sys/stdint.h>
36 
37 /*
38  * Symbol representation is specific to the symtab style:
39  * BSD compilers use dbx' nlist, other compilers might use
40  * a different one
41  */
42 typedef	char *		db_sym_t;	/* opaque handle on symbols */
43 
44 /*
45  * Non-stripped symbol tables will have duplicates, for instance
46  * the same string could match a parameter name, a local var, a
47  * global var, etc.
48  * We are most concern with the following matches.
49  */
50 typedef int		db_strategy_t;	/* search strategy */
51 
52 #define	DB_STGY_ANY	0			/* anything goes */
53 #define DB_STGY_XTRN	1			/* only external symbols */
54 #define DB_STGY_PROC	2			/* only procedures */
55 
56 
57 /*
58  * Internal db_forall function calling convention:
59  *
60  * (*db_forall_func)(stab, sym, name, suffix, prefix, arg);
61  *
62  * stab is the symbol table, symbol the (opaque) symbol pointer,
63  * name the name of the symbol, suffix a string representing
64  * the type, prefix an initial ignorable function prefix (e.g. "_"
65  * in a.out), and arg an opaque argument to be passed in.
66  */
67 typedef void (db_forall_func_t)(db_sym_t, char *, char *, int, void *);
68 
69 extern unsigned int db_maxoff;		/* like gdb's "max-symbolic-offset" */
70 
71 int db_eqname(char *, char *, int);
72 					/* strcmp, modulo leading char */
73 
74 int db_value_of_name(char *, db_expr_t *);
75 					/* find symbol value given name */
76 
77 db_sym_t db_search_symbol(db_addr_t, db_strategy_t, db_expr_t *);
78 					/* find symbol given value */
79 
80 void db_symbol_values(db_sym_t, char **, db_expr_t *);
81 					/* return name and value of symbol */
82 
83 #define db_find_sym_and_offset(val,namep,offp)	\
84 	db_symbol_values(db_search_symbol(val,DB_STGY_ANY,offp),namep,0)
85 					/* find name&value given approx val */
86 
87 #define db_find_xtrn_sym_and_offset(val,namep,offp)	\
88 	db_symbol_values(db_search_symbol(val,DB_STGY_XTRN,offp),namep,0)
89 					/* ditto, but no locals */
90 
91 void db_printsym(db_expr_t, db_strategy_t, int (*)(const char *, ...));
92 					/* print closest symbol to a value */
93 
94 int db_elf_sym_init(int, void *, void *, const char *);
95 db_sym_t db_elf_sym_search(db_addr_t, db_strategy_t, db_expr_t *);
96 int db_elf_line_at_pc(db_sym_t, char **, int *, db_expr_t);
97 void db_elf_sym_forall(db_forall_func_t db_forall_func, void *);
98 
99 bool db_dwarf_line_at_pc(const char *, size_t, uintptr_t,
100     const char **, const char **, int *);
101 
102 #endif /* _DDB_DB_SYM_H_ */
103