db_sym.h revision 1.16 1 1.16 simonb /* $NetBSD: db_sym.h,v 1.16 2002/02/15 07:33:53 simonb Exp $ */
2 1.5 cgd
3 1.16 simonb /*
4 1.1 cgd * Mach Operating System
5 1.1 cgd * Copyright (c) 1991,1990 Carnegie Mellon University
6 1.1 cgd * All Rights Reserved.
7 1.16 simonb *
8 1.1 cgd * Permission to use, copy, modify and distribute this software and its
9 1.1 cgd * documentation is hereby granted, provided that both the copyright
10 1.1 cgd * notice and this permission notice appear in all copies of the
11 1.1 cgd * software, derivative works or modified versions, and any portions
12 1.1 cgd * thereof, and that both notices appear in supporting documentation.
13 1.16 simonb *
14 1.11 pk * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 1.1 cgd * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.16 simonb *
18 1.1 cgd * Carnegie Mellon requests users of this software to return to
19 1.16 simonb *
20 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 cgd * School of Computer Science
22 1.1 cgd * Carnegie Mellon University
23 1.1 cgd * Pittsburgh PA 15213-3890
24 1.16 simonb *
25 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
26 1.1 cgd * rights to redistribute these changes.
27 1.2 cgd *
28 1.1 cgd * Author: Alessandro Forin, Carnegie Mellon University
29 1.1 cgd * Date: 8/90
30 1.1 cgd */
31 1.1 cgd
32 1.1 cgd /*
33 1.1 cgd * This module can handle multiple symbol tables
34 1.1 cgd */
35 1.1 cgd typedef struct {
36 1.9 thorpej const char *name; /* symtab name */
37 1.1 cgd char *start; /* symtab location */
38 1.1 cgd char *end;
39 1.1 cgd char *private; /* optional machdep pointer */
40 1.1 cgd } db_symtab_t;
41 1.1 cgd
42 1.1 cgd extern db_symtab_t *db_last_symtab; /* where last symbol was found */
43 1.1 cgd
44 1.1 cgd /*
45 1.1 cgd * Symbol representation is specific to the symtab style:
46 1.1 cgd * BSD compilers use dbx' nlist, other compilers might use
47 1.1 cgd * a different one
48 1.1 cgd */
49 1.1 cgd typedef char * db_sym_t; /* opaque handle on symbols */
50 1.1 cgd #define DB_SYM_NULL ((db_sym_t)0)
51 1.1 cgd
52 1.1 cgd /*
53 1.1 cgd * Non-stripped symbol tables will have duplicates, for instance
54 1.1 cgd * the same string could match a parameter name, a local var, a
55 1.1 cgd * global var, etc.
56 1.1 cgd * We are most concern with the following matches.
57 1.1 cgd */
58 1.1 cgd typedef int db_strategy_t; /* search strategy */
59 1.1 cgd
60 1.1 cgd #define DB_STGY_ANY 0 /* anything goes */
61 1.1 cgd #define DB_STGY_XTRN 1 /* only external symbols */
62 1.1 cgd #define DB_STGY_PROC 2 /* only procedures */
63 1.1 cgd
64 1.12 jhawk
65 1.12 jhawk /*
66 1.12 jhawk * Internal db_forall function calling convention:
67 1.12 jhawk *
68 1.12 jhawk * (*db_forall_func)(stab, sym, name, suffix, prefix, arg);
69 1.12 jhawk *
70 1.12 jhawk * stab is the symbol table, symbol the (opaque) symbol pointer,
71 1.12 jhawk * name the name of the symbol, suffix a string representing
72 1.12 jhawk * the type, prefix an initial ignorable function prefix (e.g. "_"
73 1.12 jhawk * in a.out), and arg an opaque argument to be passed in.
74 1.12 jhawk */
75 1.12 jhawk typedef void (db_forall_func_t)
76 1.16 simonb (db_symtab_t *, db_sym_t, char *, char *, int, void *);
77 1.12 jhawk
78 1.9 thorpej /*
79 1.9 thorpej * A symbol table may be in one of many formats. All symbol tables
80 1.9 thorpej * must be of the same format as the master kernel symbol table.
81 1.9 thorpej */
82 1.9 thorpej typedef struct {
83 1.16 simonb const char *sym_format;
84 1.16 simonb boolean_t (*sym_init)(int, void *, void *, const char *);
85 1.16 simonb db_sym_t (*sym_lookup)(db_symtab_t *, char *);
86 1.16 simonb db_sym_t (*sym_search)(db_symtab_t *, db_addr_t, db_strategy_t,
87 1.16 simonb db_expr_t *);
88 1.16 simonb void (*sym_value)(db_symtab_t *, db_sym_t, char **,
89 1.16 simonb db_expr_t *);
90 1.16 simonb boolean_t (*sym_line_at_pc)(db_symtab_t *, db_sym_t, char **,
91 1.16 simonb int *, db_expr_t);
92 1.16 simonb boolean_t (*sym_numargs)(db_symtab_t *, db_sym_t, int *, char **);
93 1.16 simonb void (*sym_forall)(db_symtab_t *,
94 1.16 simonb db_forall_func_t *db_forall_func, void *);
95 1.9 thorpej } db_symformat_t;
96 1.9 thorpej
97 1.1 cgd extern boolean_t db_qualify_ambiguous_names;
98 1.1 cgd /* if TRUE, check across symbol tables
99 1.1 cgd * for multiple occurrences of a name.
100 1.1 cgd * Might slow down quite a bit */
101 1.1 cgd
102 1.8 ross extern unsigned int db_maxoff; /* like gdb's "max-symbolic-offset" */
103 1.16 simonb
104 1.1 cgd /*
105 1.1 cgd * Functions exported by the symtable module
106 1.1 cgd */
107 1.16 simonb int db_add_symbol_table(char *, char *, const char *, char *);
108 1.1 cgd /* extend the list of symbol tables */
109 1.3 brezak
110 1.16 simonb void db_del_symbol_table(char *);
111 1.3 brezak /* remove a symbol table from list */
112 1.1 cgd
113 1.16 simonb boolean_t db_eqname(char *, char *, int);
114 1.7 christos /* strcmp, modulo leading char */
115 1.7 christos
116 1.16 simonb int db_value_of_name(char *, db_expr_t *);
117 1.1 cgd /* find symbol value given name */
118 1.1 cgd
119 1.16 simonb void db_sifting(char *, int);
120 1.12 jhawk /* print partially matching symbol names */
121 1.7 christos
122 1.16 simonb boolean_t db_symbol_is_ambiguous(db_sym_t);
123 1.7 christos
124 1.16 simonb db_sym_t db_search_symbol(db_addr_t, db_strategy_t, db_expr_t *);
125 1.1 cgd /* find symbol given value */
126 1.1 cgd
127 1.16 simonb void db_symbol_values(db_sym_t, char **, db_expr_t *);
128 1.1 cgd /* return name and value of symbol */
129 1.1 cgd
130 1.1 cgd #define db_find_sym_and_offset(val,namep,offp) \
131 1.1 cgd db_symbol_values(db_search_symbol(val,DB_STGY_ANY,offp),namep,0)
132 1.1 cgd /* find name&value given approx val */
133 1.1 cgd
134 1.1 cgd #define db_find_xtrn_sym_and_offset(val,namep,offp) \
135 1.1 cgd db_symbol_values(db_search_symbol(val,DB_STGY_XTRN,offp),namep,0)
136 1.1 cgd /* ditto, but no locals */
137 1.1 cgd
138 1.16 simonb void db_symstr(char *, db_expr_t, db_strategy_t);
139 1.16 simonb void db_printsym(db_expr_t, db_strategy_t,
140 1.16 simonb void(*)(const char *, ...));
141 1.1 cgd /* print closest symbol to a value */
142 1.7 christos
143 1.16 simonb int db_sym_numargs(db_sym_t, int *, char **);
144 1.9 thorpej
145 1.9 thorpej #ifdef DB_AOUT_SYMBOLS
146 1.14 jdolecek extern const db_symformat_t db_symformat_aout;
147 1.9 thorpej #endif
148 1.9 thorpej #ifdef DB_ELF_SYMBOLS
149 1.14 jdolecek extern const db_symformat_t db_symformat_elf;
150 1.9 thorpej #endif
151