Function.h revision 75ccf50c3371d8c8e293af25461705b86fb10a46
1//===-- Function.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_Function_h_ 11#define liblldb_Function_h_ 12 13#include "lldb/Core/AddressRange.h" 14#include "lldb/Symbol/Block.h" 15#include "lldb/Symbol/Declaration.h" 16#include "lldb/Expression/DWARFExpression.h" 17#include "lldb/Core/Mangled.h" 18#include "lldb/Core/UserID.h" 19 20namespace lldb_private { 21 22//---------------------------------------------------------------------- 23/// @class FunctionInfo Function.h "lldb/Symbol/Function.h" 24/// @brief A class that contains generic function information. 25/// 26/// This provides generic function information that gets resused between 27/// inline functions and function types. 28//---------------------------------------------------------------------- 29class FunctionInfo 30{ 31public: 32 //------------------------------------------------------------------ 33 /// Construct with the function method name and optional declaration 34 /// information. 35 /// 36 /// @param[in] name 37 /// A C string name for the method name for this function. This 38 /// value should not be the mangled named, but the simple method 39 /// name. 40 /// 41 /// @param[in] decl_ptr 42 /// Optional declaration information that describes where the 43 /// function was declared. This can be NULL. 44 //------------------------------------------------------------------ 45 FunctionInfo (const char *name, const Declaration *decl_ptr); 46 47 //------------------------------------------------------------------ 48 /// Construct with the function method name and optional declaration 49 /// information. 50 /// 51 /// @param[in] name 52 /// A name for the method name for this function. This value 53 /// should not be the mangled named, but the simple method name. 54 /// 55 /// @param[in] decl_ptr 56 /// Optional declaration information that describes where the 57 /// function was declared. This can be NULL. 58 //------------------------------------------------------------------ 59 FunctionInfo (const ConstString& name, const Declaration *decl_ptr); 60 61 //------------------------------------------------------------------ 62 /// Destructor. 63 /// 64 /// The destructor is virtual since classes inherit from this class. 65 //------------------------------------------------------------------ 66 virtual 67 ~FunctionInfo (); 68 69 //------------------------------------------------------------------ 70 /// Compare two function information objects. 71 /// 72 /// First compares the method names, and if equal, then compares 73 /// the declaration information. 74 /// 75 /// @param[in] lhs 76 /// The Left Hand Side const FunctionInfo object reference. 77 /// 78 /// @param[in] rhs 79 /// The Right Hand Side const FunctionInfo object reference. 80 /// 81 /// @return 82 /// @li -1 if lhs < rhs 83 /// @li 0 if lhs == rhs 84 /// @li 1 if lhs > rhs 85 //------------------------------------------------------------------ 86 static int 87 Compare (const FunctionInfo& lhs, const FunctionInfo& rhs); 88 89 //------------------------------------------------------------------ 90 /// Dump a description of this object to a Stream. 91 /// 92 /// Dump a description of the contents of this object to the 93 /// supplied stream \a s. 94 /// 95 /// @param[in] s 96 /// The stream to which to dump the object descripton. 97 //------------------------------------------------------------------ 98 void 99 Dump (Stream *s) const; 100 101 //------------------------------------------------------------------ 102 /// Get accessor for the declaration information. 103 /// 104 /// @return 105 /// A reference to the declaration object. 106 //------------------------------------------------------------------ 107 Declaration& 108 GetDeclaration (); 109 110 //------------------------------------------------------------------ 111 /// Get const accessor for the declaration information. 112 /// 113 /// @return 114 /// A const reference to the declaration object. 115 //------------------------------------------------------------------ 116 const Declaration& 117 GetDeclaration () const; 118 119 //------------------------------------------------------------------ 120 /// Get accessor for the method name. 121 /// 122 /// @return 123 /// A const reference to the method name object. 124 //------------------------------------------------------------------ 125 const ConstString& 126 GetName () const; 127 128 //------------------------------------------------------------------ 129 /// Get the memory cost of this object. 130 /// 131 /// @return 132 /// The number of bytes that this object occupies in memory. 133 /// The returned value does not include the bytes for any 134 /// shared string values. 135 /// 136 /// @see ConstString::StaticMemorySize () 137 //------------------------------------------------------------------ 138 virtual size_t 139 MemorySize () const; 140 141protected: 142 //------------------------------------------------------------------ 143 // Member variables. 144 //------------------------------------------------------------------ 145 ConstString m_name; ///< Function method name (not a mangled name). 146 Declaration m_declaration; ///< Information describing where this function information was defined. 147}; 148 149 150//---------------------------------------------------------------------- 151/// @class InlineFunctionInfo Function.h "lldb/Symbol/Function.h" 152/// @brief A class that describes information for an inlined function. 153//---------------------------------------------------------------------- 154class InlineFunctionInfo : public FunctionInfo 155{ 156public: 157 //------------------------------------------------------------------ 158 /// Construct with the function method name, mangled name, and 159 /// optional declaration information. 160 /// 161 /// @param[in] name 162 /// A C string name for the method name for this function. This 163 /// value should not be the mangled named, but the simple method 164 /// name. 165 /// 166 /// @param[in] mangled 167 /// A C string name for the mangled name for this function. This 168 /// value can be NULL if there is no mangled information. 169 /// 170 /// @param[in] decl_ptr 171 /// Optional declaration information that describes where the 172 /// function was declared. This can be NULL. 173 /// 174 /// @param[in] call_decl_ptr 175 /// Optional calling location declaration information that 176 /// describes from where this inlined function was called. 177 //------------------------------------------------------------------ 178 InlineFunctionInfo(const char *name, const char *mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr); 179 180 //------------------------------------------------------------------ 181 /// Construct with the function method name, mangled name, and 182 /// optional declaration information. 183 /// 184 /// @param[in] name 185 /// A name for the method name for this function. This value 186 /// should not be the mangled named, but the simple method name. 187 /// 188 /// @param[in] mangled 189 /// A name for the mangled name for this function. This value 190 /// can be empty if there is no mangled information. 191 /// 192 /// @param[in] decl_ptr 193 /// Optional declaration information that describes where the 194 /// function was declared. This can be NULL. 195 /// 196 /// @param[in] call_decl_ptr 197 /// Optional calling location declaration information that 198 /// describes from where this inlined function was called. 199 //------------------------------------------------------------------ 200 InlineFunctionInfo(const ConstString& name, const Mangled &mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr); 201 202 //------------------------------------------------------------------ 203 /// Destructor. 204 //------------------------------------------------------------------ 205 ~InlineFunctionInfo(); 206 207 //------------------------------------------------------------------ 208 /// Compare two inlined function information objects. 209 /// 210 /// First compares the FunctionInfo objects, and if equal, 211 /// compares the mangled names. 212 /// 213 /// @param[in] lhs 214 /// The Left Hand Side const InlineFunctionInfo object 215 /// reference. 216 /// 217 /// @param[in] rhs 218 /// The Right Hand Side const InlineFunctionInfo object 219 /// reference. 220 /// 221 /// @return 222 /// @li -1 if lhs < rhs 223 /// @li 0 if lhs == rhs 224 /// @li 1 if lhs > rhs 225 //------------------------------------------------------------------ 226 int 227 Compare(const InlineFunctionInfo& lhs, const InlineFunctionInfo& rhs); 228 229 //------------------------------------------------------------------ 230 /// Dump a description of this object to a Stream. 231 /// 232 /// Dump a description of the contents of this object to the 233 /// supplied stream \a s. 234 /// 235 /// @param[in] s 236 /// The stream to which to dump the object descripton. 237 //------------------------------------------------------------------ 238 void 239 Dump(Stream *s) const; 240 241 void 242 DumpStopContext (Stream *s) const; 243 244 //------------------------------------------------------------------ 245 /// Get accessor for the call site declaration information. 246 /// 247 /// @return 248 /// A reference to the declaration object. 249 //------------------------------------------------------------------ 250 Declaration& 251 GetCallSite (); 252 253 //------------------------------------------------------------------ 254 /// Get const accessor for the call site declaration information. 255 /// 256 /// @return 257 /// A const reference to the declaration object. 258 //------------------------------------------------------------------ 259 const Declaration& 260 GetCallSite () const; 261 262 //------------------------------------------------------------------ 263 /// Get accessor for the mangled name object. 264 /// 265 /// @return 266 /// A reference to the mangled name object. 267 //------------------------------------------------------------------ 268 Mangled& 269 GetMangled(); 270 271 //------------------------------------------------------------------ 272 /// Get const accessor for the mangled name object. 273 /// 274 /// @return 275 /// A const reference to the mangled name object. 276 //------------------------------------------------------------------ 277 const Mangled& 278 GetMangled() const; 279 280 //------------------------------------------------------------------ 281 /// Get the memory cost of this object. 282 /// 283 /// @return 284 /// The number of bytes that this object occupies in memory. 285 /// The returned value does not include the bytes for any 286 /// shared string values. 287 /// 288 /// @see ConstString::StaticMemorySize () 289 //------------------------------------------------------------------ 290 virtual size_t 291 MemorySize() const; 292 293private: 294 //------------------------------------------------------------------ 295 // Member variables. 296 //------------------------------------------------------------------ 297 Mangled m_mangled; ///< Mangled inlined function name (can be empty if there is no mangled information). 298 Declaration m_call_decl; 299}; 300 301//---------------------------------------------------------------------- 302/// @class Function Function.h "lldb/Symbol/Function.h" 303/// @brief A class that describes a function. 304/// 305/// Functions belong to CompileUnit objects (Function::m_comp_unit), 306/// have unique user IDs (Function::UserID), know how to reconstruct 307/// their symbol context (Function::SymbolContextScope), have a 308/// specific function type (Function::m_type_uid), have a simple 309/// method name (FunctionInfo::m_name), be declared at a specific 310/// location (FunctionInfo::m_declaration), possibly have mangled 311/// names (Function::m_mangled), an optional return type 312/// (Function::m_type), and contains lexical blocks 313/// (Function::m_blocks). 314/// 315/// The function inforation is split into a few pieces: 316/// @li The concrete instance information 317/// @li The abstract information 318/// 319/// The abstract information is found in the function type (Type) that 320/// describes a function information, return type and parameter types. 321/// 322/// The concreate information is the address range information and 323/// specific locations for an instance of this function. 324//---------------------------------------------------------------------- 325class Function : 326 public UserID, 327 public SymbolContextScope 328{ 329public: 330 //------------------------------------------------------------------ 331 /// Construct with a compile unit, function UID, function type UID, 332 /// optional mangled name, function type, and a section offset 333 /// based address range. 334 /// 335 /// @param[in] comp_unit 336 /// The compile unit to which this function belongs. 337 /// 338 /// @param[in] func_uid 339 /// The UID for this function. This value is provided by the 340 /// SymbolFile plug-in and can be any value that allows 341 /// the plug-in to quickly find and parse more detailed 342 /// information when and if more information is needed. 343 /// 344 /// @param[in] func_type_uid 345 /// The type UID for the function Type to allow for lazy type 346 /// parsing from the debug information. 347 /// 348 /// @param[in] mangled 349 /// The optional mangled name for this function. If empty, there 350 /// is no mangled information. 351 /// 352 /// @param[in] func_type 353 /// The optional function type. If NULL, the function type will 354 /// be parsed on demand when accessed using the 355 /// Function::GetType() function by asking the SymbolFile 356 /// plug-in to get the type for \a func_type_uid. 357 /// 358 /// @param[in] range 359 /// The section offset based address for this function. 360 //------------------------------------------------------------------ 361 Function ( 362 CompileUnit *comp_unit, 363 lldb::user_id_t func_uid, 364 lldb::user_id_t func_type_uid, 365 const Mangled &mangled, 366 Type * func_type, 367 const AddressRange& range); 368 369 //------------------------------------------------------------------ 370 /// Construct with a compile unit, function UID, function type UID, 371 /// optional mangled name, function type, and a section offset 372 /// based address range. 373 /// 374 /// @param[in] comp_unit 375 /// The compile unit to which this function belongs. 376 /// 377 /// @param[in] func_uid 378 /// The UID for this function. This value is provided by the 379 /// SymbolFile plug-in and can be any value that allows 380 /// the plug-in to quickly find and parse more detailed 381 /// information when and if more information is needed. 382 /// 383 /// @param[in] func_type_uid 384 /// The type UID for the function Type to allow for lazy type 385 /// parsing from the debug information. 386 /// 387 /// @param[in] mangled 388 /// The optional mangled name for this function. If empty, there 389 /// is no mangled information. 390 /// 391 /// @param[in] func_type 392 /// The optional function type. If NULL, the function type will 393 /// be parsed on demand when accessed using the 394 /// Function::GetType() function by asking the SymbolFile 395 /// plug-in to get the type for \a func_type_uid. 396 /// 397 /// @param[in] range 398 /// The section offset based address for this function. 399 //------------------------------------------------------------------ 400 Function ( 401 CompileUnit *comp_unit, 402 lldb::user_id_t func_uid, 403 lldb::user_id_t func_type_uid, 404 const char *mangled, 405 Type * func_type, 406 const AddressRange& range); 407 408 //------------------------------------------------------------------ 409 /// Destructor. 410 //------------------------------------------------------------------ 411 ~Function (); 412 413 //------------------------------------------------------------------ 414 /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*) 415 /// 416 /// @see SymbolContextScope 417 //------------------------------------------------------------------ 418 virtual void 419 CalculateSymbolContext(SymbolContext* sc); 420 421 const AddressRange & 422 GetAddressRange() 423 { 424 return m_range; 425 } 426 427 //------------------------------------------------------------------ 428 /// Find the file and line number of the source location of the start 429 /// of the function. This will use the declaration if present and fall 430 /// back on the line table if that fails. So there may NOT be a line 431 /// table entry for this source file/line combo. 432 /// 433 /// @param[out] source_file 434 /// The source file. 435 /// 436 /// @param[out] line_no 437 /// The line number. 438 //------------------------------------------------------------------ 439 void 440 GetStartLineSourceInfo (FileSpec &source_file, uint32_t &line_no); 441 442 //------------------------------------------------------------------ 443 /// Find the file and line number of the source location of the end 444 /// of the function. 445 /// 446 /// 447 /// @param[out] source_file 448 /// The source file. 449 /// 450 /// @param[out] line_no 451 /// The line number. 452 //------------------------------------------------------------------ 453 void 454 GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no); 455 456 //------------------------------------------------------------------ 457 /// Get accessor for the block list. 458 /// 459 /// @return 460 /// The block list object that describes all lexical blocks 461 /// in the function. 462 /// 463 /// @see BlockList 464 //------------------------------------------------------------------ 465 Block& 466 GetBlock (bool can_create); 467 468 //------------------------------------------------------------------ 469 /// Get accessor for the compile unit that owns this function. 470 /// 471 /// @return 472 /// A compile unit object pointer. 473 //------------------------------------------------------------------ 474 CompileUnit* 475 GetCompileUnit(); 476 477 //------------------------------------------------------------------ 478 /// Get const accessor for the compile unit that owns this function. 479 /// 480 /// @return 481 /// A const compile unit object pointer. 482 //------------------------------------------------------------------ 483 const CompileUnit* 484 GetCompileUnit() const; 485 486 void 487 GetDescription(Stream *s, lldb::DescriptionLevel level, Process *process); 488 489 //------------------------------------------------------------------ 490 /// Get accessor for the frame base location. 491 /// 492 /// @return 493 /// A location expression that describes the function frame 494 /// base. 495 //------------------------------------------------------------------ 496 DWARFExpression & 497 GetFrameBaseExpression() 498 { 499 return m_frame_base; 500 } 501 502 //------------------------------------------------------------------ 503 /// Get const accessor for the frame base location. 504 /// 505 /// @return 506 /// A const compile unit object pointer. 507 //------------------------------------------------------------------ 508 const DWARFExpression & 509 GetFrameBaseExpression() const 510 { 511 return m_frame_base; 512 } 513 514 const Mangled & 515 GetMangled() const 516 { 517 return m_mangled; 518 } 519 520 //------------------------------------------------------------------ 521 /// Get accessor for the type that describes the function 522 /// return value type, and paramter types. 523 /// 524 /// @return 525 /// A type object pointer. 526 //------------------------------------------------------------------ 527 Type* 528 GetType(); 529 530 //------------------------------------------------------------------ 531 /// Get const accessor for the type that describes the function 532 /// return value type, and paramter types. 533 /// 534 /// @return 535 /// A const type object pointer. 536 //------------------------------------------------------------------ 537 const Type* 538 GetType() const; 539 540 Type 541 GetReturnType (); 542 543 // The Number of arguments, or -1 for an unprototyped function. 544 int 545 GetArgumentCount (); 546 547 const Type 548 GetArgumentTypeAtIndex (size_t idx); 549 550 const char * 551 GetArgumentNameAtIndex (size_t idx); 552 553 bool 554 IsVariadic (); 555 556 uint32_t 557 GetPrologueByteSize (); 558 559 //------------------------------------------------------------------ 560 /// Dump a description of this object to a Stream. 561 /// 562 /// Dump a description of the contents of this object to the 563 /// supplied stream \a s. 564 /// 565 /// @param[in] s 566 /// The stream to which to dump the object descripton. 567 /// 568 /// @param[in] show_context 569 /// If \b true, variables will dump their symbol context 570 /// information. 571 //------------------------------------------------------------------ 572 void 573 Dump(Stream *s, bool show_context) const; 574 575 //------------------------------------------------------------------ 576 /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*) 577 /// 578 /// @see SymbolContextScope 579 //------------------------------------------------------------------ 580 virtual void 581 DumpSymbolContext(Stream *s); 582 583 //------------------------------------------------------------------ 584 /// Get the memory cost of this object. 585 /// 586 /// @return 587 /// The number of bytes that this object occupies in memory. 588 /// The returned value does not include the bytes for any 589 /// shared string values. 590 /// 591 /// @see ConstString::StaticMemorySize () 592 //------------------------------------------------------------------ 593 size_t 594 MemorySize () const; 595 596protected: 597 598 enum 599 { 600 flagsCalculatedPrologueSize = (1 << 0) ///< Have we already tried to calculate the prologue size? 601 }; 602 603 604 605 //------------------------------------------------------------------ 606 // Member variables. 607 //------------------------------------------------------------------ 608 CompileUnit *m_comp_unit; ///< The compile unit that owns this function. 609 lldb::user_id_t m_type_uid; ///< The user ID of for the prototype Type for this function. 610 Type * m_type; ///< The function prototype type for this function that include the function info (FunctionInfo), return type and parameters. 611 Mangled m_mangled; ///< The mangled function name if any, if empty, there is no mangled information. 612 Block m_block; ///< All lexical blocks contained in this function. 613 AddressRange m_range; ///< The function address range that covers the widest range needed to contain all blocks 614 DWARFExpression m_frame_base; ///< The frame base expression for variables that are relative to the frame pointer. 615 Flags m_flags; 616 uint32_t m_prologue_byte_size; ///< Compute the prologue size once and cache it 617private: 618 DISALLOW_COPY_AND_ASSIGN(Function); 619}; 620 621} // namespace lldb_private 622 623#endif // liblldb_Function_h_ 624