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