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