GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/symfile.h
Go to the documentation of this file.
1/* Definitions for reading symbol files into GDB.
2
3 Copyright (C) 1990-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#if !defined (SYMFILE_H)
21#define SYMFILE_H
22
23/* This file requires that you first include "bfd.h". */
24#include "symtab.h"
25#include "probe.h"
26#include "symfile-add-flags.h"
27#include "objfile-flags.h"
28#include "gdb_bfd.h"
29#include "gdbsupport/function-view.h"
30#include "target-section.h"
31#include "quick-symbol.h"
32
33/* Opaque declarations. */
34struct target_section;
35struct objfile;
36struct obj_section;
37struct obstack;
38struct block;
39struct value;
40class frame_info_ptr;
41struct agent_expr;
42struct axs_value;
43class probe;
44
46{
47 other_sections (CORE_ADDR addr_, std::string &&name_, int sectindex_)
48 : addr (addr_),
49 name (std::move (name_)),
50 sectindex (sectindex_)
51 {
52 }
53
54 other_sections (other_sections &&other) = default;
55
57
58 CORE_ADDR addr;
59 std::string name;
60
61 /* SECTINDEX must be valid for associated BFD or set to -1.
62 See syms_from_objfile_1 for an exception to this rule.
63 */
65};
66
67/* Define an array of addresses to accommodate non-contiguous dynamic
68 loading of modules. This is for use when entering commands, so we
69 can keep track of the section names until we read the file and can
70 map them to bfd sections. This structure is also used by solib.c
71 to communicate the section addresses in shared objects to
72 symbol_file_add (). */
73
74typedef std::vector<other_sections> section_addr_info;
75
76/* A table listing the load segments in a symfile, and which segment
77 each BFD section belongs to. */
79{
80 struct segment
81 {
82 segment (CORE_ADDR base, CORE_ADDR size)
83 : base (base), size (size)
84 {}
85
86 /* The original base address the segment. */
87 CORE_ADDR base;
88
89 /* The memory size of the segment. */
90 CORE_ADDR size;
91 };
92
93 /* The segments present in this file. If there are
94 two, the text segment is the first one and the data segment
95 is the second one. */
96 std::vector<segment> segments;
97
98 /* This is an array of entries recording which segment contains each BFD
99 section. SEGMENT_INFO[I] is S+1 if the I'th BFD section belongs to segment
100 S, or zero if it is not in any segment. */
101 std::vector<int> segment_info;
102};
103
104using symfile_segment_data_up = std::unique_ptr<symfile_segment_data>;
105
106/* Structure of functions used for probe support. If one of these functions
107 is provided, all must be. */
108
110{
111 /* If non-NULL, return a reference to vector of probe objects. */
112 const std::vector<std::unique_ptr<probe>> &(*sym_get_probes)
113 (struct objfile *);
114};
115
116/* Structure to keep track of symbol reading functions for various
117 object file types. */
118
120{
121 /* Initializes anything that is global to the entire symbol table.
122 It is called during symbol_file_add, when we begin debugging an
123 entirely new program. */
124
125 void (*sym_new_init) (struct objfile *);
126
127 /* Reads any initial information from a symbol file, and initializes
128 the struct sym_fns SF in preparation for sym_read(). It is
129 called every time we read a symbol file for any reason. */
130
131 void (*sym_init) (struct objfile *);
132
133 /* sym_read (objfile, symfile_flags) Reads a symbol file into a psymtab
134 (or possibly a symtab). OBJFILE is the objfile struct for the
135 file we are reading. SYMFILE_FLAGS are the flags passed to
136 symbol_file_add & co. */
137
138 void (*sym_read) (struct objfile *, symfile_add_flags);
139
140 /* Called when we are finished with an objfile. Should do all
141 cleanup that is specific to the object file format for the
142 particular objfile. */
143
144 void (*sym_finish) (struct objfile *);
145
146
147 /* This function produces a file-dependent section_offsets
148 structure, allocated in the objfile's storage.
149
150 The section_addr_info structure contains the offset of loadable and
151 allocated sections, relative to the absolute offsets found in the BFD. */
152
153 void (*sym_offsets) (struct objfile *, const section_addr_info &);
154
155 /* This function produces a format-independent description of
156 the segments of ABFD. Each segment is a unit of the file
157 which may be relocated independently. */
158
160
161 /* This function should read the linetable from the objfile when
162 the line table cannot be read while processing the debugging
163 information. */
164
165 void (*sym_read_linetable) (struct objfile *);
166
167 /* Relocate the contents of a debug section SECTP. The
168 contents are stored in BUF if it is non-NULL, or returned in a
169 malloc'd buffer otherwise. */
170
171 bfd_byte *(*sym_relocate) (struct objfile *, asection *sectp, bfd_byte *buf);
172
173 /* If non-NULL, this objfile has probe support, and all the probe
174 functions referred to here will be non-NULL. */
176};
177
180
183
185 bfd *abfd);
186
187/* The default version of sym_fns.sym_offsets for readers that don't
188 do anything special. */
189
190extern void default_symfile_offsets (struct objfile *objfile,
191 const section_addr_info &);
192
193/* The default version of sym_fns.sym_segments for readers that don't
194 do anything special. */
195
197
198/* The default version of sym_fns.sym_relocate for readers that don't
199 do anything special. */
200
201extern bfd_byte *default_symfile_relocate (struct objfile *objfile,
202 asection *sectp, bfd_byte *buf);
203
204extern struct symtab *allocate_symtab
205 (struct compunit_symtab *cust, const char *filename, const char *id)
206 ATTRIBUTE_NONNULL (1);
207
208/* Same as the above, but passes FILENAME for ID. */
209
210static inline struct symtab *
211allocate_symtab (struct compunit_symtab *cust, const char *filename)
212{
213 return allocate_symtab (cust, filename, filename);
214}
215
216extern struct compunit_symtab *allocate_compunit_symtab (struct objfile *,
217 const char *)
218 ATTRIBUTE_NONNULL (1);
219
220extern void add_compunit_symtab_to_objfile (struct compunit_symtab *cu);
221
222extern void add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *);
223
224extern void clear_symtab_users (symfile_add_flags add_flags);
225
226extern enum language deduce_language_from_filename (const char *);
227
228/* Map the filename extension EXT to the language LANG. Any previous
229 association of EXT will be removed. EXT will be copied by this
230 function. */
231extern void add_filename_language (const char *ext, enum language lang);
232
233extern struct objfile *symbol_file_add (const char *, symfile_add_flags,
234 section_addr_info *, objfile_flags);
235
236extern struct objfile *symbol_file_add_from_bfd (const gdb_bfd_ref_ptr &,
237 const char *, symfile_add_flags,
239 objfile_flags, struct objfile *parent);
240
241extern void symbol_file_add_separate (const gdb_bfd_ref_ptr &, const char *,
242 symfile_add_flags, struct objfile *);
243
244extern std::string find_separate_debug_file_by_debuglink (struct objfile *);
245
246/* Build (allocate and populate) a section_addr_info struct from an
247 existing section table. */
248
251
252 /* Variables */
253
254/* If true, shared library symbols will be added automatically
255 when the inferior is created, new libraries are loaded, or when
256 attaching to the inferior. This is almost always what users will
257 want to have happen; but for very large programs, the startup time
258 will be excessive, and so if this is a problem, the user can clear
259 this flag and then add the shared library symbols as needed. Note
260 that there is a potential for confusion, since if the shared
261 library symbols are not loaded, commands like "info fun" will *not*
262 report all the functions that are actually present. */
263
264extern bool auto_solib_add;
265
266/* From symfile.c */
267
268extern void set_initial_language (void);
269
270extern gdb_bfd_ref_ptr symfile_bfd_open (const char *);
271
272extern int get_section_index (struct objfile *, const char *);
273
274extern int print_symbol_loading_p (int from_tty, int mainline, int full);
275
276/* Utility functions for overlay sections: */
278{
283extern int overlay_cache_invalid;
284
285/* Return the "mapped" overlay section containing the PC. */
286extern struct obj_section *find_pc_mapped_section (CORE_ADDR);
287
288/* Return any overlay section containing the PC (even in its LMA
289 region). */
290extern struct obj_section *find_pc_overlay (CORE_ADDR);
291
292/* Return true if the section is an overlay. */
293extern int section_is_overlay (struct obj_section *);
294
295/* Return true if the overlay section is currently "mapped". */
296extern int section_is_mapped (struct obj_section *);
297
298/* Return true if pc belongs to section's VMA. */
299extern CORE_ADDR pc_in_mapped_range (CORE_ADDR, struct obj_section *);
300
301/* Return true if pc belongs to section's LMA. */
302extern CORE_ADDR pc_in_unmapped_range (CORE_ADDR, struct obj_section *);
303
304/* Map an address from a section's LMA to its VMA. */
305extern CORE_ADDR overlay_mapped_address (CORE_ADDR, struct obj_section *);
306
307/* Map an address from a section's VMA to its LMA. */
308extern CORE_ADDR overlay_unmapped_address (CORE_ADDR, struct obj_section *);
309
310/* Convert an address in an overlay section (force into VMA range). */
311extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
312
313/* Load symbols from a file. */
314extern void symbol_file_add_main (const char *args,
315 symfile_add_flags add_flags);
316
317/* Clear GDB symbol tables. */
318extern void symbol_file_clear (int from_tty);
319
320/* Default overlay update function. */
321extern void simple_overlay_update (struct obj_section *);
322
323extern bfd_byte *symfile_relocate_debug_section (struct objfile *, asection *,
324 bfd_byte *);
325
326extern int symfile_map_offsets_to_segments (bfd *,
327 const struct symfile_segment_data *,
329 int, const CORE_ADDR *);
331
332extern scoped_restore_tmpl<int> increment_reading_symtab (void);
333
335 (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
336 const lookup_name_info &lookup_name,
337 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
338 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
339 block_search_flags search_flags,
340 enum search_domain kind);
341
342void map_symbol_filenames (gdb::function_view<symbol_filename_ftype> fun,
343 bool need_fullname);
344
345/* Target-agnostic function to load the sections of an executable into memory.
346
347 ARGS should be in the form "EXECUTABLE [OFFSET]", where OFFSET is an
348 optional offset to apply to each section. */
349extern void generic_load (const char *args, int from_tty);
350
351/* From minidebug.c. */
352
354
355/* True if we are printing debug output about separate debug info files. */
356
357extern bool separate_debug_file_debug;
358
359/* Read full symbols immediately. */
360
361extern int readnow_symbol_files;
362
363/* Never read full symbols. */
364
365extern int readnever_symbol_files;
366
367#endif /* !defined(SYMFILE_H) */
Definition: probe.h:115
language
Definition: defs.h:211
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition: gdb_bfd.h:78
Definition: aarch64.h:50
Definition: ax.h:82
Definition: block.h:109
int sectindex
Definition: symfile.h:64
other_sections(CORE_ADDR addr_, std::string &&name_, int sectindex_)
Definition: symfile.h:47
std::string name
Definition: symfile.h:59
other_sections(other_sections &&other)=default
DISABLE_COPY_AND_ASSIGN(other_sections)
CORE_ADDR addr
Definition: symfile.h:58
void(* sym_read)(struct objfile *, symfile_add_flags)
Definition: symfile.h:138
void(* sym_read_linetable)(struct objfile *)
Definition: symfile.h:165
void(* sym_new_init)(struct objfile *)
Definition: symfile.h:125
void(* sym_init)(struct objfile *)
Definition: symfile.h:131
symfile_segment_data_up(* sym_segments)(bfd *abfd)
Definition: symfile.h:159
const struct sym_probe_fns * sym_probe_fns
Definition: symfile.h:175
void(* sym_offsets)(struct objfile *, const section_addr_info &)
Definition: symfile.h:153
void(* sym_finish)(struct objfile *)
Definition: symfile.h:144
segment(CORE_ADDR base, CORE_ADDR size)
Definition: symfile.h:82
std::vector< segment > segments
Definition: symfile.h:96
std::vector< int > segment_info
Definition: symfile.h:101
const char * filename
Definition: symtab.h:1651
Definition: value.c:181
int section_is_overlay(struct obj_section *)
Definition: symfile.c:2940
CORE_ADDR pc_in_mapped_range(CORE_ADDR, struct obj_section *)
Definition: symfile.c:3036
bool separate_debug_file_debug
Definition: symfile.c:1243
bfd_byte * symfile_relocate_debug_section(struct objfile *, asection *, bfd_byte *)
Definition: symfile.c:3599
CORE_ADDR pc_in_unmapped_range(CORE_ADDR, struct obj_section *)
Definition: symfile.c:3014
void default_symfile_offsets(struct objfile *objfile, const section_addr_info &)
Definition: symfile.c:627
std::unique_ptr< symfile_segment_data > symfile_segment_data_up
Definition: symfile.h:104
void add_filename_language(const char *ext, enum language lang)
Definition: symfile.c:2672
std::vector< other_sections > section_addr_info
Definition: symfile.h:74
int get_section_index(struct objfile *, const char *)
Definition: symfile.c:1751
void simple_overlay_update(struct obj_section *)
Definition: symfile.c:3508
gdb_bfd_ref_ptr symfile_bfd_open(const char *)
Definition: symfile.c:1702
enum language deduce_language_from_filename(const char *)
Definition: symfile.c:2759
section_addr_info build_section_addr_info_from_objfile(const struct objfile *objfile)
Definition: symfile.c:259
CORE_ADDR symbol_overlayed_address(CORE_ADDR, struct obj_section *)
Definition: symfile.c:3103
void symbol_file_clear(int from_tty)
Definition: symfile.c:1218
void add_compunit_symtab_to_objfile(struct compunit_symtab *cu)
Definition: symfile.c:2851
CORE_ADDR overlay_unmapped_address(CORE_ADDR, struct obj_section *)
Definition: symfile.c:3067
bool auto_solib_add
Definition: symfile.c:151
int readnow_symbol_files
Definition: symfile.c:90
int section_is_mapped(struct obj_section *)
Definition: symfile.c:2978
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *)
Definition: symfile.c:1768
std::string find_separate_debug_file_by_debuglink(struct objfile *)
Definition: symfile.c:1514
void symbol_file_add_main(const char *args, symfile_add_flags add_flags)
Definition: symfile.c:1194
void set_initial_language(void)
Definition: symfile.c:1668
section_addr_info build_section_addr_info_from_section_table(const target_section_table &table)
Definition: symfile.c:220
struct objfile * symbol_file_add_from_bfd(const gdb_bfd_ref_ptr &, const char *, symfile_add_flags, section_addr_info *, objfile_flags, struct objfile *parent)
Definition: symfile.c:1163
bool expand_symtabs_matching(gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info &lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, enum search_domain kind)
Definition: symfile.c:3727
void symbol_file_add_separate(const gdb_bfd_ref_ptr &, const char *, symfile_add_flags, struct objfile *)
Definition: symfile.c:1142
struct obj_section * find_pc_overlay(CORE_ADDR)
Definition: symfile.c:3133
struct compunit_symtab * allocate_compunit_symtab(struct objfile *, const char *) ATTRIBUTE_NONNULL(1)
Definition: symfile.c:2825
int print_symbol_loading_p(int from_tty, int mainline, int full)
Definition: symfile.c:163
int readnever_symbol_files
Definition: symfile.c:94
void generic_load(const char *args, int from_tty)
Definition: symfile.c:2001
void addr_info_make_relative(section_addr_info *addrs, bfd *abfd)
Definition: symfile.c:485
int overlay_cache_invalid
Definition: symfile.c:2933
struct objfile * symbol_file_add(const char *, symfile_add_flags, section_addr_info *, objfile_flags)
Definition: symfile.c:1176
overlay_debugging_state
Definition: symfile.h:278
@ ovly_auto
Definition: symfile.h:281
@ ovly_on
Definition: symfile.h:280
@ ovly_off
Definition: symfile.h:279
symfile_segment_data_up get_symfile_segment_data(bfd *abfd)
Definition: symfile.c:3608
void relative_addr_info_to_section_offsets(section_offsets &section_offsets, const section_addr_info &addrs)
Definition: symfile.c:406
CORE_ADDR overlay_mapped_address(CORE_ADDR, struct obj_section *)
Definition: symfile.c:3085
symfile_segment_data_up default_symfile_segments(bfd *abfd)
Definition: symfile.c:713
void map_symbol_filenames(gdb::function_view< symbol_filename_ftype > fun, bool need_fullname)
Definition: symfile.c:3751
gdb_bfd_ref_ptr find_separate_debug_file_in_section(struct objfile *)
Definition: minidebug.c:263
int symfile_map_offsets_to_segments(bfd *, const struct symfile_segment_data *, section_offsets &, int, const CORE_ADDR *)
Definition: symfile.c:3634
enum overlay_debugging_state overlay_debugging
struct symtab * allocate_symtab(struct compunit_symtab *cust, const char *filename, const char *id) ATTRIBUTE_NONNULL(1)
Definition: symfile.c:2778
struct obj_section * find_pc_mapped_section(CORE_ADDR)
Definition: symfile.c:3162
void clear_symtab_users(symfile_add_flags add_flags)
Definition: symfile.c:2862
scoped_restore_tmpl< int > increment_reading_symtab(void)
Definition: symfile.c:187
bfd_byte * default_symfile_relocate(struct objfile *objfile, asection *sectp, bfd_byte *buf)
Definition: symfile.c:3561
search_domain
Definition: symtab.h:916
std::vector< CORE_ADDR > section_offsets
Definition: symtab.h:1595
std::vector< target_section > target_section_table