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