symfile.h 12 KB

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