1 /* Definitions for reading symbol files into GDB.
3 Copyright (C) 1990-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #if !defined (SYMFILE_H)
23 /* This file requires that you first include "bfd.h". */
26 #include "symfile-add-flags.h"
27 #include "objfile-flags.h"
29 #include "gdbsupport/function-view.h"
30 #include "target-section.h"
31 #include "quick-symbol.h"
33 /* Opaque declarations. */
34 struct target_section
;
47 other_sections (CORE_ADDR addr_
, std::string
&&name_
, int sectindex_
)
49 name (std::move (name_
)),
50 sectindex (sectindex_
)
54 other_sections (other_sections
&&other
) = default;
56 DISABLE_COPY_AND_ASSIGN (other_sections
);
61 /* SECTINDEX must be valid for associated BFD or set to -1.
62 See syms_from_objfile_1 for an exception to this rule.
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 (). */
74 typedef std::vector
<other_sections
> section_addr_info
;
76 /* A table listing the load segments in a symfile, and which segment
77 each BFD section belongs to. */
78 struct symfile_segment_data
82 segment (CORE_ADDR base
, CORE_ADDR size
)
83 : base (base
), size (size
)
86 /* The original base address the segment. */
89 /* The memory size of the segment. */
93 /* The segments present in this file. If there are
94 two, the text segment is the first one and the data segment
96 std::vector
<segment
> segments
;
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
;
104 using symfile_segment_data_up
= std::unique_ptr
<symfile_segment_data
>;
106 /* Structure of functions used for probe support. If one of these functions
107 is provided, all must be. */
111 /* If non-NULL, return a reference to vector of probe objects. */
112 const std::vector
<std::unique_ptr
<probe
>> &(*sym_get_probes
)
116 /* Structure to keep track of symbol reading functions for various
117 object file types. */
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. */
125 void (*sym_new_init
) (struct objfile
*);
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. */
131 void (*sym_init
) (struct objfile
*);
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. */
138 void (*sym_read
) (struct objfile
*, symfile_add_flags
);
140 /* Read the partial symbols for an objfile. This may be NULL, in which case
141 gdb has to check other ways if this objfile has any symbols. This may
142 only be non-NULL if the objfile actually does have debuginfo available.
145 void (*sym_read_psymbols
) (struct objfile
*);
147 /* Called when we are finished with an objfile. Should do all
148 cleanup that is specific to the object file format for the
149 particular objfile. */
151 void (*sym_finish
) (struct objfile
*);
154 /* This function produces a file-dependent section_offsets
155 structure, allocated in the objfile's storage.
157 The section_addr_info structure contains the offset of loadable and
158 allocated sections, relative to the absolute offsets found in the BFD. */
160 void (*sym_offsets
) (struct objfile
*, const section_addr_info
&);
162 /* This function produces a format-independent description of
163 the segments of ABFD. Each segment is a unit of the file
164 which may be relocated independently. */
166 symfile_segment_data_up (*sym_segments
) (bfd
*abfd
);
168 /* This function should read the linetable from the objfile when
169 the line table cannot be read while processing the debugging
172 void (*sym_read_linetable
) (struct objfile
*);
174 /* Relocate the contents of a debug section SECTP. The
175 contents are stored in BUF if it is non-NULL, or returned in a
176 malloc'd buffer otherwise. */
178 bfd_byte
*(*sym_relocate
) (struct objfile
*, asection
*sectp
, bfd_byte
*buf
);
180 /* If non-NULL, this objfile has probe support, and all the probe
181 functions referred to here will be non-NULL. */
182 const struct sym_probe_fns
*sym_probe_fns
;
184 /* The "quick" (aka partial) symbol functions for this symbol
186 const struct quick_symbol_functions
*qf
;
189 extern section_addr_info
190 build_section_addr_info_from_objfile (const struct objfile
*objfile
);
192 extern void relative_addr_info_to_section_offsets
193 (section_offsets
§ion_offsets
, const section_addr_info
&addrs
);
195 extern void addr_info_make_relative (section_addr_info
*addrs
,
198 /* The default version of sym_fns.sym_offsets for readers that don't
199 do anything special. */
201 extern void default_symfile_offsets (struct objfile
*objfile
,
202 const section_addr_info
&);
204 /* The default version of sym_fns.sym_segments for readers that don't
205 do anything special. */
207 extern symfile_segment_data_up
default_symfile_segments (bfd
*abfd
);
209 /* The default version of sym_fns.sym_relocate for readers that don't
210 do anything special. */
212 extern bfd_byte
*default_symfile_relocate (struct objfile
*objfile
,
213 asection
*sectp
, bfd_byte
*buf
);
215 extern struct symtab
*allocate_symtab (struct compunit_symtab
*, const char *)
216 ATTRIBUTE_NONNULL (1);
218 extern struct compunit_symtab
*allocate_compunit_symtab (struct objfile
*,
220 ATTRIBUTE_NONNULL (1);
222 extern void add_compunit_symtab_to_objfile (struct compunit_symtab
*cu
);
224 extern void add_symtab_fns (enum bfd_flavour flavour
, const struct sym_fns
*);
226 extern void clear_symtab_users (symfile_add_flags add_flags
);
228 extern enum language
deduce_language_from_filename (const char *);
230 /* Map the filename extension EXT to the language LANG. Any previous
231 association of EXT will be removed. EXT will be copied by this
233 extern void add_filename_language (const char *ext
, enum language lang
);
235 extern struct objfile
*symbol_file_add (const char *, symfile_add_flags
,
236 section_addr_info
*, objfile_flags
);
238 extern struct objfile
*symbol_file_add_from_bfd (bfd
*, const char *, symfile_add_flags
,
240 objfile_flags
, struct objfile
*parent
);
242 extern void symbol_file_add_separate (bfd
*, const char *, symfile_add_flags
,
245 extern std::string
find_separate_debug_file_by_debuglink (struct objfile
*);
247 /* Build (allocate and populate) a section_addr_info struct from an
248 existing section table. */
250 extern section_addr_info
251 build_section_addr_info_from_section_table (const target_section_table
&table
);
255 /* If true, shared library symbols will be added automatically
256 when the inferior is created, new libraries are loaded, or when
257 attaching to the inferior. This is almost always what users will
258 want to have happen; but for very large programs, the startup time
259 will be excessive, and so if this is a problem, the user can clear
260 this flag and then add the shared library symbols as needed. Note
261 that there is a potential for confusion, since if the shared
262 library symbols are not loaded, commands like "info fun" will *not*
263 report all the functions that are actually present. */
265 extern bool auto_solib_add
;
269 extern void set_initial_language (void);
271 extern gdb_bfd_ref_ptr
symfile_bfd_open (const char *);
273 extern int get_section_index (struct objfile
*, const char *);
275 extern int print_symbol_loading_p (int from_tty
, int mainline
, int full
);
277 /* Utility functions for overlay sections: */
278 extern enum overlay_debugging_state
284 extern int overlay_cache_invalid
;
286 /* Return the "mapped" overlay section containing the PC. */
287 extern struct obj_section
*find_pc_mapped_section (CORE_ADDR
);
289 /* Return any overlay section containing the PC (even in its LMA
291 extern struct obj_section
*find_pc_overlay (CORE_ADDR
);
293 /* Return true if the section is an overlay. */
294 extern int section_is_overlay (struct obj_section
*);
296 /* Return true if the overlay section is currently "mapped". */
297 extern int section_is_mapped (struct obj_section
*);
299 /* Return true if pc belongs to section's VMA. */
300 extern CORE_ADDR
pc_in_mapped_range (CORE_ADDR
, struct obj_section
*);
302 /* Return true if pc belongs to section's LMA. */
303 extern CORE_ADDR
pc_in_unmapped_range (CORE_ADDR
, struct obj_section
*);
305 /* Map an address from a section's LMA to its VMA. */
306 extern CORE_ADDR
overlay_mapped_address (CORE_ADDR
, struct obj_section
*);
308 /* Map an address from a section's VMA to its LMA. */
309 extern CORE_ADDR
overlay_unmapped_address (CORE_ADDR
, struct obj_section
*);
311 /* Convert an address in an overlay section (force into VMA range). */
312 extern CORE_ADDR
symbol_overlayed_address (CORE_ADDR
, struct obj_section
*);
314 /* Load symbols from a file. */
315 extern void symbol_file_add_main (const char *args
,
316 symfile_add_flags add_flags
);
318 /* Clear GDB symbol tables. */
319 extern void symbol_file_clear (int from_tty
);
321 /* Default overlay update function. */
322 extern void simple_overlay_update (struct obj_section
*);
324 extern bfd_byte
*symfile_relocate_debug_section (struct objfile
*, asection
*,
327 extern int symfile_map_offsets_to_segments (bfd
*,
328 const struct symfile_segment_data
*,
330 int, const CORE_ADDR
*);
331 symfile_segment_data_up
get_symfile_segment_data (bfd
*abfd
);
333 extern scoped_restore_tmpl
<int> increment_reading_symtab (void);
335 void expand_symtabs_matching
336 (gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
337 const lookup_name_info
&lookup_name
,
338 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
339 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
340 enum search_domain kind
);
342 void map_symbol_filenames (symbol_filename_ftype
*fun
, void *data
,
345 /* Target-agnostic function to load the sections of an executable into memory.
347 ARGS should be in the form "EXECUTABLE [OFFSET]", where OFFSET is an
348 optional offset to apply to each section. */
349 extern void generic_load (const char *args
, int from_tty
);
351 /* From minidebug.c. */
353 extern gdb_bfd_ref_ptr
find_separate_debug_file_in_section (struct objfile
*);
355 /* True if we are printing debug output about separate debug info files. */
357 extern bool separate_debug_file_debug
;
359 /* Read full symbols immediately. */
361 extern int readnow_symbol_files
;
363 /* Never read full symbols. */
365 extern int readnever_symbol_files
;
367 #endif /* !defined(SYMFILE_H) */