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