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