1 //===-- SymbolContext.h -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_SymbolContext_h_
12 #define liblldb_SymbolContext_h_
16 #include "lldb/lldb-private.h"
17 #include "lldb/Core/Address.h"
18 #include "lldb/Core/Mangled.h"
19 #include "lldb/Symbol/ClangASTType.h"
20 #include "lldb/Symbol/LineEntry.h"
22 namespace lldb_private {
24 class SymbolContextScope;
25 //----------------------------------------------------------------------
26 /// @class SymbolContext SymbolContext.h "lldb/Symbol/SymbolContext.h"
27 /// @brief Defines a symbol context baton that can be handed other debug
30 /// Many debugger functions require a context when doing lookups. This
31 /// class provides a common structure that can be used as the result
32 /// of a query that can contain a single result. Examples of such
34 /// @li Looking up a load address.
35 //----------------------------------------------------------------------
40 //------------------------------------------------------------------
41 /// Default constructor.
43 /// Initialize all pointer members to NULL and all struct members
44 /// to their default state.
45 //------------------------------------------------------------------
48 //------------------------------------------------------------------
49 /// Construct with an object that knows how to reconstruct its
52 /// @param[in] sc_scope
53 /// A symbol context scope object that knows how to reconstruct
55 //------------------------------------------------------------------
57 SymbolContext (SymbolContextScope *sc_scope);
59 //------------------------------------------------------------------
60 /// Construct with module, and optional compile unit, function,
61 /// block, line table, line entry and symbol.
63 /// Initialize all pointer to the specified values.
66 /// A Module pointer to the module for this context.
68 /// @param[in] comp_unit
69 /// A CompileUnit pointer to the compile unit for this context.
71 /// @param[in] function
72 /// A Function pointer to the function for this context.
75 /// A Block pointer to the deepest block for this context.
77 /// @param[in] line_entry
78 /// A LineEntry pointer to the line entry for this context.
81 /// A Symbol pointer to the symbol for this context.
82 //------------------------------------------------------------------
84 SymbolContext (const lldb::TargetSP &target_sp,
85 const lldb::ModuleSP &module_sp,
86 CompileUnit *comp_unit = NULL,
87 Function *function = NULL,
89 LineEntry *line_entry = NULL,
90 Symbol *symbol = NULL);
92 // This version sets the target to a NULL TargetSP if you don't know it.
94 SymbolContext (const lldb::ModuleSP &module_sp,
95 CompileUnit *comp_unit = NULL,
96 Function *function = NULL,
98 LineEntry *line_entry = NULL,
99 Symbol *symbol = NULL);
102 //------------------------------------------------------------------
105 /// Makes a copy of the another SymbolContext object \a rhs.
108 /// A const SymbolContext object reference to copy.
109 //------------------------------------------------------------------
110 SymbolContext (const SymbolContext& rhs);
112 //------------------------------------------------------------------
113 /// Assignment operator.
115 /// Copies the address value from another SymbolContext object \a
116 /// rhs into \a this object.
119 /// A const SymbolContext object reference to copy.
122 /// A const SymbolContext object reference to \a this.
123 //------------------------------------------------------------------
125 operator= (const SymbolContext& rhs);
127 //------------------------------------------------------------------
128 /// Clear the object's state.
130 /// Resets all pointer members to NULL, and clears any class objects
131 /// to their default state.
132 //------------------------------------------------------------------
134 Clear (bool clear_target);
136 //------------------------------------------------------------------
137 /// Dump a description of this object to a Stream.
139 /// Dump a description of the contents of this object to the
140 /// supplied stream \a s.
143 /// The stream to which to dump the object descripton.
144 //------------------------------------------------------------------
146 Dump (Stream *s, Target *target) const;
148 //------------------------------------------------------------------
149 /// Dump the stop context in this object to a Stream.
151 /// Dump the best description of this object to the stream. The
152 /// information displayed depends on the amount and quality of the
153 /// information in this context. If a module, function, file and
154 /// line number are available, they will be dumped. If only a
155 /// module and function or symbol name with offset is available,
156 /// that will be output. Else just the address at which the target
157 /// was stopped will be displayed.
160 /// The stream to which to dump the object descripton.
162 /// @param[in] so_addr
163 /// The resolved section offset address.
164 //------------------------------------------------------------------
166 DumpStopContext (Stream *s,
167 ExecutionContextScope *exe_scope,
168 const Address &so_addr,
171 bool show_inlined_frames) const;
173 //------------------------------------------------------------------
174 /// Get the address range contained within a symbol context.
176 /// Address range priority is as follows:
177 /// - line_entry address range if line_entry is valid and eSymbolContextLineEntry is set in \a scope
178 /// - block address range if block is not NULL and eSymbolContextBlock is set in \a scope
179 /// - function address range if function is not NULL and eSymbolContextFunction is set in \a scope
180 /// - symbol address range if symbol is not NULL and eSymbolContextSymbol is set in \a scope
183 /// A mask of symbol context bits telling this function which
184 /// address ranges it can use when trying to extract one from
185 /// the valid (non-NULL) symbol context classes.
187 /// @param[in] range_idx
188 /// The address range index to grab. Since many functions and
189 /// blocks are not always contiguous, they may have more than
190 /// one address range.
192 /// @param[in] use_inline_block_range
193 /// If \a scope has the eSymbolContextBlock bit set, and there
194 /// is a valid block in the symbol context, return the block
195 /// address range for the containing inline function block, not
196 /// the deepest most block. This allows us to extract information
197 /// for the address range of the inlined function block, not
198 /// the deepest lexical block.
200 /// @param[out] range
201 /// An address range object that will be filled in if \b true
205 /// \b True if this symbol context contains items that describe
206 /// an address range, \b false otherwise.
207 //------------------------------------------------------------------
209 GetAddressRange (uint32_t scope,
211 bool use_inline_block_range,
212 AddressRange &range) const;
216 GetDescription(Stream *s,
217 lldb::DescriptionLevel level,
218 Target *target) const;
221 GetResolvedMask () const;
224 //------------------------------------------------------------------
225 /// Find a block that defines the function represented by this
228 /// If this symbol context points to a block that is an inlined
229 /// function, or is contained within an inlined function, the block
230 /// that defines the inlined function is returned.
232 /// If this symbol context has no block in it, or the block is not
233 /// itself an inlined function block or contained within one, we
234 /// return the top level function block.
236 /// This is a handy function to call when you want to get the block
237 /// whose variable list will include the arguments for the function
238 /// that is represented by this symbol context (whether the function
239 /// is an inline function or not).
242 /// The block object pointer that defines the function that is
243 /// represented by this symbol context object, NULL otherwise.
244 //------------------------------------------------------------------
249 //------------------------------------------------------------------
250 /// If this symbol context represents a function that is a method,
251 /// return true and provide information about the method.
253 /// @param[out] language
254 /// If \b true is returned, the language for the method.
256 /// @param[out] is_instance_method
257 /// If \b true is returned, \b true if this is a instance method,
258 /// \b false if this is a static/class function.
260 /// @param[out] language_object_name
261 /// If \b true is returned, the name of the artificial variable
262 /// for the language ("this" for C++, "self" for ObjC).
265 /// \b True if this symbol context represents a function that
266 /// is a method of a class, \b false otherwise.
267 //------------------------------------------------------------------
269 GetFunctionMethodInfo (lldb::LanguageType &language,
270 bool &is_instance_method,
271 ConstString &language_object_name);
273 //------------------------------------------------------------------
274 /// Find a name of the innermost function for the symbol context.
276 /// For instance, if the symbol context contains an inlined block,
277 /// it will return the inlined function name.
279 /// @param[in] prefer_mangled
280 /// if \btrue, then the mangled name will be returned if there
281 /// is one. Otherwise the unmangled name will be returned if it
285 /// The name of the function represented by this symbol context.
286 //------------------------------------------------------------------
288 GetFunctionName (Mangled::NamePreference preference = Mangled::ePreferDemangled) const;
291 //------------------------------------------------------------------
292 /// Get the line entry that corresponds to the function.
294 /// If the symbol context contains an inlined block, the line entry
295 /// for the start address of the inlined function will be returned,
296 /// otherwise the line entry for the start address of the function
297 /// will be returned. This can be used after doing a
298 /// Module::FindFunctions(...) or ModuleList::FindFunctions(...)
299 /// call in order to get the correct line table information for
300 /// the symbol context.
301 /// it will return the inlined function name.
303 /// @param[in] prefer_mangled
304 /// if \btrue, then the mangled name will be returned if there
305 /// is one. Otherwise the unmangled name will be returned if it
309 /// The name of the function represented by this symbol context.
310 //------------------------------------------------------------------
312 GetFunctionStartLineEntry () const;
314 //------------------------------------------------------------------
315 /// Find the block containing the inlined block that contains this block.
317 /// For instance, if the symbol context contains an inlined block,
318 /// it will return the inlined function name.
320 /// @param[in] curr_frame_pc
321 /// The address within the block of this object.
323 /// @param[out] next_frame_sc
324 /// A new symbol context that does what the title says it does.
326 /// @param[out] next_frame_addr
327 /// This is what you should report as the PC in \a next_frame_sc.
330 /// \b true if this SymbolContext specifies a block contained in an
331 /// inlined block. If this returns \b true, \a next_frame_sc and
332 /// \a next_frame_addr will be filled in correctly.
333 //------------------------------------------------------------------
335 GetParentOfInlinedScope (const Address &curr_frame_pc,
336 SymbolContext &next_frame_sc,
337 Address &inlined_frame_addr) const;
339 //------------------------------------------------------------------
341 //------------------------------------------------------------------
342 lldb::TargetSP target_sp; ///< The Target for a given query
343 lldb::ModuleSP module_sp; ///< The Module for a given query
344 CompileUnit * comp_unit; ///< The CompileUnit for a given query
345 Function * function; ///< The Function for a given query
346 Block * block; ///< The Block for a given query
347 LineEntry line_entry; ///< The LineEntry for a given query
348 Symbol * symbol; ///< The Symbol for a given query
352 class SymbolContextSpecifier
355 typedef enum SpecificationType
357 eNothingSpecified = 0,
358 eModuleSpecified = 1 << 0,
359 eFileSpecified = 1 << 1,
360 eLineStartSpecified = 1 << 2,
361 eLineEndSpecified = 1 << 3,
362 eFunctionSpecified = 1 << 4,
363 eClassOrNamespaceSpecified = 1 << 5,
364 eAddressRangeSpecified = 1 << 6
367 // This one produces a specifier that matches everything...
368 SymbolContextSpecifier (const lldb::TargetSP& target_sp);
370 ~SymbolContextSpecifier();
373 AddSpecification (const char *spec_string, SpecificationType type);
376 AddLineSpecification (uint32_t line_no, SpecificationType type);
382 SymbolContextMatches(SymbolContext &sc);
385 AddressMatches(lldb::addr_t addr);
388 GetDescription (Stream *s, lldb::DescriptionLevel level) const;
391 lldb::TargetSP m_target_sp;
392 std::string m_module_spec;
393 lldb::ModuleSP m_module_sp;
394 std::unique_ptr<FileSpec> m_file_spec_ap;
397 std::string m_function_spec;
398 std::string m_class_name;
399 std::unique_ptr<AddressRange> m_address_range_ap;
400 uint32_t m_type; // Or'ed bits from SpecificationType
404 //----------------------------------------------------------------------
405 /// @class SymbolContextList SymbolContext.h "lldb/Symbol/SymbolContext.h"
406 /// @brief Defines a list of symbol context objects.
408 /// This class provides a common structure that can be used to contain
409 /// the result of a query that can contain a multiple results. Examples
410 /// of such queries include:
411 /// @li Looking up a function by name.
412 /// @li Finding all addressses for a specified file and line number.
413 //----------------------------------------------------------------------
414 class SymbolContextList
417 //------------------------------------------------------------------
418 /// Default constructor.
420 /// Initialize with an empty list.
421 //------------------------------------------------------------------
422 SymbolContextList ();
424 //------------------------------------------------------------------
426 //------------------------------------------------------------------
427 ~SymbolContextList ();
429 //------------------------------------------------------------------
430 /// Append a new symbol context to the list.
433 /// A symbol context to append to the list.
434 //------------------------------------------------------------------
436 Append (const SymbolContext& sc);
439 Append (const SymbolContextList& sc_list);
442 AppendIfUnique (const SymbolContext& sc,
443 bool merge_symbol_into_function);
446 MergeSymbolContextIntoFunctionContext (const SymbolContext& symbol_sc,
447 uint32_t start_idx = 0,
448 uint32_t stop_idx = UINT32_MAX);
451 AppendIfUnique (const SymbolContextList& sc_list,
452 bool merge_symbol_into_function);
453 //------------------------------------------------------------------
454 /// Clear the object's state.
456 /// Clears the symbol context list.
457 //------------------------------------------------------------------
461 //------------------------------------------------------------------
462 /// Dump a description of this object to a Stream.
464 /// Dump a description of the contents of each symbol context in
465 /// the list to the supplied stream \a s.
468 /// The stream to which to dump the object descripton.
469 //------------------------------------------------------------------
471 Dump(Stream *s, Target *target) const;
473 //------------------------------------------------------------------
474 /// Get accessor for a symbol context at index \a idx.
476 /// Dump a description of the contents of each symbol context in
477 /// the list to the supplied stream \a s.
480 /// The zero based index into the symbol context list.
483 /// A reference to the symbol context to fill in.
486 /// Returns \b true if \a idx was a valid index into this
487 /// symbol context list and \a sc was filled in, \b false
489 //------------------------------------------------------------------
491 GetContextAtIndex(size_t idx, SymbolContext& sc) const;
493 //------------------------------------------------------------------
494 /// Direct reference accessor for a symbol context at index \a idx.
496 /// The index \a idx must be a valid index, no error checking will
497 /// be done to ensure that it is valid.
500 /// The zero based index into the symbol context list.
503 /// A const reference to the symbol context to fill in.
504 //------------------------------------------------------------------
506 operator [] (size_t idx)
508 return m_symbol_contexts[idx];
512 operator [] (size_t idx) const
514 return m_symbol_contexts[idx];
517 //------------------------------------------------------------------
518 /// Get accessor for the last symbol context in the list.
521 /// A reference to the symbol context to fill in.
524 /// Returns \b true if \a sc was filled in, \b false if the
526 //------------------------------------------------------------------
528 GetLastContext(SymbolContext& sc) const;
531 RemoveContextAtIndex (size_t idx);
532 //------------------------------------------------------------------
533 /// Get accessor for a symbol context list size.
536 /// Returns the number of symbol context objects in the list.
537 //------------------------------------------------------------------
542 NumLineEntriesWithLine (uint32_t line) const;
545 GetDescription(Stream *s,
546 lldb::DescriptionLevel level,
547 Target *target) const;
550 typedef std::vector<SymbolContext> collection; ///< The collection type for the list.
552 //------------------------------------------------------------------
554 //------------------------------------------------------------------
555 collection m_symbol_contexts; ///< The list of symbol contexts.
558 bool operator== (const SymbolContext& lhs, const SymbolContext& rhs);
559 bool operator!= (const SymbolContext& lhs, const SymbolContext& rhs);
561 bool operator== (const SymbolContextList& lhs, const SymbolContextList& rhs);
562 bool operator!= (const SymbolContextList& lhs, const SymbolContextList& rhs);
564 } // namespace lldb_private
566 #endif // liblldb_SymbolContext_h_