symtab.h 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646
  1. /* Symbol table definitions for GDB.
  2. Copyright (C) 1986-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 (SYMTAB_H)
  15. #define SYMTAB_H 1
  16. #include <array>
  17. #include <vector>
  18. #include <string>
  19. #include <set>
  20. #include "gdbsupport/gdb_vecs.h"
  21. #include "gdbtypes.h"
  22. #include "gdbsupport/gdb_obstack.h"
  23. #include "gdbsupport/gdb_regex.h"
  24. #include "gdbsupport/enum-flags.h"
  25. #include "gdbsupport/function-view.h"
  26. #include "gdbsupport/gdb_optional.h"
  27. #include "gdbsupport/gdb_string_view.h"
  28. #include "gdbsupport/next-iterator.h"
  29. #include "gdbsupport/iterator-range.h"
  30. #include "completer.h"
  31. #include "gdb-demangle.h"
  32. /* Opaque declarations. */
  33. struct ui_file;
  34. struct frame_info;
  35. struct symbol;
  36. struct obstack;
  37. struct objfile;
  38. struct block;
  39. struct blockvector;
  40. struct axs_value;
  41. struct agent_expr;
  42. struct program_space;
  43. struct language_defn;
  44. struct common_block;
  45. struct obj_section;
  46. struct cmd_list_element;
  47. class probe;
  48. struct lookup_name_info;
  49. /* How to match a lookup name against a symbol search name. */
  50. enum class symbol_name_match_type
  51. {
  52. /* Wild matching. Matches unqualified symbol names in all
  53. namespace/module/packages, etc. */
  54. WILD,
  55. /* Full matching. The lookup name indicates a fully-qualified name,
  56. and only matches symbol search names in the specified
  57. namespace/module/package. */
  58. FULL,
  59. /* Search name matching. This is like FULL, but the search name did
  60. not come from the user; instead it is already a search name
  61. retrieved from a search_name () call.
  62. For Ada, this avoids re-encoding an already-encoded search name
  63. (which would potentially incorrectly lowercase letters in the
  64. linkage/search name that should remain uppercase). For C++, it
  65. avoids trying to demangle a name we already know is
  66. demangled. */
  67. SEARCH_NAME,
  68. /* Expression matching. The same as FULL matching in most
  69. languages. The same as WILD matching in Ada. */
  70. EXPRESSION,
  71. };
  72. /* Hash the given symbol search name according to LANGUAGE's
  73. rules. */
  74. extern unsigned int search_name_hash (enum language language,
  75. const char *search_name);
  76. /* Ada-specific bits of a lookup_name_info object. This is lazily
  77. constructed on demand. */
  78. class ada_lookup_name_info final
  79. {
  80. public:
  81. /* Construct. */
  82. explicit ada_lookup_name_info (const lookup_name_info &lookup_name);
  83. /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE
  84. as name match type. Returns true if there's a match, false
  85. otherwise. If non-NULL, store the matching results in MATCH. */
  86. bool matches (const char *symbol_search_name,
  87. symbol_name_match_type match_type,
  88. completion_match_result *comp_match_res) const;
  89. /* The Ada-encoded lookup name. */
  90. const std::string &lookup_name () const
  91. { return m_encoded_name; }
  92. /* Return true if we're supposed to be doing a wild match look
  93. up. */
  94. bool wild_match_p () const
  95. { return m_wild_match_p; }
  96. /* Return true if we're looking up a name inside package
  97. Standard. */
  98. bool standard_p () const
  99. { return m_standard_p; }
  100. /* Return true if doing a verbatim match. */
  101. bool verbatim_p () const
  102. { return m_verbatim_p; }
  103. private:
  104. /* The Ada-encoded lookup name. */
  105. std::string m_encoded_name;
  106. /* Whether the user-provided lookup name was Ada encoded. If so,
  107. then return encoded names in the 'matches' method's 'completion
  108. match result' output. */
  109. bool m_encoded_p : 1;
  110. /* True if really doing wild matching. Even if the user requests
  111. wild matching, some cases require full matching. */
  112. bool m_wild_match_p : 1;
  113. /* True if doing a verbatim match. This is true if the decoded
  114. version of the symbol name is wrapped in '<'/'>'. This is an
  115. escape hatch users can use to look up symbols the Ada encoding
  116. does not understand. */
  117. bool m_verbatim_p : 1;
  118. /* True if the user specified a symbol name that is inside package
  119. Standard. Symbol names inside package Standard are handled
  120. specially. We always do a non-wild match of the symbol name
  121. without the "standard__" prefix, and only search static and
  122. global symbols. This was primarily introduced in order to allow
  123. the user to specifically access the standard exceptions using,
  124. for instance, Standard.Constraint_Error when Constraint_Error is
  125. ambiguous (due to the user defining its own Constraint_Error
  126. entity inside its program). */
  127. bool m_standard_p : 1;
  128. };
  129. /* Language-specific bits of a lookup_name_info object, for languages
  130. that do name searching using demangled names (C++/D/Go). This is
  131. lazily constructed on demand. */
  132. struct demangle_for_lookup_info final
  133. {
  134. public:
  135. demangle_for_lookup_info (const lookup_name_info &lookup_name,
  136. language lang);
  137. /* The demangled lookup name. */
  138. const std::string &lookup_name () const
  139. { return m_demangled_name; }
  140. private:
  141. /* The demangled lookup name. */
  142. std::string m_demangled_name;
  143. };
  144. /* Object that aggregates all information related to a symbol lookup
  145. name. I.e., the name that is matched against the symbol's search
  146. name. Caches per-language information so that it doesn't require
  147. recomputing it for every symbol comparison, like for example the
  148. Ada encoded name and the symbol's name hash for a given language.
  149. The object is conceptually immutable once constructed, and thus has
  150. no setters. This is to prevent some code path from tweaking some
  151. property of the lookup name for some local reason and accidentally
  152. altering the results of any continuing search(es).
  153. lookup_name_info objects are generally passed around as a const
  154. reference to reinforce that. (They're not passed around by value
  155. because they're not small.) */
  156. class lookup_name_info final
  157. {
  158. public:
  159. /* We delete this overload so that the callers are required to
  160. explicitly handle the lifetime of the name. */
  161. lookup_name_info (std::string &&name,
  162. symbol_name_match_type match_type,
  163. bool completion_mode = false,
  164. bool ignore_parameters = false) = delete;
  165. /* This overload requires that NAME have a lifetime at least as long
  166. as the lifetime of this object. */
  167. lookup_name_info (const std::string &name,
  168. symbol_name_match_type match_type,
  169. bool completion_mode = false,
  170. bool ignore_parameters = false)
  171. : m_match_type (match_type),
  172. m_completion_mode (completion_mode),
  173. m_ignore_parameters (ignore_parameters),
  174. m_name (name)
  175. {}
  176. /* This overload requires that NAME have a lifetime at least as long
  177. as the lifetime of this object. */
  178. lookup_name_info (const char *name,
  179. symbol_name_match_type match_type,
  180. bool completion_mode = false,
  181. bool ignore_parameters = false)
  182. : m_match_type (match_type),
  183. m_completion_mode (completion_mode),
  184. m_ignore_parameters (ignore_parameters),
  185. m_name (name)
  186. {}
  187. /* Getters. See description of each corresponding field. */
  188. symbol_name_match_type match_type () const { return m_match_type; }
  189. bool completion_mode () const { return m_completion_mode; }
  190. gdb::string_view name () const { return m_name; }
  191. const bool ignore_parameters () const { return m_ignore_parameters; }
  192. /* Like the "name" method but guarantees that the returned string is
  193. \0-terminated. */
  194. const char *c_str () const
  195. {
  196. /* Actually this is always guaranteed due to how the class is
  197. constructed. */
  198. return m_name.data ();
  199. }
  200. /* Return a version of this lookup name that is usable with
  201. comparisons against symbols have no parameter info, such as
  202. psymbols and GDB index symbols. */
  203. lookup_name_info make_ignore_params () const
  204. {
  205. return lookup_name_info (c_str (), m_match_type, m_completion_mode,
  206. true /* ignore params */);
  207. }
  208. /* Get the search name hash for searches in language LANG. */
  209. unsigned int search_name_hash (language lang) const
  210. {
  211. /* Only compute each language's hash once. */
  212. if (!m_demangled_hashes_p[lang])
  213. {
  214. m_demangled_hashes[lang]
  215. = ::search_name_hash (lang, language_lookup_name (lang));
  216. m_demangled_hashes_p[lang] = true;
  217. }
  218. return m_demangled_hashes[lang];
  219. }
  220. /* Get the search name for searches in language LANG. */
  221. const char *language_lookup_name (language lang) const
  222. {
  223. switch (lang)
  224. {
  225. case language_ada:
  226. return ada ().lookup_name ().c_str ();
  227. case language_cplus:
  228. return cplus ().lookup_name ().c_str ();
  229. case language_d:
  230. return d ().lookup_name ().c_str ();
  231. case language_go:
  232. return go ().lookup_name ().c_str ();
  233. default:
  234. return m_name.data ();
  235. }
  236. }
  237. /* Get the Ada-specific lookup info. */
  238. const ada_lookup_name_info &ada () const
  239. {
  240. maybe_init (m_ada);
  241. return *m_ada;
  242. }
  243. /* Get the C++-specific lookup info. */
  244. const demangle_for_lookup_info &cplus () const
  245. {
  246. maybe_init (m_cplus, language_cplus);
  247. return *m_cplus;
  248. }
  249. /* Get the D-specific lookup info. */
  250. const demangle_for_lookup_info &d () const
  251. {
  252. maybe_init (m_d, language_d);
  253. return *m_d;
  254. }
  255. /* Get the Go-specific lookup info. */
  256. const demangle_for_lookup_info &go () const
  257. {
  258. maybe_init (m_go, language_go);
  259. return *m_go;
  260. }
  261. /* Get a reference to a lookup_name_info object that matches any
  262. symbol name. */
  263. static const lookup_name_info &match_any ();
  264. private:
  265. /* Initialize FIELD, if not initialized yet. */
  266. template<typename Field, typename... Args>
  267. void maybe_init (Field &field, Args&&... args) const
  268. {
  269. if (!field)
  270. field.emplace (*this, std::forward<Args> (args)...);
  271. }
  272. /* The lookup info as passed to the ctor. */
  273. symbol_name_match_type m_match_type;
  274. bool m_completion_mode;
  275. bool m_ignore_parameters;
  276. gdb::string_view m_name;
  277. /* Language-specific info. These fields are filled lazily the first
  278. time a lookup is done in the corresponding language. They're
  279. mutable because lookup_name_info objects are typically passed
  280. around by const reference (see intro), and they're conceptually
  281. "cache" that can always be reconstructed from the non-mutable
  282. fields. */
  283. mutable gdb::optional<ada_lookup_name_info> m_ada;
  284. mutable gdb::optional<demangle_for_lookup_info> m_cplus;
  285. mutable gdb::optional<demangle_for_lookup_info> m_d;
  286. mutable gdb::optional<demangle_for_lookup_info> m_go;
  287. /* The demangled hashes. Stored in an array with one entry for each
  288. possible language. The second array records whether we've
  289. already computed the each language's hash. (These are separate
  290. arrays instead of a single array of optional<unsigned> to avoid
  291. alignment padding). */
  292. mutable std::array<unsigned int, nr_languages> m_demangled_hashes;
  293. mutable std::array<bool, nr_languages> m_demangled_hashes_p {};
  294. };
  295. /* Comparison function for completion symbol lookup.
  296. Returns true if the symbol name matches against LOOKUP_NAME.
  297. SYMBOL_SEARCH_NAME should be a symbol's "search" name.
  298. On success and if non-NULL, COMP_MATCH_RES->match is set to point
  299. to the symbol name as should be presented to the user as a
  300. completion match list element. In most languages, this is the same
  301. as the symbol's search name, but in some, like Ada, the display
  302. name is dynamically computed within the comparison routine.
  303. Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd
  304. points the part of SYMBOL_SEARCH_NAME that was considered to match
  305. LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is
  306. "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD
  307. points to "function()" inside SYMBOL_SEARCH_NAME. */
  308. typedef bool (symbol_name_matcher_ftype)
  309. (const char *symbol_search_name,
  310. const lookup_name_info &lookup_name,
  311. completion_match_result *comp_match_res);
  312. /* Some of the structures in this file are space critical.
  313. The space-critical structures are:
  314. struct general_symbol_info
  315. struct symbol
  316. struct partial_symbol
  317. These structures are laid out to encourage good packing.
  318. They use ENUM_BITFIELD and short int fields, and they order the
  319. structure members so that fields less than a word are next
  320. to each other so they can be packed together. */
  321. /* Rearranged: used ENUM_BITFIELD and rearranged field order in
  322. all the space critical structures (plus struct minimal_symbol).
  323. Memory usage dropped from 99360768 bytes to 90001408 bytes.
  324. I measured this with before-and-after tests of
  325. "HEAD-old-gdb -readnow HEAD-old-gdb" and
  326. "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
  327. red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
  328. typing "maint space 1" at the first command prompt.
  329. Here is another measurement (from andrew c):
  330. # no /usr/lib/debug, just plain glibc, like a normal user
  331. gdb HEAD-old-gdb
  332. (gdb) break internal_error
  333. (gdb) run
  334. (gdb) maint internal-error
  335. (gdb) backtrace
  336. (gdb) maint space 1
  337. gdb gdb_6_0_branch 2003-08-19 space used: 8896512
  338. gdb HEAD 2003-08-19 space used: 8904704
  339. gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h)
  340. gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h)
  341. The third line shows the savings from the optimizations in symtab.h.
  342. The fourth line shows the savings from the optimizations in
  343. gdbtypes.h. Both optimizations are in gdb HEAD now.
  344. --chastain 2003-08-21 */
  345. /* Define a structure for the information that is common to all symbol types,
  346. including minimal symbols, partial symbols, and full symbols. In a
  347. multilanguage environment, some language specific information may need to
  348. be recorded along with each symbol. */
  349. /* This structure is space critical. See space comments at the top. */
  350. struct general_symbol_info
  351. {
  352. /* Short version as to when to use which name accessor:
  353. Use natural_name () to refer to the name of the symbol in the original
  354. source code. Use linkage_name () if you want to know what the linker
  355. thinks the symbol's name is. Use print_name () for output. Use
  356. demangled_name () if you specifically need to know whether natural_name ()
  357. and linkage_name () are different. */
  358. const char *linkage_name () const
  359. { return m_name; }
  360. /* Return SYMBOL's "natural" name, i.e. the name that it was called in
  361. the original source code. In languages like C++ where symbols may
  362. be mangled for ease of manipulation by the linker, this is the
  363. demangled name. */
  364. const char *natural_name () const;
  365. /* Returns a version of the name of a symbol that is
  366. suitable for output. In C++ this is the "demangled" form of the
  367. name if demangle is on and the "mangled" form of the name if
  368. demangle is off. In other languages this is just the symbol name.
  369. The result should never be NULL. Don't use this for internal
  370. purposes (e.g. storing in a hashtable): it's only suitable for output. */
  371. const char *print_name () const
  372. { return demangle ? natural_name () : linkage_name (); }
  373. /* Return the demangled name for a symbol based on the language for
  374. that symbol. If no demangled name exists, return NULL. */
  375. const char *demangled_name () const;
  376. /* Returns the name to be used when sorting and searching symbols.
  377. In C++, we search for the demangled form of a name,
  378. and so sort symbols accordingly. In Ada, however, we search by mangled
  379. name. If there is no distinct demangled name, then this
  380. returns the same value (same pointer) as linkage_name (). */
  381. const char *search_name () const;
  382. /* Set just the linkage name of a symbol; do not try to demangle
  383. it. Used for constructs which do not have a mangled name,
  384. e.g. struct tags. Unlike compute_and_set_names, linkage_name must
  385. be terminated and either already on the objfile's obstack or
  386. permanently allocated. */
  387. void set_linkage_name (const char *linkage_name)
  388. { m_name = linkage_name; }
  389. /* Set the demangled name of this symbol to NAME. NAME must be
  390. already correctly allocated. If the symbol's language is Ada,
  391. then the name is ignored and the obstack is set. */
  392. void set_demangled_name (const char *name, struct obstack *obstack);
  393. enum language language () const
  394. { return m_language; }
  395. /* Initializes the language dependent portion of a symbol
  396. depending upon the language for the symbol. */
  397. void set_language (enum language language, struct obstack *obstack);
  398. /* Set the linkage and natural names of a symbol, by demangling
  399. the linkage name. If linkage_name may not be nullterminated,
  400. copy_name must be set to true. */
  401. void compute_and_set_names (gdb::string_view linkage_name, bool copy_name,
  402. struct objfile_per_bfd_storage *per_bfd,
  403. gdb::optional<hashval_t> hash
  404. = gdb::optional<hashval_t> ());
  405. /* Name of the symbol. This is a required field. Storage for the
  406. name is allocated on the objfile_obstack for the associated
  407. objfile. For languages like C++ that make a distinction between
  408. the mangled name and demangled name, this is the mangled
  409. name. */
  410. const char *m_name;
  411. /* Value of the symbol. Which member of this union to use, and what
  412. it means, depends on what kind of symbol this is and its
  413. SYMBOL_CLASS. See comments there for more details. All of these
  414. are in host byte order (though what they point to might be in
  415. target byte order, e.g. LOC_CONST_BYTES). */
  416. union
  417. {
  418. LONGEST ivalue;
  419. const struct block *block;
  420. const gdb_byte *bytes;
  421. CORE_ADDR address;
  422. /* A common block. Used with LOC_COMMON_BLOCK. */
  423. const struct common_block *common_block;
  424. /* For opaque typedef struct chain. */
  425. struct symbol *chain;
  426. }
  427. value;
  428. /* Since one and only one language can apply, wrap the language specific
  429. information inside a union. */
  430. union
  431. {
  432. /* A pointer to an obstack that can be used for storage associated
  433. with this symbol. This is only used by Ada, and only when the
  434. 'ada_mangled' field is zero. */
  435. struct obstack *obstack;
  436. /* This is used by languages which wish to store a demangled name.
  437. currently used by Ada, C++, and Objective C. */
  438. const char *demangled_name;
  439. }
  440. language_specific;
  441. /* Record the source code language that applies to this symbol.
  442. This is used to select one of the fields from the language specific
  443. union above. */
  444. ENUM_BITFIELD(language) m_language : LANGUAGE_BITS;
  445. /* This is only used by Ada. If set, then the 'demangled_name' field
  446. of language_specific is valid. Otherwise, the 'obstack' field is
  447. valid. */
  448. unsigned int ada_mangled : 1;
  449. /* Which section is this symbol in? This is an index into
  450. section_offsets for this objfile. Negative means that the symbol
  451. does not get relocated relative to a section. */
  452. short m_section;
  453. /* Set the index into the obj_section list (within the containing
  454. objfile) for the section that contains this symbol. See M_SECTION
  455. for more details. */
  456. void set_section_index (short idx)
  457. { m_section = idx; }
  458. /* Return the index into the obj_section list (within the containing
  459. objfile) for the section that contains this symbol. See M_SECTION
  460. for more details. */
  461. short section_index () const
  462. { return m_section; }
  463. /* Return the obj_section from OBJFILE for this symbol. The symbol
  464. returned is based on the SECTION member variable, and can be nullptr
  465. if SECTION is negative. */
  466. struct obj_section *obj_section (const struct objfile *objfile) const;
  467. };
  468. extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
  469. /* Return the address of SYM. The MAYBE_COPIED flag must be set on
  470. SYM. If SYM appears in the main program's minimal symbols, then
  471. that minsym's address is returned; otherwise, SYM's address is
  472. returned. This should generally only be used via the
  473. SYMBOL_VALUE_ADDRESS macro. */
  474. extern CORE_ADDR get_symbol_address (const struct symbol *sym);
  475. /* Note that these macros only work with symbol, not partial_symbol. */
  476. #define SYMBOL_VALUE(symbol) (symbol)->value.ivalue
  477. #define SYMBOL_VALUE_ADDRESS(symbol) \
  478. (((symbol)->maybe_copied) ? get_symbol_address (symbol) \
  479. : ((symbol)->value.address))
  480. #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value) \
  481. ((symbol)->value.address = (new_value))
  482. #define SYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
  483. #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
  484. #define SYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
  485. #define SYMBOL_VALUE_CHAIN(symbol) (symbol)->value.chain
  486. /* Try to determine the demangled name for a symbol, based on the
  487. language of that symbol. If the language is set to language_auto,
  488. it will attempt to find any demangling algorithm that works and
  489. then set the language appropriately. The returned name is allocated
  490. by the demangler and should be xfree'd. */
  491. extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name
  492. (struct general_symbol_info *gsymbol, const char *mangled);
  493. /* Return true if NAME matches the "search" name of GSYMBOL, according
  494. to the symbol's language. */
  495. extern bool symbol_matches_search_name
  496. (const struct general_symbol_info *gsymbol,
  497. const lookup_name_info &name);
  498. /* Compute the hash of the given symbol search name of a symbol of
  499. language LANGUAGE. */
  500. extern unsigned int search_name_hash (enum language language,
  501. const char *search_name);
  502. /* Classification types for a minimal symbol. These should be taken as
  503. "advisory only", since if gdb can't easily figure out a
  504. classification it simply selects mst_unknown. It may also have to
  505. guess when it can't figure out which is a better match between two
  506. types (mst_data versus mst_bss) for example. Since the minimal
  507. symbol info is sometimes derived from the BFD library's view of a
  508. file, we need to live with what information bfd supplies. */
  509. enum minimal_symbol_type
  510. {
  511. mst_unknown = 0, /* Unknown type, the default */
  512. mst_text, /* Generally executable instructions */
  513. /* A GNU ifunc symbol, in the .text section. GDB uses to know
  514. whether the user is setting a breakpoint on a GNU ifunc function,
  515. and thus GDB needs to actually set the breakpoint on the target
  516. function. It is also used to know whether the program stepped
  517. into an ifunc resolver -- the resolver may get a separate
  518. symbol/alias under a different name, but it'll have the same
  519. address as the ifunc symbol. */
  520. mst_text_gnu_ifunc, /* Executable code returning address
  521. of executable code */
  522. /* A GNU ifunc function descriptor symbol, in a data section
  523. (typically ".opd"). Seen on architectures that use function
  524. descriptors, like PPC64/ELFv1. In this case, this symbol's value
  525. is the address of the descriptor. There'll be a corresponding
  526. mst_text_gnu_ifunc synthetic symbol for the text/entry
  527. address. */
  528. mst_data_gnu_ifunc, /* Executable code returning address
  529. of executable code */
  530. mst_slot_got_plt, /* GOT entries for .plt sections */
  531. mst_data, /* Generally initialized data */
  532. mst_bss, /* Generally uninitialized data */
  533. mst_abs, /* Generally absolute (nonrelocatable) */
  534. /* GDB uses mst_solib_trampoline for the start address of a shared
  535. library trampoline entry. Breakpoints for shared library functions
  536. are put there if the shared library is not yet loaded.
  537. After the shared library is loaded, lookup_minimal_symbol will
  538. prefer the minimal symbol from the shared library (usually
  539. a mst_text symbol) over the mst_solib_trampoline symbol, and the
  540. breakpoints will be moved to their true address in the shared
  541. library via breakpoint_re_set. */
  542. mst_solib_trampoline, /* Shared library trampoline code */
  543. /* For the mst_file* types, the names are only guaranteed to be unique
  544. within a given .o file. */
  545. mst_file_text, /* Static version of mst_text */
  546. mst_file_data, /* Static version of mst_data */
  547. mst_file_bss, /* Static version of mst_bss */
  548. nr_minsym_types
  549. };
  550. /* The number of enum minimal_symbol_type values, with some padding for
  551. reasonable growth. */
  552. #define MINSYM_TYPE_BITS 4
  553. gdb_static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS));
  554. /* Define a simple structure used to hold some very basic information about
  555. all defined global symbols (text, data, bss, abs, etc). The only required
  556. information is the general_symbol_info.
  557. In many cases, even if a file was compiled with no special options for
  558. debugging at all, as long as was not stripped it will contain sufficient
  559. information to build a useful minimal symbol table using this structure.
  560. Even when a file contains enough debugging information to build a full
  561. symbol table, these minimal symbols are still useful for quickly mapping
  562. between names and addresses, and vice versa. They are also sometimes
  563. used to figure out what full symbol table entries need to be read in. */
  564. struct minimal_symbol : public general_symbol_info
  565. {
  566. /* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
  567. information to calculate the end of the partial symtab based on the
  568. address of the last symbol plus the size of the last symbol. */
  569. unsigned long size;
  570. /* Which source file is this symbol in? Only relevant for mst_file_*. */
  571. const char *filename;
  572. /* Classification type for this minimal symbol. */
  573. ENUM_BITFIELD(minimal_symbol_type) type : MINSYM_TYPE_BITS;
  574. /* Non-zero if this symbol was created by gdb.
  575. Such symbols do not appear in the output of "info var|fun". */
  576. unsigned int created_by_gdb : 1;
  577. /* Two flag bits provided for the use of the target. */
  578. unsigned int target_flag_1 : 1;
  579. unsigned int target_flag_2 : 1;
  580. /* Nonzero iff the size of the minimal symbol has been set.
  581. Symbol size information can sometimes not be determined, because
  582. the object file format may not carry that piece of information. */
  583. unsigned int has_size : 1;
  584. /* For data symbols only, if this is set, then the symbol might be
  585. subject to copy relocation. In this case, a minimal symbol
  586. matching the symbol's linkage name is first looked for in the
  587. main objfile. If found, then that address is used; otherwise the
  588. address in this symbol is used. */
  589. unsigned maybe_copied : 1;
  590. /* Non-zero if this symbol ever had its demangled name set (even if
  591. it was set to NULL). */
  592. unsigned int name_set : 1;
  593. /* Minimal symbols with the same hash key are kept on a linked
  594. list. This is the link. */
  595. struct minimal_symbol *hash_next;
  596. /* Minimal symbols are stored in two different hash tables. This is
  597. the `next' pointer for the demangled hash table. */
  598. struct minimal_symbol *demangled_hash_next;
  599. /* True if this symbol is of some data type. */
  600. bool data_p () const;
  601. /* True if MSYMBOL is of some text type. */
  602. bool text_p () const;
  603. };
  604. /* Return the address of MINSYM, which comes from OBJF. The
  605. MAYBE_COPIED flag must be set on MINSYM. If MINSYM appears in the
  606. main program's minimal symbols, then that minsym's address is
  607. returned; otherwise, MINSYM's address is returned. This should
  608. generally only be used via the MSYMBOL_VALUE_ADDRESS macro. */
  609. extern CORE_ADDR get_msymbol_address (struct objfile *objf,
  610. const struct minimal_symbol *minsym);
  611. #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
  612. #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
  613. #define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
  614. #define SET_MSYMBOL_SIZE(msymbol, sz) \
  615. do \
  616. { \
  617. (msymbol)->size = sz; \
  618. (msymbol)->has_size = 1; \
  619. } while (0)
  620. #define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
  621. #define MSYMBOL_TYPE(msymbol) (msymbol)->type
  622. #define MSYMBOL_VALUE(symbol) (symbol)->value.ivalue
  623. /* The unrelocated address of the minimal symbol. */
  624. #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
  625. /* The relocated address of the minimal symbol, using the section
  626. offsets from OBJFILE. */
  627. #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
  628. (((symbol)->maybe_copied) ? get_msymbol_address (objfile, symbol) \
  629. : ((symbol)->value.address \
  630. + (objfile)->section_offsets[(symbol)->section_index ()]))
  631. /* For a bound minsym, we can easily compute the address directly. */
  632. #define BMSYMBOL_VALUE_ADDRESS(symbol) \
  633. MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
  634. #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
  635. ((symbol)->value.address = (new_value))
  636. #define MSYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
  637. #define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
  638. #include "minsyms.h"
  639. /* Represent one symbol name; a variable, constant, function or typedef. */
  640. /* Different name domains for symbols. Looking up a symbol specifies a
  641. domain and ignores symbol definitions in other name domains. */
  642. typedef enum domain_enum_tag
  643. {
  644. /* UNDEF_DOMAIN is used when a domain has not been discovered or
  645. none of the following apply. This usually indicates an error either
  646. in the symbol information or in gdb's handling of symbols. */
  647. UNDEF_DOMAIN,
  648. /* VAR_DOMAIN is the usual domain. In C, this contains variables,
  649. function names, typedef names and enum type values. */
  650. VAR_DOMAIN,
  651. /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
  652. Thus, if `struct foo' is used in a C program, it produces a symbol named
  653. `foo' in the STRUCT_DOMAIN. */
  654. STRUCT_DOMAIN,
  655. /* MODULE_DOMAIN is used in Fortran to hold module type names. */
  656. MODULE_DOMAIN,
  657. /* LABEL_DOMAIN may be used for names of labels (for gotos). */
  658. LABEL_DOMAIN,
  659. /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN.
  660. They also always use LOC_COMMON_BLOCK. */
  661. COMMON_BLOCK_DOMAIN,
  662. /* This must remain last. */
  663. NR_DOMAINS
  664. } domain_enum;
  665. /* The number of bits in a symbol used to represent the domain. */
  666. #define SYMBOL_DOMAIN_BITS 3
  667. gdb_static_assert (NR_DOMAINS <= (1 << SYMBOL_DOMAIN_BITS));
  668. extern const char *domain_name (domain_enum);
  669. /* Searching domains, used when searching for symbols. Element numbers are
  670. hardcoded in GDB, check all enum uses before changing it. */
  671. enum search_domain
  672. {
  673. /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
  674. TYPES_DOMAIN. */
  675. VARIABLES_DOMAIN = 0,
  676. /* All functions -- for some reason not methods, though. */
  677. FUNCTIONS_DOMAIN = 1,
  678. /* All defined types */
  679. TYPES_DOMAIN = 2,
  680. /* All modules. */
  681. MODULES_DOMAIN = 3,
  682. /* Any type. */
  683. ALL_DOMAIN = 4
  684. };
  685. extern const char *search_domain_name (enum search_domain);
  686. /* An address-class says where to find the value of a symbol. */
  687. enum address_class
  688. {
  689. /* Not used; catches errors. */
  690. LOC_UNDEF,
  691. /* Value is constant int SYMBOL_VALUE, host byteorder. */
  692. LOC_CONST,
  693. /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */
  694. LOC_STATIC,
  695. /* Value is in register. SYMBOL_VALUE is the register number
  696. in the original debug format. SYMBOL_REGISTER_OPS holds a
  697. function that can be called to transform this into the
  698. actual register number this represents in a specific target
  699. architecture (gdbarch).
  700. For some symbol formats (stabs, for some compilers at least),
  701. the compiler generates two symbols, an argument and a register.
  702. In some cases we combine them to a single LOC_REGISTER in symbol
  703. reading, but currently not for all cases (e.g. it's passed on the
  704. stack and then loaded into a register). */
  705. LOC_REGISTER,
  706. /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */
  707. LOC_ARG,
  708. /* Value address is at SYMBOL_VALUE offset in arglist. */
  709. LOC_REF_ARG,
  710. /* Value is in specified register. Just like LOC_REGISTER except the
  711. register holds the address of the argument instead of the argument
  712. itself. This is currently used for the passing of structs and unions
  713. on sparc and hppa. It is also used for call by reference where the
  714. address is in a register, at least by mipsread.c. */
  715. LOC_REGPARM_ADDR,
  716. /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */
  717. LOC_LOCAL,
  718. /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain
  719. STRUCT_DOMAIN all have this class. */
  720. LOC_TYPEDEF,
  721. /* Value is address SYMBOL_VALUE_ADDRESS in the code. */
  722. LOC_LABEL,
  723. /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
  724. In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
  725. of the block. Function names have this class. */
  726. LOC_BLOCK,
  727. /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
  728. target byte order. */
  729. LOC_CONST_BYTES,
  730. /* Value is at fixed address, but the address of the variable has
  731. to be determined from the minimal symbol table whenever the
  732. variable is referenced.
  733. This happens if debugging information for a global symbol is
  734. emitted and the corresponding minimal symbol is defined
  735. in another object file or runtime common storage.
  736. The linker might even remove the minimal symbol if the global
  737. symbol is never referenced, in which case the symbol remains
  738. unresolved.
  739. GDB would normally find the symbol in the minimal symbol table if it will
  740. not find it in the full symbol table. But a reference to an external
  741. symbol in a local block shadowing other definition requires full symbol
  742. without possibly having its address available for LOC_STATIC. Testcase
  743. is provided as `gdb.dwarf2/dw2-unresolved.exp'.
  744. This is also used for thread local storage (TLS) variables. In this case,
  745. the address of the TLS variable must be determined when the variable is
  746. referenced, from the MSYMBOL_VALUE_RAW_ADDRESS, which is the offset
  747. of the TLS variable in the thread local storage of the shared
  748. library/object. */
  749. LOC_UNRESOLVED,
  750. /* The variable does not actually exist in the program.
  751. The value is ignored. */
  752. LOC_OPTIMIZED_OUT,
  753. /* The variable's address is computed by a set of location
  754. functions (see "struct symbol_computed_ops" below). */
  755. LOC_COMPUTED,
  756. /* The variable uses general_symbol_info->value->common_block field.
  757. It also always uses COMMON_BLOCK_DOMAIN. */
  758. LOC_COMMON_BLOCK,
  759. /* Not used, just notes the boundary of the enum. */
  760. LOC_FINAL_VALUE
  761. };
  762. /* The number of bits needed for values in enum address_class, with some
  763. padding for reasonable growth, and room for run-time registered address
  764. classes. See symtab.c:MAX_SYMBOL_IMPLS.
  765. This is a #define so that we can have a assertion elsewhere to
  766. verify that we have reserved enough space for synthetic address
  767. classes. */
  768. #define SYMBOL_ACLASS_BITS 5
  769. gdb_static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS));
  770. /* The methods needed to implement LOC_COMPUTED. These methods can
  771. use the symbol's .aux_value for additional per-symbol information.
  772. At present this is only used to implement location expressions. */
  773. struct symbol_computed_ops
  774. {
  775. /* Return the value of the variable SYMBOL, relative to the stack
  776. frame FRAME. If the variable has been optimized out, return
  777. zero.
  778. Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then
  779. FRAME may be zero. */
  780. struct value *(*read_variable) (struct symbol * symbol,
  781. struct frame_info * frame);
  782. /* Read variable SYMBOL like read_variable at (callee) FRAME's function
  783. entry. SYMBOL should be a function parameter, otherwise
  784. NO_ENTRY_VALUE_ERROR will be thrown. */
  785. struct value *(*read_variable_at_entry) (struct symbol *symbol,
  786. struct frame_info *frame);
  787. /* Find the "symbol_needs_kind" value for the given symbol. This
  788. value determines whether reading the symbol needs memory (e.g., a
  789. global variable), just registers (a thread-local), or a frame (a
  790. local variable). */
  791. enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol);
  792. /* Write to STREAM a natural-language description of the location of
  793. SYMBOL, in the context of ADDR. */
  794. void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
  795. struct ui_file * stream);
  796. /* Non-zero if this symbol's address computation is dependent on PC. */
  797. unsigned char location_has_loclist;
  798. /* Tracepoint support. Append bytecodes to the tracepoint agent
  799. expression AX that push the address of the object SYMBOL. Set
  800. VALUE appropriately. Note --- for objects in registers, this
  801. needn't emit any code; as long as it sets VALUE properly, then
  802. the caller will generate the right code in the process of
  803. treating this as an lvalue or rvalue. */
  804. void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax,
  805. struct axs_value *value);
  806. /* Generate C code to compute the location of SYMBOL. The C code is
  807. emitted to STREAM. GDBARCH is the current architecture and PC is
  808. the PC at which SYMBOL's location should be evaluated.
  809. REGISTERS_USED is a vector indexed by register number; the
  810. generator function should set an element in this vector if the
  811. corresponding register is needed by the location computation.
  812. The generated C code must assign the location to a local
  813. variable; this variable's name is RESULT_NAME. */
  814. void (*generate_c_location) (struct symbol *symbol, string_file *stream,
  815. struct gdbarch *gdbarch,
  816. std::vector<bool> &registers_used,
  817. CORE_ADDR pc, const char *result_name);
  818. };
  819. /* The methods needed to implement LOC_BLOCK for inferior functions.
  820. These methods can use the symbol's .aux_value for additional
  821. per-symbol information. */
  822. struct symbol_block_ops
  823. {
  824. /* Fill in *START and *LENGTH with DWARF block data of function
  825. FRAMEFUNC valid for inferior context address PC. Set *LENGTH to
  826. zero if such location is not valid for PC; *START is left
  827. uninitialized in such case. */
  828. void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc,
  829. const gdb_byte **start, size_t *length);
  830. /* Return the frame base address. FRAME is the frame for which we want to
  831. compute the base address while FRAMEFUNC is the symbol for the
  832. corresponding function. Return 0 on failure (FRAMEFUNC may not hold the
  833. information we need).
  834. This method is designed to work with static links (nested functions
  835. handling). Static links are function properties whose evaluation returns
  836. the frame base address for the enclosing frame. However, there are
  837. multiple definitions for "frame base": the content of the frame base
  838. register, the CFA as defined by DWARF unwinding information, ...
  839. So this specific method is supposed to compute the frame base address such
  840. as for nested functions, the static link computes the same address. For
  841. instance, considering DWARF debugging information, the static link is
  842. computed with DW_AT_static_link and this method must be used to compute
  843. the corresponding DW_AT_frame_base attribute. */
  844. CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
  845. struct frame_info *frame);
  846. };
  847. /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */
  848. struct symbol_register_ops
  849. {
  850. int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
  851. };
  852. /* Objects of this type are used to find the address class and the
  853. various computed ops vectors of a symbol. */
  854. struct symbol_impl
  855. {
  856. enum address_class aclass;
  857. /* Used with LOC_COMPUTED. */
  858. const struct symbol_computed_ops *ops_computed;
  859. /* Used with LOC_BLOCK. */
  860. const struct symbol_block_ops *ops_block;
  861. /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */
  862. const struct symbol_register_ops *ops_register;
  863. };
  864. /* struct symbol has some subclasses. This enum is used to
  865. differentiate between them. */
  866. enum symbol_subclass_kind
  867. {
  868. /* Plain struct symbol. */
  869. SYMBOL_NONE,
  870. /* struct template_symbol. */
  871. SYMBOL_TEMPLATE,
  872. /* struct rust_vtable_symbol. */
  873. SYMBOL_RUST_VTABLE
  874. };
  875. extern const struct symbol_impl *symbol_impls;
  876. /* This structure is space critical. See space comments at the top. */
  877. struct symbol : public general_symbol_info, public allocate_on_obstack
  878. {
  879. symbol ()
  880. /* Class-initialization of bitfields is only allowed in C++20. */
  881. : m_domain (UNDEF_DOMAIN),
  882. m_aclass_index (0),
  883. m_is_objfile_owned (1),
  884. m_is_argument (0),
  885. m_is_inlined (0),
  886. maybe_copied (0),
  887. subclass (SYMBOL_NONE),
  888. artificial (false)
  889. {
  890. /* We can't use an initializer list for members of a base class, and
  891. general_symbol_info needs to stay a POD type. */
  892. m_name = nullptr;
  893. value.ivalue = 0;
  894. language_specific.obstack = nullptr;
  895. m_language = language_unknown;
  896. ada_mangled = 0;
  897. m_section = -1;
  898. /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
  899. initialization of unions, so we initialize it manually here. */
  900. owner.symtab = nullptr;
  901. }
  902. symbol (const symbol &) = default;
  903. symbol &operator= (const symbol &) = default;
  904. unsigned int aclass_index () const
  905. {
  906. return m_aclass_index;
  907. }
  908. void set_aclass_index (unsigned int aclass_index)
  909. {
  910. m_aclass_index = aclass_index;
  911. }
  912. const symbol_impl &impl () const
  913. {
  914. return symbol_impls[this->aclass_index ()];
  915. }
  916. address_class aclass () const
  917. {
  918. return this->impl ().aclass;
  919. }
  920. domain_enum domain () const
  921. {
  922. return m_domain;
  923. }
  924. void set_domain (domain_enum domain)
  925. {
  926. m_domain = domain;
  927. }
  928. bool is_objfile_owned () const
  929. {
  930. return m_is_objfile_owned;
  931. }
  932. void set_is_objfile_owned (bool is_objfile_owned)
  933. {
  934. m_is_objfile_owned = is_objfile_owned;
  935. }
  936. bool is_argument () const
  937. {
  938. return m_is_argument;
  939. }
  940. void set_is_argument (bool is_argument)
  941. {
  942. m_is_argument = is_argument;
  943. }
  944. bool is_inlined () const
  945. {
  946. return m_is_inlined;
  947. }
  948. void set_is_inlined (bool is_inlined)
  949. {
  950. m_is_inlined = is_inlined;
  951. }
  952. bool is_cplus_template_function () const
  953. {
  954. return this->subclass == SYMBOL_TEMPLATE;
  955. }
  956. struct type *type () const
  957. {
  958. return m_type;
  959. }
  960. void set_type (struct type *type)
  961. {
  962. m_type = type;
  963. }
  964. unsigned short line () const
  965. {
  966. return m_line;
  967. }
  968. void set_line (unsigned short line)
  969. {
  970. m_line = line;
  971. }
  972. /* Data type of value */
  973. struct type *m_type = nullptr;
  974. /* The owner of this symbol.
  975. Which one to use is defined by symbol.is_objfile_owned. */
  976. union
  977. {
  978. /* The symbol table containing this symbol. This is the file associated
  979. with LINE. It can be NULL during symbols read-in but it is never NULL
  980. during normal operation. */
  981. struct symtab *symtab;
  982. /* For types defined by the architecture. */
  983. struct gdbarch *arch;
  984. } owner;
  985. /* Domain code. */
  986. ENUM_BITFIELD(domain_enum_tag) m_domain : SYMBOL_DOMAIN_BITS;
  987. /* Address class. This holds an index into the 'symbol_impls'
  988. table. The actual enum address_class value is stored there,
  989. alongside any per-class ops vectors. */
  990. unsigned int m_aclass_index : SYMBOL_ACLASS_BITS;
  991. /* If non-zero then symbol is objfile-owned, use owner.symtab.
  992. Otherwise symbol is arch-owned, use owner.arch. */
  993. unsigned int m_is_objfile_owned : 1;
  994. /* Whether this is an argument. */
  995. unsigned m_is_argument : 1;
  996. /* Whether this is an inlined function (class LOC_BLOCK only). */
  997. unsigned m_is_inlined : 1;
  998. /* For LOC_STATIC only, if this is set, then the symbol might be
  999. subject to copy relocation. In this case, a minimal symbol
  1000. matching the symbol's linkage name is first looked for in the
  1001. main objfile. If found, then that address is used; otherwise the
  1002. address in this symbol is used. */
  1003. unsigned maybe_copied : 1;
  1004. /* The concrete type of this symbol. */
  1005. ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
  1006. /* Whether this symbol is artificial. */
  1007. bool artificial : 1;
  1008. /* Line number of this symbol's definition, except for inlined
  1009. functions. For an inlined function (class LOC_BLOCK and
  1010. SYMBOL_INLINED set) this is the line number of the function's call
  1011. site. Inlined function symbols are not definitions, and they are
  1012. never found by symbol table lookup.
  1013. If this symbol is arch-owned, LINE shall be zero.
  1014. FIXME: Should we really make the assumption that nobody will try
  1015. to debug files longer than 64K lines? What about machine
  1016. generated programs? */
  1017. unsigned short m_line = 0;
  1018. /* An arbitrary data pointer, allowing symbol readers to record
  1019. additional information on a per-symbol basis. Note that this data
  1020. must be allocated using the same obstack as the symbol itself. */
  1021. /* So far it is only used by:
  1022. LOC_COMPUTED: to find the location information
  1023. LOC_BLOCK (DWARF2 function): information used internally by the
  1024. DWARF 2 code --- specifically, the location expression for the frame
  1025. base for this function. */
  1026. /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
  1027. to add a magic symbol to the block containing this information,
  1028. or to have a generic debug info annotation slot for symbols. */
  1029. void *aux_value = nullptr;
  1030. struct symbol *hash_next = nullptr;
  1031. };
  1032. /* Several lookup functions return both a symbol and the block in which the
  1033. symbol is found. This structure is used in these cases. */
  1034. struct block_symbol
  1035. {
  1036. /* The symbol that was found, or NULL if no symbol was found. */
  1037. struct symbol *symbol;
  1038. /* If SYMBOL is not NULL, then this is the block in which the symbol is
  1039. defined. */
  1040. const struct block *block;
  1041. };
  1042. /* Note: There is no accessor macro for symbol.owner because it is
  1043. "private". */
  1044. #define SYMBOL_COMPUTED_OPS(symbol) ((symbol)->impl ().ops_computed)
  1045. #define SYMBOL_BLOCK_OPS(symbol) ((symbol)->impl ().ops_block)
  1046. #define SYMBOL_REGISTER_OPS(symbol) ((symbol)->impl ().ops_register)
  1047. #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value
  1048. extern int register_symbol_computed_impl (enum address_class,
  1049. const struct symbol_computed_ops *);
  1050. extern int register_symbol_block_impl (enum address_class aclass,
  1051. const struct symbol_block_ops *ops);
  1052. extern int register_symbol_register_impl (enum address_class,
  1053. const struct symbol_register_ops *);
  1054. /* Return the OBJFILE of SYMBOL.
  1055. It is an error to call this if symbol.is_objfile_owned is false, which
  1056. only happens for architecture-provided types. */
  1057. extern struct objfile *symbol_objfile (const struct symbol *symbol);
  1058. /* Return the ARCH of SYMBOL. */
  1059. extern struct gdbarch *symbol_arch (const struct symbol *symbol);
  1060. /* Return the SYMTAB of SYMBOL.
  1061. It is an error to call this if symbol.is_objfile_owned is false, which
  1062. only happens for architecture-provided types. */
  1063. extern struct symtab *symbol_symtab (const struct symbol *symbol);
  1064. /* Set the symtab of SYMBOL to SYMTAB.
  1065. It is an error to call this if symbol.is_objfile_owned is false, which
  1066. only happens for architecture-provided types. */
  1067. extern void symbol_set_symtab (struct symbol *symbol, struct symtab *symtab);
  1068. /* An instance of this type is used to represent a C++ template
  1069. function. A symbol is really of this type iff
  1070. symbol::is_cplus_template_function is true. */
  1071. struct template_symbol : public symbol
  1072. {
  1073. /* The number of template arguments. */
  1074. int n_template_arguments = 0;
  1075. /* The template arguments. This is an array with
  1076. N_TEMPLATE_ARGUMENTS elements. */
  1077. struct symbol **template_arguments = nullptr;
  1078. };
  1079. /* A symbol that represents a Rust virtual table object. */
  1080. struct rust_vtable_symbol : public symbol
  1081. {
  1082. /* The concrete type for which this vtable was created; that is, in
  1083. "impl Trait for Type", this is "Type". */
  1084. struct type *concrete_type = nullptr;
  1085. };
  1086. /* Each item represents a line-->pc (or the reverse) mapping. This is
  1087. somewhat more wasteful of space than one might wish, but since only
  1088. the files which are actually debugged are read in to core, we don't
  1089. waste much space. */
  1090. struct linetable_entry
  1091. {
  1092. /* The line number for this entry. */
  1093. int line;
  1094. /* True if this PC is a good location to place a breakpoint for LINE. */
  1095. unsigned is_stmt : 1;
  1096. /* True if this location is a good location to place a breakpoint after a
  1097. function prologue. */
  1098. bool prologue_end : 1;
  1099. /* The address for this entry. */
  1100. CORE_ADDR pc;
  1101. };
  1102. /* The order of entries in the linetable is significant. They should
  1103. be sorted by increasing values of the pc field. If there is more than
  1104. one entry for a given pc, then I'm not sure what should happen (and
  1105. I not sure whether we currently handle it the best way).
  1106. Example: a C for statement generally looks like this
  1107. 10 0x100 - for the init/test part of a for stmt.
  1108. 20 0x200
  1109. 30 0x300
  1110. 10 0x400 - for the increment part of a for stmt.
  1111. If an entry has a line number of zero, it marks the start of a PC
  1112. range for which no line number information is available. It is
  1113. acceptable, though wasteful of table space, for such a range to be
  1114. zero length. */
  1115. struct linetable
  1116. {
  1117. int nitems;
  1118. /* Actually NITEMS elements. If you don't like this use of the
  1119. `struct hack', you can shove it up your ANSI (seriously, if the
  1120. committee tells us how to do it, we can probably go along). */
  1121. struct linetable_entry item[1];
  1122. };
  1123. /* How to relocate the symbols from each section in a symbol file.
  1124. The ordering and meaning of the offsets is file-type-dependent;
  1125. typically it is indexed by section numbers or symbol types or
  1126. something like that. */
  1127. typedef std::vector<CORE_ADDR> section_offsets;
  1128. /* Each source file or header is represented by a struct symtab.
  1129. The name "symtab" is historical, another name for it is "filetab".
  1130. These objects are chained through the `next' field. */
  1131. struct symtab
  1132. {
  1133. struct compunit_symtab *compunit () const
  1134. {
  1135. return m_compunit;
  1136. }
  1137. void set_compunit (struct compunit_symtab *compunit)
  1138. {
  1139. m_compunit = compunit;
  1140. }
  1141. struct linetable *linetable () const
  1142. {
  1143. return m_linetable;
  1144. }
  1145. void set_linetable (struct linetable *linetable)
  1146. {
  1147. m_linetable = linetable;
  1148. }
  1149. enum language language () const
  1150. {
  1151. return m_language;
  1152. }
  1153. void set_language (enum language language)
  1154. {
  1155. m_language = language;
  1156. }
  1157. /* Unordered chain of all filetabs in the compunit, with the exception
  1158. that the "main" source file is the first entry in the list. */
  1159. struct symtab *next;
  1160. /* Backlink to containing compunit symtab. */
  1161. struct compunit_symtab *m_compunit;
  1162. /* Table mapping core addresses to line numbers for this file.
  1163. Can be NULL if none. Never shared between different symtabs. */
  1164. struct linetable *m_linetable;
  1165. /* Name of this source file. This pointer is never NULL. */
  1166. const char *filename;
  1167. /* Language of this source file. */
  1168. enum language m_language;
  1169. /* Full name of file as found by searching the source path.
  1170. NULL if not yet known. */
  1171. char *fullname;
  1172. };
  1173. /* A range adapter to allowing iterating over all the file tables in a list. */
  1174. using symtab_range = next_range<symtab>;
  1175. /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
  1176. as the list of all source files (what gdb has historically associated with
  1177. the term "symtab").
  1178. Additional information is recorded here that is common to all symtabs in a
  1179. compilation unit (DWARF or otherwise).
  1180. Example:
  1181. For the case of a program built out of these files:
  1182. foo.c
  1183. foo1.h
  1184. foo2.h
  1185. bar.c
  1186. foo1.h
  1187. bar.h
  1188. This is recorded as:
  1189. objfile -> foo.c(cu) -> bar.c(cu) -> NULL
  1190. | |
  1191. v v
  1192. foo.c bar.c
  1193. | |
  1194. v v
  1195. foo1.h foo1.h
  1196. | |
  1197. v v
  1198. foo2.h bar.h
  1199. | |
  1200. v v
  1201. NULL NULL
  1202. where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects,
  1203. and the files foo.c, etc. are struct symtab objects. */
  1204. struct compunit_symtab
  1205. {
  1206. struct objfile *objfile () const
  1207. {
  1208. return m_objfile;
  1209. }
  1210. void set_objfile (struct objfile *objfile)
  1211. {
  1212. m_objfile = objfile;
  1213. }
  1214. symtab_range filetabs () const
  1215. {
  1216. return symtab_range (m_filetabs);
  1217. }
  1218. void add_filetab (symtab *filetab)
  1219. {
  1220. if (m_filetabs == nullptr)
  1221. {
  1222. m_filetabs = filetab;
  1223. m_last_filetab = filetab;
  1224. }
  1225. else
  1226. {
  1227. m_last_filetab->next = filetab;
  1228. m_last_filetab = filetab;
  1229. }
  1230. }
  1231. const char *debugformat () const
  1232. {
  1233. return m_debugformat;
  1234. }
  1235. void set_debugformat (const char *debugformat)
  1236. {
  1237. m_debugformat = debugformat;
  1238. }
  1239. const char *producer () const
  1240. {
  1241. return m_producer;
  1242. }
  1243. void set_producer (const char *producer)
  1244. {
  1245. m_producer = producer;
  1246. }
  1247. const char *dirname () const
  1248. {
  1249. return m_dirname;
  1250. }
  1251. void set_dirname (const char *dirname)
  1252. {
  1253. m_dirname = dirname;
  1254. }
  1255. const struct blockvector *blockvector () const
  1256. {
  1257. return m_blockvector;
  1258. }
  1259. void set_blockvector (const struct blockvector *blockvector)
  1260. {
  1261. m_blockvector = blockvector;
  1262. }
  1263. int block_line_section () const
  1264. {
  1265. return m_block_line_section;
  1266. }
  1267. void set_block_line_section (int block_line_section)
  1268. {
  1269. m_block_line_section = block_line_section;
  1270. }
  1271. bool locations_valid () const
  1272. {
  1273. return m_locations_valid;
  1274. }
  1275. void set_locations_valid (bool locations_valid)
  1276. {
  1277. m_locations_valid = locations_valid;
  1278. }
  1279. bool epilogue_unwind_valid () const
  1280. {
  1281. return m_epilogue_unwind_valid;
  1282. }
  1283. void set_epilogue_unwind_valid (bool epilogue_unwind_valid)
  1284. {
  1285. m_epilogue_unwind_valid = epilogue_unwind_valid;
  1286. }
  1287. struct macro_table *macro_table () const
  1288. {
  1289. return m_macro_table;
  1290. }
  1291. void set_macro_table (struct macro_table *macro_table)
  1292. {
  1293. m_macro_table = macro_table;
  1294. }
  1295. /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
  1296. PRIMARY_FILETAB must already be a filetab of this compunit symtab. */
  1297. void set_primary_filetab (symtab *primary_filetab);
  1298. /* Return the primary filetab of the compunit. */
  1299. symtab *primary_filetab () const;
  1300. /* Set m_call_site_htab. */
  1301. void set_call_site_htab (htab_t call_site_htab);
  1302. /* Find call_site info for PC. */
  1303. call_site *find_call_site (CORE_ADDR pc) const;
  1304. /* Unordered chain of all compunit symtabs of this objfile. */
  1305. struct compunit_symtab *next;
  1306. /* Object file from which this symtab information was read. */
  1307. struct objfile *m_objfile;
  1308. /* Name of the symtab.
  1309. This is *not* intended to be a usable filename, and is
  1310. for debugging purposes only. */
  1311. const char *name;
  1312. /* Unordered list of file symtabs, except that by convention the "main"
  1313. source file (e.g., .c, .cc) is guaranteed to be first.
  1314. Each symtab is a file, either the "main" source file (e.g., .c, .cc)
  1315. or header (e.g., .h). */
  1316. symtab *m_filetabs;
  1317. /* Last entry in FILETABS list.
  1318. Subfiles are added to the end of the list so they accumulate in order,
  1319. with the main source subfile living at the front.
  1320. The main reason is so that the main source file symtab is at the head
  1321. of the list, and the rest appear in order for debugging convenience. */
  1322. symtab *m_last_filetab;
  1323. /* Non-NULL string that identifies the format of the debugging information,
  1324. such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful
  1325. for automated testing of gdb but may also be information that is
  1326. useful to the user. */
  1327. const char *m_debugformat;
  1328. /* String of producer version information, or NULL if we don't know. */
  1329. const char *m_producer;
  1330. /* Directory in which it was compiled, or NULL if we don't know. */
  1331. const char *m_dirname;
  1332. /* List of all symbol scope blocks for this symtab. It is shared among
  1333. all symtabs in a given compilation unit. */
  1334. const struct blockvector *m_blockvector;
  1335. /* Section in objfile->section_offsets for the blockvector and
  1336. the linetable. Probably always SECT_OFF_TEXT. */
  1337. int m_block_line_section;
  1338. /* Symtab has been compiled with both optimizations and debug info so that
  1339. GDB may stop skipping prologues as variables locations are valid already
  1340. at function entry points. */
  1341. unsigned int m_locations_valid : 1;
  1342. /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
  1343. instruction). This is supported by GCC since 4.5.0. */
  1344. unsigned int m_epilogue_unwind_valid : 1;
  1345. /* struct call_site entries for this compilation unit or NULL. */
  1346. htab_t m_call_site_htab;
  1347. /* The macro table for this symtab. Like the blockvector, this
  1348. is shared between different symtabs in a given compilation unit.
  1349. It's debatable whether it *should* be shared among all the symtabs in
  1350. the given compilation unit, but it currently is. */
  1351. struct macro_table *m_macro_table;
  1352. /* If non-NULL, then this points to a NULL-terminated vector of
  1353. included compunits. When searching the static or global
  1354. block of this compunit, the corresponding block of all
  1355. included compunits will also be searched. Note that this
  1356. list must be flattened -- the symbol reader is responsible for
  1357. ensuring that this vector contains the transitive closure of all
  1358. included compunits. */
  1359. struct compunit_symtab **includes;
  1360. /* If this is an included compunit, this points to one includer
  1361. of the table. This user is considered the canonical compunit
  1362. containing this one. An included compunit may itself be
  1363. included by another. */
  1364. struct compunit_symtab *user;
  1365. };
  1366. using compunit_symtab_range = next_range<compunit_symtab>;
  1367. /* Return the language of CUST. */
  1368. extern enum language compunit_language (const struct compunit_symtab *cust);
  1369. /* Return true if this symtab is the "main" symtab of its compunit_symtab. */
  1370. static inline bool
  1371. is_main_symtab_of_compunit_symtab (struct symtab *symtab)
  1372. {
  1373. return symtab == symtab->compunit ()->primary_filetab ();
  1374. }
  1375. /* The virtual function table is now an array of structures which have the
  1376. form { int16 offset, delta; void *pfn; }.
  1377. In normal virtual function tables, OFFSET is unused.
  1378. DELTA is the amount which is added to the apparent object's base
  1379. address in order to point to the actual object to which the
  1380. virtual function should be applied.
  1381. PFN is a pointer to the virtual function.
  1382. Note that this macro is g++ specific (FIXME). */
  1383. #define VTBL_FNADDR_OFFSET 2
  1384. /* External variables and functions for the objects described above. */
  1385. /* True if we are nested inside psymtab_to_symtab. */
  1386. extern int currently_reading_symtab;
  1387. /* symtab.c lookup functions */
  1388. extern const char multiple_symbols_ask[];
  1389. extern const char multiple_symbols_all[];
  1390. extern const char multiple_symbols_cancel[];
  1391. const char *multiple_symbols_select_mode (void);
  1392. bool symbol_matches_domain (enum language symbol_language,
  1393. domain_enum symbol_domain,
  1394. domain_enum domain);
  1395. /* lookup a symbol table by source file name. */
  1396. extern struct symtab *lookup_symtab (const char *);
  1397. /* An object of this type is passed as the 'is_a_field_of_this'
  1398. argument to lookup_symbol and lookup_symbol_in_language. */
  1399. struct field_of_this_result
  1400. {
  1401. /* The type in which the field was found. If this is NULL then the
  1402. symbol was not found in 'this'. If non-NULL, then one of the
  1403. other fields will be non-NULL as well. */
  1404. struct type *type;
  1405. /* If the symbol was found as an ordinary field of 'this', then this
  1406. is non-NULL and points to the particular field. */
  1407. struct field *field;
  1408. /* If the symbol was found as a function field of 'this', then this
  1409. is non-NULL and points to the particular field. */
  1410. struct fn_fieldlist *fn_field;
  1411. };
  1412. /* Find the definition for a specified symbol name NAME
  1413. in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
  1414. if non-NULL or from global/static blocks if BLOCK is NULL.
  1415. Returns the struct symbol pointer, or NULL if no symbol is found.
  1416. C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
  1417. NAME is a field of the current implied argument `this'. If so fill in the
  1418. fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL.
  1419. The symbol's section is fixed up if necessary. */
  1420. extern struct block_symbol
  1421. lookup_symbol_in_language (const char *,
  1422. const struct block *,
  1423. const domain_enum,
  1424. enum language,
  1425. struct field_of_this_result *);
  1426. /* Same as lookup_symbol_in_language, but using the current language. */
  1427. extern struct block_symbol lookup_symbol (const char *,
  1428. const struct block *,
  1429. const domain_enum,
  1430. struct field_of_this_result *);
  1431. /* Find the definition for a specified symbol search name in domain
  1432. DOMAIN, visible from lexical block BLOCK if non-NULL or from
  1433. global/static blocks if BLOCK is NULL. The passed-in search name
  1434. should not come from the user; instead it should already be a
  1435. search name as retrieved from a search_name () call. See definition of
  1436. symbol_name_match_type::SEARCH_NAME. Returns the struct symbol
  1437. pointer, or NULL if no symbol is found. The symbol's section is
  1438. fixed up if necessary. */
  1439. extern struct block_symbol lookup_symbol_search_name (const char *search_name,
  1440. const struct block *block,
  1441. domain_enum domain);
  1442. /* Some helper functions for languages that need to write their own
  1443. lookup_symbol_nonlocal functions. */
  1444. /* Lookup a symbol in the static block associated to BLOCK, if there
  1445. is one; do nothing if BLOCK is NULL or a global block.
  1446. Upon success fixes up the symbol's section if necessary. */
  1447. extern struct block_symbol
  1448. lookup_symbol_in_static_block (const char *name,
  1449. const struct block *block,
  1450. const domain_enum domain);
  1451. /* Search all static file-level symbols for NAME from DOMAIN.
  1452. Upon success fixes up the symbol's section if necessary. */
  1453. extern struct block_symbol lookup_static_symbol (const char *name,
  1454. const domain_enum domain);
  1455. /* Lookup a symbol in all files' global blocks.
  1456. If BLOCK is non-NULL then it is used for two things:
  1457. 1) If a target-specific lookup routine for libraries exists, then use the
  1458. routine for the objfile of BLOCK, and
  1459. 2) The objfile of BLOCK is used to assist in determining the search order
  1460. if the target requires it.
  1461. See gdbarch_iterate_over_objfiles_in_search_order.
  1462. Upon success fixes up the symbol's section if necessary. */
  1463. extern struct block_symbol
  1464. lookup_global_symbol (const char *name,
  1465. const struct block *block,
  1466. const domain_enum domain);
  1467. /* Lookup a symbol in block BLOCK.
  1468. Upon success fixes up the symbol's section if necessary. */
  1469. extern struct symbol *
  1470. lookup_symbol_in_block (const char *name,
  1471. symbol_name_match_type match_type,
  1472. const struct block *block,
  1473. const domain_enum domain);
  1474. /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if
  1475. found, or NULL if not found. */
  1476. extern struct block_symbol
  1477. lookup_language_this (const struct language_defn *lang,
  1478. const struct block *block);
  1479. /* Lookup a [struct, union, enum] by name, within a specified block. */
  1480. extern struct type *lookup_struct (const char *, const struct block *);
  1481. extern struct type *lookup_union (const char *, const struct block *);
  1482. extern struct type *lookup_enum (const char *, const struct block *);
  1483. /* from blockframe.c: */
  1484. /* lookup the function symbol corresponding to the address. The
  1485. return value will not be an inlined function; the containing
  1486. function will be returned instead. */
  1487. extern struct symbol *find_pc_function (CORE_ADDR);
  1488. /* lookup the function corresponding to the address and section. The
  1489. return value will not be an inlined function; the containing
  1490. function will be returned instead. */
  1491. extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
  1492. /* lookup the function symbol corresponding to the address and
  1493. section. The return value will be the closest enclosing function,
  1494. which might be an inline function. */
  1495. extern struct symbol *find_pc_sect_containing_function
  1496. (CORE_ADDR pc, struct obj_section *section);
  1497. /* Find the symbol at the given address. Returns NULL if no symbol
  1498. found. Only exact matches for ADDRESS are considered. */
  1499. extern struct symbol *find_symbol_at_address (CORE_ADDR);
  1500. /* Finds the "function" (text symbol) that is smaller than PC but
  1501. greatest of all of the potential text symbols in SECTION. Sets
  1502. *NAME and/or *ADDRESS conditionally if that pointer is non-null.
  1503. If ENDADDR is non-null, then set *ENDADDR to be the end of the
  1504. function (exclusive). If the optional parameter BLOCK is non-null,
  1505. then set *BLOCK to the address of the block corresponding to the
  1506. function symbol, if such a symbol could be found during the lookup;
  1507. nullptr is used as a return value for *BLOCK if no block is found.
  1508. This function either succeeds or fails (not halfway succeeds). If
  1509. it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
  1510. information and returns true. If it fails, it sets *NAME, *ADDRESS
  1511. and *ENDADDR to zero and returns false.
  1512. If the function in question occupies non-contiguous ranges,
  1513. *ADDRESS and *ENDADDR are (subject to the conditions noted above) set
  1514. to the start and end of the range in which PC is found. Thus
  1515. *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges
  1516. from other functions might be found).
  1517. This property allows find_pc_partial_function to be used (as it had
  1518. been prior to the introduction of non-contiguous range support) by
  1519. various tdep files for finding a start address and limit address
  1520. for prologue analysis. This still isn't ideal, however, because we
  1521. probably shouldn't be doing prologue analysis (in which
  1522. instructions are scanned to determine frame size and stack layout)
  1523. for any range that doesn't contain the entry pc. Moreover, a good
  1524. argument can be made that prologue analysis ought to be performed
  1525. starting from the entry pc even when PC is within some other range.
  1526. This might suggest that *ADDRESS and *ENDADDR ought to be set to the
  1527. limits of the entry pc range, but that will cause the
  1528. *ADDRESS <= PC < *ENDADDR condition to be violated; many of the
  1529. callers of find_pc_partial_function expect this condition to hold.
  1530. Callers which require the start and/or end addresses for the range
  1531. containing the entry pc should instead call
  1532. find_function_entry_range_from_pc. */
  1533. extern bool find_pc_partial_function (CORE_ADDR pc, const char **name,
  1534. CORE_ADDR *address, CORE_ADDR *endaddr,
  1535. const struct block **block = nullptr);
  1536. /* Like find_pc_partial_function, above, but returns the underlying
  1537. general_symbol_info (rather than the name) as an out parameter. */
  1538. extern bool find_pc_partial_function_sym
  1539. (CORE_ADDR pc, const general_symbol_info **sym,
  1540. CORE_ADDR *address, CORE_ADDR *endaddr,
  1541. const struct block **block = nullptr);
  1542. /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
  1543. set to start and end addresses of the range containing the entry pc.
  1544. Note that it is not necessarily the case that (for non-NULL ADDRESS
  1545. and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will
  1546. hold.
  1547. See comment for find_pc_partial_function, above, for further
  1548. explanation. */
  1549. extern bool find_function_entry_range_from_pc (CORE_ADDR pc,
  1550. const char **name,
  1551. CORE_ADDR *address,
  1552. CORE_ADDR *endaddr);
  1553. /* Return the type of a function with its first instruction exactly at
  1554. the PC address. Return NULL otherwise. */
  1555. extern struct type *find_function_type (CORE_ADDR pc);
  1556. /* See if we can figure out the function's actual type from the type
  1557. that the resolver returns. RESOLVER_FUNADDR is the address of the
  1558. ifunc resolver. */
  1559. extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr);
  1560. /* Find the GNU ifunc minimal symbol that matches SYM. */
  1561. extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym);
  1562. extern void clear_pc_function_cache (void);
  1563. /* Expand symtab containing PC, SECTION if not already expanded. */
  1564. extern void expand_symtab_containing_pc (CORE_ADDR, struct obj_section *);
  1565. /* lookup full symbol table by address. */
  1566. extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR);
  1567. /* lookup full symbol table by address and section. */
  1568. extern struct compunit_symtab *
  1569. find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
  1570. extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
  1571. extern void reread_symbols (int from_tty);
  1572. /* Look up a type named NAME in STRUCT_DOMAIN in the current language.
  1573. The type returned must not be opaque -- i.e., must have at least one field
  1574. defined. */
  1575. extern struct type *lookup_transparent_type (const char *);
  1576. extern struct type *basic_lookup_transparent_type (const char *);
  1577. /* Macro for name of symbol to indicate a file compiled with gcc. */
  1578. #ifndef GCC_COMPILED_FLAG_SYMBOL
  1579. #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
  1580. #endif
  1581. /* Macro for name of symbol to indicate a file compiled with gcc2. */
  1582. #ifndef GCC2_COMPILED_FLAG_SYMBOL
  1583. #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
  1584. #endif
  1585. extern bool in_gnu_ifunc_stub (CORE_ADDR pc);
  1586. /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
  1587. for ELF symbol files. */
  1588. struct gnu_ifunc_fns
  1589. {
  1590. /* See elf_gnu_ifunc_resolve_addr for its real implementation. */
  1591. CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
  1592. /* See elf_gnu_ifunc_resolve_name for its real implementation. */
  1593. bool (*gnu_ifunc_resolve_name) (const char *function_name,
  1594. CORE_ADDR *function_address_p);
  1595. /* See elf_gnu_ifunc_resolver_stop for its real implementation. */
  1596. void (*gnu_ifunc_resolver_stop) (struct breakpoint *b);
  1597. /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */
  1598. void (*gnu_ifunc_resolver_return_stop) (struct breakpoint *b);
  1599. };
  1600. #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
  1601. #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
  1602. #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
  1603. #define gnu_ifunc_resolver_return_stop \
  1604. gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
  1605. extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
  1606. extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR);
  1607. struct symtab_and_line
  1608. {
  1609. /* The program space of this sal. */
  1610. struct program_space *pspace = NULL;
  1611. struct symtab *symtab = NULL;
  1612. struct symbol *symbol = NULL;
  1613. struct obj_section *section = NULL;
  1614. struct minimal_symbol *msymbol = NULL;
  1615. /* Line number. Line numbers start at 1 and proceed through symtab->nlines.
  1616. 0 is never a valid line number; it is used to indicate that line number
  1617. information is not available. */
  1618. int line = 0;
  1619. CORE_ADDR pc = 0;
  1620. CORE_ADDR end = 0;
  1621. bool explicit_pc = false;
  1622. bool explicit_line = false;
  1623. /* If the line number information is valid, then this indicates if this
  1624. line table entry had the is-stmt flag set or not. */
  1625. bool is_stmt = false;
  1626. /* The probe associated with this symtab_and_line. */
  1627. probe *prob = NULL;
  1628. /* If PROBE is not NULL, then this is the objfile in which the probe
  1629. originated. */
  1630. struct objfile *objfile = NULL;
  1631. };
  1632. /* Given a pc value, return line number it is in. Second arg nonzero means
  1633. if pc is on the boundary use the previous statement's line number. */
  1634. extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
  1635. /* Same function, but specify a section as well as an address. */
  1636. extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
  1637. struct obj_section *, int);
  1638. /* Wrapper around find_pc_line to just return the symtab. */
  1639. extern struct symtab *find_pc_line_symtab (CORE_ADDR);
  1640. /* Given a symtab and line number, return the pc there. */
  1641. extern bool find_line_pc (struct symtab *, int, CORE_ADDR *);
  1642. extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
  1643. CORE_ADDR *);
  1644. extern void resolve_sal_pc (struct symtab_and_line *);
  1645. /* solib.c */
  1646. extern void clear_solib (void);
  1647. /* The reason we're calling into a completion match list collector
  1648. function. */
  1649. enum class complete_symbol_mode
  1650. {
  1651. /* Completing an expression. */
  1652. EXPRESSION,
  1653. /* Completing a linespec. */
  1654. LINESPEC,
  1655. };
  1656. extern void default_collect_symbol_completion_matches_break_on
  1657. (completion_tracker &tracker,
  1658. complete_symbol_mode mode,
  1659. symbol_name_match_type name_match_type,
  1660. const char *text, const char *word, const char *break_on,
  1661. enum type_code code);
  1662. extern void collect_symbol_completion_matches
  1663. (completion_tracker &tracker,
  1664. complete_symbol_mode mode,
  1665. symbol_name_match_type name_match_type,
  1666. const char *, const char *);
  1667. extern void collect_symbol_completion_matches_type (completion_tracker &tracker,
  1668. const char *, const char *,
  1669. enum type_code);
  1670. extern void collect_file_symbol_completion_matches
  1671. (completion_tracker &tracker,
  1672. complete_symbol_mode,
  1673. symbol_name_match_type name_match_type,
  1674. const char *, const char *, const char *);
  1675. extern completion_list
  1676. make_source_files_completion_list (const char *, const char *);
  1677. /* Return whether SYM is a function/method, as opposed to a data symbol. */
  1678. extern bool symbol_is_function_or_method (symbol *sym);
  1679. /* Return whether MSYMBOL is a function/method, as opposed to a data
  1680. symbol */
  1681. extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
  1682. /* Return whether SYM should be skipped in completion mode MODE. In
  1683. linespec mode, we're only interested in functions/methods. */
  1684. template<typename Symbol>
  1685. static bool
  1686. completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
  1687. {
  1688. return (mode == complete_symbol_mode::LINESPEC
  1689. && !symbol_is_function_or_method (sym));
  1690. }
  1691. /* symtab.c */
  1692. bool matching_obj_sections (struct obj_section *, struct obj_section *);
  1693. extern struct symtab *find_line_symtab (struct symtab *, int, int *, bool *);
  1694. /* Given a function symbol SYM, find the symtab and line for the start
  1695. of the function. If FUNFIRSTLINE is true, we want the first line
  1696. of real code inside the function. */
  1697. extern symtab_and_line find_function_start_sal (symbol *sym, bool
  1698. funfirstline);
  1699. /* Same, but start with a function address/section instead of a
  1700. symbol. */
  1701. extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr,
  1702. obj_section *section,
  1703. bool funfirstline);
  1704. extern void skip_prologue_sal (struct symtab_and_line *);
  1705. /* symtab.c */
  1706. extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
  1707. CORE_ADDR func_addr);
  1708. extern struct symbol *fixup_symbol_section (struct symbol *,
  1709. struct objfile *);
  1710. /* If MSYMBOL is an text symbol, look for a function debug symbol with
  1711. the same address. Returns NULL if not found. This is necessary in
  1712. case a function is an alias to some other function, because debug
  1713. information is only emitted for the alias target function's
  1714. definition, not for the alias. */
  1715. extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
  1716. /* Symbol searching */
  1717. /* When using the symbol_searcher struct to search for symbols, a vector of
  1718. the following structs is returned. */
  1719. struct symbol_search
  1720. {
  1721. symbol_search (int block_, struct symbol *symbol_)
  1722. : block (block_),
  1723. symbol (symbol_)
  1724. {
  1725. msymbol.minsym = nullptr;
  1726. msymbol.objfile = nullptr;
  1727. }
  1728. symbol_search (int block_, struct minimal_symbol *minsym,
  1729. struct objfile *objfile)
  1730. : block (block_),
  1731. symbol (nullptr)
  1732. {
  1733. msymbol.minsym = minsym;
  1734. msymbol.objfile = objfile;
  1735. }
  1736. bool operator< (const symbol_search &other) const
  1737. {
  1738. return compare_search_syms (*this, other) < 0;
  1739. }
  1740. bool operator== (const symbol_search &other) const
  1741. {
  1742. return compare_search_syms (*this, other) == 0;
  1743. }
  1744. /* The block in which the match was found. Could be, for example,
  1745. STATIC_BLOCK or GLOBAL_BLOCK. */
  1746. int block;
  1747. /* Information describing what was found.
  1748. If symbol is NOT NULL, then information was found for this match. */
  1749. struct symbol *symbol;
  1750. /* If msymbol is non-null, then a match was made on something for
  1751. which only minimal_symbols exist. */
  1752. struct bound_minimal_symbol msymbol;
  1753. private:
  1754. static int compare_search_syms (const symbol_search &sym_a,
  1755. const symbol_search &sym_b);
  1756. };
  1757. /* In order to search for global symbols of a particular kind matching
  1758. particular regular expressions, create an instance of this structure and
  1759. call the SEARCH member function. */
  1760. class global_symbol_searcher
  1761. {
  1762. public:
  1763. /* Constructor. */
  1764. global_symbol_searcher (enum search_domain kind,
  1765. const char *symbol_name_regexp)
  1766. : m_kind (kind),
  1767. m_symbol_name_regexp (symbol_name_regexp)
  1768. {
  1769. /* The symbol searching is designed to only find one kind of thing. */
  1770. gdb_assert (m_kind != ALL_DOMAIN);
  1771. }
  1772. /* Set the optional regexp that matches against the symbol type. */
  1773. void set_symbol_type_regexp (const char *regexp)
  1774. {
  1775. m_symbol_type_regexp = regexp;
  1776. }
  1777. /* Set the flag to exclude minsyms from the search results. */
  1778. void set_exclude_minsyms (bool exclude_minsyms)
  1779. {
  1780. m_exclude_minsyms = exclude_minsyms;
  1781. }
  1782. /* Set the maximum number of search results to be returned. */
  1783. void set_max_search_results (size_t max_search_results)
  1784. {
  1785. m_max_search_results = max_search_results;
  1786. }
  1787. /* Search the symbols from all objfiles in the current program space
  1788. looking for matches as defined by the current state of this object.
  1789. Within each file the results are sorted locally; each symtab's global
  1790. and static blocks are separately alphabetized. Duplicate entries are
  1791. removed. */
  1792. std::vector<symbol_search> search () const;
  1793. /* The set of source files to search in for matching symbols. This is
  1794. currently public so that it can be populated after this object has
  1795. been constructed. */
  1796. std::vector<const char *> filenames;
  1797. private:
  1798. /* The kind of symbols are we searching for.
  1799. VARIABLES_DOMAIN - Search all symbols, excluding functions, type
  1800. names, and constants (enums).
  1801. FUNCTIONS_DOMAIN - Search all functions..
  1802. TYPES_DOMAIN - Search all type names.
  1803. MODULES_DOMAIN - Search all Fortran modules.
  1804. ALL_DOMAIN - Not valid for this function. */
  1805. enum search_domain m_kind;
  1806. /* Regular expression to match against the symbol name. */
  1807. const char *m_symbol_name_regexp = nullptr;
  1808. /* Regular expression to match against the symbol type. */
  1809. const char *m_symbol_type_regexp = nullptr;
  1810. /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will
  1811. be included in the results, otherwise they are excluded. */
  1812. bool m_exclude_minsyms = false;
  1813. /* Maximum number of search results. We currently impose a hard limit
  1814. of SIZE_MAX, there is no "unlimited". */
  1815. size_t m_max_search_results = SIZE_MAX;
  1816. /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return
  1817. true if any msymbols were seen that we should later consider adding to
  1818. the results list. */
  1819. bool expand_symtabs (objfile *objfile,
  1820. const gdb::optional<compiled_regex> &preg) const;
  1821. /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are
  1822. of type M_KIND, to the results set RESULTS_SET. Return false if we
  1823. stop adding results early due to having already found too many results
  1824. (based on M_MAX_SEARCH_RESULTS limit), otherwise return true.
  1825. Returning true does not indicate that any results were added, just
  1826. that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
  1827. bool add_matching_symbols (objfile *objfile,
  1828. const gdb::optional<compiled_regex> &preg,
  1829. const gdb::optional<compiled_regex> &treg,
  1830. std::set<symbol_search> *result_set) const;
  1831. /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results
  1832. vector RESULTS. Return false if we stop adding results early due to
  1833. having already found too many results (based on max search results
  1834. limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true
  1835. does not indicate that any results were added, just that we didn't
  1836. _not_ add a result due to reaching MAX_SEARCH_RESULTS. */
  1837. bool add_matching_msymbols (objfile *objfile,
  1838. const gdb::optional<compiled_regex> &preg,
  1839. std::vector<symbol_search> *results) const;
  1840. /* Return true if MSYMBOL is of type KIND. */
  1841. static bool is_suitable_msymbol (const enum search_domain kind,
  1842. const minimal_symbol *msymbol);
  1843. };
  1844. /* When searching for Fortran symbols within modules (functions/variables)
  1845. we return a vector of this type. The first item in the pair is the
  1846. module symbol, and the second item is the symbol for the function or
  1847. variable we found. */
  1848. typedef std::pair<symbol_search, symbol_search> module_symbol_search;
  1849. /* Searches the symbols to find function and variables symbols (depending
  1850. on KIND) within Fortran modules. The MODULE_REGEXP matches against the
  1851. name of the module, REGEXP matches against the name of the symbol within
  1852. the module, and TYPE_REGEXP matches against the type of the symbol
  1853. within the module. */
  1854. extern std::vector<module_symbol_search> search_module_symbols
  1855. (const char *module_regexp, const char *regexp,
  1856. const char *type_regexp, search_domain kind);
  1857. /* Convert a global or static symbol SYM (based on BLOCK, which should be
  1858. either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
  1859. type commands (e.g. 'info variables', 'info functions', etc). KIND is
  1860. the type of symbol that was searched for which gave us SYM. */
  1861. extern std::string symbol_to_info_string (struct symbol *sym, int block,
  1862. enum search_domain kind);
  1863. extern bool treg_matches_sym_type_name (const compiled_regex &treg,
  1864. const struct symbol *sym);
  1865. /* The name of the ``main'' function. */
  1866. extern const char *main_name ();
  1867. extern enum language main_language (void);
  1868. /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
  1869. as specified by BLOCK_INDEX.
  1870. This searches MAIN_OBJFILE as well as any associated separate debug info
  1871. objfiles of MAIN_OBJFILE.
  1872. BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
  1873. Upon success fixes up the symbol's section if necessary. */
  1874. extern struct block_symbol
  1875. lookup_global_symbol_from_objfile (struct objfile *main_objfile,
  1876. enum block_enum block_index,
  1877. const char *name,
  1878. const domain_enum domain);
  1879. /* Return 1 if the supplied producer string matches the ARM RealView
  1880. compiler (armcc). */
  1881. bool producer_is_realview (const char *producer);
  1882. void fixup_section (struct general_symbol_info *ginfo,
  1883. CORE_ADDR addr, struct objfile *objfile);
  1884. extern unsigned int symtab_create_debug;
  1885. extern unsigned int symbol_lookup_debug;
  1886. extern bool basenames_may_differ;
  1887. bool compare_filenames_for_search (const char *filename,
  1888. const char *search_name);
  1889. bool compare_glob_filenames_for_search (const char *filename,
  1890. const char *search_name);
  1891. bool iterate_over_some_symtabs (const char *name,
  1892. const char *real_path,
  1893. struct compunit_symtab *first,
  1894. struct compunit_symtab *after_last,
  1895. gdb::function_view<bool (symtab *)> callback);
  1896. void iterate_over_symtabs (const char *name,
  1897. gdb::function_view<bool (symtab *)> callback);
  1898. std::vector<CORE_ADDR> find_pcs_for_symtab_line
  1899. (struct symtab *symtab, int line, struct linetable_entry **best_entry);
  1900. /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
  1901. is called once per matching symbol SYM. The callback should return
  1902. true to indicate that LA_ITERATE_OVER_SYMBOLS should continue
  1903. iterating, or false to indicate that the iteration should end. */
  1904. typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
  1905. /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
  1906. For each symbol that matches, CALLBACK is called. The symbol is
  1907. passed to the callback.
  1908. If CALLBACK returns false, the iteration ends and this function
  1909. returns false. Otherwise, the search continues, and the function
  1910. eventually returns true. */
  1911. bool iterate_over_symbols (const struct block *block,
  1912. const lookup_name_info &name,
  1913. const domain_enum domain,
  1914. gdb::function_view<symbol_found_callback_ftype> callback);
  1915. /* Like iterate_over_symbols, but if all calls to CALLBACK return
  1916. true, then calls CALLBACK one additional time with a block_symbol
  1917. that has a valid block but a NULL symbol. */
  1918. bool iterate_over_symbols_terminated
  1919. (const struct block *block,
  1920. const lookup_name_info &name,
  1921. const domain_enum domain,
  1922. gdb::function_view<symbol_found_callback_ftype> callback);
  1923. /* Storage type used by demangle_for_lookup. demangle_for_lookup
  1924. either returns a const char * pointer that points to either of the
  1925. fields of this type, or a pointer to the input NAME. This is done
  1926. this way to avoid depending on the precise details of the storage
  1927. for the string. */
  1928. class demangle_result_storage
  1929. {
  1930. public:
  1931. /* Swap the malloc storage to STR, and return a pointer to the
  1932. beginning of the new string. */
  1933. const char *set_malloc_ptr (gdb::unique_xmalloc_ptr<char> &&str)
  1934. {
  1935. m_malloc = std::move (str);
  1936. return m_malloc.get ();
  1937. }
  1938. /* Set the malloc storage to now point at PTR. Any previous malloc
  1939. storage is released. */
  1940. const char *set_malloc_ptr (char *ptr)
  1941. {
  1942. m_malloc.reset (ptr);
  1943. return ptr;
  1944. }
  1945. private:
  1946. /* The storage. */
  1947. gdb::unique_xmalloc_ptr<char> m_malloc;
  1948. };
  1949. const char *
  1950. demangle_for_lookup (const char *name, enum language lang,
  1951. demangle_result_storage &storage);
  1952. /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
  1953. SYMNAME (which is already demangled for C++ symbols) matches
  1954. SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to
  1955. the current completion list and return true. Otherwise, return
  1956. false. */
  1957. bool completion_list_add_name (completion_tracker &tracker,
  1958. language symbol_language,
  1959. const char *symname,
  1960. const lookup_name_info &lookup_name,
  1961. const char *text, const char *word);
  1962. /* A simple symbol searching class. */
  1963. class symbol_searcher
  1964. {
  1965. public:
  1966. /* Returns the symbols found for the search. */
  1967. const std::vector<block_symbol> &
  1968. matching_symbols () const
  1969. {
  1970. return m_symbols;
  1971. }
  1972. /* Returns the minimal symbols found for the search. */
  1973. const std::vector<bound_minimal_symbol> &
  1974. matching_msymbols () const
  1975. {
  1976. return m_minimal_symbols;
  1977. }
  1978. /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
  1979. search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
  1980. to search all symtabs and program spaces. */
  1981. void find_all_symbols (const std::string &name,
  1982. const struct language_defn *language,
  1983. enum search_domain search_domain,
  1984. std::vector<symtab *> *search_symtabs,
  1985. struct program_space *search_pspace);
  1986. /* Reset this object to perform another search. */
  1987. void reset ()
  1988. {
  1989. m_symbols.clear ();
  1990. m_minimal_symbols.clear ();
  1991. }
  1992. private:
  1993. /* Matching debug symbols. */
  1994. std::vector<block_symbol> m_symbols;
  1995. /* Matching non-debug symbols. */
  1996. std::vector<bound_minimal_symbol> m_minimal_symbols;
  1997. };
  1998. /* Class used to encapsulate the filename filtering for the "info sources"
  1999. command. */
  2000. struct info_sources_filter
  2001. {
  2002. /* If filename filtering is being used (see M_C_REGEXP) then which part
  2003. of the filename is being filtered against? */
  2004. enum class match_on
  2005. {
  2006. /* Match against the full filename. */
  2007. FULLNAME,
  2008. /* Match only against the directory part of the full filename. */
  2009. DIRNAME,
  2010. /* Match only against the basename part of the full filename. */
  2011. BASENAME
  2012. };
  2013. /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
  2014. REGEXP is nullptr then all files will match the filter and MATCH_TYPE
  2015. is ignored.
  2016. The string pointed too by REGEXP must remain live and unchanged for
  2017. this lifetime of this object as the object only retains a copy of the
  2018. pointer. */
  2019. info_sources_filter (match_on match_type, const char *regexp);
  2020. DISABLE_COPY_AND_ASSIGN (info_sources_filter);
  2021. /* Does FULLNAME match the filter defined by this object, return true if
  2022. it does, otherwise, return false. If there is no filtering defined
  2023. then this function will always return true. */
  2024. bool matches (const char *fullname) const;
  2025. private:
  2026. /* The type of filtering in place. */
  2027. match_on m_match_type;
  2028. /* Points to the original regexp used to create this filter. */
  2029. const char *m_regexp;
  2030. /* A compiled version of M_REGEXP. This object is only given a value if
  2031. M_REGEXP is not nullptr and is not the empty string. */
  2032. gdb::optional<compiled_regex> m_c_regexp;
  2033. };
  2034. /* Perform the core of the 'info sources' command.
  2035. FILTER is used to perform regular expression based filtering on the
  2036. source files that will be displayed.
  2037. Output is written to UIOUT in CLI or MI style as appropriate. */
  2038. extern void info_sources_worker (struct ui_out *uiout,
  2039. bool group_by_objfile,
  2040. const info_sources_filter &filter);
  2041. #endif /* !defined(SYMTAB_H) */