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