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