]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/symfile.h
Add --rosegment option to BFD linker to stop the '-z separate-code' from generating...
[thirdparty/binutils-gdb.git] / gdb / symfile.h
CommitLineData
c906108c 1/* Definitions for reading symbol files into GDB.
3a6c3343 2
1d506c26 3 Copyright (C) 1990-2024 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#if !defined (SYMFILE_H)
21#define SYMFILE_H
22
23/* This file requires that you first include "bfd.h". */
16708cba 24#include "symtab.h"
48faced0 25#include "probe.h"
b15cc25c
PA
26#include "symfile-add-flags.h"
27#include "objfile-flags.h"
192b62ce 28#include "gdb_bfd.h"
268a13a5 29#include "gdbsupport/function-view.h"
bb2a6777 30#include "target-section.h"
9b99dcc8 31#include "quick-symbol.h"
c906108c 32
63ca651f 33/* Opaque declarations. */
0542c86d 34struct target_section;
da3331ec 35struct objfile;
1c772458 36struct obj_section;
63ca651f 37struct obstack;
fe898f56 38struct block;
55aa24fb 39struct value;
bd2b40ac 40class frame_info_ptr;
55aa24fb
SDJ
41struct agent_expr;
42struct axs_value;
935676c9 43class probe;
63ca651f 44
52059ffd
TT
45struct other_sections
46{
37e136b1
TT
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
56 DISABLE_COPY_AND_ASSIGN (other_sections);
57
52059ffd 58 CORE_ADDR addr;
37e136b1 59 std::string name;
52059ffd 60
d81a3eaf
PT
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 */
52059ffd
TT
64 int sectindex;
65};
66
62557bbc
KB
67/* Define an array of addresses to accommodate non-contiguous dynamic
68 loading of modules. This is for use when entering commands, so we
3a6c3343
AC
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
37e136b1 74typedef std::vector<other_sections> section_addr_info;
28c32713
JB
75
76/* A table listing the load segments in a symfile, and which segment
77 each BFD section belongs to. */
31d99776
DJ
78struct symfile_segment_data
79{
68b888ff
SM
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
68b888ff 93 /* The segments present in this file. If there are
31d99776
DJ
94 two, the text segment is the first one and the data segment
95 is the second one. */
68b888ff 96 std::vector<segment> segments;
31d99776 97
68b888ff
SM
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
28c32713 100 S, or zero if it is not in any segment. */
9005fbbb 101 std::vector<int> segment_info;
31d99776
DJ
102};
103
62982abd
SM
104using symfile_segment_data_up = std::unique_ptr<symfile_segment_data>;
105
55aa24fb
SDJ
106/* Structure of functions used for probe support. If one of these functions
107 is provided, all must be. */
108
109struct sym_probe_fns
110{
aaa63a31 111 /* If non-NULL, return a reference to vector of probe objects. */
814cf43a
TT
112 const std::vector<std::unique_ptr<probe>> &(*sym_get_probes)
113 (struct objfile *);
55aa24fb
SDJ
114};
115
c906108c
SS
116/* Structure to keep track of symbol reading functions for various
117 object file types. */
118
c5aa993b 119struct sym_fns
3a6c3343 120{
3a6c3343
AC
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. */
c906108c 124
3a6c3343 125 void (*sym_new_init) (struct objfile *);
c906108c 126
3a6c3343
AC
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. */
c906108c 130
3a6c3343 131 void (*sym_init) (struct objfile *);
c906108c 132
f4352531 133 /* sym_read (objfile, symfile_flags) Reads a symbol file into a psymtab
3a6c3343 134 (or possibly a symtab). OBJFILE is the objfile struct for the
f4352531
TG
135 file we are reading. SYMFILE_FLAGS are the flags passed to
136 symbol_file_add & co. */
c906108c 137
b15cc25c 138 void (*sym_read) (struct objfile *, symfile_add_flags);
c906108c 139
3a6c3343
AC
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. */
c906108c 143
3a6c3343 144 void (*sym_finish) (struct objfile *);
c906108c 145
db7a9bcd 146
3a6c3343 147 /* This function produces a file-dependent section_offsets
db7a9bcd
SM
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. */
c906108c 152
37e136b1 153 void (*sym_offsets) (struct objfile *, const section_addr_info &);
c906108c 154
31d99776
DJ
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
62982abd 159 symfile_segment_data_up (*sym_segments) (bfd *abfd);
31d99776 160
c295b2e5
JB
161 /* This function should read the linetable from the objfile when
162 the line table cannot be read while processing the debugging
163 information. */
ac8035ab 164
f56ce883 165 void (*sym_read_linetable) (struct objfile *);
c295b2e5 166
ac8035ab
TG
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
55aa24fb
SDJ
173 /* If non-NULL, this objfile has probe support, and all the probe
174 functions referred to here will be non-NULL. */
175 const struct sym_probe_fns *sym_probe_fns;
3a6c3343 176};
c906108c 177
37e136b1 178extern section_addr_info
3e43a32a 179 build_section_addr_info_from_objfile (const struct objfile *objfile);
567995e1 180
75242ef4 181extern void relative_addr_info_to_section_offsets
6a053cb1 182 (section_offsets &section_offsets, const section_addr_info &addrs);
75242ef4 183
37e136b1 184extern void addr_info_make_relative (section_addr_info *addrs,
75242ef4
JK
185 bfd *abfd);
186
c906108c
SS
187/* The default version of sym_fns.sym_offsets for readers that don't
188 do anything special. */
189
570b8f7c 190extern void default_symfile_offsets (struct objfile *objfile,
37e136b1 191 const section_addr_info &);
c906108c 192
31d99776
DJ
193/* The default version of sym_fns.sym_segments for readers that don't
194 do anything special. */
195
62982abd 196extern symfile_segment_data_up default_symfile_segments (bfd *abfd);
c906108c 197
ac8035ab
TG
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,
dda83cd7 202 asection *sectp, bfd_byte *buf);
ac8035ab 203
f71ad555
SM
204extern struct symtab *allocate_symtab
205 (struct compunit_symtab *cust, const char *filename, const char *id)
4e04028d 206 ATTRIBUTE_NONNULL (1);
c906108c 207
f71ad555
SM
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
43f3e411
DE
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
c256e171 222extern void add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *);
c906108c 223
b15cc25c 224extern void clear_symtab_users (symfile_add_flags add_flags);
f176c4b5
DE
225
226extern enum language deduce_language_from_filename (const char *);
227
56618e20
TT
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
b15cc25c 233extern struct objfile *symbol_file_add (const char *, symfile_add_flags,
37e136b1 234 section_addr_info *, objfile_flags);
7eedccfa 235
98badbfd
TT
236extern struct objfile *symbol_file_add_from_bfd (const gdb_bfd_ref_ptr &,
237 const char *, symfile_add_flags,
37e136b1 238 section_addr_info *,
dda83cd7 239 objfile_flags, struct objfile *parent);
eb4556d7 240
98badbfd
TT
241extern void symbol_file_add_separate (const gdb_bfd_ref_ptr &, const char *,
242 symfile_add_flags, struct objfile *);
9cce227f 243
6647f05d
AH
244/* Find separate debuginfo for OBJFILE (using .gnu_debuglink section).
245 Returns pathname, or an empty string.
246
34f997c8
AB
247 Any warnings generated as part of this lookup are added to WARNINGS. If
248 some other mechanism can be used to lookup the debug information then
249 the warning will not be shown, however, if GDB fails to find suitable
250 debug information using any approach, then any warnings will be
251 printed. */
6647f05d
AH
252
253extern std::string find_separate_debug_file_by_debuglink
34f997c8 254 (struct objfile *objfile, deferred_warnings *warnings);
9cce227f 255
3a6c3343
AC
256/* Build (allocate and populate) a section_addr_info struct from an
257 existing section table. */
62557bbc 258
37e136b1 259extern section_addr_info
25b5a04e 260 build_section_addr_info_from_section_table (const std::vector<target_section> &table);
62557bbc 261
c906108c
SS
262 /* Variables */
263
491144b5 264/* If true, shared library symbols will be added automatically
b7209cb4
FF
265 when the inferior is created, new libraries are loaded, or when
266 attaching to the inferior. This is almost always what users will
267 want to have happen; but for very large programs, the startup time
268 will be excessive, and so if this is a problem, the user can clear
269 this flag and then add the shared library symbols as needed. Note
270 that there is a potential for confusion, since if the shared
271 library symbols are not loaded, commands like "info fun" will *not*
3a6c3343 272 report all the functions that are actually present. */
c906108c 273
491144b5 274extern bool auto_solib_add;
c906108c 275
c906108c
SS
276/* From symfile.c */
277
8b60591b
JB
278extern void set_initial_language (void);
279
192b62ce 280extern gdb_bfd_ref_ptr symfile_bfd_open (const char *);
c906108c 281
f96328ac
TT
282/* Like symfile_bfd_open, but will not throw an exception on error.
283 Instead, it issues a warning and returns nullptr. */
284
285extern gdb_bfd_ref_ptr symfile_bfd_open_no_error (const char *) noexcept;
286
a121b7c1 287extern int get_section_index (struct objfile *, const char *);
e2f6d8e5 288
770e7fc7
DE
289extern int print_symbol_loading_p (int from_tty, int mainline, int full);
290
c906108c 291/* Utility functions for overlay sections: */
3a6c3343
AC
292extern enum overlay_debugging_state
293{
294 ovly_off,
295 ovly_on,
d874f1e2
MS
296 ovly_auto
297} overlay_debugging;
c906108c
SS
298extern int overlay_cache_invalid;
299
3a6c3343 300/* Return the "mapped" overlay section containing the PC. */
714835d5 301extern struct obj_section *find_pc_mapped_section (CORE_ADDR);
c906108c 302
3a6c3343
AC
303/* Return any overlay section containing the PC (even in its LMA
304 region). */
714835d5 305extern struct obj_section *find_pc_overlay (CORE_ADDR);
c906108c 306
3a6c3343 307/* Return true if the section is an overlay. */
714835d5 308extern int section_is_overlay (struct obj_section *);
c906108c 309
3a6c3343 310/* Return true if the overlay section is currently "mapped". */
714835d5 311extern int section_is_mapped (struct obj_section *);
c906108c 312
3a6c3343 313/* Return true if pc belongs to section's VMA. */
6ec27270 314extern bool pc_in_mapped_range (CORE_ADDR, struct obj_section *);
c906108c 315
3a6c3343 316/* Return true if pc belongs to section's LMA. */
6ec27270 317extern bool pc_in_unmapped_range (CORE_ADDR, struct obj_section *);
c906108c 318
3a6c3343 319/* Map an address from a section's LMA to its VMA. */
714835d5 320extern CORE_ADDR overlay_mapped_address (CORE_ADDR, struct obj_section *);
c906108c 321
3a6c3343 322/* Map an address from a section's VMA to its LMA. */
714835d5 323extern CORE_ADDR overlay_unmapped_address (CORE_ADDR, struct obj_section *);
c906108c 324
3a6c3343 325/* Convert an address in an overlay section (force into VMA range). */
714835d5 326extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
c906108c 327
3a6c3343 328/* Load symbols from a file. */
ecf45d2c
SL
329extern void symbol_file_add_main (const char *args,
330 symfile_add_flags add_flags);
1adeb98a 331
3a6c3343 332/* Clear GDB symbol tables. */
1adeb98a
FN
333extern void symbol_file_clear (int from_tty);
334
1c772458
UW
335/* Default overlay update function. */
336extern void simple_overlay_update (struct obj_section *);
337
ac8035ab
TG
338extern bfd_byte *symfile_relocate_debug_section (struct objfile *, asection *,
339 bfd_byte *);
086df311 340
31d99776 341extern int symfile_map_offsets_to_segments (bfd *,
3189cb12 342 const struct symfile_segment_data *,
6a053cb1 343 section_offsets &,
31d99776 344 int, const CORE_ADDR *);
62982abd 345symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
31d99776 346
c83dd867 347extern scoped_restore_tmpl<int> increment_reading_symtab (void);
ccefe4c4 348
df35e626 349bool expand_symtabs_matching
14bc53a8 350 (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
b5ec771e 351 const lookup_name_info &lookup_name,
14bc53a8
PA
352 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
353 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
03a8ea51 354 block_search_flags search_flags,
c92d4de1 355 domain_search_flags kind);
540c2971 356
f4655dee
TT
357void map_symbol_filenames (gdb::function_view<symbol_filename_ftype> fun,
358 bool need_fullname);
540c2971 359
854f6088
SM
360/* Target-agnostic function to load the sections of an executable into memory.
361
362 ARGS should be in the form "EXECUTABLE [OFFSET]", where OFFSET is an
363 optional offset to apply to each section. */
364extern void generic_load (const char *args, int from_tty);
365
608e2dbb
TT
366/* From minidebug.c. */
367
192b62ce 368extern gdb_bfd_ref_ptr find_separate_debug_file_in_section (struct objfile *);
608e2dbb 369
c4dcb155
SM
370/* True if we are printing debug output about separate debug info files. */
371
491144b5 372extern bool separate_debug_file_debug;
c4dcb155 373
6dfd0722
AB
374/* Print a "separate-debug-file" debug statement. */
375
376#define separate_debug_file_debug_printf(fmt, ...) \
377 debug_prefixed_printf_cond (separate_debug_file_debug, \
378 "separate-debug-file", \
379 fmt, ##__VA_ARGS__)
380
381/* Print "separate-debug-file" enter/exit debug statements. */
382
383#define SEPARATE_DEBUG_FILE_SCOPED_DEBUG_ENTER_EXIT \
384 scoped_debug_enter_exit (separate_debug_file_debug, \
385 "separate-debug-file")
386
387/* Print "separate-debug-file" start/end debug statements. */
388
389#define SEPARATE_DEBUG_FILE_SCOPED_DEBUG_START_END(fmt, ...) \
390 scoped_debug_start_end (separate_debug_file_debug, \
391 "separate-debug-file", fmt, ##__VA_ARGS__)
392
fe7a351a
SM
393/* Read full symbols immediately. */
394
395extern int readnow_symbol_files;
396
397/* Never read full symbols. */
398
399extern int readnever_symbol_files;
400
9085a018
SM
401/* This is the symbol-file command. Read the file, analyze its
402 symbols, and add a struct symtab to a symtab list. The syntax of
403 the command is rather bizarre:
404
405 1. The function buildargv implements various quoting conventions
406 which are undocumented and have little or nothing in common with
407 the way things are quoted (or not quoted) elsewhere in GDB.
408
409 2. Options are used, which are not generally used in GDB (perhaps
410 "set mapped on", "set readnow on" would be better)
411
412 3. The order of options matters, which is contrary to GNU
413 conventions (because it is confusing and inconvenient). */
414
415extern void symbol_file_command (const char *, int);
416
c5aa993b 417#endif /* !defined(SYMFILE_H) */