10b57cec5SDimitry Andric //===-- SymbolContext.h -----------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
95ffd83dbSDimitry Andric #ifndef LLDB_SYMBOL_SYMBOLCONTEXT_H
105ffd83dbSDimitry Andric #define LLDB_SYMBOL_SYMBOLCONTEXT_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include <memory>
130b57cec5SDimitry Andric #include <string>
140b57cec5SDimitry Andric #include <vector>
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "lldb/Core/Address.h"
170b57cec5SDimitry Andric #include "lldb/Core/Mangled.h"
180b57cec5SDimitry Andric #include "lldb/Symbol/LineEntry.h"
190b57cec5SDimitry Andric #include "lldb/Utility/Iterable.h"
207a6dacacSDimitry Andric #include "lldb/Utility/Stream.h"
210b57cec5SDimitry Andric #include "lldb/lldb-private.h"
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric namespace lldb_private {
240b57cec5SDimitry Andric 
250b57cec5SDimitry Andric class SymbolContextScope;
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric /// \class SymbolContext SymbolContext.h "lldb/Symbol/SymbolContext.h" Defines
280b57cec5SDimitry Andric /// a symbol context baton that can be handed other debug core functions.
290b57cec5SDimitry Andric ///
300b57cec5SDimitry Andric /// Many debugger functions require a context when doing lookups. This class
310b57cec5SDimitry Andric /// provides a common structure that can be used as the result of a query that
320b57cec5SDimitry Andric /// can contain a single result. Examples of such queries include
330b57cec5SDimitry Andric ///     \li Looking up a load address.
340b57cec5SDimitry Andric class SymbolContext {
350b57cec5SDimitry Andric public:
360b57cec5SDimitry Andric   /// Default constructor.
370b57cec5SDimitry Andric   ///
380b57cec5SDimitry Andric   /// Initialize all pointer members to nullptr and all struct members to
390b57cec5SDimitry Andric   /// their default state.
400b57cec5SDimitry Andric   SymbolContext();
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric   /// Construct with an object that knows how to reconstruct its symbol
430b57cec5SDimitry Andric   /// context.
440b57cec5SDimitry Andric   ///
450b57cec5SDimitry Andric   /// \param[in] sc_scope
460b57cec5SDimitry Andric   ///     A symbol context scope object that knows how to reconstruct
470b57cec5SDimitry Andric   ///     it's context.
480b57cec5SDimitry Andric   explicit SymbolContext(SymbolContextScope *sc_scope);
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric   /// Construct with module, and optional compile unit, function, block, line
510b57cec5SDimitry Andric   /// table, line entry and symbol.
520b57cec5SDimitry Andric   ///
530b57cec5SDimitry Andric   /// Initialize all pointer to the specified values.
540b57cec5SDimitry Andric   ///
55480093f4SDimitry Andric   /// \param[in] module_sp
560b57cec5SDimitry Andric   ///     A Module pointer to the module for this context.
570b57cec5SDimitry Andric   ///
580b57cec5SDimitry Andric   /// \param[in] comp_unit
590b57cec5SDimitry Andric   ///     A CompileUnit pointer to the compile unit for this context.
600b57cec5SDimitry Andric   ///
610b57cec5SDimitry Andric   /// \param[in] function
620b57cec5SDimitry Andric   ///     A Function pointer to the function for this context.
630b57cec5SDimitry Andric   ///
640b57cec5SDimitry Andric   /// \param[in] block
650b57cec5SDimitry Andric   ///     A Block pointer to the deepest block for this context.
660b57cec5SDimitry Andric   ///
670b57cec5SDimitry Andric   /// \param[in] line_entry
680b57cec5SDimitry Andric   ///     A LineEntry pointer to the line entry for this context.
690b57cec5SDimitry Andric   ///
700b57cec5SDimitry Andric   /// \param[in] symbol
710b57cec5SDimitry Andric   ///     A Symbol pointer to the symbol for this context.
720b57cec5SDimitry Andric   explicit SymbolContext(const lldb::TargetSP &target_sp,
730b57cec5SDimitry Andric                          const lldb::ModuleSP &module_sp,
740b57cec5SDimitry Andric                          CompileUnit *comp_unit = nullptr,
750b57cec5SDimitry Andric                          Function *function = nullptr, Block *block = nullptr,
760b57cec5SDimitry Andric                          LineEntry *line_entry = nullptr,
770b57cec5SDimitry Andric                          Symbol *symbol = nullptr);
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   // This version sets the target to a NULL TargetSP if you don't know it.
800b57cec5SDimitry Andric   explicit SymbolContext(const lldb::ModuleSP &module_sp,
810b57cec5SDimitry Andric                          CompileUnit *comp_unit = nullptr,
820b57cec5SDimitry Andric                          Function *function = nullptr, Block *block = nullptr,
830b57cec5SDimitry Andric                          LineEntry *line_entry = nullptr,
840b57cec5SDimitry Andric                          Symbol *symbol = nullptr);
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric   ~SymbolContext();
870b57cec5SDimitry Andric 
880b57cec5SDimitry Andric   /// Clear the object's state.
890b57cec5SDimitry Andric   ///
900b57cec5SDimitry Andric   /// Resets all pointer members to nullptr, and clears any class objects to
910b57cec5SDimitry Andric   /// their default state.
920b57cec5SDimitry Andric   void Clear(bool clear_target);
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric   /// Dump a description of this object to a Stream.
950b57cec5SDimitry Andric   ///
960b57cec5SDimitry Andric   /// Dump a description of the contents of this object to the supplied stream
970b57cec5SDimitry Andric   /// \a s.
980b57cec5SDimitry Andric   ///
990b57cec5SDimitry Andric   /// \param[in] s
1000b57cec5SDimitry Andric   ///     The stream to which to dump the object description.
1010b57cec5SDimitry Andric   void Dump(Stream *s, Target *target) const;
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   /// Dump the stop context in this object to a Stream.
1040b57cec5SDimitry Andric   ///
1050b57cec5SDimitry Andric   /// Dump the best description of this object to the stream. The information
1060b57cec5SDimitry Andric   /// displayed depends on the amount and quality of the information in this
1070b57cec5SDimitry Andric   /// context. If a module, function, file and line number are available, they
1080b57cec5SDimitry Andric   /// will be dumped. If only a module and function or symbol name with offset
1090b57cec5SDimitry Andric   /// is available, that will be output. Else just the address at which the
1100b57cec5SDimitry Andric   /// target was stopped will be displayed.
1110b57cec5SDimitry Andric   ///
1120b57cec5SDimitry Andric   /// \param[in] s
1130b57cec5SDimitry Andric   ///     The stream to which to dump the object description.
1140b57cec5SDimitry Andric   ///
1150b57cec5SDimitry Andric   /// \param[in] so_addr
1160b57cec5SDimitry Andric   ///     The resolved section offset address.
1170b57cec5SDimitry Andric   ///
1180b57cec5SDimitry Andric   /// \param[in] show_fullpaths
1190b57cec5SDimitry Andric   ///     When printing file paths (with the Module), whether the
1200b57cec5SDimitry Andric   ///     base name of the Module should be printed or the full path.
1210b57cec5SDimitry Andric   ///
1220b57cec5SDimitry Andric   /// \param[in] show_module
1230b57cec5SDimitry Andric   ///     Whether the module name should be printed followed by a
1240b57cec5SDimitry Andric   ///     grave accent "`" character.
1250b57cec5SDimitry Andric   ///
1260b57cec5SDimitry Andric   /// \param[in] show_inlined_frames
1270b57cec5SDimitry Andric   ///     If a given pc is in inlined function(s), whether the inlined
1280b57cec5SDimitry Andric   ///     functions should be printed on separate lines in addition to
1290b57cec5SDimitry Andric   ///     the concrete function containing the pc.
1300b57cec5SDimitry Andric   ///
1310b57cec5SDimitry Andric   /// \param[in] show_function_arguments
1320b57cec5SDimitry Andric   ///     If false, this method will try to elide the function argument
1330b57cec5SDimitry Andric   ///     types when printing the function name.  This may be ambiguous
1340b57cec5SDimitry Andric   ///     for languages that have function overloading - but it may
1350b57cec5SDimitry Andric   ///     make the "function name" too long to include all the argument
1360b57cec5SDimitry Andric   ///     types.
1370b57cec5SDimitry Andric   ///
1380b57cec5SDimitry Andric   /// \param[in] show_function_name
1390b57cec5SDimitry Andric   ///     Normally this should be true - the function/symbol name should
1400b57cec5SDimitry Andric   ///     be printed.  In disassembly formatting, where we want a format
1410b57cec5SDimitry Andric   ///     like "<*+36>", this should be false and "*" will be printed
1420b57cec5SDimitry Andric   ///     instead.
143e8d8bef9SDimitry Andric   ///
144e8d8bef9SDimitry Andric   /// \param[in] show_inline_callsite_line_info
145e8d8bef9SDimitry Andric   ///     When processing an inline block, the line info of the callsite
146e8d8bef9SDimitry Andric   ///     is dumped if this flag is \b true, otherwise the line info
147e8d8bef9SDimitry Andric   ///     of the actual inlined function is dumped.
148e8d8bef9SDimitry Andric   ///
1495f757f3fSDimitry Andric   /// \param[in] pattern
1505f757f3fSDimitry Andric   ///     An optional regex pattern to match against the stop context
1515f757f3fSDimitry Andric   ///     description. If specified, parts of the description matching this
1525f757f3fSDimitry Andric   ///     pattern may be highlighted or processed differently. If this parameter
1535f757f3fSDimitry Andric   ///     is an empty string or not provided, no highlighting is applied.
1545f757f3fSDimitry Andric   ///
155e8d8bef9SDimitry Andric   /// \return
156e8d8bef9SDimitry Andric   ///     \b true if some text was dumped, \b false otherwise.
1577a6dacacSDimitry Andric   bool DumpStopContext(
1587a6dacacSDimitry Andric       Stream *s, ExecutionContextScope *exe_scope, const Address &so_addr,
1597a6dacacSDimitry Andric       bool show_fullpaths, bool show_module, bool show_inlined_frames,
1605f757f3fSDimitry Andric       bool show_function_arguments, bool show_function_name,
1617a6dacacSDimitry Andric       std::optional<Stream::HighlightSettings> settings = std::nullopt) const;
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   /// Get the address range contained within a symbol context.
1640b57cec5SDimitry Andric   ///
1650b57cec5SDimitry Andric   /// Address range priority is as follows:
1660b57cec5SDimitry Andric   ///     - line_entry address range if line_entry is valid and
1670b57cec5SDimitry Andric   ///     eSymbolContextLineEntry is set in \a scope
1680b57cec5SDimitry Andric   ///     - block address range if block is not nullptr and eSymbolContextBlock
1690b57cec5SDimitry Andric   ///     is set in \a scope
1700b57cec5SDimitry Andric   ///     - function address range if function is not nullptr and
1710b57cec5SDimitry Andric   ///     eSymbolContextFunction is set in \a scope
1720b57cec5SDimitry Andric   ///     - symbol address range if symbol is not nullptr and
1730b57cec5SDimitry Andric   ///     eSymbolContextSymbol is set in \a scope
1740b57cec5SDimitry Andric   ///
1750b57cec5SDimitry Andric   /// \param[in] scope
1760b57cec5SDimitry Andric   ///     A mask of symbol context bits telling this function which
1770b57cec5SDimitry Andric   ///     address ranges it can use when trying to extract one from
1780b57cec5SDimitry Andric   ///     the valid (non-nullptr) symbol context classes.
1790b57cec5SDimitry Andric   ///
1800b57cec5SDimitry Andric   /// \param[in] range_idx
1810b57cec5SDimitry Andric   ///     The address range index to grab. Since many functions and
1820b57cec5SDimitry Andric   ///     blocks are not always contiguous, they may have more than
1830b57cec5SDimitry Andric   ///     one address range.
1840b57cec5SDimitry Andric   ///
1850b57cec5SDimitry Andric   /// \param[in] use_inline_block_range
1860b57cec5SDimitry Andric   ///     If \a scope has the eSymbolContextBlock bit set, and there
1870b57cec5SDimitry Andric   ///     is a valid block in the symbol context, return the block
1880b57cec5SDimitry Andric   ///     address range for the containing inline function block, not
1890b57cec5SDimitry Andric   ///     the deepest most block. This allows us to extract information
1900b57cec5SDimitry Andric   ///     for the address range of the inlined function block, not
1910b57cec5SDimitry Andric   ///     the deepest lexical block.
1920b57cec5SDimitry Andric   ///
1930b57cec5SDimitry Andric   /// \param[out] range
1940b57cec5SDimitry Andric   ///     An address range object that will be filled in if \b true
1950b57cec5SDimitry Andric   ///     is returned.
1960b57cec5SDimitry Andric   ///
1970b57cec5SDimitry Andric   /// \return
1980b57cec5SDimitry Andric   ///     \b True if this symbol context contains items that describe
1990b57cec5SDimitry Andric   ///     an address range, \b false otherwise.
2000b57cec5SDimitry Andric   bool GetAddressRange(uint32_t scope, uint32_t range_idx,
2010b57cec5SDimitry Andric                        bool use_inline_block_range, AddressRange &range) const;
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric   bool GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range,
2040b57cec5SDimitry Andric                                         Status &error);
2050b57cec5SDimitry Andric 
2060b57cec5SDimitry Andric   /// Find the best global data symbol visible from this context.
2070b57cec5SDimitry Andric   ///
2080b57cec5SDimitry Andric   /// Symbol priority is:
2090b57cec5SDimitry Andric   ///     - extern symbol in the current module if there is one
2100b57cec5SDimitry Andric   ///     - non-extern symbol in the current module if there is one
2110b57cec5SDimitry Andric   ///     - extern symbol in the target
2120b57cec5SDimitry Andric   ///     - non-extern symbol in the target
2130b57cec5SDimitry Andric   /// It is an error if the highest-priority result is ambiguous.
2140b57cec5SDimitry Andric   ///
2150b57cec5SDimitry Andric   /// \param[in] name
2160b57cec5SDimitry Andric   ///     The name of the symbol to search for.
2170b57cec5SDimitry Andric   ///
2180b57cec5SDimitry Andric   /// \param[out] error
2190b57cec5SDimitry Andric   ///     An error that will be populated with a message if there was an
2200b57cec5SDimitry Andric   ///     ambiguous result.  The error will not be populated if no result
2210b57cec5SDimitry Andric   ///     was found.
2220b57cec5SDimitry Andric   ///
2230b57cec5SDimitry Andric   /// \return
2240b57cec5SDimitry Andric   ///     The symbol that was found, or \b nullptr if none was found.
2250b57cec5SDimitry Andric   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status &error);
2260b57cec5SDimitry Andric 
2277a6dacacSDimitry Andric   void GetDescription(
2287a6dacacSDimitry Andric       Stream *s, lldb::DescriptionLevel level, Target *target,
2297a6dacacSDimitry Andric       std::optional<Stream::HighlightSettings> settings = std::nullopt) const;
2300b57cec5SDimitry Andric 
2310b57cec5SDimitry Andric   uint32_t GetResolvedMask() const;
2320b57cec5SDimitry Andric 
2330b57cec5SDimitry Andric   lldb::LanguageType GetLanguage() const;
2340b57cec5SDimitry Andric 
2350b57cec5SDimitry Andric   /// Find a block that defines the function represented by this symbol
2360b57cec5SDimitry Andric   /// context.
2370b57cec5SDimitry Andric   ///
2380b57cec5SDimitry Andric   /// If this symbol context points to a block that is an inlined function, or
2390b57cec5SDimitry Andric   /// is contained within an inlined function, the block that defines the
2400b57cec5SDimitry Andric   /// inlined function is returned.
2410b57cec5SDimitry Andric   ///
2420b57cec5SDimitry Andric   /// If this symbol context has no block in it, or the block is not itself an
2430b57cec5SDimitry Andric   /// inlined function block or contained within one, we return the top level
2440b57cec5SDimitry Andric   /// function block.
2450b57cec5SDimitry Andric   ///
2460b57cec5SDimitry Andric   /// This is a handy function to call when you want to get the block whose
2470b57cec5SDimitry Andric   /// variable list will include the arguments for the function that is
2480b57cec5SDimitry Andric   /// represented by this symbol context (whether the function is an inline
2490b57cec5SDimitry Andric   /// function or not).
2500b57cec5SDimitry Andric   ///
2510b57cec5SDimitry Andric   /// \return
2520b57cec5SDimitry Andric   ///     The block object pointer that defines the function that is
2530b57cec5SDimitry Andric   ///     represented by this symbol context object, nullptr otherwise.
2540b57cec5SDimitry Andric   Block *GetFunctionBlock();
2550b57cec5SDimitry Andric 
25606c3fb27SDimitry Andric   /// Determines the name of the instance variable for the this decl context.
2570b57cec5SDimitry Andric   ///
25806c3fb27SDimitry Andric   /// For C++ the name is "this", for Objective-C the name is "self".
2590b57cec5SDimitry Andric   ///
2600b57cec5SDimitry Andric   /// \return
26106c3fb27SDimitry Andric   ///     Returns a StringRef for the name of the instance variable.
26206c3fb27SDimitry Andric   llvm::StringRef GetInstanceVariableName();
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric   /// Sorts the types in TypeMap according to SymbolContext to TypeList
2650b57cec5SDimitry Andric   ///
2660b57cec5SDimitry Andric   void SortTypeList(TypeMap &type_map, TypeList &type_list) const;
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   /// Find a name of the innermost function for the symbol context.
2690b57cec5SDimitry Andric   ///
2700b57cec5SDimitry Andric   /// For instance, if the symbol context contains an inlined block, it will
2710b57cec5SDimitry Andric   /// return the inlined function name.
2720b57cec5SDimitry Andric   ///
2730b57cec5SDimitry Andric   /// \return
2740b57cec5SDimitry Andric   ///     The name of the function represented by this symbol context.
2750b57cec5SDimitry Andric   ConstString GetFunctionName(
2760b57cec5SDimitry Andric       Mangled::NamePreference preference = Mangled::ePreferDemangled) const;
2770b57cec5SDimitry Andric 
2780b57cec5SDimitry Andric   /// Get the line entry that corresponds to the function.
2790b57cec5SDimitry Andric   ///
2800b57cec5SDimitry Andric   /// If the symbol context contains an inlined block, the line entry for the
2810b57cec5SDimitry Andric   /// start address of the inlined function will be returned, otherwise the
2820b57cec5SDimitry Andric   /// line entry for the start address of the function will be returned. This
2830b57cec5SDimitry Andric   /// can be used after doing a Module::FindFunctions(...) or
2840b57cec5SDimitry Andric   /// ModuleList::FindFunctions(...) call in order to get the correct line
2850b57cec5SDimitry Andric   /// table information for the symbol context. it will return the inlined
2860b57cec5SDimitry Andric   /// function name.
2870b57cec5SDimitry Andric   LineEntry GetFunctionStartLineEntry() const;
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric   /// Find the block containing the inlined block that contains this block.
2900b57cec5SDimitry Andric   ///
2910b57cec5SDimitry Andric   /// For instance, if the symbol context contains an inlined block, it will
2920b57cec5SDimitry Andric   /// return the inlined function name.
2930b57cec5SDimitry Andric   ///
2940b57cec5SDimitry Andric   /// \param[in] curr_frame_pc
2950b57cec5SDimitry Andric   ///    The address within the block of this object.
2960b57cec5SDimitry Andric   ///
2970b57cec5SDimitry Andric   /// \param[out] next_frame_sc
2980b57cec5SDimitry Andric   ///     A new symbol context that does what the title says it does.
2990b57cec5SDimitry Andric   ///
300480093f4SDimitry Andric   /// \param[out] inlined_frame_addr
3010b57cec5SDimitry Andric   ///     This is what you should report as the PC in \a next_frame_sc.
3020b57cec5SDimitry Andric   ///
3030b57cec5SDimitry Andric   /// \return
3040b57cec5SDimitry Andric   ///     \b true if this SymbolContext specifies a block contained in an
3050b57cec5SDimitry Andric   ///     inlined block.  If this returns \b true, \a next_frame_sc and
306480093f4SDimitry Andric   ///     \a inlined_frame_addr will be filled in correctly.
3070b57cec5SDimitry Andric   bool GetParentOfInlinedScope(const Address &curr_frame_pc,
3080b57cec5SDimitry Andric                                SymbolContext &next_frame_sc,
3090b57cec5SDimitry Andric                                Address &inlined_frame_addr) const;
3100b57cec5SDimitry Andric 
3110b57cec5SDimitry Andric   // Member variables
3120b57cec5SDimitry Andric   lldb::TargetSP target_sp; ///< The Target for a given query
3130b57cec5SDimitry Andric   lldb::ModuleSP module_sp; ///< The Module for a given query
314fe6060f1SDimitry Andric   CompileUnit *comp_unit = nullptr; ///< The CompileUnit for a given query
315fe6060f1SDimitry Andric   Function *function = nullptr;     ///< The Function for a given query
316fe6060f1SDimitry Andric   Block *block = nullptr;           ///< The Block for a given query
3170b57cec5SDimitry Andric   LineEntry line_entry;     ///< The LineEntry for a given query
318fe6060f1SDimitry Andric   Symbol *symbol = nullptr; ///< The Symbol for a given query
319fe6060f1SDimitry Andric   Variable *variable =
320fe6060f1SDimitry Andric       nullptr; ///< The global variable matching the given query
3210b57cec5SDimitry Andric };
3220b57cec5SDimitry Andric 
3230b57cec5SDimitry Andric class SymbolContextSpecifier {
3240b57cec5SDimitry Andric public:
3250b57cec5SDimitry Andric   enum SpecificationType {
3260b57cec5SDimitry Andric     eNothingSpecified = 0,
3270b57cec5SDimitry Andric     eModuleSpecified = 1 << 0,
3280b57cec5SDimitry Andric     eFileSpecified = 1 << 1,
3290b57cec5SDimitry Andric     eLineStartSpecified = 1 << 2,
3300b57cec5SDimitry Andric     eLineEndSpecified = 1 << 3,
3310b57cec5SDimitry Andric     eFunctionSpecified = 1 << 4,
3320b57cec5SDimitry Andric     eClassOrNamespaceSpecified = 1 << 5,
3330b57cec5SDimitry Andric     eAddressRangeSpecified = 1 << 6
3340b57cec5SDimitry Andric   };
3350b57cec5SDimitry Andric 
3360b57cec5SDimitry Andric   // This one produces a specifier that matches everything...
3370b57cec5SDimitry Andric   SymbolContextSpecifier(const lldb::TargetSP &target_sp);
3380b57cec5SDimitry Andric 
3390b57cec5SDimitry Andric   ~SymbolContextSpecifier();
3400b57cec5SDimitry Andric 
3410b57cec5SDimitry Andric   bool AddSpecification(const char *spec_string, SpecificationType type);
3420b57cec5SDimitry Andric 
3430b57cec5SDimitry Andric   bool AddLineSpecification(uint32_t line_no, SpecificationType type);
3440b57cec5SDimitry Andric 
3450b57cec5SDimitry Andric   void Clear();
3460b57cec5SDimitry Andric 
347e8d8bef9SDimitry Andric   bool SymbolContextMatches(const SymbolContext &sc);
3480b57cec5SDimitry Andric 
3490b57cec5SDimitry Andric   bool AddressMatches(lldb::addr_t addr);
3500b57cec5SDimitry Andric 
3510b57cec5SDimitry Andric   void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
3520b57cec5SDimitry Andric 
3530b57cec5SDimitry Andric private:
3540b57cec5SDimitry Andric   lldb::TargetSP m_target_sp;
3550b57cec5SDimitry Andric   std::string m_module_spec;
3560b57cec5SDimitry Andric   lldb::ModuleSP m_module_sp;
3570b57cec5SDimitry Andric   std::unique_ptr<FileSpec> m_file_spec_up;
3580b57cec5SDimitry Andric   size_t m_start_line;
3590b57cec5SDimitry Andric   size_t m_end_line;
3600b57cec5SDimitry Andric   std::string m_function_spec;
3610b57cec5SDimitry Andric   std::string m_class_name;
3620b57cec5SDimitry Andric   std::unique_ptr<AddressRange> m_address_range_up;
3630b57cec5SDimitry Andric   uint32_t m_type; // Or'ed bits from SpecificationType
3640b57cec5SDimitry Andric };
3650b57cec5SDimitry Andric 
3660b57cec5SDimitry Andric /// \class SymbolContextList SymbolContext.h "lldb/Symbol/SymbolContext.h"
3670b57cec5SDimitry Andric /// Defines a list of symbol context objects.
3680b57cec5SDimitry Andric ///
3690b57cec5SDimitry Andric /// This class provides a common structure that can be used to contain the
3700b57cec5SDimitry Andric /// result of a query that can contain a multiple results. Examples of such
3710b57cec5SDimitry Andric /// queries include:
3720b57cec5SDimitry Andric ///     \li Looking up a function by name.
3730b57cec5SDimitry Andric ///     \li Finding all addresses for a specified file and line number.
3740b57cec5SDimitry Andric class SymbolContextList {
3750b57cec5SDimitry Andric public:
3760b57cec5SDimitry Andric   /// Default constructor.
3770b57cec5SDimitry Andric   ///
3780b57cec5SDimitry Andric   /// Initialize with an empty list.
3790b57cec5SDimitry Andric   SymbolContextList();
3800b57cec5SDimitry Andric 
3810b57cec5SDimitry Andric   /// Destructor.
3820b57cec5SDimitry Andric   ~SymbolContextList();
3830b57cec5SDimitry Andric 
3840b57cec5SDimitry Andric   /// Append a new symbol context to the list.
3850b57cec5SDimitry Andric   ///
3860b57cec5SDimitry Andric   /// \param[in] sc
3870b57cec5SDimitry Andric   ///     A symbol context to append to the list.
3880b57cec5SDimitry Andric   void Append(const SymbolContext &sc);
3890b57cec5SDimitry Andric 
3900b57cec5SDimitry Andric   void Append(const SymbolContextList &sc_list);
3910b57cec5SDimitry Andric 
3920b57cec5SDimitry Andric   bool AppendIfUnique(const SymbolContext &sc, bool merge_symbol_into_function);
3930b57cec5SDimitry Andric 
3940b57cec5SDimitry Andric   uint32_t AppendIfUnique(const SymbolContextList &sc_list,
3950b57cec5SDimitry Andric                           bool merge_symbol_into_function);
3960b57cec5SDimitry Andric 
3970b57cec5SDimitry Andric   /// Clear the object's state.
3980b57cec5SDimitry Andric   ///
3990b57cec5SDimitry Andric   /// Clears the symbol context list.
4000b57cec5SDimitry Andric   void Clear();
4010b57cec5SDimitry Andric 
4020b57cec5SDimitry Andric   /// Dump a description of this object to a Stream.
4030b57cec5SDimitry Andric   ///
4040b57cec5SDimitry Andric   /// Dump a description of the contents of each symbol context in the list to
4050b57cec5SDimitry Andric   /// the supplied stream \a s.
4060b57cec5SDimitry Andric   ///
4070b57cec5SDimitry Andric   /// \param[in] s
4080b57cec5SDimitry Andric   ///     The stream to which to dump the object description.
4090b57cec5SDimitry Andric   void Dump(Stream *s, Target *target) const;
4100b57cec5SDimitry Andric 
4110b57cec5SDimitry Andric   /// Get accessor for a symbol context at index \a idx.
4120b57cec5SDimitry Andric   ///
4130b57cec5SDimitry Andric   /// Dump a description of the contents of each symbol context in the list to
4140b57cec5SDimitry Andric   /// the supplied stream \a s.
4150b57cec5SDimitry Andric   ///
4160b57cec5SDimitry Andric   /// \param[in] idx
4170b57cec5SDimitry Andric   ///     The zero based index into the symbol context list.
4180b57cec5SDimitry Andric   ///
4190b57cec5SDimitry Andric   /// \param[out] sc
4200b57cec5SDimitry Andric   ///     A reference to the symbol context to fill in.
4210b57cec5SDimitry Andric   ///
4220b57cec5SDimitry Andric   /// \return
4230b57cec5SDimitry Andric   ///     Returns \b true if \a idx was a valid index into this
4240b57cec5SDimitry Andric   ///     symbol context list and \a sc was filled in, \b false
4250b57cec5SDimitry Andric   ///     otherwise.
4260b57cec5SDimitry Andric   bool GetContextAtIndex(size_t idx, SymbolContext &sc) const;
4270b57cec5SDimitry Andric 
4280b57cec5SDimitry Andric   /// Direct reference accessor for a symbol context at index \a idx.
4290b57cec5SDimitry Andric   ///
4300b57cec5SDimitry Andric   /// The index \a idx must be a valid index, no error checking will be done
4310b57cec5SDimitry Andric   /// to ensure that it is valid.
4320b57cec5SDimitry Andric   ///
4330b57cec5SDimitry Andric   /// \param[in] idx
4340b57cec5SDimitry Andric   ///     The zero based index into the symbol context list.
4350b57cec5SDimitry Andric   ///
4360b57cec5SDimitry Andric   /// \return
4370b57cec5SDimitry Andric   ///     A const reference to the symbol context to fill in.
4380b57cec5SDimitry Andric   SymbolContext &operator[](size_t idx) { return m_symbol_contexts[idx]; }
4390b57cec5SDimitry Andric 
4400b57cec5SDimitry Andric   const SymbolContext &operator[](size_t idx) const {
4410b57cec5SDimitry Andric     return m_symbol_contexts[idx];
4420b57cec5SDimitry Andric   }
4430b57cec5SDimitry Andric 
4440b57cec5SDimitry Andric   bool RemoveContextAtIndex(size_t idx);
4450b57cec5SDimitry Andric 
4460b57cec5SDimitry Andric   /// Get accessor for a symbol context list size.
4470b57cec5SDimitry Andric   ///
4480b57cec5SDimitry Andric   /// \return
4490b57cec5SDimitry Andric   ///     Returns the number of symbol context objects in the list.
4500b57cec5SDimitry Andric   uint32_t GetSize() const;
4510b57cec5SDimitry Andric 
4529dba64beSDimitry Andric   bool IsEmpty() const;
4539dba64beSDimitry Andric 
4540b57cec5SDimitry Andric   uint32_t NumLineEntriesWithLine(uint32_t line) const;
4550b57cec5SDimitry Andric 
4560b57cec5SDimitry Andric   void GetDescription(Stream *s, lldb::DescriptionLevel level,
4570b57cec5SDimitry Andric                       Target *target) const;
4580b57cec5SDimitry Andric 
4590b57cec5SDimitry Andric protected:
4600b57cec5SDimitry Andric   typedef std::vector<SymbolContext>
4610b57cec5SDimitry Andric       collection; ///< The collection type for the list.
46206c3fb27SDimitry Andric   typedef collection::const_iterator const_iterator;
4630b57cec5SDimitry Andric 
4640b57cec5SDimitry Andric   // Member variables.
4650b57cec5SDimitry Andric   collection m_symbol_contexts; ///< The list of symbol contexts.
4660b57cec5SDimitry Andric 
4670b57cec5SDimitry Andric public:
begin()46806c3fb27SDimitry Andric   const_iterator begin() const { return m_symbol_contexts.begin(); }
end()46906c3fb27SDimitry Andric   const_iterator end() const { return m_symbol_contexts.end(); }
47006c3fb27SDimitry Andric 
4710b57cec5SDimitry Andric   typedef AdaptedIterable<collection, SymbolContext, vector_adapter>
4720b57cec5SDimitry Andric       SymbolContextIterable;
SymbolContexts()4730b57cec5SDimitry Andric   SymbolContextIterable SymbolContexts() {
4740b57cec5SDimitry Andric     return SymbolContextIterable(m_symbol_contexts);
4750b57cec5SDimitry Andric   }
4760b57cec5SDimitry Andric };
4770b57cec5SDimitry Andric 
4780b57cec5SDimitry Andric bool operator==(const SymbolContext &lhs, const SymbolContext &rhs);
4790b57cec5SDimitry Andric bool operator!=(const SymbolContext &lhs, const SymbolContext &rhs);
4800b57cec5SDimitry Andric 
4810b57cec5SDimitry Andric bool operator==(const SymbolContextList &lhs, const SymbolContextList &rhs);
4820b57cec5SDimitry Andric bool operator!=(const SymbolContextList &lhs, const SymbolContextList &rhs);
4830b57cec5SDimitry Andric 
4840b57cec5SDimitry Andric } // namespace lldb_private
4850b57cec5SDimitry Andric 
4865ffd83dbSDimitry Andric #endif // LLDB_SYMBOL_SYMBOLCONTEXT_H
487