Block.h revision 1bd2b2feb7694e06b9a971063c283f9c490479d2
1//===-- Block.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#ifndef liblldb_Block_h_ 11#define liblldb_Block_h_ 12 13#include "lldb/lldb-private.h" 14#include "lldb/Core/AddressRange.h" 15#include "lldb/Core/Stream.h" 16#include "lldb/Core/UserID.h" 17#include "lldb/Core/VMRange.h" 18#include "lldb/Symbol/LineEntry.h" 19#include "lldb/Symbol/SymbolContext.h" 20 21namespace lldb_private { 22 23//---------------------------------------------------------------------- 24/// @class Block Block.h "lldb/Symbol/Block.h" 25/// @brief A class that describes a single lexical block. 26/// 27/// A Function object owns a BlockList object which owns one or more 28/// Block objects. The BlockList object contains a section offset 29/// address range, and Block objects contain one or more ranges 30/// which are offsets into that range. Blocks are can have discontiguous 31/// ranges within the BlockList adress range, and each block can 32/// contain child blocks each with their own sets of ranges. 33/// 34/// Each block has a variable list that represents local, argument, and 35/// static variables that are scoped to the block. 36/// 37/// Inlined functions are representated by attaching a 38/// InlineFunctionInfo shared pointer object to a block. Inlined 39/// functions are represented as named blocks. 40//---------------------------------------------------------------------- 41class Block : 42 public UserID, 43 public SymbolContextScope 44{ 45public: 46 47 //------------------------------------------------------------------ 48 /// Construct with a User ID \a uid, \a depth. 49 /// 50 /// Initialize this block with the specified UID \a uid. The 51 /// \a depth in the \a block_list is used to represent the parent, 52 /// sibling, and child block information and also allows for partial 53 /// parsing at the block level. 54 /// 55 /// @param[in] uid 56 /// The UID for a given block. This value is given by the 57 /// SymbolFile plug-in and can be any value that helps the 58 /// SymbolFile plug-in to match this block back to the debug 59 /// information data that it parses for further or more in 60 /// depth parsing. Common values would be the index into a 61 /// table, or an offset into the debug information. 62 /// 63 /// @param[in] depth 64 /// The integer depth of this block in the block list hierarchy. 65 /// 66 /// @param[in] block_list 67 /// The block list that this object belongs to. 68 /// 69 /// @see BlockList 70 //------------------------------------------------------------------ 71 Block (lldb::user_id_t uid); 72 73 //------------------------------------------------------------------ 74 /// Destructor. 75 //------------------------------------------------------------------ 76 ~Block (); 77 78 //------------------------------------------------------------------ 79 /// Add a child to this object. 80 /// 81 /// @param[in] child_block_sp 82 /// A shared pointer to a child block that will get added to 83 /// this block. 84 //------------------------------------------------------------------ 85 void 86 AddChild (const lldb::BlockSP &child_block_sp); 87 88 //------------------------------------------------------------------ 89 /// Add a new offset range to this block. 90 /// 91 /// @param[in] start_offset 92 /// An offset into this Function's address range that 93 /// describes the start address of a range for this block. 94 /// 95 /// @param[in] end_offset 96 /// An offset into this Function's address range that 97 /// describes the end address of a range for this block. 98 //------------------------------------------------------------------ 99 void 100 AddRange(lldb::addr_t start_offset, lldb::addr_t end_offset); 101 102 //------------------------------------------------------------------ 103 /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*) 104 /// 105 /// @see SymbolContextScope 106 //------------------------------------------------------------------ 107 virtual void 108 CalculateSymbolContext(SymbolContext* sc); 109 110 //------------------------------------------------------------------ 111 /// Check if an offset is in one of the block offset ranges. 112 /// 113 /// @param[in] range_offset 114 /// An offset into the Function's address range. 115 /// 116 /// @return 117 /// Returns \b true if \a range_offset falls in one of this 118 /// block's ranges, \b false otherwise. 119 //------------------------------------------------------------------ 120 bool 121 Contains (lldb::addr_t range_offset) const; 122 123 //------------------------------------------------------------------ 124 /// Check if a offset range is in one of the block offset ranges. 125 /// 126 /// @param[in] range 127 /// An offset range into the Function's address range. 128 /// 129 /// @return 130 /// Returns \b true if \a range falls in one of this 131 /// block's ranges, \b false otherwise. 132 //------------------------------------------------------------------ 133 bool 134 Contains (const VMRange& range) const; 135 136 //------------------------------------------------------------------ 137 /// Check if this object contains "block" as a child block at any 138 /// depth. 139 /// 140 /// @param[in] block 141 /// A potential child block. 142 /// 143 /// @return 144 /// Returns \b true if \a block is a child of this block, \b 145 /// false otherwise. 146 //------------------------------------------------------------------ 147 bool 148 Contains (const Block *block) const; 149 150 //------------------------------------------------------------------ 151 /// Dump the block contents. 152 /// 153 /// @param[in] s 154 /// The stream to which to dump the object descripton. 155 /// 156 /// @param[in] base_addr 157 /// The resolved start address of the Function's address 158 /// range. This should be resolved as the file or load address 159 /// prior to passing the value into this function for dumping. 160 /// 161 /// @param[in] depth 162 /// Limit the number of levels deep that this function should 163 /// print as this block can contain child blocks. Specify 164 /// INT_MAX to dump all child blocks. 165 /// 166 /// @param[in] show_context 167 /// If \b true, variables will dump their context information. 168 //------------------------------------------------------------------ 169 void 170 Dump (Stream *s, lldb::addr_t base_addr, int32_t depth, bool show_context) const; 171 172 void 173 DumpStopContext (Stream *s, 174 const SymbolContext *sc, 175 const Declaration *child_inline_call_site, 176 bool show_fullpaths, 177 bool show_inline_blocks); 178 179 //------------------------------------------------------------------ 180 /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*) 181 /// 182 /// @see SymbolContextScope 183 //------------------------------------------------------------------ 184 virtual void 185 DumpSymbolContext(Stream *s); 186 187 void 188 DumpAddressRanges (Stream *s, 189 lldb::addr_t base_addr); 190 191 void 192 GetDescription (Stream *s, 193 Function *function, 194 lldb::DescriptionLevel level, 195 Target *target) const; 196 197 //------------------------------------------------------------------ 198 /// Get the parent block. 199 /// 200 /// @return 201 /// The parent block pointer, or NULL if this block has no 202 /// parent. 203 //------------------------------------------------------------------ 204 Block * 205 GetParent () const; 206 207 208 //------------------------------------------------------------------ 209 /// Get the inlined block that contains this block. 210 /// 211 /// @return 212 /// If this block contains inlined function info, it will return 213 /// this block, else parent blocks will be searched to see if 214 /// any contain this block. NULL will be returned if this block 215 /// nor any parent blocks are inlined function blocks. 216 //------------------------------------------------------------------ 217 Block * 218 GetContainingInlinedBlock (); 219 220 //------------------------------------------------------------------ 221 /// Get the inlined parent block for this block. 222 /// 223 /// @return 224 /// The parent block pointer, or NULL if this block has no 225 /// parent. 226 //------------------------------------------------------------------ 227 Block * 228 GetInlinedParent (); 229 230 //------------------------------------------------------------------ 231 /// Get the sibling block for this block. 232 /// 233 /// @return 234 /// The sibling block pointer, or NULL if this block has no 235 /// sibling. 236 //------------------------------------------------------------------ 237 Block * 238 GetSibling () const 239 { 240 return m_sibling; 241 } 242 243 //------------------------------------------------------------------ 244 /// Get the first child block. 245 /// 246 /// @return 247 /// The first child block pointer, or NULL if this block has no 248 /// children. 249 //------------------------------------------------------------------ 250 Block * 251 GetFirstChild () const 252 { 253 if (m_children.empty()) 254 return NULL; 255 return m_children.front().get(); 256 } 257 258 //------------------------------------------------------------------ 259 /// Get the variable list for this block and optionally all child 260 /// blocks if \a get_child_variables is \b true. 261 /// 262 /// @param[in] get_child_variables 263 /// If \b true, all variables from all child blocks will be 264 /// added to the variable list. 265 /// 266 /// @param[in] can_create 267 /// If \b true, the variables can be parsed if they already 268 /// haven't been, else the current state of the block will be 269 /// returned. Passing \b true for this parameter can be used 270 /// to see the current state of what has been parsed up to this 271 /// point. 272 /// 273 /// @param[in] add_inline_child_block_variables 274 /// If this is \b false, no child variables of child blocks 275 /// that are inlined functions will be gotten. If \b true then 276 /// all child variables will be added regardless of whether they 277 /// come from inlined functions or not. 278 /// 279 /// @return 280 /// A variable list shared pointer that contains all variables 281 /// for this block. 282 //------------------------------------------------------------------ 283 lldb::VariableListSP 284 GetBlockVariableList (bool can_create); 285 286 287 uint32_t 288 AppendBlockVariables (bool can_create, 289 bool get_child_block_variables, 290 bool stop_if_child_block_is_inlined_function, 291 VariableList *variable_list); 292 293 //------------------------------------------------------------------ 294 /// Appends the variables from this block, and optionally from all 295 /// parent blocks, to \a variable_list. 296 /// 297 /// @param[in] can_create 298 /// If \b true, the variables can be parsed if they already 299 /// haven't been, else the current state of the block will be 300 /// returned. Passing \b true for this parameter can be used 301 /// to see the current state of what has been parsed up to this 302 /// point. 303 /// 304 /// @param[in] get_parent_variables 305 /// If \b true, all variables from all parent blocks will be 306 /// added to the variable list. 307 /// 308 /// @param[in] stop_if_block_is_inlined_function 309 /// If \b true, all variables from all parent blocks will be 310 /// added to the variable list until there are no parent blocks 311 /// or the parent block has inlined function info. 312 /// 313 /// @param[in/out] variable_list 314 /// All variables in this block, and optionally all parent 315 /// blocks will be added to this list. 316 /// 317 /// @return 318 /// The number of variable that were appended to \a 319 /// variable_list. 320 //------------------------------------------------------------------ 321 uint32_t 322 AppendVariables (bool can_create, 323 bool get_parent_variables, 324 bool stop_if_block_is_inlined_function, 325 VariableList *variable_list); 326 327 //------------------------------------------------------------------ 328 /// Get const accessor for any inlined function information. 329 /// 330 /// @return 331 /// A comst pointer to any inlined function information, or NULL 332 /// if this is a regular block. 333 //------------------------------------------------------------------ 334 const InlineFunctionInfo* 335 GetInlinedFunctionInfo () const 336 { 337 return m_inlineInfoSP.get(); 338 } 339 340 //------------------------------------------------------------------ 341 /// Get the memory cost of this object. 342 /// 343 /// Returns the cost of this object plus any owned objects from the 344 /// ranges, variables, and inline function information. 345 /// 346 /// @return 347 /// The number of bytes that this object occupies in memory. 348 //------------------------------------------------------------------ 349 size_t 350 MemorySize() const; 351 352 //------------------------------------------------------------------ 353 /// Set accessor for any inlined function information. 354 /// 355 /// @param[in] name 356 /// The method name for the inlined function. This value should 357 /// not be NULL. 358 /// 359 /// @param[in] mangled 360 /// The mangled method name for the inlined function. This can 361 /// be NULL if there is no mangled name for an inlined function 362 /// or if the name is the same as \a name. 363 /// 364 /// @param[in] decl_ptr 365 /// A optional pointer to declaration information for the 366 /// inlined function information. This value can be NULL to 367 /// indicate that no declaration information is available. 368 /// 369 /// @param[in] call_decl_ptr 370 /// Optional calling location declaration information that 371 /// describes from where this inlined function was called. 372 //------------------------------------------------------------------ 373 void 374 SetInlinedFunctionInfo (const char *name, 375 const char *mangled, 376 const Declaration *decl_ptr, 377 const Declaration *call_decl_ptr); 378 379 380 void 381 SetParentScope (SymbolContextScope *parent_scope) 382 { 383 m_parent_scope = parent_scope; 384 } 385 386 void 387 SetSibling (Block *block) 388 { 389 m_sibling = block; 390 } 391 392 //------------------------------------------------------------------ 393 /// Set accessor for the variable list. 394 /// 395 /// Called by the SymbolFile plug-ins after they have parsed the 396 /// variable lists and are ready to hand ownership of the list over 397 /// to this object. 398 /// 399 /// @param[in] variable_list_sp 400 /// A shared pointer to a VariableList. 401 //------------------------------------------------------------------ 402 void 403 SetVariableList (lldb::VariableListSP& variable_list_sp) 404 { 405 m_variable_list_sp = variable_list_sp; 406 } 407 408 409 410 bool 411 BlockInfoHasBeenParsed() const 412 { 413 return m_parsed_block_info; 414 } 415 416 void 417 SetBlockInfoHasBeenParsed (bool b, bool set_children); 418 419 Block * 420 FindBlockByID (lldb::user_id_t block_id); 421 422 bool 423 GetRangeContainingOffset (const lldb::addr_t offset, VMRange &range); 424 425 bool 426 GetRangeContainingAddress (const Address& addr, AddressRange &range); 427 428 //------------------------------------------------------------------ 429 // Since blocks might have multiple discontiguous addresss ranges, 430 // we need to be able to get at any of the address ranges in a block. 431 //------------------------------------------------------------------ 432 bool 433 GetRangeAtIndex (uint32_t range_idx, 434 AddressRange &range); 435 436 bool 437 GetStartAddress (Address &addr); 438 439 void 440 SetDidParseVariables (bool b, bool set_children); 441 442protected: 443 typedef std::vector<lldb::BlockSP> collection; 444 //------------------------------------------------------------------ 445 // Member variables. 446 //------------------------------------------------------------------ 447 SymbolContextScope *m_parent_scope; 448 Block *m_sibling; 449 collection m_children; 450 VMRange::collection m_ranges; ///< A list of address offset ranges relative to the function's section/offset address. 451 lldb::InlineFunctionInfoSP m_inlineInfoSP; ///< Inlined function information. 452 lldb::VariableListSP m_variable_list_sp; ///< The variable list for all local, static and paramter variables scoped to this block. 453 bool m_parsed_block_info:1, ///< Set to true if this block and it's children have all been parsed 454 m_parsed_block_variables:1, 455 m_parsed_child_blocks:1; 456 457private: 458 DISALLOW_COPY_AND_ASSIGN (Block); 459}; 460 461 462} // namespace lldb_private 463 464#endif // liblldb_Block_h_ 465