ClangExpressionDeclMap.h revision cbc07cfd435fb703d8feb69b97ca8590e6ee2fd8
1//===-- ClangExpressionDeclMap.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_ClangExpressionDeclMap_h_ 11#define liblldb_ClangExpressionDeclMap_h_ 12 13// C Includes 14#include <signal.h> 15#include <stdint.h> 16 17// C++ Includes 18#include <vector> 19 20// Other libraries and framework includes 21// Project includes 22#include "llvm/ADT/APInt.h" 23#include "llvm/ADT/DenseMap.h" 24#include "lldb/lldb-public.h" 25#include "lldb/Core/ClangForward.h" 26#include "lldb/Core/Value.h" 27#include "lldb/Expression/ClangExpressionVariable.h" 28#include "lldb/Symbol/TaggedASTType.h" 29#include "lldb/Symbol/SymbolContext.h" 30#include "lldb/Target/ExecutionContext.h" 31 32namespace lldb_private { 33 34//---------------------------------------------------------------------- 35/// @class ClangExpressionDeclMap ClangExpressionDeclMap.h "lldb/Expression/ClangExpressionDeclMap.h" 36/// @brief Manages named entities that are defined in LLDB's debug information. 37/// 38/// The Clang parser uses the ClangASTSource as an interface to request named 39/// entities from outside an expression. The ClangASTSource reports back, listing 40/// all possible objects corresponding to a particular name. But it in turn 41/// relies on ClangExpressionDeclMap, which performs several important functions. 42/// 43/// First, it records what variables and functions were looked up and what Decls 44/// were returned for them. 45/// 46/// Second, it constructs a struct on behalf of IRForTarget, recording which 47/// variables should be placed where and relaying this information back so that 48/// IRForTarget can generate context-independent code. 49/// 50/// Third, it "materializes" this struct on behalf of the expression command, 51/// finding the current values of each variable and placing them into the 52/// struct so that it can be passed to the JITted version of the IR. 53/// 54/// Fourth and finally, it "dematerializes" the struct after the JITted code has 55/// has executed, placing the new values back where it found the old ones. 56//---------------------------------------------------------------------- 57class ClangExpressionDeclMap 58{ 59public: 60 //------------------------------------------------------------------ 61 /// Constructor 62 /// 63 /// Initializes class variables. 64 /// 65 /// @param[in] keep_result_in_memory 66 /// If true, inhibits the normal deallocation of the memory for 67 /// the result persistent variable, and instead marks the variable 68 /// as persisting. 69 //------------------------------------------------------------------ 70 ClangExpressionDeclMap (bool keep_result_in_memory); 71 72 //------------------------------------------------------------------ 73 /// Destructor 74 //------------------------------------------------------------------ 75 ~ClangExpressionDeclMap (); 76 77 //------------------------------------------------------------------ 78 /// Enable the state needed for parsing and IR transformation. 79 /// 80 /// @param[in] exe_ctx 81 /// The execution context to use when finding types for variables. 82 /// Also used to find a "scratch" AST context to store result types. 83 //------------------------------------------------------------------ 84 void 85 WillParse (ExecutionContext &exe_ctx); 86 87 //------------------------------------------------------------------ 88 /// [Used by ClangExpressionParser] For each variable that had an unknown 89 /// type at the beginning of parsing, determine its final type now. 90 /// 91 /// @return 92 /// True on success; false otherwise. 93 //------------------------------------------------------------------ 94 bool 95 ResolveUnknownTypes(); 96 97 //------------------------------------------------------------------ 98 /// Disable the state needed for parsing and IR transformation. 99 //------------------------------------------------------------------ 100 void 101 DidParse (); 102 103 //------------------------------------------------------------------ 104 /// [Used by IRForTarget] Get a new result variable name of the form 105 /// $n, where n is a natural number starting with 0. 106 /// 107 /// @param[in] name 108 /// The std::string to place the name into. 109 //------------------------------------------------------------------ 110 const ConstString & 111 GetPersistentResultName (); 112 113 clang::NamespaceDecl * 114 AddNamespace (NameSearchContext &context, 115 const ClangNamespaceDecl &namespace_decl); 116 117 //------------------------------------------------------------------ 118 /// [Used by IRForTarget] Get a constant variable given a name, 119 /// a type, and an llvm::APInt. 120 /// 121 /// @param[in] name 122 /// The name of the variable 123 /// 124 /// @param[in] type 125 /// The type of the variable, which will be imported into the 126 /// target's AST context 127 /// 128 /// @param[in] value 129 /// The value of the variable 130 /// 131 /// @return 132 /// The created variable 133 //------------------------------------------------------------------ 134 lldb::ClangExpressionVariableSP 135 BuildIntegerVariable (const ConstString &name, 136 lldb_private::TypeFromParser type, 137 const llvm::APInt& value); 138 139 //------------------------------------------------------------------ 140 /// [Used by IRForTarget] Cast an existing variable given a Decl and 141 /// a type. 142 /// 143 /// @param[in] name 144 /// The name of the new variable 145 /// 146 /// @param[in] decl 147 /// The Clang variable declaration for the original variable, 148 /// which must be looked up in the map 149 /// 150 /// @param[in] type 151 /// The desired type of the variable after casting 152 /// 153 /// @return 154 /// The created variable 155 //------------------------------------------------------------------ 156 lldb::ClangExpressionVariableSP 157 BuildCastVariable (const ConstString &name, 158 clang::VarDecl *decl, 159 lldb_private::TypeFromParser type); 160 161 //------------------------------------------------------------------ 162 /// [Used by IRForTarget] Add a variable to the list of persistent 163 /// variables for the process. 164 /// 165 /// @param[in] decl 166 /// The Clang declaration for the persistent variable, used for 167 /// lookup during parsing. 168 /// 169 /// @param[in] name 170 /// The name of the persistent variable, usually $something. 171 /// 172 /// @param[in] type 173 /// The type of the variable, in the Clang parser's context. 174 /// 175 /// @return 176 /// True on success; false otherwise. 177 //------------------------------------------------------------------ 178 bool 179 AddPersistentVariable (const clang::NamedDecl *decl, 180 const ConstString &name, 181 TypeFromParser type, 182 bool is_result, 183 bool is_lvalue); 184 185 //------------------------------------------------------------------ 186 /// [Used by IRForTarget] Add a variable to the struct that needs to 187 /// be materialized each time the expression runs. 188 /// 189 /// @param[in] decl 190 /// The Clang declaration for the variable. 191 /// 192 /// @param[in] name 193 /// The name of the variable. 194 /// 195 /// @param[in] value 196 /// The LLVM IR value for this variable. 197 /// 198 /// @param[in] size 199 /// The size of the variable in bytes. 200 /// 201 /// @param[in] alignment 202 /// The required alignment of the variable in bytes. 203 /// 204 /// @return 205 /// True on success; false otherwise. 206 //------------------------------------------------------------------ 207 bool 208 AddValueToStruct (const clang::NamedDecl *decl, 209 const ConstString &name, 210 llvm::Value *value, 211 size_t size, 212 off_t alignment); 213 214 //------------------------------------------------------------------ 215 /// [Used by IRForTarget] Finalize the struct, laying out the position 216 /// of each object in it. 217 /// 218 /// @return 219 /// True on success; false otherwise. 220 //------------------------------------------------------------------ 221 bool 222 DoStructLayout (); 223 224 //------------------------------------------------------------------ 225 /// [Used by IRForTarget] Get general information about the laid-out 226 /// struct after DoStructLayout() has been called. 227 /// 228 /// @param[out] num_elements 229 /// The number of elements in the struct. 230 /// 231 /// @param[out] size 232 /// The size of the struct, in bytes. 233 /// 234 /// @param[out] alignment 235 /// The alignment of the struct, in bytes. 236 /// 237 /// @return 238 /// True if the information could be retrieved; false otherwise. 239 //------------------------------------------------------------------ 240 bool 241 GetStructInfo (uint32_t &num_elements, 242 size_t &size, 243 off_t &alignment); 244 245 //------------------------------------------------------------------ 246 /// [Used by IRForTarget] Get specific information about one field 247 /// of the laid-out struct after DoStructLayout() has been called. 248 /// 249 /// @param[out] decl 250 /// The parsed Decl for the field, as generated by ClangASTSource 251 /// on ClangExpressionDeclMap's behalf. In the case of the result 252 /// value, this will have the name $__lldb_result even if the 253 /// result value ends up having the name $1. This is an 254 /// implementation detail of IRForTarget. 255 /// 256 /// @param[out] value 257 /// The IR value for the field (usually a GlobalVariable). In 258 /// the case of the result value, this will have the correct 259 /// name ($1, for instance). This is an implementation detail 260 /// of IRForTarget. 261 /// 262 /// @param[out] offset 263 /// The offset of the field from the beginning of the struct. 264 /// As long as the struct is aligned according to its required 265 /// alignment, this offset will align the field correctly. 266 /// 267 /// @param[out] name 268 /// The name of the field as used in materialization. 269 /// 270 /// @param[in] index 271 /// The index of the field about which information is requested. 272 /// 273 /// @return 274 /// True if the information could be retrieved; false otherwise. 275 //------------------------------------------------------------------ 276 bool 277 GetStructElement (const clang::NamedDecl *&decl, 278 llvm::Value *&value, 279 off_t &offset, 280 ConstString &name, 281 uint32_t index); 282 283 //------------------------------------------------------------------ 284 /// [Used by IRForTarget] Get information about a function given its 285 /// Decl. 286 /// 287 /// @param[in] decl 288 /// The parsed Decl for the Function, as generated by ClangASTSource 289 /// on ClangExpressionDeclMap's behalf. 290 /// 291 /// @param[out] value 292 /// A pointer to the address where a Value for the function's address 293 /// can be stored. IRForTarget typically places a ConstantExpr here. 294 /// 295 /// @param[out] ptr 296 /// The absolute address of the function in the target. 297 /// 298 /// @return 299 /// True if the information could be retrieved; false otherwise. 300 //------------------------------------------------------------------ 301 bool 302 GetFunctionInfo (const clang::NamedDecl *decl, 303 llvm::Value**& value, 304 uint64_t &ptr); 305 306 //------------------------------------------------------------------ 307 /// [Used by IRForTarget] Get the address of a function given nothing 308 /// but its name. Some functions are needed but didn't get Decls made 309 /// during parsing -- specifically, sel_registerName is never called 310 /// in the generated IR but we need to call it nonetheless. 311 /// 312 /// @param[in] name 313 /// The name of the function. 314 /// 315 /// @param[out] ptr 316 /// The absolute address of the function in the target. 317 /// 318 /// @return 319 /// True if the address could be retrieved; false otherwise. 320 //------------------------------------------------------------------ 321 bool 322 GetFunctionAddress (const ConstString &name, 323 uint64_t &ptr); 324 325 //------------------------------------------------------------------ 326 /// [Used by IRForTarget] Get the address of a symbol given nothing 327 /// but its name. 328 /// 329 /// @param[in] target 330 /// The target to find the symbol in. If not provided, 331 /// then the current parsing context's Target. 332 /// 333 /// @param[in] name 334 /// The name of the symbol. 335 /// 336 /// @return 337 /// Valid load address for the symbol 338 //------------------------------------------------------------------ 339 lldb::addr_t 340 GetSymbolAddress (Target &target, 341 const ConstString &name); 342 343 lldb::addr_t 344 GetSymbolAddress (const ConstString &name); 345 346 //------------------------------------------------------------------ 347 /// [Used by CommandObjectExpression] Materialize the entire struct 348 /// at a given address, which should be aligned as specified by 349 /// GetStructInfo(). 350 /// 351 /// @param[in] exe_ctx 352 /// The execution context at which to dump the struct. 353 /// 354 /// @param[in] struct_address 355 /// The address at which the struct should be written. 356 /// 357 /// @param[in] error 358 /// An Error to populate with any messages related to 359 /// materializing the struct. 360 /// 361 /// @return 362 /// True on success; false otherwise. 363 //------------------------------------------------------------------ 364 bool 365 Materialize (ExecutionContext &exe_ctx, 366 lldb::addr_t &struct_address, 367 Error &error); 368 369 //------------------------------------------------------------------ 370 /// [Used by CommandObjectExpression] Get the "this" pointer 371 /// from a given execution context. 372 /// 373 /// @param[out] object_ptr 374 /// The this pointer. 375 /// 376 /// @param[in] object_name 377 /// The name of the object pointer -- "this," "self," or similar 378 /// depending on language 379 /// 380 /// @param[in] exe_ctx 381 /// The execution context at which to dump the struct. 382 /// 383 /// @param[in] error 384 /// An Error to populate with any messages related to 385 /// finding the "this" pointer. 386 /// 387 /// @param[in] suppress_type_check 388 /// True if the type is not needed. 389 /// 390 /// @return 391 /// True on success; false otherwise. 392 //------------------------------------------------------------------ 393 bool 394 GetObjectPointer (lldb::addr_t &object_ptr, 395 ConstString &object_name, 396 ExecutionContext &exe_ctx, 397 Error &error, 398 bool suppress_type_check = false); 399 400 //------------------------------------------------------------------ 401 /// [Used by CommandObjectExpression] Pretty-print a materialized 402 /// struct, which must have been materialized by Materialize(), 403 /// byte for byte on a given stream. 404 /// 405 /// @param[in] exe_ctx 406 /// The execution context from which to read the struct. 407 /// 408 /// @param[in] s 409 /// The stream on which to write the pretty-printed output. 410 /// 411 /// @param[in] error 412 /// An Error to populate with any messages related to 413 /// pretty-printing the struct. 414 /// 415 /// @return 416 /// True on success; false otherwise. 417 //------------------------------------------------------------------ 418 bool 419 DumpMaterializedStruct (ExecutionContext &exe_ctx, 420 Stream &s, 421 Error &error); 422 423 //------------------------------------------------------------------ 424 /// [Used by CommandObjectExpression] Deaterialize the entire struct. 425 /// 426 /// @param[in] exe_ctx 427 /// The execution context from which to read the struct. 428 /// 429 /// @param[out] result 430 /// A ClangExpressionVariable containing the result of the 431 /// expression, for potential re-use. 432 /// 433 /// @param[in] stack_frame_top, stack_frame_bottom 434 /// If not LLDB_INVALID_ADDRESS, the bounds for the stack frame 435 /// in which the expression ran. A result whose address falls 436 /// inside this stack frame is dematerialized as a value 437 /// requiring rematerialization. 438 /// 439 /// @param[in] error 440 /// An Error to populate with any messages related to 441 /// dematerializing the struct. 442 /// 443 /// @return 444 /// True on success; false otherwise. 445 //------------------------------------------------------------------ 446 bool 447 Dematerialize (ExecutionContext &exe_ctx, 448 lldb::ClangExpressionVariableSP &result_sp, 449 lldb::addr_t stack_frame_top, 450 lldb::addr_t stack_frame_bottom, 451 Error &error); 452 453 //------------------------------------------------------------------ 454 /// [Used by ClangASTSource] Find all entities matching a given name, 455 /// using a NameSearchContext to make Decls for them. 456 /// 457 /// @param[in] context 458 /// The NameSearchContext that can construct Decls for this name. 459 /// 460 /// @param[in] name 461 /// The name as a plain C string. The NameSearchContext contains 462 /// a DeclarationName for the name so at first the name may seem 463 /// redundant, but ClangExpressionDeclMap operates in RTTI land so 464 /// it can't access DeclarationName. 465 /// 466 /// @return 467 /// True on success; false otherwise. 468 //------------------------------------------------------------------ 469 void 470 GetDecls (NameSearchContext &context, 471 const ConstString &name); 472 473 //------------------------------------------------------------------ 474 /// [Used by ClangASTSource] Report whether a $__lldb variable has 475 /// been searched for yet. This is the trigger for beginning to 476 /// actually look for externally-defined names. (Names that come 477 /// before this are typically the names of built-ins that don't need 478 /// to be looked up.) 479 /// 480 /// @return 481 /// True if a $__lldb variable has been found. 482 //------------------------------------------------------------------ 483 bool 484 GetLookupsEnabled () const 485 { 486 assert(m_parser_vars.get()); 487 return m_parser_vars->m_enable_lookups; 488 } 489 490 bool 491 GetImportInProgress () const 492 { 493 if (m_parser_vars.get()) 494 return m_parser_vars->m_ignore_lookups; 495 return false; 496 } 497 498 //------------------------------------------------------------------ 499 /// [Used by ClangASTSource] Indicate that a $__lldb variable has 500 /// been found. 501 //------------------------------------------------------------------ 502 void 503 SetLookupsEnabled () 504 { 505 assert(m_parser_vars.get()); 506 m_parser_vars->m_enable_lookups = true; 507 } 508 509private: 510 ClangExpressionVariableList m_found_entities; ///< All entities that were looked up for the parser. 511 ClangExpressionVariableList m_struct_members; ///< All entities that need to be placed in the struct. 512 bool m_keep_result_in_memory; ///< True if result persistent variables generated by this expression should stay in memory. 513 514 //---------------------------------------------------------------------- 515 /// The following values should not live beyond parsing 516 //---------------------------------------------------------------------- 517 class ParserVars 518 { 519 public: 520 ParserVars() : 521 m_exe_ctx(NULL), 522 m_sym_ctx(), 523 m_persistent_vars(NULL), 524 m_enable_lookups(false), 525 m_ignore_lookups(false) 526 { 527 } 528 529 Target * 530 GetTarget() 531 { 532 if (m_exe_ctx && m_exe_ctx->target) 533 return m_exe_ctx->target; 534 else if (m_sym_ctx.target_sp) 535 m_sym_ctx.target_sp.get(); 536 return NULL; 537 } 538 ExecutionContext *m_exe_ctx; ///< The execution context to use when parsing. 539 SymbolContext m_sym_ctx; ///< The symbol context to use in finding variables and types. 540 ClangPersistentVariables *m_persistent_vars; ///< The persistent variables for the process. 541 bool m_enable_lookups; ///< Set to true during parsing if we have found the first "$__lldb" name. 542 bool m_ignore_lookups; ///< True during an import when we should be ignoring type lookups. 543 private: 544 DISALLOW_COPY_AND_ASSIGN (ParserVars); 545 }; 546 547 std::auto_ptr<ParserVars> m_parser_vars; 548 549 //---------------------------------------------------------------------- 550 /// Activate parser-specific variables 551 //---------------------------------------------------------------------- 552 void 553 EnableParserVars() 554 { 555 if (!m_parser_vars.get()) 556 m_parser_vars.reset(new ParserVars); 557 } 558 559 //---------------------------------------------------------------------- 560 /// Deallocate parser-specific variables 561 //---------------------------------------------------------------------- 562 void 563 DisableParserVars() 564 { 565 m_parser_vars.reset(); 566 } 567 568 //---------------------------------------------------------------------- 569 /// The following values contain layout information for the materialized 570 /// struct, but are not specific to a single materialization 571 //---------------------------------------------------------------------- 572 struct StructVars { 573 StructVars() : 574 m_struct_alignment(0), 575 m_struct_size(0), 576 m_struct_laid_out(false), 577 m_result_name(), 578 m_object_pointer_type(NULL, NULL) 579 { 580 } 581 582 off_t m_struct_alignment; ///< The alignment of the struct in bytes. 583 size_t m_struct_size; ///< The size of the struct in bytes. 584 bool m_struct_laid_out; ///< True if the struct has been laid out and the layout is valid (that is, no new fields have been added since). 585 ConstString m_result_name; ///< The name of the result variable ($1, for example) 586 TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if one exists 587 }; 588 589 std::auto_ptr<StructVars> m_struct_vars; 590 591 //---------------------------------------------------------------------- 592 /// Activate struct variables 593 //---------------------------------------------------------------------- 594 void 595 EnableStructVars() 596 { 597 if (!m_struct_vars.get()) 598 m_struct_vars.reset(new struct StructVars); 599 } 600 601 //---------------------------------------------------------------------- 602 /// Deallocate struct variables 603 //---------------------------------------------------------------------- 604 void 605 DisableStructVars() 606 { 607 m_struct_vars.reset(); 608 } 609 610 //---------------------------------------------------------------------- 611 /// The following values refer to a specific materialization of the 612 /// structure in a process 613 //---------------------------------------------------------------------- 614 struct MaterialVars { 615 MaterialVars() : 616 m_allocated_area(NULL), 617 m_materialized_location(NULL) 618 { 619 } 620 621 Process *m_process; ///< The process that the struct is materialized into. 622 lldb::addr_t m_allocated_area; ///< The base of the memory allocated for the struct. Starts on a potentially unaligned address and may therefore be larger than the struct. 623 lldb::addr_t m_materialized_location; ///< The address at which the struct is placed. Falls inside the allocated area. 624 }; 625 626 std::auto_ptr<MaterialVars> m_material_vars; 627 628 //---------------------------------------------------------------------- 629 /// Activate materialization-specific variables 630 //---------------------------------------------------------------------- 631 void 632 EnableMaterialVars() 633 { 634 if (!m_material_vars.get()) 635 m_material_vars.reset(new struct MaterialVars); 636 } 637 638 //---------------------------------------------------------------------- 639 /// Deallocate materialization-specific variables 640 //---------------------------------------------------------------------- 641 void 642 DisableMaterialVars() 643 { 644 m_material_vars.reset(); 645 } 646 647 //------------------------------------------------------------------ 648 /// Given a stack frame, find a variable that matches the given name and 649 /// type. We need this for expression re-use; we may not always get the 650 /// same lldb::Variable back, and we want the expression to work wherever 651 /// it can. Returns the variable defined in the tightest scope. 652 /// 653 /// @param[in] frame 654 /// The stack frame to use as a basis for finding the variable. 655 /// 656 /// @param[in] name 657 /// The name as a plain C string. 658 /// 659 /// @param[in] type 660 /// The required type for the variable. This function may be called 661 /// during parsing, in which case we don't know its type; hence the 662 /// default. 663 /// 664 /// @return 665 /// The LLDB Variable found, or NULL if none was found. 666 //------------------------------------------------------------------ 667 lldb::VariableSP 668 FindVariableInScope (StackFrame &frame, 669 const ConstString &name, 670 TypeFromUser *type = NULL); 671 672 //------------------------------------------------------------------ 673 /// Given a target, find a data symbol that has the given name. 674 /// 675 /// @param[in] target 676 /// The target to use as the basis for the search. 677 /// 678 /// @param[in] name 679 /// The name as a plain C string. 680 /// 681 /// @return 682 /// The LLDB Symbol found, or NULL if none was found. 683 //--------------------------------------------------------- 684 Symbol * 685 FindGlobalDataSymbol (Target &target, 686 const ConstString &name); 687 688 //------------------------------------------------------------------ 689 /// Get the value of a variable in a given execution context and return 690 /// the associated Types if needed. 691 /// 692 /// @param[in] exe_ctx 693 /// The execution context to look for the variable in. 694 /// 695 /// @param[in] var 696 /// The variable to evaluate. 697 /// 698 /// @param[in] parser_ast_context 699 /// The AST context of the parser, to store the found type in. 700 /// 701 /// @param[out] found_type 702 /// The type of the found value, as it was found in the user process. 703 /// This is only useful when the variable is being inspected on behalf 704 /// of the parser, hence the default. 705 /// 706 /// @param[out] parser_type 707 /// The type of the found value, as it was copied into the parser's 708 /// AST context. This is only useful when the variable is being 709 /// inspected on behalf of the parser, hence the default. 710 /// 711 /// @param[in] decl 712 /// The Decl to be looked up. 713 /// 714 /// @return 715 /// The LLDB Value for the variable. 716 //------------------------------------------------------------------ 717 Value * 718 GetVariableValue (ExecutionContext &exe_ctx, 719 lldb::VariableSP var, 720 clang::ASTContext *parser_ast_context, 721 TypeFromUser *found_type = NULL, 722 TypeFromParser *parser_type = NULL); 723 724 //------------------------------------------------------------------ 725 /// Use the NameSearchContext to generate a Decl for the given LLDB 726 /// Variable, and put it in the Tuple list. 727 /// 728 /// @param[in] context 729 /// The NameSearchContext to use when constructing the Decl. 730 /// 731 /// @param[in] var 732 /// The LLDB Variable that needs a Decl. 733 //------------------------------------------------------------------ 734 void 735 AddOneVariable (NameSearchContext &context, 736 lldb::VariableSP var); 737 738 //------------------------------------------------------------------ 739 /// Use the NameSearchContext to generate a Decl for the given 740 /// persistent variable, and put it in the list of found entities. 741 /// 742 /// @param[in] context 743 /// The NameSearchContext to use when constructing the Decl. 744 /// 745 /// @param[in] pvar 746 /// The persistent variable that needs a Decl. 747 //------------------------------------------------------------------ 748 void 749 AddOneVariable (NameSearchContext &context, 750 lldb::ClangExpressionVariableSP &pvar_sp); 751 752 //------------------------------------------------------------------ 753 /// Use the NameSearchContext to generate a Decl for the given LLDB 754 /// symbol (treated as a variable), and put it in the list of found 755 /// entities. 756 /// 757 /// @param[in] context 758 /// The NameSearchContext to use when constructing the Decl. 759 /// 760 /// @param[in] var 761 /// The LLDB Variable that needs a Decl. 762 //------------------------------------------------------------------ 763 void 764 AddOneGenericVariable (NameSearchContext &context, 765 Symbol &symbol); 766 767 //------------------------------------------------------------------ 768 /// Use the NameSearchContext to generate a Decl for the given 769 /// function. (Functions are not placed in the Tuple list.) Can 770 /// handle both fully typed functions and generic functions. 771 /// 772 /// @param[in] context 773 /// The NameSearchContext to use when constructing the Decl. 774 /// 775 /// @param[in] fun 776 /// The Function that needs to be created. If non-NULL, this is 777 /// a fully-typed function. 778 /// 779 /// @param[in] sym 780 /// The Symbol that corresponds to a function that needs to be 781 /// created with generic type (unitptr_t foo(...)). 782 //------------------------------------------------------------------ 783 void 784 AddOneFunction (NameSearchContext &context, 785 Function *fun, 786 Symbol *sym); 787 788 //------------------------------------------------------------------ 789 /// Use the NameSearchContext to generate a Decl for the given 790 /// register. 791 /// 792 /// @param[in] context 793 /// The NameSearchContext to use when constructing the Decl. 794 /// 795 /// @param[in] reg_info 796 /// The information corresponding to that register. 797 //------------------------------------------------------------------ 798 void 799 AddOneRegister (NameSearchContext &context, 800 const RegisterInfo *reg_info); 801 802 //------------------------------------------------------------------ 803 /// Use the NameSearchContext to generate a Decl for the given 804 /// type. (Types are not placed in the Tuple list.) 805 /// 806 /// @param[in] context 807 /// The NameSearchContext to use when constructing the Decl. 808 /// 809 /// @param[in] type 810 /// The type that needs to be created. 811 /// 812 /// @param[in] add_method 813 /// True if a method with signature void $__lldb_expr(void*) 814 /// should be added to the C++ class type passed in 815 //------------------------------------------------------------------ 816 void 817 AddOneType (NameSearchContext &context, 818 TypeFromUser &type, 819 bool add_method = false); 820 821 //------------------------------------------------------------------ 822 /// Actually do the task of materializing or dematerializing the struct. 823 /// Since both tasks are very similar, although ClangExpressionDeclMap 824 /// exposes two functions to the outside, both call DoMaterialize. 825 /// 826 /// @param[in] dematerialize 827 /// True if the struct is to be dematerialized; false if it is to 828 /// be materialized. 829 /// 830 /// @param[in] exe_ctx 831 /// The execution context to use. 832 /// 833 /// @param[in] stack_frame_top, stack_frame_bottom 834 /// If not LLDB_INVALID_ADDRESS, the bounds for the stack frame 835 /// in which the expression ran. A result whose address falls 836 /// inside this stack frame is dematerialized as a value 837 /// requiring rematerialization. 838 /// 839 /// @param[out] result 840 /// If the struct is being dematerialized, a pointer into which the 841 /// location of the result persistent variable is placed. If not, 842 /// NULL. 843 /// 844 /// @param[in] err 845 /// An Error to populate with any messages related to 846 /// (de)materializing the struct. 847 /// 848 /// @return 849 /// True on success; false otherwise. 850 //------------------------------------------------------------------ 851 bool 852 DoMaterialize (bool dematerialize, 853 ExecutionContext &exe_ctx, 854 lldb::addr_t stack_frame_top, 855 lldb::addr_t stack_frame_bottom, 856 lldb::ClangExpressionVariableSP *result_sp_ptr, 857 Error &err); 858 859 //------------------------------------------------------------------ 860 /// Clean up the state required to dematerialize the variable. 861 //------------------------------------------------------------------ 862 void 863 DidDematerialize (); 864 865 //------------------------------------------------------------------ 866 /// Actually do the task of materializing or dematerializing a persistent 867 /// variable. 868 /// 869 /// @param[in] dematerialize 870 /// True if the variable is to be dematerialized; false if it is to 871 /// be materialized. 872 /// 873 /// @param[in] exe_ctx 874 /// The execution context to use. 875 /// 876 /// @param[in] var_sp 877 /// The persistent variable to materialize 878 /// 879 /// @param[in] addr 880 /// The address at which to materialize the variable. 881 /// 882 /// @param[in] stack_frame_top, stack_frame_bottom 883 /// If not LLDB_INVALID_ADDRESS, the bounds for the stack frame 884 /// in which the expression ran. A result whose address falls 885 /// inside this stack frame is dematerialized as a value 886 /// requiring rematerialization. 887 /// 888 /// @param[in] err 889 /// An Error to populate with any messages related to 890 /// (de)materializing the persistent variable. 891 /// 892 /// @return 893 /// True on success; false otherwise. 894 //------------------------------------------------------------------ 895 bool 896 DoMaterializeOnePersistentVariable (bool dematerialize, 897 ExecutionContext &exe_ctx, 898 lldb::ClangExpressionVariableSP &var_sp, 899 lldb::addr_t addr, 900 lldb::addr_t stack_frame_top, 901 lldb::addr_t stack_frame_bottom, 902 Error &err); 903 904 //------------------------------------------------------------------ 905 /// Actually do the task of materializing or dematerializing a 906 /// variable. 907 /// 908 /// @param[in] dematerialize 909 /// True if the variable is to be dematerialized; false if it is to 910 /// be materialized. 911 /// 912 /// @param[in] exe_ctx 913 /// The execution context to use. 914 /// 915 /// @param[in] sym_ctx 916 /// The symbol context to use (for looking the variable up). 917 /// 918 /// @param[in] expr_var 919 /// The entity that the expression parser uses for the variable. 920 /// In case the variable needs to be copied into the target's 921 /// memory, this location is stored in the variable during 922 /// materialization and cleared when it is demateralized. 923 /// 924 /// @param[in] addr 925 /// The address at which to materialize the variable. 926 /// 927 /// @param[in] err 928 /// An Error to populate with any messages related to 929 /// (de)materializing the persistent variable. 930 /// 931 /// @return 932 /// True on success; false otherwise. 933 //------------------------------------------------------------------ 934 bool 935 DoMaterializeOneVariable (bool dematerialize, 936 ExecutionContext &exe_ctx, 937 const SymbolContext &sym_ctx, 938 lldb::ClangExpressionVariableSP &expr_var, 939 lldb::addr_t addr, 940 Error &err); 941 942 //------------------------------------------------------------------ 943 /// Actually do the task of materializing or dematerializing a 944 /// register variable. 945 /// 946 /// @param[in] dematerialize 947 /// True if the variable is to be dematerialized; false if it is to 948 /// be materialized. 949 /// 950 /// @param[in] exe_ctx 951 /// The execution context to use. 952 /// 953 /// @param[in] reg_ctx 954 /// The register context to use. 955 /// 956 /// @param[in] reg_info 957 /// The information for the register to read/write. 958 /// 959 /// @param[in] addr 960 /// The address at which to materialize the variable. 961 /// 962 /// @param[in] err 963 /// An Error to populate with any messages related to 964 /// (de)materializing the persistent variable. 965 /// 966 /// @return 967 /// True on success; false otherwise. 968 //------------------------------------------------------------------ 969 bool 970 DoMaterializeOneRegister (bool dematerialize, 971 ExecutionContext &exe_ctx, 972 RegisterContext ®_ctx, 973 const RegisterInfo ®_info, 974 lldb::addr_t addr, 975 Error &err); 976 977 //------------------------------------------------------------------ 978 /// A wrapper for ClangASTContext::CopyType that sets a flag that 979 /// indicates that we should not respond to queries during import. 980 /// 981 /// @param[in] dest_context 982 /// The target AST context, typically the parser's AST context. 983 /// 984 /// @param[in] source_context 985 /// The source AST context, typically the AST context of whatever 986 /// symbol file the type was found in. 987 /// 988 /// @param[in] clang_type 989 /// The source type. 990 /// 991 /// @return 992 /// The imported type. 993 //------------------------------------------------------------------ 994 void * 995 GuardedCopyType (clang::ASTContext *dest_context, 996 clang::ASTContext *source_context, 997 void *clang_type); 998}; 999 1000} // namespace lldb_private 1001 1002#endif // liblldb_ClangExpressionDeclMap_h_ 1003