Process.h revision 598df88bd6fc33c6fb330bc859bdc277795501f3
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#include <limits.h> 15#include <spawn.h> 16 17// C++ Includes 18#include <list> 19#include <iosfwd> 20#include <vector> 21 22// Other libraries and framework includes 23// Project includes 24#include "lldb/lldb-private.h" 25#include "lldb/Core/ArchSpec.h" 26#include "lldb/Core/Broadcaster.h" 27#include "lldb/Core/Communication.h" 28#include "lldb/Core/Error.h" 29#include "lldb/Core/Event.h" 30#include "lldb/Core/RangeMap.h" 31#include "lldb/Core/StringList.h" 32#include "lldb/Core/ThreadSafeValue.h" 33#include "lldb/Core/PluginInterface.h" 34#include "lldb/Core/UserSettingsController.h" 35#include "lldb/Breakpoint/BreakpointSiteList.h" 36#include "lldb/Expression/ClangPersistentVariables.h" 37#include "lldb/Expression/IRDynamicChecks.h" 38#include "lldb/Host/FileSpec.h" 39#include "lldb/Host/Host.h" 40#include "lldb/Interpreter/Args.h" 41#include "lldb/Interpreter/Options.h" 42#include "lldb/Target/ExecutionContextScope.h" 43#include "lldb/Target/Memory.h" 44#include "lldb/Target/ThreadList.h" 45#include "lldb/Target/UnixSignals.h" 46#include "lldb/Utility/PseudoTerminal.h" 47 48namespace lldb_private { 49 50//---------------------------------------------------------------------- 51// ProcessInstanceSettings 52//---------------------------------------------------------------------- 53class ProcessInstanceSettings : public InstanceSettings 54{ 55public: 56 57 ProcessInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL); 58 59 ProcessInstanceSettings (const ProcessInstanceSettings &rhs); 60 61 virtual 62 ~ProcessInstanceSettings (); 63 64 ProcessInstanceSettings& 65 operator= (const ProcessInstanceSettings &rhs); 66 67 68 void 69 UpdateInstanceSettingsVariable (const ConstString &var_name, 70 const char *index_value, 71 const char *value, 72 const ConstString &instance_name, 73 const SettingEntry &entry, 74 VarSetOperationType op, 75 Error &err, 76 bool pending); 77 78 bool 79 GetInstanceSettingsValue (const SettingEntry &entry, 80 const ConstString &var_name, 81 StringList &value, 82 Error *err); 83 84 85protected: 86 87 void 88 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 89 bool pending); 90 91 const ConstString 92 CreateInstanceName (); 93}; 94 95//---------------------------------------------------------------------- 96// ProcessInfo 97// 98// A base class for information for a process. This can be used to fill 99// out information for a process prior to launching it, or it can be 100// used for an instance of a process and can be filled in with the 101// existing values for that process. 102//---------------------------------------------------------------------- 103class ProcessInfo 104{ 105public: 106 ProcessInfo () : 107 m_executable (), 108 m_arguments (), 109 m_environment (), 110 m_uid (UINT32_MAX), 111 m_gid (UINT32_MAX), 112 m_arch(), 113 m_pid (LLDB_INVALID_PROCESS_ID) 114 { 115 } 116 117 ProcessInfo (const char *name, 118 const ArchSpec &arch, 119 lldb::pid_t pid) : 120 m_executable (name, false), 121 m_arguments (), 122 m_environment(), 123 m_uid (UINT32_MAX), 124 m_gid (UINT32_MAX), 125 m_arch (arch), 126 m_pid (pid) 127 { 128 } 129 130 void 131 Clear () 132 { 133 m_executable.Clear(); 134 m_arguments.Clear(); 135 m_environment.Clear(); 136 m_uid = UINT32_MAX; 137 m_gid = UINT32_MAX; 138 m_arch.Clear(); 139 m_pid = LLDB_INVALID_PROCESS_ID; 140 } 141 142 const char * 143 GetName() const 144 { 145 return m_executable.GetFilename().GetCString(); 146 } 147 148 size_t 149 GetNameLength() const 150 { 151 return m_executable.GetFilename().GetLength(); 152 } 153 154 FileSpec & 155 GetExecutableFile () 156 { 157 return m_executable; 158 } 159 160 void 161 SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg) 162 { 163 if (exe_file) 164 { 165 m_executable = exe_file; 166 if (add_exe_file_as_first_arg) 167 { 168 char filename[PATH_MAX]; 169 if (exe_file.GetPath(filename, sizeof(filename))) 170 m_arguments.InsertArgumentAtIndex (0, filename); 171 } 172 } 173 else 174 { 175 m_executable.Clear(); 176 } 177 } 178 179 const FileSpec & 180 GetExecutableFile () const 181 { 182 return m_executable; 183 } 184 185 uint32_t 186 GetUserID() const 187 { 188 return m_uid; 189 } 190 191 uint32_t 192 GetGroupID() const 193 { 194 return m_gid; 195 } 196 197 bool 198 UserIDIsValid () const 199 { 200 return m_uid != UINT32_MAX; 201 } 202 203 bool 204 GroupIDIsValid () const 205 { 206 return m_gid != UINT32_MAX; 207 } 208 209 void 210 SetUserID (uint32_t uid) 211 { 212 m_uid = uid; 213 } 214 215 void 216 SetGroupID (uint32_t gid) 217 { 218 m_gid = gid; 219 } 220 221 ArchSpec & 222 GetArchitecture () 223 { 224 return m_arch; 225 } 226 227 const ArchSpec & 228 GetArchitecture () const 229 { 230 return m_arch; 231 } 232 233 lldb::pid_t 234 GetProcessID () const 235 { 236 return m_pid; 237 } 238 239 void 240 SetProcessID (lldb::pid_t pid) 241 { 242 m_pid = pid; 243 } 244 245 bool 246 ProcessIDIsValid() const 247 { 248 return m_pid != LLDB_INVALID_PROCESS_ID; 249 } 250 251 void 252 Dump (Stream &s, Platform *platform) const; 253 254 Args & 255 GetArguments () 256 { 257 return m_arguments; 258 } 259 260 const Args & 261 GetArguments () const 262 { 263 return m_arguments; 264 } 265 266 void 267 SetArguments (const Args& args, 268 bool first_arg_is_executable, 269 bool first_arg_is_executable_and_argument); 270 271 void 272 SetArguments (char const **argv, 273 bool first_arg_is_executable, 274 bool first_arg_is_executable_and_argument); 275 276 Args & 277 GetEnvironmentEntries () 278 { 279 return m_environment; 280 } 281 282 const Args & 283 GetEnvironmentEntries () const 284 { 285 return m_environment; 286 } 287 288protected: 289 FileSpec m_executable; 290 Args m_arguments; 291 Args m_environment; 292 uint32_t m_uid; 293 uint32_t m_gid; 294 ArchSpec m_arch; 295 lldb::pid_t m_pid; 296}; 297 298//---------------------------------------------------------------------- 299// ProcessInstanceInfo 300// 301// Describes an existing process and any discoverable information that 302// pertains to that process. 303//---------------------------------------------------------------------- 304class ProcessInstanceInfo : public ProcessInfo 305{ 306public: 307 ProcessInstanceInfo () : 308 ProcessInfo (), 309 m_euid (UINT32_MAX), 310 m_egid (UINT32_MAX), 311 m_parent_pid (LLDB_INVALID_PROCESS_ID) 312 { 313 } 314 315 ProcessInstanceInfo (const char *name, 316 const ArchSpec &arch, 317 lldb::pid_t pid) : 318 ProcessInfo (name, arch, pid), 319 m_euid (UINT32_MAX), 320 m_egid (UINT32_MAX), 321 m_parent_pid (LLDB_INVALID_PROCESS_ID) 322 { 323 } 324 325 void 326 Clear () 327 { 328 ProcessInfo::Clear(); 329 m_euid = UINT32_MAX; 330 m_egid = UINT32_MAX; 331 m_parent_pid = LLDB_INVALID_PROCESS_ID; 332 } 333 334 uint32_t 335 GetEffectiveUserID() const 336 { 337 return m_euid; 338 } 339 340 uint32_t 341 GetEffectiveGroupID() const 342 { 343 return m_egid; 344 } 345 346 bool 347 EffectiveUserIDIsValid () const 348 { 349 return m_euid != UINT32_MAX; 350 } 351 352 bool 353 EffectiveGroupIDIsValid () const 354 { 355 return m_egid != UINT32_MAX; 356 } 357 358 void 359 SetEffectiveUserID (uint32_t uid) 360 { 361 m_euid = uid; 362 } 363 364 void 365 SetEffectiveGroupID (uint32_t gid) 366 { 367 m_egid = gid; 368 } 369 370 lldb::pid_t 371 GetParentProcessID () const 372 { 373 return m_parent_pid; 374 } 375 376 void 377 SetParentProcessID (lldb::pid_t pid) 378 { 379 m_parent_pid = pid; 380 } 381 382 bool 383 ParentProcessIDIsValid() const 384 { 385 return m_parent_pid != LLDB_INVALID_PROCESS_ID; 386 } 387 388 void 389 Dump (Stream &s, Platform *platform) const; 390 391 static void 392 DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose); 393 394 void 395 DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const; 396 397protected: 398 uint32_t m_euid; 399 uint32_t m_egid; 400 lldb::pid_t m_parent_pid; 401}; 402 403 404//---------------------------------------------------------------------- 405// ProcessLaunchInfo 406// 407// Describes any information that is required to launch a process. 408//---------------------------------------------------------------------- 409 410class ProcessLaunchInfo : public ProcessInfo 411{ 412public: 413 414 class FileAction 415 { 416 public: 417 enum Action 418 { 419 eFileActionNone, 420 eFileActionClose, 421 eFileActionDuplicate, 422 eFileActionOpen 423 }; 424 425 426 FileAction () : 427 m_action (eFileActionNone), 428 m_fd (-1), 429 m_arg (-1), 430 m_path () 431 { 432 } 433 434 void 435 Clear() 436 { 437 m_action = eFileActionNone; 438 m_fd = -1; 439 m_arg = -1; 440 m_path.clear(); 441 } 442 443 bool 444 Close (int fd); 445 446 bool 447 Duplicate (int fd, int dup_fd); 448 449 bool 450 Open (int fd, const char *path, bool read, bool write); 451 452 static bool 453 AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions, 454 const FileAction *info, 455 Log *log, 456 Error& error); 457 458 int 459 GetFD () const 460 { 461 return m_fd; 462 } 463 464 Action 465 GetAction () const 466 { 467 return m_action; 468 } 469 470 int 471 GetActionArgument () const 472 { 473 return m_arg; 474 } 475 476 const char * 477 GetPath () const 478 { 479 if (m_path.empty()) 480 return NULL; 481 return m_path.c_str(); 482 } 483 484 protected: 485 Action m_action; // The action for this file 486 int m_fd; // An existing file descriptor 487 int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate 488 std::string m_path; // A file path to use for opening after fork or posix_spawn 489 }; 490 491 ProcessLaunchInfo () : 492 ProcessInfo(), 493 m_working_dir (), 494 m_plugin_name (), 495 m_shell (), 496 m_flags (0), 497 m_file_actions (), 498 m_pty (), 499 m_resume_count (0), 500 m_monitor_callback (NULL), 501 m_monitor_callback_baton (NULL), 502 m_monitor_signals (false) 503 { 504 } 505 506 ProcessLaunchInfo (const char *stdin_path, 507 const char *stdout_path, 508 const char *stderr_path, 509 const char *working_directory, 510 uint32_t launch_flags) : 511 ProcessInfo(), 512 m_working_dir (), 513 m_plugin_name (), 514 m_shell (), 515 m_flags (launch_flags), 516 m_file_actions (), 517 m_pty (), 518 m_resume_count (0), 519 m_monitor_callback (NULL), 520 m_monitor_callback_baton (NULL), 521 m_monitor_signals (false) 522 { 523 if (stdin_path) 524 { 525 ProcessLaunchInfo::FileAction file_action; 526 const bool read = true; 527 const bool write = false; 528 if (file_action.Open(STDIN_FILENO, stdin_path, read, write)) 529 AppendFileAction (file_action); 530 } 531 if (stdout_path) 532 { 533 ProcessLaunchInfo::FileAction file_action; 534 const bool read = false; 535 const bool write = true; 536 if (file_action.Open(STDOUT_FILENO, stdout_path, read, write)) 537 AppendFileAction (file_action); 538 } 539 if (stderr_path) 540 { 541 ProcessLaunchInfo::FileAction file_action; 542 const bool read = false; 543 const bool write = true; 544 if (file_action.Open(STDERR_FILENO, stderr_path, read, write)) 545 AppendFileAction (file_action); 546 } 547 if (working_directory) 548 SetWorkingDirectory(working_directory); 549 } 550 551 void 552 AppendFileAction (const FileAction &info) 553 { 554 m_file_actions.push_back(info); 555 } 556 557 bool 558 AppendCloseFileAction (int fd) 559 { 560 FileAction file_action; 561 if (file_action.Close (fd)) 562 { 563 AppendFileAction (file_action); 564 return true; 565 } 566 return false; 567 } 568 569 bool 570 AppendDuplicateFileAction (int fd, int dup_fd) 571 { 572 FileAction file_action; 573 if (file_action.Duplicate (fd, dup_fd)) 574 { 575 AppendFileAction (file_action); 576 return true; 577 } 578 return false; 579 } 580 581 bool 582 AppendOpenFileAction (int fd, const char *path, bool read, bool write) 583 { 584 FileAction file_action; 585 if (file_action.Open (fd, path, read, write)) 586 { 587 AppendFileAction (file_action); 588 return true; 589 } 590 return false; 591 } 592 593 bool 594 AppendSuppressFileAction (int fd, bool read, bool write) 595 { 596 FileAction file_action; 597 if (file_action.Open (fd, "/dev/null", read, write)) 598 { 599 AppendFileAction (file_action); 600 return true; 601 } 602 return false; 603 } 604 605 void 606 FinalizeFileActions (Target *target, 607 bool default_to_use_pty); 608 609 size_t 610 GetNumFileActions () const 611 { 612 return m_file_actions.size(); 613 } 614 615 const FileAction * 616 GetFileActionAtIndex (size_t idx) const 617 { 618 if (idx < m_file_actions.size()) 619 return &m_file_actions[idx]; 620 return NULL; 621 } 622 623 const FileAction * 624 GetFileActionForFD (int fd) const 625 { 626 for (uint32_t idx=0, count=m_file_actions.size(); idx < count; ++idx) 627 { 628 if (m_file_actions[idx].GetFD () == fd) 629 return &m_file_actions[idx]; 630 } 631 return NULL; 632 } 633 634 Flags & 635 GetFlags () 636 { 637 return m_flags; 638 } 639 640 const Flags & 641 GetFlags () const 642 { 643 return m_flags; 644 } 645 646 const char * 647 GetWorkingDirectory () const 648 { 649 if (m_working_dir.empty()) 650 return NULL; 651 return m_working_dir.c_str(); 652 } 653 654 void 655 SetWorkingDirectory (const char *working_dir) 656 { 657 if (working_dir && working_dir[0]) 658 m_working_dir.assign (working_dir); 659 else 660 m_working_dir.clear(); 661 } 662 663 void 664 SwapWorkingDirectory (std::string &working_dir) 665 { 666 m_working_dir.swap (working_dir); 667 } 668 669 670 const char * 671 GetProcessPluginName () const 672 { 673 if (m_plugin_name.empty()) 674 return NULL; 675 return m_plugin_name.c_str(); 676 } 677 678 void 679 SetProcessPluginName (const char *plugin) 680 { 681 if (plugin && plugin[0]) 682 m_plugin_name.assign (plugin); 683 else 684 m_plugin_name.clear(); 685 } 686 687 const char * 688 GetShell () const 689 { 690 if (m_shell.empty()) 691 return NULL; 692 return m_shell.c_str(); 693 } 694 695 void 696 SetShell (const char * path) 697 { 698 if (path && path[0]) 699 { 700 m_shell.assign (path); 701 m_flags.Set (lldb::eLaunchFlagLaunchInShell); 702 } 703 else 704 { 705 m_shell.clear(); 706 m_flags.Clear (lldb::eLaunchFlagLaunchInShell); 707 } 708 } 709 710 uint32_t 711 GetResumeCount () const 712 { 713 return m_resume_count; 714 } 715 716 void 717 SetResumeCount (uint32_t c) 718 { 719 m_resume_count = c; 720 } 721 722 void 723 Clear () 724 { 725 ProcessInfo::Clear(); 726 m_working_dir.clear(); 727 m_plugin_name.clear(); 728 m_shell.clear(); 729 m_flags.Clear(); 730 m_file_actions.clear(); 731 m_resume_count = 0; 732 } 733 734 bool 735 ConvertArgumentsForLaunchingInShell (Error &error, bool localhost); 736 737 void 738 SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback, 739 void *baton, 740 bool monitor_signals) 741 { 742 m_monitor_callback = callback; 743 m_monitor_callback_baton = baton; 744 m_monitor_signals = monitor_signals; 745 } 746 747 bool 748 MonitorProcess () const 749 { 750 if (m_monitor_callback && ProcessIDIsValid()) 751 { 752 Host::StartMonitoringChildProcess (m_monitor_callback, 753 m_monitor_callback_baton, 754 GetProcessID(), 755 m_monitor_signals); 756 return true; 757 } 758 return false; 759 } 760 761 lldb_utility::PseudoTerminal & 762 GetPTY () 763 { 764 return m_pty; 765 } 766 767protected: 768 std::string m_working_dir; 769 std::string m_plugin_name; 770 std::string m_shell; 771 Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags 772 std::vector<FileAction> m_file_actions; // File actions for any other files 773 lldb_utility::PseudoTerminal m_pty; 774 uint32_t m_resume_count; // How many times do we resume after launching 775 Host::MonitorChildProcessCallback m_monitor_callback; 776 void *m_monitor_callback_baton; 777 bool m_monitor_signals; 778}; 779 780//---------------------------------------------------------------------- 781// ProcessLaunchInfo 782// 783// Describes any information that is required to launch a process. 784//---------------------------------------------------------------------- 785 786class ProcessAttachInfo : public ProcessInstanceInfo 787{ 788public: 789 ProcessAttachInfo() : 790 ProcessInstanceInfo(), 791 m_plugin_name (), 792 m_resume_count (0), 793 m_wait_for_launch (false) 794 { 795 } 796 797 ProcessAttachInfo (const ProcessLaunchInfo &launch_info) : 798 ProcessInstanceInfo(), 799 m_plugin_name (), 800 m_resume_count (0), 801 m_wait_for_launch (false) 802 { 803 ProcessInfo::operator= (launch_info); 804 SetProcessPluginName (launch_info.GetProcessPluginName()); 805 SetResumeCount (launch_info.GetResumeCount()); 806 } 807 808 bool 809 GetWaitForLaunch () const 810 { 811 return m_wait_for_launch; 812 } 813 814 void 815 SetWaitForLaunch (bool b) 816 { 817 m_wait_for_launch = b; 818 } 819 820 uint32_t 821 GetResumeCount () const 822 { 823 return m_resume_count; 824 } 825 826 void 827 SetResumeCount (uint32_t c) 828 { 829 m_resume_count = c; 830 } 831 832 const char * 833 GetProcessPluginName () const 834 { 835 if (m_plugin_name.empty()) 836 return NULL; 837 return m_plugin_name.c_str(); 838 } 839 840 void 841 SetProcessPluginName (const char *plugin) 842 { 843 if (plugin && plugin[0]) 844 m_plugin_name.assign (plugin); 845 else 846 m_plugin_name.clear(); 847 } 848 849 void 850 Clear () 851 { 852 ProcessInstanceInfo::Clear(); 853 m_plugin_name.clear(); 854 m_resume_count = 0; 855 m_wait_for_launch = false; 856 } 857 858 bool 859 ProcessInfoSpecified () const 860 { 861 if (GetExecutableFile()) 862 return true; 863 if (GetProcessID() != LLDB_INVALID_PROCESS_ID) 864 return true; 865 if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID) 866 return true; 867 return false; 868 } 869protected: 870 std::string m_plugin_name; 871 uint32_t m_resume_count; // How many times do we resume after launching 872 bool m_wait_for_launch; 873}; 874 875class ProcessLaunchCommandOptions : public Options 876{ 877public: 878 879 ProcessLaunchCommandOptions (CommandInterpreter &interpreter) : 880 Options(interpreter) 881 { 882 // Keep default values of all options in one place: OptionParsingStarting () 883 OptionParsingStarting (); 884 } 885 886 ~ProcessLaunchCommandOptions () 887 { 888 } 889 890 Error 891 SetOptionValue (uint32_t option_idx, const char *option_arg); 892 893 void 894 OptionParsingStarting () 895 { 896 launch_info.Clear(); 897 } 898 899 const OptionDefinition* 900 GetDefinitions () 901 { 902 return g_option_table; 903 } 904 905 // Options table: Required for subclasses of Options. 906 907 static OptionDefinition g_option_table[]; 908 909 // Instance variables to hold the values for command options. 910 911 ProcessLaunchInfo launch_info; 912}; 913 914//---------------------------------------------------------------------- 915// ProcessInstanceInfoMatch 916// 917// A class to help matching one ProcessInstanceInfo to another. 918//---------------------------------------------------------------------- 919 920class ProcessInstanceInfoMatch 921{ 922public: 923 ProcessInstanceInfoMatch () : 924 m_match_info (), 925 m_name_match_type (lldb_private::eNameMatchIgnore), 926 m_match_all_users (false) 927 { 928 } 929 930 ProcessInstanceInfoMatch (const char *process_name, 931 lldb_private::NameMatchType process_name_match_type) : 932 m_match_info (), 933 m_name_match_type (process_name_match_type), 934 m_match_all_users (false) 935 { 936 m_match_info.GetExecutableFile().SetFile(process_name, false); 937 } 938 939 ProcessInstanceInfo & 940 GetProcessInfo () 941 { 942 return m_match_info; 943 } 944 945 const ProcessInstanceInfo & 946 GetProcessInfo () const 947 { 948 return m_match_info; 949 } 950 951 bool 952 GetMatchAllUsers () const 953 { 954 return m_match_all_users; 955 } 956 957 void 958 SetMatchAllUsers (bool b) 959 { 960 m_match_all_users = b; 961 } 962 963 lldb_private::NameMatchType 964 GetNameMatchType () const 965 { 966 return m_name_match_type; 967 } 968 969 void 970 SetNameMatchType (lldb_private::NameMatchType name_match_type) 971 { 972 m_name_match_type = name_match_type; 973 } 974 975 bool 976 NameMatches (const char *process_name) const; 977 978 bool 979 Matches (const ProcessInstanceInfo &proc_info) const; 980 981 bool 982 MatchAllProcesses () const; 983 void 984 Clear (); 985 986protected: 987 ProcessInstanceInfo m_match_info; 988 lldb_private::NameMatchType m_name_match_type; 989 bool m_match_all_users; 990}; 991 992class ProcessInstanceInfoList 993{ 994public: 995 ProcessInstanceInfoList () : 996 m_infos() 997 { 998 } 999 1000 void 1001 Clear() 1002 { 1003 m_infos.clear(); 1004 } 1005 1006 uint32_t 1007 GetSize() 1008 { 1009 return m_infos.size(); 1010 } 1011 1012 void 1013 Append (const ProcessInstanceInfo &info) 1014 { 1015 m_infos.push_back (info); 1016 } 1017 1018 const char * 1019 GetProcessNameAtIndex (uint32_t idx) 1020 { 1021 if (idx < m_infos.size()) 1022 return m_infos[idx].GetName(); 1023 return NULL; 1024 } 1025 1026 size_t 1027 GetProcessNameLengthAtIndex (uint32_t idx) 1028 { 1029 if (idx < m_infos.size()) 1030 return m_infos[idx].GetNameLength(); 1031 return 0; 1032 } 1033 1034 lldb::pid_t 1035 GetProcessIDAtIndex (uint32_t idx) 1036 { 1037 if (idx < m_infos.size()) 1038 return m_infos[idx].GetProcessID(); 1039 return 0; 1040 } 1041 1042 bool 1043 GetInfoAtIndex (uint32_t idx, ProcessInstanceInfo &info) 1044 { 1045 if (idx < m_infos.size()) 1046 { 1047 info = m_infos[idx]; 1048 return true; 1049 } 1050 return false; 1051 } 1052 1053 // You must ensure "idx" is valid before calling this function 1054 const ProcessInstanceInfo & 1055 GetProcessInfoAtIndex (uint32_t idx) const 1056 { 1057 assert (idx < m_infos.size()); 1058 return m_infos[idx]; 1059 } 1060 1061protected: 1062 typedef std::vector<ProcessInstanceInfo> collection; 1063 collection m_infos; 1064}; 1065 1066 1067// This class tracks the Modification state of the process. Things that can currently modify 1068// the program are running the program (which will up the StopID) and writing memory (which 1069// will up the MemoryID.) 1070// FIXME: Should we also include modification of register states? 1071 1072class ProcessModID 1073{ 1074friend bool operator== (const ProcessModID &lhs, const ProcessModID &rhs); 1075public: 1076 ProcessModID () : 1077 m_stop_id (0), 1078 m_resume_id (0), 1079 m_memory_id (0), 1080 m_last_user_expression_resume (0), 1081 m_running_user_expression (false) 1082 {} 1083 1084 ProcessModID (const ProcessModID &rhs) : 1085 m_stop_id (rhs.m_stop_id), 1086 m_memory_id (rhs.m_memory_id) 1087 {} 1088 1089 const ProcessModID & operator= (const ProcessModID &rhs) 1090 { 1091 if (this != &rhs) 1092 { 1093 m_stop_id = rhs.m_stop_id; 1094 m_memory_id = rhs.m_memory_id; 1095 } 1096 return *this; 1097 } 1098 1099 ~ProcessModID () {} 1100 1101 void BumpStopID () { 1102 m_stop_id++; 1103 } 1104 1105 void BumpMemoryID () { m_memory_id++; } 1106 1107 void BumpResumeID () { 1108 m_resume_id++; 1109 if (m_running_user_expression > 0) 1110 m_last_user_expression_resume = m_resume_id; 1111 } 1112 1113 uint32_t GetStopID() const { return m_stop_id; } 1114 uint32_t GetMemoryID () const { return m_memory_id; } 1115 uint32_t GetResumeID () const { return m_resume_id; } 1116 uint32_t GetLastUserExpressionResumeID () const { return m_last_user_expression_resume; } 1117 1118 bool MemoryIDEqual (const ProcessModID &compare) const 1119 { 1120 return m_memory_id == compare.m_memory_id; 1121 } 1122 1123 bool StopIDEqual (const ProcessModID &compare) const 1124 { 1125 return m_stop_id == compare.m_stop_id; 1126 } 1127 1128 void SetInvalid () 1129 { 1130 m_stop_id = UINT32_MAX; 1131 } 1132 1133 bool IsValid () const 1134 { 1135 return m_stop_id != UINT32_MAX; 1136 } 1137 1138 void 1139 SetRunningUserExpression (bool on) 1140 { 1141 // REMOVEME printf ("Setting running user expression %s at resume id %d - value: %d.\n", on ? "on" : "off", m_resume_id, m_running_user_expression); 1142 if (on) 1143 m_running_user_expression++; 1144 else 1145 m_running_user_expression--; 1146 } 1147 1148private: 1149 uint32_t m_stop_id; 1150 uint32_t m_resume_id; 1151 uint32_t m_memory_id; 1152 uint32_t m_last_user_expression_resume; 1153 uint32_t m_running_user_expression; 1154}; 1155inline bool operator== (const ProcessModID &lhs, const ProcessModID &rhs) 1156{ 1157 if (lhs.StopIDEqual (rhs) 1158 && lhs.MemoryIDEqual (rhs)) 1159 return true; 1160 else 1161 return false; 1162} 1163 1164inline bool operator!= (const ProcessModID &lhs, const ProcessModID &rhs) 1165{ 1166 if (!lhs.StopIDEqual (rhs) 1167 || !lhs.MemoryIDEqual (rhs)) 1168 return true; 1169 else 1170 return false; 1171} 1172 1173class MemoryRegionInfo 1174{ 1175public: 1176 typedef Range<lldb::addr_t, lldb::addr_t> RangeType; 1177 1178 enum OptionalBool { 1179 eDontKnow = -1, 1180 eNo = 0, 1181 eYes = 1 1182 }; 1183 1184 MemoryRegionInfo () : 1185 m_range (), 1186 m_read (eDontKnow), 1187 m_write (eDontKnow), 1188 m_execute (eDontKnow) 1189 { 1190 } 1191 1192 ~MemoryRegionInfo () 1193 { 1194 } 1195 1196 RangeType & 1197 GetRange() 1198 { 1199 return m_range; 1200 } 1201 1202 void 1203 Clear() 1204 { 1205 m_range.Clear(); 1206 m_read = m_write = m_execute = eDontKnow; 1207 } 1208 1209 const RangeType & 1210 GetRange() const 1211 { 1212 return m_range; 1213 } 1214 1215 OptionalBool 1216 GetReadable () const 1217 { 1218 return m_read; 1219 } 1220 1221 OptionalBool 1222 GetWritable () const 1223 { 1224 return m_write; 1225 } 1226 1227 OptionalBool 1228 GetExecutable () const 1229 { 1230 return m_execute; 1231 } 1232 1233 void 1234 SetReadable (OptionalBool val) 1235 { 1236 m_read = val; 1237 } 1238 1239 void 1240 SetWritable (OptionalBool val) 1241 { 1242 m_write = val; 1243 } 1244 1245 void 1246 SetExecutable (OptionalBool val) 1247 { 1248 m_execute = val; 1249 } 1250 1251protected: 1252 RangeType m_range; 1253 OptionalBool m_read; 1254 OptionalBool m_write; 1255 OptionalBool m_execute; 1256}; 1257 1258//---------------------------------------------------------------------- 1259/// @class Process Process.h "lldb/Target/Process.h" 1260/// @brief A plug-in interface definition class for debugging a process. 1261//---------------------------------------------------------------------- 1262class Process : 1263 public STD_ENABLE_SHARED_FROM_THIS(Process), 1264 public UserID, 1265 public Broadcaster, 1266 public ExecutionContextScope, 1267 public PluginInterface, 1268 public ProcessInstanceSettings 1269{ 1270friend class ThreadList; 1271friend class ClangFunction; // For WaitForStateChangeEventsPrivate 1272friend class CommandObjectProcessLaunch; 1273friend class ProcessEventData; 1274friend class CommandObjectBreakpointCommand; 1275friend class StopInfo; 1276 1277public: 1278 1279 //------------------------------------------------------------------ 1280 /// Broadcaster event bits definitions. 1281 //------------------------------------------------------------------ 1282 enum 1283 { 1284 eBroadcastBitStateChanged = (1 << 0), 1285 eBroadcastBitInterrupt = (1 << 1), 1286 eBroadcastBitSTDOUT = (1 << 2), 1287 eBroadcastBitSTDERR = (1 << 3) 1288 }; 1289 1290 enum 1291 { 1292 eBroadcastInternalStateControlStop = (1<<0), 1293 eBroadcastInternalStateControlPause = (1<<1), 1294 eBroadcastInternalStateControlResume = (1<<2) 1295 }; 1296 1297 typedef Range<lldb::addr_t, lldb::addr_t> LoadRange; 1298 1299 // These two functions fill out the Broadcaster interface: 1300 1301 static ConstString &GetStaticBroadcasterClass (); 1302 1303 virtual ConstString &GetBroadcasterClass() const 1304 { 1305 return GetStaticBroadcasterClass(); 1306 } 1307 1308 //------------------------------------------------------------------ 1309 /// A notification structure that can be used by clients to listen 1310 /// for changes in a process's lifetime. 1311 /// 1312 /// @see RegisterNotificationCallbacks (const Notifications&) 1313 /// @see UnregisterNotificationCallbacks (const Notifications&) 1314 //------------------------------------------------------------------ 1315#ifndef SWIG 1316 typedef struct 1317 { 1318 void *baton; 1319 void (*initialize)(void *baton, Process *process); 1320 void (*process_state_changed) (void *baton, Process *process, lldb::StateType state); 1321 } Notifications; 1322 1323 class ProcessEventData : 1324 public EventData 1325 { 1326 friend class Process; 1327 1328 public: 1329 ProcessEventData (); 1330 ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state); 1331 1332 virtual ~ProcessEventData(); 1333 1334 static const ConstString & 1335 GetFlavorString (); 1336 1337 virtual const ConstString & 1338 GetFlavor () const; 1339 1340 const lldb::ProcessSP & 1341 GetProcessSP() const 1342 { 1343 return m_process_sp; 1344 } 1345 lldb::StateType 1346 GetState() const 1347 { 1348 return m_state; 1349 } 1350 bool 1351 GetRestarted () const 1352 { 1353 return m_restarted; 1354 } 1355 bool 1356 GetInterrupted () const 1357 { 1358 return m_interrupted; 1359 } 1360 1361 virtual void 1362 Dump (Stream *s) const; 1363 1364 virtual void 1365 DoOnRemoval (Event *event_ptr); 1366 1367 static const Process::ProcessEventData * 1368 GetEventDataFromEvent (const Event *event_ptr); 1369 1370 static lldb::ProcessSP 1371 GetProcessFromEvent (const Event *event_ptr); 1372 1373 static lldb::StateType 1374 GetStateFromEvent (const Event *event_ptr); 1375 1376 static bool 1377 GetRestartedFromEvent (const Event *event_ptr); 1378 1379 static void 1380 SetRestartedInEvent (Event *event_ptr, bool new_value); 1381 1382 static bool 1383 GetInterruptedFromEvent (const Event *event_ptr); 1384 1385 static void 1386 SetInterruptedInEvent (Event *event_ptr, bool new_value); 1387 1388 static bool 1389 SetUpdateStateOnRemoval (Event *event_ptr); 1390 1391 private: 1392 1393 void 1394 SetUpdateStateOnRemoval() 1395 { 1396 m_update_state++; 1397 } 1398 void 1399 SetRestarted (bool new_value) 1400 { 1401 m_restarted = new_value; 1402 } 1403 void 1404 SetInterrupted (bool new_value) 1405 { 1406 m_interrupted = new_value; 1407 } 1408 1409 lldb::ProcessSP m_process_sp; 1410 lldb::StateType m_state; 1411 bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted. 1412 int m_update_state; 1413 bool m_interrupted; 1414 DISALLOW_COPY_AND_ASSIGN (ProcessEventData); 1415 1416 }; 1417 1418 class SettingsController : public UserSettingsController 1419 { 1420 public: 1421 1422 SettingsController (); 1423 1424 virtual 1425 ~SettingsController (); 1426 1427 static SettingEntry global_settings_table[]; 1428 static SettingEntry instance_settings_table[]; 1429 1430 protected: 1431 1432 lldb::InstanceSettingsSP 1433 CreateInstanceSettings (const char *instance_name); 1434 1435 private: 1436 1437 // Class-wide settings. 1438 1439 DISALLOW_COPY_AND_ASSIGN (SettingsController); 1440 }; 1441 1442 1443#endif 1444 1445 static void 1446 SettingsInitialize (); 1447 1448 static void 1449 SettingsTerminate (); 1450 1451 static lldb::UserSettingsControllerSP & 1452 GetSettingsController (); 1453 1454 void 1455 UpdateInstanceName (); 1456 1457 1458 //------------------------------------------------------------------ 1459 /// Construct with a shared pointer to a target, and the Process listener. 1460 //------------------------------------------------------------------ 1461 Process(Target &target, Listener &listener); 1462 1463 //------------------------------------------------------------------ 1464 /// Destructor. 1465 /// 1466 /// The destructor is virtual since this class is designed to be 1467 /// inherited from by the plug-in instance. 1468 //------------------------------------------------------------------ 1469 virtual 1470 ~Process(); 1471 1472 //------------------------------------------------------------------ 1473 /// Find a Process plug-in that can debug \a module using the 1474 /// currently selected architecture. 1475 /// 1476 /// Scans all loaded plug-in interfaces that implement versions of 1477 /// the Process plug-in interface and returns the first instance 1478 /// that can debug the file. 1479 /// 1480 /// @param[in] module_sp 1481 /// The module shared pointer that this process will debug. 1482 /// 1483 /// @param[in] plugin_name 1484 /// If NULL, select the best plug-in for the binary. If non-NULL 1485 /// then look for a plugin whose PluginInfo's name matches 1486 /// this string. 1487 /// 1488 /// @see Process::CanDebug () 1489 //------------------------------------------------------------------ 1490 static lldb::ProcessSP 1491 FindPlugin (Target &target, 1492 const char *plugin_name, 1493 Listener &listener, 1494 const FileSpec *crash_file_path); 1495 1496 1497 1498 //------------------------------------------------------------------ 1499 /// Static function that can be used with the \b host function 1500 /// Host::StartMonitoringChildProcess (). 1501 /// 1502 /// This function can be used by lldb_private::Process subclasses 1503 /// when they want to watch for a local process and have its exit 1504 /// status automatically set when the host child process exits. 1505 /// Subclasses should call Host::StartMonitoringChildProcess () 1506 /// with: 1507 /// callback = Process::SetHostProcessExitStatus 1508 /// callback_baton = NULL 1509 /// pid = Process::GetID() 1510 /// monitor_signals = false 1511 //------------------------------------------------------------------ 1512 static bool 1513 SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL 1514 lldb::pid_t pid, // The process ID we want to monitor 1515 bool exited, 1516 int signo, // Zero for no signal 1517 int status); // Exit value of process if signal is zero 1518 1519 lldb::ByteOrder 1520 GetByteOrder () const; 1521 1522 uint32_t 1523 GetAddressByteSize () const; 1524 1525 //------------------------------------------------------------------ 1526 /// Check if a plug-in instance can debug the file in \a module. 1527 /// 1528 /// Each plug-in is given a chance to say whether it can debug 1529 /// the file in \a module. If the Process plug-in instance can 1530 /// debug a file on the current system, it should return \b true. 1531 /// 1532 /// @return 1533 /// Returns \b true if this Process plug-in instance can 1534 /// debug the executable, \b false otherwise. 1535 //------------------------------------------------------------------ 1536 virtual bool 1537 CanDebug (Target &target, 1538 bool plugin_specified_by_name) = 0; 1539 1540 1541 //------------------------------------------------------------------ 1542 /// This object is about to be destroyed, do any necessary cleanup. 1543 /// 1544 /// Subclasses that override this method should always call this 1545 /// superclass method. 1546 //------------------------------------------------------------------ 1547 virtual void 1548 Finalize(); 1549 1550 //------------------------------------------------------------------ 1551 /// Launch a new process. 1552 /// 1553 /// Launch a new process by spawning a new process using the 1554 /// target object's executable module's file as the file to launch. 1555 /// Arguments are given in \a argv, and the environment variables 1556 /// are in \a envp. Standard input and output files can be 1557 /// optionally re-directed to \a stdin_path, \a stdout_path, and 1558 /// \a stderr_path. 1559 /// 1560 /// This function is not meant to be overridden by Process 1561 /// subclasses. It will first call Process::WillLaunch (Module *) 1562 /// and if that returns \b true, Process::DoLaunch (Module*, 1563 /// char const *[],char const *[],const char *,const char *, 1564 /// const char *) will be called to actually do the launching. If 1565 /// DoLaunch returns \b true, then Process::DidLaunch() will be 1566 /// called. 1567 /// 1568 /// @param[in] argv 1569 /// The argument array. 1570 /// 1571 /// @param[in] envp 1572 /// The environment array. 1573 /// 1574 /// @param[in] launch_flags 1575 /// Flags to modify the launch (@see lldb::LaunchFlags) 1576 /// 1577 /// @param[in] stdin_path 1578 /// The path to use when re-directing the STDIN of the new 1579 /// process. If all stdXX_path arguments are NULL, a pseudo 1580 /// terminal will be used. 1581 /// 1582 /// @param[in] stdout_path 1583 /// The path to use when re-directing the STDOUT of the new 1584 /// process. If all stdXX_path arguments are NULL, a pseudo 1585 /// terminal will be used. 1586 /// 1587 /// @param[in] stderr_path 1588 /// The path to use when re-directing the STDERR of the new 1589 /// process. If all stdXX_path arguments are NULL, a pseudo 1590 /// terminal will be used. 1591 /// 1592 /// @param[in] working_directory 1593 /// The working directory to have the child process run in 1594 /// 1595 /// @return 1596 /// An error object. Call GetID() to get the process ID if 1597 /// the error object is success. 1598 //------------------------------------------------------------------ 1599 virtual Error 1600 Launch (const ProcessLaunchInfo &launch_info); 1601 1602 virtual Error 1603 LoadCore (); 1604 1605 virtual Error 1606 DoLoadCore () 1607 { 1608 Error error; 1609 error.SetErrorStringWithFormat("error: %s does not support loading core files.", GetShortPluginName()); 1610 return error; 1611 } 1612 1613 //------------------------------------------------------------------ 1614 /// Get the dynamic loader plug-in for this process. 1615 /// 1616 /// The default action is to let the DynamicLoader plug-ins check 1617 /// the main executable and the DynamicLoader will select itself 1618 /// automatically. Subclasses can override this if inspecting the 1619 /// executable is not desired, or if Process subclasses can only 1620 /// use a specific DynamicLoader plug-in. 1621 //------------------------------------------------------------------ 1622 virtual DynamicLoader * 1623 GetDynamicLoader (); 1624 1625 //------------------------------------------------------------------ 1626 /// Attach to an existing process using the process attach info. 1627 /// 1628 /// This function is not meant to be overridden by Process 1629 /// subclasses. It will first call WillAttach (lldb::pid_t) 1630 /// or WillAttach (const char *), and if that returns \b 1631 /// true, DoAttach (lldb::pid_t) or DoAttach (const char *) will 1632 /// be called to actually do the attach. If DoAttach returns \b 1633 /// true, then Process::DidAttach() will be called. 1634 /// 1635 /// @param[in] pid 1636 /// The process ID that we should attempt to attach to. 1637 /// 1638 /// @return 1639 /// Returns \a pid if attaching was successful, or 1640 /// LLDB_INVALID_PROCESS_ID if attaching fails. 1641 //------------------------------------------------------------------ 1642 virtual Error 1643 Attach (ProcessAttachInfo &attach_info); 1644 1645 virtual Error 1646 ConnectRemote (const char *remote_url); 1647 1648 bool 1649 GetShouldDetach () const 1650 { 1651 return m_should_detach; 1652 } 1653 1654 void 1655 SetShouldDetach (bool b) 1656 { 1657 m_should_detach = b; 1658 } 1659 1660 //------------------------------------------------------------------ 1661 /// Get the image information address for the current process. 1662 /// 1663 /// Some runtimes have system functions that can help dynamic 1664 /// loaders locate the dynamic loader information needed to observe 1665 /// shared libraries being loaded or unloaded. This function is 1666 /// in the Process interface (as opposed to the DynamicLoader 1667 /// interface) to ensure that remote debugging can take advantage of 1668 /// this functionality. 1669 /// 1670 /// @return 1671 /// The address of the dynamic loader information, or 1672 /// LLDB_INVALID_ADDRESS if this is not supported by this 1673 /// interface. 1674 //------------------------------------------------------------------ 1675 virtual lldb::addr_t 1676 GetImageInfoAddress (); 1677 1678 //------------------------------------------------------------------ 1679 /// Load a shared library into this process. 1680 /// 1681 /// Try and load a shared library into the current process. This 1682 /// call might fail in the dynamic loader plug-in says it isn't safe 1683 /// to try and load shared libraries at the moment. 1684 /// 1685 /// @param[in] image_spec 1686 /// The image file spec that points to the shared library that 1687 /// you want to load. 1688 /// 1689 /// @param[out] error 1690 /// An error object that gets filled in with any errors that 1691 /// might occur when trying to load the shared library. 1692 /// 1693 /// @return 1694 /// A token that represents the shared library that can be 1695 /// later used to unload the shared library. A value of 1696 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 1697 /// library can't be opened. 1698 //------------------------------------------------------------------ 1699 virtual uint32_t 1700 LoadImage (const FileSpec &image_spec, Error &error); 1701 1702 virtual Error 1703 UnloadImage (uint32_t image_token); 1704 1705 //------------------------------------------------------------------ 1706 /// Register for process and thread notifications. 1707 /// 1708 /// Clients can register nofication callbacks by filling out a 1709 /// Process::Notifications structure and calling this function. 1710 /// 1711 /// @param[in] callbacks 1712 /// A structure that contains the notification baton and 1713 /// callback functions. 1714 /// 1715 /// @see Process::Notifications 1716 //------------------------------------------------------------------ 1717#ifndef SWIG 1718 void 1719 RegisterNotificationCallbacks (const Process::Notifications& callbacks); 1720#endif 1721 //------------------------------------------------------------------ 1722 /// Unregister for process and thread notifications. 1723 /// 1724 /// Clients can unregister nofication callbacks by passing a copy of 1725 /// the original baton and callbacks in \a callbacks. 1726 /// 1727 /// @param[in] callbacks 1728 /// A structure that contains the notification baton and 1729 /// callback functions. 1730 /// 1731 /// @return 1732 /// Returns \b true if the notification callbacks were 1733 /// successfully removed from the process, \b false otherwise. 1734 /// 1735 /// @see Process::Notifications 1736 //------------------------------------------------------------------ 1737#ifndef SWIG 1738 bool 1739 UnregisterNotificationCallbacks (const Process::Notifications& callbacks); 1740#endif 1741 //================================================================== 1742 // Built in Process Control functions 1743 //================================================================== 1744 //------------------------------------------------------------------ 1745 /// Resumes all of a process's threads as configured using the 1746 /// Thread run control functions. 1747 /// 1748 /// Threads for a process should be updated with one of the run 1749 /// control actions (resume, step, or suspend) that they should take 1750 /// when the process is resumed. If no run control action is given 1751 /// to a thread it will be resumed by default. 1752 /// 1753 /// This function is not meant to be overridden by Process 1754 /// subclasses. This function will take care of disabling any 1755 /// breakpoints that threads may be stopped at, single stepping, and 1756 /// re-enabling breakpoints, and enabling the basic flow control 1757 /// that the plug-in instances need not worry about. 1758 /// 1759 /// @return 1760 /// Returns an error object. 1761 /// 1762 /// @see Thread:Resume() 1763 /// @see Thread:Step() 1764 /// @see Thread:Suspend() 1765 //------------------------------------------------------------------ 1766 Error 1767 Resume (); 1768 1769 //------------------------------------------------------------------ 1770 /// Halts a running process. 1771 /// 1772 /// This function is not meant to be overridden by Process 1773 /// subclasses. 1774 /// If the process is successfully halted, a eStateStopped 1775 /// process event with GetInterrupted will be broadcast. If false, we will 1776 /// halt the process with no events generated by the halt. 1777 /// 1778 /// @return 1779 /// Returns an error object. If the error is empty, the process is halted. 1780 /// otherwise the halt has failed. 1781 //------------------------------------------------------------------ 1782 Error 1783 Halt (); 1784 1785 //------------------------------------------------------------------ 1786 /// Detaches from a running or stopped process. 1787 /// 1788 /// This function is not meant to be overridden by Process 1789 /// subclasses. 1790 /// 1791 /// @return 1792 /// Returns an error object. 1793 //------------------------------------------------------------------ 1794 Error 1795 Detach (); 1796 1797 //------------------------------------------------------------------ 1798 /// Kills the process and shuts down all threads that were spawned 1799 /// to track and monitor the process. 1800 /// 1801 /// This function is not meant to be overridden by Process 1802 /// subclasses. 1803 /// 1804 /// @return 1805 /// Returns an error object. 1806 //------------------------------------------------------------------ 1807 Error 1808 Destroy(); 1809 1810 //------------------------------------------------------------------ 1811 /// Sends a process a UNIX signal \a signal. 1812 /// 1813 /// This function is not meant to be overridden by Process 1814 /// subclasses. 1815 /// 1816 /// @return 1817 /// Returns an error object. 1818 //------------------------------------------------------------------ 1819 Error 1820 Signal (int signal); 1821 1822 virtual UnixSignals & 1823 GetUnixSignals () 1824 { 1825 return m_unix_signals; 1826 } 1827 1828 //================================================================== 1829 // Plug-in Process Control Overrides 1830 //================================================================== 1831 1832 //------------------------------------------------------------------ 1833 /// Called before attaching to a process. 1834 /// 1835 /// Allow Process plug-ins to execute some code before attaching a 1836 /// process. 1837 /// 1838 /// @return 1839 /// Returns an error object. 1840 //------------------------------------------------------------------ 1841 virtual Error 1842 WillAttachToProcessWithID (lldb::pid_t pid) 1843 { 1844 return Error(); 1845 } 1846 1847 //------------------------------------------------------------------ 1848 /// Called before attaching to a process. 1849 /// 1850 /// Allow Process plug-ins to execute some code before attaching a 1851 /// process. 1852 /// 1853 /// @return 1854 /// Returns an error object. 1855 //------------------------------------------------------------------ 1856 virtual Error 1857 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) 1858 { 1859 return Error(); 1860 } 1861 1862 virtual Error 1863 DoConnectRemote (const char *remote_url) 1864 { 1865 Error error; 1866 error.SetErrorString ("remote connections are not supported"); 1867 return error; 1868 } 1869 1870 //------------------------------------------------------------------ 1871 /// Attach to an existing process using a process ID. 1872 /// 1873 /// @param[in] pid 1874 /// The process ID that we should attempt to attach to. 1875 /// 1876 /// @return 1877 /// Returns \a pid if attaching was successful, or 1878 /// LLDB_INVALID_PROCESS_ID if attaching fails. 1879 //------------------------------------------------------------------ 1880 virtual Error 1881 DoAttachToProcessWithID (lldb::pid_t pid) 1882 { 1883 Error error; 1884 error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetShortPluginName()); 1885 return error; 1886 } 1887 1888 //------------------------------------------------------------------ 1889 /// Attach to an existing process using a process ID. 1890 /// 1891 /// @param[in] pid 1892 /// The process ID that we should attempt to attach to. 1893 /// 1894 /// @param[in] attach_info 1895 /// Information on how to do the attach. For example, GetUserID() 1896 /// will return the uid to attach as. 1897 /// 1898 /// @return 1899 /// Returns \a pid if attaching was successful, or 1900 /// LLDB_INVALID_PROCESS_ID if attaching fails. 1901 /// hanming : need flag 1902 //------------------------------------------------------------------ 1903 virtual Error 1904 DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info) 1905 { 1906 Error error; 1907 error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetShortPluginName()); 1908 return error; 1909 } 1910 1911 //------------------------------------------------------------------ 1912 /// Attach to an existing process using a partial process name. 1913 /// 1914 /// @param[in] process_name 1915 /// The name of the process to attach to. 1916 /// 1917 /// @param[in] wait_for_launch 1918 /// If \b true, wait for the process to be launched and attach 1919 /// as soon as possible after it does launch. If \b false, then 1920 /// search for a matching process the currently exists. 1921 /// 1922 /// @param[in] attach_info 1923 /// Information on how to do the attach. For example, GetUserID() 1924 /// will return the uid to attach as. 1925 /// 1926 /// @return 1927 /// Returns \a pid if attaching was successful, or 1928 /// LLDB_INVALID_PROCESS_ID if attaching fails. 1929 //------------------------------------------------------------------ 1930 virtual Error 1931 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info) 1932 { 1933 Error error; 1934 error.SetErrorString("attach by name is not supported"); 1935 return error; 1936 } 1937 1938 //------------------------------------------------------------------ 1939 /// Called after attaching a process. 1940 /// 1941 /// Allow Process plug-ins to execute some code after attaching to 1942 /// a process. 1943 //------------------------------------------------------------------ 1944 virtual void 1945 DidAttach () {} 1946 1947 1948 //------------------------------------------------------------------ 1949 /// Called before launching to a process. 1950 /// 1951 /// Allow Process plug-ins to execute some code before launching a 1952 /// process. 1953 /// 1954 /// @return 1955 /// Returns an error object. 1956 //------------------------------------------------------------------ 1957 virtual Error 1958 WillLaunch (Module* module) 1959 { 1960 return Error(); 1961 } 1962 1963 //------------------------------------------------------------------ 1964 /// Launch a new process. 1965 /// 1966 /// Launch a new process by spawning a new process using \a module's 1967 /// file as the file to launch. Arguments are given in \a argv, 1968 /// and the environment variables are in \a envp. Standard input 1969 /// and output files can be optionally re-directed to \a stdin_path, 1970 /// \a stdout_path, and \a stderr_path. 1971 /// 1972 /// @param[in] module 1973 /// The module from which to extract the file specification and 1974 /// launch. 1975 /// 1976 /// @param[in] argv 1977 /// The argument array. 1978 /// 1979 /// @param[in] envp 1980 /// The environment array. 1981 /// 1982 /// @param[in] launch_flags 1983 /// Flags to modify the launch (@see lldb::LaunchFlags) 1984 /// 1985 /// @param[in] stdin_path 1986 /// The path to use when re-directing the STDIN of the new 1987 /// process. If all stdXX_path arguments are NULL, a pseudo 1988 /// terminal will be used. 1989 /// 1990 /// @param[in] stdout_path 1991 /// The path to use when re-directing the STDOUT of the new 1992 /// process. If all stdXX_path arguments are NULL, a pseudo 1993 /// terminal will be used. 1994 /// 1995 /// @param[in] stderr_path 1996 /// The path to use when re-directing the STDERR of the new 1997 /// process. If all stdXX_path arguments are NULL, a pseudo 1998 /// terminal will be used. 1999 /// 2000 /// @param[in] working_directory 2001 /// The working directory to have the child process run in 2002 /// 2003 /// @return 2004 /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if 2005 /// launching fails. 2006 //------------------------------------------------------------------ 2007 virtual Error 2008 DoLaunch (Module *exe_module, 2009 const ProcessLaunchInfo &launch_info) 2010 { 2011 Error error; 2012 error.SetErrorStringWithFormat("error: %s does not support launching processes", GetShortPluginName()); 2013 return error; 2014 } 2015 2016 2017 //------------------------------------------------------------------ 2018 /// Called after launching a process. 2019 /// 2020 /// Allow Process plug-ins to execute some code after launching 2021 /// a process. 2022 //------------------------------------------------------------------ 2023 virtual void 2024 DidLaunch () {} 2025 2026 2027 2028 //------------------------------------------------------------------ 2029 /// Called before resuming to a process. 2030 /// 2031 /// Allow Process plug-ins to execute some code before resuming a 2032 /// process. 2033 /// 2034 /// @return 2035 /// Returns an error object. 2036 //------------------------------------------------------------------ 2037 virtual Error 2038 WillResume () { return Error(); } 2039 2040 //------------------------------------------------------------------ 2041 /// Resumes all of a process's threads as configured using the 2042 /// Thread run control functions. 2043 /// 2044 /// Threads for a process should be updated with one of the run 2045 /// control actions (resume, step, or suspend) that they should take 2046 /// when the process is resumed. If no run control action is given 2047 /// to a thread it will be resumed by default. 2048 /// 2049 /// @return 2050 /// Returns \b true if the process successfully resumes using 2051 /// the thread run control actions, \b false otherwise. 2052 /// 2053 /// @see Thread:Resume() 2054 /// @see Thread:Step() 2055 /// @see Thread:Suspend() 2056 //------------------------------------------------------------------ 2057 virtual Error 2058 DoResume () 2059 { 2060 Error error; 2061 error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetShortPluginName()); 2062 return error; 2063 } 2064 2065 2066 //------------------------------------------------------------------ 2067 /// Called after resuming a process. 2068 /// 2069 /// Allow Process plug-ins to execute some code after resuming 2070 /// a process. 2071 //------------------------------------------------------------------ 2072 virtual void 2073 DidResume () {} 2074 2075 2076 //------------------------------------------------------------------ 2077 /// Called before halting to a process. 2078 /// 2079 /// Allow Process plug-ins to execute some code before halting a 2080 /// process. 2081 /// 2082 /// @return 2083 /// Returns an error object. 2084 //------------------------------------------------------------------ 2085 virtual Error 2086 WillHalt () { return Error(); } 2087 2088 //------------------------------------------------------------------ 2089 /// Halts a running process. 2090 /// 2091 /// DoHalt must produce one and only one stop StateChanged event if it actually 2092 /// stops the process. If the stop happens through some natural event (for 2093 /// instance a SIGSTOP), then forwarding that event will do. Otherwise, you must 2094 /// generate the event manually. Note also, the private event thread is stopped when 2095 /// DoHalt is run to prevent the events generated while halting to trigger 2096 /// other state changes before the halt is complete. 2097 /// 2098 /// @param[out] caused_stop 2099 /// If true, then this Halt caused the stop, otherwise, the 2100 /// process was already stopped. 2101 /// 2102 /// @return 2103 /// Returns \b true if the process successfully halts, \b false 2104 /// otherwise. 2105 //------------------------------------------------------------------ 2106 virtual Error 2107 DoHalt (bool &caused_stop) 2108 { 2109 Error error; 2110 error.SetErrorStringWithFormat("error: %s does not support halting processes", GetShortPluginName()); 2111 return error; 2112 } 2113 2114 2115 //------------------------------------------------------------------ 2116 /// Called after halting a process. 2117 /// 2118 /// Allow Process plug-ins to execute some code after halting 2119 /// a process. 2120 //------------------------------------------------------------------ 2121 virtual void 2122 DidHalt () {} 2123 2124 //------------------------------------------------------------------ 2125 /// Called before detaching from a process. 2126 /// 2127 /// Allow Process plug-ins to execute some code before detaching 2128 /// from a process. 2129 /// 2130 /// @return 2131 /// Returns an error object. 2132 //------------------------------------------------------------------ 2133 virtual Error 2134 WillDetach () 2135 { 2136 return Error(); 2137 } 2138 2139 //------------------------------------------------------------------ 2140 /// Detaches from a running or stopped process. 2141 /// 2142 /// @return 2143 /// Returns \b true if the process successfully detaches, \b 2144 /// false otherwise. 2145 //------------------------------------------------------------------ 2146 virtual Error 2147 DoDetach () 2148 { 2149 Error error; 2150 error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetShortPluginName()); 2151 return error; 2152 } 2153 2154 2155 //------------------------------------------------------------------ 2156 /// Called after detaching from a process. 2157 /// 2158 /// Allow Process plug-ins to execute some code after detaching 2159 /// from a process. 2160 //------------------------------------------------------------------ 2161 virtual void 2162 DidDetach () {} 2163 2164 //------------------------------------------------------------------ 2165 /// Called before sending a signal to a process. 2166 /// 2167 /// Allow Process plug-ins to execute some code before sending a 2168 /// signal to a process. 2169 /// 2170 /// @return 2171 /// Returns no error if it is safe to proceed with a call to 2172 /// Process::DoSignal(int), otherwise an error describing what 2173 /// prevents the signal from being sent. 2174 //------------------------------------------------------------------ 2175 virtual Error 2176 WillSignal () { return Error(); } 2177 2178 //------------------------------------------------------------------ 2179 /// Sends a process a UNIX signal \a signal. 2180 /// 2181 /// @return 2182 /// Returns an error object. 2183 //------------------------------------------------------------------ 2184 virtual Error 2185 DoSignal (int signal) 2186 { 2187 Error error; 2188 error.SetErrorStringWithFormat("error: %s does not support senging signals to processes", GetShortPluginName()); 2189 return error; 2190 } 2191 2192 virtual Error 2193 WillDestroy () { return Error(); } 2194 2195 virtual Error 2196 DoDestroy () = 0; 2197 2198 virtual void 2199 DidDestroy () { } 2200 2201 2202 //------------------------------------------------------------------ 2203 /// Called after sending a signal to a process. 2204 /// 2205 /// Allow Process plug-ins to execute some code after sending a 2206 /// signal to a process. 2207 //------------------------------------------------------------------ 2208 virtual void 2209 DidSignal () {} 2210 2211 //------------------------------------------------------------------ 2212 /// Currently called as part of ShouldStop. 2213 /// FIXME: Should really happen when the target stops before the 2214 /// event is taken from the queue... 2215 /// 2216 /// This callback is called as the event 2217 /// is about to be queued up to allow Process plug-ins to execute 2218 /// some code prior to clients being notified that a process was 2219 /// stopped. Common operations include updating the thread list, 2220 /// invalidating any thread state (registers, stack, etc) prior to 2221 /// letting the notification go out. 2222 /// 2223 //------------------------------------------------------------------ 2224 virtual void 2225 RefreshStateAfterStop () = 0; 2226 2227 //------------------------------------------------------------------ 2228 /// Get the target object pointer for this module. 2229 /// 2230 /// @return 2231 /// A Target object pointer to the target that owns this 2232 /// module. 2233 //------------------------------------------------------------------ 2234 Target & 2235 GetTarget () 2236 { 2237 return m_target; 2238 } 2239 2240 //------------------------------------------------------------------ 2241 /// Get the const target object pointer for this module. 2242 /// 2243 /// @return 2244 /// A const Target object pointer to the target that owns this 2245 /// module. 2246 //------------------------------------------------------------------ 2247 const Target & 2248 GetTarget () const 2249 { 2250 return m_target; 2251 } 2252 2253 2254 //------------------------------------------------------------------ 2255 /// Get accessor for the current process state. 2256 /// 2257 /// @return 2258 /// The current state of the process. 2259 /// 2260 /// @see lldb::StateType 2261 //------------------------------------------------------------------ 2262 lldb::StateType 2263 GetState (); 2264 2265 ExecutionResults 2266 RunThreadPlan (ExecutionContext &exe_ctx, 2267 lldb::ThreadPlanSP &thread_plan_sp, 2268 bool stop_others, 2269 bool try_all_threads, 2270 bool discard_on_error, 2271 uint32_t single_thread_timeout_usec, 2272 Stream &errors); 2273 2274 static const char * 2275 ExecutionResultAsCString (ExecutionResults result); 2276 2277 void 2278 GetStatus (Stream &ostrm); 2279 2280 size_t 2281 GetThreadStatus (Stream &ostrm, 2282 bool only_threads_with_stop_reason, 2283 uint32_t start_frame, 2284 uint32_t num_frames, 2285 uint32_t num_frames_with_source); 2286 2287protected: 2288 2289 void 2290 SetState (lldb::EventSP &event_sp); 2291 2292 lldb::StateType 2293 GetPrivateState (); 2294 2295 //------------------------------------------------------------------ 2296 // Called internally 2297 //------------------------------------------------------------------ 2298 void 2299 CompleteAttach (); 2300 2301public: 2302 //------------------------------------------------------------------ 2303 /// Get the exit status for a process. 2304 /// 2305 /// @return 2306 /// The process's return code, or -1 if the current process 2307 /// state is not eStateExited. 2308 //------------------------------------------------------------------ 2309 int 2310 GetExitStatus (); 2311 2312 //------------------------------------------------------------------ 2313 /// Get a textual description of what the process exited. 2314 /// 2315 /// @return 2316 /// The textual description of why the process exited, or NULL 2317 /// if there is no description available. 2318 //------------------------------------------------------------------ 2319 const char * 2320 GetExitDescription (); 2321 2322 2323 virtual void 2324 DidExit () 2325 { 2326 } 2327 2328 //------------------------------------------------------------------ 2329 /// Get the Modification ID of the process. 2330 /// 2331 /// @return 2332 /// The modification ID of the process. 2333 //------------------------------------------------------------------ 2334 ProcessModID 2335 GetModID () const 2336 { 2337 return m_mod_id; 2338 } 2339 2340 const ProcessModID & 2341 GetModIDRef () const 2342 { 2343 return m_mod_id; 2344 } 2345 2346 uint32_t 2347 GetStopID () const 2348 { 2349 return m_mod_id.GetStopID(); 2350 } 2351 2352 uint32_t 2353 GetResumeID () const 2354 { 2355 return m_mod_id.GetResumeID(); 2356 } 2357 2358 uint32_t 2359 GetLastUserExpressionResumeID () const 2360 { 2361 return m_mod_id.GetLastUserExpressionResumeID(); 2362 } 2363 2364 //------------------------------------------------------------------ 2365 /// Set accessor for the process exit status (return code). 2366 /// 2367 /// Sometimes a child exits and the exit can be detected by global 2368 /// functions (signal handler for SIGCHLD for example). This 2369 /// accessor allows the exit status to be set from an external 2370 /// source. 2371 /// 2372 /// Setting this will cause a eStateExited event to be posted to 2373 /// the process event queue. 2374 /// 2375 /// @param[in] exit_status 2376 /// The value for the process's return code. 2377 /// 2378 /// @see lldb::StateType 2379 //------------------------------------------------------------------ 2380 virtual bool 2381 SetExitStatus (int exit_status, const char *cstr); 2382 2383 //------------------------------------------------------------------ 2384 /// Check if a process is still alive. 2385 /// 2386 /// @return 2387 /// Returns \b true if the process is still valid, \b false 2388 /// otherwise. 2389 //------------------------------------------------------------------ 2390 virtual bool 2391 IsAlive () = 0; 2392 2393 //------------------------------------------------------------------ 2394 /// Actually do the reading of memory from a process. 2395 /// 2396 /// Subclasses must override this function and can return fewer 2397 /// bytes than requested when memory requests are too large. This 2398 /// class will break up the memory requests and keep advancing the 2399 /// arguments along as needed. 2400 /// 2401 /// @param[in] vm_addr 2402 /// A virtual load address that indicates where to start reading 2403 /// memory from. 2404 /// 2405 /// @param[in] size 2406 /// The number of bytes to read. 2407 /// 2408 /// @param[out] buf 2409 /// A byte buffer that is at least \a size bytes long that 2410 /// will receive the memory bytes. 2411 /// 2412 /// @return 2413 /// The number of bytes that were actually read into \a buf. 2414 //------------------------------------------------------------------ 2415 virtual size_t 2416 DoReadMemory (lldb::addr_t vm_addr, 2417 void *buf, 2418 size_t size, 2419 Error &error) = 0; 2420 2421 //------------------------------------------------------------------ 2422 /// Read of memory from a process. 2423 /// 2424 /// This function will read memory from the current process's 2425 /// address space and remove any traps that may have been inserted 2426 /// into the memory. 2427 /// 2428 /// This function is not meant to be overridden by Process 2429 /// subclasses, the subclasses should implement 2430 /// Process::DoReadMemory (lldb::addr_t, size_t, void *). 2431 /// 2432 /// @param[in] vm_addr 2433 /// A virtual load address that indicates where to start reading 2434 /// memory from. 2435 /// 2436 /// @param[out] buf 2437 /// A byte buffer that is at least \a size bytes long that 2438 /// will receive the memory bytes. 2439 /// 2440 /// @param[in] size 2441 /// The number of bytes to read. 2442 /// 2443 /// @return 2444 /// The number of bytes that were actually read into \a buf. If 2445 /// the returned number is greater than zero, yet less than \a 2446 /// size, then this function will get called again with \a 2447 /// vm_addr, \a buf, and \a size updated appropriately. Zero is 2448 /// returned to indicate an error. 2449 //------------------------------------------------------------------ 2450 virtual size_t 2451 ReadMemory (lldb::addr_t vm_addr, 2452 void *buf, 2453 size_t size, 2454 Error &error); 2455 2456 //------------------------------------------------------------------ 2457 /// Read a NULL terminated C string from memory 2458 /// 2459 /// This function will read a cache page at a time until the NULL 2460 /// C stirng terminator is found. It will stop reading if the NULL 2461 /// termination byte isn't found before reading \a cstr_max_len 2462 /// bytes, and the results are always guaranteed to be NULL 2463 /// terminated (at most cstr_max_len - 1 bytes will be read). 2464 //------------------------------------------------------------------ 2465 size_t 2466 ReadCStringFromMemory (lldb::addr_t vm_addr, 2467 char *cstr, 2468 size_t cstr_max_len, 2469 Error &error); 2470 2471 size_t 2472 ReadMemoryFromInferior (lldb::addr_t vm_addr, 2473 void *buf, 2474 size_t size, 2475 Error &error); 2476 2477 //------------------------------------------------------------------ 2478 /// Reads an unsigned integer of the specified byte size from 2479 /// process memory. 2480 /// 2481 /// @param[in] load_addr 2482 /// A load address of the integer to read. 2483 /// 2484 /// @param[in] byte_size 2485 /// The size in byte of the integer to read. 2486 /// 2487 /// @param[in] fail_value 2488 /// The value to return if we fail to read an integer. 2489 /// 2490 /// @param[out] error 2491 /// An error that indicates the success or failure of this 2492 /// operation. If error indicates success (error.Success()), 2493 /// then the value returned can be trusted, otherwise zero 2494 /// will be returned. 2495 /// 2496 /// @return 2497 /// The unsigned integer that was read from the process memory 2498 /// space. If the integer was smaller than a uint64_t, any 2499 /// unused upper bytes will be zero filled. If the process 2500 /// byte order differs from the host byte order, the integer 2501 /// value will be appropriately byte swapped into host byte 2502 /// order. 2503 //------------------------------------------------------------------ 2504 uint64_t 2505 ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr, 2506 size_t byte_size, 2507 uint64_t fail_value, 2508 Error &error); 2509 2510 lldb::addr_t 2511 ReadPointerFromMemory (lldb::addr_t vm_addr, 2512 Error &error); 2513 2514 bool 2515 WritePointerToMemory (lldb::addr_t vm_addr, 2516 lldb::addr_t ptr_value, 2517 Error &error); 2518 2519 //------------------------------------------------------------------ 2520 /// Actually do the writing of memory to a process. 2521 /// 2522 /// @param[in] vm_addr 2523 /// A virtual load address that indicates where to start writing 2524 /// memory to. 2525 /// 2526 /// @param[in] buf 2527 /// A byte buffer that is at least \a size bytes long that 2528 /// contains the data to write. 2529 /// 2530 /// @param[in] size 2531 /// The number of bytes to write. 2532 /// 2533 /// @param[out] error 2534 /// An error value in case the memory write fails. 2535 /// 2536 /// @return 2537 /// The number of bytes that were actually written. 2538 //------------------------------------------------------------------ 2539 virtual size_t 2540 DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) 2541 { 2542 error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetShortPluginName()); 2543 return 0; 2544 } 2545 2546 2547 //------------------------------------------------------------------ 2548 /// Write all or part of a scalar value to memory. 2549 /// 2550 /// The value contained in \a scalar will be swapped to match the 2551 /// byte order of the process that is being debugged. If \a size is 2552 /// less than the size of scalar, the least significate \a size bytes 2553 /// from scalar will be written. If \a size is larger than the byte 2554 /// size of scalar, then the extra space will be padded with zeros 2555 /// and the scalar value will be placed in the least significant 2556 /// bytes in memory. 2557 /// 2558 /// @param[in] vm_addr 2559 /// A virtual load address that indicates where to start writing 2560 /// memory to. 2561 /// 2562 /// @param[in] scalar 2563 /// The scalar to write to the debugged process. 2564 /// 2565 /// @param[in] size 2566 /// This value can be smaller or larger than the scalar value 2567 /// itself. If \a size is smaller than the size of \a scalar, 2568 /// the least significant bytes in \a scalar will be used. If 2569 /// \a size is larger than the byte size of \a scalar, then 2570 /// the extra space will be padded with zeros. If \a size is 2571 /// set to UINT32_MAX, then the size of \a scalar will be used. 2572 /// 2573 /// @param[out] error 2574 /// An error value in case the memory write fails. 2575 /// 2576 /// @return 2577 /// The number of bytes that were actually written. 2578 //------------------------------------------------------------------ 2579 size_t 2580 WriteScalarToMemory (lldb::addr_t vm_addr, 2581 const Scalar &scalar, 2582 uint32_t size, 2583 Error &error); 2584 2585 size_t 2586 ReadScalarIntegerFromMemory (lldb::addr_t addr, 2587 uint32_t byte_size, 2588 bool is_signed, 2589 Scalar &scalar, 2590 Error &error); 2591 2592 //------------------------------------------------------------------ 2593 /// Write memory to a process. 2594 /// 2595 /// This function will write memory to the current process's 2596 /// address space and maintain any traps that might be present due 2597 /// to software breakpoints. 2598 /// 2599 /// This function is not meant to be overridden by Process 2600 /// subclasses, the subclasses should implement 2601 /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). 2602 /// 2603 /// @param[in] vm_addr 2604 /// A virtual load address that indicates where to start writing 2605 /// memory to. 2606 /// 2607 /// @param[in] buf 2608 /// A byte buffer that is at least \a size bytes long that 2609 /// contains the data to write. 2610 /// 2611 /// @param[in] size 2612 /// The number of bytes to write. 2613 /// 2614 /// @return 2615 /// The number of bytes that were actually written. 2616 //------------------------------------------------------------------ 2617 size_t 2618 WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); 2619 2620 2621 //------------------------------------------------------------------ 2622 /// Actually allocate memory in the process. 2623 /// 2624 /// This function will allocate memory in the process's address 2625 /// space. This can't rely on the generic function calling mechanism, 2626 /// since that requires this function. 2627 /// 2628 /// @param[in] size 2629 /// The size of the allocation requested. 2630 /// 2631 /// @return 2632 /// The address of the allocated buffer in the process, or 2633 /// LLDB_INVALID_ADDRESS if the allocation failed. 2634 //------------------------------------------------------------------ 2635 2636 virtual lldb::addr_t 2637 DoAllocateMemory (size_t size, uint32_t permissions, Error &error) 2638 { 2639 error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetShortPluginName()); 2640 return LLDB_INVALID_ADDRESS; 2641 } 2642 2643 2644 //------------------------------------------------------------------ 2645 /// The public interface to allocating memory in the process. 2646 /// 2647 /// This function will allocate memory in the process's address 2648 /// space. This can't rely on the generic function calling mechanism, 2649 /// since that requires this function. 2650 /// 2651 /// @param[in] size 2652 /// The size of the allocation requested. 2653 /// 2654 /// @param[in] permissions 2655 /// Or together any of the lldb::Permissions bits. The permissions on 2656 /// a given memory allocation can't be changed after allocation. Note 2657 /// that a block that isn't set writable can still be written on from lldb, 2658 /// just not by the process itself. 2659 /// 2660 /// @param[in/out] error 2661 /// An error object to fill in if things go wrong. 2662 /// @return 2663 /// The address of the allocated buffer in the process, or 2664 /// LLDB_INVALID_ADDRESS if the allocation failed. 2665 //------------------------------------------------------------------ 2666 2667 lldb::addr_t 2668 AllocateMemory (size_t size, uint32_t permissions, Error &error); 2669 2670 virtual Error 2671 GetMemoryRegionInfo (lldb::addr_t load_addr, 2672 MemoryRegionInfo &range_info) 2673 { 2674 Error error; 2675 error.SetErrorString ("Process::GetMemoryRegionInfo() not supported"); 2676 return error; 2677 } 2678 2679 lldb::ModuleSP 2680 ReadModuleFromMemory (const FileSpec& file_spec, 2681 lldb::addr_t header_addr, 2682 bool add_image_to_target, 2683 bool load_sections_in_target); 2684 2685 //------------------------------------------------------------------ 2686 /// Attempt to get the attributes for a region of memory in the process. 2687 /// 2688 /// It may be possible for the remote debug server to inspect attributes 2689 /// for a region of memory in the process, such as whether there is a 2690 /// valid page of memory at a given address or whether that page is 2691 /// readable/writable/executable by the process. 2692 /// 2693 /// @param[in] load_addr 2694 /// The address of interest in the process. 2695 /// 2696 /// @param[out] permissions 2697 /// If this call returns successfully, this bitmask will have 2698 /// its Permissions bits set to indicate whether the region is 2699 /// readable/writable/executable. If this call fails, the 2700 /// bitmask values are undefined. 2701 /// 2702 /// @return 2703 /// Returns true if it was able to determine the attributes of the 2704 /// memory region. False if not. 2705 //------------------------------------------------------------------ 2706 2707 virtual bool 2708 GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions) 2709 { 2710 MemoryRegionInfo range_info; 2711 permissions = 0; 2712 Error error (GetMemoryRegionInfo (load_addr, range_info)); 2713 if (!error.Success()) 2714 return false; 2715 if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow 2716 || range_info.GetWritable() == MemoryRegionInfo::eDontKnow 2717 || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow) 2718 { 2719 return false; 2720 } 2721 2722 if (range_info.GetReadable() == MemoryRegionInfo::eYes) 2723 permissions |= lldb::ePermissionsReadable; 2724 2725 if (range_info.GetWritable() == MemoryRegionInfo::eYes) 2726 permissions |= lldb::ePermissionsWritable; 2727 2728 if (range_info.GetExecutable() == MemoryRegionInfo::eYes) 2729 permissions |= lldb::ePermissionsExecutable; 2730 2731 return true; 2732 } 2733 2734 //------------------------------------------------------------------ 2735 /// Determines whether executing JIT-compiled code in this process 2736 /// is possible. 2737 /// 2738 /// @return 2739 /// True if execution of JIT code is possible; false otherwise. 2740 //------------------------------------------------------------------ 2741 bool CanJIT (); 2742 2743 //------------------------------------------------------------------ 2744 /// Sets whether executing JIT-compiled code in this process 2745 /// is possible. 2746 /// 2747 /// @param[in] can_jit 2748 /// True if execution of JIT code is possible; false otherwise. 2749 //------------------------------------------------------------------ 2750 void SetCanJIT (bool can_jit); 2751 2752 //------------------------------------------------------------------ 2753 /// Actually deallocate memory in the process. 2754 /// 2755 /// This function will deallocate memory in the process's address 2756 /// space that was allocated with AllocateMemory. 2757 /// 2758 /// @param[in] ptr 2759 /// A return value from AllocateMemory, pointing to the memory you 2760 /// want to deallocate. 2761 /// 2762 /// @return 2763 /// \btrue if the memory was deallocated, \bfalse otherwise. 2764 //------------------------------------------------------------------ 2765 2766 virtual Error 2767 DoDeallocateMemory (lldb::addr_t ptr) 2768 { 2769 Error error; 2770 error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetShortPluginName()); 2771 return error; 2772 } 2773 2774 2775 //------------------------------------------------------------------ 2776 /// The public interface to deallocating memory in the process. 2777 /// 2778 /// This function will deallocate memory in the process's address 2779 /// space that was allocated with AllocateMemory. 2780 /// 2781 /// @param[in] ptr 2782 /// A return value from AllocateMemory, pointing to the memory you 2783 /// want to deallocate. 2784 /// 2785 /// @return 2786 /// \btrue if the memory was deallocated, \bfalse otherwise. 2787 //------------------------------------------------------------------ 2788 2789 Error 2790 DeallocateMemory (lldb::addr_t ptr); 2791 2792 //------------------------------------------------------------------ 2793 /// Get any available STDOUT. 2794 /// 2795 /// If the process was launched without supplying valid file paths 2796 /// for stdin, stdout, and stderr, then the Process class might 2797 /// try to cache the STDOUT for the process if it is able. Events 2798 /// will be queued indicating that there is STDOUT available that 2799 /// can be retrieved using this function. 2800 /// 2801 /// @param[out] buf 2802 /// A buffer that will receive any STDOUT bytes that are 2803 /// currently available. 2804 /// 2805 /// @param[out] buf_size 2806 /// The size in bytes for the buffer \a buf. 2807 /// 2808 /// @return 2809 /// The number of bytes written into \a buf. If this value is 2810 /// equal to \a buf_size, another call to this function should 2811 /// be made to retrieve more STDOUT data. 2812 //------------------------------------------------------------------ 2813 virtual size_t 2814 GetSTDOUT (char *buf, size_t buf_size, Error &error); 2815 2816 //------------------------------------------------------------------ 2817 /// Get any available STDERR. 2818 /// 2819 /// If the process was launched without supplying valid file paths 2820 /// for stdin, stdout, and stderr, then the Process class might 2821 /// try to cache the STDERR for the process if it is able. Events 2822 /// will be queued indicating that there is STDERR available that 2823 /// can be retrieved using this function. 2824 /// 2825 /// @param[out] buf 2826 /// A buffer that will receive any STDERR bytes that are 2827 /// currently available. 2828 /// 2829 /// @param[out] buf_size 2830 /// The size in bytes for the buffer \a buf. 2831 /// 2832 /// @return 2833 /// The number of bytes written into \a buf. If this value is 2834 /// equal to \a buf_size, another call to this function should 2835 /// be made to retrieve more STDERR data. 2836 //------------------------------------------------------------------ 2837 virtual size_t 2838 GetSTDERR (char *buf, size_t buf_size, Error &error); 2839 2840 virtual size_t 2841 PutSTDIN (const char *buf, size_t buf_size, Error &error) 2842 { 2843 error.SetErrorString("stdin unsupported"); 2844 return 0; 2845 } 2846 2847 //---------------------------------------------------------------------- 2848 // Process Breakpoints 2849 //---------------------------------------------------------------------- 2850 size_t 2851 GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site); 2852 2853 virtual Error 2854 EnableBreakpoint (BreakpointSite *bp_site) 2855 { 2856 Error error; 2857 error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetShortPluginName()); 2858 return error; 2859 } 2860 2861 2862 virtual Error 2863 DisableBreakpoint (BreakpointSite *bp_site) 2864 { 2865 Error error; 2866 error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetShortPluginName()); 2867 return error; 2868 } 2869 2870 2871 // This is implemented completely using the lldb::Process API. Subclasses 2872 // don't need to implement this function unless the standard flow of 2873 // read existing opcode, write breakpoint opcode, verify breakpoint opcode 2874 // doesn't work for a specific process plug-in. 2875 virtual Error 2876 EnableSoftwareBreakpoint (BreakpointSite *bp_site); 2877 2878 // This is implemented completely using the lldb::Process API. Subclasses 2879 // don't need to implement this function unless the standard flow of 2880 // restoring original opcode in memory and verifying the restored opcode 2881 // doesn't work for a specific process plug-in. 2882 virtual Error 2883 DisableSoftwareBreakpoint (BreakpointSite *bp_site); 2884 2885 BreakpointSiteList & 2886 GetBreakpointSiteList(); 2887 2888 const BreakpointSiteList & 2889 GetBreakpointSiteList() const; 2890 2891 void 2892 DisableAllBreakpointSites (); 2893 2894 Error 2895 ClearBreakpointSiteByID (lldb::user_id_t break_id); 2896 2897 lldb::break_id_t 2898 CreateBreakpointSite (const lldb::BreakpointLocationSP &owner, 2899 bool use_hardware); 2900 2901 Error 2902 DisableBreakpointSiteByID (lldb::user_id_t break_id); 2903 2904 Error 2905 EnableBreakpointSiteByID (lldb::user_id_t break_id); 2906 2907 2908 // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove 2909 // themselves from the owner's list of this breakpoint sites. This has to 2910 // be a static function because you can't be sure that removing the 2911 // breakpoint from it's containing map won't delete the breakpoint site, 2912 // and doing that in an instance method isn't copasetic. 2913 void 2914 RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, 2915 lldb::user_id_t owner_loc_id, 2916 lldb::BreakpointSiteSP &bp_site_sp); 2917 2918 //---------------------------------------------------------------------- 2919 // Process Watchpoints (optional) 2920 //---------------------------------------------------------------------- 2921 virtual Error 2922 EnableWatchpoint (Watchpoint *wp); 2923 2924 virtual Error 2925 DisableWatchpoint (Watchpoint *wp); 2926 2927 //------------------------------------------------------------------ 2928 // Thread Queries 2929 //------------------------------------------------------------------ 2930 virtual uint32_t 2931 UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0; 2932 2933 void 2934 UpdateThreadListIfNeeded (); 2935 2936 ThreadList & 2937 GetThreadList () 2938 { 2939 return m_thread_list; 2940 } 2941 2942 2943 uint32_t 2944 GetNextThreadIndexID (); 2945 2946 //------------------------------------------------------------------ 2947 // Event Handling 2948 //------------------------------------------------------------------ 2949 lldb::StateType 2950 GetNextEvent (lldb::EventSP &event_sp); 2951 2952 lldb::StateType 2953 WaitForProcessToStop (const TimeValue *timeout); 2954 2955 lldb::StateType 2956 WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp); 2957 2958 Event * 2959 PeekAtStateChangedEvents (); 2960 2961 2962 class 2963 ProcessEventHijacker 2964 { 2965 public: 2966 ProcessEventHijacker (Process &process, Listener *listener) : 2967 m_process (process), 2968 m_listener (listener) 2969 { 2970 m_process.HijackProcessEvents (listener); 2971 } 2972 ~ProcessEventHijacker () 2973 { 2974 m_process.RestoreProcessEvents(); 2975 } 2976 2977 private: 2978 Process &m_process; 2979 Listener *m_listener; 2980 }; 2981 friend class ProcessEventHijacker; 2982 //------------------------------------------------------------------ 2983 /// If you need to ensure that you and only you will hear about some public 2984 /// event, then make a new listener, set to listen to process events, and 2985 /// then call this with that listener. Then you will have to wait on that 2986 /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* 2987 /// calls above. Be sure to call RestoreProcessEvents when you are done. 2988 /// 2989 /// @param[in] listener 2990 /// This is the new listener to whom all process events will be delivered. 2991 /// 2992 /// @return 2993 /// Returns \b true if the new listener could be installed, 2994 /// \b false otherwise. 2995 //------------------------------------------------------------------ 2996 bool 2997 HijackProcessEvents (Listener *listener); 2998 2999 //------------------------------------------------------------------ 3000 /// Restores the process event broadcasting to its normal state. 3001 /// 3002 //------------------------------------------------------------------ 3003 void 3004 RestoreProcessEvents (); 3005 3006protected: 3007 //------------------------------------------------------------------ 3008 /// This is the part of the event handling that for a process event. 3009 /// It decides what to do with the event and returns true if the 3010 /// event needs to be propagated to the user, and false otherwise. 3011 /// If the event is not propagated, this call will most likely set 3012 /// the target to executing again. 3013 /// 3014 /// @param[in] event_ptr 3015 /// This is the event we are handling. 3016 /// 3017 /// @return 3018 /// Returns \b true if the event should be reported to the 3019 /// user, \b false otherwise. 3020 //------------------------------------------------------------------ 3021 bool 3022 ShouldBroadcastEvent (Event *event_ptr); 3023 3024public: 3025 const lldb::ABISP & 3026 GetABI (); 3027 3028 OperatingSystem * 3029 GetOperatingSystem () 3030 { 3031 return m_os_ap.get(); 3032 } 3033 3034 3035 virtual LanguageRuntime * 3036 GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true); 3037 3038 virtual CPPLanguageRuntime * 3039 GetCPPLanguageRuntime (bool retry_if_null = true); 3040 3041 virtual ObjCLanguageRuntime * 3042 GetObjCLanguageRuntime (bool retry_if_null = true); 3043 3044 bool 3045 IsRunning () const; 3046 3047 DynamicCheckerFunctions *GetDynamicCheckers() 3048 { 3049 return m_dynamic_checkers_ap.get(); 3050 } 3051 3052 void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) 3053 { 3054 m_dynamic_checkers_ap.reset(dynamic_checkers); 3055 } 3056 3057 //------------------------------------------------------------------ 3058 /// Call this to set the lldb in the mode where it breaks on new thread 3059 /// creations, and then auto-restarts. This is useful when you are trying 3060 /// to run only one thread, but either that thread or the kernel is creating 3061 /// new threads in the process. If you stop when the thread is created, you 3062 /// can immediately suspend it, and keep executing only the one thread you intend. 3063 /// 3064 /// @return 3065 /// Returns \b true if we were able to start up the notification 3066 /// \b false otherwise. 3067 //------------------------------------------------------------------ 3068 virtual bool 3069 StartNoticingNewThreads() 3070 { 3071 return true; 3072 } 3073 3074 //------------------------------------------------------------------ 3075 /// Call this to turn off the stop & notice new threads mode. 3076 /// 3077 /// @return 3078 /// Returns \b true if we were able to start up the notification 3079 /// \b false otherwise. 3080 //------------------------------------------------------------------ 3081 virtual bool 3082 StopNoticingNewThreads() 3083 { 3084 return true; 3085 } 3086 3087 void 3088 SetRunningUserExpression (bool on); 3089 3090 //------------------------------------------------------------------ 3091 // lldb::ExecutionContextScope pure virtual functions 3092 //------------------------------------------------------------------ 3093 virtual lldb::TargetSP 3094 CalculateTarget (); 3095 3096 virtual lldb::ProcessSP 3097 CalculateProcess () 3098 { 3099 return shared_from_this(); 3100 } 3101 3102 virtual lldb::ThreadSP 3103 CalculateThread () 3104 { 3105 return lldb::ThreadSP(); 3106 } 3107 3108 virtual lldb::StackFrameSP 3109 CalculateStackFrame () 3110 { 3111 return lldb::StackFrameSP(); 3112 } 3113 3114 virtual void 3115 CalculateExecutionContext (ExecutionContext &exe_ctx); 3116 3117 void 3118 SetSTDIOFileDescriptor (int file_descriptor); 3119 3120 //------------------------------------------------------------------ 3121 // Add a permanent region of memory that should never be read or 3122 // written to. This can be used to ensure that memory reads or writes 3123 // to certain areas of memory never end up being sent to the 3124 // DoReadMemory or DoWriteMemory functions which can improve 3125 // performance. 3126 //------------------------------------------------------------------ 3127 void 3128 AddInvalidMemoryRegion (const LoadRange ®ion); 3129 3130 //------------------------------------------------------------------ 3131 // Remove a permanent region of memory that should never be read or 3132 // written to that was previously added with AddInvalidMemoryRegion. 3133 //------------------------------------------------------------------ 3134 bool 3135 RemoveInvalidMemoryRange (const LoadRange ®ion); 3136 3137protected: 3138 //------------------------------------------------------------------ 3139 // NextEventAction provides a way to register an action on the next 3140 // event that is delivered to this process. There is currently only 3141 // one next event action allowed in the process at one time. If a 3142 // new "NextEventAction" is added while one is already present, the 3143 // old action will be discarded (with HandleBeingUnshipped called 3144 // after it is discarded.) 3145 //------------------------------------------------------------------ 3146 class NextEventAction 3147 { 3148 public: 3149 typedef enum EventActionResult 3150 { 3151 eEventActionSuccess, 3152 eEventActionRetry, 3153 eEventActionExit 3154 } EventActionResult; 3155 3156 NextEventAction (Process *process) : 3157 m_process(process) 3158 { 3159 } 3160 3161 virtual 3162 ~NextEventAction() 3163 { 3164 } 3165 3166 virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0; 3167 virtual void HandleBeingUnshipped () {}; 3168 virtual EventActionResult HandleBeingInterrupted () = 0; 3169 virtual const char *GetExitString() = 0; 3170 protected: 3171 Process *m_process; 3172 }; 3173 3174 void SetNextEventAction (Process::NextEventAction *next_event_action) 3175 { 3176 if (m_next_event_action_ap.get()) 3177 m_next_event_action_ap->HandleBeingUnshipped(); 3178 3179 m_next_event_action_ap.reset(next_event_action); 3180 } 3181 3182 // This is the completer for Attaching: 3183 class AttachCompletionHandler : public NextEventAction 3184 { 3185 public: 3186 AttachCompletionHandler (Process *process, uint32_t exec_count) : 3187 NextEventAction (process), 3188 m_exec_count (exec_count) 3189 { 3190 } 3191 3192 virtual 3193 ~AttachCompletionHandler() 3194 { 3195 } 3196 3197 virtual EventActionResult PerformAction (lldb::EventSP &event_sp); 3198 virtual EventActionResult HandleBeingInterrupted (); 3199 virtual const char *GetExitString(); 3200 private: 3201 uint32_t m_exec_count; 3202 std::string m_exit_string; 3203 }; 3204 3205 bool 3206 HijackPrivateProcessEvents (Listener *listener); 3207 3208 void 3209 RestorePrivateProcessEvents (); 3210 3211 bool 3212 PrivateStateThreadIsValid () const 3213 { 3214 return m_private_state_thread != LLDB_INVALID_HOST_THREAD; 3215 } 3216 3217 //------------------------------------------------------------------ 3218 // Member variables 3219 //------------------------------------------------------------------ 3220 Target & m_target; ///< The target that owns this process. 3221 ThreadSafeValue<lldb::StateType> m_public_state; 3222 ThreadSafeValue<lldb::StateType> m_private_state; // The actual state of our process 3223 Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. 3224 Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. 3225 Listener m_private_state_listener; // This is the listener for the private state thread. 3226 Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. 3227 lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events 3228 ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations. 3229 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. 3230 int m_exit_status; ///< The exit status of the process, or -1 if not set. 3231 std::string m_exit_string; ///< A textual description of why a process exited. 3232 ThreadList m_thread_list; ///< The threads for this process. 3233 std::vector<Notifications> m_notifications; ///< The list of notifications that this process can deliver. 3234 std::vector<lldb::addr_t> m_image_tokens; 3235 Listener &m_listener; 3236 BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend 3237 ///< to insert in the target. 3238 std::auto_ptr<DynamicLoader> m_dyld_ap; 3239 std::auto_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. 3240 std::auto_ptr<OperatingSystem> m_os_ap; 3241 UnixSignals m_unix_signals; /// This is the current signal set for this process. 3242 lldb::ABISP m_abi_sp; 3243 lldb::InputReaderSP m_process_input_reader; 3244 lldb_private::Communication m_stdio_communication; 3245 lldb_private::Mutex m_stdio_communication_mutex; 3246 std::string m_stdout_data; 3247 std::string m_stderr_data; 3248 MemoryCache m_memory_cache; 3249 AllocatedMemoryCache m_allocated_memory_cache; 3250 bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach? 3251 3252 typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection; 3253 LanguageRuntimeCollection m_language_runtimes; 3254 std::auto_ptr<NextEventAction> m_next_event_action_ap; 3255 3256 enum { 3257 eCanJITDontKnow= 0, 3258 eCanJITYes, 3259 eCanJITNo 3260 } m_can_jit; 3261 3262 size_t 3263 RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; 3264 3265 void 3266 SynchronouslyNotifyStateChanged (lldb::StateType state); 3267 3268 void 3269 SetPublicState (lldb::StateType new_state); 3270 3271 void 3272 SetPrivateState (lldb::StateType state); 3273 3274 bool 3275 StartPrivateStateThread (); 3276 3277 void 3278 StopPrivateStateThread (); 3279 3280 void 3281 PausePrivateStateThread (); 3282 3283 void 3284 ResumePrivateStateThread (); 3285 3286 static void * 3287 PrivateStateThread (void *arg); 3288 3289 void * 3290 RunPrivateStateThread (); 3291 3292 void 3293 HandlePrivateEvent (lldb::EventSP &event_sp); 3294 3295 lldb::StateType 3296 WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 3297 3298 // This waits for both the state change broadcaster, and the control broadcaster. 3299 // If control_only, it only waits for the control broadcaster. 3300 3301 bool 3302 WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); 3303 3304 lldb::StateType 3305 WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 3306 3307 lldb::StateType 3308 WaitForState (const TimeValue *timeout, 3309 const lldb::StateType *match_states, 3310 const uint32_t num_match_states); 3311 3312 size_t 3313 WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); 3314 3315 void 3316 AppendSTDOUT (const char *s, size_t len); 3317 3318 void 3319 AppendSTDERR (const char *s, size_t len); 3320 3321 static void 3322 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); 3323 3324 void 3325 PushProcessInputReader (); 3326 3327 void 3328 PopProcessInputReader (); 3329 3330 void 3331 ResetProcessInputReader (); 3332 3333 static size_t 3334 ProcessInputReaderCallback (void *baton, 3335 InputReader &reader, 3336 lldb::InputReaderAction notification, 3337 const char *bytes, 3338 size_t bytes_len); 3339 3340 3341private: 3342 //------------------------------------------------------------------ 3343 // For Process only 3344 //------------------------------------------------------------------ 3345 void ControlPrivateStateThread (uint32_t signal); 3346 3347 DISALLOW_COPY_AND_ASSIGN (Process); 3348 3349}; 3350 3351} // namespace lldb_private 3352 3353#endif // liblldb_Process_h_ 3354