objfiles.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. /* Definitions for symbol file management in GDB.
  2. Copyright (C) 1992-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 (OBJFILES_H)
  15. #define OBJFILES_H
  16. #include "hashtab.h"
  17. #include "gdbsupport/gdb_obstack.h" /* For obstack internals. */
  18. #include "objfile-flags.h"
  19. #include "symfile.h"
  20. #include "progspace.h"
  21. #include "registry.h"
  22. #include "gdb_bfd.h"
  23. #include "psymtab.h"
  24. #include <atomic>
  25. #include <bitset>
  26. #include <vector>
  27. #include "gdbsupport/next-iterator.h"
  28. #include "gdbsupport/safe-iterator.h"
  29. #include "bcache.h"
  30. #include "gdbarch.h"
  31. #include "gdbsupport/refcounted-object.h"
  32. #include "jit.h"
  33. #include "quick-symbol.h"
  34. #include <forward_list>
  35. struct htab;
  36. struct objfile_data;
  37. struct partial_symbol;
  38. /* This structure maintains information on a per-objfile basis about the
  39. "entry point" of the objfile, and the scope within which the entry point
  40. exists. It is possible that gdb will see more than one objfile that is
  41. executable, each with its own entry point.
  42. For example, for dynamically linked executables in SVR4, the dynamic linker
  43. code is contained within the shared C library, which is actually executable
  44. and is run by the kernel first when an exec is done of a user executable
  45. that is dynamically linked. The dynamic linker within the shared C library
  46. then maps in the various program segments in the user executable and jumps
  47. to the user executable's recorded entry point, as if the call had been made
  48. directly by the kernel.
  49. The traditional gdb method of using this info was to use the
  50. recorded entry point to set the entry-file's lowpc and highpc from
  51. the debugging information, where these values are the starting
  52. address (inclusive) and ending address (exclusive) of the
  53. instruction space in the executable which correspond to the
  54. "startup file", i.e. crt0.o in most cases. This file is assumed to
  55. be a startup file and frames with pc's inside it are treated as
  56. nonexistent. Setting these variables is necessary so that
  57. backtraces do not fly off the bottom of the stack.
  58. NOTE: cagney/2003-09-09: It turns out that this "traditional"
  59. method doesn't work. Corinna writes: ``It turns out that the call
  60. to test for "inside entry file" destroys a meaningful backtrace
  61. under some conditions. E.g. the backtrace tests in the asm-source
  62. testcase are broken for some targets. In this test the functions
  63. are all implemented as part of one file and the testcase is not
  64. necessarily linked with a start file (depending on the target).
  65. What happens is, that the first frame is printed normally and
  66. following frames are treated as being inside the entry file then.
  67. This way, only the #0 frame is printed in the backtrace output.''
  68. Ref "frame.c" "NOTE: vinschen/2003-04-01".
  69. Gdb also supports an alternate method to avoid running off the bottom
  70. of the stack.
  71. There are two frames that are "special", the frame for the function
  72. containing the process entry point, since it has no predecessor frame,
  73. and the frame for the function containing the user code entry point
  74. (the main() function), since all the predecessor frames are for the
  75. process startup code. Since we have no guarantee that the linked
  76. in startup modules have any debugging information that gdb can use,
  77. we need to avoid following frame pointers back into frames that might
  78. have been built in the startup code, as we might get hopelessly
  79. confused. However, we almost always have debugging information
  80. available for main().
  81. These variables are used to save the range of PC values which are
  82. valid within the main() function and within the function containing
  83. the process entry point. If we always consider the frame for
  84. main() as the outermost frame when debugging user code, and the
  85. frame for the process entry point function as the outermost frame
  86. when debugging startup code, then all we have to do is have
  87. DEPRECATED_FRAME_CHAIN_VALID return false whenever a frame's
  88. current PC is within the range specified by these variables. In
  89. essence, we set "ceilings" in the frame chain beyond which we will
  90. not proceed when following the frame chain back up the stack.
  91. A nice side effect is that we can still debug startup code without
  92. running off the end of the frame chain, assuming that we have usable
  93. debugging information in the startup modules, and if we choose to not
  94. use the block at main, or can't find it for some reason, everything
  95. still works as before. And if we have no startup code debugging
  96. information but we do have usable information for main(), backtraces
  97. from user code don't go wandering off into the startup code. */
  98. struct entry_info
  99. {
  100. /* The unrelocated value we should use for this objfile entry point. */
  101. CORE_ADDR entry_point;
  102. /* The index of the section in which the entry point appears. */
  103. int the_bfd_section_index;
  104. /* Set to 1 iff ENTRY_POINT contains a valid value. */
  105. unsigned entry_point_p : 1;
  106. /* Set to 1 iff this object was initialized. */
  107. unsigned initialized : 1;
  108. };
  109. #define ALL_OBJFILE_OSECTIONS(objfile, osect) \
  110. for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
  111. if (osect->the_bfd_section == NULL) \
  112. { \
  113. /* Nothing. */ \
  114. } \
  115. else
  116. #define SECT_OFF_DATA(objfile) \
  117. ((objfile->sect_index_data == -1) \
  118. ? (internal_error (__FILE__, __LINE__, \
  119. _("sect_index_data not initialized")), -1) \
  120. : objfile->sect_index_data)
  121. #define SECT_OFF_RODATA(objfile) \
  122. ((objfile->sect_index_rodata == -1) \
  123. ? (internal_error (__FILE__, __LINE__, \
  124. _("sect_index_rodata not initialized")), -1) \
  125. : objfile->sect_index_rodata)
  126. #define SECT_OFF_TEXT(objfile) \
  127. ((objfile->sect_index_text == -1) \
  128. ? (internal_error (__FILE__, __LINE__, \
  129. _("sect_index_text not initialized")), -1) \
  130. : objfile->sect_index_text)
  131. /* Sometimes the .bss section is missing from the objfile, so we don't
  132. want to die here. Let the users of SECT_OFF_BSS deal with an
  133. uninitialized section index. */
  134. #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
  135. /* The "objstats" structure provides a place for gdb to record some
  136. interesting information about its internal state at runtime, on a
  137. per objfile basis, such as information about the number of symbols
  138. read, size of string table (if any), etc. */
  139. struct objstats
  140. {
  141. /* Number of full symbols read. */
  142. int n_syms = 0;
  143. /* Number of ".stabs" read (if applicable). */
  144. int n_stabs = 0;
  145. /* Number of types. */
  146. int n_types = 0;
  147. /* Size of stringtable, (if applicable). */
  148. int sz_strtab = 0;
  149. };
  150. #define OBJSTAT(objfile, expr) (objfile -> stats.expr)
  151. #define OBJSTATS struct objstats stats
  152. extern void print_objfile_statistics (void);
  153. /* Number of entries in the minimal symbol hash table. */
  154. #define MINIMAL_SYMBOL_HASH_SIZE 2039
  155. /* An iterator for minimal symbols. */
  156. struct minimal_symbol_iterator
  157. {
  158. typedef minimal_symbol_iterator self_type;
  159. typedef struct minimal_symbol *value_type;
  160. typedef struct minimal_symbol *&reference;
  161. typedef struct minimal_symbol **pointer;
  162. typedef std::forward_iterator_tag iterator_category;
  163. typedef int difference_type;
  164. explicit minimal_symbol_iterator (struct minimal_symbol *msym)
  165. : m_msym (msym)
  166. {
  167. }
  168. value_type operator* () const
  169. {
  170. return m_msym;
  171. }
  172. bool operator== (const self_type &other) const
  173. {
  174. return m_msym == other.m_msym;
  175. }
  176. bool operator!= (const self_type &other) const
  177. {
  178. return m_msym != other.m_msym;
  179. }
  180. self_type &operator++ ()
  181. {
  182. ++m_msym;
  183. return *this;
  184. }
  185. private:
  186. struct minimal_symbol *m_msym;
  187. };
  188. /* Some objfile data is hung off the BFD. This enables sharing of the
  189. data across all objfiles using the BFD. The data is stored in an
  190. instance of this structure, and associated with the BFD using the
  191. registry system. */
  192. struct objfile_per_bfd_storage
  193. {
  194. objfile_per_bfd_storage (bfd *bfd)
  195. : minsyms_read (false), m_bfd (bfd)
  196. {}
  197. ~objfile_per_bfd_storage ();
  198. /* Intern STRING in this object's string cache and return the unique copy.
  199. The copy has the same lifetime as this object.
  200. STRING must be null-terminated. */
  201. const char *intern (const char *str)
  202. {
  203. return (const char *) string_cache.insert (str, strlen (str) + 1);
  204. }
  205. /* Same as the above, but for an std::string. */
  206. const char *intern (const std::string &str)
  207. {
  208. return (const char *) string_cache.insert (str.c_str (), str.size () + 1);
  209. }
  210. /* Get the BFD this object is associated to. */
  211. bfd *get_bfd () const
  212. {
  213. return m_bfd;
  214. }
  215. /* The storage has an obstack of its own. */
  216. auto_obstack storage_obstack;
  217. /* String cache. */
  218. gdb::bcache string_cache;
  219. /* The gdbarch associated with the BFD. Note that this gdbarch is
  220. determined solely from BFD information, without looking at target
  221. information. The gdbarch determined from a running target may
  222. differ from this e.g. with respect to register types and names. */
  223. struct gdbarch *gdbarch = NULL;
  224. /* Hash table for mapping symbol names to demangled names. Each
  225. entry in the hash table is a demangled_name_entry struct, storing the
  226. language and two consecutive strings, both null-terminated; the first one
  227. is a mangled or linkage name, and the second is the demangled name or just
  228. a zero byte if the name doesn't demangle. */
  229. htab_up demangled_names_hash;
  230. /* The per-objfile information about the entry point, the scope (file/func)
  231. containing the entry point, and the scope of the user's main() func. */
  232. entry_info ei {};
  233. /* The name and language of any "main" found in this objfile. The
  234. name can be NULL, which means that the information was not
  235. recorded. */
  236. const char *name_of_main = NULL;
  237. enum language language_of_main = language_unknown;
  238. /* Each file contains a pointer to an array of minimal symbols for all
  239. global symbols that are defined within the file. The array is
  240. terminated by a "null symbol", one that has a NULL pointer for the
  241. name and a zero value for the address. This makes it easy to walk
  242. through the array when passed a pointer to somewhere in the middle
  243. of it. There is also a count of the number of symbols, which does
  244. not include the terminating null symbol. */
  245. gdb::unique_xmalloc_ptr<minimal_symbol> msymbols;
  246. int minimal_symbol_count = 0;
  247. /* The number of minimal symbols read, before any minimal symbol
  248. de-duplication is applied. Note in particular that this has only
  249. a passing relationship with the actual size of the table above;
  250. use minimal_symbol_count if you need the true size. */
  251. int n_minsyms = 0;
  252. /* This is true if minimal symbols have already been read. Symbol
  253. readers can use this to bypass minimal symbol reading. Also, the
  254. minimal symbol table management code in minsyms.c uses this to
  255. suppress new minimal symbols. You might think that MSYMBOLS or
  256. MINIMAL_SYMBOL_COUNT could be used for this, but it is possible
  257. for multiple readers to install minimal symbols into a given
  258. per-BFD. */
  259. bool minsyms_read : 1;
  260. /* This is a hash table used to index the minimal symbols by (mangled)
  261. name. */
  262. minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE] {};
  263. /* This hash table is used to index the minimal symbols by their
  264. demangled names. Uses a language-specific hash function via
  265. search_name_hash. */
  266. minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE] {};
  267. /* All the different languages of symbols found in the demangled
  268. hash table. */
  269. std::bitset<nr_languages> demangled_hash_languages;
  270. private:
  271. /* The BFD this object is associated to. */
  272. bfd *m_bfd;
  273. };
  274. /* An iterator that first returns a parent objfile, and then each
  275. separate debug objfile. */
  276. class separate_debug_iterator
  277. {
  278. public:
  279. explicit separate_debug_iterator (struct objfile *objfile)
  280. : m_objfile (objfile),
  281. m_parent (objfile)
  282. {
  283. }
  284. bool operator!= (const separate_debug_iterator &other)
  285. {
  286. return m_objfile != other.m_objfile;
  287. }
  288. separate_debug_iterator &operator++ ();
  289. struct objfile *operator* ()
  290. {
  291. return m_objfile;
  292. }
  293. private:
  294. struct objfile *m_objfile;
  295. struct objfile *m_parent;
  296. };
  297. /* A range adapter wrapping separate_debug_iterator. */
  298. typedef iterator_range<separate_debug_iterator> separate_debug_range;
  299. /* Master structure for keeping track of each file from which
  300. gdb reads symbols. There are several ways these get allocated: 1.
  301. The main symbol file, symfile_objfile, set by the symbol-file command,
  302. 2. Additional symbol files added by the add-symbol-file command,
  303. 3. Shared library objfiles, added by ADD_SOLIB, 4. symbol files
  304. for modules that were loaded when GDB attached to a remote system
  305. (see remote-vx.c).
  306. GDB typically reads symbols twice -- first an initial scan which just
  307. reads "partial symbols"; these are partial information for the
  308. static/global symbols in a symbol file. When later looking up
  309. symbols, lookup_symbol is used to check if we only have a partial
  310. symbol and if so, read and expand the full compunit. */
  311. struct objfile
  312. {
  313. private:
  314. /* The only way to create an objfile is to call objfile::make. */
  315. objfile (bfd *, const char *, objfile_flags);
  316. public:
  317. /* Normally you should not call delete. Instead, call 'unlink' to
  318. remove it from the program space's list. In some cases, you may
  319. need to hold a reference to an objfile that is independent of its
  320. existence on the program space's list; for this case, the
  321. destructor must be public so that shared_ptr can reference
  322. it. */
  323. ~objfile ();
  324. /* Create an objfile. */
  325. static objfile *make (bfd *bfd_, const char *name_, objfile_flags flags_,
  326. objfile *parent = nullptr);
  327. /* Remove an objfile from the current program space, and free
  328. it. */
  329. void unlink ();
  330. DISABLE_COPY_AND_ASSIGN (objfile);
  331. /* A range adapter that makes it possible to iterate over all
  332. compunits in one objfile. */
  333. compunit_symtab_range compunits ()
  334. {
  335. return compunit_symtab_range (compunit_symtabs);
  336. }
  337. /* A range adapter that makes it possible to iterate over all
  338. minimal symbols of an objfile. */
  339. typedef iterator_range<minimal_symbol_iterator> msymbols_range;
  340. /* Return a range adapter for iterating over all minimal
  341. symbols. */
  342. msymbols_range msymbols ()
  343. {
  344. auto start = minimal_symbol_iterator (per_bfd->msymbols.get ());
  345. auto end = minimal_symbol_iterator (per_bfd->msymbols.get ()
  346. + per_bfd->minimal_symbol_count);
  347. return msymbols_range (start, end);
  348. }
  349. /* Return a range adapter for iterating over all the separate debug
  350. objfiles of this objfile. */
  351. separate_debug_range separate_debug_objfiles ()
  352. {
  353. auto start = separate_debug_iterator (this);
  354. auto end = separate_debug_iterator (nullptr);
  355. return separate_debug_range (start, end);
  356. }
  357. CORE_ADDR text_section_offset () const
  358. {
  359. return section_offsets[SECT_OFF_TEXT (this)];
  360. }
  361. CORE_ADDR data_section_offset () const
  362. {
  363. return section_offsets[SECT_OFF_DATA (this)];
  364. }
  365. /* Intern STRING and return the unique copy. The copy has the same
  366. lifetime as the per-BFD object. */
  367. const char *intern (const char *str)
  368. {
  369. return per_bfd->intern (str);
  370. }
  371. /* Intern STRING and return the unique copy. The copy has the same
  372. lifetime as the per-BFD object. */
  373. const char *intern (const std::string &str)
  374. {
  375. return per_bfd->intern (str);
  376. }
  377. /* Retrieve the gdbarch associated with this objfile. */
  378. struct gdbarch *arch () const
  379. {
  380. return per_bfd->gdbarch;
  381. }
  382. /* Return true if OBJFILE has partial symbols. */
  383. bool has_partial_symbols ();
  384. /* Return true if this objfile has any unexpanded symbols. A return
  385. value of false indicates either, that this objfile has all its
  386. symbols fully expanded (i.e. fully read in), or that this objfile has
  387. no symbols at all (i.e. no debug information). */
  388. bool has_unexpanded_symtabs ();
  389. /* See quick_symbol_functions. */
  390. struct symtab *find_last_source_symtab ();
  391. /* See quick_symbol_functions. */
  392. void forget_cached_source_info ();
  393. /* Expand and iterate over each "partial" symbol table in OBJFILE
  394. where the source file is named NAME.
  395. If NAME is not absolute, a match after a '/' in the symbol table's
  396. file name will also work, REAL_PATH is NULL then. If NAME is
  397. absolute then REAL_PATH is non-NULL absolute file name as resolved
  398. via gdb_realpath from NAME.
  399. If a match is found, the "partial" symbol table is expanded.
  400. Then, this calls iterate_over_some_symtabs (or equivalent) over
  401. all newly-created symbol tables, passing CALLBACK to it.
  402. The result of this call is returned. */
  403. bool map_symtabs_matching_filename
  404. (const char *name, const char *real_path,
  405. gdb::function_view<bool (symtab *)> callback);
  406. /* Check to see if the symbol is defined in a "partial" symbol table
  407. of this objfile. BLOCK_INDEX should be either GLOBAL_BLOCK or
  408. STATIC_BLOCK, depending on whether we want to search global
  409. symbols or static symbols. NAME is the name of the symbol to
  410. look for. DOMAIN indicates what sort of symbol to search for.
  411. Returns the newly-expanded compunit in which the symbol is
  412. defined, or NULL if no such symbol table exists. If OBJFILE
  413. contains !TYPE_OPAQUE symbol prefer its compunit. If it contains
  414. only TYPE_OPAQUE symbol(s), return at least that compunit. */
  415. struct compunit_symtab *lookup_symbol (block_enum kind, const char *name,
  416. domain_enum domain);
  417. /* See quick_symbol_functions. */
  418. void print_stats (bool print_bcache);
  419. /* See quick_symbol_functions. */
  420. void dump ();
  421. /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
  422. the corresponding symbol tables are loaded. */
  423. void expand_symtabs_for_function (const char *func_name);
  424. /* See quick_symbol_functions. */
  425. void expand_all_symtabs ();
  426. /* Read all symbol tables associated with OBJFILE which have
  427. symtab_to_fullname equal to FULLNAME.
  428. This is for the purposes of examining code only, e.g., expand_line_sal.
  429. The routine may ignore debug info that is known to not be useful with
  430. code, e.g., DW_TAG_type_unit for dwarf debug info. */
  431. void expand_symtabs_with_fullname (const char *fullname);
  432. /* See quick_symbol_functions. */
  433. void expand_matching_symbols
  434. (const lookup_name_info &name, domain_enum domain,
  435. int global,
  436. symbol_compare_ftype *ordered_compare);
  437. /* See quick_symbol_functions. */
  438. bool expand_symtabs_matching
  439. (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
  440. const lookup_name_info *lookup_name,
  441. gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
  442. gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
  443. block_search_flags search_flags,
  444. domain_enum domain,
  445. enum search_domain kind);
  446. /* See quick_symbol_functions. */
  447. struct compunit_symtab *find_pc_sect_compunit_symtab
  448. (struct bound_minimal_symbol msymbol,
  449. CORE_ADDR pc,
  450. struct obj_section *section,
  451. int warn_if_readin);
  452. /* See quick_symbol_functions. */
  453. void map_symbol_filenames (gdb::function_view<symbol_filename_ftype> fun,
  454. bool need_fullname);
  455. /* See quick_symbol_functions. */
  456. struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address);
  457. /* See quick_symbol_functions. */
  458. enum language lookup_global_symbol_language (const char *name,
  459. domain_enum domain,
  460. bool *symbol_found_p);
  461. /* See quick_symbol_functions. */
  462. void require_partial_symbols (bool verbose);
  463. /* Return the relocation offset applied to SECTION. */
  464. CORE_ADDR section_offset (bfd_section *section) const
  465. {
  466. /* The section's owner can be nullptr if it is one of the _bfd_std_section
  467. section. */
  468. gdb_assert (section->owner == nullptr || section->owner == this->obfd);
  469. int idx = gdb_bfd_section_index (this->obfd, section);
  470. return this->section_offsets[idx];
  471. }
  472. /* Set the relocation offset applied to SECTION. */
  473. void set_section_offset (bfd_section *section, CORE_ADDR offset)
  474. {
  475. /* The section's owner can be nullptr if it is one of the _bfd_std_section
  476. section. */
  477. gdb_assert (section->owner == nullptr || section->owner == this->obfd);
  478. int idx = gdb_bfd_section_index (this->obfd, section);
  479. this->section_offsets[idx] = offset;
  480. }
  481. /* The object file's original name as specified by the user,
  482. made absolute, and tilde-expanded. However, it is not canonicalized
  483. (i.e., it has not been passed through gdb_realpath).
  484. This pointer is never NULL. This does not have to be freed; it is
  485. guaranteed to have a lifetime at least as long as the objfile. */
  486. const char *original_name = nullptr;
  487. CORE_ADDR addr_low = 0;
  488. /* Some flag bits for this objfile. */
  489. objfile_flags flags;
  490. /* The program space associated with this objfile. */
  491. struct program_space *pspace;
  492. /* List of compunits.
  493. These are used to do symbol lookups and file/line-number lookups. */
  494. struct compunit_symtab *compunit_symtabs = nullptr;
  495. /* The object file's BFD. Can be null if the objfile contains only
  496. minimal symbols, e.g. the run time common symbols for SunOS4. */
  497. bfd *obfd;
  498. /* The per-BFD data. Note that this is treated specially if OBFD
  499. is NULL. */
  500. struct objfile_per_bfd_storage *per_bfd = nullptr;
  501. /* The modification timestamp of the object file, as of the last time
  502. we read its symbols. */
  503. long mtime = 0;
  504. /* Obstack to hold objects that should be freed when we load a new symbol
  505. table from this object file. */
  506. struct obstack objfile_obstack {};
  507. /* Structure which keeps track of functions that manipulate objfile's
  508. of the same type as this objfile. I.e. the function to read partial
  509. symbols for example. Note that this structure is in statically
  510. allocated memory, and is shared by all objfiles that use the
  511. object module reader of this type. */
  512. const struct sym_fns *sf = nullptr;
  513. /* The "quick" (aka partial) symbol functions for this symbol
  514. reader. */
  515. std::forward_list<quick_symbol_functions_up> qf;
  516. /* Per objfile data-pointers required by other GDB modules. */
  517. REGISTRY_FIELDS {};
  518. /* Set of relocation offsets to apply to each section.
  519. The table is indexed by the_bfd_section->index, thus it is generally
  520. as large as the number of sections in the binary.
  521. These offsets indicate that all symbols (including partial and
  522. minimal symbols) which have been read have been relocated by this
  523. much. Symbols which are yet to be read need to be relocated by it. */
  524. ::section_offsets section_offsets;
  525. /* Indexes in the section_offsets array. These are initialized by the
  526. *_symfile_offsets() family of functions (som_symfile_offsets,
  527. xcoff_symfile_offsets, default_symfile_offsets). In theory they
  528. should correspond to the section indexes used by bfd for the
  529. current objfile. The exception to this for the time being is the
  530. SOM version.
  531. These are initialized to -1 so that we can later detect if they
  532. are used w/o being properly assigned to. */
  533. int sect_index_text = -1;
  534. int sect_index_data = -1;
  535. int sect_index_bss = -1;
  536. int sect_index_rodata = -1;
  537. /* These pointers are used to locate the section table, which
  538. among other things, is used to map pc addresses into sections.
  539. SECTIONS points to the first entry in the table, and
  540. SECTIONS_END points to the first location past the last entry
  541. in the table. The table is stored on the objfile_obstack. The
  542. sections are indexed by the BFD section index; but the
  543. structure data is only valid for certain sections
  544. (e.g. non-empty, SEC_ALLOC). */
  545. struct obj_section *sections = nullptr;
  546. struct obj_section *sections_end = nullptr;
  547. /* GDB allows to have debug symbols in separate object files. This is
  548. used by .gnu_debuglink, ELF build id note and Mach-O OSO.
  549. Although this is a tree structure, GDB only support one level
  550. (ie a separate debug for a separate debug is not supported). Note that
  551. separate debug object are in the main chain and therefore will be
  552. visited by objfiles & co iterators. Separate debug objfile always
  553. has a non-nul separate_debug_objfile_backlink. */
  554. /* Link to the first separate debug object, if any. */
  555. struct objfile *separate_debug_objfile = nullptr;
  556. /* If this is a separate debug object, this is used as a link to the
  557. actual executable objfile. */
  558. struct objfile *separate_debug_objfile_backlink = nullptr;
  559. /* If this is a separate debug object, this is a link to the next one
  560. for the same executable objfile. */
  561. struct objfile *separate_debug_objfile_link = nullptr;
  562. /* Place to stash various statistics about this objfile. */
  563. OBJSTATS;
  564. /* A linked list of symbols created when reading template types or
  565. function templates. These symbols are not stored in any symbol
  566. table, so we have to keep them here to relocate them
  567. properly. */
  568. struct symbol *template_symbols = nullptr;
  569. /* Associate a static link (struct dynamic_prop *) to all blocks (struct
  570. block *) that have one.
  571. In the context of nested functions (available in Pascal, Ada and GNU C,
  572. for instance), a static link (as in DWARF's DW_AT_static_link attribute)
  573. for a function is a way to get the frame corresponding to the enclosing
  574. function.
  575. Very few blocks have a static link, so it's more memory efficient to
  576. store these here rather than in struct block. Static links must be
  577. allocated on the objfile's obstack. */
  578. htab_up static_links;
  579. /* JIT-related data for this objfile, if the objfile is a JITer;
  580. that is, it produces JITed objfiles. */
  581. std::unique_ptr<jiter_objfile_data> jiter_data = nullptr;
  582. /* JIT-related data for this objfile, if the objfile is JITed;
  583. that is, it was produced by a JITer. */
  584. std::unique_ptr<jited_objfile_data> jited_data = nullptr;
  585. /* A flag that is set to true if the JIT interface symbols are not
  586. found in this objfile, so that we can skip the symbol lookup the
  587. next time. If an objfile does not have the symbols, it will
  588. never have them. */
  589. bool skip_jit_symbol_lookup = false;
  590. };
  591. /* A deleter for objfile. */
  592. struct objfile_deleter
  593. {
  594. void operator() (objfile *ptr) const
  595. {
  596. ptr->unlink ();
  597. }
  598. };
  599. /* A unique pointer that holds an objfile. */
  600. typedef std::unique_ptr<objfile, objfile_deleter> objfile_up;
  601. /* Sections in an objfile. The section offsets are stored in the
  602. OBJFILE. */
  603. struct obj_section
  604. {
  605. /* Relocation offset applied to the section. */
  606. CORE_ADDR offset () const
  607. {
  608. return this->objfile->section_offset (this->the_bfd_section);
  609. }
  610. /* Set the relocation offset applied to the section. */
  611. void set_offset (CORE_ADDR offset)
  612. {
  613. this->objfile->set_section_offset (this->the_bfd_section, offset);
  614. }
  615. /* The memory address of the section (vma + offset). */
  616. CORE_ADDR addr () const
  617. {
  618. return bfd_section_vma (this->the_bfd_section) + this->offset ();
  619. }
  620. /* The one-passed-the-end memory address of the section
  621. (vma + size + offset). */
  622. CORE_ADDR endaddr () const
  623. {
  624. return this->addr () + bfd_section_size (this->the_bfd_section);
  625. }
  626. /* BFD section pointer */
  627. struct bfd_section *the_bfd_section;
  628. /* Objfile this section is part of. */
  629. struct objfile *objfile;
  630. /* True if this "overlay section" is mapped into an "overlay region". */
  631. int ovly_mapped;
  632. };
  633. /* Declarations for functions defined in objfiles.c */
  634. extern int entry_point_address_query (CORE_ADDR *entry_p);
  635. extern CORE_ADDR entry_point_address (void);
  636. extern void build_objfile_section_table (struct objfile *);
  637. extern void free_objfile_separate_debug (struct objfile *);
  638. extern void objfile_relocate (struct objfile *, const section_offsets &);
  639. extern void objfile_rebase (struct objfile *, CORE_ADDR);
  640. extern int objfile_has_full_symbols (struct objfile *objfile);
  641. extern int objfile_has_symbols (struct objfile *objfile);
  642. extern int have_partial_symbols (void);
  643. extern int have_full_symbols (void);
  644. extern void objfile_set_sym_fns (struct objfile *objfile,
  645. const struct sym_fns *sf);
  646. extern void objfiles_changed (void);
  647. /* Return true if ADDR maps into one of the sections of OBJFILE and false
  648. otherwise. */
  649. extern bool is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile);
  650. /* Return true if ADDRESS maps into one of the sections of a
  651. OBJF_SHARED objfile of PSPACE and false otherwise. */
  652. extern bool shared_objfile_contains_address_p (struct program_space *pspace,
  653. CORE_ADDR address);
  654. /* This operation deletes all objfile entries that represent solibs that
  655. weren't explicitly loaded by the user, via e.g., the add-symbol-file
  656. command. */
  657. extern void objfile_purge_solibs (void);
  658. /* Functions for dealing with the minimal symbol table, really a misc
  659. address<->symbol mapping for things we don't have debug symbols for. */
  660. extern int have_minimal_symbols (void);
  661. extern struct obj_section *find_pc_section (CORE_ADDR pc);
  662. /* Return non-zero if PC is in a section called NAME. */
  663. extern int pc_in_section (CORE_ADDR, const char *);
  664. /* Return non-zero if PC is in a SVR4-style procedure linkage table
  665. section. */
  666. static inline int
  667. in_plt_section (CORE_ADDR pc)
  668. {
  669. return (pc_in_section (pc, ".plt")
  670. || pc_in_section (pc, ".plt.sec"));
  671. }
  672. /* Keep a registry of per-objfile data-pointers required by other GDB
  673. modules. */
  674. DECLARE_REGISTRY(objfile);
  675. /* In normal use, the section map will be rebuilt by find_pc_section
  676. if objfiles have been added, removed or relocated since it was last
  677. called. Calling inhibit_section_map_updates will inhibit this
  678. behavior until the returned scoped_restore object is destroyed. If
  679. you call inhibit_section_map_updates you must ensure that every
  680. call to find_pc_section in the inhibited region relates to a
  681. section that is already in the section map and has not since been
  682. removed or relocated. */
  683. extern scoped_restore_tmpl<int> inhibit_section_map_updates
  684. (struct program_space *pspace);
  685. extern void default_iterate_over_objfiles_in_search_order
  686. (struct gdbarch *gdbarch,
  687. iterate_over_objfiles_in_search_order_cb_ftype *cb,
  688. void *cb_data, struct objfile *current_objfile);
  689. /* Reset the per-BFD storage area on OBJ. */
  690. void set_objfile_per_bfd (struct objfile *obj);
  691. /* Return canonical name for OBJFILE.
  692. This is the real file name if the file has been opened.
  693. Otherwise it is the original name supplied by the user. */
  694. const char *objfile_name (const struct objfile *objfile);
  695. /* Return the (real) file name of OBJFILE if the file has been opened,
  696. otherwise return NULL. */
  697. const char *objfile_filename (const struct objfile *objfile);
  698. /* Return the name to print for OBJFILE in debugging messages. */
  699. extern const char *objfile_debug_name (const struct objfile *objfile);
  700. /* Return the name of the file format of OBJFILE if the file has been opened,
  701. otherwise return NULL. */
  702. const char *objfile_flavour_name (struct objfile *objfile);
  703. /* Set the objfile's notion of the "main" name and language. */
  704. extern void set_objfile_main_name (struct objfile *objfile,
  705. const char *name, enum language lang);
  706. /* Find an integer type SIZE_IN_BYTES bytes in size from OF and return it.
  707. UNSIGNED_P controls if the integer is unsigned or not. */
  708. extern struct type *objfile_int_type (struct objfile *of, int size_in_bytes,
  709. bool unsigned_p);
  710. extern void objfile_register_static_link
  711. (struct objfile *objfile,
  712. const struct block *block,
  713. const struct dynamic_prop *static_link);
  714. extern const struct dynamic_prop *objfile_lookup_static_link
  715. (struct objfile *objfile, const struct block *block);
  716. #endif /* !defined (OBJFILES_H) */