Process.h revision e71e258286a1713dbb2d366d8b81ff2f28e0216f
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 /// @param[in] working_directory 544 /// The working directory to have the child process run in 545 /// 546 /// @return 547 /// An error object. Call GetID() to get the process ID if 548 /// the error object is success. 549 //------------------------------------------------------------------ 550 virtual Error 551 Launch (char const *argv[], 552 char const *envp[], 553 uint32_t launch_flags, 554 const char *stdin_path, 555 const char *stdout_path, 556 const char *stderr_path, 557 const char *working_directory); 558 559 //------------------------------------------------------------------ 560 /// Attach to an existing process using a process ID. 561 /// 562 /// This function is not meant to be overridden by Process 563 /// subclasses. It will first call Process::WillAttach (lldb::pid_t) 564 /// and if that returns \b true, Process::DoAttach (lldb::pid_t) will 565 /// be called to actually do the attach. If DoAttach returns \b 566 /// true, then Process::DidAttach() will be called. 567 /// 568 /// @param[in] pid 569 /// The process ID that we should attempt to attach to. 570 /// 571 /// @return 572 /// Returns \a pid if attaching was successful, or 573 /// LLDB_INVALID_PROCESS_ID if attaching fails. 574 //------------------------------------------------------------------ 575 virtual Error 576 Attach (lldb::pid_t pid); 577 578 //------------------------------------------------------------------ 579 /// Attach to an existing process by process name. 580 /// 581 /// This function is not meant to be overridden by Process 582 /// subclasses. It will first call 583 /// Process::WillAttach (const char *) and if that returns \b 584 /// true, Process::DoAttach (const char *) will be called to 585 /// actually do the attach. If DoAttach returns \b true, then 586 /// Process::DidAttach() will be called. 587 /// 588 /// @param[in] process_name 589 /// A process name to match against the current process list. 590 /// 591 /// @return 592 /// Returns \a pid if attaching was successful, or 593 /// LLDB_INVALID_PROCESS_ID if attaching fails. 594 //------------------------------------------------------------------ 595 virtual Error 596 Attach (const char *process_name, bool wait_for_launch); 597 598 virtual Error 599 ConnectRemote (const char *remote_url); 600 //------------------------------------------------------------------ 601 /// List the processes matching the given partial name. 602 /// 603 /// FIXME: Is it too heavyweight to create an entire process object to do this? 604 /// The problem is for remote processes we're going to have to set up the same transport 605 /// to get this data as to actually attach. So we need to factor out transport 606 /// and process before we can do this separately from the process. 607 /// 608 /// @param[in] name 609 /// A partial name to match against the current process list. 610 /// 611 /// @param[out] matches 612 /// The list of process names matching \a name. 613 /// 614 /// @param[in] pids 615 /// A vector filled with the pids that correspond to the names in \a matches. 616 /// 617 /// @return 618 /// Returns the number of matching processes. 619 //------------------------------------------------------------------ 620 621 virtual uint32_t 622 ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids); 623 624 //------------------------------------------------------------------ 625 /// Find the architecture of a process by pid. 626 /// 627 /// FIXME: See comment for ListProcessesMatchingName. 628 /// 629 /// @param[in] pid 630 /// A pid to inspect. 631 /// 632 /// @return 633 /// Returns the architecture of the process or an invalid architecture if the process can't be found. 634 //------------------------------------------------------------------ 635 virtual ArchSpec 636 GetArchSpecForExistingProcess (lldb::pid_t pid); 637 638 //------------------------------------------------------------------ 639 /// Find the architecture of a process by name. 640 /// 641 /// FIXME: See comment for ListProcessesMatchingName. 642 /// 643 /// @param[in] process_name 644 /// The process name to inspect. 645 /// 646 /// @return 647 /// Returns the architecture of the process or an invalid architecture if the process can't be found. 648 //------------------------------------------------------------------ 649 virtual ArchSpec 650 GetArchSpecForExistingProcess (const char *process_name); 651 652 uint32_t 653 GetAddressByteSize(); 654 655 void 656 SetAddressByteSize (uint32_t addr_byte_size) 657 { 658 m_addr_byte_size = addr_byte_size; 659 } 660 661 //------------------------------------------------------------------ 662 /// Get the image information address for the current process. 663 /// 664 /// Some runtimes have system functions that can help dynamic 665 /// loaders locate the dynamic loader information needed to observe 666 /// shared libraries being loaded or unloaded. This function is 667 /// in the Process interface (as opposed to the DynamicLoader 668 /// interface) to ensure that remote debugging can take advantage of 669 /// this functionality. 670 /// 671 /// @return 672 /// The address of the dynamic loader information, or 673 /// LLDB_INVALID_ADDRESS if this is not supported by this 674 /// interface. 675 //------------------------------------------------------------------ 676 virtual lldb::addr_t 677 GetImageInfoAddress (); 678 679 //------------------------------------------------------------------ 680 /// Load a shared library into this process. 681 /// 682 /// Try and load a shared library into the current process. This 683 /// call might fail in the dynamic loader plug-in says it isn't safe 684 /// to try and load shared libraries at the moment. 685 /// 686 /// @param[in] image_spec 687 /// The image file spec that points to the shared library that 688 /// you want to load. 689 /// 690 /// @param[out] error 691 /// An error object that gets filled in with any errors that 692 /// might occur when trying to load the shared library. 693 /// 694 /// @return 695 /// A token that represents the shared library that can be 696 /// later used to unload the shared library. A value of 697 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 698 /// library can't be opened. 699 //------------------------------------------------------------------ 700 virtual uint32_t 701 LoadImage (const FileSpec &image_spec, Error &error); 702 703 virtual Error 704 UnloadImage (uint32_t image_token); 705 706 //------------------------------------------------------------------ 707 /// Register for process and thread notifications. 708 /// 709 /// Clients can register nofication callbacks by filling out a 710 /// Process::Notifications structure and calling this function. 711 /// 712 /// @param[in] callbacks 713 /// A structure that contains the notification baton and 714 /// callback functions. 715 /// 716 /// @see Process::Notifications 717 //------------------------------------------------------------------ 718#ifndef SWIG 719 void 720 RegisterNotificationCallbacks (const Process::Notifications& callbacks); 721#endif 722 //------------------------------------------------------------------ 723 /// Unregister for process and thread notifications. 724 /// 725 /// Clients can unregister nofication callbacks by passing a copy of 726 /// the original baton and callbacks in \a callbacks. 727 /// 728 /// @param[in] callbacks 729 /// A structure that contains the notification baton and 730 /// callback functions. 731 /// 732 /// @return 733 /// Returns \b true if the notification callbacks were 734 /// successfully removed from the process, \b false otherwise. 735 /// 736 /// @see Process::Notifications 737 //------------------------------------------------------------------ 738#ifndef SWIG 739 bool 740 UnregisterNotificationCallbacks (const Process::Notifications& callbacks); 741#endif 742 //================================================================== 743 // Built in Process Control functions 744 //================================================================== 745 //------------------------------------------------------------------ 746 /// Resumes all of a process's threads as configured using the 747 /// Thread run control functions. 748 /// 749 /// Threads for a process should be updated with one of the run 750 /// control actions (resume, step, or suspend) that they should take 751 /// when the process is resumed. If no run control action is given 752 /// to a thread it will be resumed by default. 753 /// 754 /// This function is not meant to be overridden by Process 755 /// subclasses. This function will take care of disabling any 756 /// breakpoints that threads may be stopped at, single stepping, and 757 /// re-enabling breakpoints, and enabling the basic flow control 758 /// that the plug-in instances need not worry about. 759 /// 760 /// @return 761 /// Returns an error object. 762 /// 763 /// @see Thread:Resume() 764 /// @see Thread:Step() 765 /// @see Thread:Suspend() 766 //------------------------------------------------------------------ 767 Error 768 Resume (); 769 770 //------------------------------------------------------------------ 771 /// Halts a running process. 772 /// 773 /// This function is not meant to be overridden by Process 774 /// subclasses. 775 /// If the process is successfully halted, a eStateStopped 776 /// process event with GetInterrupted will be broadcast. If false, we will 777 /// halt the process with no events generated by the halt. 778 /// 779 /// @return 780 /// Returns an error object. If the error is empty, the process is halted. 781 /// otherwise the halt has failed. 782 //------------------------------------------------------------------ 783 Error 784 Halt (); 785 786 //------------------------------------------------------------------ 787 /// Detaches from a running or stopped process. 788 /// 789 /// This function is not meant to be overridden by Process 790 /// subclasses. 791 /// 792 /// @return 793 /// Returns an error object. 794 //------------------------------------------------------------------ 795 Error 796 Detach (); 797 798 //------------------------------------------------------------------ 799 /// Kills the process and shuts down all threads that were spawned 800 /// to track and monitor the process. 801 /// 802 /// This function is not meant to be overridden by Process 803 /// subclasses. 804 /// 805 /// @return 806 /// Returns an error object. 807 //------------------------------------------------------------------ 808 Error 809 Destroy(); 810 811 //------------------------------------------------------------------ 812 /// Sends a process a UNIX signal \a signal. 813 /// 814 /// This function is not meant to be overridden by Process 815 /// subclasses. 816 /// 817 /// @return 818 /// Returns an error object. 819 //------------------------------------------------------------------ 820 Error 821 Signal (int signal); 822 823 virtual UnixSignals & 824 GetUnixSignals (); 825 826 827 //================================================================== 828 // Plug-in Process Control Overrides 829 //================================================================== 830 831 //------------------------------------------------------------------ 832 /// Called before attaching to a process. 833 /// 834 /// Allow Process plug-ins to execute some code before attaching a 835 /// process. 836 /// 837 /// @return 838 /// Returns an error object. 839 //------------------------------------------------------------------ 840 virtual Error 841 WillAttachToProcessWithID (lldb::pid_t pid) 842 { 843 return Error(); 844 } 845 846 //------------------------------------------------------------------ 847 /// Called before attaching to a process. 848 /// 849 /// Allow Process plug-ins to execute some code before attaching a 850 /// process. 851 /// 852 /// @return 853 /// Returns an error object. 854 //------------------------------------------------------------------ 855 virtual Error 856 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) 857 { 858 return Error(); 859 } 860 861 virtual Error 862 DoConnectRemote (const char *remote_url) 863 { 864 Error error; 865 error.SetErrorString ("remote connections are not supported"); 866 return error; 867 } 868 869 //------------------------------------------------------------------ 870 /// Attach to an existing process using a process ID. 871 /// 872 /// @param[in] pid 873 /// The process ID that we should attempt to attach to. 874 /// 875 /// @return 876 /// Returns \a pid if attaching was successful, or 877 /// LLDB_INVALID_PROCESS_ID if attaching fails. 878 //------------------------------------------------------------------ 879 virtual Error 880 DoAttachToProcessWithID (lldb::pid_t pid) = 0; 881 882 //------------------------------------------------------------------ 883 /// Attach to an existing process using a partial process name. 884 /// 885 /// @param[in] process_name 886 /// The name of the process to attach to. 887 /// 888 /// @param[in] wait_for_launch 889 /// If \b true, wait for the process to be launched and attach 890 /// as soon as possible after it does launch. If \b false, then 891 /// search for a matching process the currently exists. 892 /// 893 /// @return 894 /// Returns \a pid if attaching was successful, or 895 /// LLDB_INVALID_PROCESS_ID if attaching fails. 896 //------------------------------------------------------------------ 897 virtual Error 898 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch) 899 { 900 Error error; 901 error.SetErrorString("attach by name is not supported"); 902 return error; 903 } 904 905 //------------------------------------------------------------------ 906 /// Called after attaching a process. 907 /// 908 /// Allow Process plug-ins to execute some code after attaching to 909 /// a process. 910 //------------------------------------------------------------------ 911 virtual void 912 DidAttach () {} 913 914 915 //------------------------------------------------------------------ 916 /// Called before launching to a process. 917 /// 918 /// Allow Process plug-ins to execute some code before launching a 919 /// process. 920 /// 921 /// @return 922 /// Returns an error object. 923 //------------------------------------------------------------------ 924 virtual Error 925 WillLaunch (Module* module) 926 { 927 return Error(); 928 } 929 930 //------------------------------------------------------------------ 931 /// Launch a new process. 932 /// 933 /// Launch a new process by spawning a new process using \a module's 934 /// file as the file to launch. Arguments are given in \a argv, 935 /// and the environment variables are in \a envp. Standard input 936 /// and output files can be optionally re-directed to \a stdin_path, 937 /// \a stdout_path, and \a stderr_path. 938 /// 939 /// @param[in] module 940 /// The module from which to extract the file specification and 941 /// launch. 942 /// 943 /// @param[in] argv 944 /// The argument array. 945 /// 946 /// @param[in] envp 947 /// The environment array. 948 /// 949 /// @param[in] launch_flags 950 /// Flags to modify the launch (@see lldb::LaunchFlags) 951 /// 952 /// @param[in] stdin_path 953 /// The path to use when re-directing the STDIN of the new 954 /// process. If all stdXX_path arguments are NULL, a pseudo 955 /// terminal will be used. 956 /// 957 /// @param[in] stdout_path 958 /// The path to use when re-directing the STDOUT of the new 959 /// process. If all stdXX_path arguments are NULL, a pseudo 960 /// terminal will be used. 961 /// 962 /// @param[in] stderr_path 963 /// The path to use when re-directing the STDERR of the new 964 /// process. If all stdXX_path arguments are NULL, a pseudo 965 /// terminal will be used. 966 /// 967 /// @param[in] working_directory 968 /// The working directory to have the child process run in 969 /// 970 /// @return 971 /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if 972 /// launching fails. 973 //------------------------------------------------------------------ 974 virtual Error 975 DoLaunch (Module* module, 976 char const *argv[], 977 char const *envp[], 978 uint32_t launch_flags, 979 const char *stdin_path, 980 const char *stdout_path, 981 const char *stderr_path, 982 const char *working_directory) = 0; 983 984 //------------------------------------------------------------------ 985 /// Called after launching a process. 986 /// 987 /// Allow Process plug-ins to execute some code after launching 988 /// a process. 989 //------------------------------------------------------------------ 990 virtual void 991 DidLaunch () {} 992 993 994 995 //------------------------------------------------------------------ 996 /// Called before resuming to a process. 997 /// 998 /// Allow Process plug-ins to execute some code before resuming a 999 /// process. 1000 /// 1001 /// @return 1002 /// Returns an error object. 1003 //------------------------------------------------------------------ 1004 virtual Error 1005 WillResume () { return Error(); } 1006 1007 //------------------------------------------------------------------ 1008 /// Resumes all of a process's threads as configured using the 1009 /// Thread run control functions. 1010 /// 1011 /// Threads for a process should be updated with one of the run 1012 /// control actions (resume, step, or suspend) that they should take 1013 /// when the process is resumed. If no run control action is given 1014 /// to a thread it will be resumed by default. 1015 /// 1016 /// @return 1017 /// Returns \b true if the process successfully resumes using 1018 /// the thread run control actions, \b false otherwise. 1019 /// 1020 /// @see Thread:Resume() 1021 /// @see Thread:Step() 1022 /// @see Thread:Suspend() 1023 //------------------------------------------------------------------ 1024 virtual Error 1025 DoResume () = 0; 1026 1027 //------------------------------------------------------------------ 1028 /// Called after resuming a process. 1029 /// 1030 /// Allow Process plug-ins to execute some code after resuming 1031 /// a process. 1032 //------------------------------------------------------------------ 1033 virtual void 1034 DidResume () {} 1035 1036 1037 //------------------------------------------------------------------ 1038 /// Called before halting to a process. 1039 /// 1040 /// Allow Process plug-ins to execute some code before halting a 1041 /// process. 1042 /// 1043 /// @return 1044 /// Returns an error object. 1045 //------------------------------------------------------------------ 1046 virtual Error 1047 WillHalt () { return Error(); } 1048 1049 //------------------------------------------------------------------ 1050 /// Halts a running process. 1051 /// 1052 /// DoHalt must produce one and only one stop StateChanged event if it actually 1053 /// stops the process. If the stop happens through some natural event (for 1054 /// instance a SIGSTOP), then forwarding that event will do. Otherwise, you must 1055 /// generate the event manually. Note also, the private event thread is stopped when 1056 /// DoHalt is run to prevent the events generated while halting to trigger 1057 /// other state changes before the halt is complete. 1058 /// 1059 /// @param[out] caused_stop 1060 /// If true, then this Halt caused the stop, otherwise, the 1061 /// process was already stopped. 1062 /// 1063 /// @return 1064 /// Returns \b true if the process successfully halts, \b false 1065 /// otherwise. 1066 //------------------------------------------------------------------ 1067 virtual Error 1068 DoHalt (bool &caused_stop) = 0; 1069 1070 //------------------------------------------------------------------ 1071 /// Called after halting a process. 1072 /// 1073 /// Allow Process plug-ins to execute some code after halting 1074 /// a process. 1075 //------------------------------------------------------------------ 1076 virtual void 1077 DidHalt () {} 1078 1079 //------------------------------------------------------------------ 1080 /// Called before detaching from a process. 1081 /// 1082 /// Allow Process plug-ins to execute some code before detaching 1083 /// from a process. 1084 /// 1085 /// @return 1086 /// Returns an error object. 1087 //------------------------------------------------------------------ 1088 virtual Error 1089 WillDetach () 1090 { 1091 return Error(); 1092 } 1093 1094 //------------------------------------------------------------------ 1095 /// Detaches from a running or stopped process. 1096 /// 1097 /// @return 1098 /// Returns \b true if the process successfully detaches, \b 1099 /// false otherwise. 1100 //------------------------------------------------------------------ 1101 virtual Error 1102 DoDetach () = 0; 1103 1104 //------------------------------------------------------------------ 1105 /// Called after detaching from a process. 1106 /// 1107 /// Allow Process plug-ins to execute some code after detaching 1108 /// from a process. 1109 //------------------------------------------------------------------ 1110 virtual void 1111 DidDetach () {} 1112 1113 //------------------------------------------------------------------ 1114 /// Called before sending a signal to a process. 1115 /// 1116 /// Allow Process plug-ins to execute some code before sending a 1117 /// signal to a process. 1118 /// 1119 /// @return 1120 /// Returns no error if it is safe to proceed with a call to 1121 /// Process::DoSignal(int), otherwise an error describing what 1122 /// prevents the signal from being sent. 1123 //------------------------------------------------------------------ 1124 virtual Error 1125 WillSignal () { return Error(); } 1126 1127 //------------------------------------------------------------------ 1128 /// Sends a process a UNIX signal \a signal. 1129 /// 1130 /// @return 1131 /// Returns an error object. 1132 //------------------------------------------------------------------ 1133 virtual Error 1134 DoSignal (int signal) = 0; 1135 1136 1137 1138 virtual Error 1139 WillDestroy () { return Error(); } 1140 1141 virtual Error 1142 DoDestroy () = 0; 1143 1144 virtual void 1145 DidDestroy () { } 1146 1147 1148 //------------------------------------------------------------------ 1149 /// Called after sending a signal to a process. 1150 /// 1151 /// Allow Process plug-ins to execute some code after sending a 1152 /// signal to a process. 1153 //------------------------------------------------------------------ 1154 virtual void 1155 DidSignal () {} 1156 1157 1158 //------------------------------------------------------------------ 1159 /// Currently called as part of ShouldStop. 1160 /// FIXME: Should really happen when the target stops before the 1161 /// event is taken from the queue... 1162 /// 1163 /// This callback is called as the event 1164 /// is about to be queued up to allow Process plug-ins to execute 1165 /// some code prior to clients being notified that a process was 1166 /// stopped. Common operations include updating the thread list, 1167 /// invalidating any thread state (registers, stack, etc) prior to 1168 /// letting the notification go out. 1169 /// 1170 //------------------------------------------------------------------ 1171 virtual void 1172 RefreshStateAfterStop () = 0; 1173 1174 //------------------------------------------------------------------ 1175 /// Get the target object pointer for this module. 1176 /// 1177 /// @return 1178 /// A Target object pointer to the target that owns this 1179 /// module. 1180 //------------------------------------------------------------------ 1181 Target & 1182 GetTarget (); 1183 1184 //------------------------------------------------------------------ 1185 /// Get the const target object pointer for this module. 1186 /// 1187 /// @return 1188 /// A const Target object pointer to the target that owns this 1189 /// module. 1190 //------------------------------------------------------------------ 1191 const Target & 1192 GetTarget () const; 1193 1194 //------------------------------------------------------------------ 1195 /// Get accessor for the current process state. 1196 /// 1197 /// @return 1198 /// The current state of the process. 1199 /// 1200 /// @see lldb::StateType 1201 //------------------------------------------------------------------ 1202 lldb::StateType 1203 GetState (); 1204 1205 lldb::ExecutionResults 1206 RunThreadPlan (ExecutionContext &exe_ctx, 1207 lldb::ThreadPlanSP &thread_plan_sp, 1208 bool stop_others, 1209 bool try_all_threads, 1210 bool discard_on_error, 1211 uint32_t single_thread_timeout_usec, 1212 Stream &errors); 1213 1214 static const char * 1215 ExecutionResultAsCString (lldb::ExecutionResults result); 1216 1217protected: 1218 friend class CommandObjectProcessLaunch; 1219 friend class ProcessEventData; 1220 friend class CommandObjectBreakpointCommand; 1221 1222 void 1223 SetState (lldb::EventSP &event_sp); 1224 1225 lldb::StateType 1226 GetPrivateState (); 1227 1228public: 1229 //------------------------------------------------------------------ 1230 /// Get the exit status for a process. 1231 /// 1232 /// @return 1233 /// The process's return code, or -1 if the current process 1234 /// state is not eStateExited. 1235 //------------------------------------------------------------------ 1236 int 1237 GetExitStatus (); 1238 1239 //------------------------------------------------------------------ 1240 /// Get a textual description of what the process exited. 1241 /// 1242 /// @return 1243 /// The textual description of why the process exited, or NULL 1244 /// if there is no description available. 1245 //------------------------------------------------------------------ 1246 const char * 1247 GetExitDescription (); 1248 1249 1250 virtual void 1251 DidExit () 1252 { 1253 } 1254 1255 //------------------------------------------------------------------ 1256 /// Get the number of times this process has posted a stop event. 1257 /// 1258 /// @return 1259 /// The number of times this process has stopped while being 1260 /// debugged. 1261 //------------------------------------------------------------------ 1262 uint32_t 1263 GetStopID () const; 1264 1265 //------------------------------------------------------------------ 1266 /// Set accessor for the process exit status (return code). 1267 /// 1268 /// Sometimes a child exits and the exit can be detected by global 1269 /// functions (signal handler for SIGCHLD for example). This 1270 /// accessor allows the exit status to be set from an external 1271 /// source. 1272 /// 1273 /// Setting this will cause a eStateExited event to be posted to 1274 /// the process event queue. 1275 /// 1276 /// @param[in] exit_status 1277 /// The value for the process's return code. 1278 /// 1279 /// @see lldb::StateType 1280 //------------------------------------------------------------------ 1281 virtual bool 1282 SetExitStatus (int exit_status, const char *cstr); 1283 1284 //------------------------------------------------------------------ 1285 /// Check if a process is still alive. 1286 /// 1287 /// @return 1288 /// Returns \b true if the process is still valid, \b false 1289 /// otherwise. 1290 //------------------------------------------------------------------ 1291 virtual bool 1292 IsAlive () = 0; 1293 1294 //------------------------------------------------------------------ 1295 /// Actually do the reading of memory from a process. 1296 /// 1297 /// Subclasses must override this function and can return fewer 1298 /// bytes than requested when memory requests are too large. This 1299 /// class will break up the memory requests and keep advancing the 1300 /// arguments along as needed. 1301 /// 1302 /// @param[in] vm_addr 1303 /// A virtual load address that indicates where to start reading 1304 /// memory from. 1305 /// 1306 /// @param[in] size 1307 /// The number of bytes to read. 1308 /// 1309 /// @param[out] buf 1310 /// A byte buffer that is at least \a size bytes long that 1311 /// will receive the memory bytes. 1312 /// 1313 /// @return 1314 /// The number of bytes that were actually read into \a buf. 1315 //------------------------------------------------------------------ 1316 virtual size_t 1317 DoReadMemory (lldb::addr_t vm_addr, 1318 void *buf, 1319 size_t size, 1320 Error &error) = 0; 1321 1322 //------------------------------------------------------------------ 1323 /// Read of memory from a process. 1324 /// 1325 /// This function will read memory from the current process's 1326 /// address space and remove any traps that may have been inserted 1327 /// into the memory. 1328 /// 1329 /// This function is not meant to be overridden by Process 1330 /// subclasses, the subclasses should implement 1331 /// Process::DoReadMemory (lldb::addr_t, size_t, void *). 1332 /// 1333 /// @param[in] vm_addr 1334 /// A virtual load address that indicates where to start reading 1335 /// memory from. 1336 /// 1337 /// @param[out] buf 1338 /// A byte buffer that is at least \a size bytes long that 1339 /// will receive the memory bytes. 1340 /// 1341 /// @param[in] size 1342 /// The number of bytes to read. 1343 /// 1344 /// @return 1345 /// The number of bytes that were actually read into \a buf. If 1346 /// the returned number is greater than zero, yet less than \a 1347 /// size, then this function will get called again with \a 1348 /// vm_addr, \a buf, and \a size updated appropriately. Zero is 1349 /// returned to indicate an error. 1350 //------------------------------------------------------------------ 1351 size_t 1352 ReadMemory (lldb::addr_t vm_addr, 1353 void *buf, 1354 size_t size, 1355 Error &error); 1356 1357 size_t 1358 ReadMemoryFromInferior (lldb::addr_t vm_addr, 1359 void *buf, 1360 size_t size, 1361 Error &error); 1362 1363 //------------------------------------------------------------------ 1364 /// Reads an unsigned integer of the specified byte size from 1365 /// process memory. 1366 /// 1367 /// @param[in] load_addr 1368 /// A load address of the integer to read. 1369 /// 1370 /// @param[in] byte_size 1371 /// The size in byte of the integer to read. 1372 /// 1373 /// @param[out] error 1374 /// An error that indicates the success or failure of this 1375 /// operation. If error indicates success (error.Success()), 1376 /// then the value returned can be trusted, otherwise zero 1377 /// will be returned. 1378 /// 1379 /// @return 1380 /// The unsigned integer that was read from the process memory 1381 /// space. If the integer was smaller than a uint64_t, any 1382 /// unused upper bytes will be zero filled. If the process 1383 /// byte order differs from the host byte order, the integer 1384 /// value will be appropriately byte swapped into host byte 1385 /// order. 1386 //------------------------------------------------------------------ 1387 uint64_t 1388 ReadUnsignedInteger (lldb::addr_t load_addr, 1389 size_t byte_size, 1390 Error &error); 1391 //------------------------------------------------------------------ 1392 /// Actually do the writing of memory to a process. 1393 /// 1394 /// @param[in] vm_addr 1395 /// A virtual load address that indicates where to start writing 1396 /// memory to. 1397 /// 1398 /// @param[in] buf 1399 /// A byte buffer that is at least \a size bytes long that 1400 /// contains the data to write. 1401 /// 1402 /// @param[in] size 1403 /// The number of bytes to write. 1404 /// 1405 /// @return 1406 /// The number of bytes that were actually written. 1407 //------------------------------------------------------------------ 1408 virtual size_t 1409 DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) = 0; 1410 1411 //------------------------------------------------------------------ 1412 /// Write memory to a process. 1413 /// 1414 /// This function will write memory to the current process's 1415 /// address space and maintain any traps that might be present due 1416 /// to software breakpoints. 1417 /// 1418 /// This function is not meant to be overridden by Process 1419 /// subclasses, the subclasses should implement 1420 /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). 1421 /// 1422 /// @param[in] vm_addr 1423 /// A virtual load address that indicates where to start writing 1424 /// memory to. 1425 /// 1426 /// @param[in] buf 1427 /// A byte buffer that is at least \a size bytes long that 1428 /// contains the data to write. 1429 /// 1430 /// @param[in] size 1431 /// The number of bytes to write. 1432 /// 1433 /// @return 1434 /// The number of bytes that were actually written. 1435 //------------------------------------------------------------------ 1436 size_t 1437 WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); 1438 1439 1440 //------------------------------------------------------------------ 1441 /// Actually allocate memory in the process. 1442 /// 1443 /// This function will allocate memory in the process's address 1444 /// space. This can't rely on the generic function calling mechanism, 1445 /// since that requires this function. 1446 /// 1447 /// @param[in] size 1448 /// The size of the allocation requested. 1449 /// 1450 /// @return 1451 /// The address of the allocated buffer in the process, or 1452 /// LLDB_INVALID_ADDRESS if the allocation failed. 1453 //------------------------------------------------------------------ 1454 1455 virtual lldb::addr_t 1456 DoAllocateMemory (size_t size, uint32_t permissions, Error &error) = 0; 1457 1458 //------------------------------------------------------------------ 1459 /// The public interface to allocating memory in the process. 1460 /// 1461 /// This function will allocate memory in the process's address 1462 /// space. This can't rely on the generic function calling mechanism, 1463 /// since that requires this function. 1464 /// 1465 /// @param[in] size 1466 /// The size of the allocation requested. 1467 /// 1468 /// @param[in] permissions 1469 /// Or together any of the lldb::Permissions bits. The permissions on 1470 /// a given memory allocation can't be changed after allocation. Note 1471 /// that a block that isn't set writable can still be written on from lldb, 1472 /// just not by the process itself. 1473 /// 1474 /// @return 1475 /// The address of the allocated buffer in the process, or 1476 /// LLDB_INVALID_ADDRESS if the allocation failed. 1477 //------------------------------------------------------------------ 1478 1479 lldb::addr_t 1480 AllocateMemory (size_t size, uint32_t permissions, Error &error); 1481 1482 //------------------------------------------------------------------ 1483 /// Actually deallocate memory in the process. 1484 /// 1485 /// This function will deallocate memory in the process's address 1486 /// space that was allocated with AllocateMemory. 1487 /// 1488 /// @param[in] ptr 1489 /// A return value from AllocateMemory, pointing to the memory you 1490 /// want to deallocate. 1491 /// 1492 /// @return 1493 /// \btrue if the memory was deallocated, \bfalse otherwise. 1494 //------------------------------------------------------------------ 1495 1496 virtual Error 1497 DoDeallocateMemory (lldb::addr_t ptr) = 0; 1498 1499 //------------------------------------------------------------------ 1500 /// The public interface to deallocating memory in the process. 1501 /// 1502 /// This function will deallocate memory in the process's address 1503 /// space that was allocated with AllocateMemory. 1504 /// 1505 /// @param[in] ptr 1506 /// A return value from AllocateMemory, pointing to the memory you 1507 /// want to deallocate. 1508 /// 1509 /// @return 1510 /// \btrue if the memory was deallocated, \bfalse otherwise. 1511 //------------------------------------------------------------------ 1512 1513 Error 1514 DeallocateMemory (lldb::addr_t ptr); 1515 1516 //------------------------------------------------------------------ 1517 /// Get any available STDOUT. 1518 /// 1519 /// If the process was launched without supplying valid file paths 1520 /// for stdin, stdout, and stderr, then the Process class might 1521 /// try to cache the STDOUT for the process if it is able. Events 1522 /// will be queued indicating that there is STDOUT available that 1523 /// can be retrieved using this function. 1524 /// 1525 /// @param[out] buf 1526 /// A buffer that will receive any STDOUT bytes that are 1527 /// currently available. 1528 /// 1529 /// @param[out] buf_size 1530 /// The size in bytes for the buffer \a buf. 1531 /// 1532 /// @return 1533 /// The number of bytes written into \a buf. If this value is 1534 /// equal to \a buf_size, another call to this function should 1535 /// be made to retrieve more STDOUT data. 1536 //------------------------------------------------------------------ 1537 virtual size_t 1538 GetSTDOUT (char *buf, size_t buf_size, Error &error) 1539 { 1540 error.SetErrorString("stdout unsupported"); 1541 return 0; 1542 } 1543 1544 1545 //------------------------------------------------------------------ 1546 /// Get any available STDERR. 1547 /// 1548 /// If the process was launched without supplying valid file paths 1549 /// for stdin, stdout, and stderr, then the Process class might 1550 /// try to cache the STDERR for the process if it is able. Events 1551 /// will be queued indicating that there is STDERR available that 1552 /// can be retrieved using this function. 1553 /// 1554 /// @param[out] buf 1555 /// A buffer that will receive any STDERR bytes that are 1556 /// currently available. 1557 /// 1558 /// @param[out] buf_size 1559 /// The size in bytes for the buffer \a buf. 1560 /// 1561 /// @return 1562 /// The number of bytes written into \a buf. If this value is 1563 /// equal to \a buf_size, another call to this function should 1564 /// be made to retrieve more STDERR data. 1565 //------------------------------------------------------------------ 1566 virtual size_t 1567 GetSTDERR (char *buf, size_t buf_size, Error &error) 1568 { 1569 error.SetErrorString("stderr unsupported"); 1570 return 0; 1571 } 1572 1573 virtual size_t 1574 PutSTDIN (const char *buf, size_t buf_size, Error &error) 1575 { 1576 error.SetErrorString("stdin unsupported"); 1577 return 0; 1578 } 1579 1580 //---------------------------------------------------------------------- 1581 // Process Breakpoints 1582 //---------------------------------------------------------------------- 1583 virtual size_t 1584 GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) = 0; 1585 1586 virtual Error 1587 EnableBreakpoint (BreakpointSite *bp_site) = 0; 1588 1589 virtual Error 1590 DisableBreakpoint (BreakpointSite *bp_site) = 0; 1591 1592 // This is implemented completely using the lldb::Process API. Subclasses 1593 // don't need to implement this function unless the standard flow of 1594 // read existing opcode, write breakpoint opcode, verify breakpoint opcode 1595 // doesn't work for a specific process plug-in. 1596 virtual Error 1597 EnableSoftwareBreakpoint (BreakpointSite *bp_site); 1598 1599 // This is implemented completely using the lldb::Process API. Subclasses 1600 // don't need to implement this function unless the standard flow of 1601 // restoring original opcode in memory and verifying the restored opcode 1602 // doesn't work for a specific process plug-in. 1603 virtual Error 1604 DisableSoftwareBreakpoint (BreakpointSite *bp_site); 1605 1606 BreakpointSiteList & 1607 GetBreakpointSiteList(); 1608 1609 const BreakpointSiteList & 1610 GetBreakpointSiteList() const; 1611 1612 void 1613 DisableAllBreakpointSites (); 1614 1615 Error 1616 ClearBreakpointSiteByID (lldb::user_id_t break_id); 1617 1618 lldb::break_id_t 1619 CreateBreakpointSite (lldb::BreakpointLocationSP &owner, 1620 bool use_hardware); 1621 1622 Error 1623 DisableBreakpointSiteByID (lldb::user_id_t break_id); 1624 1625 Error 1626 EnableBreakpointSiteByID (lldb::user_id_t break_id); 1627 1628 1629 // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove 1630 // themselves from the owner's list of this breakpoint sites. This has to 1631 // be a static function because you can't be sure that removing the 1632 // breakpoint from it's containing map won't delete the breakpoint site, 1633 // and doing that in an instance method isn't copasetic. 1634 void 1635 RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, 1636 lldb::user_id_t owner_loc_id, 1637 lldb::BreakpointSiteSP &bp_site_sp); 1638 1639 //---------------------------------------------------------------------- 1640 // Process Watchpoints (optional) 1641 //---------------------------------------------------------------------- 1642 virtual Error 1643 EnableWatchpoint (WatchpointLocation *bp_loc); 1644 1645 virtual Error 1646 DisableWatchpoint (WatchpointLocation *bp_loc); 1647 1648 //------------------------------------------------------------------ 1649 // Thread Queries 1650 //------------------------------------------------------------------ 1651 virtual uint32_t 1652 UpdateThreadListIfNeeded () = 0; 1653 1654 ThreadList & 1655 GetThreadList (); 1656 1657 const ThreadList & 1658 GetThreadList () const; 1659 1660 uint32_t 1661 GetNextThreadIndexID (); 1662 1663 //------------------------------------------------------------------ 1664 // Event Handling 1665 //------------------------------------------------------------------ 1666 lldb::StateType 1667 GetNextEvent (lldb::EventSP &event_sp); 1668 1669 lldb::StateType 1670 WaitForProcessToStop (const TimeValue *timeout); 1671 1672 lldb::StateType 1673 WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp); 1674 1675 Event * 1676 PeekAtStateChangedEvents (); 1677 1678 1679 //------------------------------------------------------------------ 1680 /// If you need to ensure that you and only you will hear about some public 1681 /// event, then make a new listener, set to listen to process events, and 1682 /// then call this with that listener. Then you will have to wait on that 1683 /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* 1684 /// calls above. Be sure to call RestoreProcessEvents when you are done. 1685 /// 1686 /// @param[in] listener 1687 /// This is the new listener to whom all process events will be delivered. 1688 /// 1689 /// @return 1690 /// Returns \b true if the new listener could be installed, 1691 /// \b false otherwise. 1692 //------------------------------------------------------------------ 1693 bool 1694 HijackProcessEvents (Listener *listener); 1695 1696 //------------------------------------------------------------------ 1697 /// Restores the process event broadcasting to its normal state. 1698 /// 1699 //------------------------------------------------------------------ 1700 void 1701 RestoreProcessEvents (); 1702 1703protected: 1704 //------------------------------------------------------------------ 1705 /// This is the part of the event handling that for a process event. 1706 /// It decides what to do with the event and returns true if the 1707 /// event needs to be propagated to the user, and false otherwise. 1708 /// If the event is not propagated, this call will most likely set 1709 /// the target to executing again. 1710 /// 1711 /// @param[in] event_ptr 1712 /// This is the event we are handling. 1713 /// 1714 /// @return 1715 /// Returns \b true if the event should be reported to the 1716 /// user, \b false otherwise. 1717 //------------------------------------------------------------------ 1718 bool 1719 ShouldBroadcastEvent (Event *event_ptr); 1720 1721public: 1722 //------------------------------------------------------------------ 1723 /// Gets the byte order for this process. 1724 /// 1725 /// @return 1726 /// A valid ByteOrder enumeration, or eByteOrderInvalid. 1727 //------------------------------------------------------------------ 1728 lldb::ByteOrder 1729 GetByteOrder () const 1730 { 1731 return m_byte_order; 1732 } 1733 1734 void 1735 SetByteOrder (lldb::ByteOrder byte_order) 1736 { 1737 m_byte_order = byte_order; 1738 } 1739 1740 const ConstString & 1741 GetTargetTriple () 1742 { 1743 return m_target_triple; 1744 } 1745 1746 const ABI * 1747 GetABI (); 1748 1749 virtual DynamicLoader * 1750 GetDynamicLoader (); 1751 1752 virtual LanguageRuntime * 1753 GetLanguageRuntime (lldb::LanguageType language); 1754 1755 virtual CPPLanguageRuntime * 1756 GetCPPLanguageRuntime (); 1757 1758 virtual ObjCLanguageRuntime * 1759 GetObjCLanguageRuntime (); 1760 1761 bool 1762 IsRunning () const; 1763 1764 DynamicCheckerFunctions *GetDynamicCheckers() 1765 { 1766 return m_dynamic_checkers_ap.get(); 1767 } 1768 1769 void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) 1770 { 1771 m_dynamic_checkers_ap.reset(dynamic_checkers); 1772 } 1773 1774 virtual bool 1775 StartNoticingNewThreads() 1776 { 1777 return true; 1778 } 1779 1780 virtual bool 1781 StopNoticingNewThreads() 1782 { 1783 return true; 1784 } 1785 1786 //------------------------------------------------------------------ 1787 // lldb::ExecutionContextScope pure virtual functions 1788 //------------------------------------------------------------------ 1789 virtual Target * 1790 CalculateTarget (); 1791 1792 virtual Process * 1793 CalculateProcess (); 1794 1795 virtual Thread * 1796 CalculateThread (); 1797 1798 virtual StackFrame * 1799 CalculateStackFrame (); 1800 1801 virtual void 1802 CalculateExecutionContext (ExecutionContext &exe_ctx); 1803 1804 lldb::ProcessSP 1805 GetSP (); 1806 1807protected: 1808 //------------------------------------------------------------------ 1809 // lldb::ExecutionContextScope pure virtual functions 1810 //------------------------------------------------------------------ 1811 class NextEventAction 1812 { 1813 public: 1814 typedef enum EventActionResult 1815 { 1816 eEventActionSuccess, 1817 eEventActionRetry, 1818 eEventActionExit 1819 } EventActionResult; 1820 1821 NextEventAction (Process *process) : 1822 m_process(process) 1823 {} 1824 virtual ~NextEventAction() {} 1825 1826 virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0; 1827 virtual void HandleBeingUnshipped () {}; 1828 virtual EventActionResult HandleBeingInterrupted () = 0; 1829 virtual const char *GetExitString() = 0; 1830 protected: 1831 Process *m_process; 1832 }; 1833 1834 void SetNextEventAction (Process::NextEventAction *next_event_action) 1835 { 1836 if (m_next_event_action_ap.get()) 1837 m_next_event_action_ap->HandleBeingUnshipped(); 1838 1839 m_next_event_action_ap.reset(next_event_action); 1840 } 1841 1842 // This is the completer for Attaching: 1843 class AttachCompletionHandler : public NextEventAction 1844 { 1845 public: 1846 AttachCompletionHandler (Process *process) : 1847 NextEventAction(process) 1848 {} 1849 virtual ~AttachCompletionHandler() {} 1850 1851 virtual EventActionResult PerformAction (lldb::EventSP &event_sp); 1852 virtual EventActionResult HandleBeingInterrupted (); 1853 virtual const char *GetExitString(); 1854 private: 1855 std::string m_exit_string; 1856 }; 1857 1858 1859 class MemoryCache 1860 { 1861 public: 1862 //------------------------------------------------------------------ 1863 // Constructors and Destructors 1864 //------------------------------------------------------------------ 1865 MemoryCache (); 1866 1867 ~MemoryCache (); 1868 1869 void 1870 Clear(); 1871 1872 void 1873 Flush (lldb::addr_t addr, size_t size); 1874 1875 size_t 1876 Read (Process *process, 1877 lldb::addr_t addr, 1878 void *dst, 1879 size_t dst_len, 1880 Error &error); 1881 1882 protected: 1883 typedef std::map<lldb::addr_t, lldb::DataBufferSP> collection; 1884 //------------------------------------------------------------------ 1885 // Classes that inherit from MemoryCache can see and modify these 1886 //------------------------------------------------------------------ 1887 uint32_t m_cache_line_byte_size; 1888 Mutex m_cache_mutex; 1889 collection m_cache; 1890 1891 private: 1892 DISALLOW_COPY_AND_ASSIGN (MemoryCache); 1893 }; 1894 1895 1896 //------------------------------------------------------------------ 1897 // Member variables 1898 //------------------------------------------------------------------ 1899 Target & m_target; ///< The target that owns this process. 1900 ThreadSafeValue<lldb::StateType> m_public_state; 1901 ThreadSafeValue<lldb::StateType> m_private_state; // The actual state of our process 1902 Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. 1903 Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. 1904 Listener m_private_state_listener; // This is the listener for the private state thread. 1905 Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. 1906 lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events 1907 uint32_t m_stop_id; ///< A count of many times the process has stopped. 1908 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. 1909 int m_exit_status; ///< The exit status of the process, or -1 if not set. 1910 std::string m_exit_string; ///< A textual description of why a process exited. 1911 ThreadList m_thread_list; ///< The threads for this process. 1912 std::vector<Notifications> m_notifications; ///< The list of notifications that this process can deliver. 1913 std::vector<lldb::addr_t> m_image_tokens; 1914 Listener &m_listener; 1915 BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend 1916 ///< to insert in the target. 1917 std::auto_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. 1918 UnixSignals m_unix_signals; /// This is the current signal set for this process. 1919 ConstString m_target_triple; 1920 lldb::ByteOrder m_byte_order; /// The byte order of the process. Should be set in DidLaunch/DidAttach. 1921 uint32_t m_addr_byte_size; /// The size in bytes of an address/pointer for the inferior process. Should be set in DidLaunch/DidAttach. 1922 lldb::ABISP m_abi_sp; 1923 lldb::InputReaderSP m_process_input_reader; 1924 lldb_private::Communication m_stdio_communication; 1925 lldb_private::Mutex m_stdio_communication_mutex; 1926 std::string m_stdout_data; 1927 MemoryCache m_memory_cache; 1928 1929 typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection; 1930 LanguageRuntimeCollection m_language_runtimes; 1931 std::auto_ptr<NextEventAction> m_next_event_action_ap; 1932 1933 size_t 1934 RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; 1935 1936 void 1937 SynchronouslyNotifyStateChanged (lldb::StateType state); 1938 1939 void 1940 SetPublicState (lldb::StateType new_state); 1941 1942 void 1943 SetPrivateState (lldb::StateType state); 1944 1945 bool 1946 StartPrivateStateThread (); 1947 1948 void 1949 StopPrivateStateThread (); 1950 1951 void 1952 PausePrivateStateThread (); 1953 1954 void 1955 ResumePrivateStateThread (); 1956 1957 static void * 1958 PrivateStateThread (void *arg); 1959 1960 void * 1961 RunPrivateStateThread (); 1962 1963 void 1964 HandlePrivateEvent (lldb::EventSP &event_sp); 1965 1966 lldb::StateType 1967 WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 1968 1969 // This waits for both the state change broadcaster, and the control broadcaster. 1970 // If control_only, it only waits for the control broadcaster. 1971 1972 bool 1973 WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); 1974 1975 lldb::StateType 1976 WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 1977 1978 lldb::StateType 1979 WaitForState (const TimeValue *timeout, 1980 const lldb::StateType *match_states, 1981 const uint32_t num_match_states); 1982 1983 size_t 1984 WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); 1985 1986 void 1987 AppendSTDOUT (const char *s, size_t len); 1988 1989 static void 1990 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); 1991 1992 void 1993 PushProcessInputReader (); 1994 1995 void 1996 PopProcessInputReader (); 1997 1998 void 1999 ResetProcessInputReader (); 2000 2001 void 2002 SetUpProcessInputReader (int file_descriptor); 2003 2004 static size_t 2005 ProcessInputReaderCallback (void *baton, 2006 InputReader &reader, 2007 lldb::InputReaderAction notification, 2008 const char *bytes, 2009 size_t bytes_len); 2010 2011 2012private: 2013 //------------------------------------------------------------------ 2014 // For Process only 2015 //------------------------------------------------------------------ 2016 void ControlPrivateStateThread (uint32_t signal); 2017 2018 DISALLOW_COPY_AND_ASSIGN (Process); 2019 2020}; 2021 2022} // namespace lldb_private 2023 2024#endif // liblldb_Process_h_ 2025