Process.h revision 20d338fad87eba91de65aa9bec76e01c04472848
1//===-- Process.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_Process_h_ 11#define liblldb_Process_h_ 12 13// C Includes 14// C++ Includes 15#include <list> 16 17// Other libraries and framework includes 18// Project includes 19#include "lldb/lldb-private.h" 20#include "lldb/Interpreter/Args.h" 21#include "lldb/Interpreter/Options.h" 22#include "lldb/Core/Broadcaster.h" 23#include "lldb/Core/Communication.h" 24#include "lldb/Core/Error.h" 25#include "lldb/Core/Event.h" 26#include "lldb/Core/StringList.h" 27#include "lldb/Core/ThreadSafeValue.h" 28#include "lldb/Core/PluginInterface.h" 29#include "lldb/Core/UserSettingsController.h" 30#include "lldb/Breakpoint/BreakpointSiteList.h" 31#include "lldb/Expression/ClangPersistentVariables.h" 32#include "lldb/Expression/IRDynamicChecks.h" 33#include "lldb/Target/ExecutionContextScope.h" 34#include "lldb/Target/ThreadList.h" 35#include "lldb/Target/UnixSignals.h" 36 37namespace lldb_private { 38 39 40typedef enum ProcessPlugins 41{ 42 eMacosx, 43 eRemoteDebugger 44} ProcessPlugins; 45 46 47class ProcessInstanceSettings : public InstanceSettings 48{ 49public: 50 51 ProcessInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); 52 53 ProcessInstanceSettings (const ProcessInstanceSettings &rhs); 54 55 virtual 56 ~ProcessInstanceSettings (); 57 58 ProcessInstanceSettings& 59 operator= (const ProcessInstanceSettings &rhs); 60 61 62 void 63 UpdateInstanceSettingsVariable (const ConstString &var_name, 64 const char *index_value, 65 const char *value, 66 const ConstString &instance_name, 67 const SettingEntry &entry, 68 lldb::VarSetOperationType op, 69 Error &err, 70 bool pending); 71 72 bool 73 GetInstanceSettingsValue (const SettingEntry &entry, 74 const ConstString &var_name, 75 StringList &value, 76 Error *err); 77 78 79 const Args & 80 GetRunArguments () const 81 { 82 return m_run_args; 83 } 84 85 void 86 SetRunArguments (const Args &args) 87 { 88 m_run_args = args; 89 } 90 91 size_t 92 GetEnvironmentAsArgs (Args &env) const 93 { 94 dictionary::const_iterator pos, end = m_env_vars.end(); 95 for (pos = m_env_vars.begin(); pos != end; ++pos) 96 { 97 std::string env_var_equal_value (pos->first); 98 env_var_equal_value.append(1, '='); 99 env_var_equal_value.append (pos->second); 100 env.AppendArgument (env_var_equal_value.c_str()); 101 } 102 return env.GetArgumentCount(); 103 } 104 105 const char * 106 GetStandardInputPath () const 107 { 108 if (m_input_path.empty()) 109 return NULL; 110 return m_input_path.c_str(); 111 } 112 113 void 114 SetStandardInputPath (const char *path) 115 { 116 if (path && path[0]) 117 m_input_path.assign (path); 118 else 119 { 120 // Make sure we deallocate memory in string... 121 std::string tmp; 122 tmp.swap (m_input_path); 123 } 124 } 125 126 const char * 127 GetStandardOutputPath () const 128 { 129 if (m_output_path.empty()) 130 return NULL; 131 return m_output_path.c_str(); 132 } 133 134 void 135 SetStandardOutputPath (const char *path) 136 { 137 if (path && path[0]) 138 m_output_path.assign (path); 139 else 140 { 141 // Make sure we deallocate memory in string... 142 std::string tmp; 143 tmp.swap (m_output_path); 144 } 145 } 146 147 const char * 148 GetStandardErrorPath () const 149 { 150 if (m_error_path.empty()) 151 return NULL; 152 return m_error_path.c_str(); 153 } 154 155 void 156 SetStandardErrorPath (const char *path) 157 { 158 if (path && path[0]) 159 m_error_path.assign (path); 160 else 161 { 162 // Make sure we deallocate memory in string... 163 std::string tmp; 164 tmp.swap (m_error_path); 165 } 166 } 167 168 bool 169 GetDisableASLR () const 170 { 171 return m_disable_aslr; 172 } 173 174 void 175 SetDisableASLR (bool b) 176 { 177 m_disable_aslr = b; 178 } 179 180protected: 181 182 void 183 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 184 bool pending); 185 186 const ConstString 187 CreateInstanceName (); 188 189 static const ConstString & 190 RunArgsVarName (); 191 192 static const ConstString & 193 EnvVarsVarName (); 194 195 static const ConstString & 196 InputPathVarName (); 197 198 static const ConstString & 199 OutputPathVarName (); 200 201 static const ConstString & 202 ErrorPathVarName (); 203 204 static const ConstString & 205 PluginVarName (); 206 207 static const ConstString & 208 DisableASLRVarName(); 209 210 211private: 212 213 typedef std::map<std::string, std::string> dictionary; 214 Args m_run_args; 215 dictionary m_env_vars; 216 std::string m_input_path; 217 std::string m_output_path; 218 std::string m_error_path; 219 ProcessPlugins m_plugin; 220 bool m_disable_aslr; 221}; 222 223 224//---------------------------------------------------------------------- 225/// @class Process Process.h "lldb/Target/Process.h" 226/// @brief A plug-in interface definition class for debugging a process. 227//---------------------------------------------------------------------- 228class Process : 229 public UserID, 230 public Broadcaster, 231 public ExecutionContextScope, 232 public PluginInterface, 233 public ProcessInstanceSettings 234{ 235friend class ThreadList; 236friend class ClangFunction; // For WaitForStateChangeEventsPrivate 237 238public: 239 240 //------------------------------------------------------------------ 241 /// Broadcaster event bits definitions. 242 //------------------------------------------------------------------ 243 enum 244 { 245 eBroadcastBitStateChanged = (1 << 0), 246 eBroadcastBitInterrupt = (1 << 1), 247 eBroadcastBitSTDOUT = (1 << 2), 248 eBroadcastBitSTDERR = (1 << 3) 249 }; 250 251 enum 252 { 253 eBroadcastInternalStateControlStop = (1<<0), 254 eBroadcastInternalStateControlPause = (1<<1), 255 eBroadcastInternalStateControlResume = (1<<2) 256 }; 257 258 //------------------------------------------------------------------ 259 /// A notification structure that can be used by clients to listen 260 /// for changes in a process's lifetime. 261 /// 262 /// @see RegisterNotificationCallbacks (const Notifications&) 263 /// @see UnregisterNotificationCallbacks (const Notifications&) 264 //------------------------------------------------------------------ 265#ifndef SWIG 266 typedef struct 267 { 268 void *baton; 269 void (*initialize)(void *baton, Process *process); 270 void (*process_state_changed) (void *baton, Process *process, lldb::StateType state); 271 } Notifications; 272 273 class ProcessEventData : 274 public EventData 275 { 276 friend class Process; 277 278 public: 279 ProcessEventData (); 280 ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state); 281 282 virtual ~ProcessEventData(); 283 284 static const ConstString & 285 GetFlavorString (); 286 287 virtual const ConstString & 288 GetFlavor () const; 289 290 const lldb::ProcessSP & 291 GetProcessSP() const 292 { 293 return m_process_sp; 294 } 295 lldb::StateType 296 GetState() const 297 { 298 return m_state; 299 } 300 bool 301 GetRestarted () const 302 { 303 return m_restarted; 304 } 305 bool 306 GetInterrupted () const 307 { 308 return m_interrupted; 309 } 310 311 virtual void 312 Dump (Stream *s) const; 313 314 virtual void 315 DoOnRemoval (Event *event_ptr); 316 317 static const Process::ProcessEventData * 318 GetEventDataFromEvent (const Event *event_ptr); 319 320 static lldb::ProcessSP 321 GetProcessFromEvent (const Event *event_ptr); 322 323 static lldb::StateType 324 GetStateFromEvent (const Event *event_ptr); 325 326 static bool 327 GetRestartedFromEvent (const Event *event_ptr); 328 329 static void 330 SetRestartedInEvent (Event *event_ptr, bool new_value); 331 332 static bool 333 GetInterruptedFromEvent (const Event *event_ptr); 334 335 static void 336 SetInterruptedInEvent (Event *event_ptr, bool new_value); 337 338 static bool 339 SetUpdateStateOnRemoval (Event *event_ptr); 340 341 private: 342 343 void 344 SetUpdateStateOnRemoval() 345 { 346 m_update_state = true; 347 } 348 void 349 SetRestarted (bool new_value) 350 { 351 m_restarted = new_value; 352 } 353 void 354 SetInterrupted (bool new_value) 355 { 356 m_interrupted = new_value; 357 } 358 359 lldb::ProcessSP m_process_sp; 360 lldb::StateType m_state; 361 bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted. 362 bool m_update_state; 363 bool m_interrupted; 364 DISALLOW_COPY_AND_ASSIGN (ProcessEventData); 365 366 }; 367 368 class SettingsController : public UserSettingsController 369 { 370 public: 371 372 SettingsController (); 373 374 virtual 375 ~SettingsController (); 376 377 static SettingEntry global_settings_table[]; 378 static SettingEntry instance_settings_table[]; 379 380 protected: 381 382 lldb::InstanceSettingsSP 383 CreateInstanceSettings (const char *instance_name); 384 385 static lldb::OptionEnumValueElement g_plugins[]; 386 387 private: 388 389 // Class-wide settings. 390 391 DISALLOW_COPY_AND_ASSIGN (SettingsController); 392 }; 393 394#endif 395 396 static lldb::UserSettingsControllerSP 397 GetSettingsController (bool finish = false); 398 399 void 400 UpdateInstanceName (); 401 402 //------------------------------------------------------------------ 403 /// Construct with a shared pointer to a target, and the Process listener. 404 //------------------------------------------------------------------ 405 Process(Target &target, Listener &listener); 406 407 //------------------------------------------------------------------ 408 /// Destructor. 409 /// 410 /// The destructor is virtual since this class is designed to be 411 /// inherited from by the plug-in instance. 412 //------------------------------------------------------------------ 413 virtual 414 ~Process(); 415 416 //------------------------------------------------------------------ 417 /// Find a Process plug-in that can debug \a module using the 418 /// currently selected architecture. 419 /// 420 /// Scans all loaded plug-in interfaces that implement versions of 421 /// the Process plug-in interface and returns the first instance 422 /// that can debug the file. 423 /// 424 /// @param[in] module_sp 425 /// The module shared pointer that this process will debug. 426 /// 427 /// @param[in] plugin_name 428 /// If NULL, select the best plug-in for the binary. If non-NULL 429 /// then look for a plugin whose PluginInfo's name matches 430 /// this string. 431 /// 432 /// @see Process::CanDebug () 433 //------------------------------------------------------------------ 434 static Process* 435 FindPlugin (Target &target, const char *plugin_name, Listener &listener); 436 437 438 439 //------------------------------------------------------------------ 440 /// Static function that can be used with the \b host function 441 /// Host::StartMonitoringChildProcess (). 442 /// 443 /// This function can be used by lldb_private::Process subclasses 444 /// when they want to watch for a local process and have its exit 445 /// status automatically set when the host child process exits. 446 /// Subclasses should call Host::StartMonitoringChildProcess () 447 /// with: 448 /// callback = Process::SetHostProcessExitStatus 449 /// callback_baton = NULL 450 /// pid = Process::GetID() 451 /// monitor_signals = false 452 //------------------------------------------------------------------ 453 static bool 454 SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL 455 lldb::pid_t pid, // The process ID we want to monitor 456 int signo, // Zero for no signal 457 int status); // Exit value of process if signal is zero 458 459 //------------------------------------------------------------------ 460 /// Check if a plug-in instance can debug the file in \a module. 461 /// 462 /// Each plug-in is given a chance to say whether it can debug 463 /// the file in \a module. If the Process plug-in instance can 464 /// debug a file on the current system, it should return \b true. 465 /// 466 /// @return 467 /// Returns \b true if this Process plug-in instance can 468 /// debug the executable, \b false otherwise. 469 //------------------------------------------------------------------ 470 virtual bool 471 CanDebug (Target &target) = 0; 472 473 474 //------------------------------------------------------------------ 475 /// This object is about to be destroyed, do any necessary cleanup. 476 /// 477 /// Subclasses that override this method should always call this 478 /// superclass method. 479 //------------------------------------------------------------------ 480 virtual void 481 Finalize(); 482 483 //------------------------------------------------------------------ 484 /// Launch a new process. 485 /// 486 /// Launch a new process by spawning a new process using the 487 /// target object's executable module's file as the file to launch. 488 /// Arguments are given in \a argv, and the environment variables 489 /// are in \a envp. Standard input and output files can be 490 /// optionally re-directed to \a stdin_path, \a stdout_path, and 491 /// \a stderr_path. 492 /// 493 /// This function is not meant to be overridden by Process 494 /// subclasses. It will first call Process::WillLaunch (Module *) 495 /// and if that returns \b true, Process::DoLaunch (Module*, 496 /// char const *[],char const *[],const char *,const char *, 497 /// const char *) will be called to actually do the launching. If 498 /// DoLaunch returns \b true, then Process::DidLaunch() will be 499 /// called. 500 /// 501 /// @param[in] argv 502 /// The argument array. 503 /// 504 /// @param[in] envp 505 /// The environment array. 506 /// 507 /// @param[in] launch_flags 508 /// Flags to modify the launch (@see lldb::LaunchFlags) 509 /// 510 /// @param[in] stdin_path 511 /// The path to use when re-directing the STDIN of the new 512 /// process. If all stdXX_path arguments are NULL, a pseudo 513 /// terminal will be used. 514 /// 515 /// @param[in] stdout_path 516 /// The path to use when re-directing the STDOUT of the new 517 /// process. If all stdXX_path arguments are NULL, a pseudo 518 /// terminal will be used. 519 /// 520 /// @param[in] stderr_path 521 /// The path to use when re-directing the STDERR of the new 522 /// process. If all stdXX_path arguments are NULL, a pseudo 523 /// terminal will be used. 524 /// 525 /// @return 526 /// An error object. Call GetID() to get the process ID if 527 /// the error object is success. 528 //------------------------------------------------------------------ 529 virtual Error 530 Launch (char const *argv[], 531 char const *envp[], 532 uint32_t launch_flags, 533 const char *stdin_path, 534 const char *stdout_path, 535 const char *stderr_path); 536 537 //------------------------------------------------------------------ 538 /// Attach to an existing process using a process ID. 539 /// 540 /// This function is not meant to be overridden by Process 541 /// subclasses. It will first call Process::WillAttach (lldb::pid_t) 542 /// and if that returns \b true, Process::DoAttach (lldb::pid_t) will 543 /// be called to actually do the attach. If DoAttach returns \b 544 /// true, then Process::DidAttach() will be called. 545 /// 546 /// @param[in] pid 547 /// The process ID that we should attempt to attach to. 548 /// 549 /// @return 550 /// Returns \a pid if attaching was successful, or 551 /// LLDB_INVALID_PROCESS_ID if attaching fails. 552 //------------------------------------------------------------------ 553 virtual Error 554 Attach (lldb::pid_t pid); 555 556 //------------------------------------------------------------------ 557 /// Attach to an existing process by process name. 558 /// 559 /// This function is not meant to be overridden by Process 560 /// subclasses. It will first call 561 /// Process::WillAttach (const char *) and if that returns \b 562 /// true, Process::DoAttach (const char *) will be called to 563 /// actually do the attach. If DoAttach returns \b true, then 564 /// Process::DidAttach() will be called. 565 /// 566 /// @param[in] process_name 567 /// A process name to match against the current process list. 568 /// 569 /// @return 570 /// Returns \a pid if attaching was successful, or 571 /// LLDB_INVALID_PROCESS_ID if attaching fails. 572 //------------------------------------------------------------------ 573 virtual Error 574 Attach (const char *process_name, bool wait_for_launch); 575 576 //------------------------------------------------------------------ 577 /// List the processes matching the given partial name. 578 /// 579 /// FIXME: Is it too heavyweight to create an entire process object to do this? 580 /// The problem is for remote processes we're going to have to set up the same transport 581 /// to get this data as to actually attach. So we need to factor out transport 582 /// and process before we can do this separately from the process. 583 /// 584 /// @param[in] name 585 /// A partial name to match against the current process list. 586 /// 587 /// @param[out] matches 588 /// The list of process names matching \a name. 589 /// 590 /// @param[in] pids 591 /// A vector filled with the pids that correspond to the names in \a matches. 592 /// 593 /// @return 594 /// Returns the number of matching processes. 595 //------------------------------------------------------------------ 596 597 virtual uint32_t 598 ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids); 599 600 //------------------------------------------------------------------ 601 /// Find the architecture of a process by pid. 602 /// 603 /// FIXME: See comment for ListProcessesMatchingName. 604 /// 605 /// @param[in] pid 606 /// A pid to inspect. 607 /// 608 /// @return 609 /// Returns the architecture of the process or an invalid architecture if the process can't be found. 610 //------------------------------------------------------------------ 611 virtual ArchSpec 612 GetArchSpecForExistingProcess (lldb::pid_t pid); 613 614 //------------------------------------------------------------------ 615 /// Find the architecture of a process by name. 616 /// 617 /// FIXME: See comment for ListProcessesMatchingName. 618 /// 619 /// @param[in] process_name 620 /// The process name to inspect. 621 /// 622 /// @return 623 /// Returns the architecture of the process or an invalid architecture if the process can't be found. 624 //------------------------------------------------------------------ 625 virtual ArchSpec 626 GetArchSpecForExistingProcess (const char *process_name); 627 628 uint32_t 629 GetAddressByteSize(); 630 631 void 632 SetAddressByteSize (uint32_t addr_byte_size) 633 { 634 m_addr_byte_size = addr_byte_size; 635 } 636 637 //------------------------------------------------------------------ 638 /// Get the image information address for the current process. 639 /// 640 /// Some runtimes have system functions that can help dynamic 641 /// loaders locate the dynamic loader information needed to observe 642 /// shared libraries being loaded or unloaded. This function is 643 /// in the Process interface (as opposed to the DynamicLoader 644 /// interface) to ensure that remote debugging can take advantage of 645 /// this functionality. 646 /// 647 /// @return 648 /// The address of the dynamic loader information, or 649 /// LLDB_INVALID_ADDRESS if this is not supported by this 650 /// interface. 651 //------------------------------------------------------------------ 652 virtual lldb::addr_t 653 GetImageInfoAddress (); 654 655 //------------------------------------------------------------------ 656 /// Load a shared library into this process. 657 /// 658 /// Try and load a shared library into the current process. This 659 /// call might fail in the dynamic loader plug-in says it isn't safe 660 /// to try and load shared libraries at the moment. 661 /// 662 /// @param[in] image_spec 663 /// The image file spec that points to the shared library that 664 /// you want to load. 665 /// 666 /// @param[out] error 667 /// An error object that gets filled in with any errors that 668 /// might occur when trying to load the shared library. 669 /// 670 /// @return 671 /// A token that represents the shared library that can be 672 /// later used to unload the shared library. A value of 673 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 674 /// library can't be opened. 675 //------------------------------------------------------------------ 676 virtual uint32_t 677 LoadImage (const FileSpec &image_spec, Error &error); 678 679 virtual Error 680 UnloadImage (uint32_t image_token); 681 682 //------------------------------------------------------------------ 683 /// Register for process and thread notifications. 684 /// 685 /// Clients can register nofication callbacks by filling out a 686 /// Process::Notifications structure and calling this function. 687 /// 688 /// @param[in] callbacks 689 /// A structure that contains the notification baton and 690 /// callback functions. 691 /// 692 /// @see Process::Notifications 693 //------------------------------------------------------------------ 694#ifndef SWIG 695 void 696 RegisterNotificationCallbacks (const Process::Notifications& callbacks); 697#endif 698 //------------------------------------------------------------------ 699 /// Unregister for process and thread notifications. 700 /// 701 /// Clients can unregister nofication callbacks by passing a copy of 702 /// the original baton and callbacks in \a callbacks. 703 /// 704 /// @param[in] callbacks 705 /// A structure that contains the notification baton and 706 /// callback functions. 707 /// 708 /// @return 709 /// Returns \b true if the notification callbacks were 710 /// successfully removed from the process, \b false otherwise. 711 /// 712 /// @see Process::Notifications 713 //------------------------------------------------------------------ 714#ifndef SWIG 715 bool 716 UnregisterNotificationCallbacks (const Process::Notifications& callbacks); 717#endif 718 //================================================================== 719 // Built in Process Control functions 720 //================================================================== 721 //------------------------------------------------------------------ 722 /// Resumes all of a process's threads as configured using the 723 /// Thread run control functions. 724 /// 725 /// Threads for a process should be updated with one of the run 726 /// control actions (resume, step, or suspend) that they should take 727 /// when the process is resumed. If no run control action is given 728 /// to a thread it will be resumed by default. 729 /// 730 /// This function is not meant to be overridden by Process 731 /// subclasses. This function will take care of disabling any 732 /// breakpoints that threads may be stopped at, single stepping, and 733 /// re-enabling breakpoints, and enabling the basic flow control 734 /// that the plug-in instances need not worry about. 735 /// 736 /// @return 737 /// Returns an error object. 738 /// 739 /// @see Thread:Resume() 740 /// @see Thread:Step() 741 /// @see Thread:Suspend() 742 //------------------------------------------------------------------ 743 Error 744 Resume (); 745 746 //------------------------------------------------------------------ 747 /// Halts a running process. 748 /// 749 /// This function is not meant to be overridden by Process 750 /// subclasses. 751 /// If the process is successfully halted, a eStateStopped 752 /// process event with GetInterrupted will be broadcast. If false, we will 753 /// halt the process with no events generated by the halt. 754 /// 755 /// @return 756 /// Returns an error object. If the error is empty, the process is halted. 757 /// otherwise the halt has failed. 758 //------------------------------------------------------------------ 759 Error 760 Halt (); 761 762 //------------------------------------------------------------------ 763 /// Detaches from a running or stopped process. 764 /// 765 /// This function is not meant to be overridden by Process 766 /// subclasses. 767 /// 768 /// @return 769 /// Returns an error object. 770 //------------------------------------------------------------------ 771 Error 772 Detach (); 773 774 //------------------------------------------------------------------ 775 /// Kills the process and shuts down all threads that were spawned 776 /// to track and monitor the process. 777 /// 778 /// This function is not meant to be overridden by Process 779 /// subclasses. 780 /// 781 /// @return 782 /// Returns an error object. 783 //------------------------------------------------------------------ 784 Error 785 Destroy(); 786 787 //------------------------------------------------------------------ 788 /// Sends a process a UNIX signal \a signal. 789 /// 790 /// This function is not meant to be overridden by Process 791 /// subclasses. 792 /// 793 /// @return 794 /// Returns an error object. 795 //------------------------------------------------------------------ 796 Error 797 Signal (int signal); 798 799 virtual UnixSignals & 800 GetUnixSignals (); 801 802 803 //================================================================== 804 // Plug-in Process Control Overrides 805 //================================================================== 806 807 //------------------------------------------------------------------ 808 /// Called before attaching to a process. 809 /// 810 /// Allow Process plug-ins to execute some code before attaching a 811 /// process. 812 /// 813 /// @return 814 /// Returns an error object. 815 //------------------------------------------------------------------ 816 virtual Error 817 WillAttachToProcessWithID (lldb::pid_t pid) 818 { 819 return Error(); 820 } 821 822 //------------------------------------------------------------------ 823 /// Called before attaching to a process. 824 /// 825 /// Allow Process plug-ins to execute some code before attaching a 826 /// process. 827 /// 828 /// @return 829 /// Returns an error object. 830 //------------------------------------------------------------------ 831 virtual Error 832 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) 833 { 834 return Error(); 835 } 836 837 //------------------------------------------------------------------ 838 /// Attach to an existing process using a process ID. 839 /// 840 /// @param[in] pid 841 /// The process ID that we should attempt to attach to. 842 /// 843 /// @return 844 /// Returns \a pid if attaching was successful, or 845 /// LLDB_INVALID_PROCESS_ID if attaching fails. 846 //------------------------------------------------------------------ 847 virtual Error 848 DoAttachToProcessWithID (lldb::pid_t pid) = 0; 849 850 //------------------------------------------------------------------ 851 /// Attach to an existing process using a partial process name. 852 /// 853 /// @param[in] process_name 854 /// The name of the process to attach to. 855 /// 856 /// @param[in] wait_for_launch 857 /// If \b true, wait for the process to be launched and attach 858 /// as soon as possible after it does launch. If \b false, then 859 /// search for a matching process the currently exists. 860 /// 861 /// @return 862 /// Returns \a pid if attaching was successful, or 863 /// LLDB_INVALID_PROCESS_ID if attaching fails. 864 //------------------------------------------------------------------ 865 virtual Error 866 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch) 867 { 868 Error error; 869 error.SetErrorString("attach by name is not supported"); 870 return error; 871 } 872 873 //------------------------------------------------------------------ 874 /// Called after attaching a process. 875 /// 876 /// Allow Process plug-ins to execute some code after attaching to 877 /// a process. 878 //------------------------------------------------------------------ 879 virtual void 880 DidAttach () {} 881 882 883 //------------------------------------------------------------------ 884 /// Called before launching to a process. 885 /// 886 /// Allow Process plug-ins to execute some code before launching a 887 /// process. 888 /// 889 /// @return 890 /// Returns an error object. 891 //------------------------------------------------------------------ 892 virtual Error 893 WillLaunch (Module* module) 894 { 895 return Error(); 896 } 897 898 //------------------------------------------------------------------ 899 /// Launch a new process. 900 /// 901 /// Launch a new process by spawning a new process using \a module's 902 /// file as the file to launch. Arguments are given in \a argv, 903 /// and the environment variables are in \a envp. Standard input 904 /// and output files can be optionally re-directed to \a stdin_path, 905 /// \a stdout_path, and \a stderr_path. 906 /// 907 /// @param[in] module 908 /// The module from which to extract the file specification and 909 /// launch. 910 /// 911 /// @param[in] argv 912 /// The argument array. 913 /// 914 /// @param[in] envp 915 /// The environment array. 916 /// 917 /// @param[in] launch_flags 918 /// Flags to modify the launch (@see lldb::LaunchFlags) 919 /// 920 /// @param[in] stdin_path 921 /// The path to use when re-directing the STDIN of the new 922 /// process. If all stdXX_path arguments are NULL, a pseudo 923 /// terminal will be used. 924 /// 925 /// @param[in] stdout_path 926 /// The path to use when re-directing the STDOUT of the new 927 /// process. If all stdXX_path arguments are NULL, a pseudo 928 /// terminal will be used. 929 /// 930 /// @param[in] stderr_path 931 /// The path to use when re-directing the STDERR of the new 932 /// process. If all stdXX_path arguments are NULL, a pseudo 933 /// terminal will be used. 934 /// 935 /// @return 936 /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if 937 /// launching fails. 938 //------------------------------------------------------------------ 939 virtual Error 940 DoLaunch (Module* module, 941 char const *argv[], 942 char const *envp[], 943 uint32_t launch_flags, 944 const char *stdin_path, 945 const char *stdout_path, 946 const char *stderr_path) = 0; 947 948 //------------------------------------------------------------------ 949 /// Called after launching a process. 950 /// 951 /// Allow Process plug-ins to execute some code after launching 952 /// a process. 953 //------------------------------------------------------------------ 954 virtual void 955 DidLaunch () {} 956 957 958 959 //------------------------------------------------------------------ 960 /// Called before resuming to a process. 961 /// 962 /// Allow Process plug-ins to execute some code before resuming a 963 /// process. 964 /// 965 /// @return 966 /// Returns an error object. 967 //------------------------------------------------------------------ 968 virtual Error 969 WillResume () { return Error(); } 970 971 //------------------------------------------------------------------ 972 /// Resumes all of a process's threads as configured using the 973 /// Thread run control functions. 974 /// 975 /// Threads for a process should be updated with one of the run 976 /// control actions (resume, step, or suspend) that they should take 977 /// when the process is resumed. If no run control action is given 978 /// to a thread it will be resumed by default. 979 /// 980 /// @return 981 /// Returns \b true if the process successfully resumes using 982 /// the thread run control actions, \b false otherwise. 983 /// 984 /// @see Thread:Resume() 985 /// @see Thread:Step() 986 /// @see Thread:Suspend() 987 //------------------------------------------------------------------ 988 virtual Error 989 DoResume () = 0; 990 991 //------------------------------------------------------------------ 992 /// Called after resuming a process. 993 /// 994 /// Allow Process plug-ins to execute some code after resuming 995 /// a process. 996 //------------------------------------------------------------------ 997 virtual void 998 DidResume () {} 999 1000 1001 //------------------------------------------------------------------ 1002 /// Called before halting to a process. 1003 /// 1004 /// Allow Process plug-ins to execute some code before halting a 1005 /// process. 1006 /// 1007 /// @return 1008 /// Returns an error object. 1009 //------------------------------------------------------------------ 1010 virtual Error 1011 WillHalt () { return Error(); } 1012 1013 //------------------------------------------------------------------ 1014 /// Halts a running process. 1015 /// 1016 /// DoHalt should consume any process events that were delivered in 1017 /// the process of implementing the halt. 1018 /// 1019 /// @param[out] caused_stop 1020 /// If true, then this Halt caused the stop, otherwise, the 1021 /// process was already stopped. 1022 /// 1023 /// @return 1024 /// Returns \b true if the process successfully halts, \b false 1025 /// otherwise. 1026 //------------------------------------------------------------------ 1027 virtual Error 1028 DoHalt (bool &caused_stop) = 0; 1029 1030 //------------------------------------------------------------------ 1031 /// Called after halting a process. 1032 /// 1033 /// Allow Process plug-ins to execute some code after halting 1034 /// a process. 1035 //------------------------------------------------------------------ 1036 virtual void 1037 DidHalt () {} 1038 1039 //------------------------------------------------------------------ 1040 /// Called before detaching from a process. 1041 /// 1042 /// Allow Process plug-ins to execute some code before detaching 1043 /// from a process. 1044 /// 1045 /// @return 1046 /// Returns an error object. 1047 //------------------------------------------------------------------ 1048 virtual Error 1049 WillDetach () 1050 { 1051 return Error(); 1052 } 1053 1054 //------------------------------------------------------------------ 1055 /// Detaches from a running or stopped process. 1056 /// 1057 /// @return 1058 /// Returns \b true if the process successfully detaches, \b 1059 /// false otherwise. 1060 //------------------------------------------------------------------ 1061 virtual Error 1062 DoDetach () = 0; 1063 1064 //------------------------------------------------------------------ 1065 /// Called after detaching from a process. 1066 /// 1067 /// Allow Process plug-ins to execute some code after detaching 1068 /// from a process. 1069 //------------------------------------------------------------------ 1070 virtual void 1071 DidDetach () {} 1072 1073 //------------------------------------------------------------------ 1074 /// Called before sending a signal to a process. 1075 /// 1076 /// Allow Process plug-ins to execute some code before sending a 1077 /// signal to a process. 1078 /// 1079 /// @return 1080 /// Returns no error if it is safe to proceed with a call to 1081 /// Process::DoSignal(int), otherwise an error describing what 1082 /// prevents the signal from being sent. 1083 //------------------------------------------------------------------ 1084 virtual Error 1085 WillSignal () { return Error(); } 1086 1087 //------------------------------------------------------------------ 1088 /// Sends a process a UNIX signal \a signal. 1089 /// 1090 /// @return 1091 /// Returns an error object. 1092 //------------------------------------------------------------------ 1093 virtual Error 1094 DoSignal (int signal) = 0; 1095 1096 1097 1098 virtual Error 1099 WillDestroy () { return Error(); } 1100 1101 virtual Error 1102 DoDestroy () = 0; 1103 1104 virtual void 1105 DidDestroy () { } 1106 1107 1108 //------------------------------------------------------------------ 1109 /// Called after sending a signal to a process. 1110 /// 1111 /// Allow Process plug-ins to execute some code after sending a 1112 /// signal to a process. 1113 //------------------------------------------------------------------ 1114 virtual void 1115 DidSignal () {} 1116 1117 1118 //------------------------------------------------------------------ 1119 /// Currently called as part of ShouldStop. 1120 /// FIXME: Should really happen when the target stops before the 1121 /// event is taken from the queue... 1122 /// 1123 /// This callback is called as the event 1124 /// is about to be queued up to allow Process plug-ins to execute 1125 /// some code prior to clients being notified that a process was 1126 /// stopped. Common operations include updating the thread list, 1127 /// invalidating any thread state (registers, stack, etc) prior to 1128 /// letting the notification go out. 1129 /// 1130 //------------------------------------------------------------------ 1131 virtual void 1132 RefreshStateAfterStop () = 0; 1133 1134 //------------------------------------------------------------------ 1135 /// Get the target object pointer for this module. 1136 /// 1137 /// @return 1138 /// A Target object pointer to the target that owns this 1139 /// module. 1140 //------------------------------------------------------------------ 1141 Target & 1142 GetTarget (); 1143 1144 //------------------------------------------------------------------ 1145 /// Get the const target object pointer for this module. 1146 /// 1147 /// @return 1148 /// A const Target object pointer to the target that owns this 1149 /// module. 1150 //------------------------------------------------------------------ 1151 const Target & 1152 GetTarget () const; 1153 1154 //------------------------------------------------------------------ 1155 /// Get accessor for the current process state. 1156 /// 1157 /// @return 1158 /// The current state of the process. 1159 /// 1160 /// @see lldb::StateType 1161 //------------------------------------------------------------------ 1162 lldb::StateType 1163 GetState (); 1164 1165protected: 1166 friend class CommandObjectProcessLaunch; 1167 friend class ProcessEventData; 1168 friend class CommandObjectBreakpointCommand; 1169 1170 void 1171 SetState (lldb::EventSP &event_sp); 1172 1173 lldb::StateType 1174 GetPrivateState (); 1175 1176public: 1177 //------------------------------------------------------------------ 1178 /// Get the exit status for a process. 1179 /// 1180 /// @return 1181 /// The process's return code, or -1 if the current process 1182 /// state is not eStateExited. 1183 //------------------------------------------------------------------ 1184 int 1185 GetExitStatus (); 1186 1187 //------------------------------------------------------------------ 1188 /// Get a textual description of what the process exited. 1189 /// 1190 /// @return 1191 /// The textual description of why the process exited, or NULL 1192 /// if there is no description available. 1193 //------------------------------------------------------------------ 1194 const char * 1195 GetExitDescription (); 1196 1197 1198 virtual void 1199 DidExit () 1200 { 1201 } 1202 1203 //------------------------------------------------------------------ 1204 /// Get the number of times this process has posted a stop event. 1205 /// 1206 /// @return 1207 /// The number of times this process has stopped while being 1208 /// debugged. 1209 //------------------------------------------------------------------ 1210 uint32_t 1211 GetStopID () const; 1212 1213 //------------------------------------------------------------------ 1214 /// Set accessor for the process exit status (return code). 1215 /// 1216 /// Sometimes a child exits and the exit can be detected by global 1217 /// functions (signal handler for SIGCHLD for example). This 1218 /// accessor allows the exit status to be set from an external 1219 /// source. 1220 /// 1221 /// Setting this will cause a eStateExited event to be posted to 1222 /// the process event queue. 1223 /// 1224 /// @param[in] exit_status 1225 /// The value for the process's return code. 1226 /// 1227 /// @see lldb::StateType 1228 //------------------------------------------------------------------ 1229 virtual void 1230 SetExitStatus (int exit_status, const char *cstr); 1231 1232 //------------------------------------------------------------------ 1233 /// Check if a process is still alive. 1234 /// 1235 /// @return 1236 /// Returns \b true if the process is still valid, \b false 1237 /// otherwise. 1238 //------------------------------------------------------------------ 1239 virtual bool 1240 IsAlive () = 0; 1241 1242 //------------------------------------------------------------------ 1243 /// Actually do the reading of memory from a process. 1244 /// 1245 /// Subclasses must override this function and can return fewer 1246 /// bytes than requested when memory requests are too large. This 1247 /// class will break up the memory requests and keep advancing the 1248 /// arguments along as needed. 1249 /// 1250 /// @param[in] vm_addr 1251 /// A virtual load address that indicates where to start reading 1252 /// memory from. 1253 /// 1254 /// @param[in] size 1255 /// The number of bytes to read. 1256 /// 1257 /// @param[out] buf 1258 /// A byte buffer that is at least \a size bytes long that 1259 /// will receive the memory bytes. 1260 /// 1261 /// @return 1262 /// The number of bytes that were actually read into \a buf. 1263 //------------------------------------------------------------------ 1264 virtual size_t 1265 DoReadMemory (lldb::addr_t vm_addr, 1266 void *buf, 1267 size_t size, 1268 Error &error) = 0; 1269 1270 //------------------------------------------------------------------ 1271 /// Read of memory from a process. 1272 /// 1273 /// This function will read memory from the current process's 1274 /// address space and remove any traps that may have been inserted 1275 /// into the memory. 1276 /// 1277 /// This function is not meant to be overridden by Process 1278 /// subclasses, the subclasses should implement 1279 /// Process::DoReadMemory (lldb::addr_t, size_t, void *). 1280 /// 1281 /// @param[in] vm_addr 1282 /// A virtual load address that indicates where to start reading 1283 /// memory from. 1284 /// 1285 /// @param[out] buf 1286 /// A byte buffer that is at least \a size bytes long that 1287 /// will receive the memory bytes. 1288 /// 1289 /// @param[in] size 1290 /// The number of bytes to read. 1291 /// 1292 /// @return 1293 /// The number of bytes that were actually read into \a buf. If 1294 /// the returned number is greater than zero, yet less than \a 1295 /// size, then this function will get called again with \a 1296 /// vm_addr, \a buf, and \a size updated appropriately. Zero is 1297 /// returned to indicate an error. 1298 //------------------------------------------------------------------ 1299 size_t 1300 ReadMemory (lldb::addr_t vm_addr, 1301 void *buf, 1302 size_t size, 1303 Error &error); 1304 1305 //------------------------------------------------------------------ 1306 /// Actually do the writing of memory to a process. 1307 /// 1308 /// @param[in] vm_addr 1309 /// A virtual load address that indicates where to start writing 1310 /// memory to. 1311 /// 1312 /// @param[in] buf 1313 /// A byte buffer that is at least \a size bytes long that 1314 /// contains the data to write. 1315 /// 1316 /// @param[in] size 1317 /// The number of bytes to write. 1318 /// 1319 /// @return 1320 /// The number of bytes that were actually written. 1321 //------------------------------------------------------------------ 1322 virtual size_t 1323 DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) = 0; 1324 1325 //------------------------------------------------------------------ 1326 /// Write memory to a process. 1327 /// 1328 /// This function will write memory to the current process's 1329 /// address space and maintain any traps that might be present due 1330 /// to software breakpoints. 1331 /// 1332 /// This function is not meant to be overridden by Process 1333 /// subclasses, the subclasses should implement 1334 /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). 1335 /// 1336 /// @param[in] vm_addr 1337 /// A virtual load address that indicates where to start writing 1338 /// memory to. 1339 /// 1340 /// @param[in] buf 1341 /// A byte buffer that is at least \a size bytes long that 1342 /// contains the data to write. 1343 /// 1344 /// @param[in] size 1345 /// The number of bytes to write. 1346 /// 1347 /// @return 1348 /// The number of bytes that were actually written. 1349 //------------------------------------------------------------------ 1350 size_t 1351 WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); 1352 1353 1354 //------------------------------------------------------------------ 1355 /// Actually allocate memory in the process. 1356 /// 1357 /// This function will allocate memory in the process's address 1358 /// space. This can't rely on the generic function calling mechanism, 1359 /// since that requires this function. 1360 /// 1361 /// @param[in] size 1362 /// The size of the allocation requested. 1363 /// 1364 /// @return 1365 /// The address of the allocated buffer in the process, or 1366 /// LLDB_INVALID_ADDRESS if the allocation failed. 1367 //------------------------------------------------------------------ 1368 1369 virtual lldb::addr_t 1370 DoAllocateMemory (size_t size, uint32_t permissions, Error &error) = 0; 1371 1372 //------------------------------------------------------------------ 1373 /// The public interface to allocating memory in the process. 1374 /// 1375 /// This function will allocate memory in the process's address 1376 /// space. This can't rely on the generic function calling mechanism, 1377 /// since that requires this function. 1378 /// 1379 /// @param[in] size 1380 /// The size of the allocation requested. 1381 /// 1382 /// @param[in] permissions 1383 /// Or together any of the lldb::Permissions bits. The permissions on 1384 /// a given memory allocation can't be changed after allocation. Note 1385 /// that a block that isn't set writable can still be written on from lldb, 1386 /// just not by the process itself. 1387 /// 1388 /// @return 1389 /// The address of the allocated buffer in the process, or 1390 /// LLDB_INVALID_ADDRESS if the allocation failed. 1391 //------------------------------------------------------------------ 1392 1393 lldb::addr_t 1394 AllocateMemory (size_t size, uint32_t permissions, Error &error); 1395 1396 //------------------------------------------------------------------ 1397 /// Actually deallocate memory in the process. 1398 /// 1399 /// This function will deallocate memory in the process's address 1400 /// space that was allocated with AllocateMemory. 1401 /// 1402 /// @param[in] ptr 1403 /// A return value from AllocateMemory, pointing to the memory you 1404 /// want to deallocate. 1405 /// 1406 /// @return 1407 /// \btrue if the memory was deallocated, \bfalse otherwise. 1408 //------------------------------------------------------------------ 1409 1410 virtual Error 1411 DoDeallocateMemory (lldb::addr_t ptr) = 0; 1412 1413 //------------------------------------------------------------------ 1414 /// The public interface to deallocating memory in the process. 1415 /// 1416 /// This function will deallocate memory in the process's address 1417 /// space that was allocated with AllocateMemory. 1418 /// 1419 /// @param[in] ptr 1420 /// A return value from AllocateMemory, pointing to the memory you 1421 /// want to deallocate. 1422 /// 1423 /// @return 1424 /// \btrue if the memory was deallocated, \bfalse otherwise. 1425 //------------------------------------------------------------------ 1426 1427 Error 1428 DeallocateMemory (lldb::addr_t ptr); 1429 1430 //------------------------------------------------------------------ 1431 /// Get any available STDOUT. 1432 /// 1433 /// If the process was launched without supplying valid file paths 1434 /// for stdin, stdout, and stderr, then the Process class might 1435 /// try to cache the STDOUT for the process if it is able. Events 1436 /// will be queued indicating that there is STDOUT available that 1437 /// can be retrieved using this function. 1438 /// 1439 /// @param[out] buf 1440 /// A buffer that will receive any STDOUT bytes that are 1441 /// currently available. 1442 /// 1443 /// @param[out] buf_size 1444 /// The size in bytes for the buffer \a buf. 1445 /// 1446 /// @return 1447 /// The number of bytes written into \a buf. If this value is 1448 /// equal to \a buf_size, another call to this function should 1449 /// be made to retrieve more STDOUT data. 1450 //------------------------------------------------------------------ 1451 virtual size_t 1452 GetSTDOUT (char *buf, size_t buf_size, Error &error) 1453 { 1454 error.SetErrorString("stdout unsupported"); 1455 return 0; 1456 } 1457 1458 1459 //------------------------------------------------------------------ 1460 /// Get any available STDERR. 1461 /// 1462 /// If the process was launched without supplying valid file paths 1463 /// for stdin, stdout, and stderr, then the Process class might 1464 /// try to cache the STDERR for the process if it is able. Events 1465 /// will be queued indicating that there is STDERR available that 1466 /// can be retrieved using this function. 1467 /// 1468 /// @param[out] buf 1469 /// A buffer that will receive any STDERR bytes that are 1470 /// currently available. 1471 /// 1472 /// @param[out] buf_size 1473 /// The size in bytes for the buffer \a buf. 1474 /// 1475 /// @return 1476 /// The number of bytes written into \a buf. If this value is 1477 /// equal to \a buf_size, another call to this function should 1478 /// be made to retrieve more STDERR data. 1479 //------------------------------------------------------------------ 1480 virtual size_t 1481 GetSTDERR (char *buf, size_t buf_size, Error &error) 1482 { 1483 error.SetErrorString("stderr unsupported"); 1484 return 0; 1485 } 1486 1487 virtual size_t 1488 PutSTDIN (const char *buf, size_t buf_size, Error &error) 1489 { 1490 error.SetErrorString("stdin unsupported"); 1491 return 0; 1492 } 1493 1494 //---------------------------------------------------------------------- 1495 // Process Breakpoints 1496 //---------------------------------------------------------------------- 1497 virtual size_t 1498 GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) = 0; 1499 1500 virtual Error 1501 EnableBreakpoint (BreakpointSite *bp_site) = 0; 1502 1503 virtual Error 1504 DisableBreakpoint (BreakpointSite *bp_site) = 0; 1505 1506 // This is implemented completely using the lldb::Process API. Subclasses 1507 // don't need to implement this function unless the standard flow of 1508 // read existing opcode, write breakpoint opcode, verify breakpoint opcode 1509 // doesn't work for a specific process plug-in. 1510 virtual Error 1511 EnableSoftwareBreakpoint (BreakpointSite *bp_site); 1512 1513 // This is implemented completely using the lldb::Process API. Subclasses 1514 // don't need to implement this function unless the standard flow of 1515 // restoring original opcode in memory and verifying the restored opcode 1516 // doesn't work for a specific process plug-in. 1517 virtual Error 1518 DisableSoftwareBreakpoint (BreakpointSite *bp_site); 1519 1520 BreakpointSiteList & 1521 GetBreakpointSiteList(); 1522 1523 const BreakpointSiteList & 1524 GetBreakpointSiteList() const; 1525 1526 void 1527 DisableAllBreakpointSites (); 1528 1529 Error 1530 ClearBreakpointSiteByID (lldb::user_id_t break_id); 1531 1532 lldb::break_id_t 1533 CreateBreakpointSite (lldb::BreakpointLocationSP &owner, 1534 bool use_hardware); 1535 1536 Error 1537 DisableBreakpointSiteByID (lldb::user_id_t break_id); 1538 1539 Error 1540 EnableBreakpointSiteByID (lldb::user_id_t break_id); 1541 1542 1543 // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove 1544 // themselves from the owner's list of this breakpoint sites. This has to 1545 // be a static function because you can't be sure that removing the 1546 // breakpoint from it's containing map won't delete the breakpoint site, 1547 // and doing that in an instance method isn't copasetic. 1548 void 1549 RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, 1550 lldb::user_id_t owner_loc_id, 1551 lldb::BreakpointSiteSP &bp_site_sp); 1552 1553 //---------------------------------------------------------------------- 1554 // Process Watchpoints (optional) 1555 //---------------------------------------------------------------------- 1556 virtual Error 1557 EnableWatchpoint (WatchpointLocation *bp_loc); 1558 1559 virtual Error 1560 DisableWatchpoint (WatchpointLocation *bp_loc); 1561 1562 //------------------------------------------------------------------ 1563 // Thread Queries 1564 //------------------------------------------------------------------ 1565 virtual uint32_t 1566 UpdateThreadListIfNeeded () = 0; 1567 1568 ThreadList & 1569 GetThreadList (); 1570 1571 const ThreadList & 1572 GetThreadList () const; 1573 1574 uint32_t 1575 GetNextThreadIndexID (); 1576 1577 //------------------------------------------------------------------ 1578 // Event Handling 1579 //------------------------------------------------------------------ 1580 lldb::StateType 1581 GetNextEvent (lldb::EventSP &event_sp); 1582 1583 lldb::StateType 1584 WaitForProcessToStop (const TimeValue *timeout); 1585 1586 lldb::StateType 1587 WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp); 1588 1589 Event * 1590 PeekAtStateChangedEvents (); 1591 1592 1593 //------------------------------------------------------------------ 1594 /// If you need to ensure that you and only you will hear about some public 1595 /// event, then make a new listener, set to listen to process events, and 1596 /// then call this with that listener. Then you will have to wait on that 1597 /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* 1598 /// calls above. Be sure to call RestoreProcessEvents when you are done. 1599 /// 1600 /// @param[in] listener 1601 /// This is the new listener to whom all process events will be delivered. 1602 /// 1603 /// @return 1604 /// Returns \b true if the new listener could be installed, 1605 /// \b false otherwise. 1606 //------------------------------------------------------------------ 1607 bool 1608 HijackProcessEvents (Listener *listener); 1609 1610 //------------------------------------------------------------------ 1611 /// Restores the process event broadcasting to its normal state. 1612 /// 1613 //------------------------------------------------------------------ 1614 void 1615 RestoreProcessEvents (); 1616 1617protected: 1618 //------------------------------------------------------------------ 1619 /// This is the part of the event handling that for a process event. 1620 /// It decides what to do with the event and returns true if the 1621 /// event needs to be propagated to the user, and false otherwise. 1622 /// If the event is not propagated, this call will most likely set 1623 /// the target to executing again. 1624 /// 1625 /// @param[in] event_ptr 1626 /// This is the event we are handling. 1627 /// 1628 /// @return 1629 /// Returns \b true if the event should be reported to the 1630 /// user, \b false otherwise. 1631 //------------------------------------------------------------------ 1632 bool 1633 ShouldBroadcastEvent (Event *event_ptr); 1634 1635public: 1636 //------------------------------------------------------------------ 1637 /// Gets the byte order for this process. 1638 /// 1639 /// @return 1640 /// A valid ByteOrder enumeration, or eByteOrderInvalid. 1641 //------------------------------------------------------------------ 1642 lldb::ByteOrder 1643 GetByteOrder () const 1644 { 1645 return m_byte_order; 1646 } 1647 1648 void 1649 SetByteOrder (lldb::ByteOrder byte_order) 1650 { 1651 m_byte_order = byte_order; 1652 } 1653 1654 const ConstString & 1655 GetTargetTriple () 1656 { 1657 return m_target_triple; 1658 } 1659 1660 const ABI * 1661 GetABI (); 1662 1663 virtual DynamicLoader * 1664 GetDynamicLoader (); 1665 1666 virtual LanguageRuntime * 1667 GetLanguageRuntime (lldb::LanguageType language); 1668 1669 virtual CPPLanguageRuntime * 1670 GetCPPLanguageRuntime (); 1671 1672 virtual ObjCLanguageRuntime * 1673 GetObjCLanguageRuntime (); 1674 1675 bool 1676 IsRunning () const; 1677 1678 DynamicCheckerFunctions *GetDynamicCheckers() 1679 { 1680 return m_dynamic_checkers_ap.get(); 1681 } 1682 1683 void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) 1684 { 1685 m_dynamic_checkers_ap.reset(dynamic_checkers); 1686 } 1687 1688 //------------------------------------------------------------------ 1689 // lldb::ExecutionContextScope pure virtual functions 1690 //------------------------------------------------------------------ 1691 virtual Target * 1692 CalculateTarget (); 1693 1694 virtual Process * 1695 CalculateProcess (); 1696 1697 virtual Thread * 1698 CalculateThread (); 1699 1700 virtual StackFrame * 1701 CalculateStackFrame (); 1702 1703 virtual void 1704 CalculateExecutionContext (ExecutionContext &exe_ctx); 1705 1706 lldb::ProcessSP 1707 GetSP (); 1708 1709 ClangPersistentVariables & 1710 GetPersistentVariables(); 1711 1712protected: 1713 //------------------------------------------------------------------ 1714 // Member variables 1715 //------------------------------------------------------------------ 1716 Target & m_target; ///< The target that owns this process. 1717 ThreadSafeValue<lldb::StateType> m_public_state; 1718 ThreadSafeValue<lldb::StateType> m_private_state; // The actual state of our process 1719 Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. 1720 Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. 1721 Listener m_private_state_listener; // This is the listener for the private state thread. 1722 Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. 1723 lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events 1724 uint32_t m_stop_id; ///< A count of many times the process has stopped. 1725 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. 1726 int m_exit_status; ///< The exit status of the process, or -1 if not set. 1727 std::string m_exit_string; ///< A textual description of why a process exited. 1728 ThreadList m_thread_list; ///< The threads for this process. 1729 std::vector<Notifications> m_notifications; ///< The list of notifications that this process can deliver. 1730 std::vector<lldb::addr_t> m_image_tokens; 1731 Listener &m_listener; 1732 BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend 1733 ///< to insert in the target. 1734 ClangPersistentVariables m_persistent_vars; ///< These are the persistent variables associated with this process for the expression parser. 1735 std::auto_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. 1736 UnixSignals m_unix_signals; /// This is the current signal set for this process. 1737 ConstString m_target_triple; 1738 lldb::ByteOrder m_byte_order; /// The byte order of the process. Should be set in DidLaunch/DidAttach. 1739 uint32_t m_addr_byte_size; /// The size in bytes of an address/pointer for the inferior process. Should be set in DidLaunch/DidAttach. 1740 lldb::ABISP m_abi_sp; 1741 lldb::InputReaderSP m_process_input_reader; 1742 lldb_private::Communication m_stdio_communication; 1743 lldb_private::Mutex m_stdio_communication_mutex; 1744 std::string m_stdout_data; 1745 1746 typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection; 1747 LanguageRuntimeCollection m_language_runtimes; 1748 1749 size_t 1750 RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; 1751 1752 void 1753 SynchronouslyNotifyStateChanged (lldb::StateType state); 1754 1755 void 1756 SetPublicState (lldb::StateType new_state); 1757 1758 void 1759 SetPrivateState (lldb::StateType state); 1760 1761 bool 1762 StartPrivateStateThread (); 1763 1764 void 1765 StopPrivateStateThread (); 1766 1767 void 1768 PausePrivateStateThread (); 1769 1770 void 1771 ResumePrivateStateThread (); 1772 1773 static void * 1774 PrivateStateThread (void *arg); 1775 1776 void * 1777 RunPrivateStateThread (); 1778 1779 void 1780 HandlePrivateEvent (lldb::EventSP &event_sp); 1781 1782 lldb::StateType 1783 WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 1784 1785 Error 1786 CompleteAttach (); 1787 1788 1789 // This waits for both the state change broadcaster, and the control broadcaster. 1790 // If control_only, it only waits for the control broadcaster. 1791 1792 bool 1793 WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); 1794 1795 lldb::StateType 1796 WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 1797 1798 lldb::StateType 1799 WaitForState (const TimeValue *timeout, 1800 const lldb::StateType *match_states, 1801 const uint32_t num_match_states); 1802 1803 size_t 1804 WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); 1805 1806 void 1807 AppendSTDOUT (const char *s, size_t len); 1808 1809 static void 1810 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); 1811 1812 void 1813 PushProcessInputReader (); 1814 1815 void 1816 PopProcessInputReader (); 1817 1818 void 1819 ResetProcessInputReader (); 1820 1821 void 1822 SetUpProcessInputReader (int file_descriptor); 1823 1824 static size_t 1825 ProcessInputReaderCallback (void *baton, 1826 InputReader &reader, 1827 lldb::InputReaderAction notification, 1828 const char *bytes, 1829 size_t bytes_len); 1830 1831 1832private: 1833 //------------------------------------------------------------------ 1834 // For Process only 1835 //------------------------------------------------------------------ 1836 void ControlPrivateStateThread (uint32_t signal); 1837 1838 DISALLOW_COPY_AND_ASSIGN (Process); 1839 1840}; 1841 1842} // namespace lldb_private 1843 1844#endif // liblldb_Process_h_ 1845