xref: /dflybsd-src/contrib/gdb-7/gdb/minsyms.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
1*ef5ccd6cSJohn Marino /* Minimal symbol table definitions for GDB.
2*ef5ccd6cSJohn Marino 
3*ef5ccd6cSJohn Marino    Copyright (C) 2011-2013 Free Software Foundation, Inc.
4*ef5ccd6cSJohn Marino 
5*ef5ccd6cSJohn Marino    This file is part of GDB.
6*ef5ccd6cSJohn Marino 
7*ef5ccd6cSJohn Marino    This program is free software; you can redistribute it and/or modify
8*ef5ccd6cSJohn Marino    it under the terms of the GNU General Public License as published by
9*ef5ccd6cSJohn Marino    the Free Software Foundation; either version 3 of the License, or
10*ef5ccd6cSJohn Marino    (at your option) any later version.
11*ef5ccd6cSJohn Marino 
12*ef5ccd6cSJohn Marino    This program is distributed in the hope that it will be useful,
13*ef5ccd6cSJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*ef5ccd6cSJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*ef5ccd6cSJohn Marino    GNU General Public License for more details.
16*ef5ccd6cSJohn Marino 
17*ef5ccd6cSJohn Marino    You should have received a copy of the GNU General Public License
18*ef5ccd6cSJohn Marino    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*ef5ccd6cSJohn Marino 
20*ef5ccd6cSJohn Marino #ifndef MINSYMS_H
21*ef5ccd6cSJohn Marino #define MINSYMS_H
22*ef5ccd6cSJohn Marino 
23*ef5ccd6cSJohn Marino /* This header declares most of the API for dealing with minimal
24*ef5ccd6cSJohn Marino    symbols and minimal symbol tables.  A few things are declared
25*ef5ccd6cSJohn Marino    elsewhere; see below.
26*ef5ccd6cSJohn Marino 
27*ef5ccd6cSJohn Marino    A minimal symbol is a symbol for which there is no direct debug
28*ef5ccd6cSJohn Marino    information.  For example, for an ELF binary, minimal symbols are
29*ef5ccd6cSJohn Marino    created from the ELF symbol table.
30*ef5ccd6cSJohn Marino 
31*ef5ccd6cSJohn Marino    For the definition of the minimal symbol structure, see struct
32*ef5ccd6cSJohn Marino    minimal_symbol in symtab.h.
33*ef5ccd6cSJohn Marino 
34*ef5ccd6cSJohn Marino    Minimal symbols are stored in tables attached to an objfile; see
35*ef5ccd6cSJohn Marino    objfiles.h for details.  Code should generally treat these tables
36*ef5ccd6cSJohn Marino    as opaque and use functions provided by minsyms.c to inspect them.
37*ef5ccd6cSJohn Marino */
38*ef5ccd6cSJohn Marino 
39*ef5ccd6cSJohn Marino /* Prepare to start collecting minimal symbols.  This should be called
40*ef5ccd6cSJohn Marino    by a symbol reader to initialize the minimal symbol module.
41*ef5ccd6cSJohn Marino    Currently, minimal symbol table creation is not reentrant; it
42*ef5ccd6cSJohn Marino    relies on global (static) variables in minsyms.c.  */
43*ef5ccd6cSJohn Marino 
44*ef5ccd6cSJohn Marino void init_minimal_symbol_collection (void);
45*ef5ccd6cSJohn Marino 
46*ef5ccd6cSJohn Marino /* Return a cleanup which is used to clean up the global state left
47*ef5ccd6cSJohn Marino    over by minimal symbol creation.  After calling
48*ef5ccd6cSJohn Marino    init_minimal_symbol_collection, a symbol reader should call this
49*ef5ccd6cSJohn Marino    function.  Then, after all minimal symbols have been read,
50*ef5ccd6cSJohn Marino    regardless of whether they are installed or not, the cleanup
51*ef5ccd6cSJohn Marino    returned by this function should be run.  */
52*ef5ccd6cSJohn Marino 
53*ef5ccd6cSJohn Marino struct cleanup *make_cleanup_discard_minimal_symbols (void);
54*ef5ccd6cSJohn Marino 
55*ef5ccd6cSJohn Marino /* Record a new minimal symbol.  This is the "full" entry point;
56*ef5ccd6cSJohn Marino    simpler convenience entry points are also provided below.
57*ef5ccd6cSJohn Marino 
58*ef5ccd6cSJohn Marino    This returns a new minimal symbol.  It is ok to modify the returned
59*ef5ccd6cSJohn Marino    minimal symbol (though generally not necessary).  It is not ok,
60*ef5ccd6cSJohn Marino    though, to stash the pointer anywhere; as minimal symbols may be
61*ef5ccd6cSJohn Marino    moved after creation.  The memory for the returned minimal symbol
62*ef5ccd6cSJohn Marino    is still owned by the minsyms.c code, and should not be freed.
63*ef5ccd6cSJohn Marino 
64*ef5ccd6cSJohn Marino    Arguments are:
65*ef5ccd6cSJohn Marino 
66*ef5ccd6cSJohn Marino    NAME - the symbol's name
67*ef5ccd6cSJohn Marino    NAME_LEN - the length of the name
68*ef5ccd6cSJohn Marino    COPY_NAME - if true, the minsym code must make a copy of NAME.  If
69*ef5ccd6cSJohn Marino    false, then NAME must be NUL-terminated, and must have a lifetime
70*ef5ccd6cSJohn Marino    that is at least as long as OBJFILE's lifetime.
71*ef5ccd6cSJohn Marino    ADDRESS - the address of the symbol
72*ef5ccd6cSJohn Marino    MS_TYPE - the type of the symbol
73*ef5ccd6cSJohn Marino    SECTION - the symbol's section
74*ef5ccd6cSJohn Marino    BFD_SECTION - the symbol's BFD section; used to find the
75*ef5ccd6cSJohn Marino    appropriate obj_section for the minimal symbol.  This can be NULL.
76*ef5ccd6cSJohn Marino    OBJFILE - the objfile associated with the minimal symbol.  */
77*ef5ccd6cSJohn Marino 
78*ef5ccd6cSJohn Marino struct minimal_symbol *prim_record_minimal_symbol_full
79*ef5ccd6cSJohn Marino     (const char *name,
80*ef5ccd6cSJohn Marino      int name_len,
81*ef5ccd6cSJohn Marino      int copy_name,
82*ef5ccd6cSJohn Marino      CORE_ADDR address,
83*ef5ccd6cSJohn Marino      enum minimal_symbol_type ms_type,
84*ef5ccd6cSJohn Marino      int section,
85*ef5ccd6cSJohn Marino      asection *bfd_section,
86*ef5ccd6cSJohn Marino      struct objfile *objfile);
87*ef5ccd6cSJohn Marino 
88*ef5ccd6cSJohn Marino /* Like prim_record_minimal_symbol_full, but:
89*ef5ccd6cSJohn Marino    - uses strlen to compute NAME_LEN,
90*ef5ccd6cSJohn Marino    - passes COPY_NAME = 0,
91*ef5ccd6cSJohn Marino    - passes SECTION = 0,
92*ef5ccd6cSJohn Marino    - and passes BFD_SECTION = NULL.
93*ef5ccd6cSJohn Marino 
94*ef5ccd6cSJohn Marino    This variant does not return the new symbol.  */
95*ef5ccd6cSJohn Marino 
96*ef5ccd6cSJohn Marino void prim_record_minimal_symbol (const char *, CORE_ADDR,
97*ef5ccd6cSJohn Marino 				 enum minimal_symbol_type,
98*ef5ccd6cSJohn Marino 				 struct objfile *);
99*ef5ccd6cSJohn Marino 
100*ef5ccd6cSJohn Marino /* Like prim_record_minimal_symbol_full, but:
101*ef5ccd6cSJohn Marino    - uses strlen to compute NAME_LEN,
102*ef5ccd6cSJohn Marino    - passes COPY_NAME = 0.  */
103*ef5ccd6cSJohn Marino 
104*ef5ccd6cSJohn Marino struct minimal_symbol *prim_record_minimal_symbol_and_info
105*ef5ccd6cSJohn Marino     (const char *,
106*ef5ccd6cSJohn Marino      CORE_ADDR,
107*ef5ccd6cSJohn Marino      enum minimal_symbol_type,
108*ef5ccd6cSJohn Marino      int section,
109*ef5ccd6cSJohn Marino      asection *bfd_section,
110*ef5ccd6cSJohn Marino      struct objfile *);
111*ef5ccd6cSJohn Marino 
112*ef5ccd6cSJohn Marino /* Install the minimal symbols that have been collected into the given
113*ef5ccd6cSJohn Marino    objfile.  After this is called, the cleanup returned by
114*ef5ccd6cSJohn Marino    make_cleanup_discard_minimal_symbols should be run in order to
115*ef5ccd6cSJohn Marino    clean up global state.  */
116*ef5ccd6cSJohn Marino 
117*ef5ccd6cSJohn Marino void install_minimal_symbols (struct objfile *);
118*ef5ccd6cSJohn Marino 
119*ef5ccd6cSJohn Marino /* Create the terminating entry of OBJFILE's minimal symbol table.
120*ef5ccd6cSJohn Marino    If OBJFILE->msymbols is zero, allocate a single entry from
121*ef5ccd6cSJohn Marino    OBJFILE->objfile_obstack; otherwise, just initialize
122*ef5ccd6cSJohn Marino    OBJFILE->msymbols[OBJFILE->minimal_symbol_count].  */
123*ef5ccd6cSJohn Marino 
124*ef5ccd6cSJohn Marino void terminate_minimal_symbol_table (struct objfile *objfile);
125*ef5ccd6cSJohn Marino 
126*ef5ccd6cSJohn Marino /* Sort all the minimal symbols in OBJFILE.  This should be only be
127*ef5ccd6cSJohn Marino    called after relocating symbols; it ensures that the minimal
128*ef5ccd6cSJohn Marino    symbols are properly sorted by address.  */
129*ef5ccd6cSJohn Marino 
130*ef5ccd6cSJohn Marino void msymbols_sort (struct objfile *objfile);
131*ef5ccd6cSJohn Marino 
132*ef5ccd6cSJohn Marino 
133*ef5ccd6cSJohn Marino 
134*ef5ccd6cSJohn Marino /* Compute a hash code for the string argument.  */
135*ef5ccd6cSJohn Marino 
136*ef5ccd6cSJohn Marino unsigned int msymbol_hash (const char *);
137*ef5ccd6cSJohn Marino 
138*ef5ccd6cSJohn Marino /* Like msymbol_hash, but compute a hash code that is compatible with
139*ef5ccd6cSJohn Marino    strcmp_iw.  */
140*ef5ccd6cSJohn Marino 
141*ef5ccd6cSJohn Marino unsigned int msymbol_hash_iw (const char *);
142*ef5ccd6cSJohn Marino 
143*ef5ccd6cSJohn Marino /* Compute the next hash value from previous HASH and the character C.  This
144*ef5ccd6cSJohn Marino    is only a GDB in-memory computed value with no external files compatibility
145*ef5ccd6cSJohn Marino    requirements.  */
146*ef5ccd6cSJohn Marino 
147*ef5ccd6cSJohn Marino #define SYMBOL_HASH_NEXT(hash, c)			\
148*ef5ccd6cSJohn Marino   ((hash) * 67 + tolower ((unsigned char) (c)) - 113)
149*ef5ccd6cSJohn Marino 
150*ef5ccd6cSJohn Marino 
151*ef5ccd6cSJohn Marino 
152*ef5ccd6cSJohn Marino /* Return the objfile that holds the minimal symbol SYM.  Every
153*ef5ccd6cSJohn Marino    minimal symbols is held by some objfile; this will never return
154*ef5ccd6cSJohn Marino    NULL.  */
155*ef5ccd6cSJohn Marino 
156*ef5ccd6cSJohn Marino struct objfile *msymbol_objfile (struct minimal_symbol *sym);
157*ef5ccd6cSJohn Marino 
158*ef5ccd6cSJohn Marino 
159*ef5ccd6cSJohn Marino 
160*ef5ccd6cSJohn Marino /* Look through all the current minimal symbol tables and find the
161*ef5ccd6cSJohn Marino    first minimal symbol that matches NAME.  If OBJF is non-NULL, limit
162*ef5ccd6cSJohn Marino    the search to that objfile.  If SFILE is non-NULL, the only file-scope
163*ef5ccd6cSJohn Marino    symbols considered will be from that source file (global symbols are
164*ef5ccd6cSJohn Marino    still preferred).  Returns a pointer to the minimal symbol that
165*ef5ccd6cSJohn Marino    matches, or NULL if no match is found.  */
166*ef5ccd6cSJohn Marino 
167*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol (const char *,
168*ef5ccd6cSJohn Marino 					      const char *,
169*ef5ccd6cSJohn Marino 					      struct objfile *);
170*ef5ccd6cSJohn Marino 
171*ef5ccd6cSJohn Marino /* Find the minimal symbol named NAME, and return both the minsym
172*ef5ccd6cSJohn Marino    struct and its objfile.  This only checks the linkage name.  Sets
173*ef5ccd6cSJohn Marino    *OBJFILE_P and returns the minimal symbol, if it is found.  If it
174*ef5ccd6cSJohn Marino    is not found, returns NULL.  */
175*ef5ccd6cSJohn Marino 
176*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol_and_objfile (const char *,
177*ef5ccd6cSJohn Marino 							  struct objfile **);
178*ef5ccd6cSJohn Marino 
179*ef5ccd6cSJohn Marino /* Look through all the current minimal symbol tables and find the
180*ef5ccd6cSJohn Marino    first minimal symbol that matches NAME and has text type.  If OBJF
181*ef5ccd6cSJohn Marino    is non-NULL, limit the search to that objfile.  Returns a pointer
182*ef5ccd6cSJohn Marino    to the minimal symbol that matches, or NULL if no match is found.
183*ef5ccd6cSJohn Marino 
184*ef5ccd6cSJohn Marino    This function only searches the mangled (linkage) names.  */
185*ef5ccd6cSJohn Marino 
186*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol_text (const char *,
187*ef5ccd6cSJohn Marino 						   struct objfile *);
188*ef5ccd6cSJohn Marino 
189*ef5ccd6cSJohn Marino /* Look through all the current minimal symbol tables and find the
190*ef5ccd6cSJohn Marino    first minimal symbol that matches NAME and is a solib trampoline.
191*ef5ccd6cSJohn Marino    If OBJF is non-NULL, limit the search to that objfile.  Returns a
192*ef5ccd6cSJohn Marino    pointer to the minimal symbol that matches, or NULL if no match is
193*ef5ccd6cSJohn Marino    found.
194*ef5ccd6cSJohn Marino 
195*ef5ccd6cSJohn Marino    This function only searches the mangled (linkage) names.  */
196*ef5ccd6cSJohn Marino 
197*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol_solib_trampoline
198*ef5ccd6cSJohn Marino     (const char *,
199*ef5ccd6cSJohn Marino      struct objfile *);
200*ef5ccd6cSJohn Marino 
201*ef5ccd6cSJohn Marino /* Look through all the current minimal symbol tables and find the
202*ef5ccd6cSJohn Marino    first minimal symbol that matches NAME and PC.  If OBJF is non-NULL,
203*ef5ccd6cSJohn Marino    limit the search to that objfile.  Returns a pointer to the minimal
204*ef5ccd6cSJohn Marino    symbol that matches, or NULL if no match is found.  */
205*ef5ccd6cSJohn Marino 
206*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol_by_pc_name
207*ef5ccd6cSJohn Marino     (CORE_ADDR, const char *, struct objfile *);
208*ef5ccd6cSJohn Marino 
209*ef5ccd6cSJohn Marino /* Search through the minimal symbol table for each objfile and find
210*ef5ccd6cSJohn Marino    the symbol whose address is the largest address that is still less
211*ef5ccd6cSJohn Marino    than or equal to PC, and which matches SECTION.
212*ef5ccd6cSJohn Marino 
213*ef5ccd6cSJohn Marino    If SECTION is NULL, this uses the result of find_pc_section
214*ef5ccd6cSJohn Marino    instead.
215*ef5ccd6cSJohn Marino 
216*ef5ccd6cSJohn Marino    Returns a pointer to the minimal symbol if such a symbol is found,
217*ef5ccd6cSJohn Marino    or NULL if PC is not in a suitable range.  */
218*ef5ccd6cSJohn Marino 
219*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol_by_pc_section
220*ef5ccd6cSJohn Marino     (CORE_ADDR,
221*ef5ccd6cSJohn Marino      struct obj_section *);
222*ef5ccd6cSJohn Marino 
223*ef5ccd6cSJohn Marino /* Backward compatibility: search through the minimal symbol table
224*ef5ccd6cSJohn Marino    for a matching PC (no section given).
225*ef5ccd6cSJohn Marino 
226*ef5ccd6cSJohn Marino    This is a wrapper that calls lookup_minimal_symbol_by_pc_section
227*ef5ccd6cSJohn Marino    with a NULL section argument.  */
228*ef5ccd6cSJohn Marino 
229*ef5ccd6cSJohn Marino struct minimal_symbol *lookup_minimal_symbol_by_pc (CORE_ADDR);
230*ef5ccd6cSJohn Marino 
231*ef5ccd6cSJohn Marino /* Iterate over all the minimal symbols in the objfile OBJF which
232*ef5ccd6cSJohn Marino    match NAME.  Both the ordinary and demangled names of each symbol
233*ef5ccd6cSJohn Marino    are considered.  The caller is responsible for canonicalizing NAME,
234*ef5ccd6cSJohn Marino    should that need to be done.
235*ef5ccd6cSJohn Marino 
236*ef5ccd6cSJohn Marino    For each matching symbol, CALLBACK is called with the symbol and
237*ef5ccd6cSJohn Marino    USER_DATA as arguments.  */
238*ef5ccd6cSJohn Marino 
239*ef5ccd6cSJohn Marino void iterate_over_minimal_symbols (struct objfile *objf,
240*ef5ccd6cSJohn Marino 				   const char *name,
241*ef5ccd6cSJohn Marino 				   void (*callback) (struct minimal_symbol *,
242*ef5ccd6cSJohn Marino 						     void *),
243*ef5ccd6cSJohn Marino 				   void *user_data);
244*ef5ccd6cSJohn Marino 
245*ef5ccd6cSJohn Marino #endif /* MINSYMS_H */
246