SymbolContext.h revision 23b8abbe214c252028f6e09f79169529c846409d
1//===-- SymbolContext.h -----------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10 11#ifndef liblldb_SymbolContext_h_ 12#define liblldb_SymbolContext_h_ 13 14#include <vector> 15 16#include "lldb/lldb-private.h" 17#include "lldb/Core/Address.h" 18#include "lldb/Symbol/ClangASTType.h" 19#include "lldb/Symbol/LineEntry.h" 20 21namespace lldb_private { 22 23class SymbolContextScope; 24//---------------------------------------------------------------------- 25/// @class SymbolContext SymbolContext.h "lldb/Symbol/SymbolContext.h" 26/// @brief Defines a symbol context baton that can be handed other debug 27/// core functions. 28/// 29/// Many debugger functions require a context when doing lookups. This 30/// class provides a common structure that can be used as the result 31/// of a query that can contain a single result. Examples of such 32/// queries include 33/// @li Looking up a load address. 34//---------------------------------------------------------------------- 35class SymbolContext 36{ 37public: 38 39 //------------------------------------------------------------------ 40 /// Default constructor. 41 /// 42 /// Initialize all pointer members to NULL and all struct members 43 /// to their default state. 44 //------------------------------------------------------------------ 45 SymbolContext (); 46 47 //------------------------------------------------------------------ 48 /// Construct with an object that knows how to reconstruct its 49 /// symbol context. 50 /// 51 /// @param[in] sc_scope 52 /// A symbol context scope object that knows how to reconstruct 53 /// it's context. 54 //------------------------------------------------------------------ 55 explicit 56 SymbolContext (SymbolContextScope *sc_scope); 57 58 //------------------------------------------------------------------ 59 /// Construct with module, and optional compile unit, function, 60 /// block, line table, line entry and symbol. 61 /// 62 /// Initialize all pointer to the specified values. 63 /// 64 /// @param[in] module 65 /// A Module pointer to the module for this context. 66 /// 67 /// @param[in] comp_unit 68 /// A CompileUnit pointer to the compile unit for this context. 69 /// 70 /// @param[in] function 71 /// A Function pointer to the function for this context. 72 /// 73 /// @param[in] block 74 /// A Block pointer to the deepest block for this context. 75 /// 76 /// @param[in] line_entry 77 /// A LineEntry pointer to the line entry for this context. 78 /// 79 /// @param[in] symbol 80 /// A Symbol pointer to the symbol for this context. 81 //------------------------------------------------------------------ 82 explicit 83 SymbolContext (const lldb::TargetSP &target_sp, 84 const lldb::ModuleSP &module_sp, 85 CompileUnit *comp_unit = NULL, 86 Function *function = NULL, 87 Block *block = NULL, 88 LineEntry *line_entry = NULL, 89 Symbol *symbol = NULL); 90 91 // This version sets the target to a NULL TargetSP if you don't know it. 92 explicit 93 SymbolContext (const lldb::ModuleSP &module_sp, 94 CompileUnit *comp_unit = NULL, 95 Function *function = NULL, 96 Block *block = NULL, 97 LineEntry *line_entry = NULL, 98 Symbol *symbol = NULL); 99 100 ~SymbolContext (); 101 //------------------------------------------------------------------ 102 /// Copy constructor 103 /// 104 /// Makes a copy of the another SymbolContext object \a rhs. 105 /// 106 /// @param[in] rhs 107 /// A const SymbolContext object reference to copy. 108 //------------------------------------------------------------------ 109 SymbolContext (const SymbolContext& rhs); 110 111 //------------------------------------------------------------------ 112 /// Assignment operator. 113 /// 114 /// Copies the address value from another SymbolContext object \a 115 /// rhs into \a this object. 116 /// 117 /// @param[in] rhs 118 /// A const SymbolContext object reference to copy. 119 /// 120 /// @return 121 /// A const SymbolContext object reference to \a this. 122 //------------------------------------------------------------------ 123 const SymbolContext& 124 operator= (const SymbolContext& rhs); 125 126 //------------------------------------------------------------------ 127 /// Clear the object's state. 128 /// 129 /// Resets all pointer members to NULL, and clears any class objects 130 /// to their default state. 131 //------------------------------------------------------------------ 132 void 133 Clear (); 134 135 //------------------------------------------------------------------ 136 /// Dump a description of this object to a Stream. 137 /// 138 /// Dump a description of the contents of this object to the 139 /// supplied stream \a s. 140 /// 141 /// @param[in] s 142 /// The stream to which to dump the object descripton. 143 //------------------------------------------------------------------ 144 void 145 Dump (Stream *s, Target *target) const; 146 147 //------------------------------------------------------------------ 148 /// Dump the stop context in this object to a Stream. 149 /// 150 /// Dump the best description of this object to the stream. The 151 /// information displayed depends on the amount and quality of the 152 /// information in this context. If a module, function, file and 153 /// line number are available, they will be dumped. If only a 154 /// module and function or symbol name with offset is available, 155 /// that will be ouput. Else just the address at which the target 156 /// was stopped will be displayed. 157 /// 158 /// @param[in] s 159 /// The stream to which to dump the object descripton. 160 /// 161 /// @param[in] so_addr 162 /// The resolved section offset address. 163 //------------------------------------------------------------------ 164 bool 165 DumpStopContext (Stream *s, 166 ExecutionContextScope *exe_scope, 167 const Address &so_addr, 168 bool show_fullpaths, 169 bool show_module, 170 bool show_inlined_frames) const; 171 172 //------------------------------------------------------------------ 173 /// Get the address range contained within a symbol context. 174 /// 175 /// Address range priority is as follows: 176 /// - line_entry address range if line_entry is valid and eSymbolContextLineEntry is set in \a scope 177 /// - block address range if block is not NULL and eSymbolContextBlock is set in \a scope 178 /// - function address range if function is not NULL and eSymbolContextFunction is set in \a scope 179 /// - symbol address range if symbol is not NULL and eSymbolContextSymbol is set in \a scope 180 /// 181 /// @param[in] scope 182 /// A mask of symbol context bits telling this function which 183 /// address ranges it can use when trying to extract one from 184 /// the valid (non-NULL) symbol context classes. 185 /// 186 /// @param[in] range_idx 187 /// The address range index to grab. Since many functions and 188 /// blocks are not always contiguous, they may have more than 189 /// one address range. 190 /// 191 /// @param[in] use_inline_block_range 192 /// If \a scope has the eSymbolContextBlock bit set, and there 193 /// is a valid block in the symbol context, return the block 194 /// address range for the containing inline function block, not 195 /// the deepest most block. This allows us to extract information 196 /// for the address range of the inlined function block, not 197 /// the deepest lexical block. 198 /// 199 /// @param[out] range 200 /// An address range object that will be filled in if \b true 201 /// is returned. 202 /// 203 /// @return 204 /// \b True if this symbol context contains items that describe 205 /// an address range, \b false otherwise. 206 //------------------------------------------------------------------ 207 bool 208 GetAddressRange (uint32_t scope, 209 uint32_t range_idx, 210 bool use_inline_block_range, 211 AddressRange &range) const; 212 213 214 void 215 GetDescription(Stream *s, 216 lldb::DescriptionLevel level, 217 Target *target) const; 218 219 uint32_t 220 GetResolvedMask () const; 221 222 223 //------------------------------------------------------------------ 224 /// Find a function matching the given name, working out from this 225 /// symbol context. 226 /// 227 /// @return 228 /// The number of symbol contexts found. 229 //------------------------------------------------------------------ 230 size_t 231 FindFunctionsByName (const ConstString &name, 232 bool include_symbols, 233 bool append, 234 SymbolContextList &sc_list) const; 235 236 237 ClangNamespaceDecl 238 FindNamespace (const ConstString &name) const; 239 240 //------------------------------------------------------------------ 241 /// Find a variable matching the given name, working out from this 242 /// symbol context. 243 /// 244 /// @return 245 /// A shared pointer to the variable found. 246 //------------------------------------------------------------------ 247 //lldb::VariableSP 248 //FindVariableByName (const char *name) const; 249 250 //------------------------------------------------------------------ 251 /// Find a type matching the given name, working out from this 252 /// symbol context. 253 /// 254 /// @return 255 /// A shared pointer to the variable found. 256 //------------------------------------------------------------------ 257 lldb::TypeSP 258 FindTypeByName (const ConstString &name) const; 259 260// static SymbolContext 261// CreateSymbolContextFromDescription (lldb::TargetSP &target, 262// const char *module, 263// const char *comp_unit, 264// const char *function, 265// const char *block_spec 266// const char *line_number, 267// const char *symbol); 268 269 bool 270 GetParentInlinedFrameInfo (const Address &curr_frame_pc, 271 bool is_concrete_frame, 272 SymbolContext &next_frame_sc, 273 Address &inlined_frame_addr) const; 274 275 //------------------------------------------------------------------ 276 // Member variables 277 //------------------------------------------------------------------ 278 lldb::TargetSP target_sp; ///< The Target for a given query 279 lldb::ModuleSP module_sp; ///< The Module for a given query 280 CompileUnit * comp_unit; ///< The CompileUnit for a given query 281 Function * function; ///< The Function for a given query 282 Block * block; ///< The Block for a given query 283 LineEntry line_entry; ///< The LineEntry for a given query 284 Symbol * symbol; ///< The Symbol for a given query 285}; 286 287 288class SymbolContextSpecifier 289{ 290public: 291 typedef enum SpecificationType 292 { 293 eNothingSpecified = 0, 294 eModuleSpecified = 1 << 0, 295 eFileSpecified = 1 << 1, 296 eLineStartSpecified = 1 << 2, 297 eLineEndSpecified = 1 << 3, 298 eFunctionSpecified = 1 << 4, 299 eClassOrNamespaceSpecified = 1 << 5, 300 eAddressRangeSpecified = 1 << 6 301 } SpecificationType; 302 303 // This one produces a specifier that matches everything... 304 SymbolContextSpecifier (const lldb::TargetSP& target_sp); 305 306 ~SymbolContextSpecifier(); 307 308 bool 309 AddSpecification (const char *spec_string, SpecificationType type); 310 311 bool 312 AddLineSpecification (uint32_t line_no, SpecificationType type); 313 314 void 315 Clear(); 316 317 bool 318 SymbolContextMatches(SymbolContext &sc); 319 320 bool 321 AddressMatches(lldb::addr_t addr); 322 323 void 324 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 325 326private: 327 lldb::TargetSP m_target_sp; 328 std::string m_module_spec; 329 lldb::ModuleSP m_module_sp; 330 std::auto_ptr<FileSpec> m_file_spec_ap; 331 size_t m_start_line; 332 size_t m_end_line; 333 std::string m_function_spec; 334 std::string m_class_name; 335 std::auto_ptr<AddressRange> m_address_range_ap; 336 uint32_t m_type; // Or'ed bits from SpecificationType 337 338}; 339 340//---------------------------------------------------------------------- 341/// @class SymbolContextList SymbolContext.h "lldb/Symbol/SymbolContext.h" 342/// @brief Defines a list of symbol context objects. 343/// 344/// This class provides a common structure that can be used to contain 345/// the result of a query that can contain a multiple results. Examples 346/// of such queries include: 347/// @li Looking up a function by name. 348/// @li Finding all addressses for a specified file and line number. 349//---------------------------------------------------------------------- 350class SymbolContextList 351{ 352public: 353 //------------------------------------------------------------------ 354 /// Default constructor. 355 /// 356 /// Initialize with an empty list. 357 //------------------------------------------------------------------ 358 SymbolContextList (); 359 360 //------------------------------------------------------------------ 361 /// Destructor. 362 //------------------------------------------------------------------ 363 ~SymbolContextList (); 364 365 //------------------------------------------------------------------ 366 /// Append a new symbol context to the list. 367 /// 368 /// @param[in] sc 369 /// A symbol context to append to the list. 370 //------------------------------------------------------------------ 371 void 372 Append (const SymbolContext& sc); 373 374 bool 375 AppendIfUnique (const SymbolContext& sc, bool merge_symbol_into_function); 376 377 //------------------------------------------------------------------ 378 /// Clear the object's state. 379 /// 380 /// Clears the symbol context list. 381 //------------------------------------------------------------------ 382 void 383 Clear(); 384 385 //------------------------------------------------------------------ 386 /// Dump a description of this object to a Stream. 387 /// 388 /// Dump a description of the contents of each symbol context in 389 /// the list to the supplied stream \a s. 390 /// 391 /// @param[in] s 392 /// The stream to which to dump the object descripton. 393 //------------------------------------------------------------------ 394 void 395 Dump(Stream *s, Target *target) const; 396 397 //------------------------------------------------------------------ 398 /// Get accessor for a symbol context at index \a idx. 399 /// 400 /// Dump a description of the contents of each symbol context in 401 /// the list to the supplied stream \a s. 402 /// 403 /// @param[in] idx 404 /// The zero based index into the symbol context list. 405 /// 406 /// @param[out] sc 407 /// A reference to the symbol context to fill in. 408 /// 409 /// @return 410 /// Returns \b true if \a idx was a valid index into this 411 /// symbol context list and \a sc was filled in, \b false 412 /// otherwise. 413 //------------------------------------------------------------------ 414 bool 415 GetContextAtIndex(uint32_t idx, SymbolContext& sc) const; 416 417 bool 418 RemoveContextAtIndex (uint32_t idx); 419 //------------------------------------------------------------------ 420 /// Get accessor for a symbol context list size. 421 /// 422 /// @return 423 /// Returns the number of symbol context objects in the list. 424 //------------------------------------------------------------------ 425 uint32_t 426 GetSize() const; 427 428 uint32_t 429 NumLineEntriesWithLine (uint32_t line) const; 430 431protected: 432 typedef std::vector<SymbolContext> collection; ///< The collection type for the list. 433 434 //------------------------------------------------------------------ 435 // Member variables. 436 //------------------------------------------------------------------ 437 collection m_symbol_contexts; ///< The list of symbol contexts. 438}; 439 440bool operator== (const SymbolContext& lhs, const SymbolContext& rhs); 441bool operator!= (const SymbolContext& lhs, const SymbolContext& rhs); 442 443} // namespace lldb_private 444 445#endif // liblldb_SymbolContext_h_ 446