SBTarget.h revision 59b96d5fdda21be0c7abbe7567af75239748be61
1//===-- SBTarget.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 LLDB_SBTarget_h_ 11#define LLDB_SBTarget_h_ 12 13#include "lldb/API/SBDefines.h" 14#include "lldb/API/SBAddress.h" 15#include "lldb/API/SBBroadcaster.h" 16#include "lldb/API/SBFileSpec.h" 17#include "lldb/API/SBFileSpecList.h" 18#include "lldb/API/SBSymbolContextList.h" 19#include "lldb/API/SBType.h" 20#include "lldb/API/SBValue.h" 21#include "lldb/API/SBWatchpoint.h" 22 23namespace lldb { 24 25class SBLaunchInfo 26{ 27public: 28 SBLaunchInfo (const char **argv); 29 30 ~SBLaunchInfo(); 31 32 uint32_t 33 GetUserID(); 34 35 uint32_t 36 GetGroupID(); 37 38 bool 39 UserIDIsValid (); 40 41 bool 42 GroupIDIsValid (); 43 44 void 45 SetUserID (uint32_t uid); 46 47 void 48 SetGroupID (uint32_t gid); 49 50 uint32_t 51 GetNumArguments (); 52 53 const char * 54 GetArgumentAtIndex (uint32_t idx); 55 56 void 57 SetArguments (const char **argv, bool append); 58 59 uint32_t 60 GetNumEnvironmentEntries (); 61 62 const char * 63 GetEnvironmentEntryAtIndex (uint32_t idx); 64 65 void 66 SetEnvironmentEntries (const char **envp, bool append); 67 68 void 69 Clear (); 70 71 const char * 72 GetWorkingDirectory () const; 73 74 void 75 SetWorkingDirectory (const char *working_dir); 76 77 uint32_t 78 GetLaunchFlags (); 79 80 void 81 SetLaunchFlags (uint32_t flags); 82 83 const char * 84 GetProcessPluginName (); 85 86 void 87 SetProcessPluginName (const char *plugin_name); 88 89 const char * 90 GetShell (); 91 92 void 93 SetShell (const char * path); 94 95 uint32_t 96 GetResumeCount (); 97 98 void 99 SetResumeCount (uint32_t c); 100 101 bool 102 AddCloseFileAction (int fd); 103 104 bool 105 AddDuplicateFileAction (int fd, int dup_fd); 106 107 bool 108 AddOpenFileAction (int fd, const char *path, bool read, bool write); 109 110 bool 111 AddSuppressFileAction (int fd, bool read, bool write); 112 113protected: 114 friend class SBTarget; 115 116 lldb_private::ProcessLaunchInfo & 117 ref (); 118 119 ProcessLaunchInfoSP m_opaque_sp; 120}; 121 122class SBAttachInfo 123{ 124public: 125 SBAttachInfo (); 126 127 SBAttachInfo (lldb::pid_t pid); 128 129 SBAttachInfo (const char *path, bool wait_for); 130 131 SBAttachInfo (const SBAttachInfo &rhs); 132 133 ~SBAttachInfo(); 134 135 SBAttachInfo & 136 operator = (const SBAttachInfo &rhs); 137 138 lldb::pid_t 139 GetProcessID (); 140 141 void 142 SetProcessID (lldb::pid_t pid); 143 144 void 145 SetExecutable (const char *path); 146 147 void 148 SetExecutable (lldb::SBFileSpec exe_file); 149 150 bool 151 GetWaitForLaunch (); 152 153 void 154 SetWaitForLaunch (bool b); 155 156 bool 157 GetIgnoreExisting (); 158 159 void 160 SetIgnoreExisting (bool b); 161 162 uint32_t 163 GetResumeCount (); 164 165 void 166 SetResumeCount (uint32_t c); 167 168 const char * 169 GetProcessPluginName (); 170 171 void 172 SetProcessPluginName (const char *plugin_name); 173 174 uint32_t 175 GetUserID(); 176 177 uint32_t 178 GetGroupID(); 179 180 bool 181 UserIDIsValid (); 182 183 bool 184 GroupIDIsValid (); 185 186 void 187 SetUserID (uint32_t uid); 188 189 void 190 SetGroupID (uint32_t gid); 191 192 uint32_t 193 GetEffectiveUserID(); 194 195 uint32_t 196 GetEffectiveGroupID(); 197 198 bool 199 EffectiveUserIDIsValid (); 200 201 bool 202 EffectiveGroupIDIsValid (); 203 204 void 205 SetEffectiveUserID (uint32_t uid); 206 207 void 208 SetEffectiveGroupID (uint32_t gid); 209 210 lldb::pid_t 211 GetParentProcessID (); 212 213 void 214 SetParentProcessID (lldb::pid_t pid); 215 216 bool 217 ParentProcessIDIsValid(); 218 219 220protected: 221 friend class SBTarget; 222 223 lldb_private::ProcessAttachInfo & 224 ref (); 225 226 ProcessAttachInfoSP m_opaque_sp; 227}; 228 229class SBTarget 230{ 231public: 232 //------------------------------------------------------------------ 233 // Broadcaster bits. 234 //------------------------------------------------------------------ 235 enum 236 { 237 eBroadcastBitBreakpointChanged = (1 << 0), 238 eBroadcastBitModulesLoaded = (1 << 1), 239 eBroadcastBitModulesUnloaded = (1 << 2), 240 eBroadcastBitWatchpointChanged = (1 << 3) 241 }; 242 243 //------------------------------------------------------------------ 244 // Constructors 245 //------------------------------------------------------------------ 246 SBTarget (); 247 248 SBTarget (const lldb::SBTarget& rhs); 249 250 const lldb::SBTarget& 251 operator = (const lldb::SBTarget& rhs); 252 253 //------------------------------------------------------------------ 254 // Destructor 255 //------------------------------------------------------------------ 256 ~SBTarget(); 257 258 bool 259 IsValid() const; 260 261 static const char * 262 GetBroadcasterClassName (); 263 264 lldb::SBProcess 265 GetProcess (); 266 267 //------------------------------------------------------------------ 268 /// Launch a new process. 269 /// 270 /// Launch a new process by spawning a new process using the 271 /// target object's executable module's file as the file to launch. 272 /// Arguments are given in \a argv, and the environment variables 273 /// are in \a envp. Standard input and output files can be 274 /// optionally re-directed to \a stdin_path, \a stdout_path, and 275 /// \a stderr_path. 276 /// 277 /// @param[in] listener 278 /// An optional listener that will receive all process events. 279 /// If \a listener is valid then \a listener will listen to all 280 /// process events. If not valid, then this target's debugger 281 /// (SBTarget::GetDebugger()) will listen to all process events. 282 /// 283 /// @param[in] argv 284 /// The argument array. 285 /// 286 /// @param[in] envp 287 /// The environment array. 288 /// 289 /// @param[in] launch_flags 290 /// Flags to modify the launch (@see lldb::LaunchFlags) 291 /// 292 /// @param[in] stdin_path 293 /// The path to use when re-directing the STDIN of the new 294 /// process. If all stdXX_path arguments are NULL, a pseudo 295 /// terminal will be used. 296 /// 297 /// @param[in] stdout_path 298 /// The path to use when re-directing the STDOUT of the new 299 /// process. If all stdXX_path arguments are NULL, a pseudo 300 /// terminal will be used. 301 /// 302 /// @param[in] stderr_path 303 /// The path to use when re-directing the STDERR of the new 304 /// process. If all stdXX_path arguments are NULL, a pseudo 305 /// terminal will be used. 306 /// 307 /// @param[in] working_directory 308 /// The working directory to have the child process run in 309 /// 310 /// @param[in] launch_flags 311 /// Some launch options specified by logical OR'ing 312 /// lldb::LaunchFlags enumeration values together. 313 /// 314 /// @param[in] stop_at_endtry 315 /// If false do not stop the inferior at the entry point. 316 /// 317 /// @param[out] 318 /// An error object. Contains the reason if there is some failure. 319 /// 320 /// @return 321 /// A process object for the newly created process. 322 //------------------------------------------------------------------ 323 lldb::SBProcess 324 Launch (SBListener &listener, 325 char const **argv, 326 char const **envp, 327 const char *stdin_path, 328 const char *stdout_path, 329 const char *stderr_path, 330 const char *working_directory, 331 uint32_t launch_flags, // See LaunchFlags 332 bool stop_at_entry, 333 lldb::SBError& error); 334 335 336 //------------------------------------------------------------------ 337 /// Launch a new process with sensible defaults. 338 /// 339 /// @param[in] argv 340 /// The argument array. 341 /// 342 /// @param[in] envp 343 /// The environment array. 344 /// 345 /// @param[in] working_directory 346 /// The working directory to have the child process run in 347 /// 348 /// Default: listener 349 /// Set to the target's debugger (SBTarget::GetDebugger()) 350 /// 351 /// Default: launch_flags 352 /// Empty launch flags 353 /// 354 /// Default: stdin_path 355 /// Default: stdout_path 356 /// Default: stderr_path 357 /// A pseudo terminal will be used. 358 /// 359 /// @return 360 /// A process object for the newly created process. 361 //------------------------------------------------------------------ 362 SBProcess 363 LaunchSimple (const char **argv, 364 const char **envp, 365 const char *working_directory); 366 367 SBProcess 368 Launch (SBLaunchInfo &launch_info, SBError& error); 369 370 SBProcess 371 LoadCore (const char *core_file); 372 373 SBProcess 374 Attach (SBAttachInfo &attach_info, SBError& error); 375 376 //------------------------------------------------------------------ 377 /// Attach to process with pid. 378 /// 379 /// @param[in] listener 380 /// An optional listener that will receive all process events. 381 /// If \a listener is valid then \a listener will listen to all 382 /// process events. If not valid, then this target's debugger 383 /// (SBTarget::GetDebugger()) will listen to all process events. 384 /// 385 /// @param[in] pid 386 /// The process ID to attach to. 387 /// 388 /// @param[out] 389 /// An error explaining what went wrong if attach fails. 390 /// 391 /// @return 392 /// A process object for the attached process. 393 //------------------------------------------------------------------ 394 lldb::SBProcess 395 AttachToProcessWithID (SBListener &listener, 396 lldb::pid_t pid, 397 lldb::SBError& error); 398 399#if defined(__APPLE__) 400 // We need to keep this around for a build or two since Xcode links 401 // to the 32 bit version of this function. We will take it out soon. 402 lldb::SBProcess 403 AttachToProcessWithID (SBListener &listener, 404 ::pid_t pid, // 32 bit int process ID 405 lldb::SBError& error); // DEPRECATED 406#endif 407 //------------------------------------------------------------------ 408 /// Attach to process with name. 409 /// 410 /// @param[in] listener 411 /// An optional listener that will receive all process events. 412 /// If \a listener is valid then \a listener will listen to all 413 /// process events. If not valid, then this target's debugger 414 /// (SBTarget::GetDebugger()) will listen to all process events. 415 /// 416 /// @param[in] name 417 /// Basename of process to attach to. 418 /// 419 /// @param[in] wait_for 420 /// If true wait for a new instance of 'name' to be launched. 421 /// 422 /// @param[out] 423 /// An error explaining what went wrong if attach fails. 424 /// 425 /// @return 426 /// A process object for the attached process. 427 //------------------------------------------------------------------ 428 lldb::SBProcess 429 AttachToProcessWithName (SBListener &listener, 430 const char *name, 431 bool wait_for, 432 lldb::SBError& error); 433 434 //------------------------------------------------------------------ 435 /// Connect to a remote debug server with url. 436 /// 437 /// @param[in] listener 438 /// An optional listener that will receive all process events. 439 /// If \a listener is valid then \a listener will listen to all 440 /// process events. If not valid, then this target's debugger 441 /// (SBTarget::GetDebugger()) will listen to all process events. 442 /// 443 /// @param[in] url 444 /// The url to connect to, e.g., 'connect://localhost:12345'. 445 /// 446 /// @param[in] plugin_name 447 /// The plugin name to be used; can be NULL. 448 /// 449 /// @param[out] 450 /// An error explaining what went wrong if the connect fails. 451 /// 452 /// @return 453 /// A process object for the connected process. 454 //------------------------------------------------------------------ 455 lldb::SBProcess 456 ConnectRemote (SBListener &listener, 457 const char *url, 458 const char *plugin_name, 459 SBError& error); 460 461 lldb::SBFileSpec 462 GetExecutable (); 463 464 bool 465 AddModule (lldb::SBModule &module); 466 467 lldb::SBModule 468 AddModule (const char *path, 469 const char *triple, 470 const char *uuid); 471 472 lldb::SBModule 473 AddModule (const char *path, 474 const char *triple, 475 const char *uuid_cstr, 476 const char *symfile); 477 uint32_t 478 GetNumModules () const; 479 480 lldb::SBModule 481 GetModuleAtIndex (uint32_t idx); 482 483 bool 484 RemoveModule (lldb::SBModule module); 485 486 lldb::SBDebugger 487 GetDebugger() const; 488 489 lldb::SBModule 490 FindModule (const lldb::SBFileSpec &file_spec); 491 492 lldb::ByteOrder 493 GetByteOrder (); 494 495 uint32_t 496 GetAddressByteSize(); 497 498 const char * 499 GetTriple (); 500 501 //------------------------------------------------------------------ 502 /// Set the base load address for a module section. 503 /// 504 /// @param[in] section 505 /// The section whose base load address will be set within this 506 /// target. 507 /// 508 /// @param[in] section_base_addr 509 /// The base address for the section. 510 /// 511 /// @return 512 /// An error to indicate success, fail, and any reason for 513 /// failure. 514 //------------------------------------------------------------------ 515 lldb::SBError 516 SetSectionLoadAddress (lldb::SBSection section, 517 lldb::addr_t section_base_addr); 518 519 //------------------------------------------------------------------ 520 /// Clear the base load address for a module section. 521 /// 522 /// @param[in] section 523 /// The section whose base load address will be cleared within 524 /// this target. 525 /// 526 /// @return 527 /// An error to indicate success, fail, and any reason for 528 /// failure. 529 //------------------------------------------------------------------ 530 lldb::SBError 531 ClearSectionLoadAddress (lldb::SBSection section); 532 533 //------------------------------------------------------------------ 534 /// Slide all file addresses for all module sections so that \a module 535 /// appears to loaded at these slide addresses. 536 /// 537 /// When you need all sections within a module to be loaded at a 538 /// rigid slide from the addresses found in the module object file, 539 /// this function will allow you to easily and quickly slide all 540 /// module sections. 541 /// 542 /// @param[in] module 543 /// The module to load. 544 /// 545 /// @param[in] sections_offset 546 /// An offset that will be applied to all section file addresses 547 /// (the virtual addresses found in the object file itself). 548 /// 549 /// @return 550 /// An error to indicate success, fail, and any reason for 551 /// failure. 552 //------------------------------------------------------------------ 553 lldb::SBError 554 SetModuleLoadAddress (lldb::SBModule module, 555 int64_t sections_offset); 556 557 558 //------------------------------------------------------------------ 559 /// The the section base load addresses for all sections in a module. 560 /// 561 /// @param[in] module 562 /// The module to unload. 563 /// 564 /// @return 565 /// An error to indicate success, fail, and any reason for 566 /// failure. 567 //------------------------------------------------------------------ 568 lldb::SBError 569 ClearModuleLoadAddress (lldb::SBModule module); 570 571 //------------------------------------------------------------------ 572 /// Find functions by name. 573 /// 574 /// @param[in] name 575 /// The name of the function we are looking for. 576 /// 577 /// @param[in] name_type_mask 578 /// A logical OR of one or more FunctionNameType enum bits that 579 /// indicate what kind of names should be used when doing the 580 /// lookup. Bits include fully qualified names, base names, 581 /// C++ methods, or ObjC selectors. 582 /// See FunctionNameType for more details. 583 /// 584 /// @return 585 /// A lldb::SBSymbolContextList that gets filled in with all of 586 /// the symbol contexts for all the matches. 587 //------------------------------------------------------------------ 588 lldb::SBSymbolContextList 589 FindFunctions (const char *name, 590 uint32_t name_type_mask = lldb::eFunctionNameTypeAny); 591 592 //------------------------------------------------------------------ 593 /// Find global and static variables by name. 594 /// 595 /// @param[in] name 596 /// The name of the global or static variable we are looking 597 /// for. 598 /// 599 /// @param[in] max_matches 600 /// Allow the number of matches to be limited to \a max_matches. 601 /// 602 /// @return 603 /// A list of matched variables in an SBValueList. 604 //------------------------------------------------------------------ 605 lldb::SBValueList 606 FindGlobalVariables (const char *name, 607 uint32_t max_matches); 608 609 //------------------------------------------------------------------ 610 /// Find the first global (or static) variable by name. 611 /// 612 /// @param[in] name 613 /// The name of the global or static variable we are looking 614 /// for. 615 /// 616 /// @return 617 /// An SBValue that gets filled in with the found variable (if any). 618 //------------------------------------------------------------------ 619 lldb::SBValue 620 FindFirstGlobalVariable (const char* name); 621 622 void 623 Clear (); 624 625 lldb::SBAddress 626 ResolveLoadAddress (lldb::addr_t vm_addr); 627 628 SBSymbolContext 629 ResolveSymbolContextForAddress (const SBAddress& addr, 630 uint32_t resolve_scope); 631 632 lldb::SBBreakpoint 633 BreakpointCreateByLocation (const char *file, uint32_t line); 634 635 lldb::SBBreakpoint 636 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line); 637 638 lldb::SBBreakpoint 639 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL); 640 641 // This version uses name_type_mask = eFunctionNameTypeAuto 642 lldb::SBBreakpoint 643 BreakpointCreateByName (const char *symbol_name, 644 const SBFileSpecList &module_list, 645 const SBFileSpecList &comp_unit_list); 646 647 lldb::SBBreakpoint 648 BreakpointCreateByName (const char *symbol_name, 649 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits 650 const SBFileSpecList &module_list, 651 const SBFileSpecList &comp_unit_list); 652 653 lldb::SBBreakpoint 654 BreakpointCreateByNames (const char *symbol_name[], 655 uint32_t num_names, 656 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits 657 const SBFileSpecList &module_list, 658 const SBFileSpecList &comp_unit_list); 659 660 lldb::SBBreakpoint 661 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL); 662 663 lldb::SBBreakpoint 664 BreakpointCreateByRegex (const char *symbol_name_regex, 665 const SBFileSpecList &module_list, 666 const SBFileSpecList &comp_unit_list); 667 668 lldb::SBBreakpoint 669 BreakpointCreateBySourceRegex (const char *source_regex, 670 const lldb::SBFileSpec &source_file, 671 const char *module_name = NULL); 672 673 lldb::SBBreakpoint 674 BreakpointCreateBySourceRegex (const char *source_regex, 675 const SBFileSpecList &module_list, 676 const lldb::SBFileSpecList &source_file); 677 678 lldb::SBBreakpoint 679 BreakpointCreateForException (lldb::LanguageType language, 680 bool catch_bp, 681 bool throw_bp); 682 683 lldb::SBBreakpoint 684 BreakpointCreateByAddress (addr_t address); 685 686 uint32_t 687 GetNumBreakpoints () const; 688 689 lldb::SBBreakpoint 690 GetBreakpointAtIndex (uint32_t idx) const; 691 692 bool 693 BreakpointDelete (break_id_t break_id); 694 695 lldb::SBBreakpoint 696 FindBreakpointByID (break_id_t break_id); 697 698 bool 699 EnableAllBreakpoints (); 700 701 bool 702 DisableAllBreakpoints (); 703 704 bool 705 DeleteAllBreakpoints (); 706 707 uint32_t 708 GetNumWatchpoints () const; 709 710 lldb::SBWatchpoint 711 GetWatchpointAtIndex (uint32_t idx) const; 712 713 bool 714 DeleteWatchpoint (lldb::watch_id_t watch_id); 715 716 lldb::SBWatchpoint 717 FindWatchpointByID (lldb::watch_id_t watch_id); 718 719 lldb::SBWatchpoint 720 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error); 721 722 bool 723 EnableAllWatchpoints (); 724 725 bool 726 DisableAllWatchpoints (); 727 728 bool 729 DeleteAllWatchpoints (); 730 731 lldb::SBBroadcaster 732 GetBroadcaster () const; 733 734 lldb::SBType 735 FindFirstType (const char* type); 736 737 lldb::SBTypeList 738 FindTypes (const char* type); 739 740 lldb::SBType 741 GetBasicType(lldb::BasicType type); 742 743 SBSourceManager 744 GetSourceManager(); 745 746 lldb::SBInstructionList 747 ReadInstructions (lldb::SBAddress base_addr, uint32_t count); 748 749 lldb::SBInstructionList 750 ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string); 751 752 lldb::SBInstructionList 753 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size); 754 755 // The "WithFlavor" is necessary to keep SWIG from getting confused about overloaded arguments when 756 // using the buf + size -> Python Object magic. 757 758 lldb::SBInstructionList 759 GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size); 760 761 lldb::SBInstructionList 762 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size); 763 764 lldb::SBInstructionList 765 GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size); 766 767 lldb::SBSymbolContextList 768 FindSymbols (const char *name, 769 lldb::SymbolType type = eSymbolTypeAny); 770 771 bool 772 operator == (const lldb::SBTarget &rhs) const; 773 774 bool 775 operator != (const lldb::SBTarget &rhs) const; 776 777 bool 778 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); 779 780 lldb::SBValue 781 EvaluateExpression (const char *expr, const SBExpressionOptions &options); 782 783 lldb::addr_t 784 GetStackRedZoneSize(); 785 786protected: 787 friend class SBAddress; 788 friend class SBBlock; 789 friend class SBDebugger; 790 friend class SBFunction; 791 friend class SBInstruction; 792 friend class SBModule; 793 friend class SBProcess; 794 friend class SBSection; 795 friend class SBSourceManager; 796 friend class SBSymbol; 797 friend class SBValue; 798 799 //------------------------------------------------------------------ 800 // Constructors are private, use static Target::Create function to 801 // create an instance of this class. 802 //------------------------------------------------------------------ 803 804 SBTarget (const lldb::TargetSP& target_sp); 805 806 lldb::TargetSP 807 GetSP () const; 808 809 void 810 SetSP (const lldb::TargetSP& target_sp); 811 812 813private: 814 //------------------------------------------------------------------ 815 // For Target only 816 //------------------------------------------------------------------ 817 818 lldb::TargetSP m_opaque_sp; 819}; 820 821} // namespace lldb 822 823#endif // LLDB_SBTarget_h_ 824