1 1.1 christos /* Symbol table definitions for GDB. 2 1.1 christos 3 1.11 christos Copyright (C) 1986-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.12 christos #ifndef GDB_SYMTAB_H 21 1.12 christos #define GDB_SYMTAB_H 22 1.1 christos 23 1.8 christos #include <array> 24 1.7 christos #include <vector> 25 1.8 christos #include <string> 26 1.9 christos #include <set> 27 1.12 christos #include "dwarf2/call-site.h" 28 1.1 christos #include "gdbtypes.h" 29 1.10 christos #include "gdbsupport/gdb_obstack.h" 30 1.10 christos #include "gdbsupport/gdb_regex.h" 31 1.9 christos #include "gdbsupport/enum-flags.h" 32 1.9 christos #include "gdbsupport/function-view.h" 33 1.11 christos #include <optional> 34 1.11 christos #include <string_view> 35 1.9 christos #include "gdbsupport/next-iterator.h" 36 1.10 christos #include "gdbsupport/iterator-range.h" 37 1.8 christos #include "completer.h" 38 1.9 christos #include "gdb-demangle.h" 39 1.10 christos #include "split-name.h" 40 1.11 christos #include "frame.h" 41 1.11 christos #include <optional> 42 1.1 christos 43 1.1 christos /* Opaque declarations. */ 44 1.1 christos struct ui_file; 45 1.10 christos class frame_info_ptr; 46 1.1 christos struct symbol; 47 1.1 christos struct obstack; 48 1.1 christos struct objfile; 49 1.1 christos struct block; 50 1.1 christos struct blockvector; 51 1.1 christos struct axs_value; 52 1.1 christos struct agent_expr; 53 1.1 christos struct program_space; 54 1.1 christos struct language_defn; 55 1.1 christos struct common_block; 56 1.6 christos struct obj_section; 57 1.6 christos struct cmd_list_element; 58 1.8 christos class probe; 59 1.8 christos struct lookup_name_info; 60 1.10 christos struct code_breakpoint; 61 1.8 christos 62 1.8 christos /* How to match a lookup name against a symbol search name. */ 63 1.8 christos enum class symbol_name_match_type 64 1.8 christos { 65 1.8 christos /* Wild matching. Matches unqualified symbol names in all 66 1.8 christos namespace/module/packages, etc. */ 67 1.8 christos WILD, 68 1.8 christos 69 1.8 christos /* Full matching. The lookup name indicates a fully-qualified name, 70 1.8 christos and only matches symbol search names in the specified 71 1.8 christos namespace/module/package. */ 72 1.8 christos FULL, 73 1.8 christos 74 1.8 christos /* Search name matching. This is like FULL, but the search name did 75 1.8 christos not come from the user; instead it is already a search name 76 1.9 christos retrieved from a search_name () call. 77 1.8 christos For Ada, this avoids re-encoding an already-encoded search name 78 1.8 christos (which would potentially incorrectly lowercase letters in the 79 1.8 christos linkage/search name that should remain uppercase). For C++, it 80 1.8 christos avoids trying to demangle a name we already know is 81 1.8 christos demangled. */ 82 1.8 christos SEARCH_NAME, 83 1.8 christos 84 1.8 christos /* Expression matching. The same as FULL matching in most 85 1.8 christos languages. The same as WILD matching in Ada. */ 86 1.8 christos EXPRESSION, 87 1.8 christos }; 88 1.8 christos 89 1.8 christos /* Hash the given symbol search name according to LANGUAGE's 90 1.8 christos rules. */ 91 1.8 christos extern unsigned int search_name_hash (enum language language, 92 1.8 christos const char *search_name); 93 1.8 christos 94 1.8 christos /* Ada-specific bits of a lookup_name_info object. This is lazily 95 1.8 christos constructed on demand. */ 96 1.8 christos 97 1.8 christos class ada_lookup_name_info final 98 1.8 christos { 99 1.8 christos public: 100 1.8 christos /* Construct. */ 101 1.8 christos explicit ada_lookup_name_info (const lookup_name_info &lookup_name); 102 1.8 christos 103 1.8 christos /* Compare SYMBOL_SEARCH_NAME with our lookup name, using MATCH_TYPE 104 1.8 christos as name match type. Returns true if there's a match, false 105 1.8 christos otherwise. If non-NULL, store the matching results in MATCH. */ 106 1.8 christos bool matches (const char *symbol_search_name, 107 1.8 christos symbol_name_match_type match_type, 108 1.8 christos completion_match_result *comp_match_res) const; 109 1.8 christos 110 1.8 christos /* The Ada-encoded lookup name. */ 111 1.8 christos const std::string &lookup_name () const 112 1.8 christos { return m_encoded_name; } 113 1.8 christos 114 1.8 christos /* Return true if we're supposed to be doing a wild match look 115 1.8 christos up. */ 116 1.8 christos bool wild_match_p () const 117 1.8 christos { return m_wild_match_p; } 118 1.8 christos 119 1.8 christos /* Return true if we're looking up a name inside package 120 1.8 christos Standard. */ 121 1.8 christos bool standard_p () const 122 1.8 christos { return m_standard_p; } 123 1.8 christos 124 1.8 christos /* Return true if doing a verbatim match. */ 125 1.8 christos bool verbatim_p () const 126 1.8 christos { return m_verbatim_p; } 127 1.8 christos 128 1.10 christos /* A wrapper for ::split_name that handles some Ada-specific 129 1.10 christos peculiarities. */ 130 1.11 christos std::vector<std::string_view> split_name () const 131 1.10 christos { 132 1.11 christos if (m_verbatim_p) 133 1.10 christos { 134 1.11 christos /* For verbatim matches, just return the encoded name 135 1.11 christos as-is. */ 136 1.11 christos std::vector<std::string_view> result; 137 1.10 christos result.emplace_back (m_encoded_name); 138 1.10 christos return result; 139 1.10 christos } 140 1.11 christos /* Otherwise, split the decoded name for matching. */ 141 1.11 christos return ::split_name (m_decoded_name.c_str (), split_style::DOT_STYLE); 142 1.10 christos } 143 1.10 christos 144 1.8 christos private: 145 1.8 christos /* The Ada-encoded lookup name. */ 146 1.8 christos std::string m_encoded_name; 147 1.8 christos 148 1.11 christos /* The decoded lookup name. This is formed by calling ada_decode 149 1.11 christos with both 'operators' and 'wide' set to false. */ 150 1.11 christos std::string m_decoded_name; 151 1.11 christos 152 1.8 christos /* Whether the user-provided lookup name was Ada encoded. If so, 153 1.8 christos then return encoded names in the 'matches' method's 'completion 154 1.8 christos match result' output. */ 155 1.8 christos bool m_encoded_p : 1; 156 1.8 christos 157 1.8 christos /* True if really doing wild matching. Even if the user requests 158 1.8 christos wild matching, some cases require full matching. */ 159 1.8 christos bool m_wild_match_p : 1; 160 1.8 christos 161 1.8 christos /* True if doing a verbatim match. This is true if the decoded 162 1.8 christos version of the symbol name is wrapped in '<'/'>'. This is an 163 1.8 christos escape hatch users can use to look up symbols the Ada encoding 164 1.8 christos does not understand. */ 165 1.8 christos bool m_verbatim_p : 1; 166 1.8 christos 167 1.8 christos /* True if the user specified a symbol name that is inside package 168 1.8 christos Standard. Symbol names inside package Standard are handled 169 1.8 christos specially. We always do a non-wild match of the symbol name 170 1.8 christos without the "standard__" prefix, and only search static and 171 1.8 christos global symbols. This was primarily introduced in order to allow 172 1.8 christos the user to specifically access the standard exceptions using, 173 1.8 christos for instance, Standard.Constraint_Error when Constraint_Error is 174 1.8 christos ambiguous (due to the user defining its own Constraint_Error 175 1.8 christos entity inside its program). */ 176 1.8 christos bool m_standard_p : 1; 177 1.8 christos }; 178 1.8 christos 179 1.8 christos /* Language-specific bits of a lookup_name_info object, for languages 180 1.8 christos that do name searching using demangled names (C++/D/Go). This is 181 1.8 christos lazily constructed on demand. */ 182 1.8 christos 183 1.8 christos struct demangle_for_lookup_info final 184 1.8 christos { 185 1.8 christos public: 186 1.8 christos demangle_for_lookup_info (const lookup_name_info &lookup_name, 187 1.8 christos language lang); 188 1.8 christos 189 1.8 christos /* The demangled lookup name. */ 190 1.8 christos const std::string &lookup_name () const 191 1.8 christos { return m_demangled_name; } 192 1.8 christos 193 1.8 christos private: 194 1.8 christos /* The demangled lookup name. */ 195 1.8 christos std::string m_demangled_name; 196 1.8 christos }; 197 1.8 christos 198 1.8 christos /* Object that aggregates all information related to a symbol lookup 199 1.8 christos name. I.e., the name that is matched against the symbol's search 200 1.8 christos name. Caches per-language information so that it doesn't require 201 1.8 christos recomputing it for every symbol comparison, like for example the 202 1.8 christos Ada encoded name and the symbol's name hash for a given language. 203 1.8 christos The object is conceptually immutable once constructed, and thus has 204 1.8 christos no setters. This is to prevent some code path from tweaking some 205 1.8 christos property of the lookup name for some local reason and accidentally 206 1.8 christos altering the results of any continuing search(es). 207 1.8 christos lookup_name_info objects are generally passed around as a const 208 1.8 christos reference to reinforce that. (They're not passed around by value 209 1.8 christos because they're not small.) */ 210 1.8 christos class lookup_name_info final 211 1.8 christos { 212 1.8 christos public: 213 1.9 christos /* We delete this overload so that the callers are required to 214 1.9 christos explicitly handle the lifetime of the name. */ 215 1.9 christos lookup_name_info (std::string &&name, 216 1.9 christos symbol_name_match_type match_type, 217 1.9 christos bool completion_mode = false, 218 1.9 christos bool ignore_parameters = false) = delete; 219 1.9 christos 220 1.9 christos /* This overload requires that NAME have a lifetime at least as long 221 1.9 christos as the lifetime of this object. */ 222 1.9 christos lookup_name_info (const std::string &name, 223 1.9 christos symbol_name_match_type match_type, 224 1.9 christos bool completion_mode = false, 225 1.9 christos bool ignore_parameters = false) 226 1.9 christos : m_match_type (match_type), 227 1.9 christos m_completion_mode (completion_mode), 228 1.9 christos m_ignore_parameters (ignore_parameters), 229 1.9 christos m_name (name) 230 1.9 christos {} 231 1.9 christos 232 1.9 christos /* This overload requires that NAME have a lifetime at least as long 233 1.9 christos as the lifetime of this object. */ 234 1.9 christos lookup_name_info (const char *name, 235 1.8 christos symbol_name_match_type match_type, 236 1.8 christos bool completion_mode = false, 237 1.8 christos bool ignore_parameters = false) 238 1.8 christos : m_match_type (match_type), 239 1.8 christos m_completion_mode (completion_mode), 240 1.8 christos m_ignore_parameters (ignore_parameters), 241 1.9 christos m_name (name) 242 1.8 christos {} 243 1.8 christos 244 1.8 christos /* Getters. See description of each corresponding field. */ 245 1.8 christos symbol_name_match_type match_type () const { return m_match_type; } 246 1.8 christos bool completion_mode () const { return m_completion_mode; } 247 1.11 christos std::string_view name () const { return m_name; } 248 1.8 christos const bool ignore_parameters () const { return m_ignore_parameters; } 249 1.8 christos 250 1.9 christos /* Like the "name" method but guarantees that the returned string is 251 1.9 christos \0-terminated. */ 252 1.9 christos const char *c_str () const 253 1.9 christos { 254 1.9 christos /* Actually this is always guaranteed due to how the class is 255 1.9 christos constructed. */ 256 1.9 christos return m_name.data (); 257 1.9 christos } 258 1.9 christos 259 1.8 christos /* Return a version of this lookup name that is usable with 260 1.8 christos comparisons against symbols have no parameter info, such as 261 1.8 christos psymbols and GDB index symbols. */ 262 1.8 christos lookup_name_info make_ignore_params () const 263 1.8 christos { 264 1.9 christos return lookup_name_info (c_str (), m_match_type, m_completion_mode, 265 1.8 christos true /* ignore params */); 266 1.8 christos } 267 1.8 christos 268 1.8 christos /* Get the search name hash for searches in language LANG. */ 269 1.12 christos unsigned int search_name_hash (language lang) const; 270 1.8 christos 271 1.8 christos /* Get the search name for searches in language LANG. */ 272 1.9 christos const char *language_lookup_name (language lang) const 273 1.8 christos { 274 1.8 christos switch (lang) 275 1.8 christos { 276 1.8 christos case language_ada: 277 1.9 christos return ada ().lookup_name ().c_str (); 278 1.8 christos case language_cplus: 279 1.9 christos return cplus ().lookup_name ().c_str (); 280 1.8 christos case language_d: 281 1.9 christos return d ().lookup_name ().c_str (); 282 1.8 christos case language_go: 283 1.9 christos return go ().lookup_name ().c_str (); 284 1.8 christos default: 285 1.9 christos return m_name.data (); 286 1.8 christos } 287 1.8 christos } 288 1.8 christos 289 1.10 christos /* A wrapper for ::split_name (see split-name.h) that splits this 290 1.10 christos name, and that handles any language-specific peculiarities. */ 291 1.11 christos std::vector<std::string_view> split_name (language lang) const 292 1.10 christos { 293 1.10 christos if (lang == language_ada) 294 1.10 christos return ada ().split_name (); 295 1.10 christos split_style style = split_style::NONE; 296 1.10 christos switch (lang) 297 1.10 christos { 298 1.10 christos case language_cplus: 299 1.10 christos case language_rust: 300 1.10 christos style = split_style::CXX; 301 1.10 christos break; 302 1.10 christos case language_d: 303 1.10 christos case language_go: 304 1.11 christos style = split_style::DOT_STYLE; 305 1.10 christos break; 306 1.10 christos } 307 1.10 christos return ::split_name (language_lookup_name (lang), style); 308 1.10 christos } 309 1.10 christos 310 1.8 christos /* Get the Ada-specific lookup info. */ 311 1.8 christos const ada_lookup_name_info &ada () const 312 1.8 christos { 313 1.8 christos maybe_init (m_ada); 314 1.8 christos return *m_ada; 315 1.8 christos } 316 1.8 christos 317 1.8 christos /* Get the C++-specific lookup info. */ 318 1.8 christos const demangle_for_lookup_info &cplus () const 319 1.8 christos { 320 1.8 christos maybe_init (m_cplus, language_cplus); 321 1.8 christos return *m_cplus; 322 1.8 christos } 323 1.8 christos 324 1.8 christos /* Get the D-specific lookup info. */ 325 1.8 christos const demangle_for_lookup_info &d () const 326 1.8 christos { 327 1.8 christos maybe_init (m_d, language_d); 328 1.8 christos return *m_d; 329 1.8 christos } 330 1.8 christos 331 1.8 christos /* Get the Go-specific lookup info. */ 332 1.8 christos const demangle_for_lookup_info &go () const 333 1.8 christos { 334 1.8 christos maybe_init (m_go, language_go); 335 1.8 christos return *m_go; 336 1.8 christos } 337 1.8 christos 338 1.8 christos /* Get a reference to a lookup_name_info object that matches any 339 1.8 christos symbol name. */ 340 1.8 christos static const lookup_name_info &match_any (); 341 1.8 christos 342 1.8 christos private: 343 1.8 christos /* Initialize FIELD, if not initialized yet. */ 344 1.8 christos template<typename Field, typename... Args> 345 1.8 christos void maybe_init (Field &field, Args&&... args) const 346 1.8 christos { 347 1.8 christos if (!field) 348 1.8 christos field.emplace (*this, std::forward<Args> (args)...); 349 1.8 christos } 350 1.8 christos 351 1.8 christos /* The lookup info as passed to the ctor. */ 352 1.8 christos symbol_name_match_type m_match_type; 353 1.8 christos bool m_completion_mode; 354 1.8 christos bool m_ignore_parameters; 355 1.11 christos std::string_view m_name; 356 1.8 christos 357 1.8 christos /* Language-specific info. These fields are filled lazily the first 358 1.8 christos time a lookup is done in the corresponding language. They're 359 1.8 christos mutable because lookup_name_info objects are typically passed 360 1.8 christos around by const reference (see intro), and they're conceptually 361 1.8 christos "cache" that can always be reconstructed from the non-mutable 362 1.8 christos fields. */ 363 1.11 christos mutable std::optional<ada_lookup_name_info> m_ada; 364 1.11 christos mutable std::optional<demangle_for_lookup_info> m_cplus; 365 1.11 christos mutable std::optional<demangle_for_lookup_info> m_d; 366 1.11 christos mutable std::optional<demangle_for_lookup_info> m_go; 367 1.8 christos 368 1.8 christos /* The demangled hashes. Stored in an array with one entry for each 369 1.8 christos possible language. The second array records whether we've 370 1.8 christos already computed the each language's hash. (These are separate 371 1.8 christos arrays instead of a single array of optional<unsigned> to avoid 372 1.8 christos alignment padding). */ 373 1.8 christos mutable std::array<unsigned int, nr_languages> m_demangled_hashes; 374 1.8 christos mutable std::array<bool, nr_languages> m_demangled_hashes_p {}; 375 1.8 christos }; 376 1.8 christos 377 1.8 christos /* Comparison function for completion symbol lookup. 378 1.8 christos 379 1.8 christos Returns true if the symbol name matches against LOOKUP_NAME. 380 1.8 christos 381 1.8 christos SYMBOL_SEARCH_NAME should be a symbol's "search" name. 382 1.8 christos 383 1.8 christos On success and if non-NULL, COMP_MATCH_RES->match is set to point 384 1.8 christos to the symbol name as should be presented to the user as a 385 1.8 christos completion match list element. In most languages, this is the same 386 1.8 christos as the symbol's search name, but in some, like Ada, the display 387 1.8 christos name is dynamically computed within the comparison routine. 388 1.8 christos 389 1.8 christos Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd 390 1.8 christos points the part of SYMBOL_SEARCH_NAME that was considered to match 391 1.8 christos LOOKUP_NAME. E.g., in C++, in linespec/wild mode, if the symbol is 392 1.8 christos "foo::function()" and LOOKUP_NAME is "function(", MATCH_FOR_LCD 393 1.8 christos points to "function()" inside SYMBOL_SEARCH_NAME. */ 394 1.8 christos typedef bool (symbol_name_matcher_ftype) 395 1.8 christos (const char *symbol_search_name, 396 1.8 christos const lookup_name_info &lookup_name, 397 1.8 christos completion_match_result *comp_match_res); 398 1.1 christos 399 1.1 christos /* Some of the structures in this file are space critical. 400 1.1 christos The space-critical structures are: 401 1.1 christos 402 1.1 christos struct general_symbol_info 403 1.1 christos struct symbol 404 1.1 christos struct partial_symbol 405 1.1 christos 406 1.1 christos These structures are laid out to encourage good packing. 407 1.1 christos They use ENUM_BITFIELD and short int fields, and they order the 408 1.1 christos structure members so that fields less than a word are next 409 1.1 christos to each other so they can be packed together. */ 410 1.1 christos 411 1.1 christos /* Rearranged: used ENUM_BITFIELD and rearranged field order in 412 1.1 christos all the space critical structures (plus struct minimal_symbol). 413 1.1 christos Memory usage dropped from 99360768 bytes to 90001408 bytes. 414 1.1 christos I measured this with before-and-after tests of 415 1.1 christos "HEAD-old-gdb -readnow HEAD-old-gdb" and 416 1.1 christos "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu, 417 1.1 christos red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug, 418 1.1 christos typing "maint space 1" at the first command prompt. 419 1.1 christos 420 1.1 christos Here is another measurement (from andrew c): 421 1.1 christos # no /usr/lib/debug, just plain glibc, like a normal user 422 1.1 christos gdb HEAD-old-gdb 423 1.1 christos (gdb) break internal_error 424 1.1 christos (gdb) run 425 1.1 christos (gdb) maint internal-error 426 1.1 christos (gdb) backtrace 427 1.1 christos (gdb) maint space 1 428 1.1 christos 429 1.1 christos gdb gdb_6_0_branch 2003-08-19 space used: 8896512 430 1.1 christos gdb HEAD 2003-08-19 space used: 8904704 431 1.1 christos gdb HEAD 2003-08-21 space used: 8396800 (+symtab.h) 432 1.1 christos gdb HEAD 2003-08-21 space used: 8265728 (+gdbtypes.h) 433 1.1 christos 434 1.1 christos The third line shows the savings from the optimizations in symtab.h. 435 1.1 christos The fourth line shows the savings from the optimizations in 436 1.1 christos gdbtypes.h. Both optimizations are in gdb HEAD now. 437 1.1 christos 438 1.1 christos --chastain 2003-08-21 */ 439 1.1 christos 440 1.1 christos /* Define a structure for the information that is common to all symbol types, 441 1.1 christos including minimal symbols, partial symbols, and full symbols. In a 442 1.1 christos multilanguage environment, some language specific information may need to 443 1.1 christos be recorded along with each symbol. */ 444 1.1 christos 445 1.1 christos /* This structure is space critical. See space comments at the top. */ 446 1.1 christos 447 1.1 christos struct general_symbol_info 448 1.1 christos { 449 1.9 christos /* Short version as to when to use which name accessor: 450 1.9 christos Use natural_name () to refer to the name of the symbol in the original 451 1.9 christos source code. Use linkage_name () if you want to know what the linker 452 1.9 christos thinks the symbol's name is. Use print_name () for output. Use 453 1.9 christos demangled_name () if you specifically need to know whether natural_name () 454 1.9 christos and linkage_name () are different. */ 455 1.9 christos 456 1.9 christos const char *linkage_name () const 457 1.9 christos { return m_name; } 458 1.9 christos 459 1.9 christos /* Return SYMBOL's "natural" name, i.e. the name that it was called in 460 1.9 christos the original source code. In languages like C++ where symbols may 461 1.9 christos be mangled for ease of manipulation by the linker, this is the 462 1.9 christos demangled name. */ 463 1.9 christos const char *natural_name () const; 464 1.9 christos 465 1.9 christos /* Returns a version of the name of a symbol that is 466 1.9 christos suitable for output. In C++ this is the "demangled" form of the 467 1.9 christos name if demangle is on and the "mangled" form of the name if 468 1.9 christos demangle is off. In other languages this is just the symbol name. 469 1.9 christos The result should never be NULL. Don't use this for internal 470 1.9 christos purposes (e.g. storing in a hashtable): it's only suitable for output. */ 471 1.9 christos const char *print_name () const 472 1.9 christos { return demangle ? natural_name () : linkage_name (); } 473 1.9 christos 474 1.9 christos /* Return the demangled name for a symbol based on the language for 475 1.9 christos that symbol. If no demangled name exists, return NULL. */ 476 1.9 christos const char *demangled_name () const; 477 1.9 christos 478 1.9 christos /* Returns the name to be used when sorting and searching symbols. 479 1.9 christos In C++, we search for the demangled form of a name, 480 1.9 christos and so sort symbols accordingly. In Ada, however, we search by mangled 481 1.9 christos name. If there is no distinct demangled name, then this 482 1.9 christos returns the same value (same pointer) as linkage_name (). */ 483 1.9 christos const char *search_name () const; 484 1.9 christos 485 1.9 christos /* Set just the linkage name of a symbol; do not try to demangle 486 1.9 christos it. Used for constructs which do not have a mangled name, 487 1.9 christos e.g. struct tags. Unlike compute_and_set_names, linkage_name must 488 1.9 christos be terminated and either already on the objfile's obstack or 489 1.9 christos permanently allocated. */ 490 1.9 christos void set_linkage_name (const char *linkage_name) 491 1.9 christos { m_name = linkage_name; } 492 1.9 christos 493 1.9 christos /* Set the demangled name of this symbol to NAME. NAME must be 494 1.9 christos already correctly allocated. If the symbol's language is Ada, 495 1.9 christos then the name is ignored and the obstack is set. */ 496 1.9 christos void set_demangled_name (const char *name, struct obstack *obstack); 497 1.9 christos 498 1.9 christos enum language language () const 499 1.9 christos { return m_language; } 500 1.9 christos 501 1.9 christos /* Initializes the language dependent portion of a symbol 502 1.9 christos depending upon the language for the symbol. */ 503 1.9 christos void set_language (enum language language, struct obstack *obstack); 504 1.9 christos 505 1.9 christos /* Set the linkage and natural names of a symbol, by demangling 506 1.9 christos the linkage name. If linkage_name may not be nullterminated, 507 1.9 christos copy_name must be set to true. */ 508 1.11 christos void compute_and_set_names (std::string_view linkage_name, bool copy_name, 509 1.9 christos struct objfile_per_bfd_storage *per_bfd, 510 1.11 christos std::optional<hashval_t> hash 511 1.11 christos = std::optional<hashval_t> ()); 512 1.10 christos 513 1.10 christos CORE_ADDR value_address () const 514 1.10 christos { 515 1.10 christos return m_value.address; 516 1.10 christos } 517 1.10 christos 518 1.10 christos void set_value_address (CORE_ADDR address) 519 1.10 christos { 520 1.10 christos m_value.address = address; 521 1.10 christos } 522 1.9 christos 523 1.11 christos /* Return the unrelocated address of this symbol. */ 524 1.11 christos unrelocated_addr unrelocated_address () const 525 1.11 christos { 526 1.11 christos return m_value.unrel_addr; 527 1.11 christos } 528 1.11 christos 529 1.11 christos /* Set the unrelocated address of this symbol. */ 530 1.11 christos void set_unrelocated_address (unrelocated_addr addr) 531 1.11 christos { 532 1.11 christos m_value.unrel_addr = addr; 533 1.11 christos } 534 1.11 christos 535 1.1 christos /* Name of the symbol. This is a required field. Storage for the 536 1.1 christos name is allocated on the objfile_obstack for the associated 537 1.1 christos objfile. For languages like C++ that make a distinction between 538 1.1 christos the mangled name and demangled name, this is the mangled 539 1.1 christos name. */ 540 1.1 christos 541 1.9 christos const char *m_name; 542 1.1 christos 543 1.1 christos /* Value of the symbol. Which member of this union to use, and what 544 1.1 christos it means, depends on what kind of symbol this is and its 545 1.1 christos SYMBOL_CLASS. See comments there for more details. All of these 546 1.1 christos are in host byte order (though what they point to might be in 547 1.1 christos target byte order, e.g. LOC_CONST_BYTES). */ 548 1.1 christos 549 1.1 christos union 550 1.1 christos { 551 1.1 christos LONGEST ivalue; 552 1.1 christos 553 1.3 christos const struct block *block; 554 1.1 christos 555 1.1 christos const gdb_byte *bytes; 556 1.1 christos 557 1.1 christos CORE_ADDR address; 558 1.1 christos 559 1.11 christos /* The address, if unrelocated. An unrelocated symbol does not 560 1.11 christos have the runtime section offset applied. */ 561 1.11 christos unrelocated_addr unrel_addr; 562 1.11 christos 563 1.1 christos /* A common block. Used with LOC_COMMON_BLOCK. */ 564 1.1 christos 565 1.3 christos const struct common_block *common_block; 566 1.1 christos 567 1.1 christos /* For opaque typedef struct chain. */ 568 1.1 christos 569 1.1 christos struct symbol *chain; 570 1.1 christos } 571 1.10 christos m_value; 572 1.1 christos 573 1.1 christos /* Since one and only one language can apply, wrap the language specific 574 1.1 christos information inside a union. */ 575 1.1 christos 576 1.1 christos union 577 1.1 christos { 578 1.1 christos /* A pointer to an obstack that can be used for storage associated 579 1.1 christos with this symbol. This is only used by Ada, and only when the 580 1.1 christos 'ada_mangled' field is zero. */ 581 1.1 christos struct obstack *obstack; 582 1.1 christos 583 1.1 christos /* This is used by languages which wish to store a demangled name. 584 1.7 christos currently used by Ada, C++, and Objective C. */ 585 1.6 christos const char *demangled_name; 586 1.1 christos } 587 1.1 christos language_specific; 588 1.1 christos 589 1.1 christos /* Record the source code language that applies to this symbol. 590 1.1 christos This is used to select one of the fields from the language specific 591 1.1 christos union above. */ 592 1.1 christos 593 1.9 christos ENUM_BITFIELD(language) m_language : LANGUAGE_BITS; 594 1.1 christos 595 1.6 christos /* This is only used by Ada. If set, then the 'demangled_name' field 596 1.1 christos of language_specific is valid. Otherwise, the 'obstack' field is 597 1.1 christos valid. */ 598 1.1 christos unsigned int ada_mangled : 1; 599 1.1 christos 600 1.1 christos /* Which section is this symbol in? This is an index into 601 1.1 christos section_offsets for this objfile. Negative means that the symbol 602 1.1 christos does not get relocated relative to a section. */ 603 1.1 christos 604 1.12 christos int m_section; 605 1.10 christos 606 1.10 christos /* Set the index into the obj_section list (within the containing 607 1.10 christos objfile) for the section that contains this symbol. See M_SECTION 608 1.10 christos for more details. */ 609 1.10 christos 610 1.12 christos void set_section_index (int idx) 611 1.10 christos { m_section = idx; } 612 1.10 christos 613 1.10 christos /* Return the index into the obj_section list (within the containing 614 1.10 christos objfile) for the section that contains this symbol. See M_SECTION 615 1.10 christos for more details. */ 616 1.10 christos 617 1.12 christos auto section_index () const 618 1.10 christos { return m_section; } 619 1.10 christos 620 1.10 christos /* Return the obj_section from OBJFILE for this symbol. The symbol 621 1.10 christos returned is based on the SECTION member variable, and can be nullptr 622 1.10 christos if SECTION is negative. */ 623 1.10 christos 624 1.10 christos struct obj_section *obj_section (const struct objfile *objfile) const; 625 1.1 christos }; 626 1.1 christos 627 1.1 christos extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *); 628 1.1 christos 629 1.9 christos /* Try to determine the demangled name for a symbol, based on the 630 1.9 christos language of that symbol. If the language is set to language_auto, 631 1.9 christos it will attempt to find any demangling algorithm that works and 632 1.9 christos then set the language appropriately. The returned name is allocated 633 1.9 christos by the demangler and should be xfree'd. */ 634 1.9 christos 635 1.10 christos extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name 636 1.10 christos (struct general_symbol_info *gsymbol, const char *mangled); 637 1.1 christos 638 1.10 christos /* Return true if NAME matches the "search" name of GSYMBOL, according 639 1.8 christos to the symbol's language. */ 640 1.8 christos extern bool symbol_matches_search_name 641 1.8 christos (const struct general_symbol_info *gsymbol, 642 1.8 christos const lookup_name_info &name); 643 1.8 christos 644 1.8 christos /* Compute the hash of the given symbol search name of a symbol of 645 1.8 christos language LANGUAGE. */ 646 1.8 christos extern unsigned int search_name_hash (enum language language, 647 1.8 christos const char *search_name); 648 1.1 christos 649 1.1 christos /* Classification types for a minimal symbol. These should be taken as 650 1.1 christos "advisory only", since if gdb can't easily figure out a 651 1.1 christos classification it simply selects mst_unknown. It may also have to 652 1.1 christos guess when it can't figure out which is a better match between two 653 1.1 christos types (mst_data versus mst_bss) for example. Since the minimal 654 1.1 christos symbol info is sometimes derived from the BFD library's view of a 655 1.1 christos file, we need to live with what information bfd supplies. */ 656 1.1 christos 657 1.1 christos enum minimal_symbol_type 658 1.1 christos { 659 1.1 christos mst_unknown = 0, /* Unknown type, the default */ 660 1.1 christos mst_text, /* Generally executable instructions */ 661 1.8 christos 662 1.8 christos /* A GNU ifunc symbol, in the .text section. GDB uses to know 663 1.8 christos whether the user is setting a breakpoint on a GNU ifunc function, 664 1.8 christos and thus GDB needs to actually set the breakpoint on the target 665 1.8 christos function. It is also used to know whether the program stepped 666 1.8 christos into an ifunc resolver -- the resolver may get a separate 667 1.8 christos symbol/alias under a different name, but it'll have the same 668 1.8 christos address as the ifunc symbol. */ 669 1.8 christos mst_text_gnu_ifunc, /* Executable code returning address 670 1.8 christos of executable code */ 671 1.8 christos 672 1.8 christos /* A GNU ifunc function descriptor symbol, in a data section 673 1.8 christos (typically ".opd"). Seen on architectures that use function 674 1.8 christos descriptors, like PPC64/ELFv1. In this case, this symbol's value 675 1.8 christos is the address of the descriptor. There'll be a corresponding 676 1.8 christos mst_text_gnu_ifunc synthetic symbol for the text/entry 677 1.8 christos address. */ 678 1.8 christos mst_data_gnu_ifunc, /* Executable code returning address 679 1.1 christos of executable code */ 680 1.8 christos 681 1.1 christos mst_slot_got_plt, /* GOT entries for .plt sections */ 682 1.1 christos mst_data, /* Generally initialized data */ 683 1.1 christos mst_bss, /* Generally uninitialized data */ 684 1.1 christos mst_abs, /* Generally absolute (nonrelocatable) */ 685 1.1 christos /* GDB uses mst_solib_trampoline for the start address of a shared 686 1.1 christos library trampoline entry. Breakpoints for shared library functions 687 1.1 christos are put there if the shared library is not yet loaded. 688 1.1 christos After the shared library is loaded, lookup_minimal_symbol will 689 1.1 christos prefer the minimal symbol from the shared library (usually 690 1.1 christos a mst_text symbol) over the mst_solib_trampoline symbol, and the 691 1.1 christos breakpoints will be moved to their true address in the shared 692 1.1 christos library via breakpoint_re_set. */ 693 1.1 christos mst_solib_trampoline, /* Shared library trampoline code */ 694 1.1 christos /* For the mst_file* types, the names are only guaranteed to be unique 695 1.1 christos within a given .o file. */ 696 1.1 christos mst_file_text, /* Static version of mst_text */ 697 1.1 christos mst_file_data, /* Static version of mst_data */ 698 1.6 christos mst_file_bss, /* Static version of mst_bss */ 699 1.6 christos nr_minsym_types 700 1.1 christos }; 701 1.1 christos 702 1.6 christos /* The number of enum minimal_symbol_type values, with some padding for 703 1.6 christos reasonable growth. */ 704 1.6 christos #define MINSYM_TYPE_BITS 4 705 1.11 christos static_assert (nr_minsym_types <= (1 << MINSYM_TYPE_BITS)); 706 1.10 christos 707 1.1 christos /* Define a simple structure used to hold some very basic information about 708 1.1 christos all defined global symbols (text, data, bss, abs, etc). The only required 709 1.1 christos information is the general_symbol_info. 710 1.1 christos 711 1.1 christos In many cases, even if a file was compiled with no special options for 712 1.1 christos debugging at all, as long as was not stripped it will contain sufficient 713 1.1 christos information to build a useful minimal symbol table using this structure. 714 1.1 christos Even when a file contains enough debugging information to build a full 715 1.1 christos symbol table, these minimal symbols are still useful for quickly mapping 716 1.1 christos between names and addresses, and vice versa. They are also sometimes 717 1.1 christos used to figure out what full symbol table entries need to be read in. */ 718 1.1 christos 719 1.9 christos struct minimal_symbol : public general_symbol_info 720 1.1 christos { 721 1.10 christos LONGEST value_longest () const 722 1.10 christos { 723 1.10 christos return m_value.ivalue; 724 1.10 christos } 725 1.10 christos 726 1.10 christos /* The relocated address of the minimal symbol, using the section 727 1.10 christos offsets from OBJFILE. */ 728 1.10 christos CORE_ADDR value_address (objfile *objfile) const; 729 1.10 christos 730 1.11 christos /* It does not make sense to call this for minimal symbols, as they 731 1.11 christos are stored unrelocated. */ 732 1.11 christos CORE_ADDR value_address () const = delete; 733 1.11 christos 734 1.10 christos /* The unrelocated address of the minimal symbol. */ 735 1.11 christos unrelocated_addr unrelocated_address () const 736 1.10 christos { 737 1.11 christos return m_value.unrel_addr; 738 1.11 christos } 739 1.11 christos 740 1.11 christos /* The unrelocated address just after the end of the the minimal 741 1.11 christos symbol. */ 742 1.11 christos unrelocated_addr unrelocated_end_address () const 743 1.11 christos { 744 1.11 christos return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ()); 745 1.10 christos } 746 1.10 christos 747 1.10 christos /* Return this minimal symbol's type. */ 748 1.10 christos 749 1.10 christos minimal_symbol_type type () const 750 1.10 christos { 751 1.10 christos return m_type; 752 1.10 christos } 753 1.10 christos 754 1.10 christos /* Set this minimal symbol's type. */ 755 1.10 christos 756 1.10 christos void set_type (minimal_symbol_type type) 757 1.10 christos { 758 1.10 christos m_type = type; 759 1.10 christos } 760 1.10 christos 761 1.10 christos /* Return this minimal symbol's size. */ 762 1.10 christos 763 1.10 christos unsigned long size () const 764 1.10 christos { 765 1.10 christos return m_size; 766 1.10 christos } 767 1.10 christos 768 1.10 christos /* Set this minimal symbol's size. */ 769 1.10 christos 770 1.10 christos void set_size (unsigned long size) 771 1.10 christos { 772 1.10 christos m_size = size; 773 1.10 christos m_has_size = 1; 774 1.10 christos } 775 1.10 christos 776 1.10 christos /* Return true if this minimal symbol's size is known. */ 777 1.10 christos 778 1.10 christos bool has_size () const 779 1.10 christos { 780 1.10 christos return m_has_size; 781 1.10 christos } 782 1.10 christos 783 1.10 christos /* Return this minimal symbol's first target-specific flag. */ 784 1.10 christos 785 1.10 christos bool target_flag_1 () const 786 1.10 christos { 787 1.10 christos return m_target_flag_1; 788 1.10 christos } 789 1.10 christos 790 1.10 christos /* Set this minimal symbol's first target-specific flag. */ 791 1.10 christos 792 1.10 christos void set_target_flag_1 (bool target_flag_1) 793 1.10 christos { 794 1.10 christos m_target_flag_1 = target_flag_1; 795 1.10 christos } 796 1.10 christos 797 1.10 christos /* Return this minimal symbol's second target-specific flag. */ 798 1.10 christos 799 1.10 christos bool target_flag_2 () const 800 1.10 christos { 801 1.10 christos return m_target_flag_2; 802 1.10 christos } 803 1.10 christos 804 1.10 christos /* Set this minimal symbol's second target-specific flag. */ 805 1.10 christos 806 1.10 christos void set_target_flag_2 (bool target_flag_2) 807 1.10 christos { 808 1.10 christos m_target_flag_2 = target_flag_2; 809 1.10 christos } 810 1.10 christos 811 1.12 christos /* Size of this symbol. stabs_end_psymtab in stabsread.c uses this 812 1.1 christos information to calculate the end of the partial symtab based on the 813 1.1 christos address of the last symbol plus the size of the last symbol. */ 814 1.1 christos 815 1.10 christos unsigned long m_size; 816 1.1 christos 817 1.1 christos /* Which source file is this symbol in? Only relevant for mst_file_*. */ 818 1.1 christos const char *filename; 819 1.1 christos 820 1.1 christos /* Classification type for this minimal symbol. */ 821 1.1 christos 822 1.10 christos ENUM_BITFIELD(minimal_symbol_type) m_type : MINSYM_TYPE_BITS; 823 1.1 christos 824 1.1 christos /* Non-zero if this symbol was created by gdb. 825 1.1 christos Such symbols do not appear in the output of "info var|fun". */ 826 1.1 christos unsigned int created_by_gdb : 1; 827 1.1 christos 828 1.1 christos /* Two flag bits provided for the use of the target. */ 829 1.10 christos unsigned int m_target_flag_1 : 1; 830 1.10 christos unsigned int m_target_flag_2 : 1; 831 1.1 christos 832 1.1 christos /* Nonzero iff the size of the minimal symbol has been set. 833 1.1 christos Symbol size information can sometimes not be determined, because 834 1.1 christos the object file format may not carry that piece of information. */ 835 1.10 christos unsigned int m_has_size : 1; 836 1.1 christos 837 1.9 christos /* Non-zero if this symbol ever had its demangled name set (even if 838 1.9 christos it was set to NULL). */ 839 1.9 christos unsigned int name_set : 1; 840 1.9 christos 841 1.1 christos /* Minimal symbols with the same hash key are kept on a linked 842 1.1 christos list. This is the link. */ 843 1.1 christos 844 1.1 christos struct minimal_symbol *hash_next; 845 1.1 christos 846 1.1 christos /* Minimal symbols are stored in two different hash tables. This is 847 1.1 christos the `next' pointer for the demangled hash table. */ 848 1.1 christos 849 1.1 christos struct minimal_symbol *demangled_hash_next; 850 1.8 christos 851 1.9 christos /* True if this symbol is of some data type. */ 852 1.8 christos 853 1.8 christos bool data_p () const; 854 1.8 christos 855 1.8 christos /* True if MSYMBOL is of some text type. */ 856 1.8 christos 857 1.8 christos bool text_p () const; 858 1.11 christos 859 1.11 christos /* For data symbols only, given an objfile, if 'maybe_copied' 860 1.11 christos evaluates to 'true' for that objfile, then the symbol might be 861 1.11 christos subject to copy relocation. In this case, a minimal symbol 862 1.11 christos matching the symbol's linkage name is first looked for in the 863 1.11 christos main objfile. If found, then that address is used; otherwise the 864 1.11 christos address in this symbol is used. */ 865 1.11 christos 866 1.11 christos bool maybe_copied (objfile *objfile) const; 867 1.11 christos 868 1.11 christos private: 869 1.11 christos /* Return the address of this minimal symbol, in the context of OBJF. The 870 1.11 christos MAYBE_COPIED flag must be set. If the minimal symbol appears in the 871 1.11 christos main program's minimal symbols, then that minsym's address is 872 1.11 christos returned; otherwise, this minimal symbol's address is returned. */ 873 1.11 christos CORE_ADDR get_maybe_copied_address (objfile *objf) const; 874 1.1 christos }; 875 1.1 christos 876 1.1 christos #include "minsyms.h" 877 1.1 christos 878 1.1 christos 879 1.1 christos 881 1.1 christos /* Represent one symbol name; a variable, constant, function or typedef. */ 882 1.1 christos 883 1.1 christos /* Different name domains for symbols. Looking up a symbol specifies a 884 1.1 christos domain and ignores symbol definitions in other name domains. */ 885 1.10 christos 886 1.1 christos enum domain_enum 887 1.11 christos { 888 1.11 christos #define SYM_DOMAIN(X) X ## _DOMAIN, 889 1.11 christos #include "sym-domains.def" 890 1.10 christos #undef SYM_DOMAIN 891 1.1 christos }; 892 1.3 christos 893 1.3 christos /* The number of bits in a symbol used to represent the domain. */ 894 1.6 christos 895 1.3 christos #define SYMBOL_DOMAIN_BITS 3 896 1.1 christos 897 1.1 christos extern const char *domain_name (domain_enum); 898 1.11 christos 899 1.11 christos /* Flags used for searching symbol tables. These can be combined to 900 1.11 christos let the search match multiple kinds of symbol. */ 901 1.11 christos enum domain_search_flag 902 1.11 christos { 903 1.11 christos #define SYM_DOMAIN(X) \ 904 1.11 christos SEARCH_ ## X ## _DOMAIN = (1 << X ## _DOMAIN), 905 1.11 christos #include "sym-domains.def" 906 1.11 christos #undef SYM_DOMAIN 907 1.11 christos }; 908 1.11 christos DEF_ENUM_FLAGS_TYPE (enum domain_search_flag, domain_search_flags); 909 1.11 christos 910 1.11 christos /* A convenience constant to search for any symbol. */ 911 1.11 christos constexpr domain_search_flags SEARCH_ALL_DOMAINS 912 1.11 christos = ((domain_search_flags) 0 913 1.11 christos #define SYM_DOMAIN(X) | SEARCH_ ## X ## _DOMAIN 914 1.11 christos #include "sym-domains.def" 915 1.11 christos #undef SYM_DOMAIN 916 1.11 christos ); 917 1.11 christos 918 1.11 christos /* A convenience define for "C-like" name lookups, matching variables, 919 1.11 christos types, and functions. */ 920 1.11 christos #define SEARCH_VFT \ 921 1.11 christos (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN | SEARCH_TYPE_DOMAIN) 922 1.11 christos 923 1.11 christos /* Return a string representing the given flags. */ 924 1.11 christos extern std::string domain_name (domain_search_flags); 925 1.11 christos 926 1.11 christos /* Convert a symbol domain to search flags. */ 927 1.11 christos static inline domain_search_flags 928 1.11 christos to_search_flags (domain_enum domain) 929 1.11 christos { 930 1.11 christos return domain_search_flags (domain_search_flag (1 << domain)); 931 1.1 christos } 932 1.11 christos 933 1.11 christos /* Return true if the given domain matches the given flags, false 934 1.11 christos otherwise. */ 935 1.11 christos static inline bool 936 1.1 christos search_flags_matches (domain_search_flags flags, domain_enum domain) 937 1.11 christos { 938 1.11 christos return (flags & to_search_flags (domain)) != 0; 939 1.1 christos } 940 1.11 christos 941 1.11 christos /* Some helpers for Python and Guile to account for backward 942 1.11 christos compatibility. Those exposed the domains for lookup as well as 943 1.11 christos checking attributes of a symbol, so special encoding and decoding 944 1.11 christos is needed to continue to support both uses. Domain constants must 945 1.11 christos remain unchanged, so that comparing a symbol's domain against a 946 1.11 christos constant yields the correct result, so search symbols are 947 1.11 christos distinguished by adding a flag bit. This way, either sort of 948 1.11 christos constant can be used for lookup. */ 949 1.11 christos 950 1.11 christos /* The flag bit. */ 951 1.11 christos constexpr int SCRIPTING_SEARCH_FLAG = 0x8000; 952 1.11 christos static_assert (SCRIPTING_SEARCH_FLAG > SEARCH_ALL_DOMAINS); 953 1.11 christos 954 1.11 christos /* Convert a domain constant to a "scripting domain". */ 955 1.11 christos static constexpr inline int 956 1.11 christos to_scripting_domain (domain_enum val) 957 1.11 christos { 958 1.11 christos return val; 959 1.1 christos } 960 1.11 christos 961 1.11 christos /* Convert a search constant to a "scripting domain". */ 962 1.11 christos static constexpr inline int 963 1.11 christos to_scripting_domain (domain_search_flags val) 964 1.11 christos { 965 1.11 christos return SCRIPTING_SEARCH_FLAG | (int) val; 966 1.1 christos } 967 1.11 christos 968 1.11 christos /* Convert from a "scripting domain" constant back to search flags. 969 1.11 christos Throws an exception if VAL is not one of the allowable values. */ 970 1.1 christos extern domain_search_flags from_scripting_domain (int val); 971 1.1 christos 972 1.1 christos /* An address-class says where to find the value of a symbol. */ 973 1.1 christos 974 1.1 christos enum address_class 975 1.1 christos { 976 1.1 christos /* Not used; catches errors. */ 977 1.1 christos 978 1.1 christos LOC_UNDEF, 979 1.1 christos 980 1.1 christos /* Value is constant int SYMBOL_VALUE, host byteorder. */ 981 1.1 christos 982 1.1 christos LOC_CONST, 983 1.1 christos 984 1.1 christos /* Value is at fixed address SYMBOL_VALUE_ADDRESS. */ 985 1.1 christos 986 1.1 christos LOC_STATIC, 987 1.1 christos 988 1.1 christos /* Value is in register. SYMBOL_VALUE is the register number 989 1.1 christos in the original debug format. SYMBOL_REGISTER_OPS holds a 990 1.1 christos function that can be called to transform this into the 991 1.1 christos actual register number this represents in a specific target 992 1.1 christos architecture (gdbarch). 993 1.1 christos 994 1.1 christos For some symbol formats (stabs, for some compilers at least), 995 1.1 christos the compiler generates two symbols, an argument and a register. 996 1.1 christos In some cases we combine them to a single LOC_REGISTER in symbol 997 1.1 christos reading, but currently not for all cases (e.g. it's passed on the 998 1.1 christos stack and then loaded into a register). */ 999 1.1 christos 1000 1.1 christos LOC_REGISTER, 1001 1.1 christos 1002 1.1 christos /* It's an argument; the value is at SYMBOL_VALUE offset in arglist. */ 1003 1.1 christos 1004 1.1 christos LOC_ARG, 1005 1.1 christos 1006 1.1 christos /* Value address is at SYMBOL_VALUE offset in arglist. */ 1007 1.1 christos 1008 1.1 christos LOC_REF_ARG, 1009 1.1 christos 1010 1.1 christos /* Value is in specified register. Just like LOC_REGISTER except the 1011 1.1 christos register holds the address of the argument instead of the argument 1012 1.1 christos itself. This is currently used for the passing of structs and unions 1013 1.1 christos on sparc and hppa. It is also used for call by reference where the 1014 1.1 christos address is in a register, at least by mipsread.c. */ 1015 1.1 christos 1016 1.1 christos LOC_REGPARM_ADDR, 1017 1.1 christos 1018 1.1 christos /* Value is a local variable at SYMBOL_VALUE offset in stack frame. */ 1019 1.1 christos 1020 1.1 christos LOC_LOCAL, 1021 1.1 christos 1022 1.1 christos /* Value not used; definition in SYMBOL_TYPE. Symbols in the domain 1023 1.1 christos STRUCT_DOMAIN all have this class. */ 1024 1.1 christos 1025 1.1 christos LOC_TYPEDEF, 1026 1.1 christos 1027 1.1 christos /* Value is address SYMBOL_VALUE_ADDRESS in the code. */ 1028 1.1 christos 1029 1.1 christos LOC_LABEL, 1030 1.1 christos 1031 1.1 christos /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'. 1032 1.1 christos In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address 1033 1.1 christos of the block. Function names have this class. */ 1034 1.1 christos 1035 1.1 christos LOC_BLOCK, 1036 1.1 christos 1037 1.1 christos /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in 1038 1.1 christos target byte order. */ 1039 1.1 christos 1040 1.1 christos LOC_CONST_BYTES, 1041 1.1 christos 1042 1.1 christos /* Value is at fixed address, but the address of the variable has 1043 1.1 christos to be determined from the minimal symbol table whenever the 1044 1.1 christos variable is referenced. 1045 1.1 christos This happens if debugging information for a global symbol is 1046 1.1 christos emitted and the corresponding minimal symbol is defined 1047 1.1 christos in another object file or runtime common storage. 1048 1.1 christos The linker might even remove the minimal symbol if the global 1049 1.1 christos symbol is never referenced, in which case the symbol remains 1050 1.1 christos unresolved. 1051 1.1 christos 1052 1.1 christos GDB would normally find the symbol in the minimal symbol table if it will 1053 1.1 christos not find it in the full symbol table. But a reference to an external 1054 1.1 christos symbol in a local block shadowing other definition requires full symbol 1055 1.6 christos without possibly having its address available for LOC_STATIC. Testcase 1056 1.6 christos is provided as `gdb.dwarf2/dw2-unresolved.exp'. 1057 1.11 christos 1058 1.11 christos This is also used for thread local storage (TLS) variables. In 1059 1.11 christos this case, the address of the TLS variable must be determined 1060 1.11 christos when the variable is referenced, from the msymbol's address, 1061 1.11 christos which is the offset of the TLS variable in the thread local 1062 1.1 christos storage of the shared library/object. */ 1063 1.1 christos 1064 1.1 christos LOC_UNRESOLVED, 1065 1.1 christos 1066 1.1 christos /* The variable does not actually exist in the program. 1067 1.1 christos The value is ignored. */ 1068 1.1 christos 1069 1.1 christos LOC_OPTIMIZED_OUT, 1070 1.1 christos 1071 1.1 christos /* The variable's address is computed by a set of location 1072 1.1 christos functions (see "struct symbol_computed_ops" below). */ 1073 1.1 christos LOC_COMPUTED, 1074 1.1 christos 1075 1.1 christos /* The variable uses general_symbol_info->value->common_block field. 1076 1.1 christos It also always uses COMMON_BLOCK_DOMAIN. */ 1077 1.1 christos LOC_COMMON_BLOCK, 1078 1.1 christos 1079 1.1 christos /* Not used, just notes the boundary of the enum. */ 1080 1.1 christos LOC_FINAL_VALUE 1081 1.1 christos }; 1082 1.6 christos 1083 1.6 christos /* The number of bits needed for values in enum address_class, with some 1084 1.6 christos padding for reasonable growth, and room for run-time registered address 1085 1.6 christos classes. See symtab.c:MAX_SYMBOL_IMPLS. 1086 1.6 christos This is a #define so that we can have a assertion elsewhere to 1087 1.6 christos verify that we have reserved enough space for synthetic address 1088 1.6 christos classes. */ 1089 1.11 christos #define SYMBOL_ACLASS_BITS 5 1090 1.6 christos static_assert (LOC_FINAL_VALUE <= (1 << SYMBOL_ACLASS_BITS)); 1091 1.1 christos 1092 1.1 christos /* The methods needed to implement LOC_COMPUTED. These methods can 1093 1.1 christos use the symbol's .aux_value for additional per-symbol information. 1094 1.1 christos 1095 1.1 christos At present this is only used to implement location expressions. */ 1096 1.1 christos 1097 1.1 christos struct symbol_computed_ops 1098 1.1 christos { 1099 1.1 christos 1100 1.1 christos /* Return the value of the variable SYMBOL, relative to the stack 1101 1.1 christos frame FRAME. If the variable has been optimized out, return 1102 1.1 christos zero. 1103 1.6 christos 1104 1.6 christos Iff `read_needs_frame (SYMBOL)' is not SYMBOL_NEEDS_FRAME, then 1105 1.1 christos FRAME may be zero. */ 1106 1.1 christos 1107 1.11 christos struct value *(*read_variable) (struct symbol * symbol, 1108 1.1 christos const frame_info_ptr &frame); 1109 1.1 christos 1110 1.1 christos /* Read variable SYMBOL like read_variable at (callee) FRAME's function 1111 1.1 christos entry. SYMBOL should be a function parameter, otherwise 1112 1.1 christos NO_ENTRY_VALUE_ERROR will be thrown. */ 1113 1.11 christos struct value *(*read_variable_at_entry) (struct symbol *symbol, 1114 1.1 christos const frame_info_ptr &frame); 1115 1.6 christos 1116 1.6 christos /* Find the "symbol_needs_kind" value for the given symbol. This 1117 1.6 christos value determines whether reading the symbol needs memory (e.g., a 1118 1.6 christos global variable), just registers (a thread-local), or a frame (a 1119 1.6 christos local variable). */ 1120 1.1 christos enum symbol_needs_kind (*get_symbol_read_needs) (struct symbol * symbol); 1121 1.1 christos 1122 1.1 christos /* Write to STREAM a natural-language description of the location of 1123 1.1 christos SYMBOL, in the context of ADDR. */ 1124 1.1 christos void (*describe_location) (struct symbol * symbol, CORE_ADDR addr, 1125 1.1 christos struct ui_file * stream); 1126 1.1 christos 1127 1.1 christos /* Non-zero if this symbol's address computation is dependent on PC. */ 1128 1.1 christos unsigned char location_has_loclist; 1129 1.1 christos 1130 1.1 christos /* Tracepoint support. Append bytecodes to the tracepoint agent 1131 1.1 christos expression AX that push the address of the object SYMBOL. Set 1132 1.1 christos VALUE appropriately. Note --- for objects in registers, this 1133 1.1 christos needn't emit any code; as long as it sets VALUE properly, then 1134 1.1 christos the caller will generate the right code in the process of 1135 1.1 christos treating this as an lvalue or rvalue. */ 1136 1.8 christos 1137 1.8 christos void (*tracepoint_var_ref) (struct symbol *symbol, struct agent_expr *ax, 1138 1.3 christos struct axs_value *value); 1139 1.3 christos 1140 1.3 christos /* Generate C code to compute the location of SYMBOL. The C code is 1141 1.3 christos emitted to STREAM. GDBARCH is the current architecture and PC is 1142 1.3 christos the PC at which SYMBOL's location should be evaluated. 1143 1.3 christos REGISTERS_USED is a vector indexed by register number; the 1144 1.3 christos generator function should set an element in this vector if the 1145 1.3 christos corresponding register is needed by the location computation. 1146 1.3 christos The generated C code must assign the location to a local 1147 1.3 christos variable; this variable's name is RESULT_NAME. */ 1148 1.8 christos 1149 1.3 christos void (*generate_c_location) (struct symbol *symbol, string_file *stream, 1150 1.10 christos struct gdbarch *gdbarch, 1151 1.3 christos std::vector<bool> ®isters_used, 1152 1.3 christos CORE_ADDR pc, const char *result_name); 1153 1.1 christos 1154 1.1 christos }; 1155 1.1 christos 1156 1.1 christos /* The methods needed to implement LOC_BLOCK for inferior functions. 1157 1.1 christos These methods can use the symbol's .aux_value for additional 1158 1.1 christos per-symbol information. */ 1159 1.1 christos 1160 1.1 christos struct symbol_block_ops 1161 1.1 christos { 1162 1.1 christos /* Fill in *START and *LENGTH with DWARF block data of function 1163 1.1 christos FRAMEFUNC valid for inferior context address PC. Set *LENGTH to 1164 1.1 christos zero if such location is not valid for PC; *START is left 1165 1.1 christos uninitialized in such case. */ 1166 1.1 christos void (*find_frame_base_location) (struct symbol *framefunc, CORE_ADDR pc, 1167 1.6 christos const gdb_byte **start, size_t *length); 1168 1.6 christos 1169 1.6 christos /* Return the frame base address. FRAME is the frame for which we want to 1170 1.6 christos compute the base address while FRAMEFUNC is the symbol for the 1171 1.6 christos corresponding function. Return 0 on failure (FRAMEFUNC may not hold the 1172 1.6 christos information we need). 1173 1.6 christos 1174 1.6 christos This method is designed to work with static links (nested functions 1175 1.6 christos handling). Static links are function properties whose evaluation returns 1176 1.6 christos the frame base address for the enclosing frame. However, there are 1177 1.6 christos multiple definitions for "frame base": the content of the frame base 1178 1.6 christos register, the CFA as defined by DWARF unwinding information, ... 1179 1.6 christos 1180 1.9 christos So this specific method is supposed to compute the frame base address such 1181 1.6 christos as for nested functions, the static link computes the same address. For 1182 1.6 christos instance, considering DWARF debugging information, the static link is 1183 1.6 christos computed with DW_AT_static_link and this method must be used to compute 1184 1.6 christos the corresponding DW_AT_frame_base attribute. */ 1185 1.11 christos CORE_ADDR (*get_frame_base) (struct symbol *framefunc, 1186 1.11 christos const frame_info_ptr &frame); 1187 1.11 christos 1188 1.11 christos /* Return the block for this function. So far, this is used to 1189 1.11 christos implement function aliases. So, if this is set, then it's not 1190 1.11 christos necessary to set the other functions in this structure; and vice 1191 1.11 christos versa. */ 1192 1.1 christos const block *(*get_block_value) (const struct symbol *sym); 1193 1.1 christos }; 1194 1.1 christos 1195 1.1 christos /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */ 1196 1.1 christos 1197 1.1 christos struct symbol_register_ops 1198 1.1 christos { 1199 1.1 christos int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch); 1200 1.1 christos }; 1201 1.1 christos 1202 1.1 christos /* Objects of this type are used to find the address class and the 1203 1.1 christos various computed ops vectors of a symbol. */ 1204 1.1 christos 1205 1.1 christos struct symbol_impl 1206 1.1 christos { 1207 1.1 christos enum address_class aclass; 1208 1.1 christos 1209 1.1 christos /* Used with LOC_COMPUTED. */ 1210 1.1 christos const struct symbol_computed_ops *ops_computed; 1211 1.1 christos 1212 1.1 christos /* Used with LOC_BLOCK. */ 1213 1.1 christos const struct symbol_block_ops *ops_block; 1214 1.1 christos 1215 1.1 christos /* Used with LOC_REGISTER and LOC_REGPARM_ADDR. */ 1216 1.1 christos const struct symbol_register_ops *ops_register; 1217 1.1 christos }; 1218 1.8 christos 1219 1.8 christos /* struct symbol has some subclasses. This enum is used to 1220 1.8 christos differentiate between them. */ 1221 1.8 christos 1222 1.8 christos enum symbol_subclass_kind 1223 1.8 christos { 1224 1.8 christos /* Plain struct symbol. */ 1225 1.8 christos SYMBOL_NONE, 1226 1.8 christos 1227 1.8 christos /* struct template_symbol. */ 1228 1.8 christos SYMBOL_TEMPLATE, 1229 1.8 christos 1230 1.8 christos /* struct rust_vtable_symbol. */ 1231 1.8 christos SYMBOL_RUST_VTABLE 1232 1.8 christos }; 1233 1.10 christos 1234 1.10 christos extern gdb::array_view<const struct symbol_impl> symbol_impls; 1235 1.1 christos 1236 1.1 christos /* This structure is space critical. See space comments at the top. */ 1237 1.11 christos 1238 1.1 christos struct symbol : public general_symbol_info, public allocate_on_obstack<symbol> 1239 1.9 christos { 1240 1.9 christos symbol () 1241 1.10 christos /* Class-initialization of bitfields is only allowed in C++20. */ 1242 1.10 christos : m_domain (UNDEF_DOMAIN), 1243 1.10 christos m_aclass_index (0), 1244 1.10 christos m_is_objfile_owned (1), 1245 1.10 christos m_is_argument (0), 1246 1.9 christos m_is_inlined (0), 1247 1.10 christos maybe_copied (0), 1248 1.10 christos subclass (SYMBOL_NONE), 1249 1.9 christos m_artificial (false) 1250 1.9 christos { 1251 1.10 christos /* We can't use an initializer list for members of a base class, and 1252 1.9 christos general_symbol_info needs to stay a POD type. */ 1253 1.10 christos m_name = nullptr; 1254 1.9 christos m_value.ivalue = 0; 1255 1.9 christos language_specific.obstack = nullptr; 1256 1.9 christos m_language = language_unknown; 1257 1.10 christos ada_mangled = 0; 1258 1.9 christos m_section = -1; 1259 1.10 christos /* GCC 4.8.5 (on CentOS 7) does not correctly compile class- 1260 1.9 christos initialization of unions, so we initialize it manually here. */ 1261 1.9 christos owner.symtab = nullptr; 1262 1.1 christos } 1263 1.9 christos 1264 1.10 christos symbol (const symbol &) = default; 1265 1.10 christos symbol &operator= (const symbol &) = default; 1266 1.10 christos 1267 1.10 christos void set_aclass_index (unsigned int aclass_index) 1268 1.10 christos { 1269 1.10 christos m_aclass_index = aclass_index; 1270 1.10 christos } 1271 1.10 christos 1272 1.10 christos const symbol_impl &impl () const 1273 1.10 christos { 1274 1.10 christos return symbol_impls[this->m_aclass_index]; 1275 1.10 christos } 1276 1.11 christos 1277 1.11 christos const symbol_block_ops *block_ops () const 1278 1.11 christos { 1279 1.11 christos return this->impl ().ops_block; 1280 1.11 christos } 1281 1.11 christos 1282 1.11 christos const symbol_computed_ops *computed_ops () const 1283 1.11 christos { 1284 1.11 christos return this->impl ().ops_computed; 1285 1.11 christos } 1286 1.11 christos 1287 1.11 christos const symbol_register_ops *register_ops () const 1288 1.11 christos { 1289 1.11 christos return this->impl ().ops_register; 1290 1.11 christos } 1291 1.10 christos 1292 1.10 christos address_class aclass () const 1293 1.10 christos { 1294 1.10 christos return this->impl ().aclass; 1295 1.10 christos } 1296 1.11 christos 1297 1.11 christos /* Return true if this symbol's domain matches FLAGS. */ 1298 1.11 christos bool matches (domain_search_flags flags) const; 1299 1.10 christos 1300 1.10 christos domain_enum domain () const 1301 1.10 christos { 1302 1.10 christos return m_domain; 1303 1.10 christos } 1304 1.10 christos 1305 1.10 christos void set_domain (domain_enum domain) 1306 1.10 christos { 1307 1.10 christos m_domain = domain; 1308 1.10 christos } 1309 1.10 christos 1310 1.10 christos bool is_objfile_owned () const 1311 1.10 christos { 1312 1.10 christos return m_is_objfile_owned; 1313 1.10 christos } 1314 1.10 christos 1315 1.10 christos void set_is_objfile_owned (bool is_objfile_owned) 1316 1.10 christos { 1317 1.10 christos m_is_objfile_owned = is_objfile_owned; 1318 1.10 christos } 1319 1.10 christos 1320 1.10 christos bool is_argument () const 1321 1.10 christos { 1322 1.10 christos return m_is_argument; 1323 1.10 christos } 1324 1.10 christos 1325 1.10 christos void set_is_argument (bool is_argument) 1326 1.10 christos { 1327 1.10 christos m_is_argument = is_argument; 1328 1.10 christos } 1329 1.10 christos 1330 1.10 christos bool is_inlined () const 1331 1.10 christos { 1332 1.10 christos return m_is_inlined; 1333 1.10 christos } 1334 1.10 christos 1335 1.10 christos void set_is_inlined (bool is_inlined) 1336 1.10 christos { 1337 1.10 christos m_is_inlined = is_inlined; 1338 1.10 christos } 1339 1.12 christos 1340 1.12 christos /* Return true if this symbol is a template function. Template 1341 1.12 christos functions actually are of type 'template_symbol' and have extra 1342 1.12 christos symbols (the template parameters) attached. */ 1343 1.12 christos 1344 1.10 christos bool is_template_function () const 1345 1.10 christos { 1346 1.10 christos return this->subclass == SYMBOL_TEMPLATE; 1347 1.10 christos } 1348 1.10 christos 1349 1.10 christos struct type *type () const 1350 1.10 christos { 1351 1.10 christos return m_type; 1352 1.10 christos } 1353 1.10 christos 1354 1.10 christos void set_type (struct type *type) 1355 1.10 christos { 1356 1.10 christos m_type = type; 1357 1.10 christos } 1358 1.11 christos 1359 1.10 christos unsigned int line () const 1360 1.10 christos { 1361 1.10 christos return m_line; 1362 1.10 christos } 1363 1.11 christos 1364 1.10 christos void set_line (unsigned int line) 1365 1.10 christos { 1366 1.10 christos m_line = line; 1367 1.10 christos } 1368 1.10 christos 1369 1.10 christos LONGEST value_longest () const 1370 1.10 christos { 1371 1.10 christos return m_value.ivalue; 1372 1.10 christos } 1373 1.10 christos 1374 1.10 christos void set_value_longest (LONGEST value) 1375 1.10 christos { 1376 1.10 christos m_value.ivalue = value; 1377 1.10 christos } 1378 1.10 christos 1379 1.10 christos CORE_ADDR value_address () const 1380 1.10 christos { 1381 1.11 christos if (this->maybe_copied) 1382 1.10 christos return this->get_maybe_copied_address (); 1383 1.10 christos else 1384 1.10 christos return m_value.address; 1385 1.10 christos } 1386 1.10 christos 1387 1.10 christos void set_value_address (CORE_ADDR address) 1388 1.10 christos { 1389 1.10 christos m_value.address = address; 1390 1.10 christos } 1391 1.10 christos 1392 1.10 christos const gdb_byte *value_bytes () const 1393 1.10 christos { 1394 1.10 christos return m_value.bytes; 1395 1.10 christos } 1396 1.10 christos 1397 1.10 christos void set_value_bytes (const gdb_byte *bytes) 1398 1.10 christos { 1399 1.10 christos m_value.bytes = bytes; 1400 1.10 christos } 1401 1.10 christos 1402 1.10 christos const common_block *value_common_block () const 1403 1.10 christos { 1404 1.10 christos return m_value.common_block; 1405 1.10 christos } 1406 1.10 christos 1407 1.10 christos void set_value_common_block (const common_block *common_block) 1408 1.10 christos { 1409 1.10 christos m_value.common_block = common_block; 1410 1.10 christos } 1411 1.11 christos 1412 1.10 christos const block *value_block () const; 1413 1.10 christos 1414 1.10 christos void set_value_block (const block *block) 1415 1.10 christos { 1416 1.10 christos m_value.block = block; 1417 1.10 christos } 1418 1.10 christos 1419 1.10 christos symbol *value_chain () const 1420 1.10 christos { 1421 1.10 christos return m_value.chain; 1422 1.10 christos } 1423 1.10 christos 1424 1.10 christos void set_value_chain (symbol *sym) 1425 1.10 christos { 1426 1.10 christos m_value.chain = sym; 1427 1.10 christos } 1428 1.10 christos 1429 1.10 christos /* Return true if this symbol was marked as artificial. */ 1430 1.10 christos bool is_artificial () const 1431 1.10 christos { 1432 1.10 christos return m_artificial; 1433 1.10 christos } 1434 1.10 christos 1435 1.10 christos /* Set the 'artificial' flag on this symbol. */ 1436 1.10 christos void set_is_artificial (bool artificial) 1437 1.10 christos { 1438 1.10 christos m_artificial = artificial; 1439 1.10 christos } 1440 1.10 christos 1441 1.10 christos /* Return the OBJFILE of this symbol. It is an error to call this 1442 1.10 christos if is_objfile_owned is false, which only happens for 1443 1.10 christos architecture-provided types. */ 1444 1.10 christos 1445 1.10 christos struct objfile *objfile () const; 1446 1.10 christos 1447 1.10 christos /* Return the ARCH of this symbol. */ 1448 1.10 christos 1449 1.10 christos struct gdbarch *arch () const; 1450 1.10 christos 1451 1.10 christos /* Return the symtab of this symbol. It is an error to call this if 1452 1.10 christos is_objfile_owned is false, which only happens for 1453 1.10 christos architecture-provided types. */ 1454 1.10 christos 1455 1.10 christos struct symtab *symtab () const; 1456 1.10 christos 1457 1.10 christos /* Set the symtab of this symbol to SYMTAB. It is an error to call 1458 1.10 christos this if is_objfile_owned is false, which only happens for 1459 1.10 christos architecture-provided types. */ 1460 1.10 christos 1461 1.1 christos void set_symtab (struct symtab *symtab); 1462 1.1 christos 1463 1.1 christos /* Data type of value */ 1464 1.10 christos 1465 1.1 christos struct type *m_type = nullptr; 1466 1.3 christos 1467 1.3 christos /* The owner of this symbol. 1468 1.3 christos Which one to use is defined by symbol.is_objfile_owned. */ 1469 1.3 christos 1470 1.3 christos union 1471 1.3 christos { 1472 1.3 christos /* The symbol table containing this symbol. This is the file associated 1473 1.3 christos with LINE. It can be NULL during symbols read-in but it is never NULL 1474 1.3 christos during normal operation. */ 1475 1.3 christos struct symtab *symtab; 1476 1.3 christos 1477 1.3 christos /* For types defined by the architecture. */ 1478 1.3 christos struct gdbarch *arch; 1479 1.1 christos } owner; 1480 1.1 christos 1481 1.1 christos /* Domain code. */ 1482 1.10 christos 1483 1.1 christos ENUM_BITFIELD(domain_enum) m_domain : SYMBOL_DOMAIN_BITS; 1484 1.1 christos 1485 1.1 christos /* Address class. This holds an index into the 'symbol_impls' 1486 1.1 christos table. The actual enum address_class value is stored there, 1487 1.1 christos alongside any per-class ops vectors. */ 1488 1.10 christos 1489 1.1 christos unsigned int m_aclass_index : SYMBOL_ACLASS_BITS; 1490 1.3 christos 1491 1.9 christos /* If non-zero then symbol is objfile-owned, use owner.symtab. 1492 1.3 christos Otherwise symbol is arch-owned, use owner.arch. */ 1493 1.10 christos 1494 1.3 christos unsigned int m_is_objfile_owned : 1; 1495 1.1 christos 1496 1.1 christos /* Whether this is an argument. */ 1497 1.10 christos 1498 1.1 christos unsigned m_is_argument : 1; 1499 1.1 christos 1500 1.10 christos /* Whether this is an inlined function (class LOC_BLOCK only). */ 1501 1.1 christos unsigned m_is_inlined : 1; 1502 1.9 christos 1503 1.9 christos /* For LOC_STATIC only, if this is set, then the symbol might be 1504 1.9 christos subject to copy relocation. In this case, a minimal symbol 1505 1.9 christos matching the symbol's linkage name is first looked for in the 1506 1.9 christos main objfile. If found, then that address is used; otherwise the 1507 1.9 christos address in this symbol is used. */ 1508 1.9 christos 1509 1.9 christos unsigned maybe_copied : 1; 1510 1.8 christos 1511 1.8 christos /* The concrete type of this symbol. */ 1512 1.8 christos 1513 1.1 christos ENUM_BITFIELD (symbol_subclass_kind) subclass : 2; 1514 1.10 christos 1515 1.10 christos /* Whether this symbol is artificial. */ 1516 1.10 christos 1517 1.10 christos bool m_artificial : 1; 1518 1.1 christos 1519 1.1 christos /* Line number of this symbol's definition, except for inlined 1520 1.1 christos functions. For an inlined function (class LOC_BLOCK and 1521 1.1 christos SYMBOL_INLINED set) this is the line number of the function's call 1522 1.1 christos site. Inlined function symbols are not definitions, and they are 1523 1.11 christos never found by symbol table lookup. 1524 1.1 christos If this symbol is arch-owned, LINE shall be zero. */ 1525 1.11 christos 1526 1.1 christos unsigned int m_line = 0; 1527 1.1 christos 1528 1.1 christos /* An arbitrary data pointer, allowing symbol readers to record 1529 1.1 christos additional information on a per-symbol basis. Note that this data 1530 1.6 christos must be allocated using the same obstack as the symbol itself. */ 1531 1.6 christos /* So far it is only used by: 1532 1.6 christos LOC_COMPUTED: to find the location information 1533 1.6 christos LOC_BLOCK (DWARF2 function): information used internally by the 1534 1.1 christos DWARF 2 code --- specifically, the location expression for the frame 1535 1.1 christos base for this function. */ 1536 1.1 christos /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better 1537 1.1 christos to add a magic symbol to the block containing this information, 1538 1.1 christos or to have a generic debug info annotation slot for symbols. */ 1539 1.9 christos 1540 1.1 christos void *aux_value = nullptr; 1541 1.9 christos 1542 1.11 christos struct symbol *hash_next = nullptr; 1543 1.11 christos 1544 1.11 christos private: 1545 1.11 christos /* Return the address of this symbol. The MAYBE_COPIED flag must be set. 1546 1.11 christos If the symbol appears in the main program's minimal symbols, then 1547 1.11 christos that minsym's address is returned; otherwise, this symbol's address is 1548 1.11 christos returned. */ 1549 1.1 christos CORE_ADDR get_maybe_copied_address () const; 1550 1.1 christos }; 1551 1.6 christos 1552 1.6 christos /* Several lookup functions return both a symbol and the block in which the 1553 1.6 christos symbol is found. This structure is used in these cases. */ 1554 1.6 christos 1555 1.6 christos struct block_symbol 1556 1.6 christos { 1557 1.6 christos /* The symbol that was found, or NULL if no symbol was found. */ 1558 1.6 christos struct symbol *symbol; 1559 1.6 christos 1560 1.6 christos /* If SYMBOL is not NULL, then this is the block in which the symbol is 1561 1.6 christos defined. */ 1562 1.6 christos const struct block *block; 1563 1.6 christos }; 1564 1.3 christos 1565 1.3 christos /* Note: There is no accessor macro for symbol.owner because it is 1566 1.3 christos "private". */ 1567 1.1 christos 1568 1.1 christos #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value 1569 1.11 christos 1570 1.11 christos inline const block * 1571 1.11 christos symbol::value_block () const 1572 1.11 christos { 1573 1.11 christos if (const symbol_block_ops *block_ops = this->block_ops (); 1574 1.11 christos block_ops != nullptr && block_ops->get_block_value != nullptr) 1575 1.11 christos return block_ops->get_block_value (this); 1576 1.11 christos 1577 1.11 christos return m_value.block; 1578 1.11 christos } 1579 1.1 christos 1580 1.1 christos extern int register_symbol_computed_impl (enum address_class, 1581 1.1 christos const struct symbol_computed_ops *); 1582 1.1 christos 1583 1.1 christos extern int register_symbol_block_impl (enum address_class aclass, 1584 1.1 christos const struct symbol_block_ops *ops); 1585 1.1 christos 1586 1.1 christos extern int register_symbol_register_impl (enum address_class, 1587 1.1 christos const struct symbol_register_ops *); 1588 1.1 christos 1589 1.8 christos /* An instance of this type is used to represent a C++ template 1590 1.12 christos function. A symbol is really of this type iff 1591 1.1 christos symbol::is_template_function is true. */ 1592 1.8 christos 1593 1.1 christos struct template_symbol : public symbol 1594 1.1 christos { 1595 1.9 christos /* The number of template arguments. */ 1596 1.1 christos int n_template_arguments = 0; 1597 1.1 christos 1598 1.1 christos /* The template arguments. This is an array with 1599 1.9 christos N_TEMPLATE_ARGUMENTS elements. */ 1600 1.1 christos struct symbol **template_arguments = nullptr; 1601 1.1 christos }; 1602 1.8 christos 1603 1.8 christos /* A symbol that represents a Rust virtual table object. */ 1604 1.8 christos 1605 1.8 christos struct rust_vtable_symbol : public symbol 1606 1.8 christos { 1607 1.8 christos /* The concrete type for which this vtable was created; that is, in 1608 1.9 christos "impl Trait for Type", this is "Type". */ 1609 1.8 christos struct type *concrete_type = nullptr; 1610 1.8 christos }; 1611 1.1 christos 1612 1.1 christos 1613 1.1 christos /* Each item represents a line-->pc (or the reverse) mapping. This is 1615 1.1 christos somewhat more wasteful of space than one might wish, but since only 1616 1.1 christos the files which are actually debugged are read in to core, we don't 1617 1.1 christos waste much space. */ 1618 1.1 christos 1619 1.11 christos struct linetable_entry 1620 1.11 christos { 1621 1.11 christos /* Set the (unrelocated) PC for this entry. */ 1622 1.11 christos void set_unrelocated_pc (unrelocated_addr pc) 1623 1.11 christos { m_pc = pc; } 1624 1.11 christos 1625 1.11 christos /* Return the unrelocated PC for this entry. */ 1626 1.11 christos unrelocated_addr unrelocated_pc () const 1627 1.11 christos { return m_pc; } 1628 1.11 christos 1629 1.11 christos /* Return the relocated PC for this entry. */ 1630 1.11 christos CORE_ADDR pc (const struct objfile *objfile) const; 1631 1.11 christos 1632 1.11 christos bool operator< (const linetable_entry &other) const 1633 1.11 christos { 1634 1.11 christos if (m_pc == other.m_pc 1635 1.11 christos && (line != 0) != (other.line != 0)) 1636 1.11 christos return line == 0; 1637 1.11 christos return m_pc < other.m_pc; 1638 1.11 christos } 1639 1.11 christos 1640 1.11 christos /* Two entries are equal if they have the same line and PC. The 1641 1.11 christos other members are ignored. */ 1642 1.11 christos bool operator== (const linetable_entry &other) const 1643 1.9 christos { return line == other.line && m_pc == other.m_pc; } 1644 1.1 christos 1645 1.9 christos /* The line number for this entry. */ 1646 1.9 christos int line; 1647 1.11 christos 1648 1.9 christos /* True if this PC is a good location to place a breakpoint for LINE. */ 1649 1.10 christos bool is_stmt : 1; 1650 1.10 christos 1651 1.10 christos /* True if this location is a good location to place a breakpoint after a 1652 1.10 christos function prologue. */ 1653 1.11 christos bool prologue_end : 1; 1654 1.11 christos 1655 1.11 christos /* True if this location marks the start of the epilogue. */ 1656 1.11 christos bool epilogue_begin : 1; 1657 1.11 christos 1658 1.9 christos private: 1659 1.11 christos 1660 1.1 christos /* The address for this entry. */ 1661 1.1 christos unrelocated_addr m_pc; 1662 1.1 christos }; 1663 1.1 christos 1664 1.1 christos /* The order of entries in the linetable is significant. They should 1665 1.1 christos be sorted by increasing values of the pc field. If there is more than 1666 1.1 christos one entry for a given pc, then I'm not sure what should happen (and 1667 1.1 christos I not sure whether we currently handle it the best way). 1668 1.1 christos 1669 1.1 christos Example: a C for statement generally looks like this 1670 1.1 christos 1671 1.1 christos 10 0x100 - for the init/test part of a for stmt. 1672 1.1 christos 20 0x200 1673 1.1 christos 30 0x300 1674 1.1 christos 10 0x400 - for the increment part of a for stmt. 1675 1.1 christos 1676 1.1 christos If an entry has a line number of zero, it marks the start of a PC 1677 1.1 christos range for which no line number information is available. It is 1678 1.1 christos acceptable, though wasteful of table space, for such a range to be 1679 1.1 christos zero length. */ 1680 1.1 christos 1681 1.1 christos struct linetable 1682 1.1 christos { 1683 1.1 christos int nitems; 1684 1.1 christos 1685 1.1 christos /* Actually NITEMS elements. If you don't like this use of the 1686 1.1 christos `struct hack', you can shove it up your ANSI (seriously, if the 1687 1.1 christos committee tells us how to do it, we can probably go along). */ 1688 1.1 christos struct linetable_entry item[1]; 1689 1.1 christos }; 1690 1.1 christos 1691 1.1 christos /* How to relocate the symbols from each section in a symbol file. 1692 1.9 christos The ordering and meaning of the offsets is file-type-dependent; 1693 1.1 christos typically it is indexed by section numbers or symbol types or 1694 1.9 christos something like that. */ 1695 1.1 christos 1696 1.1 christos typedef std::vector<CORE_ADDR> section_offsets; 1697 1.3 christos 1698 1.1 christos /* Each source file or header is represented by a struct symtab. 1699 1.1 christos The name "symtab" is historical, another name for it is "filetab". 1700 1.1 christos These objects are chained through the `next' field. */ 1701 1.1 christos 1702 1.10 christos struct symtab 1703 1.10 christos { 1704 1.10 christos struct compunit_symtab *compunit () const 1705 1.10 christos { 1706 1.10 christos return m_compunit; 1707 1.10 christos } 1708 1.10 christos 1709 1.10 christos void set_compunit (struct compunit_symtab *compunit) 1710 1.10 christos { 1711 1.10 christos m_compunit = compunit; 1712 1.11 christos } 1713 1.10 christos 1714 1.10 christos const struct linetable *linetable () const 1715 1.10 christos { 1716 1.10 christos return m_linetable; 1717 1.11 christos } 1718 1.10 christos 1719 1.10 christos void set_linetable (const struct linetable *linetable) 1720 1.10 christos { 1721 1.10 christos m_linetable = linetable; 1722 1.10 christos } 1723 1.10 christos 1724 1.10 christos enum language language () const 1725 1.10 christos { 1726 1.10 christos return m_language; 1727 1.10 christos } 1728 1.10 christos 1729 1.10 christos void set_language (enum language language) 1730 1.10 christos { 1731 1.10 christos m_language = language; 1732 1.12 christos } 1733 1.12 christos 1734 1.12 christos /* Return the current full name of this symtab. */ 1735 1.12 christos const char *fullname () const 1736 1.12 christos { return m_fullname; } 1737 1.12 christos 1738 1.12 christos /* Transfer ownership of the current full name to the caller. The 1739 1.12 christos full name is reset to nullptr. */ 1740 1.12 christos gdb::unique_xmalloc_ptr<char> release_fullname () 1741 1.12 christos { 1742 1.12 christos gdb::unique_xmalloc_ptr<char> result (m_fullname); 1743 1.12 christos m_fullname = nullptr; 1744 1.12 christos return result; 1745 1.12 christos } 1746 1.12 christos 1747 1.12 christos /* Set the current full name to NAME, transferring ownership to this 1748 1.12 christos symtab. */ 1749 1.12 christos void set_fullname (gdb::unique_xmalloc_ptr<char> name) 1750 1.12 christos { 1751 1.12 christos gdb_assert (m_fullname == nullptr); 1752 1.12 christos m_fullname = name.release (); 1753 1.5 christos } 1754 1.5 christos 1755 1.1 christos /* Unordered chain of all filetabs in the compunit, with the exception 1756 1.1 christos that the "main" source file is the first entry in the list. */ 1757 1.1 christos 1758 1.10 christos struct symtab *next; 1759 1.10 christos 1760 1.10 christos /* Name of this source file, in a form appropriate to print to the user. 1761 1.1 christos 1762 1.1 christos This pointer is never nullptr. */ 1763 1.1 christos 1764 1.10 christos const char *filename; 1765 1.10 christos 1766 1.10 christos /* Filename for this source file, used as an identifier to link with 1767 1.10 christos related objects such as associated macro_source_file objects. It must 1768 1.10 christos therefore match the name of any macro_source_file object created for this 1769 1.10 christos source file. The value can be the same as FILENAME if it is known to 1770 1.10 christos follow that rule, or another form of the same file name, this is up to 1771 1.10 christos the specific debug info reader. 1772 1.10 christos 1773 1.10 christos This pointer is never nullptr.*/ 1774 1.12 christos const char *filename_for_id; 1775 1.12 christos 1776 1.12 christos private: 1777 1.12 christos 1778 1.12 christos /* Backlink to containing compunit symtab. */ 1779 1.12 christos 1780 1.12 christos struct compunit_symtab *m_compunit; 1781 1.12 christos 1782 1.12 christos /* Table mapping core addresses to line numbers for this file. 1783 1.12 christos Can be NULL if none. Never shared between different symtabs. */ 1784 1.12 christos 1785 1.1 christos const struct linetable *m_linetable; 1786 1.1 christos 1787 1.10 christos /* Language of this source file. */ 1788 1.1 christos 1789 1.3 christos enum language m_language; 1790 1.3 christos 1791 1.3 christos /* Full name of file as found by searching the source path. 1792 1.12 christos NULL if not yet known. */ 1793 1.3 christos 1794 1.3 christos char *m_fullname; 1795 1.10 christos }; 1796 1.10 christos 1797 1.10 christos /* A range adapter to allowing iterating over all the file tables in a list. */ 1798 1.3 christos 1799 1.3 christos using symtab_range = next_range<symtab>; 1800 1.3 christos 1801 1.3 christos /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well 1802 1.3 christos as the list of all source files (what gdb has historically associated with 1803 1.3 christos the term "symtab"). 1804 1.3 christos Additional information is recorded here that is common to all symtabs in a 1805 1.3 christos compilation unit (DWARF or otherwise). 1806 1.3 christos 1807 1.3 christos Example: 1808 1.3 christos For the case of a program built out of these files: 1809 1.3 christos 1810 1.3 christos foo.c 1811 1.3 christos foo1.h 1812 1.3 christos foo2.h 1813 1.3 christos bar.c 1814 1.3 christos foo1.h 1815 1.3 christos bar.h 1816 1.3 christos 1817 1.3 christos This is recorded as: 1818 1.10 christos 1819 1.10 christos objfile -> foo.c(cu) -> bar.c(cu) -> NULL 1820 1.10 christos | | 1821 1.10 christos v v 1822 1.10 christos foo.c bar.c 1823 1.10 christos | | 1824 1.10 christos v v 1825 1.10 christos foo1.h foo1.h 1826 1.10 christos | | 1827 1.10 christos v v 1828 1.10 christos foo2.h bar.h 1829 1.10 christos | | 1830 1.3 christos v v 1831 1.3 christos NULL NULL 1832 1.3 christos 1833 1.3 christos where "foo.c(cu)" and "bar.c(cu)" are struct compunit_symtab objects, 1834 1.3 christos and the files foo.c, etc. are struct symtab objects. */ 1835 1.3 christos 1836 1.10 christos struct compunit_symtab 1837 1.10 christos { 1838 1.10 christos struct objfile *objfile () const 1839 1.10 christos { 1840 1.10 christos return m_objfile; 1841 1.10 christos } 1842 1.10 christos 1843 1.10 christos void set_objfile (struct objfile *objfile) 1844 1.10 christos { 1845 1.10 christos m_objfile = objfile; 1846 1.10 christos } 1847 1.10 christos 1848 1.10 christos symtab_range filetabs () const 1849 1.10 christos { 1850 1.10 christos return symtab_range (m_filetabs); 1851 1.10 christos } 1852 1.10 christos 1853 1.10 christos void add_filetab (symtab *filetab) 1854 1.10 christos { 1855 1.10 christos if (m_filetabs == nullptr) 1856 1.10 christos { 1857 1.10 christos m_filetabs = filetab; 1858 1.10 christos m_last_filetab = filetab; 1859 1.10 christos } 1860 1.10 christos else 1861 1.10 christos { 1862 1.10 christos m_last_filetab->next = filetab; 1863 1.10 christos m_last_filetab = filetab; 1864 1.10 christos } 1865 1.10 christos } 1866 1.10 christos 1867 1.10 christos const char *debugformat () const 1868 1.10 christos { 1869 1.10 christos return m_debugformat; 1870 1.10 christos } 1871 1.10 christos 1872 1.10 christos void set_debugformat (const char *debugformat) 1873 1.10 christos { 1874 1.10 christos m_debugformat = debugformat; 1875 1.10 christos } 1876 1.10 christos 1877 1.10 christos const char *producer () const 1878 1.10 christos { 1879 1.10 christos return m_producer; 1880 1.10 christos } 1881 1.10 christos 1882 1.10 christos void set_producer (const char *producer) 1883 1.10 christos { 1884 1.10 christos m_producer = producer; 1885 1.10 christos } 1886 1.10 christos 1887 1.10 christos const char *dirname () const 1888 1.10 christos { 1889 1.10 christos return m_dirname; 1890 1.10 christos } 1891 1.10 christos 1892 1.10 christos void set_dirname (const char *dirname) 1893 1.10 christos { 1894 1.10 christos m_dirname = dirname; 1895 1.10 christos } 1896 1.10 christos 1897 1.10 christos struct blockvector *blockvector () 1898 1.10 christos { 1899 1.10 christos return m_blockvector; 1900 1.10 christos } 1901 1.10 christos 1902 1.10 christos const struct blockvector *blockvector () const 1903 1.10 christos { 1904 1.10 christos return m_blockvector; 1905 1.10 christos } 1906 1.10 christos 1907 1.10 christos void set_blockvector (struct blockvector *blockvector) 1908 1.10 christos { 1909 1.10 christos m_blockvector = blockvector; 1910 1.10 christos } 1911 1.10 christos 1912 1.10 christos bool locations_valid () const 1913 1.10 christos { 1914 1.10 christos return m_locations_valid; 1915 1.10 christos } 1916 1.10 christos 1917 1.10 christos void set_locations_valid (bool locations_valid) 1918 1.10 christos { 1919 1.10 christos m_locations_valid = locations_valid; 1920 1.10 christos } 1921 1.10 christos 1922 1.10 christos bool epilogue_unwind_valid () const 1923 1.10 christos { 1924 1.10 christos return m_epilogue_unwind_valid; 1925 1.10 christos } 1926 1.10 christos 1927 1.10 christos void set_epilogue_unwind_valid (bool epilogue_unwind_valid) 1928 1.10 christos { 1929 1.10 christos m_epilogue_unwind_valid = epilogue_unwind_valid; 1930 1.10 christos } 1931 1.10 christos 1932 1.10 christos struct macro_table *macro_table () const 1933 1.10 christos { 1934 1.10 christos return m_macro_table; 1935 1.10 christos } 1936 1.10 christos 1937 1.10 christos void set_macro_table (struct macro_table *macro_table) 1938 1.10 christos { 1939 1.10 christos m_macro_table = macro_table; 1940 1.10 christos } 1941 1.10 christos 1942 1.10 christos /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab. 1943 1.10 christos 1944 1.10 christos PRIMARY_FILETAB must already be a filetab of this compunit symtab. */ 1945 1.10 christos 1946 1.10 christos void set_primary_filetab (symtab *primary_filetab); 1947 1.10 christos 1948 1.10 christos /* Return the primary filetab of the compunit. */ 1949 1.10 christos symtab *primary_filetab () const; 1950 1.12 christos 1951 1.10 christos /* Set m_call_site_htab. */ 1952 1.10 christos void set_call_site_htab (call_site_htab_t &&call_site_htab); 1953 1.10 christos 1954 1.10 christos /* Find call_site info for PC. */ 1955 1.10 christos call_site *find_call_site (CORE_ADDR pc) const; 1956 1.10 christos 1957 1.10 christos /* Return the language of this compunit_symtab. */ 1958 1.12 christos enum language language () const; 1959 1.12 christos 1960 1.12 christos /* Clear any cached source file names. */ 1961 1.12 christos void forget_cached_source_info (); 1962 1.12 christos 1963 1.12 christos /* This is called when an objfile is being destroyed and will free 1964 1.12 christos any resources used by this compunit_symtab. Normally a 1965 1.12 christos destructor would be used instead, but at the moment 1966 1.12 christos compunit_symtab objects are allocated on an obstack. */ 1967 1.3 christos void finalize (); 1968 1.3 christos 1969 1.3 christos /* Unordered chain of all compunit symtabs of this objfile. */ 1970 1.3 christos struct compunit_symtab *next; 1971 1.10 christos 1972 1.3 christos /* Object file from which this symtab information was read. */ 1973 1.3 christos struct objfile *m_objfile; 1974 1.3 christos 1975 1.3 christos /* Name of the symtab. 1976 1.3 christos This is *not* intended to be a usable filename, and is 1977 1.3 christos for debugging purposes only. */ 1978 1.3 christos const char *name; 1979 1.3 christos 1980 1.3 christos /* Unordered list of file symtabs, except that by convention the "main" 1981 1.3 christos source file (e.g., .c, .cc) is guaranteed to be first. 1982 1.10 christos Each symtab is a file, either the "main" source file (e.g., .c, .cc) 1983 1.3 christos or header (e.g., .h). */ 1984 1.3 christos symtab *m_filetabs; 1985 1.3 christos 1986 1.3 christos /* Last entry in FILETABS list. 1987 1.3 christos Subfiles are added to the end of the list so they accumulate in order, 1988 1.3 christos with the main source subfile living at the front. 1989 1.10 christos The main reason is so that the main source file symtab is at the head 1990 1.3 christos of the list, and the rest appear in order for debugging convenience. */ 1991 1.3 christos symtab *m_last_filetab; 1992 1.3 christos 1993 1.1 christos /* Non-NULL string that identifies the format of the debugging information, 1994 1.1 christos such as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful 1995 1.10 christos for automated testing of gdb but may also be information that is 1996 1.1 christos useful to the user. */ 1997 1.3 christos const char *m_debugformat; 1998 1.10 christos 1999 1.1 christos /* String of producer version information, or NULL if we don't know. */ 2000 1.3 christos const char *m_producer; 2001 1.10 christos 2002 1.1 christos /* Directory in which it was compiled, or NULL if we don't know. */ 2003 1.3 christos const char *m_dirname; 2004 1.3 christos 2005 1.10 christos /* List of all symbol scope blocks for this symtab. It is shared among 2006 1.1 christos all symtabs in a given compilation unit. */ 2007 1.3 christos struct blockvector *m_blockvector; 2008 1.3 christos 2009 1.3 christos /* Symtab has been compiled with both optimizations and debug info so that 2010 1.10 christos GDB may stop skipping prologues as variables locations are valid already 2011 1.1 christos at function entry points. */ 2012 1.3 christos unsigned int m_locations_valid : 1; 2013 1.3 christos 2014 1.10 christos /* DWARF unwinder for this CU is valid even for epilogues (PC at the return 2015 1.1 christos instruction). This is supported by GCC since 4.5.0. */ 2016 1.1 christos unsigned int m_epilogue_unwind_valid : 1; 2017 1.12 christos 2018 1.1 christos /* struct call_site entries for this compilation unit or NULL. */ 2019 1.3 christos call_site_htab_t *m_call_site_htab; 2020 1.3 christos 2021 1.3 christos /* The macro table for this symtab. Like the blockvector, this 2022 1.3 christos is shared between different symtabs in a given compilation unit. 2023 1.10 christos It's debatable whether it *should* be shared among all the symtabs in 2024 1.1 christos the given compilation unit, but it currently is. */ 2025 1.1 christos struct macro_table *m_macro_table; 2026 1.3 christos 2027 1.3 christos /* If non-NULL, then this points to a NULL-terminated vector of 2028 1.3 christos included compunits. When searching the static or global 2029 1.1 christos block of this compunit, the corresponding block of all 2030 1.1 christos included compunits will also be searched. Note that this 2031 1.3 christos list must be flattened -- the symbol reader is responsible for 2032 1.3 christos ensuring that this vector contains the transitive closure of all 2033 1.3 christos included compunits. */ 2034 1.3 christos struct compunit_symtab **includes; 2035 1.3 christos 2036 1.3 christos /* If this is an included compunit, this points to one includer 2037 1.3 christos of the table. This user is considered the canonical compunit 2038 1.3 christos containing this one. An included compunit may itself be 2039 1.3 christos included by another. */ 2040 1.1 christos struct compunit_symtab *user; 2041 1.10 christos }; 2042 1.1 christos 2043 1.9 christos using compunit_symtab_range = next_range<compunit_symtab>; 2044 1.9 christos 2045 1.9 christos /* Return true if this symtab is the "main" symtab of its compunit_symtab. */ 2046 1.9 christos 2047 1.9 christos static inline bool 2048 1.10 christos is_main_symtab_of_compunit_symtab (struct symtab *symtab) 2049 1.9 christos { 2050 1.11 christos return symtab == symtab->compunit ()->primary_filetab (); 2051 1.11 christos } 2052 1.11 christos 2053 1.11 christos /* Return true if epilogue unwind info of CUST is valid. */ 2054 1.11 christos 2055 1.11 christos static inline bool 2056 1.11 christos compunit_epilogue_unwind_valid (struct compunit_symtab *cust) 2057 1.11 christos { 2058 1.11 christos /* In absence of producer information, assume epilogue unwind info is 2059 1.11 christos valid. */ 2060 1.11 christos if (cust == nullptr) 2061 1.11 christos return true; 2062 1.11 christos 2063 1.1 christos return cust->epilogue_unwind_valid (); 2064 1.1 christos } 2065 1.1 christos 2066 1.1 christos 2068 1.1 christos /* The virtual function table is now an array of structures which have the 2069 1.1 christos form { int16 offset, delta; void *pfn; }. 2070 1.1 christos 2071 1.1 christos In normal virtual function tables, OFFSET is unused. 2072 1.1 christos DELTA is the amount which is added to the apparent object's base 2073 1.1 christos address in order to point to the actual object to which the 2074 1.1 christos virtual function should be applied. 2075 1.1 christos PFN is a pointer to the virtual function. 2076 1.1 christos 2077 1.1 christos Note that this macro is g++ specific (FIXME). */ 2078 1.1 christos 2079 1.1 christos #define VTBL_FNADDR_OFFSET 2 2080 1.1 christos 2081 1.1 christos /* External variables and functions for the objects described above. */ 2082 1.1 christos 2083 1.1 christos /* True if we are nested inside psymtab_to_symtab. */ 2084 1.1 christos 2085 1.1 christos extern int currently_reading_symtab; 2086 1.1 christos 2087 1.1 christos /* symtab.c lookup functions */ 2088 1.1 christos 2089 1.1 christos extern const char multiple_symbols_ask[]; 2090 1.1 christos extern const char multiple_symbols_all[]; 2091 1.1 christos extern const char multiple_symbols_cancel[]; 2092 1.12 christos 2093 1.1 christos const char *multiple_symbols_select_mode (void); 2094 1.12 christos 2095 1.1 christos /* Lookup a symbol table in PSPACE by source file name. */ 2096 1.1 christos 2097 1.1 christos extern symtab *lookup_symtab (program_space *pspace, const char *name); 2098 1.1 christos 2099 1.1 christos /* An object of this type is passed as the 'is_a_field_of_this' 2100 1.1 christos argument to lookup_symbol and lookup_symbol_in_language. */ 2101 1.1 christos 2102 1.1 christos struct field_of_this_result 2103 1.1 christos { 2104 1.1 christos /* The type in which the field was found. If this is NULL then the 2105 1.1 christos symbol was not found in 'this'. If non-NULL, then one of the 2106 1.1 christos other fields will be non-NULL as well. */ 2107 1.1 christos 2108 1.1 christos struct type *type; 2109 1.1 christos 2110 1.1 christos /* If the symbol was found as an ordinary field of 'this', then this 2111 1.1 christos is non-NULL and points to the particular field. */ 2112 1.3 christos 2113 1.1 christos struct field *field; 2114 1.1 christos 2115 1.1 christos /* If the symbol was found as a function field of 'this', then this 2116 1.1 christos is non-NULL and points to the particular field. */ 2117 1.1 christos 2118 1.3 christos struct fn_fieldlist *fn_field; 2119 1.3 christos }; 2120 1.3 christos 2121 1.3 christos /* Find the definition for a specified symbol name NAME 2122 1.3 christos in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK 2123 1.3 christos if non-NULL or from global/static blocks if BLOCK is NULL. 2124 1.3 christos Returns the struct symbol pointer, or NULL if no symbol is found. 2125 1.3 christos C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if 2126 1.1 christos NAME is a field of the current implied argument `this'. If so fill in the 2127 1.6 christos fields of IS_A_FIELD_OF_THIS, otherwise the fields are set to NULL. 2128 1.6 christos The symbol's section is fixed up if necessary. */ 2129 1.6 christos 2130 1.11 christos extern struct block_symbol 2131 1.6 christos lookup_symbol_in_language (const char *, 2132 1.6 christos const struct block *, 2133 1.1 christos const domain_search_flags, 2134 1.3 christos enum language, 2135 1.1 christos struct field_of_this_result *); 2136 1.6 christos 2137 1.6 christos /* Same as lookup_symbol_in_language, but using the current language. */ 2138 1.11 christos 2139 1.6 christos extern struct block_symbol lookup_symbol (const char *, 2140 1.1 christos const struct block *, 2141 1.8 christos const domain_search_flags, 2142 1.8 christos struct field_of_this_result *); 2143 1.8 christos 2144 1.8 christos /* Find the definition for a specified symbol search name in domain 2145 1.9 christos DOMAIN, visible from lexical block BLOCK if non-NULL or from 2146 1.8 christos global/static blocks if BLOCK is NULL. The passed-in search name 2147 1.8 christos should not come from the user; instead it should already be a 2148 1.8 christos search name as retrieved from a search_name () call. See definition of 2149 1.8 christos symbol_name_match_type::SEARCH_NAME. Returns the struct symbol 2150 1.11 christos pointer, or NULL if no symbol is found. The symbol's section is 2151 1.11 christos fixed up if necessary. */ 2152 1.11 christos 2153 1.11 christos extern struct block_symbol lookup_symbol_search_name 2154 1.8 christos (const char *search_name, 2155 1.1 christos const struct block *block, 2156 1.1 christos domain_search_flags domain); 2157 1.1 christos 2158 1.1 christos /* Some helper functions for languages that need to write their own 2159 1.3 christos lookup_symbol_nonlocal functions. */ 2160 1.6 christos 2161 1.3 christos /* Lookup a symbol in the static block associated to BLOCK, if there 2162 1.6 christos is one; do nothing if BLOCK is NULL or a global block. 2163 1.6 christos Upon success fixes up the symbol's section if necessary. */ 2164 1.6 christos 2165 1.11 christos extern struct block_symbol 2166 1.3 christos lookup_symbol_in_static_block (const char *name, 2167 1.3 christos const struct block *block, 2168 1.6 christos const domain_search_flags domain); 2169 1.1 christos 2170 1.11 christos /* Search all static file-level symbols for NAME from DOMAIN. 2171 1.11 christos Upon success fixes up the symbol's section if necessary. */ 2172 1.1 christos 2173 1.3 christos extern struct block_symbol lookup_static_symbol 2174 1.3 christos (const char *name, const domain_search_flags domain); 2175 1.3 christos 2176 1.3 christos /* Lookup a symbol in all files' global blocks. 2177 1.3 christos 2178 1.3 christos If BLOCK is non-NULL then it is used for two things: 2179 1.3 christos 1) If a target-specific lookup routine for libraries exists, then use the 2180 1.3 christos routine for the objfile of BLOCK, and 2181 1.1 christos 2) The objfile of BLOCK is used to assist in determining the search order 2182 1.6 christos if the target requires it. 2183 1.3 christos See gdbarch_iterate_over_objfiles_in_search_order. 2184 1.6 christos 2185 1.6 christos Upon success fixes up the symbol's section if necessary. */ 2186 1.6 christos 2187 1.11 christos extern struct block_symbol 2188 1.1 christos lookup_global_symbol (const char *name, 2189 1.3 christos const struct block *block, 2190 1.6 christos const domain_search_flags domain); 2191 1.3 christos 2192 1.6 christos /* Lookup a symbol in block BLOCK. 2193 1.6 christos Upon success fixes up the symbol's section if necessary. */ 2194 1.8 christos 2195 1.6 christos extern struct symbol * 2196 1.11 christos lookup_symbol_in_block (const char *name, 2197 1.3 christos symbol_name_match_type match_type, 2198 1.3 christos const struct block *block, 2199 1.3 christos const domain_search_flags domain); 2200 1.1 christos 2201 1.6 christos /* Look up the `this' symbol for LANG in BLOCK. Return the symbol if 2202 1.6 christos found, or NULL if not found. */ 2203 1.6 christos 2204 1.1 christos extern struct block_symbol 2205 1.3 christos lookup_language_this (const struct language_defn *lang, 2206 1.1 christos const struct block *block); 2207 1.1 christos 2208 1.1 christos /* Lookup a [struct, union, enum] by name, within a specified block. */ 2209 1.1 christos 2210 1.1 christos extern struct type *lookup_struct (const char *, const struct block *); 2211 1.1 christos 2212 1.1 christos extern struct type *lookup_union (const char *, const struct block *); 2213 1.1 christos 2214 1.1 christos extern struct type *lookup_enum (const char *, const struct block *); 2215 1.8 christos 2216 1.8 christos /* from blockframe.c: */ 2217 1.8 christos 2218 1.1 christos /* lookup the function symbol corresponding to the address. The 2219 1.1 christos return value will not be an inlined function; the containing 2220 1.1 christos function will be returned instead. */ 2221 1.8 christos 2222 1.8 christos extern struct symbol *find_pc_function (CORE_ADDR); 2223 1.8 christos 2224 1.1 christos /* lookup the function corresponding to the address and section. The 2225 1.1 christos return value will not be an inlined function; the containing 2226 1.1 christos function will be returned instead. */ 2227 1.8 christos 2228 1.8 christos extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *); 2229 1.8 christos 2230 1.8 christos /* lookup the function symbol corresponding to the address and 2231 1.8 christos section. The return value will be the closest enclosing function, 2232 1.8 christos which might be an inline function. */ 2233 1.8 christos 2234 1.8 christos extern struct symbol *find_pc_sect_containing_function 2235 1.8 christos (CORE_ADDR pc, struct obj_section *section); 2236 1.8 christos 2237 1.8 christos /* Find the symbol at the given address. Returns NULL if no symbol 2238 1.8 christos found. Only exact matches for ADDRESS are considered. */ 2239 1.8 christos 2240 1.8 christos extern struct symbol *find_symbol_at_address (CORE_ADDR); 2241 1.8 christos 2242 1.8 christos /* Finds the "function" (text symbol) that is smaller than PC but 2243 1.8 christos greatest of all of the potential text symbols in SECTION. Sets 2244 1.8 christos *NAME and/or *ADDRESS conditionally if that pointer is non-null. 2245 1.8 christos If ENDADDR is non-null, then set *ENDADDR to be the end of the 2246 1.8 christos function (exclusive). If the optional parameter BLOCK is non-null, 2247 1.8 christos then set *BLOCK to the address of the block corresponding to the 2248 1.8 christos function symbol, if such a symbol could be found during the lookup; 2249 1.9 christos nullptr is used as a return value for *BLOCK if no block is found. 2250 1.9 christos This function either succeeds or fails (not halfway succeeds). If 2251 1.8 christos it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real 2252 1.8 christos information and returns true. If it fails, it sets *NAME, *ADDRESS 2253 1.8 christos and *ENDADDR to zero and returns false. 2254 1.8 christos 2255 1.8 christos If the function in question occupies non-contiguous ranges, 2256 1.8 christos *ADDRESS and *ENDADDR are (subject to the conditions noted above) set 2257 1.8 christos to the start and end of the range in which PC is found. Thus 2258 1.8 christos *ADDRESS <= PC < *ENDADDR with no intervening gaps (in which ranges 2259 1.8 christos from other functions might be found). 2260 1.8 christos 2261 1.8 christos This property allows find_pc_partial_function to be used (as it had 2262 1.8 christos been prior to the introduction of non-contiguous range support) by 2263 1.8 christos various tdep files for finding a start address and limit address 2264 1.8 christos for prologue analysis. This still isn't ideal, however, because we 2265 1.8 christos probably shouldn't be doing prologue analysis (in which 2266 1.8 christos instructions are scanned to determine frame size and stack layout) 2267 1.8 christos for any range that doesn't contain the entry pc. Moreover, a good 2268 1.8 christos argument can be made that prologue analysis ought to be performed 2269 1.8 christos starting from the entry pc even when PC is within some other range. 2270 1.8 christos This might suggest that *ADDRESS and *ENDADDR ought to be set to the 2271 1.8 christos limits of the entry pc range, but that will cause the 2272 1.8 christos *ADDRESS <= PC < *ENDADDR condition to be violated; many of the 2273 1.8 christos callers of find_pc_partial_function expect this condition to hold. 2274 1.8 christos 2275 1.8 christos Callers which require the start and/or end addresses for the range 2276 1.9 christos containing the entry pc should instead call 2277 1.9 christos find_function_entry_range_from_pc. */ 2278 1.9 christos 2279 1.9 christos extern bool find_pc_partial_function (CORE_ADDR pc, const char **name, 2280 1.9 christos CORE_ADDR *address, CORE_ADDR *endaddr, 2281 1.9 christos const struct block **block = nullptr); 2282 1.9 christos 2283 1.9 christos /* Like find_pc_partial_function, above, but returns the underlying 2284 1.9 christos general_symbol_info (rather than the name) as an out parameter. */ 2285 1.9 christos 2286 1.9 christos extern bool find_pc_partial_function_sym 2287 1.8 christos (CORE_ADDR pc, const general_symbol_info **sym, 2288 1.8 christos CORE_ADDR *address, CORE_ADDR *endaddr, 2289 1.8 christos const struct block **block = nullptr); 2290 1.8 christos 2291 1.8 christos /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are 2292 1.8 christos set to start and end addresses of the range containing the entry pc. 2293 1.8 christos 2294 1.8 christos Note that it is not necessarily the case that (for non-NULL ADDRESS 2295 1.8 christos and ENDADDR arguments) the *ADDRESS <= PC < *ENDADDR condition will 2296 1.8 christos hold. 2297 1.8 christos 2298 1.8 christos See comment for find_pc_partial_function, above, for further 2299 1.8 christos explanation. */ 2300 1.1 christos 2301 1.8 christos extern bool find_function_entry_range_from_pc (CORE_ADDR pc, 2302 1.1 christos const char **name, 2303 1.8 christos CORE_ADDR *address, 2304 1.8 christos CORE_ADDR *endaddr); 2305 1.1 christos 2306 1.8 christos /* Return the type of a function with its first instruction exactly at 2307 1.8 christos the PC address. Return NULL otherwise. */ 2308 1.8 christos 2309 1.8 christos extern struct type *find_function_type (CORE_ADDR pc); 2310 1.8 christos 2311 1.8 christos /* See if we can figure out the function's actual type from the type 2312 1.8 christos that the resolver returns. RESOLVER_FUNADDR is the address of the 2313 1.8 christos ifunc resolver. */ 2314 1.8 christos 2315 1.8 christos extern struct type *find_gnu_ifunc_target_type (CORE_ADDR resolver_funaddr); 2316 1.1 christos 2317 1.1 christos /* Find the GNU ifunc minimal symbol that matches SYM. */ 2318 1.1 christos extern bound_minimal_symbol find_gnu_ifunc (const symbol *sym); 2319 1.1 christos 2320 1.1 christos extern void clear_pc_function_cache (void); 2321 1.3 christos 2322 1.1 christos /* lookup full symbol table by address. */ 2323 1.1 christos 2324 1.1 christos extern struct compunit_symtab *find_pc_compunit_symtab (CORE_ADDR); 2325 1.3 christos 2326 1.3 christos /* lookup full symbol table by address and section. */ 2327 1.1 christos 2328 1.9 christos extern struct compunit_symtab * 2329 1.1 christos find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *); 2330 1.10 christos 2331 1.1 christos extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *); 2332 1.3 christos 2333 1.3 christos extern void reread_symbols (int from_tty); 2334 1.3 christos 2335 1.3 christos /* Look up a type named NAME in STRUCT_DOMAIN in the current language. 2336 1.11 christos The type returned must not be opaque -- i.e., must have at least one field 2337 1.11 christos defined. */ 2338 1.3 christos 2339 1.11 christos extern struct type *lookup_transparent_type 2340 1.11 christos (const char *name, domain_search_flags flags = SEARCH_STRUCT_DOMAIN); 2341 1.1 christos 2342 1.1 christos extern struct type *basic_lookup_transparent_type 2343 1.1 christos (const char *name, domain_search_flags flags = SEARCH_STRUCT_DOMAIN); 2344 1.1 christos 2345 1.1 christos /* Macro for name of symbol to indicate a file compiled with gcc. */ 2346 1.1 christos #ifndef GCC_COMPILED_FLAG_SYMBOL 2347 1.1 christos #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled." 2348 1.1 christos #endif 2349 1.1 christos 2350 1.1 christos /* Macro for name of symbol to indicate a file compiled with gcc2. */ 2351 1.1 christos #ifndef GCC2_COMPILED_FLAG_SYMBOL 2352 1.9 christos #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled." 2353 1.1 christos #endif 2354 1.1 christos 2355 1.1 christos extern bool in_gnu_ifunc_stub (CORE_ADDR pc); 2356 1.1 christos 2357 1.1 christos /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only 2358 1.1 christos for ELF symbol files. */ 2359 1.1 christos 2360 1.1 christos struct gnu_ifunc_fns 2361 1.1 christos { 2362 1.1 christos /* See elf_gnu_ifunc_resolve_addr for its real implementation. */ 2363 1.9 christos CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc); 2364 1.1 christos 2365 1.1 christos /* See elf_gnu_ifunc_resolve_name for its real implementation. */ 2366 1.1 christos bool (*gnu_ifunc_resolve_name) (const char *function_name, 2367 1.10 christos CORE_ADDR *function_address_p); 2368 1.1 christos 2369 1.1 christos /* See elf_gnu_ifunc_resolver_stop for its real implementation. */ 2370 1.10 christos void (*gnu_ifunc_resolver_stop) (code_breakpoint *b); 2371 1.1 christos 2372 1.1 christos /* See elf_gnu_ifunc_resolver_return_stop for its real implementation. */ 2373 1.1 christos void (*gnu_ifunc_resolver_return_stop) (code_breakpoint *b); 2374 1.1 christos }; 2375 1.1 christos 2376 1.1 christos #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr 2377 1.1 christos #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name 2378 1.1 christos #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop 2379 1.1 christos #define gnu_ifunc_resolver_return_stop \ 2380 1.1 christos gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop 2381 1.11 christos 2382 1.1 christos extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p; 2383 1.1 christos 2384 1.1 christos extern CORE_ADDR find_solib_trampoline_target (const frame_info_ptr &, CORE_ADDR); 2385 1.1 christos 2386 1.8 christos struct symtab_and_line 2387 1.1 christos { 2388 1.8 christos /* The program space of this sal. */ 2389 1.8 christos struct program_space *pspace = NULL; 2390 1.8 christos 2391 1.8 christos struct symtab *symtab = NULL; 2392 1.1 christos struct symbol *symbol = NULL; 2393 1.1 christos struct obj_section *section = NULL; 2394 1.1 christos struct minimal_symbol *msymbol = NULL; 2395 1.8 christos /* Line number. Line numbers start at 1 and proceed through symtab->nlines. 2396 1.1 christos 0 is never a valid line number; it is used to indicate that line number 2397 1.8 christos information is not available. */ 2398 1.8 christos int line = 0; 2399 1.8 christos 2400 1.8 christos CORE_ADDR pc = 0; 2401 1.1 christos CORE_ADDR end = 0; 2402 1.9 christos bool explicit_pc = false; 2403 1.9 christos bool explicit_line = false; 2404 1.9 christos 2405 1.9 christos /* If the line number information is valid, then this indicates if this 2406 1.1 christos line table entry had the is-stmt flag set or not. */ 2407 1.8 christos bool is_stmt = false; 2408 1.3 christos 2409 1.3 christos /* The probe associated with this symtab_and_line. */ 2410 1.8 christos probe *prob = NULL; 2411 1.1 christos /* If PROBE is not NULL, then this is the objfile in which the probe 2412 1.1 christos originated. */ 2413 1.1 christos struct objfile *objfile = NULL; 2414 1.1 christos }; 2415 1.1 christos 2416 1.1 christos 2417 1.1 christos 2419 1.1 christos /* Given a pc value, return line number it is in. Second arg nonzero means 2420 1.1 christos if pc is on the boundary use the previous statement's line number. */ 2421 1.1 christos 2422 1.1 christos extern struct symtab_and_line find_pc_line (CORE_ADDR, int); 2423 1.1 christos 2424 1.1 christos /* Same function, but specify a section as well as an address. */ 2425 1.11 christos 2426 1.11 christos extern struct symtab_and_line find_pc_sect_line (CORE_ADDR, 2427 1.11 christos struct obj_section *, int); 2428 1.11 christos 2429 1.11 christos /* Given PC, and assuming it is part of a range of addresses that is part of 2430 1.11 christos a line, go back through the linetable and find the starting PC of that 2431 1.11 christos line. 2432 1.11 christos 2433 1.11 christos For example, suppose we have 3 PC ranges for line X: 2434 1.11 christos 2435 1.11 christos Line X - [0x0 - 0x8] 2436 1.11 christos Line X - [0x8 - 0x10] 2437 1.11 christos Line X - [0x10 - 0x18] 2438 1.11 christos 2439 1.11 christos If we call the function with PC == 0x14, we want to return 0x0, as that is 2440 1.11 christos the starting PC of line X, and the ranges are contiguous. 2441 1.3 christos */ 2442 1.3 christos 2443 1.3 christos extern std::optional<CORE_ADDR> find_line_range_start (CORE_ADDR pc); 2444 1.3 christos 2445 1.1 christos /* Wrapper around find_pc_line to just return the symtab. */ 2446 1.1 christos 2447 1.9 christos extern struct symtab *find_pc_line_symtab (CORE_ADDR); 2448 1.1 christos 2449 1.9 christos /* Given a symtab and line number, return the pc there. */ 2450 1.9 christos 2451 1.1 christos extern bool find_line_pc (struct symtab *, int, CORE_ADDR *); 2452 1.1 christos 2453 1.1 christos extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *, 2454 1.8 christos CORE_ADDR *); 2455 1.8 christos 2456 1.8 christos extern void resolve_sal_pc (struct symtab_and_line *); 2457 1.8 christos 2458 1.8 christos /* The reason we're calling into a completion match list collector 2459 1.8 christos function. */ 2460 1.8 christos enum class complete_symbol_mode 2461 1.8 christos { 2462 1.8 christos /* Completing an expression. */ 2463 1.8 christos EXPRESSION, 2464 1.1 christos 2465 1.8 christos /* Completing a linespec. */ 2466 1.8 christos LINESPEC, 2467 1.8 christos }; 2468 1.8 christos 2469 1.8 christos extern void default_collect_symbol_completion_matches_break_on 2470 1.8 christos (completion_tracker &tracker, 2471 1.8 christos complete_symbol_mode mode, 2472 1.8 christos symbol_name_match_type name_match_type, 2473 1.8 christos const char *text, const char *word, const char *break_on, 2474 1.8 christos enum type_code code); 2475 1.8 christos extern void collect_symbol_completion_matches 2476 1.8 christos (completion_tracker &tracker, 2477 1.8 christos complete_symbol_mode mode, 2478 1.8 christos symbol_name_match_type name_match_type, 2479 1.1 christos const char *, const char *); 2480 1.8 christos extern void collect_symbol_completion_matches_type (completion_tracker &tracker, 2481 1.8 christos const char *, const char *, 2482 1.8 christos enum type_code); 2483 1.8 christos 2484 1.8 christos extern void collect_file_symbol_completion_matches 2485 1.1 christos (completion_tracker &tracker, 2486 1.8 christos complete_symbol_mode, 2487 1.8 christos symbol_name_match_type name_match_type, 2488 1.1 christos const char *, const char *, const char *); 2489 1.8 christos 2490 1.1 christos extern completion_list 2491 1.8 christos make_source_files_completion_list (const char *, const char *); 2492 1.1 christos 2493 1.8 christos /* Return whether SYM is a function/method, as opposed to a data symbol. */ 2494 1.8 christos 2495 1.1 christos extern bool symbol_is_function_or_method (symbol *sym); 2496 1.8 christos 2497 1.1 christos /* Return whether MSYMBOL is a function/method, as opposed to a data 2498 1.8 christos symbol */ 2499 1.8 christos 2500 1.1 christos extern bool symbol_is_function_or_method (minimal_symbol *msymbol); 2501 1.8 christos 2502 1.8 christos /* Return whether SYM should be skipped in completion mode MODE. In 2503 1.8 christos linespec mode, we're only interested in functions/methods. */ 2504 1.8 christos 2505 1.8 christos template<typename Symbol> 2506 1.8 christos static bool 2507 1.8 christos completion_skip_symbol (complete_symbol_mode mode, Symbol *sym) 2508 1.1 christos { 2509 1.1 christos return (mode == complete_symbol_mode::LINESPEC 2510 1.1 christos && !symbol_is_function_or_method (sym)); 2511 1.9 christos } 2512 1.1 christos 2513 1.12 christos /* symtab.c */ 2514 1.12 christos 2515 1.12 christos bool matching_obj_sections (struct obj_section *, struct obj_section *); 2516 1.12 christos 2517 1.12 christos /* Find line number LINE in any symtab whose name is the same as 2518 1.12 christos SYMTAB. 2519 1.12 christos 2520 1.12 christos If found, return the symtab that contains the linetable in which it was 2521 1.12 christos found, set *INDEX to the index in the linetable of the best entry 2522 1.12 christos found. The returned index includes inexact matches. 2523 1.1 christos 2524 1.8 christos If not found, return NULL. */ 2525 1.8 christos 2526 1.8 christos extern symtab *find_line_symtab (symtab *sym_tab, int line, int *index); 2527 1.8 christos 2528 1.8 christos /* Given a function symbol SYM, find the symtab and line for the start 2529 1.8 christos of the function. If FUNFIRSTLINE is true, we want the first line 2530 1.8 christos of real code inside the function. */ 2531 1.8 christos extern symtab_and_line find_function_start_sal (symbol *sym, bool 2532 1.8 christos funfirstline); 2533 1.8 christos 2534 1.8 christos /* Same, but start with a function address/section instead of a 2535 1.1 christos symbol. */ 2536 1.1 christos extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr, 2537 1.1 christos obj_section *section, 2538 1.1 christos bool funfirstline); 2539 1.1 christos 2540 1.1 christos extern void skip_prologue_sal (struct symtab_and_line *); 2541 1.1 christos 2542 1.1 christos /* symtab.c */ 2543 1.11 christos 2544 1.11 christos extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch, 2545 1.11 christos CORE_ADDR func_addr); 2546 1.11 christos 2547 1.11 christos /* If SYM requires a section index, find it either via minimal symbols 2548 1.11 christos or examining OBJFILE's sections. Note that SYM's current address 2549 1.1 christos must not have any runtime offsets applied. */ 2550 1.8 christos 2551 1.8 christos extern void fixup_symbol_section (struct symbol *sym, 2552 1.8 christos struct objfile *objfile); 2553 1.8 christos 2554 1.8 christos /* If MSYMBOL is an text symbol, look for a function debug symbol with 2555 1.8 christos the same address. Returns NULL if not found. This is necessary in 2556 1.8 christos case a function is an alias to some other function, because debug 2557 1.1 christos information is only emitted for the alias target function's 2558 1.1 christos definition, not for the alias. */ 2559 1.9 christos extern symbol *find_function_alias_target (bound_minimal_symbol msymbol); 2560 1.9 christos 2561 1.1 christos /* Symbol searching */ 2562 1.1 christos 2563 1.11 christos /* When using the symbol_searcher struct to search for symbols, a vector of 2564 1.8 christos the following structs is returned. */ 2565 1.8 christos struct symbol_search 2566 1.8 christos { 2567 1.8 christos symbol_search (block_enum block_, struct symbol *symbol_) 2568 1.8 christos : block (block_), 2569 1.8 christos symbol (symbol_) 2570 1.8 christos { 2571 1.11 christos msymbol.minsym = nullptr; 2572 1.8 christos msymbol.objfile = nullptr; 2573 1.8 christos } 2574 1.8 christos 2575 1.8 christos symbol_search (block_enum block_, struct minimal_symbol *minsym, 2576 1.8 christos struct objfile *objfile) 2577 1.8 christos : block (block_), 2578 1.8 christos symbol (nullptr) 2579 1.8 christos { 2580 1.8 christos msymbol.minsym = minsym; 2581 1.8 christos msymbol.objfile = objfile; 2582 1.8 christos } 2583 1.8 christos 2584 1.8 christos bool operator< (const symbol_search &other) const 2585 1.8 christos { 2586 1.8 christos return compare_search_syms (*this, other) < 0; 2587 1.8 christos } 2588 1.8 christos 2589 1.8 christos bool operator== (const symbol_search &other) const 2590 1.11 christos { 2591 1.11 christos return compare_search_syms (*this, other) == 0; 2592 1.11 christos } 2593 1.1 christos 2594 1.1 christos /* The block in which the match was found. Either STATIC_BLOCK or 2595 1.1 christos GLOBAL_BLOCK. */ 2596 1.3 christos block_enum block; 2597 1.1 christos 2598 1.1 christos /* Information describing what was found. 2599 1.1 christos 2600 1.1 christos If symbol is NOT NULL, then information was found for this match. */ 2601 1.12 christos struct symbol *symbol; 2602 1.1 christos 2603 1.8 christos /* If msymbol is non-null, then a match was made on something for 2604 1.8 christos which only minimal_symbols exist. */ 2605 1.8 christos bound_minimal_symbol msymbol; 2606 1.8 christos 2607 1.1 christos private: 2608 1.1 christos 2609 1.9 christos static int compare_search_syms (const symbol_search &sym_a, 2610 1.9 christos const symbol_search &sym_b); 2611 1.9 christos }; 2612 1.9 christos 2613 1.9 christos /* In order to search for global symbols of a particular kind matching 2614 1.9 christos particular regular expressions, create an instance of this structure and 2615 1.9 christos call the SEARCH member function. */ 2616 1.9 christos class global_symbol_searcher 2617 1.11 christos { 2618 1.9 christos public: 2619 1.9 christos 2620 1.9 christos /* Constructor. */ 2621 1.9 christos global_symbol_searcher (domain_search_flags kind, 2622 1.9 christos const char *symbol_name_regexp) 2623 1.9 christos : m_kind (kind), 2624 1.9 christos m_symbol_name_regexp (symbol_name_regexp) 2625 1.9 christos { 2626 1.9 christos } 2627 1.9 christos 2628 1.9 christos /* Set the optional regexp that matches against the symbol type. */ 2629 1.9 christos void set_symbol_type_regexp (const char *regexp) 2630 1.9 christos { 2631 1.9 christos m_symbol_type_regexp = regexp; 2632 1.9 christos } 2633 1.9 christos 2634 1.9 christos /* Set the flag to exclude minsyms from the search results. */ 2635 1.9 christos void set_exclude_minsyms (bool exclude_minsyms) 2636 1.9 christos { 2637 1.9 christos m_exclude_minsyms = exclude_minsyms; 2638 1.9 christos } 2639 1.9 christos 2640 1.9 christos /* Set the maximum number of search results to be returned. */ 2641 1.9 christos void set_max_search_results (size_t max_search_results) 2642 1.9 christos { 2643 1.9 christos m_max_search_results = max_search_results; 2644 1.9 christos } 2645 1.9 christos 2646 1.9 christos /* Search the symbols from all objfiles in the current program space 2647 1.9 christos looking for matches as defined by the current state of this object. 2648 1.9 christos 2649 1.9 christos Within each file the results are sorted locally; each symtab's global 2650 1.12 christos and static blocks are separately alphabetized. Duplicate entries are 2651 1.12 christos removed. */ 2652 1.12 christos std::vector<symbol_search> search () const; 2653 1.9 christos 2654 1.9 christos /* Add a filename to the list of file names to search. */ 2655 1.12 christos void add_filename (gdb::unique_xmalloc_ptr<char> filename) 2656 1.12 christos { m_filenames.push_back (std::move (filename)); } 2657 1.12 christos 2658 1.9 christos private: 2659 1.9 christos /* The set of source files to search in for matching symbols. */ 2660 1.10 christos std::vector<gdb::unique_xmalloc_ptr<char>> m_filenames; 2661 1.9 christos 2662 1.9 christos /* The kind of symbols are we searching for. 2663 1.9 christos VARIABLES_DOMAIN - Search all symbols, excluding functions, type 2664 1.9 christos names, and constants (enums). 2665 1.11 christos FUNCTIONS_DOMAIN - Search all functions.. 2666 1.9 christos TYPES_DOMAIN - Search all type names. 2667 1.9 christos MODULES_DOMAIN - Search all Fortran modules. 2668 1.9 christos ALL_DOMAIN - Not valid for this function. */ 2669 1.9 christos domain_search_flags m_kind; 2670 1.9 christos 2671 1.9 christos /* Regular expression to match against the symbol name. */ 2672 1.9 christos const char *m_symbol_name_regexp = nullptr; 2673 1.9 christos 2674 1.9 christos /* Regular expression to match against the symbol type. */ 2675 1.9 christos const char *m_symbol_type_regexp = nullptr; 2676 1.9 christos 2677 1.9 christos /* When this flag is false then minsyms that match M_SYMBOL_REGEXP will 2678 1.9 christos be included in the results, otherwise they are excluded. */ 2679 1.9 christos bool m_exclude_minsyms = false; 2680 1.9 christos 2681 1.9 christos /* Maximum number of search results. We currently impose a hard limit 2682 1.9 christos of SIZE_MAX, there is no "unlimited". */ 2683 1.9 christos size_t m_max_search_results = SIZE_MAX; 2684 1.9 christos 2685 1.11 christos /* Expand symtabs in OBJFILE that match PREG, are of type M_KIND. Return 2686 1.9 christos true if any msymbols were seen that we should later consider adding to 2687 1.9 christos the results list. */ 2688 1.9 christos bool expand_symtabs (objfile *objfile, 2689 1.9 christos const std::optional<compiled_regex> &preg) const; 2690 1.9 christos 2691 1.9 christos /* Add symbols from symtabs in OBJFILE that match PREG, and TREG, and are 2692 1.9 christos of type M_KIND, to the results set RESULTS_SET. Return false if we 2693 1.9 christos stop adding results early due to having already found too many results 2694 1.11 christos (based on M_MAX_SEARCH_RESULTS limit), otherwise return true. 2695 1.11 christos Returning true does not indicate that any results were added, just 2696 1.9 christos that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS. */ 2697 1.9 christos bool add_matching_symbols (objfile *objfile, 2698 1.9 christos const std::optional<compiled_regex> &preg, 2699 1.9 christos const std::optional<compiled_regex> &treg, 2700 1.9 christos std::set<symbol_search> *result_set) const; 2701 1.9 christos 2702 1.9 christos /* Add msymbols from OBJFILE that match PREG and M_KIND, to the results 2703 1.9 christos vector RESULTS. Return false if we stop adding results early due to 2704 1.9 christos having already found too many results (based on max search results 2705 1.11 christos limit M_MAX_SEARCH_RESULTS), otherwise return true. Returning true 2706 1.9 christos does not indicate that any results were added, just that we didn't 2707 1.9 christos _not_ add a result due to reaching MAX_SEARCH_RESULTS. */ 2708 1.9 christos bool add_matching_msymbols (objfile *objfile, 2709 1.11 christos const std::optional<compiled_regex> &preg, 2710 1.9 christos std::vector<symbol_search> *results) const; 2711 1.9 christos 2712 1.9 christos /* Return true if MSYMBOL is of type KIND. */ 2713 1.9 christos static bool is_suitable_msymbol (const domain_search_flags kind, 2714 1.9 christos const minimal_symbol *msymbol); 2715 1.9 christos }; 2716 1.9 christos 2717 1.9 christos /* When searching for Fortran symbols within modules (functions/variables) 2718 1.9 christos we return a vector of this type. The first item in the pair is the 2719 1.9 christos module symbol, and the second item is the symbol for the function or 2720 1.9 christos variable we found. */ 2721 1.9 christos typedef std::pair<symbol_search, symbol_search> module_symbol_search; 2722 1.9 christos 2723 1.9 christos /* Searches the symbols to find function and variables symbols (depending 2724 1.9 christos on KIND) within Fortran modules. The MODULE_REGEXP matches against the 2725 1.9 christos name of the module, REGEXP matches against the name of the symbol within 2726 1.11 christos the module, and TYPE_REGEXP matches against the type of the symbol 2727 1.9 christos within the module. */ 2728 1.9 christos extern std::vector<module_symbol_search> search_module_symbols 2729 1.9 christos (const char *module_regexp, const char *regexp, 2730 1.11 christos const char *type_regexp, domain_search_flags kind); 2731 1.9 christos 2732 1.11 christos /* Convert a global or static symbol SYM (based on BLOCK, which should be 2733 1.9 christos either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info' 2734 1.8 christos type commands (e.g. 'info variables', 'info functions', etc). */ 2735 1.8 christos 2736 1.1 christos extern std::string symbol_to_info_string (struct symbol *sym, int block); 2737 1.9 christos 2738 1.9 christos extern bool treg_matches_sym_type_name (const compiled_regex &treg, 2739 1.3 christos const struct symbol *sym); 2740 1.1 christos 2741 1.9 christos /* The name of the ``main'' function. */ 2742 1.9 christos extern const char *main_name (); 2743 1.3 christos extern enum language main_language (void); 2744 1.3 christos 2745 1.9 christos /* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks, 2746 1.6 christos as specified by BLOCK_INDEX. 2747 1.3 christos This searches MAIN_OBJFILE as well as any associated separate debug info 2748 1.6 christos objfiles of MAIN_OBJFILE. 2749 1.3 christos BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK. 2750 1.9 christos Upon success fixes up the symbol's section if necessary. */ 2751 1.3 christos 2752 1.11 christos extern struct block_symbol 2753 1.1 christos lookup_global_symbol_from_objfile (struct objfile *main_objfile, 2754 1.1 christos enum block_enum block_index, 2755 1.1 christos const char *name, 2756 1.9 christos const domain_search_flags domain); 2757 1.1 christos 2758 1.1 christos /* Return 1 if the supplied producer string matches the ARM RealView 2759 1.1 christos compiler (armcc). */ 2760 1.10 christos bool producer_is_realview (const char *producer); 2761 1.10 christos 2762 1.10 christos extern unsigned int symtab_create_debug; 2763 1.10 christos 2764 1.10 christos /* Print a "symtab-create" debug statement. */ 2765 1.10 christos 2766 1.10 christos #define symtab_create_debug_printf(fmt, ...) \ 2767 1.10 christos debug_prefixed_printf_cond (symtab_create_debug >= 1, "symtab-create", fmt, ##__VA_ARGS__) 2768 1.10 christos 2769 1.10 christos /* Print a verbose "symtab-create" debug statement, only if 2770 1.10 christos "set debug symtab-create" is set to 2 or higher. */ 2771 1.3 christos 2772 1.3 christos #define symtab_create_debug_printf_v(fmt, ...) \ 2773 1.10 christos debug_prefixed_printf_cond (symtab_create_debug >= 2, "symtab-create", fmt, ##__VA_ARGS__) 2774 1.10 christos 2775 1.10 christos extern unsigned int symbol_lookup_debug; 2776 1.10 christos 2777 1.10 christos /* Return true if symbol-lookup debug is turned on at all. */ 2778 1.10 christos 2779 1.10 christos static inline bool 2780 1.10 christos symbol_lookup_debug_enabled () 2781 1.10 christos { 2782 1.10 christos return symbol_lookup_debug > 0; 2783 1.10 christos } 2784 1.10 christos 2785 1.10 christos /* Return true if symbol-lookup debug is turned to verbose mode. */ 2786 1.10 christos 2787 1.10 christos static inline bool 2788 1.10 christos symbol_lookup_debug_enabled_v () 2789 1.10 christos { 2790 1.10 christos return symbol_lookup_debug > 1; 2791 1.10 christos } 2792 1.10 christos 2793 1.10 christos /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 1. */ 2794 1.10 christos 2795 1.10 christos #define symbol_lookup_debug_printf(fmt, ...) \ 2796 1.10 christos debug_prefixed_printf_cond (symbol_lookup_debug_enabled (), \ 2797 1.10 christos "symbol-lookup", fmt, ##__VA_ARGS__) 2798 1.10 christos 2799 1.10 christos /* Print a "symbol-lookup" debug statement if symbol_lookup_debug is >= 2. */ 2800 1.10 christos 2801 1.10 christos #define symbol_lookup_debug_printf_v(fmt, ...) \ 2802 1.10 christos debug_prefixed_printf_cond (symbol_lookup_debug_enabled_v (), \ 2803 1.10 christos "symbol-lookup", fmt, ##__VA_ARGS__) 2804 1.10 christos 2805 1.10 christos /* Print "symbol-lookup" enter/exit debug statements. */ 2806 1.9 christos 2807 1.1 christos #define SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT \ 2808 1.9 christos scoped_debug_enter_exit (symbol_lookup_debug_enabled, "symbol-lookup") 2809 1.9 christos 2810 1.1 christos extern bool basenames_may_differ; 2811 1.9 christos 2812 1.9 christos bool compare_filenames_for_search (const char *filename, 2813 1.6 christos const char *search_name); 2814 1.7 christos 2815 1.7 christos bool compare_glob_filenames_for_search (const char *filename, 2816 1.7 christos const char *search_name); 2817 1.7 christos 2818 1.7 christos bool iterate_over_some_symtabs (const char *name, 2819 1.1 christos const char *real_path, 2820 1.12 christos struct compunit_symtab *first, 2821 1.12 christos struct compunit_symtab *after_last, 2822 1.12 christos gdb::function_view<bool (symtab *)> callback); 2823 1.12 christos 2824 1.12 christos /* Check in PSPACE for a symtab of a specific name; first in symtabs, then in 2825 1.12 christos psymtabs. *If* there is no '/' in the name, a match after a '/' in the 2826 1.12 christos symtab filename will also work. 2827 1.12 christos 2828 1.7 christos Call CALLBACK with each symtab that is found. If CALLBACK returns 2829 1.1 christos true, the search stops. */ 2830 1.7 christos 2831 1.11 christos void iterate_over_symtabs (program_space *pspace, const char *name, 2832 1.7 christos gdb::function_view<bool (symtab *)> callback); 2833 1.7 christos 2834 1.7 christos std::vector<CORE_ADDR> find_pcs_for_symtab_line 2835 1.7 christos (struct symtab *symtab, int line, const linetable_entry **best_entry); 2836 1.7 christos 2837 1.7 christos /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback 2838 1.8 christos is called once per matching symbol SYM. The callback should return 2839 1.1 christos true to indicate that LA_ITERATE_OVER_SYMBOLS should continue 2840 1.9 christos iterating, or false to indicate that the iteration should end. */ 2841 1.9 christos 2842 1.9 christos typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym); 2843 1.9 christos 2844 1.9 christos /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK. 2845 1.9 christos 2846 1.9 christos For each symbol that matches, CALLBACK is called. The symbol is 2847 1.9 christos passed to the callback. 2848 1.9 christos 2849 1.9 christos If CALLBACK returns false, the iteration ends and this function 2850 1.8 christos returns false. Otherwise, the search continues, and the function 2851 1.11 christos eventually returns true. */ 2852 1.7 christos 2853 1.7 christos bool iterate_over_symbols (const struct block *block, 2854 1.9 christos const lookup_name_info &name, 2855 1.9 christos const domain_search_flags domain, 2856 1.9 christos gdb::function_view<symbol_found_callback_ftype> callback); 2857 1.9 christos 2858 1.9 christos /* Like iterate_over_symbols, but if all calls to CALLBACK return 2859 1.9 christos true, then calls CALLBACK one additional time with a block_symbol 2860 1.9 christos that has a valid block but a NULL symbol. */ 2861 1.11 christos 2862 1.9 christos bool iterate_over_symbols_terminated 2863 1.9 christos (const struct block *block, 2864 1.7 christos const lookup_name_info &name, 2865 1.7 christos const domain_search_flags domain, 2866 1.7 christos gdb::function_view<symbol_found_callback_ftype> callback); 2867 1.9 christos 2868 1.9 christos /* Storage type used by demangle_for_lookup. demangle_for_lookup 2869 1.7 christos either returns a const char * pointer that points to either of the 2870 1.7 christos fields of this type, or a pointer to the input NAME. This is done 2871 1.7 christos this way to avoid depending on the precise details of the storage 2872 1.7 christos for the string. */ 2873 1.9 christos class demangle_result_storage 2874 1.9 christos { 2875 1.9 christos public: 2876 1.7 christos 2877 1.9 christos /* Swap the malloc storage to STR, and return a pointer to the 2878 1.9 christos beginning of the new string. */ 2879 1.7 christos const char *set_malloc_ptr (gdb::unique_xmalloc_ptr<char> &&str) 2880 1.7 christos { 2881 1.7 christos m_malloc = std::move (str); 2882 1.7 christos return m_malloc.get (); 2883 1.7 christos } 2884 1.7 christos 2885 1.7 christos /* Set the malloc storage to now point at PTR. Any previous malloc 2886 1.7 christos storage is released. */ 2887 1.7 christos const char *set_malloc_ptr (char *ptr) 2888 1.7 christos { 2889 1.7 christos m_malloc.reset (ptr); 2890 1.7 christos return ptr; 2891 1.7 christos } 2892 1.7 christos 2893 1.7 christos private: 2894 1.1 christos 2895 1.7 christos /* The storage. */ 2896 1.7 christos gdb::unique_xmalloc_ptr<char> m_malloc; 2897 1.7 christos }; 2898 1.1 christos 2899 1.8 christos const char * 2900 1.8 christos demangle_for_lookup (const char *name, enum language lang, 2901 1.8 christos demangle_result_storage &storage); 2902 1.9 christos 2903 1.9 christos /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by 2904 1.9 christos SYMNAME (which is already demangled for C++ symbols) matches 2905 1.8 christos SYM_TEXT in the first SYM_TEXT_LEN characters. If so, add it to 2906 1.8 christos the current completion list and return true. Otherwise, return 2907 1.8 christos false. */ 2908 1.8 christos bool completion_list_add_name (completion_tracker &tracker, 2909 1.8 christos language symbol_language, 2910 1.8 christos const char *symname, 2911 1.8 christos const lookup_name_info &lookup_name, 2912 1.8 christos const char *text, const char *word); 2913 1.8 christos 2914 1.8 christos /* A simple symbol searching class. */ 2915 1.8 christos 2916 1.8 christos class symbol_searcher 2917 1.8 christos { 2918 1.8 christos public: 2919 1.8 christos /* Returns the symbols found for the search. */ 2920 1.8 christos const std::vector<block_symbol> & 2921 1.8 christos matching_symbols () const 2922 1.8 christos { 2923 1.8 christos return m_symbols; 2924 1.8 christos } 2925 1.8 christos 2926 1.8 christos /* Returns the minimal symbols found for the search. */ 2927 1.8 christos const std::vector<bound_minimal_symbol> & 2928 1.8 christos matching_msymbols () const 2929 1.8 christos { 2930 1.8 christos return m_minimal_symbols; 2931 1.8 christos } 2932 1.8 christos 2933 1.8 christos /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting 2934 1.11 christos search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL 2935 1.8 christos to search all symtabs and program spaces. */ 2936 1.8 christos void find_all_symbols (const std::string &name, 2937 1.8 christos const struct language_defn *language, 2938 1.8 christos domain_search_flags domain_search_flags, 2939 1.8 christos std::vector<symtab *> *search_symtabs, 2940 1.8 christos struct program_space *search_pspace); 2941 1.8 christos 2942 1.8 christos /* Reset this object to perform another search. */ 2943 1.8 christos void reset () 2944 1.8 christos { 2945 1.8 christos m_symbols.clear (); 2946 1.8 christos m_minimal_symbols.clear (); 2947 1.8 christos } 2948 1.8 christos 2949 1.8 christos private: 2950 1.8 christos /* Matching debug symbols. */ 2951 1.8 christos std::vector<block_symbol> m_symbols; 2952 1.8 christos 2953 1.10 christos /* Matching non-debug symbols. */ 2954 1.10 christos std::vector<bound_minimal_symbol> m_minimal_symbols; 2955 1.10 christos }; 2956 1.10 christos 2957 1.10 christos /* Class used to encapsulate the filename filtering for the "info sources" 2958 1.10 christos command. */ 2959 1.10 christos 2960 1.10 christos struct info_sources_filter 2961 1.10 christos { 2962 1.10 christos /* If filename filtering is being used (see M_C_REGEXP) then which part 2963 1.10 christos of the filename is being filtered against? */ 2964 1.10 christos enum class match_on 2965 1.10 christos { 2966 1.10 christos /* Match against the full filename. */ 2967 1.10 christos FULLNAME, 2968 1.10 christos 2969 1.10 christos /* Match only against the directory part of the full filename. */ 2970 1.10 christos DIRNAME, 2971 1.10 christos 2972 1.10 christos /* Match only against the basename part of the full filename. */ 2973 1.10 christos BASENAME 2974 1.10 christos }; 2975 1.10 christos 2976 1.10 christos /* Create a filter of MATCH_TYPE using regular expression REGEXP. If 2977 1.10 christos REGEXP is nullptr then all files will match the filter and MATCH_TYPE 2978 1.10 christos is ignored. 2979 1.10 christos 2980 1.10 christos The string pointed too by REGEXP must remain live and unchanged for 2981 1.10 christos this lifetime of this object as the object only retains a copy of the 2982 1.10 christos pointer. */ 2983 1.10 christos info_sources_filter (match_on match_type, const char *regexp); 2984 1.10 christos 2985 1.10 christos DISABLE_COPY_AND_ASSIGN (info_sources_filter); 2986 1.10 christos 2987 1.10 christos /* Does FULLNAME match the filter defined by this object, return true if 2988 1.10 christos it does, otherwise, return false. If there is no filtering defined 2989 1.10 christos then this function will always return true. */ 2990 1.10 christos bool matches (const char *fullname) const; 2991 1.10 christos 2992 1.10 christos private: 2993 1.10 christos 2994 1.10 christos /* The type of filtering in place. */ 2995 1.10 christos match_on m_match_type; 2996 1.10 christos 2997 1.10 christos /* Points to the original regexp used to create this filter. */ 2998 1.11 christos const char *m_regexp; 2999 1.10 christos 3000 1.10 christos /* A compiled version of M_REGEXP. This object is only given a value if 3001 1.10 christos M_REGEXP is not nullptr and is not the empty string. */ 3002 1.10 christos std::optional<compiled_regex> m_c_regexp; 3003 1.10 christos }; 3004 1.10 christos 3005 1.10 christos /* Perform the core of the 'info sources' command. 3006 1.10 christos 3007 1.10 christos FILTER is used to perform regular expression based filtering on the 3008 1.10 christos source files that will be displayed. 3009 1.10 christos 3010 1.10 christos Output is written to UIOUT in CLI or MI style as appropriate. */ 3011 1.10 christos 3012 1.11 christos extern void info_sources_worker (struct ui_out *uiout, 3013 1.11 christos bool group_by_objfile, 3014 1.11 christos const info_sources_filter &filter); 3015 1.11 christos 3016 1.11 christos /* This function returns the address at which the function epilogue begins, 3017 1.11 christos according to the linetable. 3018 1.11 christos 3019 1.11 christos Returns an empty optional if EPILOGUE_BEGIN is never set in the 3020 1.12 christos linetable. */ 3021 1.12 christos 3022 1.12 christos std::optional<CORE_ADDR> find_epilogue_using_linetable (CORE_ADDR func_addr); 3023 1.12 christos 3024 1.12 christos /* Search an array of symbols for one named NAME. Name comparison is 3025 1.12 christos done using strcmp -- i.e., this is only useful for simple names. 3026 1.12 christos Returns the symbol, if found, or nullptr if not. */ 3027 1.12 christos 3028 extern struct symbol *search_symbol_list (const char *name, int num, 3029 struct symbol **syms); 3030 3031 #endif /* GDB_SYMTAB_H */ 3032