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