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