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