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