1254721Semaste//===-- Process.h -----------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_Process_h_ 11254721Semaste#define liblldb_Process_h_ 12254721Semaste 13263363Semaste#include "lldb/Host/Config.h" 14263363Semaste 15254721Semaste// C Includes 16254721Semaste#include <limits.h> 17254721Semaste 18254721Semaste// C++ Includes 19254721Semaste#include <list> 20254721Semaste#include <iosfwd> 21254721Semaste#include <vector> 22254721Semaste 23254721Semaste// Other libraries and framework includes 24254721Semaste// Project includes 25254721Semaste#include "lldb/lldb-private.h" 26254721Semaste#include "lldb/Core/ArchSpec.h" 27254721Semaste#include "lldb/Core/Broadcaster.h" 28254721Semaste#include "lldb/Core/Communication.h" 29254721Semaste#include "lldb/Core/Error.h" 30254721Semaste#include "lldb/Core/Event.h" 31254721Semaste#include "lldb/Core/RangeMap.h" 32254721Semaste#include "lldb/Core/StringList.h" 33254721Semaste#include "lldb/Core/ThreadSafeValue.h" 34254721Semaste#include "lldb/Core/PluginInterface.h" 35254721Semaste#include "lldb/Core/UserSettingsController.h" 36254721Semaste#include "lldb/Breakpoint/BreakpointSiteList.h" 37254721Semaste#include "lldb/Expression/ClangPersistentVariables.h" 38254721Semaste#include "lldb/Expression/IRDynamicChecks.h" 39254721Semaste#include "lldb/Host/FileSpec.h" 40254721Semaste#include "lldb/Host/Host.h" 41254721Semaste#include "lldb/Host/ProcessRunLock.h" 42254721Semaste#include "lldb/Interpreter/Args.h" 43254721Semaste#include "lldb/Interpreter/Options.h" 44254721Semaste#include "lldb/Target/ExecutionContextScope.h" 45254721Semaste#include "lldb/Target/Memory.h" 46269024Semaste#include "lldb/Target/QueueList.h" 47254721Semaste#include "lldb/Target/ThreadList.h" 48254721Semaste#include "lldb/Target/UnixSignals.h" 49254721Semaste#include "lldb/Utility/PseudoTerminal.h" 50254721Semaste 51254721Semastenamespace lldb_private { 52254721Semaste 53254721Semaste//---------------------------------------------------------------------- 54254721Semaste// ProcessProperties 55254721Semaste//---------------------------------------------------------------------- 56254721Semasteclass ProcessProperties : public Properties 57254721Semaste{ 58254721Semastepublic: 59254721Semaste ProcessProperties(bool is_global); 60254721Semaste 61254721Semaste virtual 62254721Semaste ~ProcessProperties(); 63254721Semaste 64254721Semaste bool 65254721Semaste GetDisableMemoryCache() const; 66254721Semaste 67254721Semaste Args 68254721Semaste GetExtraStartupCommands () const; 69254721Semaste 70254721Semaste void 71254721Semaste SetExtraStartupCommands (const Args &args); 72254721Semaste 73254721Semaste FileSpec 74254721Semaste GetPythonOSPluginPath () const; 75254721Semaste 76254721Semaste void 77254721Semaste SetPythonOSPluginPath (const FileSpec &file); 78254721Semaste 79254721Semaste bool 80254721Semaste GetIgnoreBreakpointsInExpressions () const; 81254721Semaste 82254721Semaste void 83254721Semaste SetIgnoreBreakpointsInExpressions (bool ignore); 84254721Semaste 85254721Semaste bool 86254721Semaste GetUnwindOnErrorInExpressions () const; 87254721Semaste 88254721Semaste void 89254721Semaste SetUnwindOnErrorInExpressions (bool ignore); 90254721Semaste 91254721Semaste bool 92254721Semaste GetStopOnSharedLibraryEvents () const; 93254721Semaste 94254721Semaste void 95254721Semaste SetStopOnSharedLibraryEvents (bool stop); 96254721Semaste 97254721Semaste bool 98254721Semaste GetDetachKeepsStopped () const; 99254721Semaste 100254721Semaste void 101254721Semaste SetDetachKeepsStopped (bool keep_stopped); 102254721Semaste}; 103254721Semaste 104254721Semastetypedef std::shared_ptr<ProcessProperties> ProcessPropertiesSP; 105254721Semaste 106254721Semaste//---------------------------------------------------------------------- 107254721Semaste// ProcessInfo 108254721Semaste// 109254721Semaste// A base class for information for a process. This can be used to fill 110254721Semaste// out information for a process prior to launching it, or it can be 111254721Semaste// used for an instance of a process and can be filled in with the 112254721Semaste// existing values for that process. 113254721Semaste//---------------------------------------------------------------------- 114254721Semasteclass ProcessInfo 115254721Semaste{ 116254721Semastepublic: 117254721Semaste ProcessInfo () : 118254721Semaste m_executable (), 119254721Semaste m_arguments (), 120254721Semaste m_environment (), 121254721Semaste m_uid (UINT32_MAX), 122254721Semaste m_gid (UINT32_MAX), 123254721Semaste m_arch(), 124254721Semaste m_pid (LLDB_INVALID_PROCESS_ID) 125254721Semaste { 126254721Semaste } 127254721Semaste 128254721Semaste ProcessInfo (const char *name, 129254721Semaste const ArchSpec &arch, 130254721Semaste lldb::pid_t pid) : 131254721Semaste m_executable (name, false), 132254721Semaste m_arguments (), 133254721Semaste m_environment(), 134254721Semaste m_uid (UINT32_MAX), 135254721Semaste m_gid (UINT32_MAX), 136254721Semaste m_arch (arch), 137254721Semaste m_pid (pid) 138254721Semaste { 139254721Semaste } 140254721Semaste 141254721Semaste void 142254721Semaste Clear () 143254721Semaste { 144254721Semaste m_executable.Clear(); 145254721Semaste m_arguments.Clear(); 146254721Semaste m_environment.Clear(); 147254721Semaste m_uid = UINT32_MAX; 148254721Semaste m_gid = UINT32_MAX; 149254721Semaste m_arch.Clear(); 150254721Semaste m_pid = LLDB_INVALID_PROCESS_ID; 151254721Semaste } 152254721Semaste 153254721Semaste const char * 154254721Semaste GetName() const 155254721Semaste { 156254721Semaste return m_executable.GetFilename().GetCString(); 157254721Semaste } 158254721Semaste 159254721Semaste size_t 160254721Semaste GetNameLength() const 161254721Semaste { 162254721Semaste return m_executable.GetFilename().GetLength(); 163254721Semaste } 164254721Semaste 165254721Semaste FileSpec & 166254721Semaste GetExecutableFile () 167254721Semaste { 168254721Semaste return m_executable; 169254721Semaste } 170254721Semaste 171254721Semaste void 172254721Semaste SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg) 173254721Semaste { 174254721Semaste if (exe_file) 175254721Semaste { 176254721Semaste m_executable = exe_file; 177254721Semaste if (add_exe_file_as_first_arg) 178254721Semaste { 179254721Semaste char filename[PATH_MAX]; 180254721Semaste if (exe_file.GetPath(filename, sizeof(filename))) 181254721Semaste m_arguments.InsertArgumentAtIndex (0, filename); 182254721Semaste } 183254721Semaste } 184254721Semaste else 185254721Semaste { 186254721Semaste m_executable.Clear(); 187254721Semaste } 188254721Semaste } 189254721Semaste 190254721Semaste const FileSpec & 191254721Semaste GetExecutableFile () const 192254721Semaste { 193254721Semaste return m_executable; 194254721Semaste } 195254721Semaste 196254721Semaste uint32_t 197254721Semaste GetUserID() const 198254721Semaste { 199254721Semaste return m_uid; 200254721Semaste } 201254721Semaste 202254721Semaste uint32_t 203254721Semaste GetGroupID() const 204254721Semaste { 205254721Semaste return m_gid; 206254721Semaste } 207254721Semaste 208254721Semaste bool 209254721Semaste UserIDIsValid () const 210254721Semaste { 211254721Semaste return m_uid != UINT32_MAX; 212254721Semaste } 213254721Semaste 214254721Semaste bool 215254721Semaste GroupIDIsValid () const 216254721Semaste { 217254721Semaste return m_gid != UINT32_MAX; 218254721Semaste } 219254721Semaste 220254721Semaste void 221254721Semaste SetUserID (uint32_t uid) 222254721Semaste { 223254721Semaste m_uid = uid; 224254721Semaste } 225254721Semaste 226254721Semaste void 227254721Semaste SetGroupID (uint32_t gid) 228254721Semaste { 229254721Semaste m_gid = gid; 230254721Semaste } 231254721Semaste 232254721Semaste ArchSpec & 233254721Semaste GetArchitecture () 234254721Semaste { 235254721Semaste return m_arch; 236254721Semaste } 237254721Semaste 238254721Semaste const ArchSpec & 239254721Semaste GetArchitecture () const 240254721Semaste { 241254721Semaste return m_arch; 242254721Semaste } 243254721Semaste 244263363Semaste void 245263363Semaste SetArchitecture (ArchSpec arch) 246263363Semaste { 247263363Semaste m_arch = arch; 248263363Semaste } 249263363Semaste 250254721Semaste lldb::pid_t 251254721Semaste GetProcessID () const 252254721Semaste { 253254721Semaste return m_pid; 254254721Semaste } 255254721Semaste 256254721Semaste void 257254721Semaste SetProcessID (lldb::pid_t pid) 258254721Semaste { 259254721Semaste m_pid = pid; 260254721Semaste } 261254721Semaste 262254721Semaste bool 263254721Semaste ProcessIDIsValid() const 264254721Semaste { 265254721Semaste return m_pid != LLDB_INVALID_PROCESS_ID; 266254721Semaste } 267254721Semaste 268254721Semaste void 269254721Semaste Dump (Stream &s, Platform *platform) const; 270254721Semaste 271254721Semaste Args & 272254721Semaste GetArguments () 273254721Semaste { 274254721Semaste return m_arguments; 275254721Semaste } 276254721Semaste 277254721Semaste const Args & 278254721Semaste GetArguments () const 279254721Semaste { 280254721Semaste return m_arguments; 281254721Semaste } 282254721Semaste 283254721Semaste const char * 284254721Semaste GetArg0 () const 285254721Semaste { 286254721Semaste if (m_arg0.empty()) 287254721Semaste return NULL; 288254721Semaste return m_arg0.c_str(); 289254721Semaste } 290254721Semaste 291254721Semaste void 292254721Semaste SetArg0 (const char *arg) 293254721Semaste { 294254721Semaste if (arg && arg[0]) 295254721Semaste m_arg0 = arg; 296254721Semaste else 297254721Semaste m_arg0.clear(); 298254721Semaste } 299254721Semaste 300254721Semaste void 301254721Semaste SetArguments (const Args& args, bool first_arg_is_executable); 302254721Semaste 303254721Semaste void 304254721Semaste SetArguments (char const **argv, bool first_arg_is_executable); 305254721Semaste 306254721Semaste Args & 307254721Semaste GetEnvironmentEntries () 308254721Semaste { 309254721Semaste return m_environment; 310254721Semaste } 311254721Semaste 312254721Semaste const Args & 313254721Semaste GetEnvironmentEntries () const 314254721Semaste { 315254721Semaste return m_environment; 316254721Semaste } 317254721Semaste 318254721Semasteprotected: 319254721Semaste FileSpec m_executable; 320254721Semaste std::string m_arg0; // argv[0] if supported. If empty, then use m_executable. 321254721Semaste // Not all process plug-ins support specifying an argv[0] 322254721Semaste // that differs from the resolved platform executable 323254721Semaste // (which is in m_executable) 324254721Semaste Args m_arguments; // All program arguments except argv[0] 325254721Semaste Args m_environment; 326254721Semaste uint32_t m_uid; 327254721Semaste uint32_t m_gid; 328254721Semaste ArchSpec m_arch; 329254721Semaste lldb::pid_t m_pid; 330254721Semaste}; 331254721Semaste 332254721Semaste//---------------------------------------------------------------------- 333254721Semaste// ProcessInstanceInfo 334254721Semaste// 335254721Semaste// Describes an existing process and any discoverable information that 336254721Semaste// pertains to that process. 337254721Semaste//---------------------------------------------------------------------- 338254721Semasteclass ProcessInstanceInfo : public ProcessInfo 339254721Semaste{ 340254721Semastepublic: 341254721Semaste ProcessInstanceInfo () : 342254721Semaste ProcessInfo (), 343254721Semaste m_euid (UINT32_MAX), 344254721Semaste m_egid (UINT32_MAX), 345254721Semaste m_parent_pid (LLDB_INVALID_PROCESS_ID) 346254721Semaste { 347254721Semaste } 348254721Semaste 349254721Semaste ProcessInstanceInfo (const char *name, 350254721Semaste const ArchSpec &arch, 351254721Semaste lldb::pid_t pid) : 352254721Semaste ProcessInfo (name, arch, pid), 353254721Semaste m_euid (UINT32_MAX), 354254721Semaste m_egid (UINT32_MAX), 355254721Semaste m_parent_pid (LLDB_INVALID_PROCESS_ID) 356254721Semaste { 357254721Semaste } 358254721Semaste 359254721Semaste void 360254721Semaste Clear () 361254721Semaste { 362254721Semaste ProcessInfo::Clear(); 363254721Semaste m_euid = UINT32_MAX; 364254721Semaste m_egid = UINT32_MAX; 365254721Semaste m_parent_pid = LLDB_INVALID_PROCESS_ID; 366254721Semaste } 367254721Semaste 368254721Semaste uint32_t 369254721Semaste GetEffectiveUserID() const 370254721Semaste { 371254721Semaste return m_euid; 372254721Semaste } 373254721Semaste 374254721Semaste uint32_t 375254721Semaste GetEffectiveGroupID() const 376254721Semaste { 377254721Semaste return m_egid; 378254721Semaste } 379254721Semaste 380254721Semaste bool 381254721Semaste EffectiveUserIDIsValid () const 382254721Semaste { 383254721Semaste return m_euid != UINT32_MAX; 384254721Semaste } 385254721Semaste 386254721Semaste bool 387254721Semaste EffectiveGroupIDIsValid () const 388254721Semaste { 389254721Semaste return m_egid != UINT32_MAX; 390254721Semaste } 391254721Semaste 392254721Semaste void 393254721Semaste SetEffectiveUserID (uint32_t uid) 394254721Semaste { 395254721Semaste m_euid = uid; 396254721Semaste } 397254721Semaste 398254721Semaste void 399254721Semaste SetEffectiveGroupID (uint32_t gid) 400254721Semaste { 401254721Semaste m_egid = gid; 402254721Semaste } 403254721Semaste 404254721Semaste lldb::pid_t 405254721Semaste GetParentProcessID () const 406254721Semaste { 407254721Semaste return m_parent_pid; 408254721Semaste } 409254721Semaste 410254721Semaste void 411254721Semaste SetParentProcessID (lldb::pid_t pid) 412254721Semaste { 413254721Semaste m_parent_pid = pid; 414254721Semaste } 415254721Semaste 416254721Semaste bool 417254721Semaste ParentProcessIDIsValid() const 418254721Semaste { 419254721Semaste return m_parent_pid != LLDB_INVALID_PROCESS_ID; 420254721Semaste } 421254721Semaste 422254721Semaste void 423254721Semaste Dump (Stream &s, Platform *platform) const; 424254721Semaste 425254721Semaste static void 426254721Semaste DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose); 427254721Semaste 428254721Semaste void 429254721Semaste DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const; 430254721Semaste 431254721Semasteprotected: 432254721Semaste uint32_t m_euid; 433254721Semaste uint32_t m_egid; 434254721Semaste lldb::pid_t m_parent_pid; 435254721Semaste}; 436254721Semaste 437254721Semaste 438254721Semaste//---------------------------------------------------------------------- 439254721Semaste// ProcessLaunchInfo 440254721Semaste// 441254721Semaste// Describes any information that is required to launch a process. 442254721Semaste//---------------------------------------------------------------------- 443254721Semaste 444254721Semasteclass ProcessLaunchInfo : public ProcessInfo 445254721Semaste{ 446254721Semastepublic: 447254721Semaste 448254721Semaste class FileAction 449254721Semaste { 450254721Semaste public: 451254721Semaste enum Action 452254721Semaste { 453254721Semaste eFileActionNone, 454254721Semaste eFileActionClose, 455254721Semaste eFileActionDuplicate, 456254721Semaste eFileActionOpen 457254721Semaste }; 458254721Semaste 459254721Semaste 460254721Semaste FileAction () : 461254721Semaste m_action (eFileActionNone), 462254721Semaste m_fd (-1), 463254721Semaste m_arg (-1), 464254721Semaste m_path () 465254721Semaste { 466254721Semaste } 467254721Semaste 468254721Semaste void 469254721Semaste Clear() 470254721Semaste { 471254721Semaste m_action = eFileActionNone; 472254721Semaste m_fd = -1; 473254721Semaste m_arg = -1; 474254721Semaste m_path.clear(); 475254721Semaste } 476254721Semaste 477254721Semaste bool 478254721Semaste Close (int fd); 479254721Semaste 480254721Semaste bool 481254721Semaste Duplicate (int fd, int dup_fd); 482254721Semaste 483254721Semaste bool 484254721Semaste Open (int fd, const char *path, bool read, bool write); 485254721Semaste 486263363Semaste#ifndef LLDB_DISABLE_POSIX 487254721Semaste static bool 488263363Semaste AddPosixSpawnFileAction (void *file_actions, 489254721Semaste const FileAction *info, 490254721Semaste Log *log, 491254721Semaste Error& error); 492263363Semaste#endif 493254721Semaste 494254721Semaste int 495254721Semaste GetFD () const 496254721Semaste { 497254721Semaste return m_fd; 498254721Semaste } 499254721Semaste 500254721Semaste Action 501254721Semaste GetAction () const 502254721Semaste { 503254721Semaste return m_action; 504254721Semaste } 505254721Semaste 506254721Semaste int 507254721Semaste GetActionArgument () const 508254721Semaste { 509254721Semaste return m_arg; 510254721Semaste } 511254721Semaste 512254721Semaste const char * 513254721Semaste GetPath () const 514254721Semaste { 515254721Semaste if (m_path.empty()) 516254721Semaste return NULL; 517254721Semaste return m_path.c_str(); 518254721Semaste } 519254721Semaste 520254721Semaste protected: 521254721Semaste Action m_action; // The action for this file 522254721Semaste int m_fd; // An existing file descriptor 523254721Semaste int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate 524254721Semaste std::string m_path; // A file path to use for opening after fork or posix_spawn 525254721Semaste }; 526254721Semaste 527254721Semaste ProcessLaunchInfo () : 528254721Semaste ProcessInfo(), 529254721Semaste m_working_dir (), 530254721Semaste m_plugin_name (), 531254721Semaste m_shell (), 532254721Semaste m_flags (0), 533254721Semaste m_file_actions (), 534254721Semaste m_pty (), 535254721Semaste m_resume_count (0), 536254721Semaste m_monitor_callback (NULL), 537254721Semaste m_monitor_callback_baton (NULL), 538269024Semaste m_monitor_signals (false), 539269024Semaste m_hijack_listener_sp () 540254721Semaste { 541254721Semaste } 542254721Semaste 543254721Semaste ProcessLaunchInfo (const char *stdin_path, 544254721Semaste const char *stdout_path, 545254721Semaste const char *stderr_path, 546254721Semaste const char *working_directory, 547254721Semaste uint32_t launch_flags) : 548254721Semaste ProcessInfo(), 549254721Semaste m_working_dir (), 550254721Semaste m_plugin_name (), 551254721Semaste m_shell (), 552254721Semaste m_flags (launch_flags), 553254721Semaste m_file_actions (), 554254721Semaste m_pty (), 555254721Semaste m_resume_count (0), 556254721Semaste m_monitor_callback (NULL), 557254721Semaste m_monitor_callback_baton (NULL), 558269024Semaste m_monitor_signals (false), 559269024Semaste m_hijack_listener_sp () 560254721Semaste { 561254721Semaste if (stdin_path) 562254721Semaste { 563254721Semaste ProcessLaunchInfo::FileAction file_action; 564254721Semaste const bool read = true; 565254721Semaste const bool write = false; 566254721Semaste if (file_action.Open(STDIN_FILENO, stdin_path, read, write)) 567254721Semaste AppendFileAction (file_action); 568254721Semaste } 569254721Semaste if (stdout_path) 570254721Semaste { 571254721Semaste ProcessLaunchInfo::FileAction file_action; 572254721Semaste const bool read = false; 573254721Semaste const bool write = true; 574254721Semaste if (file_action.Open(STDOUT_FILENO, stdout_path, read, write)) 575254721Semaste AppendFileAction (file_action); 576254721Semaste } 577254721Semaste if (stderr_path) 578254721Semaste { 579254721Semaste ProcessLaunchInfo::FileAction file_action; 580254721Semaste const bool read = false; 581254721Semaste const bool write = true; 582254721Semaste if (file_action.Open(STDERR_FILENO, stderr_path, read, write)) 583254721Semaste AppendFileAction (file_action); 584254721Semaste } 585254721Semaste if (working_directory) 586254721Semaste SetWorkingDirectory(working_directory); 587254721Semaste } 588254721Semaste 589254721Semaste void 590254721Semaste AppendFileAction (const FileAction &info) 591254721Semaste { 592254721Semaste m_file_actions.push_back(info); 593254721Semaste } 594254721Semaste 595254721Semaste bool 596254721Semaste AppendCloseFileAction (int fd) 597254721Semaste { 598254721Semaste FileAction file_action; 599254721Semaste if (file_action.Close (fd)) 600254721Semaste { 601254721Semaste AppendFileAction (file_action); 602254721Semaste return true; 603254721Semaste } 604254721Semaste return false; 605254721Semaste } 606254721Semaste 607254721Semaste bool 608254721Semaste AppendDuplicateFileAction (int fd, int dup_fd) 609254721Semaste { 610254721Semaste FileAction file_action; 611254721Semaste if (file_action.Duplicate (fd, dup_fd)) 612254721Semaste { 613254721Semaste AppendFileAction (file_action); 614254721Semaste return true; 615254721Semaste } 616254721Semaste return false; 617254721Semaste } 618254721Semaste 619254721Semaste bool 620254721Semaste AppendOpenFileAction (int fd, const char *path, bool read, bool write) 621254721Semaste { 622254721Semaste FileAction file_action; 623254721Semaste if (file_action.Open (fd, path, read, write)) 624254721Semaste { 625254721Semaste AppendFileAction (file_action); 626254721Semaste return true; 627254721Semaste } 628254721Semaste return false; 629254721Semaste } 630254721Semaste 631254721Semaste bool 632254721Semaste AppendSuppressFileAction (int fd, bool read, bool write) 633254721Semaste { 634254721Semaste FileAction file_action; 635254721Semaste if (file_action.Open (fd, "/dev/null", read, write)) 636254721Semaste { 637254721Semaste AppendFileAction (file_action); 638254721Semaste return true; 639254721Semaste } 640254721Semaste return false; 641254721Semaste } 642254721Semaste 643254721Semaste void 644254721Semaste FinalizeFileActions (Target *target, 645254721Semaste bool default_to_use_pty); 646254721Semaste 647254721Semaste size_t 648254721Semaste GetNumFileActions () const 649254721Semaste { 650254721Semaste return m_file_actions.size(); 651254721Semaste } 652254721Semaste 653254721Semaste const FileAction * 654254721Semaste GetFileActionAtIndex (size_t idx) const 655254721Semaste { 656254721Semaste if (idx < m_file_actions.size()) 657254721Semaste return &m_file_actions[idx]; 658254721Semaste return NULL; 659254721Semaste } 660254721Semaste 661254721Semaste const FileAction * 662254721Semaste GetFileActionForFD (int fd) const 663254721Semaste { 664254721Semaste for (size_t idx=0, count=m_file_actions.size(); idx < count; ++idx) 665254721Semaste { 666254721Semaste if (m_file_actions[idx].GetFD () == fd) 667254721Semaste return &m_file_actions[idx]; 668254721Semaste } 669254721Semaste return NULL; 670254721Semaste } 671254721Semaste 672254721Semaste Flags & 673254721Semaste GetFlags () 674254721Semaste { 675254721Semaste return m_flags; 676254721Semaste } 677254721Semaste 678254721Semaste const Flags & 679254721Semaste GetFlags () const 680254721Semaste { 681254721Semaste return m_flags; 682254721Semaste } 683254721Semaste 684254721Semaste const char * 685254721Semaste GetWorkingDirectory () const 686254721Semaste { 687254721Semaste if (m_working_dir.empty()) 688254721Semaste return NULL; 689254721Semaste return m_working_dir.c_str(); 690254721Semaste } 691254721Semaste 692254721Semaste void 693254721Semaste SetWorkingDirectory (const char *working_dir) 694254721Semaste { 695254721Semaste if (working_dir && working_dir[0]) 696254721Semaste m_working_dir.assign (working_dir); 697254721Semaste else 698254721Semaste m_working_dir.clear(); 699254721Semaste } 700254721Semaste 701254721Semaste void 702254721Semaste SwapWorkingDirectory (std::string &working_dir) 703254721Semaste { 704254721Semaste m_working_dir.swap (working_dir); 705254721Semaste } 706254721Semaste 707254721Semaste 708254721Semaste const char * 709254721Semaste GetProcessPluginName () const 710254721Semaste { 711254721Semaste if (m_plugin_name.empty()) 712254721Semaste return NULL; 713254721Semaste return m_plugin_name.c_str(); 714254721Semaste } 715254721Semaste 716254721Semaste void 717254721Semaste SetProcessPluginName (const char *plugin) 718254721Semaste { 719254721Semaste if (plugin && plugin[0]) 720254721Semaste m_plugin_name.assign (plugin); 721254721Semaste else 722254721Semaste m_plugin_name.clear(); 723254721Semaste } 724254721Semaste 725254721Semaste const char * 726254721Semaste GetShell () const 727254721Semaste { 728254721Semaste if (m_shell.empty()) 729254721Semaste return NULL; 730254721Semaste return m_shell.c_str(); 731254721Semaste } 732254721Semaste 733254721Semaste void 734254721Semaste SetShell (const char * path) 735254721Semaste { 736254721Semaste if (path && path[0]) 737254721Semaste { 738254721Semaste m_shell.assign (path); 739254721Semaste m_flags.Set (lldb::eLaunchFlagLaunchInShell); 740254721Semaste } 741254721Semaste else 742254721Semaste { 743254721Semaste m_shell.clear(); 744254721Semaste m_flags.Clear (lldb::eLaunchFlagLaunchInShell); 745254721Semaste } 746254721Semaste } 747254721Semaste 748254721Semaste uint32_t 749254721Semaste GetResumeCount () const 750254721Semaste { 751254721Semaste return m_resume_count; 752254721Semaste } 753254721Semaste 754254721Semaste void 755254721Semaste SetResumeCount (uint32_t c) 756254721Semaste { 757254721Semaste m_resume_count = c; 758254721Semaste } 759254721Semaste 760254721Semaste bool 761254721Semaste GetLaunchInSeparateProcessGroup () 762254721Semaste { 763254721Semaste return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup); 764254721Semaste } 765254721Semaste 766254721Semaste void 767254721Semaste SetLaunchInSeparateProcessGroup (bool separate) 768254721Semaste { 769254721Semaste if (separate) 770254721Semaste m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup); 771254721Semaste else 772254721Semaste m_flags.Clear (lldb::eLaunchFlagLaunchInSeparateProcessGroup); 773254721Semaste 774254721Semaste } 775254721Semaste 776254721Semaste void 777254721Semaste Clear () 778254721Semaste { 779254721Semaste ProcessInfo::Clear(); 780254721Semaste m_working_dir.clear(); 781254721Semaste m_plugin_name.clear(); 782254721Semaste m_shell.clear(); 783254721Semaste m_flags.Clear(); 784254721Semaste m_file_actions.clear(); 785254721Semaste m_resume_count = 0; 786269024Semaste m_hijack_listener_sp.reset(); 787254721Semaste } 788254721Semaste 789254721Semaste bool 790254721Semaste ConvertArgumentsForLaunchingInShell (Error &error, 791254721Semaste bool localhost, 792254721Semaste bool will_debug, 793263363Semaste bool first_arg_is_full_shell_command, 794263363Semaste int32_t num_resumes); 795254721Semaste 796254721Semaste void 797254721Semaste SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback, 798254721Semaste void *baton, 799254721Semaste bool monitor_signals) 800254721Semaste { 801254721Semaste m_monitor_callback = callback; 802254721Semaste m_monitor_callback_baton = baton; 803254721Semaste m_monitor_signals = monitor_signals; 804254721Semaste } 805254721Semaste 806269024Semaste Host::MonitorChildProcessCallback 807269024Semaste GetMonitorProcessCallback () 808269024Semaste { 809269024Semaste return m_monitor_callback; 810269024Semaste } 811269024Semaste 812269024Semaste const void* 813269024Semaste GetMonitorProcessBaton () const 814269024Semaste { 815269024Semaste return m_monitor_callback_baton; 816269024Semaste } 817269024Semaste 818269024Semaste // If the LaunchInfo has a monitor callback, then arrange to monitor the process. 819269024Semaste // Return true if the LaunchInfo has taken care of monitoring the process, and false if the 820269024Semaste // caller might want to monitor the process themselves. 821269024Semaste 822254721Semaste bool 823254721Semaste MonitorProcess () const 824254721Semaste { 825269024Semaste if (GetFlags().Test(lldb::eLaunchFlagsDontMonitorProcess)) 826269024Semaste return true; 827269024Semaste 828254721Semaste if (m_monitor_callback && ProcessIDIsValid()) 829254721Semaste { 830254721Semaste Host::StartMonitoringChildProcess (m_monitor_callback, 831254721Semaste m_monitor_callback_baton, 832254721Semaste GetProcessID(), 833254721Semaste m_monitor_signals); 834254721Semaste return true; 835254721Semaste } 836254721Semaste return false; 837254721Semaste } 838254721Semaste 839254721Semaste lldb_utility::PseudoTerminal & 840254721Semaste GetPTY () 841254721Semaste { 842254721Semaste return m_pty; 843254721Semaste } 844269024Semaste 845269024Semaste lldb::ListenerSP 846269024Semaste GetHijackListener () const 847269024Semaste { 848269024Semaste return m_hijack_listener_sp; 849269024Semaste } 850269024Semaste 851269024Semaste void 852269024Semaste SetHijackListener (const lldb::ListenerSP &listener_sp) 853269024Semaste { 854269024Semaste m_hijack_listener_sp = listener_sp; 855269024Semaste } 856254721Semaste 857269024Semaste 858254721Semasteprotected: 859254721Semaste std::string m_working_dir; 860254721Semaste std::string m_plugin_name; 861254721Semaste std::string m_shell; 862254721Semaste Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags 863254721Semaste std::vector<FileAction> m_file_actions; // File actions for any other files 864254721Semaste lldb_utility::PseudoTerminal m_pty; 865254721Semaste uint32_t m_resume_count; // How many times do we resume after launching 866254721Semaste Host::MonitorChildProcessCallback m_monitor_callback; 867254721Semaste void *m_monitor_callback_baton; 868254721Semaste bool m_monitor_signals; 869269024Semaste lldb::ListenerSP m_hijack_listener_sp; 870254721Semaste}; 871254721Semaste 872254721Semaste//---------------------------------------------------------------------- 873254721Semaste// ProcessLaunchInfo 874254721Semaste// 875254721Semaste// Describes any information that is required to launch a process. 876254721Semaste//---------------------------------------------------------------------- 877254721Semaste 878254721Semasteclass ProcessAttachInfo : public ProcessInstanceInfo 879254721Semaste{ 880254721Semastepublic: 881254721Semaste ProcessAttachInfo() : 882254721Semaste ProcessInstanceInfo(), 883254721Semaste m_plugin_name (), 884254721Semaste m_resume_count (0), 885254721Semaste m_wait_for_launch (false), 886254721Semaste m_ignore_existing (true), 887254721Semaste m_continue_once_attached (false) 888254721Semaste { 889254721Semaste } 890254721Semaste 891254721Semaste ProcessAttachInfo (const ProcessLaunchInfo &launch_info) : 892254721Semaste ProcessInstanceInfo(), 893254721Semaste m_plugin_name (), 894254721Semaste m_resume_count (0), 895254721Semaste m_wait_for_launch (false), 896254721Semaste m_ignore_existing (true), 897254721Semaste m_continue_once_attached (false) 898254721Semaste { 899254721Semaste ProcessInfo::operator= (launch_info); 900254721Semaste SetProcessPluginName (launch_info.GetProcessPluginName()); 901254721Semaste SetResumeCount (launch_info.GetResumeCount()); 902269024Semaste SetHijackListener(launch_info.GetHijackListener()); 903254721Semaste } 904254721Semaste 905254721Semaste bool 906254721Semaste GetWaitForLaunch () const 907254721Semaste { 908254721Semaste return m_wait_for_launch; 909254721Semaste } 910254721Semaste 911254721Semaste void 912254721Semaste SetWaitForLaunch (bool b) 913254721Semaste { 914254721Semaste m_wait_for_launch = b; 915254721Semaste } 916254721Semaste 917254721Semaste bool 918254721Semaste GetIgnoreExisting () const 919254721Semaste { 920254721Semaste return m_ignore_existing; 921254721Semaste } 922254721Semaste 923254721Semaste void 924254721Semaste SetIgnoreExisting (bool b) 925254721Semaste { 926254721Semaste m_ignore_existing = b; 927254721Semaste } 928254721Semaste 929254721Semaste bool 930254721Semaste GetContinueOnceAttached () const 931254721Semaste { 932254721Semaste return m_continue_once_attached; 933254721Semaste } 934254721Semaste 935254721Semaste void 936254721Semaste SetContinueOnceAttached (bool b) 937254721Semaste { 938254721Semaste m_continue_once_attached = b; 939254721Semaste } 940254721Semaste 941254721Semaste uint32_t 942254721Semaste GetResumeCount () const 943254721Semaste { 944254721Semaste return m_resume_count; 945254721Semaste } 946254721Semaste 947254721Semaste void 948254721Semaste SetResumeCount (uint32_t c) 949254721Semaste { 950254721Semaste m_resume_count = c; 951254721Semaste } 952254721Semaste 953254721Semaste const char * 954254721Semaste GetProcessPluginName () const 955254721Semaste { 956254721Semaste if (m_plugin_name.empty()) 957254721Semaste return NULL; 958254721Semaste return m_plugin_name.c_str(); 959254721Semaste } 960254721Semaste 961254721Semaste void 962254721Semaste SetProcessPluginName (const char *plugin) 963254721Semaste { 964254721Semaste if (plugin && plugin[0]) 965254721Semaste m_plugin_name.assign (plugin); 966254721Semaste else 967254721Semaste m_plugin_name.clear(); 968254721Semaste } 969254721Semaste 970254721Semaste void 971254721Semaste Clear () 972254721Semaste { 973254721Semaste ProcessInstanceInfo::Clear(); 974254721Semaste m_plugin_name.clear(); 975254721Semaste m_resume_count = 0; 976254721Semaste m_wait_for_launch = false; 977254721Semaste m_ignore_existing = true; 978254721Semaste m_continue_once_attached = false; 979254721Semaste } 980254721Semaste 981254721Semaste bool 982254721Semaste ProcessInfoSpecified () const 983254721Semaste { 984254721Semaste if (GetExecutableFile()) 985254721Semaste return true; 986254721Semaste if (GetProcessID() != LLDB_INVALID_PROCESS_ID) 987254721Semaste return true; 988254721Semaste if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID) 989254721Semaste return true; 990254721Semaste return false; 991254721Semaste } 992269024Semaste 993269024Semaste lldb::ListenerSP 994269024Semaste GetHijackListener () const 995269024Semaste { 996269024Semaste return m_hijack_listener_sp; 997269024Semaste } 998269024Semaste 999269024Semaste void 1000269024Semaste SetHijackListener (const lldb::ListenerSP &listener_sp) 1001269024Semaste { 1002269024Semaste m_hijack_listener_sp = listener_sp; 1003269024Semaste } 1004269024Semaste 1005269024Semaste 1006254721Semasteprotected: 1007269024Semaste lldb::ListenerSP m_hijack_listener_sp; 1008254721Semaste std::string m_plugin_name; 1009254721Semaste uint32_t m_resume_count; // How many times do we resume after launching 1010254721Semaste bool m_wait_for_launch; 1011254721Semaste bool m_ignore_existing; 1012254721Semaste bool m_continue_once_attached; // Supports the use-case scenario of immediately continuing the process once attached. 1013254721Semaste}; 1014254721Semaste 1015254721Semasteclass ProcessLaunchCommandOptions : public Options 1016254721Semaste{ 1017254721Semastepublic: 1018254721Semaste 1019254721Semaste ProcessLaunchCommandOptions (CommandInterpreter &interpreter) : 1020254721Semaste Options(interpreter) 1021254721Semaste { 1022254721Semaste // Keep default values of all options in one place: OptionParsingStarting () 1023254721Semaste OptionParsingStarting (); 1024254721Semaste } 1025254721Semaste 1026254721Semaste ~ProcessLaunchCommandOptions () 1027254721Semaste { 1028254721Semaste } 1029254721Semaste 1030254721Semaste Error 1031254721Semaste SetOptionValue (uint32_t option_idx, const char *option_arg); 1032254721Semaste 1033254721Semaste void 1034254721Semaste OptionParsingStarting () 1035254721Semaste { 1036254721Semaste launch_info.Clear(); 1037254721Semaste } 1038254721Semaste 1039254721Semaste const OptionDefinition* 1040254721Semaste GetDefinitions () 1041254721Semaste { 1042254721Semaste return g_option_table; 1043254721Semaste } 1044254721Semaste 1045254721Semaste // Options table: Required for subclasses of Options. 1046254721Semaste 1047254721Semaste static OptionDefinition g_option_table[]; 1048254721Semaste 1049254721Semaste // Instance variables to hold the values for command options. 1050254721Semaste 1051254721Semaste ProcessLaunchInfo launch_info; 1052254721Semaste}; 1053254721Semaste 1054254721Semaste//---------------------------------------------------------------------- 1055254721Semaste// ProcessInstanceInfoMatch 1056254721Semaste// 1057254721Semaste// A class to help matching one ProcessInstanceInfo to another. 1058254721Semaste//---------------------------------------------------------------------- 1059254721Semaste 1060254721Semasteclass ProcessInstanceInfoMatch 1061254721Semaste{ 1062254721Semastepublic: 1063254721Semaste ProcessInstanceInfoMatch () : 1064254721Semaste m_match_info (), 1065254721Semaste m_name_match_type (eNameMatchIgnore), 1066254721Semaste m_match_all_users (false) 1067254721Semaste { 1068254721Semaste } 1069254721Semaste 1070254721Semaste ProcessInstanceInfoMatch (const char *process_name, 1071254721Semaste NameMatchType process_name_match_type) : 1072254721Semaste m_match_info (), 1073254721Semaste m_name_match_type (process_name_match_type), 1074254721Semaste m_match_all_users (false) 1075254721Semaste { 1076254721Semaste m_match_info.GetExecutableFile().SetFile(process_name, false); 1077254721Semaste } 1078254721Semaste 1079254721Semaste ProcessInstanceInfo & 1080254721Semaste GetProcessInfo () 1081254721Semaste { 1082254721Semaste return m_match_info; 1083254721Semaste } 1084254721Semaste 1085254721Semaste const ProcessInstanceInfo & 1086254721Semaste GetProcessInfo () const 1087254721Semaste { 1088254721Semaste return m_match_info; 1089254721Semaste } 1090254721Semaste 1091254721Semaste bool 1092254721Semaste GetMatchAllUsers () const 1093254721Semaste { 1094254721Semaste return m_match_all_users; 1095254721Semaste } 1096254721Semaste 1097254721Semaste void 1098254721Semaste SetMatchAllUsers (bool b) 1099254721Semaste { 1100254721Semaste m_match_all_users = b; 1101254721Semaste } 1102254721Semaste 1103254721Semaste NameMatchType 1104254721Semaste GetNameMatchType () const 1105254721Semaste { 1106254721Semaste return m_name_match_type; 1107254721Semaste } 1108254721Semaste 1109254721Semaste void 1110254721Semaste SetNameMatchType (NameMatchType name_match_type) 1111254721Semaste { 1112254721Semaste m_name_match_type = name_match_type; 1113254721Semaste } 1114254721Semaste 1115254721Semaste bool 1116254721Semaste NameMatches (const char *process_name) const; 1117254721Semaste 1118254721Semaste bool 1119254721Semaste Matches (const ProcessInstanceInfo &proc_info) const; 1120254721Semaste 1121254721Semaste bool 1122254721Semaste MatchAllProcesses () const; 1123254721Semaste void 1124254721Semaste Clear (); 1125254721Semaste 1126254721Semasteprotected: 1127254721Semaste ProcessInstanceInfo m_match_info; 1128254721Semaste NameMatchType m_name_match_type; 1129254721Semaste bool m_match_all_users; 1130254721Semaste}; 1131254721Semaste 1132254721Semasteclass ProcessInstanceInfoList 1133254721Semaste{ 1134254721Semastepublic: 1135254721Semaste ProcessInstanceInfoList () : 1136254721Semaste m_infos() 1137254721Semaste { 1138254721Semaste } 1139254721Semaste 1140254721Semaste void 1141254721Semaste Clear() 1142254721Semaste { 1143254721Semaste m_infos.clear(); 1144254721Semaste } 1145254721Semaste 1146254721Semaste size_t 1147254721Semaste GetSize() 1148254721Semaste { 1149254721Semaste return m_infos.size(); 1150254721Semaste } 1151254721Semaste 1152254721Semaste void 1153254721Semaste Append (const ProcessInstanceInfo &info) 1154254721Semaste { 1155254721Semaste m_infos.push_back (info); 1156254721Semaste } 1157254721Semaste 1158254721Semaste const char * 1159254721Semaste GetProcessNameAtIndex (size_t idx) 1160254721Semaste { 1161254721Semaste if (idx < m_infos.size()) 1162254721Semaste return m_infos[idx].GetName(); 1163254721Semaste return NULL; 1164254721Semaste } 1165254721Semaste 1166254721Semaste size_t 1167254721Semaste GetProcessNameLengthAtIndex (size_t idx) 1168254721Semaste { 1169254721Semaste if (idx < m_infos.size()) 1170254721Semaste return m_infos[idx].GetNameLength(); 1171254721Semaste return 0; 1172254721Semaste } 1173254721Semaste 1174254721Semaste lldb::pid_t 1175254721Semaste GetProcessIDAtIndex (size_t idx) 1176254721Semaste { 1177254721Semaste if (idx < m_infos.size()) 1178254721Semaste return m_infos[idx].GetProcessID(); 1179254721Semaste return 0; 1180254721Semaste } 1181254721Semaste 1182254721Semaste bool 1183254721Semaste GetInfoAtIndex (size_t idx, ProcessInstanceInfo &info) 1184254721Semaste { 1185254721Semaste if (idx < m_infos.size()) 1186254721Semaste { 1187254721Semaste info = m_infos[idx]; 1188254721Semaste return true; 1189254721Semaste } 1190254721Semaste return false; 1191254721Semaste } 1192254721Semaste 1193254721Semaste // You must ensure "idx" is valid before calling this function 1194254721Semaste const ProcessInstanceInfo & 1195254721Semaste GetProcessInfoAtIndex (size_t idx) const 1196254721Semaste { 1197254721Semaste assert (idx < m_infos.size()); 1198254721Semaste return m_infos[idx]; 1199254721Semaste } 1200254721Semaste 1201254721Semasteprotected: 1202254721Semaste typedef std::vector<ProcessInstanceInfo> collection; 1203254721Semaste collection m_infos; 1204254721Semaste}; 1205254721Semaste 1206254721Semaste 1207254721Semaste// This class tracks the Modification state of the process. Things that can currently modify 1208254721Semaste// the program are running the program (which will up the StopID) and writing memory (which 1209254721Semaste// will up the MemoryID.) 1210254721Semaste// FIXME: Should we also include modification of register states? 1211254721Semaste 1212254721Semasteclass ProcessModID 1213254721Semaste{ 1214254721Semastefriend bool operator== (const ProcessModID &lhs, const ProcessModID &rhs); 1215254721Semastepublic: 1216254721Semaste ProcessModID () : 1217254721Semaste m_stop_id (0), 1218254721Semaste m_last_natural_stop_id(0), 1219254721Semaste m_resume_id (0), 1220254721Semaste m_memory_id (0), 1221254721Semaste m_last_user_expression_resume (0), 1222254721Semaste m_running_user_expression (false) 1223254721Semaste {} 1224254721Semaste 1225254721Semaste ProcessModID (const ProcessModID &rhs) : 1226254721Semaste m_stop_id (rhs.m_stop_id), 1227254721Semaste m_memory_id (rhs.m_memory_id) 1228254721Semaste {} 1229254721Semaste 1230254721Semaste const ProcessModID & operator= (const ProcessModID &rhs) 1231254721Semaste { 1232254721Semaste if (this != &rhs) 1233254721Semaste { 1234254721Semaste m_stop_id = rhs.m_stop_id; 1235254721Semaste m_memory_id = rhs.m_memory_id; 1236254721Semaste } 1237254721Semaste return *this; 1238254721Semaste } 1239254721Semaste 1240254721Semaste ~ProcessModID () {} 1241254721Semaste 1242254721Semaste void BumpStopID () { 1243254721Semaste m_stop_id++; 1244254721Semaste if (!IsLastResumeForUserExpression()) 1245254721Semaste m_last_natural_stop_id++; 1246254721Semaste } 1247254721Semaste 1248254721Semaste void BumpMemoryID () { m_memory_id++; } 1249254721Semaste 1250254721Semaste void BumpResumeID () { 1251254721Semaste m_resume_id++; 1252254721Semaste if (m_running_user_expression > 0) 1253254721Semaste m_last_user_expression_resume = m_resume_id; 1254254721Semaste } 1255254721Semaste 1256254721Semaste uint32_t GetStopID() const { return m_stop_id; } 1257254721Semaste uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; } 1258254721Semaste uint32_t GetMemoryID () const { return m_memory_id; } 1259254721Semaste uint32_t GetResumeID () const { return m_resume_id; } 1260254721Semaste uint32_t GetLastUserExpressionResumeID () const { return m_last_user_expression_resume; } 1261254721Semaste 1262254721Semaste bool MemoryIDEqual (const ProcessModID &compare) const 1263254721Semaste { 1264254721Semaste return m_memory_id == compare.m_memory_id; 1265254721Semaste } 1266254721Semaste 1267254721Semaste bool StopIDEqual (const ProcessModID &compare) const 1268254721Semaste { 1269254721Semaste return m_stop_id == compare.m_stop_id; 1270254721Semaste } 1271254721Semaste 1272254721Semaste void SetInvalid () 1273254721Semaste { 1274254721Semaste m_stop_id = UINT32_MAX; 1275254721Semaste } 1276254721Semaste 1277254721Semaste bool IsValid () const 1278254721Semaste { 1279254721Semaste return m_stop_id != UINT32_MAX; 1280254721Semaste } 1281254721Semaste 1282254721Semaste bool 1283254721Semaste IsLastResumeForUserExpression () const 1284254721Semaste { 1285254721Semaste return m_resume_id == m_last_user_expression_resume; 1286254721Semaste } 1287254721Semaste 1288254721Semaste void 1289254721Semaste SetRunningUserExpression (bool on) 1290254721Semaste { 1291254721Semaste // REMOVEME printf ("Setting running user expression %s at resume id %d - value: %d.\n", on ? "on" : "off", m_resume_id, m_running_user_expression); 1292254721Semaste if (on) 1293254721Semaste m_running_user_expression++; 1294254721Semaste else 1295254721Semaste m_running_user_expression--; 1296254721Semaste } 1297254721Semaste 1298254721Semasteprivate: 1299254721Semaste uint32_t m_stop_id; 1300254721Semaste uint32_t m_last_natural_stop_id; 1301254721Semaste uint32_t m_resume_id; 1302254721Semaste uint32_t m_memory_id; 1303254721Semaste uint32_t m_last_user_expression_resume; 1304254721Semaste uint32_t m_running_user_expression; 1305254721Semaste}; 1306254721Semasteinline bool operator== (const ProcessModID &lhs, const ProcessModID &rhs) 1307254721Semaste{ 1308254721Semaste if (lhs.StopIDEqual (rhs) 1309254721Semaste && lhs.MemoryIDEqual (rhs)) 1310254721Semaste return true; 1311254721Semaste else 1312254721Semaste return false; 1313254721Semaste} 1314254721Semaste 1315254721Semasteinline bool operator!= (const ProcessModID &lhs, const ProcessModID &rhs) 1316254721Semaste{ 1317254721Semaste if (!lhs.StopIDEqual (rhs) 1318254721Semaste || !lhs.MemoryIDEqual (rhs)) 1319254721Semaste return true; 1320254721Semaste else 1321254721Semaste return false; 1322254721Semaste} 1323254721Semaste 1324254721Semasteclass MemoryRegionInfo 1325254721Semaste{ 1326254721Semastepublic: 1327254721Semaste typedef Range<lldb::addr_t, lldb::addr_t> RangeType; 1328254721Semaste 1329254721Semaste enum OptionalBool { 1330254721Semaste eDontKnow = -1, 1331254721Semaste eNo = 0, 1332254721Semaste eYes = 1 1333254721Semaste }; 1334254721Semaste 1335254721Semaste MemoryRegionInfo () : 1336254721Semaste m_range (), 1337254721Semaste m_read (eDontKnow), 1338254721Semaste m_write (eDontKnow), 1339254721Semaste m_execute (eDontKnow) 1340254721Semaste { 1341254721Semaste } 1342254721Semaste 1343254721Semaste ~MemoryRegionInfo () 1344254721Semaste { 1345254721Semaste } 1346254721Semaste 1347254721Semaste RangeType & 1348254721Semaste GetRange() 1349254721Semaste { 1350254721Semaste return m_range; 1351254721Semaste } 1352254721Semaste 1353254721Semaste void 1354254721Semaste Clear() 1355254721Semaste { 1356254721Semaste m_range.Clear(); 1357254721Semaste m_read = m_write = m_execute = eDontKnow; 1358254721Semaste } 1359254721Semaste 1360254721Semaste const RangeType & 1361254721Semaste GetRange() const 1362254721Semaste { 1363254721Semaste return m_range; 1364254721Semaste } 1365254721Semaste 1366254721Semaste OptionalBool 1367254721Semaste GetReadable () const 1368254721Semaste { 1369254721Semaste return m_read; 1370254721Semaste } 1371254721Semaste 1372254721Semaste OptionalBool 1373254721Semaste GetWritable () const 1374254721Semaste { 1375254721Semaste return m_write; 1376254721Semaste } 1377254721Semaste 1378254721Semaste OptionalBool 1379254721Semaste GetExecutable () const 1380254721Semaste { 1381254721Semaste return m_execute; 1382254721Semaste } 1383254721Semaste 1384254721Semaste void 1385254721Semaste SetReadable (OptionalBool val) 1386254721Semaste { 1387254721Semaste m_read = val; 1388254721Semaste } 1389254721Semaste 1390254721Semaste void 1391254721Semaste SetWritable (OptionalBool val) 1392254721Semaste { 1393254721Semaste m_write = val; 1394254721Semaste } 1395254721Semaste 1396254721Semaste void 1397254721Semaste SetExecutable (OptionalBool val) 1398254721Semaste { 1399254721Semaste m_execute = val; 1400254721Semaste } 1401254721Semaste 1402254721Semasteprotected: 1403254721Semaste RangeType m_range; 1404254721Semaste OptionalBool m_read; 1405254721Semaste OptionalBool m_write; 1406254721Semaste OptionalBool m_execute; 1407254721Semaste}; 1408254721Semaste 1409254721Semaste//---------------------------------------------------------------------- 1410254721Semaste/// @class Process Process.h "lldb/Target/Process.h" 1411254721Semaste/// @brief A plug-in interface definition class for debugging a process. 1412254721Semaste//---------------------------------------------------------------------- 1413254721Semasteclass Process : 1414254721Semaste public std::enable_shared_from_this<Process>, 1415254721Semaste public ProcessProperties, 1416254721Semaste public UserID, 1417254721Semaste public Broadcaster, 1418254721Semaste public ExecutionContextScope, 1419254721Semaste public PluginInterface 1420254721Semaste{ 1421269024Semaste friend class ClangFunction; // For WaitForStateChangeEventsPrivate 1422269024Semaste friend class ProcessEventData; 1423269024Semaste friend class StopInfo; 1424269024Semaste friend class Target; 1425269024Semaste friend class ThreadList; 1426254721Semaste 1427254721Semastepublic: 1428254721Semaste 1429254721Semaste //------------------------------------------------------------------ 1430254721Semaste /// Broadcaster event bits definitions. 1431254721Semaste //------------------------------------------------------------------ 1432254721Semaste enum 1433254721Semaste { 1434254721Semaste eBroadcastBitStateChanged = (1 << 0), 1435254721Semaste eBroadcastBitInterrupt = (1 << 1), 1436254721Semaste eBroadcastBitSTDOUT = (1 << 2), 1437254721Semaste eBroadcastBitSTDERR = (1 << 3), 1438254721Semaste eBroadcastBitProfileData = (1 << 4) 1439254721Semaste }; 1440254721Semaste 1441254721Semaste enum 1442254721Semaste { 1443254721Semaste eBroadcastInternalStateControlStop = (1<<0), 1444254721Semaste eBroadcastInternalStateControlPause = (1<<1), 1445254721Semaste eBroadcastInternalStateControlResume = (1<<2) 1446254721Semaste }; 1447254721Semaste 1448254721Semaste typedef Range<lldb::addr_t, lldb::addr_t> LoadRange; 1449254721Semaste // We use a read/write lock to allow on or more clients to 1450254721Semaste // access the process state while the process is stopped (reader). 1451254721Semaste // We lock the write lock to control access to the process 1452254721Semaste // while it is running (readers, or clients that want the process 1453254721Semaste // stopped can block waiting for the process to stop, or just 1454254721Semaste // try to lock it to see if they can immediately access the stopped 1455254721Semaste // process. If the try read lock fails, then the process is running. 1456254721Semaste typedef ProcessRunLock::ProcessRunLocker StopLocker; 1457254721Semaste 1458254721Semaste // These two functions fill out the Broadcaster interface: 1459254721Semaste 1460254721Semaste static ConstString &GetStaticBroadcasterClass (); 1461254721Semaste 1462254721Semaste virtual ConstString &GetBroadcasterClass() const 1463254721Semaste { 1464254721Semaste return GetStaticBroadcasterClass(); 1465254721Semaste } 1466254721Semaste 1467254721Semaste 1468254721Semaste //------------------------------------------------------------------ 1469254721Semaste /// A notification structure that can be used by clients to listen 1470254721Semaste /// for changes in a process's lifetime. 1471254721Semaste /// 1472254721Semaste /// @see RegisterNotificationCallbacks (const Notifications&) 1473254721Semaste /// @see UnregisterNotificationCallbacks (const Notifications&) 1474254721Semaste //------------------------------------------------------------------ 1475254721Semaste#ifndef SWIG 1476254721Semaste typedef struct 1477254721Semaste { 1478254721Semaste void *baton; 1479254721Semaste void (*initialize)(void *baton, Process *process); 1480254721Semaste void (*process_state_changed) (void *baton, Process *process, lldb::StateType state); 1481254721Semaste } Notifications; 1482254721Semaste 1483254721Semaste class ProcessEventData : 1484254721Semaste public EventData 1485254721Semaste { 1486254721Semaste friend class Process; 1487254721Semaste 1488254721Semaste public: 1489254721Semaste ProcessEventData (); 1490254721Semaste ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state); 1491254721Semaste 1492254721Semaste virtual ~ProcessEventData(); 1493254721Semaste 1494254721Semaste static const ConstString & 1495254721Semaste GetFlavorString (); 1496254721Semaste 1497254721Semaste virtual const ConstString & 1498254721Semaste GetFlavor () const; 1499254721Semaste 1500254721Semaste const lldb::ProcessSP & 1501254721Semaste GetProcessSP() const 1502254721Semaste { 1503254721Semaste return m_process_sp; 1504254721Semaste } 1505254721Semaste lldb::StateType 1506254721Semaste GetState() const 1507254721Semaste { 1508254721Semaste return m_state; 1509254721Semaste } 1510254721Semaste bool 1511254721Semaste GetRestarted () const 1512254721Semaste { 1513254721Semaste return m_restarted; 1514254721Semaste } 1515254721Semaste 1516254721Semaste size_t 1517254721Semaste GetNumRestartedReasons () 1518254721Semaste { 1519254721Semaste return m_restarted_reasons.size(); 1520254721Semaste } 1521254721Semaste 1522254721Semaste const char * 1523254721Semaste GetRestartedReasonAtIndex(size_t idx) 1524254721Semaste { 1525254721Semaste if (idx > m_restarted_reasons.size()) 1526254721Semaste return NULL; 1527254721Semaste else 1528254721Semaste return m_restarted_reasons[idx].c_str(); 1529254721Semaste } 1530254721Semaste 1531254721Semaste bool 1532254721Semaste GetInterrupted () const 1533254721Semaste { 1534254721Semaste return m_interrupted; 1535254721Semaste } 1536254721Semaste 1537254721Semaste virtual void 1538254721Semaste Dump (Stream *s) const; 1539254721Semaste 1540254721Semaste virtual void 1541254721Semaste DoOnRemoval (Event *event_ptr); 1542254721Semaste 1543254721Semaste static const Process::ProcessEventData * 1544254721Semaste GetEventDataFromEvent (const Event *event_ptr); 1545254721Semaste 1546254721Semaste static lldb::ProcessSP 1547254721Semaste GetProcessFromEvent (const Event *event_ptr); 1548254721Semaste 1549254721Semaste static lldb::StateType 1550254721Semaste GetStateFromEvent (const Event *event_ptr); 1551254721Semaste 1552254721Semaste static bool 1553254721Semaste GetRestartedFromEvent (const Event *event_ptr); 1554254721Semaste 1555254721Semaste static size_t 1556254721Semaste GetNumRestartedReasons(const Event *event_ptr); 1557254721Semaste 1558254721Semaste static const char * 1559254721Semaste GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx); 1560254721Semaste 1561254721Semaste static void 1562254721Semaste AddRestartedReason (Event *event_ptr, const char *reason); 1563254721Semaste 1564254721Semaste static void 1565254721Semaste SetRestartedInEvent (Event *event_ptr, bool new_value); 1566254721Semaste 1567254721Semaste static bool 1568254721Semaste GetInterruptedFromEvent (const Event *event_ptr); 1569254721Semaste 1570254721Semaste static void 1571254721Semaste SetInterruptedInEvent (Event *event_ptr, bool new_value); 1572254721Semaste 1573254721Semaste static bool 1574254721Semaste SetUpdateStateOnRemoval (Event *event_ptr); 1575254721Semaste 1576254721Semaste private: 1577254721Semaste 1578254721Semaste void 1579254721Semaste SetUpdateStateOnRemoval() 1580254721Semaste { 1581254721Semaste m_update_state++; 1582254721Semaste } 1583254721Semaste void 1584254721Semaste SetRestarted (bool new_value) 1585254721Semaste { 1586254721Semaste m_restarted = new_value; 1587254721Semaste } 1588254721Semaste void 1589254721Semaste SetInterrupted (bool new_value) 1590254721Semaste { 1591254721Semaste m_interrupted = new_value; 1592254721Semaste } 1593254721Semaste void 1594254721Semaste AddRestartedReason (const char *reason) 1595254721Semaste { 1596254721Semaste m_restarted_reasons.push_back(reason); 1597254721Semaste } 1598254721Semaste 1599254721Semaste lldb::ProcessSP m_process_sp; 1600254721Semaste lldb::StateType m_state; 1601254721Semaste std::vector<std::string> m_restarted_reasons; 1602254721Semaste bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted. 1603254721Semaste int m_update_state; 1604254721Semaste bool m_interrupted; 1605254721Semaste DISALLOW_COPY_AND_ASSIGN (ProcessEventData); 1606254721Semaste 1607254721Semaste }; 1608254721Semaste 1609254721Semaste#endif 1610254721Semaste 1611254721Semaste static void 1612254721Semaste SettingsInitialize (); 1613254721Semaste 1614254721Semaste static void 1615254721Semaste SettingsTerminate (); 1616254721Semaste 1617254721Semaste static const ProcessPropertiesSP & 1618254721Semaste GetGlobalProperties(); 1619254721Semaste 1620254721Semaste //------------------------------------------------------------------ 1621254721Semaste /// Construct with a shared pointer to a target, and the Process listener. 1622254721Semaste //------------------------------------------------------------------ 1623254721Semaste Process(Target &target, Listener &listener); 1624254721Semaste 1625254721Semaste //------------------------------------------------------------------ 1626254721Semaste /// Destructor. 1627254721Semaste /// 1628254721Semaste /// The destructor is virtual since this class is designed to be 1629254721Semaste /// inherited from by the plug-in instance. 1630254721Semaste //------------------------------------------------------------------ 1631254721Semaste virtual 1632254721Semaste ~Process(); 1633254721Semaste 1634254721Semaste //------------------------------------------------------------------ 1635254721Semaste /// Find a Process plug-in that can debug \a module using the 1636254721Semaste /// currently selected architecture. 1637254721Semaste /// 1638254721Semaste /// Scans all loaded plug-in interfaces that implement versions of 1639254721Semaste /// the Process plug-in interface and returns the first instance 1640254721Semaste /// that can debug the file. 1641254721Semaste /// 1642254721Semaste /// @param[in] module_sp 1643254721Semaste /// The module shared pointer that this process will debug. 1644254721Semaste /// 1645254721Semaste /// @param[in] plugin_name 1646254721Semaste /// If NULL, select the best plug-in for the binary. If non-NULL 1647254721Semaste /// then look for a plugin whose PluginInfo's name matches 1648254721Semaste /// this string. 1649254721Semaste /// 1650254721Semaste /// @see Process::CanDebug () 1651254721Semaste //------------------------------------------------------------------ 1652254721Semaste static lldb::ProcessSP 1653254721Semaste FindPlugin (Target &target, 1654254721Semaste const char *plugin_name, 1655254721Semaste Listener &listener, 1656254721Semaste const FileSpec *crash_file_path); 1657254721Semaste 1658254721Semaste 1659254721Semaste 1660254721Semaste //------------------------------------------------------------------ 1661254721Semaste /// Static function that can be used with the \b host function 1662254721Semaste /// Host::StartMonitoringChildProcess (). 1663254721Semaste /// 1664254721Semaste /// This function can be used by lldb_private::Process subclasses 1665254721Semaste /// when they want to watch for a local process and have its exit 1666254721Semaste /// status automatically set when the host child process exits. 1667254721Semaste /// Subclasses should call Host::StartMonitoringChildProcess () 1668254721Semaste /// with: 1669254721Semaste /// callback = Process::SetHostProcessExitStatus 1670254721Semaste /// callback_baton = NULL 1671254721Semaste /// pid = Process::GetID() 1672254721Semaste /// monitor_signals = false 1673254721Semaste //------------------------------------------------------------------ 1674254721Semaste static bool 1675254721Semaste SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL 1676254721Semaste lldb::pid_t pid, // The process ID we want to monitor 1677254721Semaste bool exited, 1678254721Semaste int signo, // Zero for no signal 1679254721Semaste int status); // Exit value of process if signal is zero 1680254721Semaste 1681254721Semaste lldb::ByteOrder 1682254721Semaste GetByteOrder () const; 1683254721Semaste 1684254721Semaste uint32_t 1685254721Semaste GetAddressByteSize () const; 1686254721Semaste 1687254721Semaste uint32_t 1688254721Semaste GetUniqueID() const 1689254721Semaste { 1690254721Semaste return m_process_unique_id; 1691254721Semaste } 1692254721Semaste //------------------------------------------------------------------ 1693254721Semaste /// Check if a plug-in instance can debug the file in \a module. 1694254721Semaste /// 1695254721Semaste /// Each plug-in is given a chance to say whether it can debug 1696254721Semaste /// the file in \a module. If the Process plug-in instance can 1697254721Semaste /// debug a file on the current system, it should return \b true. 1698254721Semaste /// 1699254721Semaste /// @return 1700254721Semaste /// Returns \b true if this Process plug-in instance can 1701254721Semaste /// debug the executable, \b false otherwise. 1702254721Semaste //------------------------------------------------------------------ 1703254721Semaste virtual bool 1704254721Semaste CanDebug (Target &target, 1705254721Semaste bool plugin_specified_by_name) = 0; 1706254721Semaste 1707254721Semaste 1708254721Semaste //------------------------------------------------------------------ 1709254721Semaste /// This object is about to be destroyed, do any necessary cleanup. 1710254721Semaste /// 1711254721Semaste /// Subclasses that override this method should always call this 1712254721Semaste /// superclass method. 1713254721Semaste //------------------------------------------------------------------ 1714254721Semaste virtual void 1715254721Semaste Finalize(); 1716254721Semaste 1717254721Semaste 1718254721Semaste //------------------------------------------------------------------ 1719254721Semaste /// Return whether this object is valid (i.e. has not been finalized.) 1720254721Semaste /// 1721254721Semaste /// @return 1722254721Semaste /// Returns \b true if this Process has not been finalized 1723254721Semaste /// and \b false otherwise. 1724254721Semaste //------------------------------------------------------------------ 1725254721Semaste bool 1726254721Semaste IsValid() const 1727254721Semaste { 1728254721Semaste return !m_finalize_called; 1729254721Semaste } 1730254721Semaste 1731254721Semaste //------------------------------------------------------------------ 1732254721Semaste /// Return a multi-word command object that can be used to expose 1733254721Semaste /// plug-in specific commands. 1734254721Semaste /// 1735254721Semaste /// This object will be used to resolve plug-in commands and can be 1736254721Semaste /// triggered by a call to: 1737254721Semaste /// 1738254721Semaste /// (lldb) process commmand <args> 1739254721Semaste /// 1740254721Semaste /// @return 1741254721Semaste /// A CommandObject which can be one of the concrete subclasses 1742254721Semaste /// of CommandObject like CommandObjectRaw, CommandObjectParsed, 1743254721Semaste /// or CommandObjectMultiword. 1744254721Semaste //------------------------------------------------------------------ 1745254721Semaste virtual CommandObject * 1746254721Semaste GetPluginCommandObject() 1747254721Semaste { 1748254721Semaste return NULL; 1749254721Semaste } 1750254721Semaste 1751254721Semaste //------------------------------------------------------------------ 1752254721Semaste /// Launch a new process. 1753254721Semaste /// 1754254721Semaste /// Launch a new process by spawning a new process using the 1755254721Semaste /// target object's executable module's file as the file to launch. 1756254721Semaste /// Arguments are given in \a argv, and the environment variables 1757254721Semaste /// are in \a envp. Standard input and output files can be 1758254721Semaste /// optionally re-directed to \a stdin_path, \a stdout_path, and 1759254721Semaste /// \a stderr_path. 1760254721Semaste /// 1761254721Semaste /// This function is not meant to be overridden by Process 1762254721Semaste /// subclasses. It will first call Process::WillLaunch (Module *) 1763254721Semaste /// and if that returns \b true, Process::DoLaunch (Module*, 1764254721Semaste /// char const *[],char const *[],const char *,const char *, 1765254721Semaste /// const char *) will be called to actually do the launching. If 1766254721Semaste /// DoLaunch returns \b true, then Process::DidLaunch() will be 1767254721Semaste /// called. 1768254721Semaste /// 1769254721Semaste /// @param[in] argv 1770254721Semaste /// The argument array. 1771254721Semaste /// 1772254721Semaste /// @param[in] envp 1773254721Semaste /// The environment array. 1774254721Semaste /// 1775254721Semaste /// @param[in] launch_flags 1776254721Semaste /// Flags to modify the launch (@see lldb::LaunchFlags) 1777254721Semaste /// 1778254721Semaste /// @param[in] stdin_path 1779254721Semaste /// The path to use when re-directing the STDIN of the new 1780254721Semaste /// process. If all stdXX_path arguments are NULL, a pseudo 1781254721Semaste /// terminal will be used. 1782254721Semaste /// 1783254721Semaste /// @param[in] stdout_path 1784254721Semaste /// The path to use when re-directing the STDOUT of the new 1785254721Semaste /// process. If all stdXX_path arguments are NULL, a pseudo 1786254721Semaste /// terminal will be used. 1787254721Semaste /// 1788254721Semaste /// @param[in] stderr_path 1789254721Semaste /// The path to use when re-directing the STDERR of the new 1790254721Semaste /// process. If all stdXX_path arguments are NULL, a pseudo 1791254721Semaste /// terminal will be used. 1792254721Semaste /// 1793254721Semaste /// @param[in] working_directory 1794254721Semaste /// The working directory to have the child process run in 1795254721Semaste /// 1796254721Semaste /// @return 1797254721Semaste /// An error object. Call GetID() to get the process ID if 1798254721Semaste /// the error object is success. 1799254721Semaste //------------------------------------------------------------------ 1800254721Semaste virtual Error 1801263367Semaste Launch (ProcessLaunchInfo &launch_info); 1802254721Semaste 1803254721Semaste virtual Error 1804254721Semaste LoadCore (); 1805254721Semaste 1806254721Semaste virtual Error 1807254721Semaste DoLoadCore () 1808254721Semaste { 1809254721Semaste Error error; 1810254721Semaste error.SetErrorStringWithFormat("error: %s does not support loading core files.", GetPluginName().GetCString()); 1811254721Semaste return error; 1812254721Semaste } 1813263363Semaste 1814254721Semaste //------------------------------------------------------------------ 1815254721Semaste /// Get the dynamic loader plug-in for this process. 1816254721Semaste /// 1817254721Semaste /// The default action is to let the DynamicLoader plug-ins check 1818254721Semaste /// the main executable and the DynamicLoader will select itself 1819254721Semaste /// automatically. Subclasses can override this if inspecting the 1820254721Semaste /// executable is not desired, or if Process subclasses can only 1821254721Semaste /// use a specific DynamicLoader plug-in. 1822254721Semaste //------------------------------------------------------------------ 1823254721Semaste virtual DynamicLoader * 1824254721Semaste GetDynamicLoader (); 1825254721Semaste 1826254721Semaste //------------------------------------------------------------------ 1827263363Semaste /// Get the system runtime plug-in for this process. 1828263363Semaste /// 1829263363Semaste /// @return 1830263363Semaste /// Returns a pointer to the SystemRuntime plugin for this Process 1831263363Semaste /// if one is available. Else returns NULL. 1832263363Semaste //------------------------------------------------------------------ 1833263363Semaste virtual SystemRuntime * 1834263363Semaste GetSystemRuntime (); 1835263363Semaste 1836263363Semaste //------------------------------------------------------------------ 1837254721Semaste /// Attach to an existing process using the process attach info. 1838254721Semaste /// 1839254721Semaste /// This function is not meant to be overridden by Process 1840254721Semaste /// subclasses. It will first call WillAttach (lldb::pid_t) 1841254721Semaste /// or WillAttach (const char *), and if that returns \b 1842254721Semaste /// true, DoAttach (lldb::pid_t) or DoAttach (const char *) will 1843254721Semaste /// be called to actually do the attach. If DoAttach returns \b 1844254721Semaste /// true, then Process::DidAttach() will be called. 1845254721Semaste /// 1846254721Semaste /// @param[in] pid 1847254721Semaste /// The process ID that we should attempt to attach to. 1848254721Semaste /// 1849254721Semaste /// @return 1850254721Semaste /// Returns \a pid if attaching was successful, or 1851254721Semaste /// LLDB_INVALID_PROCESS_ID if attaching fails. 1852254721Semaste //------------------------------------------------------------------ 1853254721Semaste virtual Error 1854254721Semaste Attach (ProcessAttachInfo &attach_info); 1855254721Semaste 1856254721Semaste //------------------------------------------------------------------ 1857254721Semaste /// Attach to a remote system via a URL 1858254721Semaste /// 1859254721Semaste /// @param[in] strm 1860254721Semaste /// A stream where output intended for the user 1861254721Semaste /// (if the driver has a way to display that) generated during 1862254721Semaste /// the connection. This may be NULL if no output is needed.A 1863254721Semaste /// 1864254721Semaste /// @param[in] remote_url 1865254721Semaste /// The URL format that we are connecting to. 1866254721Semaste /// 1867254721Semaste /// @return 1868254721Semaste /// Returns an error object. 1869254721Semaste //------------------------------------------------------------------ 1870254721Semaste virtual Error 1871254721Semaste ConnectRemote (Stream *strm, const char *remote_url); 1872254721Semaste 1873254721Semaste bool 1874254721Semaste GetShouldDetach () const 1875254721Semaste { 1876254721Semaste return m_should_detach; 1877254721Semaste } 1878254721Semaste 1879254721Semaste void 1880254721Semaste SetShouldDetach (bool b) 1881254721Semaste { 1882254721Semaste m_should_detach = b; 1883254721Semaste } 1884254721Semaste 1885254721Semaste //------------------------------------------------------------------ 1886254721Semaste /// Get the image information address for the current process. 1887254721Semaste /// 1888254721Semaste /// Some runtimes have system functions that can help dynamic 1889254721Semaste /// loaders locate the dynamic loader information needed to observe 1890254721Semaste /// shared libraries being loaded or unloaded. This function is 1891254721Semaste /// in the Process interface (as opposed to the DynamicLoader 1892254721Semaste /// interface) to ensure that remote debugging can take advantage of 1893254721Semaste /// this functionality. 1894254721Semaste /// 1895254721Semaste /// @return 1896254721Semaste /// The address of the dynamic loader information, or 1897254721Semaste /// LLDB_INVALID_ADDRESS if this is not supported by this 1898254721Semaste /// interface. 1899254721Semaste //------------------------------------------------------------------ 1900254721Semaste virtual lldb::addr_t 1901254721Semaste GetImageInfoAddress (); 1902254721Semaste 1903254721Semaste //------------------------------------------------------------------ 1904254721Semaste /// Load a shared library into this process. 1905254721Semaste /// 1906254721Semaste /// Try and load a shared library into the current process. This 1907254721Semaste /// call might fail in the dynamic loader plug-in says it isn't safe 1908254721Semaste /// to try and load shared libraries at the moment. 1909254721Semaste /// 1910254721Semaste /// @param[in] image_spec 1911254721Semaste /// The image file spec that points to the shared library that 1912254721Semaste /// you want to load. 1913254721Semaste /// 1914254721Semaste /// @param[out] error 1915254721Semaste /// An error object that gets filled in with any errors that 1916254721Semaste /// might occur when trying to load the shared library. 1917254721Semaste /// 1918254721Semaste /// @return 1919254721Semaste /// A token that represents the shared library that can be 1920254721Semaste /// later used to unload the shared library. A value of 1921254721Semaste /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared 1922254721Semaste /// library can't be opened. 1923254721Semaste //------------------------------------------------------------------ 1924254721Semaste virtual uint32_t 1925254721Semaste LoadImage (const FileSpec &image_spec, Error &error); 1926254721Semaste 1927254721Semaste virtual Error 1928254721Semaste UnloadImage (uint32_t image_token); 1929254721Semaste 1930254721Semaste //------------------------------------------------------------------ 1931254721Semaste /// Register for process and thread notifications. 1932254721Semaste /// 1933254721Semaste /// Clients can register nofication callbacks by filling out a 1934254721Semaste /// Process::Notifications structure and calling this function. 1935254721Semaste /// 1936254721Semaste /// @param[in] callbacks 1937254721Semaste /// A structure that contains the notification baton and 1938254721Semaste /// callback functions. 1939254721Semaste /// 1940254721Semaste /// @see Process::Notifications 1941254721Semaste //------------------------------------------------------------------ 1942254721Semaste#ifndef SWIG 1943254721Semaste void 1944254721Semaste RegisterNotificationCallbacks (const Process::Notifications& callbacks); 1945254721Semaste#endif 1946254721Semaste //------------------------------------------------------------------ 1947254721Semaste /// Unregister for process and thread notifications. 1948254721Semaste /// 1949254721Semaste /// Clients can unregister nofication callbacks by passing a copy of 1950254721Semaste /// the original baton and callbacks in \a callbacks. 1951254721Semaste /// 1952254721Semaste /// @param[in] callbacks 1953254721Semaste /// A structure that contains the notification baton and 1954254721Semaste /// callback functions. 1955254721Semaste /// 1956254721Semaste /// @return 1957254721Semaste /// Returns \b true if the notification callbacks were 1958254721Semaste /// successfully removed from the process, \b false otherwise. 1959254721Semaste /// 1960254721Semaste /// @see Process::Notifications 1961254721Semaste //------------------------------------------------------------------ 1962254721Semaste#ifndef SWIG 1963254721Semaste bool 1964254721Semaste UnregisterNotificationCallbacks (const Process::Notifications& callbacks); 1965254721Semaste#endif 1966254721Semaste //================================================================== 1967254721Semaste // Built in Process Control functions 1968254721Semaste //================================================================== 1969254721Semaste //------------------------------------------------------------------ 1970254721Semaste /// Resumes all of a process's threads as configured using the 1971254721Semaste /// Thread run control functions. 1972254721Semaste /// 1973254721Semaste /// Threads for a process should be updated with one of the run 1974254721Semaste /// control actions (resume, step, or suspend) that they should take 1975254721Semaste /// when the process is resumed. If no run control action is given 1976254721Semaste /// to a thread it will be resumed by default. 1977254721Semaste /// 1978254721Semaste /// This function is not meant to be overridden by Process 1979254721Semaste /// subclasses. This function will take care of disabling any 1980254721Semaste /// breakpoints that threads may be stopped at, single stepping, and 1981254721Semaste /// re-enabling breakpoints, and enabling the basic flow control 1982254721Semaste /// that the plug-in instances need not worry about. 1983254721Semaste /// 1984254721Semaste /// N.B. This function also sets the Write side of the Run Lock, 1985254721Semaste /// which is unset when the corresponding stop event is pulled off 1986254721Semaste /// the Public Event Queue. If you need to resume the process without 1987254721Semaste /// setting the Run Lock, use PrivateResume (though you should only do 1988254721Semaste /// that from inside the Process class. 1989254721Semaste /// 1990254721Semaste /// @return 1991254721Semaste /// Returns an error object. 1992254721Semaste /// 1993254721Semaste /// @see Thread:Resume() 1994254721Semaste /// @see Thread:Step() 1995254721Semaste /// @see Thread:Suspend() 1996254721Semaste //------------------------------------------------------------------ 1997254721Semaste Error 1998254721Semaste Resume(); 1999254721Semaste 2000254721Semaste //------------------------------------------------------------------ 2001254721Semaste /// Halts a running process. 2002254721Semaste /// 2003254721Semaste /// This function is not meant to be overridden by Process 2004254721Semaste /// subclasses. 2005254721Semaste /// If the process is successfully halted, a eStateStopped 2006254721Semaste /// process event with GetInterrupted will be broadcast. If false, we will 2007254721Semaste /// halt the process with no events generated by the halt. 2008254721Semaste /// 2009254721Semaste /// @param[in] clear_thread_plans 2010254721Semaste /// If true, when the process stops, clear all thread plans. 2011254721Semaste /// 2012254721Semaste /// @return 2013254721Semaste /// Returns an error object. If the error is empty, the process is halted. 2014254721Semaste /// otherwise the halt has failed. 2015254721Semaste //------------------------------------------------------------------ 2016254721Semaste Error 2017254721Semaste Halt (bool clear_thread_plans = false); 2018254721Semaste 2019254721Semaste //------------------------------------------------------------------ 2020254721Semaste /// Detaches from a running or stopped process. 2021254721Semaste /// 2022254721Semaste /// This function is not meant to be overridden by Process 2023254721Semaste /// subclasses. 2024254721Semaste /// 2025254721Semaste /// @param[in] keep_stopped 2026254721Semaste /// If true, don't resume the process on detach. 2027254721Semaste /// 2028254721Semaste /// @return 2029254721Semaste /// Returns an error object. 2030254721Semaste //------------------------------------------------------------------ 2031254721Semaste Error 2032254721Semaste Detach (bool keep_stopped); 2033254721Semaste 2034254721Semaste //------------------------------------------------------------------ 2035254721Semaste /// Kills the process and shuts down all threads that were spawned 2036254721Semaste /// to track and monitor the process. 2037254721Semaste /// 2038254721Semaste /// This function is not meant to be overridden by Process 2039254721Semaste /// subclasses. 2040254721Semaste /// 2041254721Semaste /// @return 2042254721Semaste /// Returns an error object. 2043254721Semaste //------------------------------------------------------------------ 2044254721Semaste Error 2045254721Semaste Destroy(); 2046254721Semaste 2047254721Semaste //------------------------------------------------------------------ 2048254721Semaste /// Sends a process a UNIX signal \a signal. 2049254721Semaste /// 2050254721Semaste /// This function is not meant to be overridden by Process 2051254721Semaste /// subclasses. 2052254721Semaste /// 2053254721Semaste /// @return 2054254721Semaste /// Returns an error object. 2055254721Semaste //------------------------------------------------------------------ 2056254721Semaste Error 2057254721Semaste Signal (int signal); 2058254721Semaste 2059254721Semaste virtual UnixSignals & 2060254721Semaste GetUnixSignals () 2061254721Semaste { 2062254721Semaste return m_unix_signals; 2063254721Semaste } 2064254721Semaste 2065254721Semaste //================================================================== 2066254721Semaste // Plug-in Process Control Overrides 2067254721Semaste //================================================================== 2068254721Semaste 2069254721Semaste //------------------------------------------------------------------ 2070254721Semaste /// Called before attaching to a process. 2071254721Semaste /// 2072254721Semaste /// Allow Process plug-ins to execute some code before attaching a 2073254721Semaste /// process. 2074254721Semaste /// 2075254721Semaste /// @return 2076254721Semaste /// Returns an error object. 2077254721Semaste //------------------------------------------------------------------ 2078254721Semaste virtual Error 2079254721Semaste WillAttachToProcessWithID (lldb::pid_t pid) 2080254721Semaste { 2081254721Semaste return Error(); 2082254721Semaste } 2083254721Semaste 2084254721Semaste //------------------------------------------------------------------ 2085254721Semaste /// Called before attaching to a process. 2086254721Semaste /// 2087254721Semaste /// Allow Process plug-ins to execute some code before attaching a 2088254721Semaste /// process. 2089254721Semaste /// 2090254721Semaste /// @return 2091254721Semaste /// Returns an error object. 2092254721Semaste //------------------------------------------------------------------ 2093254721Semaste virtual Error 2094254721Semaste WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) 2095254721Semaste { 2096254721Semaste return Error(); 2097254721Semaste } 2098254721Semaste 2099254721Semaste //------------------------------------------------------------------ 2100254721Semaste /// Attach to a remote system via a URL 2101254721Semaste /// 2102254721Semaste /// @param[in] strm 2103254721Semaste /// A stream where output intended for the user 2104254721Semaste /// (if the driver has a way to display that) generated during 2105254721Semaste /// the connection. This may be NULL if no output is needed.A 2106254721Semaste /// 2107254721Semaste /// @param[in] remote_url 2108254721Semaste /// The URL format that we are connecting to. 2109254721Semaste /// 2110254721Semaste /// @return 2111254721Semaste /// Returns an error object. 2112254721Semaste //------------------------------------------------------------------ 2113254721Semaste virtual Error 2114254721Semaste DoConnectRemote (Stream *strm, const char *remote_url) 2115254721Semaste { 2116254721Semaste Error error; 2117254721Semaste error.SetErrorString ("remote connections are not supported"); 2118254721Semaste return error; 2119254721Semaste } 2120254721Semaste 2121254721Semaste //------------------------------------------------------------------ 2122254721Semaste /// Attach to an existing process using a process ID. 2123254721Semaste /// 2124254721Semaste /// @param[in] pid 2125254721Semaste /// The process ID that we should attempt to attach to. 2126254721Semaste /// 2127254721Semaste /// @return 2128254721Semaste /// Returns \a pid if attaching was successful, or 2129254721Semaste /// LLDB_INVALID_PROCESS_ID if attaching fails. 2130254721Semaste //------------------------------------------------------------------ 2131254721Semaste virtual Error 2132254721Semaste DoAttachToProcessWithID (lldb::pid_t pid) 2133254721Semaste { 2134254721Semaste Error error; 2135254721Semaste error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString()); 2136254721Semaste return error; 2137254721Semaste } 2138254721Semaste 2139254721Semaste //------------------------------------------------------------------ 2140254721Semaste /// Attach to an existing process using a process ID. 2141254721Semaste /// 2142254721Semaste /// @param[in] pid 2143254721Semaste /// The process ID that we should attempt to attach to. 2144254721Semaste /// 2145254721Semaste /// @param[in] attach_info 2146254721Semaste /// Information on how to do the attach. For example, GetUserID() 2147254721Semaste /// will return the uid to attach as. 2148254721Semaste /// 2149254721Semaste /// @return 2150254721Semaste /// Returns \a pid if attaching was successful, or 2151254721Semaste /// LLDB_INVALID_PROCESS_ID if attaching fails. 2152254721Semaste /// hanming : need flag 2153254721Semaste //------------------------------------------------------------------ 2154254721Semaste virtual Error 2155254721Semaste DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info) 2156254721Semaste { 2157254721Semaste Error error; 2158254721Semaste error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString()); 2159254721Semaste return error; 2160254721Semaste } 2161254721Semaste 2162254721Semaste //------------------------------------------------------------------ 2163254721Semaste /// Attach to an existing process using a partial process name. 2164254721Semaste /// 2165254721Semaste /// @param[in] process_name 2166254721Semaste /// The name of the process to attach to. 2167254721Semaste /// 2168254721Semaste /// @param[in] attach_info 2169254721Semaste /// Information on how to do the attach. For example, GetUserID() 2170254721Semaste /// will return the uid to attach as. 2171254721Semaste /// 2172254721Semaste /// @return 2173269024Semaste /// Returns an error object. 2174254721Semaste //------------------------------------------------------------------ 2175254721Semaste virtual Error 2176269024Semaste DoAttachToProcessWithName (const char *process_name, const ProcessAttachInfo &attach_info) 2177254721Semaste { 2178254721Semaste Error error; 2179254721Semaste error.SetErrorString("attach by name is not supported"); 2180254721Semaste return error; 2181254721Semaste } 2182254721Semaste 2183254721Semaste //------------------------------------------------------------------ 2184254721Semaste /// Called after attaching a process. 2185254721Semaste /// 2186254721Semaste /// Allow Process plug-ins to execute some code after attaching to 2187254721Semaste /// a process. 2188254721Semaste //------------------------------------------------------------------ 2189254721Semaste virtual void 2190254721Semaste DidAttach () {} 2191254721Semaste 2192254721Semaste 2193254721Semaste //------------------------------------------------------------------ 2194254721Semaste /// Called after a process re-execs itself. 2195254721Semaste /// 2196254721Semaste /// Allow Process plug-ins to execute some code after a process has 2197254721Semaste /// exec'ed itself. Subclasses typically should override DoDidExec() 2198254721Semaste /// as the lldb_private::Process class needs to remove its dynamic 2199254721Semaste /// loader, runtime, ABI and other plug-ins, as well as unload all 2200254721Semaste /// shared libraries. 2201254721Semaste //------------------------------------------------------------------ 2202254721Semaste virtual void 2203254721Semaste DidExec (); 2204254721Semaste 2205254721Semaste //------------------------------------------------------------------ 2206254721Semaste /// Subclasses of Process should implement this function if they 2207254721Semaste /// need to do anything after a process exec's itself. 2208254721Semaste //------------------------------------------------------------------ 2209254721Semaste virtual void 2210254721Semaste DoDidExec () 2211254721Semaste { 2212254721Semaste } 2213254721Semaste 2214254721Semaste //------------------------------------------------------------------ 2215254721Semaste /// Called before launching to a process. 2216254721Semaste /// 2217254721Semaste /// Allow Process plug-ins to execute some code before launching a 2218254721Semaste /// process. 2219254721Semaste /// 2220254721Semaste /// @return 2221254721Semaste /// Returns an error object. 2222254721Semaste //------------------------------------------------------------------ 2223254721Semaste virtual Error 2224254721Semaste WillLaunch (Module* module) 2225254721Semaste { 2226254721Semaste return Error(); 2227254721Semaste } 2228254721Semaste 2229254721Semaste //------------------------------------------------------------------ 2230254721Semaste /// Launch a new process. 2231254721Semaste /// 2232254721Semaste /// Launch a new process by spawning a new process using \a module's 2233254721Semaste /// file as the file to launch. Arguments are given in \a argv, 2234254721Semaste /// and the environment variables are in \a envp. Standard input 2235254721Semaste /// and output files can be optionally re-directed to \a stdin_path, 2236254721Semaste /// \a stdout_path, and \a stderr_path. 2237254721Semaste /// 2238254721Semaste /// @param[in] module 2239254721Semaste /// The module from which to extract the file specification and 2240254721Semaste /// launch. 2241254721Semaste /// 2242254721Semaste /// @param[in] argv 2243254721Semaste /// The argument array. 2244254721Semaste /// 2245254721Semaste /// @param[in] envp 2246254721Semaste /// The environment array. 2247254721Semaste /// 2248254721Semaste /// @param[in] launch_flags 2249254721Semaste /// Flags to modify the launch (@see lldb::LaunchFlags) 2250254721Semaste /// 2251254721Semaste /// @param[in] stdin_path 2252254721Semaste /// The path to use when re-directing the STDIN of the new 2253254721Semaste /// process. If all stdXX_path arguments are NULL, a pseudo 2254254721Semaste /// terminal will be used. 2255254721Semaste /// 2256254721Semaste /// @param[in] stdout_path 2257254721Semaste /// The path to use when re-directing the STDOUT of the new 2258254721Semaste /// process. If all stdXX_path arguments are NULL, a pseudo 2259254721Semaste /// terminal will be used. 2260254721Semaste /// 2261254721Semaste /// @param[in] stderr_path 2262254721Semaste /// The path to use when re-directing the STDERR of the new 2263254721Semaste /// process. If all stdXX_path arguments are NULL, a pseudo 2264254721Semaste /// terminal will be used. 2265254721Semaste /// 2266254721Semaste /// @param[in] working_directory 2267254721Semaste /// The working directory to have the child process run in 2268254721Semaste /// 2269254721Semaste /// @return 2270254721Semaste /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if 2271254721Semaste /// launching fails. 2272254721Semaste //------------------------------------------------------------------ 2273254721Semaste virtual Error 2274254721Semaste DoLaunch (Module *exe_module, 2275269024Semaste ProcessLaunchInfo &launch_info) 2276254721Semaste { 2277254721Semaste Error error; 2278254721Semaste error.SetErrorStringWithFormat("error: %s does not support launching processes", GetPluginName().GetCString()); 2279254721Semaste return error; 2280254721Semaste } 2281254721Semaste 2282254721Semaste 2283254721Semaste //------------------------------------------------------------------ 2284254721Semaste /// Called after launching a process. 2285254721Semaste /// 2286254721Semaste /// Allow Process plug-ins to execute some code after launching 2287254721Semaste /// a process. 2288254721Semaste //------------------------------------------------------------------ 2289254721Semaste virtual void 2290254721Semaste DidLaunch () {} 2291254721Semaste 2292254721Semaste 2293254721Semaste 2294254721Semaste //------------------------------------------------------------------ 2295254721Semaste /// Called before resuming to a process. 2296254721Semaste /// 2297254721Semaste /// Allow Process plug-ins to execute some code before resuming a 2298254721Semaste /// process. 2299254721Semaste /// 2300254721Semaste /// @return 2301254721Semaste /// Returns an error object. 2302254721Semaste //------------------------------------------------------------------ 2303254721Semaste virtual Error 2304254721Semaste WillResume () { return Error(); } 2305254721Semaste 2306254721Semaste //------------------------------------------------------------------ 2307254721Semaste /// Resumes all of a process's threads as configured using the 2308254721Semaste /// Thread run control functions. 2309254721Semaste /// 2310254721Semaste /// Threads for a process should be updated with one of the run 2311254721Semaste /// control actions (resume, step, or suspend) that they should take 2312254721Semaste /// when the process is resumed. If no run control action is given 2313254721Semaste /// to a thread it will be resumed by default. 2314254721Semaste /// 2315254721Semaste /// @return 2316254721Semaste /// Returns \b true if the process successfully resumes using 2317254721Semaste /// the thread run control actions, \b false otherwise. 2318254721Semaste /// 2319254721Semaste /// @see Thread:Resume() 2320254721Semaste /// @see Thread:Step() 2321254721Semaste /// @see Thread:Suspend() 2322254721Semaste //------------------------------------------------------------------ 2323254721Semaste virtual Error 2324254721Semaste DoResume () 2325254721Semaste { 2326254721Semaste Error error; 2327254721Semaste error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetPluginName().GetCString()); 2328254721Semaste return error; 2329254721Semaste } 2330254721Semaste 2331254721Semaste 2332254721Semaste //------------------------------------------------------------------ 2333254721Semaste /// Called after resuming a process. 2334254721Semaste /// 2335254721Semaste /// Allow Process plug-ins to execute some code after resuming 2336254721Semaste /// a process. 2337254721Semaste //------------------------------------------------------------------ 2338254721Semaste virtual void 2339254721Semaste DidResume () {} 2340254721Semaste 2341254721Semaste 2342254721Semaste //------------------------------------------------------------------ 2343254721Semaste /// Called before halting to a process. 2344254721Semaste /// 2345254721Semaste /// Allow Process plug-ins to execute some code before halting a 2346254721Semaste /// process. 2347254721Semaste /// 2348254721Semaste /// @return 2349254721Semaste /// Returns an error object. 2350254721Semaste //------------------------------------------------------------------ 2351254721Semaste virtual Error 2352254721Semaste WillHalt () { return Error(); } 2353254721Semaste 2354254721Semaste //------------------------------------------------------------------ 2355254721Semaste /// Halts a running process. 2356254721Semaste /// 2357254721Semaste /// DoHalt must produce one and only one stop StateChanged event if it actually 2358254721Semaste /// stops the process. If the stop happens through some natural event (for 2359254721Semaste /// instance a SIGSTOP), then forwarding that event will do. Otherwise, you must 2360254721Semaste /// generate the event manually. Note also, the private event thread is stopped when 2361254721Semaste /// DoHalt is run to prevent the events generated while halting to trigger 2362254721Semaste /// other state changes before the halt is complete. 2363254721Semaste /// 2364254721Semaste /// @param[out] caused_stop 2365254721Semaste /// If true, then this Halt caused the stop, otherwise, the 2366254721Semaste /// process was already stopped. 2367254721Semaste /// 2368254721Semaste /// @return 2369254721Semaste /// Returns \b true if the process successfully halts, \b false 2370254721Semaste /// otherwise. 2371254721Semaste //------------------------------------------------------------------ 2372254721Semaste virtual Error 2373254721Semaste DoHalt (bool &caused_stop) 2374254721Semaste { 2375254721Semaste Error error; 2376254721Semaste error.SetErrorStringWithFormat("error: %s does not support halting processes", GetPluginName().GetCString()); 2377254721Semaste return error; 2378254721Semaste } 2379254721Semaste 2380254721Semaste 2381254721Semaste //------------------------------------------------------------------ 2382254721Semaste /// Called after halting a process. 2383254721Semaste /// 2384254721Semaste /// Allow Process plug-ins to execute some code after halting 2385254721Semaste /// a process. 2386254721Semaste //------------------------------------------------------------------ 2387254721Semaste virtual void 2388254721Semaste DidHalt () {} 2389254721Semaste 2390254721Semaste //------------------------------------------------------------------ 2391254721Semaste /// Called before detaching from a process. 2392254721Semaste /// 2393254721Semaste /// Allow Process plug-ins to execute some code before detaching 2394254721Semaste /// from a process. 2395254721Semaste /// 2396254721Semaste /// @return 2397254721Semaste /// Returns an error object. 2398254721Semaste //------------------------------------------------------------------ 2399254721Semaste virtual Error 2400254721Semaste WillDetach () 2401254721Semaste { 2402254721Semaste return Error(); 2403254721Semaste } 2404254721Semaste 2405254721Semaste //------------------------------------------------------------------ 2406254721Semaste /// Detaches from a running or stopped process. 2407254721Semaste /// 2408254721Semaste /// @return 2409254721Semaste /// Returns \b true if the process successfully detaches, \b 2410254721Semaste /// false otherwise. 2411254721Semaste //------------------------------------------------------------------ 2412254721Semaste virtual Error 2413254721Semaste DoDetach (bool keep_stopped) 2414254721Semaste { 2415254721Semaste Error error; 2416254721Semaste error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetPluginName().GetCString()); 2417254721Semaste return error; 2418254721Semaste } 2419254721Semaste 2420254721Semaste 2421254721Semaste //------------------------------------------------------------------ 2422254721Semaste /// Called after detaching from a process. 2423254721Semaste /// 2424254721Semaste /// Allow Process plug-ins to execute some code after detaching 2425254721Semaste /// from a process. 2426254721Semaste //------------------------------------------------------------------ 2427254721Semaste virtual void 2428254721Semaste DidDetach () {} 2429254721Semaste 2430254721Semaste virtual bool 2431254721Semaste DetachRequiresHalt() { return false; } 2432254721Semaste 2433254721Semaste //------------------------------------------------------------------ 2434254721Semaste /// Called before sending a signal to a process. 2435254721Semaste /// 2436254721Semaste /// Allow Process plug-ins to execute some code before sending a 2437254721Semaste /// signal to a process. 2438254721Semaste /// 2439254721Semaste /// @return 2440254721Semaste /// Returns no error if it is safe to proceed with a call to 2441254721Semaste /// Process::DoSignal(int), otherwise an error describing what 2442254721Semaste /// prevents the signal from being sent. 2443254721Semaste //------------------------------------------------------------------ 2444254721Semaste virtual Error 2445254721Semaste WillSignal () { return Error(); } 2446254721Semaste 2447254721Semaste //------------------------------------------------------------------ 2448254721Semaste /// Sends a process a UNIX signal \a signal. 2449254721Semaste /// 2450254721Semaste /// @return 2451254721Semaste /// Returns an error object. 2452254721Semaste //------------------------------------------------------------------ 2453254721Semaste virtual Error 2454254721Semaste DoSignal (int signal) 2455254721Semaste { 2456254721Semaste Error error; 2457254721Semaste error.SetErrorStringWithFormat("error: %s does not support senging signals to processes", GetPluginName().GetCString()); 2458254721Semaste return error; 2459254721Semaste } 2460254721Semaste 2461254721Semaste virtual Error 2462254721Semaste WillDestroy () { return Error(); } 2463254721Semaste 2464254721Semaste virtual Error 2465254721Semaste DoDestroy () = 0; 2466254721Semaste 2467254721Semaste virtual void 2468254721Semaste DidDestroy () { } 2469254721Semaste 2470254721Semaste virtual bool 2471254721Semaste DestroyRequiresHalt() { return true; } 2472254721Semaste 2473254721Semaste 2474254721Semaste //------------------------------------------------------------------ 2475254721Semaste /// Called after sending a signal to a process. 2476254721Semaste /// 2477254721Semaste /// Allow Process plug-ins to execute some code after sending a 2478254721Semaste /// signal to a process. 2479254721Semaste //------------------------------------------------------------------ 2480254721Semaste virtual void 2481254721Semaste DidSignal () {} 2482254721Semaste 2483254721Semaste //------------------------------------------------------------------ 2484254721Semaste /// Currently called as part of ShouldStop. 2485254721Semaste /// FIXME: Should really happen when the target stops before the 2486254721Semaste /// event is taken from the queue... 2487254721Semaste /// 2488254721Semaste /// This callback is called as the event 2489254721Semaste /// is about to be queued up to allow Process plug-ins to execute 2490254721Semaste /// some code prior to clients being notified that a process was 2491254721Semaste /// stopped. Common operations include updating the thread list, 2492254721Semaste /// invalidating any thread state (registers, stack, etc) prior to 2493254721Semaste /// letting the notification go out. 2494254721Semaste /// 2495254721Semaste //------------------------------------------------------------------ 2496254721Semaste virtual void 2497254721Semaste RefreshStateAfterStop () = 0; 2498254721Semaste 2499254721Semaste //------------------------------------------------------------------ 2500254721Semaste /// Get the target object pointer for this module. 2501254721Semaste /// 2502254721Semaste /// @return 2503254721Semaste /// A Target object pointer to the target that owns this 2504254721Semaste /// module. 2505254721Semaste //------------------------------------------------------------------ 2506254721Semaste Target & 2507254721Semaste GetTarget () 2508254721Semaste { 2509254721Semaste return m_target; 2510254721Semaste } 2511254721Semaste 2512254721Semaste //------------------------------------------------------------------ 2513254721Semaste /// Get the const target object pointer for this module. 2514254721Semaste /// 2515254721Semaste /// @return 2516254721Semaste /// A const Target object pointer to the target that owns this 2517254721Semaste /// module. 2518254721Semaste //------------------------------------------------------------------ 2519254721Semaste const Target & 2520254721Semaste GetTarget () const 2521254721Semaste { 2522254721Semaste return m_target; 2523254721Semaste } 2524254721Semaste 2525254721Semaste //------------------------------------------------------------------ 2526254721Semaste /// Flush all data in the process. 2527254721Semaste /// 2528254721Semaste /// Flush the memory caches, all threads, and any other cached data 2529254721Semaste /// in the process. 2530254721Semaste /// 2531254721Semaste /// This function can be called after a world changing event like 2532254721Semaste /// adding a new symbol file, or after the process makes a large 2533254721Semaste /// context switch (from boot ROM to booted into an OS). 2534254721Semaste //------------------------------------------------------------------ 2535254721Semaste void 2536254721Semaste Flush (); 2537254721Semaste 2538254721Semaste //------------------------------------------------------------------ 2539254721Semaste /// Get accessor for the current process state. 2540254721Semaste /// 2541254721Semaste /// @return 2542254721Semaste /// The current state of the process. 2543254721Semaste /// 2544254721Semaste /// @see lldb::StateType 2545254721Semaste //------------------------------------------------------------------ 2546254721Semaste lldb::StateType 2547254721Semaste GetState (); 2548254721Semaste 2549254721Semaste ExecutionResults 2550254721Semaste RunThreadPlan (ExecutionContext &exe_ctx, 2551254721Semaste lldb::ThreadPlanSP &thread_plan_sp, 2552263367Semaste const EvaluateExpressionOptions &options, 2553254721Semaste Stream &errors); 2554254721Semaste 2555254721Semaste static const char * 2556254721Semaste ExecutionResultAsCString (ExecutionResults result); 2557254721Semaste 2558254721Semaste void 2559254721Semaste GetStatus (Stream &ostrm); 2560254721Semaste 2561254721Semaste size_t 2562254721Semaste GetThreadStatus (Stream &ostrm, 2563254721Semaste bool only_threads_with_stop_reason, 2564254721Semaste uint32_t start_frame, 2565254721Semaste uint32_t num_frames, 2566254721Semaste uint32_t num_frames_with_source); 2567254721Semaste 2568254721Semaste void 2569254721Semaste SendAsyncInterrupt (); 2570254721Semaste 2571254721Semasteprotected: 2572254721Semaste 2573254721Semaste void 2574254721Semaste SetState (lldb::EventSP &event_sp); 2575254721Semaste 2576254721Semaste lldb::StateType 2577254721Semaste GetPrivateState (); 2578254721Semaste 2579254721Semaste //------------------------------------------------------------------ 2580254721Semaste /// The "private" side of resuming a process. This doesn't alter the 2581254721Semaste /// state of m_run_lock, but just causes the process to resume. 2582254721Semaste /// 2583254721Semaste /// @return 2584254721Semaste /// An Error object describing the success or failure of the resume. 2585254721Semaste //------------------------------------------------------------------ 2586254721Semaste Error 2587254721Semaste PrivateResume (); 2588254721Semaste 2589254721Semaste //------------------------------------------------------------------ 2590254721Semaste // Called internally 2591254721Semaste //------------------------------------------------------------------ 2592254721Semaste void 2593254721Semaste CompleteAttach (); 2594254721Semaste 2595254721Semastepublic: 2596254721Semaste //------------------------------------------------------------------ 2597254721Semaste /// Get the exit status for a process. 2598254721Semaste /// 2599254721Semaste /// @return 2600254721Semaste /// The process's return code, or -1 if the current process 2601254721Semaste /// state is not eStateExited. 2602254721Semaste //------------------------------------------------------------------ 2603254721Semaste int 2604254721Semaste GetExitStatus (); 2605254721Semaste 2606254721Semaste //------------------------------------------------------------------ 2607254721Semaste /// Get a textual description of what the process exited. 2608254721Semaste /// 2609254721Semaste /// @return 2610254721Semaste /// The textual description of why the process exited, or NULL 2611254721Semaste /// if there is no description available. 2612254721Semaste //------------------------------------------------------------------ 2613254721Semaste const char * 2614254721Semaste GetExitDescription (); 2615254721Semaste 2616254721Semaste 2617254721Semaste virtual void 2618254721Semaste DidExit () 2619254721Semaste { 2620254721Semaste } 2621254721Semaste 2622254721Semaste //------------------------------------------------------------------ 2623254721Semaste /// Get the Modification ID of the process. 2624254721Semaste /// 2625254721Semaste /// @return 2626254721Semaste /// The modification ID of the process. 2627254721Semaste //------------------------------------------------------------------ 2628254721Semaste ProcessModID 2629254721Semaste GetModID () const 2630254721Semaste { 2631254721Semaste return m_mod_id; 2632254721Semaste } 2633254721Semaste 2634254721Semaste const ProcessModID & 2635254721Semaste GetModIDRef () const 2636254721Semaste { 2637254721Semaste return m_mod_id; 2638254721Semaste } 2639254721Semaste 2640254721Semaste uint32_t 2641254721Semaste GetStopID () const 2642254721Semaste { 2643254721Semaste return m_mod_id.GetStopID(); 2644254721Semaste } 2645254721Semaste 2646254721Semaste uint32_t 2647254721Semaste GetResumeID () const 2648254721Semaste { 2649254721Semaste return m_mod_id.GetResumeID(); 2650254721Semaste } 2651254721Semaste 2652254721Semaste uint32_t 2653254721Semaste GetLastUserExpressionResumeID () const 2654254721Semaste { 2655254721Semaste return m_mod_id.GetLastUserExpressionResumeID(); 2656254721Semaste } 2657254721Semaste 2658254721Semaste uint32_t 2659254721Semaste GetLastNaturalStopID() 2660254721Semaste { 2661254721Semaste return m_mod_id.GetLastNaturalStopID(); 2662254721Semaste } 2663254721Semaste 2664254721Semaste //------------------------------------------------------------------ 2665254721Semaste /// Set accessor for the process exit status (return code). 2666254721Semaste /// 2667254721Semaste /// Sometimes a child exits and the exit can be detected by global 2668254721Semaste /// functions (signal handler for SIGCHLD for example). This 2669254721Semaste /// accessor allows the exit status to be set from an external 2670254721Semaste /// source. 2671254721Semaste /// 2672254721Semaste /// Setting this will cause a eStateExited event to be posted to 2673254721Semaste /// the process event queue. 2674254721Semaste /// 2675254721Semaste /// @param[in] exit_status 2676254721Semaste /// The value for the process's return code. 2677254721Semaste /// 2678254721Semaste /// @see lldb::StateType 2679254721Semaste //------------------------------------------------------------------ 2680254721Semaste virtual bool 2681254721Semaste SetExitStatus (int exit_status, const char *cstr); 2682254721Semaste 2683254721Semaste //------------------------------------------------------------------ 2684254721Semaste /// Check if a process is still alive. 2685254721Semaste /// 2686254721Semaste /// @return 2687254721Semaste /// Returns \b true if the process is still valid, \b false 2688254721Semaste /// otherwise. 2689254721Semaste //------------------------------------------------------------------ 2690254721Semaste virtual bool 2691254721Semaste IsAlive () = 0; 2692254721Semaste 2693254721Semaste //------------------------------------------------------------------ 2694254721Semaste /// Before lldb detaches from a process, it warns the user that they are about to lose their debug session. 2695254721Semaste /// In some cases, this warning doesn't need to be emitted -- for instance, with core file debugging where 2696254721Semaste /// the user can reconstruct the "state" by simply re-running the debugger on the core file. 2697254721Semaste /// 2698254721Semaste /// @return 2699254721Semaste // true if the user should be warned about detaching from this process. 2700254721Semaste //------------------------------------------------------------------ 2701254721Semaste virtual bool 2702254721Semaste WarnBeforeDetach () const 2703254721Semaste { 2704254721Semaste return true; 2705254721Semaste } 2706254721Semaste 2707254721Semaste //------------------------------------------------------------------ 2708254721Semaste /// Actually do the reading of memory from a process. 2709254721Semaste /// 2710254721Semaste /// Subclasses must override this function and can return fewer 2711254721Semaste /// bytes than requested when memory requests are too large. This 2712254721Semaste /// class will break up the memory requests and keep advancing the 2713254721Semaste /// arguments along as needed. 2714254721Semaste /// 2715254721Semaste /// @param[in] vm_addr 2716254721Semaste /// A virtual load address that indicates where to start reading 2717254721Semaste /// memory from. 2718254721Semaste /// 2719254721Semaste /// @param[in] size 2720254721Semaste /// The number of bytes to read. 2721254721Semaste /// 2722254721Semaste /// @param[out] buf 2723254721Semaste /// A byte buffer that is at least \a size bytes long that 2724254721Semaste /// will receive the memory bytes. 2725254721Semaste /// 2726254721Semaste /// @return 2727254721Semaste /// The number of bytes that were actually read into \a buf. 2728254721Semaste //------------------------------------------------------------------ 2729254721Semaste virtual size_t 2730254721Semaste DoReadMemory (lldb::addr_t vm_addr, 2731254721Semaste void *buf, 2732254721Semaste size_t size, 2733254721Semaste Error &error) = 0; 2734254721Semaste 2735254721Semaste //------------------------------------------------------------------ 2736254721Semaste /// Read of memory from a process. 2737254721Semaste /// 2738254721Semaste /// This function will read memory from the current process's 2739254721Semaste /// address space and remove any traps that may have been inserted 2740254721Semaste /// into the memory. 2741254721Semaste /// 2742254721Semaste /// This function is not meant to be overridden by Process 2743254721Semaste /// subclasses, the subclasses should implement 2744254721Semaste /// Process::DoReadMemory (lldb::addr_t, size_t, void *). 2745254721Semaste /// 2746254721Semaste /// @param[in] vm_addr 2747254721Semaste /// A virtual load address that indicates where to start reading 2748254721Semaste /// memory from. 2749254721Semaste /// 2750254721Semaste /// @param[out] buf 2751254721Semaste /// A byte buffer that is at least \a size bytes long that 2752254721Semaste /// will receive the memory bytes. 2753254721Semaste /// 2754254721Semaste /// @param[in] size 2755254721Semaste /// The number of bytes to read. 2756254721Semaste /// 2757254721Semaste /// @return 2758254721Semaste /// The number of bytes that were actually read into \a buf. If 2759254721Semaste /// the returned number is greater than zero, yet less than \a 2760254721Semaste /// size, then this function will get called again with \a 2761254721Semaste /// vm_addr, \a buf, and \a size updated appropriately. Zero is 2762254721Semaste /// returned to indicate an error. 2763254721Semaste //------------------------------------------------------------------ 2764254721Semaste virtual size_t 2765254721Semaste ReadMemory (lldb::addr_t vm_addr, 2766254721Semaste void *buf, 2767254721Semaste size_t size, 2768254721Semaste Error &error); 2769254721Semaste 2770254721Semaste //------------------------------------------------------------------ 2771254721Semaste /// Read a NULL terminated string from memory 2772254721Semaste /// 2773254721Semaste /// This function will read a cache page at a time until a NULL 2774254721Semaste /// string terminator is found. It will stop reading if an aligned 2775254721Semaste /// sequence of NULL termination \a type_width bytes is not found 2776254721Semaste /// before reading \a cstr_max_len bytes. The results are always 2777254721Semaste /// guaranteed to be NULL terminated, and that no more than 2778254721Semaste /// (max_bytes - type_width) bytes will be read. 2779254721Semaste /// 2780254721Semaste /// @param[in] vm_addr 2781254721Semaste /// The virtual load address to start the memory read. 2782254721Semaste /// 2783254721Semaste /// @param[in] str 2784254721Semaste /// A character buffer containing at least max_bytes. 2785254721Semaste /// 2786254721Semaste /// @param[in] max_bytes 2787254721Semaste /// The maximum number of bytes to read. 2788254721Semaste /// 2789254721Semaste /// @param[in] error 2790254721Semaste /// The error status of the read operation. 2791254721Semaste /// 2792254721Semaste /// @param[in] type_width 2793254721Semaste /// The size of the null terminator (1 to 4 bytes per 2794254721Semaste /// character). Defaults to 1. 2795254721Semaste /// 2796254721Semaste /// @return 2797254721Semaste /// The error status or the number of bytes prior to the null terminator. 2798254721Semaste //------------------------------------------------------------------ 2799254721Semaste size_t 2800254721Semaste ReadStringFromMemory (lldb::addr_t vm_addr, 2801254721Semaste char *str, 2802254721Semaste size_t max_bytes, 2803254721Semaste Error &error, 2804254721Semaste size_t type_width = 1); 2805254721Semaste 2806254721Semaste //------------------------------------------------------------------ 2807254721Semaste /// Read a NULL terminated C string from memory 2808254721Semaste /// 2809254721Semaste /// This function will read a cache page at a time until the NULL 2810254721Semaste /// C string terminator is found. It will stop reading if the NULL 2811254721Semaste /// termination byte isn't found before reading \a cstr_max_len 2812254721Semaste /// bytes, and the results are always guaranteed to be NULL 2813254721Semaste /// terminated (at most cstr_max_len - 1 bytes will be read). 2814254721Semaste //------------------------------------------------------------------ 2815254721Semaste size_t 2816254721Semaste ReadCStringFromMemory (lldb::addr_t vm_addr, 2817254721Semaste char *cstr, 2818254721Semaste size_t cstr_max_len, 2819254721Semaste Error &error); 2820254721Semaste 2821254721Semaste size_t 2822254721Semaste ReadCStringFromMemory (lldb::addr_t vm_addr, 2823254721Semaste std::string &out_str, 2824254721Semaste Error &error); 2825254721Semaste 2826254721Semaste size_t 2827254721Semaste ReadMemoryFromInferior (lldb::addr_t vm_addr, 2828254721Semaste void *buf, 2829254721Semaste size_t size, 2830254721Semaste Error &error); 2831254721Semaste 2832254721Semaste //------------------------------------------------------------------ 2833254721Semaste /// Reads an unsigned integer of the specified byte size from 2834254721Semaste /// process memory. 2835254721Semaste /// 2836254721Semaste /// @param[in] load_addr 2837254721Semaste /// A load address of the integer to read. 2838254721Semaste /// 2839254721Semaste /// @param[in] byte_size 2840254721Semaste /// The size in byte of the integer to read. 2841254721Semaste /// 2842254721Semaste /// @param[in] fail_value 2843254721Semaste /// The value to return if we fail to read an integer. 2844254721Semaste /// 2845254721Semaste /// @param[out] error 2846254721Semaste /// An error that indicates the success or failure of this 2847254721Semaste /// operation. If error indicates success (error.Success()), 2848254721Semaste /// then the value returned can be trusted, otherwise zero 2849254721Semaste /// will be returned. 2850254721Semaste /// 2851254721Semaste /// @return 2852254721Semaste /// The unsigned integer that was read from the process memory 2853254721Semaste /// space. If the integer was smaller than a uint64_t, any 2854254721Semaste /// unused upper bytes will be zero filled. If the process 2855254721Semaste /// byte order differs from the host byte order, the integer 2856254721Semaste /// value will be appropriately byte swapped into host byte 2857254721Semaste /// order. 2858254721Semaste //------------------------------------------------------------------ 2859254721Semaste uint64_t 2860254721Semaste ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr, 2861254721Semaste size_t byte_size, 2862254721Semaste uint64_t fail_value, 2863254721Semaste Error &error); 2864254721Semaste 2865254721Semaste lldb::addr_t 2866254721Semaste ReadPointerFromMemory (lldb::addr_t vm_addr, 2867254721Semaste Error &error); 2868254721Semaste 2869254721Semaste bool 2870254721Semaste WritePointerToMemory (lldb::addr_t vm_addr, 2871254721Semaste lldb::addr_t ptr_value, 2872254721Semaste Error &error); 2873254721Semaste 2874254721Semaste //------------------------------------------------------------------ 2875254721Semaste /// Actually do the writing of memory to a process. 2876254721Semaste /// 2877254721Semaste /// @param[in] vm_addr 2878254721Semaste /// A virtual load address that indicates where to start writing 2879254721Semaste /// memory to. 2880254721Semaste /// 2881254721Semaste /// @param[in] buf 2882254721Semaste /// A byte buffer that is at least \a size bytes long that 2883254721Semaste /// contains the data to write. 2884254721Semaste /// 2885254721Semaste /// @param[in] size 2886254721Semaste /// The number of bytes to write. 2887254721Semaste /// 2888254721Semaste /// @param[out] error 2889254721Semaste /// An error value in case the memory write fails. 2890254721Semaste /// 2891254721Semaste /// @return 2892254721Semaste /// The number of bytes that were actually written. 2893254721Semaste //------------------------------------------------------------------ 2894254721Semaste virtual size_t 2895254721Semaste DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) 2896254721Semaste { 2897254721Semaste error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetPluginName().GetCString()); 2898254721Semaste return 0; 2899254721Semaste } 2900254721Semaste 2901254721Semaste 2902254721Semaste //------------------------------------------------------------------ 2903254721Semaste /// Write all or part of a scalar value to memory. 2904254721Semaste /// 2905254721Semaste /// The value contained in \a scalar will be swapped to match the 2906254721Semaste /// byte order of the process that is being debugged. If \a size is 2907254721Semaste /// less than the size of scalar, the least significate \a size bytes 2908254721Semaste /// from scalar will be written. If \a size is larger than the byte 2909254721Semaste /// size of scalar, then the extra space will be padded with zeros 2910254721Semaste /// and the scalar value will be placed in the least significant 2911254721Semaste /// bytes in memory. 2912254721Semaste /// 2913254721Semaste /// @param[in] vm_addr 2914254721Semaste /// A virtual load address that indicates where to start writing 2915254721Semaste /// memory to. 2916254721Semaste /// 2917254721Semaste /// @param[in] scalar 2918254721Semaste /// The scalar to write to the debugged process. 2919254721Semaste /// 2920254721Semaste /// @param[in] size 2921254721Semaste /// This value can be smaller or larger than the scalar value 2922254721Semaste /// itself. If \a size is smaller than the size of \a scalar, 2923254721Semaste /// the least significant bytes in \a scalar will be used. If 2924254721Semaste /// \a size is larger than the byte size of \a scalar, then 2925254721Semaste /// the extra space will be padded with zeros. If \a size is 2926254721Semaste /// set to UINT32_MAX, then the size of \a scalar will be used. 2927254721Semaste /// 2928254721Semaste /// @param[out] error 2929254721Semaste /// An error value in case the memory write fails. 2930254721Semaste /// 2931254721Semaste /// @return 2932254721Semaste /// The number of bytes that were actually written. 2933254721Semaste //------------------------------------------------------------------ 2934254721Semaste size_t 2935254721Semaste WriteScalarToMemory (lldb::addr_t vm_addr, 2936254721Semaste const Scalar &scalar, 2937254721Semaste size_t size, 2938254721Semaste Error &error); 2939254721Semaste 2940254721Semaste size_t 2941254721Semaste ReadScalarIntegerFromMemory (lldb::addr_t addr, 2942254721Semaste uint32_t byte_size, 2943254721Semaste bool is_signed, 2944254721Semaste Scalar &scalar, 2945254721Semaste Error &error); 2946254721Semaste 2947254721Semaste //------------------------------------------------------------------ 2948254721Semaste /// Write memory to a process. 2949254721Semaste /// 2950254721Semaste /// This function will write memory to the current process's 2951254721Semaste /// address space and maintain any traps that might be present due 2952254721Semaste /// to software breakpoints. 2953254721Semaste /// 2954254721Semaste /// This function is not meant to be overridden by Process 2955254721Semaste /// subclasses, the subclasses should implement 2956254721Semaste /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). 2957254721Semaste /// 2958254721Semaste /// @param[in] vm_addr 2959254721Semaste /// A virtual load address that indicates where to start writing 2960254721Semaste /// memory to. 2961254721Semaste /// 2962254721Semaste /// @param[in] buf 2963254721Semaste /// A byte buffer that is at least \a size bytes long that 2964254721Semaste /// contains the data to write. 2965254721Semaste /// 2966254721Semaste /// @param[in] size 2967254721Semaste /// The number of bytes to write. 2968254721Semaste /// 2969254721Semaste /// @return 2970254721Semaste /// The number of bytes that were actually written. 2971254721Semaste //------------------------------------------------------------------ 2972254721Semaste size_t 2973254721Semaste WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); 2974254721Semaste 2975254721Semaste 2976254721Semaste //------------------------------------------------------------------ 2977254721Semaste /// Actually allocate memory in the process. 2978254721Semaste /// 2979254721Semaste /// This function will allocate memory in the process's address 2980254721Semaste /// space. This can't rely on the generic function calling mechanism, 2981254721Semaste /// since that requires this function. 2982254721Semaste /// 2983254721Semaste /// @param[in] size 2984254721Semaste /// The size of the allocation requested. 2985254721Semaste /// 2986254721Semaste /// @return 2987254721Semaste /// The address of the allocated buffer in the process, or 2988254721Semaste /// LLDB_INVALID_ADDRESS if the allocation failed. 2989254721Semaste //------------------------------------------------------------------ 2990254721Semaste 2991254721Semaste virtual lldb::addr_t 2992254721Semaste DoAllocateMemory (size_t size, uint32_t permissions, Error &error) 2993254721Semaste { 2994254721Semaste error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetPluginName().GetCString()); 2995254721Semaste return LLDB_INVALID_ADDRESS; 2996254721Semaste } 2997254721Semaste 2998254721Semaste 2999254721Semaste //------------------------------------------------------------------ 3000254721Semaste /// The public interface to allocating memory in the process. 3001254721Semaste /// 3002254721Semaste /// This function will allocate memory in the process's address 3003254721Semaste /// space. This can't rely on the generic function calling mechanism, 3004254721Semaste /// since that requires this function. 3005254721Semaste /// 3006254721Semaste /// @param[in] size 3007254721Semaste /// The size of the allocation requested. 3008254721Semaste /// 3009254721Semaste /// @param[in] permissions 3010254721Semaste /// Or together any of the lldb::Permissions bits. The permissions on 3011254721Semaste /// a given memory allocation can't be changed after allocation. Note 3012254721Semaste /// that a block that isn't set writable can still be written on from lldb, 3013254721Semaste /// just not by the process itself. 3014254721Semaste /// 3015254721Semaste /// @param[in/out] error 3016254721Semaste /// An error object to fill in if things go wrong. 3017254721Semaste /// @return 3018254721Semaste /// The address of the allocated buffer in the process, or 3019254721Semaste /// LLDB_INVALID_ADDRESS if the allocation failed. 3020254721Semaste //------------------------------------------------------------------ 3021254721Semaste 3022254721Semaste lldb::addr_t 3023254721Semaste AllocateMemory (size_t size, uint32_t permissions, Error &error); 3024254721Semaste 3025254721Semaste 3026254721Semaste //------------------------------------------------------------------ 3027254721Semaste /// Resolve dynamically loaded indirect functions. 3028254721Semaste /// 3029254721Semaste /// @param[in] address 3030254721Semaste /// The load address of the indirect function to resolve. 3031254721Semaste /// 3032254721Semaste /// @param[out] error 3033254721Semaste /// An error value in case the resolve fails. 3034254721Semaste /// 3035254721Semaste /// @return 3036254721Semaste /// The address of the resolved function. 3037254721Semaste /// LLDB_INVALID_ADDRESS if the resolution failed. 3038254721Semaste //------------------------------------------------------------------ 3039254721Semaste 3040254721Semaste virtual lldb::addr_t 3041269024Semaste ResolveIndirectFunction(const Address *address, Error &error); 3042254721Semaste 3043254721Semaste virtual Error 3044269024Semaste GetMemoryRegionInfo (lldb::addr_t load_addr, 3045269024Semaste MemoryRegionInfo &range_info) 3046254721Semaste { 3047254721Semaste Error error; 3048254721Semaste error.SetErrorString ("Process::GetMemoryRegionInfo() not supported"); 3049254721Semaste return error; 3050254721Semaste } 3051254721Semaste 3052254721Semaste virtual Error 3053254721Semaste GetWatchpointSupportInfo (uint32_t &num) 3054254721Semaste { 3055254721Semaste Error error; 3056254721Semaste num = 0; 3057254721Semaste error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported"); 3058254721Semaste return error; 3059254721Semaste } 3060254721Semaste 3061254721Semaste virtual Error 3062254721Semaste GetWatchpointSupportInfo (uint32_t &num, bool& after) 3063254721Semaste { 3064254721Semaste Error error; 3065254721Semaste num = 0; 3066254721Semaste after = true; 3067254721Semaste error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported"); 3068254721Semaste return error; 3069254721Semaste } 3070254721Semaste 3071254721Semaste lldb::ModuleSP 3072254721Semaste ReadModuleFromMemory (const FileSpec& file_spec, 3073254721Semaste lldb::addr_t header_addr); 3074254721Semaste 3075254721Semaste //------------------------------------------------------------------ 3076254721Semaste /// Attempt to get the attributes for a region of memory in the process. 3077254721Semaste /// 3078254721Semaste /// It may be possible for the remote debug server to inspect attributes 3079254721Semaste /// for a region of memory in the process, such as whether there is a 3080254721Semaste /// valid page of memory at a given address or whether that page is 3081254721Semaste /// readable/writable/executable by the process. 3082254721Semaste /// 3083254721Semaste /// @param[in] load_addr 3084254721Semaste /// The address of interest in the process. 3085254721Semaste /// 3086254721Semaste /// @param[out] permissions 3087254721Semaste /// If this call returns successfully, this bitmask will have 3088254721Semaste /// its Permissions bits set to indicate whether the region is 3089254721Semaste /// readable/writable/executable. If this call fails, the 3090254721Semaste /// bitmask values are undefined. 3091254721Semaste /// 3092254721Semaste /// @return 3093254721Semaste /// Returns true if it was able to determine the attributes of the 3094254721Semaste /// memory region. False if not. 3095254721Semaste //------------------------------------------------------------------ 3096254721Semaste 3097254721Semaste virtual bool 3098254721Semaste GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions) 3099254721Semaste { 3100254721Semaste MemoryRegionInfo range_info; 3101254721Semaste permissions = 0; 3102254721Semaste Error error (GetMemoryRegionInfo (load_addr, range_info)); 3103254721Semaste if (!error.Success()) 3104254721Semaste return false; 3105254721Semaste if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow 3106254721Semaste || range_info.GetWritable() == MemoryRegionInfo::eDontKnow 3107254721Semaste || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow) 3108254721Semaste { 3109254721Semaste return false; 3110254721Semaste } 3111254721Semaste 3112254721Semaste if (range_info.GetReadable() == MemoryRegionInfo::eYes) 3113254721Semaste permissions |= lldb::ePermissionsReadable; 3114254721Semaste 3115254721Semaste if (range_info.GetWritable() == MemoryRegionInfo::eYes) 3116254721Semaste permissions |= lldb::ePermissionsWritable; 3117254721Semaste 3118254721Semaste if (range_info.GetExecutable() == MemoryRegionInfo::eYes) 3119254721Semaste permissions |= lldb::ePermissionsExecutable; 3120254721Semaste 3121254721Semaste return true; 3122254721Semaste } 3123254721Semaste 3124254721Semaste //------------------------------------------------------------------ 3125254721Semaste /// Determines whether executing JIT-compiled code in this process 3126254721Semaste /// is possible. 3127254721Semaste /// 3128254721Semaste /// @return 3129254721Semaste /// True if execution of JIT code is possible; false otherwise. 3130254721Semaste //------------------------------------------------------------------ 3131254721Semaste bool CanJIT (); 3132254721Semaste 3133254721Semaste //------------------------------------------------------------------ 3134254721Semaste /// Sets whether executing JIT-compiled code in this process 3135254721Semaste /// is possible. 3136254721Semaste /// 3137254721Semaste /// @param[in] can_jit 3138254721Semaste /// True if execution of JIT code is possible; false otherwise. 3139254721Semaste //------------------------------------------------------------------ 3140254721Semaste void SetCanJIT (bool can_jit); 3141254721Semaste 3142254721Semaste //------------------------------------------------------------------ 3143254721Semaste /// Actually deallocate memory in the process. 3144254721Semaste /// 3145254721Semaste /// This function will deallocate memory in the process's address 3146254721Semaste /// space that was allocated with AllocateMemory. 3147254721Semaste /// 3148254721Semaste /// @param[in] ptr 3149254721Semaste /// A return value from AllocateMemory, pointing to the memory you 3150254721Semaste /// want to deallocate. 3151254721Semaste /// 3152254721Semaste /// @return 3153254721Semaste /// \btrue if the memory was deallocated, \bfalse otherwise. 3154254721Semaste //------------------------------------------------------------------ 3155254721Semaste 3156254721Semaste virtual Error 3157254721Semaste DoDeallocateMemory (lldb::addr_t ptr) 3158254721Semaste { 3159254721Semaste Error error; 3160254721Semaste error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetPluginName().GetCString()); 3161254721Semaste return error; 3162254721Semaste } 3163254721Semaste 3164254721Semaste 3165254721Semaste //------------------------------------------------------------------ 3166254721Semaste /// The public interface to deallocating memory in the process. 3167254721Semaste /// 3168254721Semaste /// This function will deallocate memory in the process's address 3169254721Semaste /// space that was allocated with AllocateMemory. 3170254721Semaste /// 3171254721Semaste /// @param[in] ptr 3172254721Semaste /// A return value from AllocateMemory, pointing to the memory you 3173254721Semaste /// want to deallocate. 3174254721Semaste /// 3175254721Semaste /// @return 3176254721Semaste /// \btrue if the memory was deallocated, \bfalse otherwise. 3177254721Semaste //------------------------------------------------------------------ 3178254721Semaste 3179254721Semaste Error 3180254721Semaste DeallocateMemory (lldb::addr_t ptr); 3181254721Semaste 3182254721Semaste //------------------------------------------------------------------ 3183254721Semaste /// Get any available STDOUT. 3184254721Semaste /// 3185254721Semaste /// If the process was launched without supplying valid file paths 3186254721Semaste /// for stdin, stdout, and stderr, then the Process class might 3187254721Semaste /// try to cache the STDOUT for the process if it is able. Events 3188254721Semaste /// will be queued indicating that there is STDOUT available that 3189254721Semaste /// can be retrieved using this function. 3190254721Semaste /// 3191254721Semaste /// @param[out] buf 3192254721Semaste /// A buffer that will receive any STDOUT bytes that are 3193254721Semaste /// currently available. 3194254721Semaste /// 3195254721Semaste /// @param[out] buf_size 3196254721Semaste /// The size in bytes for the buffer \a buf. 3197254721Semaste /// 3198254721Semaste /// @return 3199254721Semaste /// The number of bytes written into \a buf. If this value is 3200254721Semaste /// equal to \a buf_size, another call to this function should 3201254721Semaste /// be made to retrieve more STDOUT data. 3202254721Semaste //------------------------------------------------------------------ 3203254721Semaste virtual size_t 3204254721Semaste GetSTDOUT (char *buf, size_t buf_size, Error &error); 3205254721Semaste 3206254721Semaste //------------------------------------------------------------------ 3207254721Semaste /// Get any available STDERR. 3208254721Semaste /// 3209254721Semaste /// If the process was launched without supplying valid file paths 3210254721Semaste /// for stdin, stdout, and stderr, then the Process class might 3211254721Semaste /// try to cache the STDERR for the process if it is able. Events 3212254721Semaste /// will be queued indicating that there is STDERR available that 3213254721Semaste /// can be retrieved using this function. 3214254721Semaste /// 3215254721Semaste /// @param[out] buf 3216254721Semaste /// A buffer that will receive any STDERR bytes that are 3217254721Semaste /// currently available. 3218254721Semaste /// 3219254721Semaste /// @param[out] buf_size 3220254721Semaste /// The size in bytes for the buffer \a buf. 3221254721Semaste /// 3222254721Semaste /// @return 3223254721Semaste /// The number of bytes written into \a buf. If this value is 3224254721Semaste /// equal to \a buf_size, another call to this function should 3225254721Semaste /// be made to retrieve more STDERR data. 3226254721Semaste //------------------------------------------------------------------ 3227254721Semaste virtual size_t 3228254721Semaste GetSTDERR (char *buf, size_t buf_size, Error &error); 3229254721Semaste 3230254721Semaste virtual size_t 3231254721Semaste PutSTDIN (const char *buf, size_t buf_size, Error &error) 3232254721Semaste { 3233254721Semaste error.SetErrorString("stdin unsupported"); 3234254721Semaste return 0; 3235254721Semaste } 3236254721Semaste 3237254721Semaste //------------------------------------------------------------------ 3238254721Semaste /// Get any available profile data. 3239254721Semaste /// 3240254721Semaste /// @param[out] buf 3241254721Semaste /// A buffer that will receive any profile data bytes that are 3242254721Semaste /// currently available. 3243254721Semaste /// 3244254721Semaste /// @param[out] buf_size 3245254721Semaste /// The size in bytes for the buffer \a buf. 3246254721Semaste /// 3247254721Semaste /// @return 3248254721Semaste /// The number of bytes written into \a buf. If this value is 3249254721Semaste /// equal to \a buf_size, another call to this function should 3250254721Semaste /// be made to retrieve more profile data. 3251254721Semaste //------------------------------------------------------------------ 3252254721Semaste virtual size_t 3253254721Semaste GetAsyncProfileData (char *buf, size_t buf_size, Error &error); 3254254721Semaste 3255254721Semaste //---------------------------------------------------------------------- 3256254721Semaste // Process Breakpoints 3257254721Semaste //---------------------------------------------------------------------- 3258254721Semaste size_t 3259254721Semaste GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site); 3260254721Semaste 3261254721Semaste virtual Error 3262254721Semaste EnableBreakpointSite (BreakpointSite *bp_site) 3263254721Semaste { 3264254721Semaste Error error; 3265254721Semaste error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetPluginName().GetCString()); 3266254721Semaste return error; 3267254721Semaste } 3268254721Semaste 3269254721Semaste 3270254721Semaste virtual Error 3271254721Semaste DisableBreakpointSite (BreakpointSite *bp_site) 3272254721Semaste { 3273254721Semaste Error error; 3274254721Semaste error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetPluginName().GetCString()); 3275254721Semaste return error; 3276254721Semaste } 3277254721Semaste 3278254721Semaste 3279254721Semaste // This is implemented completely using the lldb::Process API. Subclasses 3280254721Semaste // don't need to implement this function unless the standard flow of 3281254721Semaste // read existing opcode, write breakpoint opcode, verify breakpoint opcode 3282254721Semaste // doesn't work for a specific process plug-in. 3283254721Semaste virtual Error 3284254721Semaste EnableSoftwareBreakpoint (BreakpointSite *bp_site); 3285254721Semaste 3286254721Semaste // This is implemented completely using the lldb::Process API. Subclasses 3287254721Semaste // don't need to implement this function unless the standard flow of 3288254721Semaste // restoring original opcode in memory and verifying the restored opcode 3289254721Semaste // doesn't work for a specific process plug-in. 3290254721Semaste virtual Error 3291254721Semaste DisableSoftwareBreakpoint (BreakpointSite *bp_site); 3292254721Semaste 3293254721Semaste BreakpointSiteList & 3294254721Semaste GetBreakpointSiteList(); 3295254721Semaste 3296254721Semaste const BreakpointSiteList & 3297254721Semaste GetBreakpointSiteList() const; 3298254721Semaste 3299254721Semaste void 3300254721Semaste DisableAllBreakpointSites (); 3301254721Semaste 3302254721Semaste Error 3303254721Semaste ClearBreakpointSiteByID (lldb::user_id_t break_id); 3304254721Semaste 3305254721Semaste lldb::break_id_t 3306254721Semaste CreateBreakpointSite (const lldb::BreakpointLocationSP &owner, 3307254721Semaste bool use_hardware); 3308254721Semaste 3309254721Semaste Error 3310254721Semaste DisableBreakpointSiteByID (lldb::user_id_t break_id); 3311254721Semaste 3312254721Semaste Error 3313254721Semaste EnableBreakpointSiteByID (lldb::user_id_t break_id); 3314254721Semaste 3315254721Semaste 3316254721Semaste // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove 3317254721Semaste // themselves from the owner's list of this breakpoint sites. 3318254721Semaste void 3319254721Semaste RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, 3320254721Semaste lldb::user_id_t owner_loc_id, 3321254721Semaste lldb::BreakpointSiteSP &bp_site_sp); 3322254721Semaste 3323254721Semaste //---------------------------------------------------------------------- 3324254721Semaste // Process Watchpoints (optional) 3325254721Semaste //---------------------------------------------------------------------- 3326254721Semaste virtual Error 3327254721Semaste EnableWatchpoint (Watchpoint *wp, bool notify = true); 3328254721Semaste 3329254721Semaste virtual Error 3330254721Semaste DisableWatchpoint (Watchpoint *wp, bool notify = true); 3331254721Semaste 3332254721Semaste //------------------------------------------------------------------ 3333254721Semaste // Thread Queries 3334254721Semaste //------------------------------------------------------------------ 3335254721Semaste virtual bool 3336254721Semaste UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0; 3337254721Semaste 3338254721Semaste void 3339254721Semaste UpdateThreadListIfNeeded (); 3340254721Semaste 3341254721Semaste ThreadList & 3342254721Semaste GetThreadList () 3343254721Semaste { 3344254721Semaste return m_thread_list; 3345254721Semaste } 3346263367Semaste 3347263367Semaste // When ExtendedBacktraces are requested, the HistoryThreads that are 3348263367Semaste // created need an owner -- they're saved here in the Process. The 3349263367Semaste // threads in this list are not iterated over - driver programs need to 3350263367Semaste // request the extended backtrace calls starting from a root concrete 3351263367Semaste // thread one by one. 3352263367Semaste ThreadList & 3353263367Semaste GetExtendedThreadList () 3354263367Semaste { 3355263367Semaste return m_extended_thread_list; 3356263367Semaste } 3357263367Semaste 3358263367Semaste ThreadList::ThreadIterable 3359263367Semaste Threads () 3360263367Semaste { 3361263367Semaste return m_thread_list.Threads(); 3362263367Semaste } 3363269024Semaste 3364254721Semaste uint32_t 3365254721Semaste GetNextThreadIndexID (uint64_t thread_id); 3366269024Semaste 3367254721Semaste lldb::ThreadSP 3368254721Semaste CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context); 3369254721Semaste 3370254721Semaste // Returns true if an index id has been assigned to a thread. 3371254721Semaste bool 3372254721Semaste HasAssignedIndexIDToThread(uint64_t sb_thread_id); 3373254721Semaste 3374254721Semaste // Given a thread_id, it will assign a more reasonable index id for display to the user. 3375254721Semaste // If the thread_id has previously been assigned, the same index id will be used. 3376254721Semaste uint32_t 3377254721Semaste AssignIndexIDToThread(uint64_t thread_id); 3378254721Semaste 3379254721Semaste //------------------------------------------------------------------ 3380269024Semaste // Queue Queries 3381269024Semaste //------------------------------------------------------------------ 3382269024Semaste 3383269024Semaste void 3384269024Semaste UpdateQueueListIfNeeded (); 3385269024Semaste 3386269024Semaste QueueList & 3387269024Semaste GetQueueList () 3388269024Semaste { 3389269024Semaste UpdateQueueListIfNeeded(); 3390269024Semaste return m_queue_list; 3391269024Semaste } 3392269024Semaste 3393269024Semaste QueueList::QueueIterable 3394269024Semaste Queues () 3395269024Semaste { 3396269024Semaste UpdateQueueListIfNeeded(); 3397269024Semaste return m_queue_list.Queues(); 3398269024Semaste } 3399269024Semaste 3400269024Semaste //------------------------------------------------------------------ 3401254721Semaste // Event Handling 3402254721Semaste //------------------------------------------------------------------ 3403254721Semaste lldb::StateType 3404254721Semaste GetNextEvent (lldb::EventSP &event_sp); 3405254721Semaste 3406263363Semaste // Returns the process state when it is stopped. If specified, event_sp_ptr 3407263363Semaste // is set to the event which triggered the stop. If wait_always = false, 3408263363Semaste // and the process is already stopped, this function returns immediately. 3409254721Semaste lldb::StateType 3410269024Semaste WaitForProcessToStop (const TimeValue *timeout, 3411269024Semaste lldb::EventSP *event_sp_ptr = NULL, 3412269024Semaste bool wait_always = true, 3413269024Semaste Listener *hijack_listener = NULL); 3414254721Semaste 3415254721Semaste lldb::StateType 3416269024Semaste WaitForStateChangedEvents (const TimeValue *timeout, 3417269024Semaste lldb::EventSP &event_sp, 3418269024Semaste Listener *hijack_listener); // Pass NULL to use builtin listener 3419254721Semaste 3420254721Semaste Event * 3421254721Semaste PeekAtStateChangedEvents (); 3422254721Semaste 3423254721Semaste 3424254721Semaste class 3425254721Semaste ProcessEventHijacker 3426254721Semaste { 3427254721Semaste public: 3428254721Semaste ProcessEventHijacker (Process &process, Listener *listener) : 3429254721Semaste m_process (process) 3430254721Semaste { 3431254721Semaste m_process.HijackProcessEvents (listener); 3432254721Semaste } 3433254721Semaste ~ProcessEventHijacker () 3434254721Semaste { 3435254721Semaste m_process.RestoreProcessEvents(); 3436254721Semaste } 3437254721Semaste 3438254721Semaste private: 3439254721Semaste Process &m_process; 3440254721Semaste }; 3441254721Semaste friend class ProcessEventHijacker; 3442254721Semaste //------------------------------------------------------------------ 3443254721Semaste /// If you need to ensure that you and only you will hear about some public 3444254721Semaste /// event, then make a new listener, set to listen to process events, and 3445254721Semaste /// then call this with that listener. Then you will have to wait on that 3446254721Semaste /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* 3447254721Semaste /// calls above. Be sure to call RestoreProcessEvents when you are done. 3448254721Semaste /// 3449254721Semaste /// @param[in] listener 3450254721Semaste /// This is the new listener to whom all process events will be delivered. 3451254721Semaste /// 3452254721Semaste /// @return 3453254721Semaste /// Returns \b true if the new listener could be installed, 3454254721Semaste /// \b false otherwise. 3455254721Semaste //------------------------------------------------------------------ 3456254721Semaste bool 3457254721Semaste HijackProcessEvents (Listener *listener); 3458254721Semaste 3459254721Semaste //------------------------------------------------------------------ 3460254721Semaste /// Restores the process event broadcasting to its normal state. 3461254721Semaste /// 3462254721Semaste //------------------------------------------------------------------ 3463254721Semaste void 3464254721Semaste RestoreProcessEvents (); 3465254721Semaste 3466254721Semasteprivate: 3467254721Semaste //------------------------------------------------------------------ 3468254721Semaste /// This is the part of the event handling that for a process event. 3469254721Semaste /// It decides what to do with the event and returns true if the 3470254721Semaste /// event needs to be propagated to the user, and false otherwise. 3471254721Semaste /// If the event is not propagated, this call will most likely set 3472254721Semaste /// the target to executing again. 3473254721Semaste /// There is only one place where this call should be called, HandlePrivateEvent. 3474254721Semaste /// Don't call it from anywhere else... 3475254721Semaste /// 3476254721Semaste /// @param[in] event_ptr 3477254721Semaste /// This is the event we are handling. 3478254721Semaste /// 3479254721Semaste /// @return 3480254721Semaste /// Returns \b true if the event should be reported to the 3481254721Semaste /// user, \b false otherwise. 3482254721Semaste //------------------------------------------------------------------ 3483254721Semaste bool 3484254721Semaste ShouldBroadcastEvent (Event *event_ptr); 3485254721Semaste 3486254721Semastepublic: 3487254721Semaste const lldb::ABISP & 3488254721Semaste GetABI (); 3489254721Semaste 3490254721Semaste OperatingSystem * 3491254721Semaste GetOperatingSystem () 3492254721Semaste { 3493254721Semaste return m_os_ap.get(); 3494254721Semaste } 3495254721Semaste 3496254721Semaste 3497254721Semaste virtual LanguageRuntime * 3498254721Semaste GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true); 3499254721Semaste 3500254721Semaste virtual CPPLanguageRuntime * 3501254721Semaste GetCPPLanguageRuntime (bool retry_if_null = true); 3502254721Semaste 3503254721Semaste virtual ObjCLanguageRuntime * 3504254721Semaste GetObjCLanguageRuntime (bool retry_if_null = true); 3505254721Semaste 3506254721Semaste bool 3507254721Semaste IsPossibleDynamicValue (ValueObject& in_value); 3508254721Semaste 3509254721Semaste bool 3510254721Semaste IsRunning () const; 3511254721Semaste 3512254721Semaste DynamicCheckerFunctions *GetDynamicCheckers() 3513254721Semaste { 3514254721Semaste return m_dynamic_checkers_ap.get(); 3515254721Semaste } 3516254721Semaste 3517254721Semaste void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) 3518254721Semaste { 3519254721Semaste m_dynamic_checkers_ap.reset(dynamic_checkers); 3520254721Semaste } 3521254721Semaste 3522254721Semaste //------------------------------------------------------------------ 3523254721Semaste /// Call this to set the lldb in the mode where it breaks on new thread 3524254721Semaste /// creations, and then auto-restarts. This is useful when you are trying 3525254721Semaste /// to run only one thread, but either that thread or the kernel is creating 3526254721Semaste /// new threads in the process. If you stop when the thread is created, you 3527254721Semaste /// can immediately suspend it, and keep executing only the one thread you intend. 3528254721Semaste /// 3529254721Semaste /// @return 3530254721Semaste /// Returns \b true if we were able to start up the notification 3531254721Semaste /// \b false otherwise. 3532254721Semaste //------------------------------------------------------------------ 3533254721Semaste virtual bool 3534254721Semaste StartNoticingNewThreads() 3535254721Semaste { 3536254721Semaste return true; 3537254721Semaste } 3538254721Semaste 3539254721Semaste //------------------------------------------------------------------ 3540254721Semaste /// Call this to turn off the stop & notice new threads mode. 3541254721Semaste /// 3542254721Semaste /// @return 3543254721Semaste /// Returns \b true if we were able to start up the notification 3544254721Semaste /// \b false otherwise. 3545254721Semaste //------------------------------------------------------------------ 3546254721Semaste virtual bool 3547254721Semaste StopNoticingNewThreads() 3548254721Semaste { 3549254721Semaste return true; 3550254721Semaste } 3551254721Semaste 3552254721Semaste void 3553254721Semaste SetRunningUserExpression (bool on); 3554254721Semaste 3555254721Semaste //------------------------------------------------------------------ 3556254721Semaste // lldb::ExecutionContextScope pure virtual functions 3557254721Semaste //------------------------------------------------------------------ 3558254721Semaste virtual lldb::TargetSP 3559254721Semaste CalculateTarget (); 3560254721Semaste 3561254721Semaste virtual lldb::ProcessSP 3562254721Semaste CalculateProcess () 3563254721Semaste { 3564254721Semaste return shared_from_this(); 3565254721Semaste } 3566254721Semaste 3567254721Semaste virtual lldb::ThreadSP 3568254721Semaste CalculateThread () 3569254721Semaste { 3570254721Semaste return lldb::ThreadSP(); 3571254721Semaste } 3572254721Semaste 3573254721Semaste virtual lldb::StackFrameSP 3574254721Semaste CalculateStackFrame () 3575254721Semaste { 3576254721Semaste return lldb::StackFrameSP(); 3577254721Semaste } 3578254721Semaste 3579254721Semaste virtual void 3580254721Semaste CalculateExecutionContext (ExecutionContext &exe_ctx); 3581254721Semaste 3582254721Semaste void 3583254721Semaste SetSTDIOFileDescriptor (int file_descriptor); 3584254721Semaste 3585269024Semaste void 3586269024Semaste WatchForSTDIN (IOHandler &io_handler); 3587269024Semaste 3588269024Semaste void 3589269024Semaste CancelWatchForSTDIN (bool exited); 3590269024Semaste 3591254721Semaste //------------------------------------------------------------------ 3592254721Semaste // Add a permanent region of memory that should never be read or 3593254721Semaste // written to. This can be used to ensure that memory reads or writes 3594254721Semaste // to certain areas of memory never end up being sent to the 3595254721Semaste // DoReadMemory or DoWriteMemory functions which can improve 3596254721Semaste // performance. 3597254721Semaste //------------------------------------------------------------------ 3598254721Semaste void 3599254721Semaste AddInvalidMemoryRegion (const LoadRange ®ion); 3600254721Semaste 3601254721Semaste //------------------------------------------------------------------ 3602254721Semaste // Remove a permanent region of memory that should never be read or 3603254721Semaste // written to that was previously added with AddInvalidMemoryRegion. 3604254721Semaste //------------------------------------------------------------------ 3605254721Semaste bool 3606254721Semaste RemoveInvalidMemoryRange (const LoadRange ®ion); 3607254721Semaste 3608254721Semaste //------------------------------------------------------------------ 3609254721Semaste // If the setup code of a thread plan needs to do work that might involve 3610254721Semaste // calling a function in the target, it should not do that work directly 3611254721Semaste // in one of the thread plan functions (DidPush/WillResume) because 3612254721Semaste // such work needs to be handled carefully. Instead, put that work in 3613254721Semaste // a PreResumeAction callback, and register it with the process. It will 3614254721Semaste // get done before the actual "DoResume" gets called. 3615254721Semaste //------------------------------------------------------------------ 3616254721Semaste 3617254721Semaste typedef bool (PreResumeActionCallback)(void *); 3618254721Semaste 3619254721Semaste void 3620254721Semaste AddPreResumeAction (PreResumeActionCallback callback, void *baton); 3621254721Semaste 3622254721Semaste bool 3623254721Semaste RunPreResumeActions (); 3624254721Semaste 3625254721Semaste void 3626254721Semaste ClearPreResumeActions (); 3627254721Semaste 3628254721Semaste ProcessRunLock & 3629254721Semaste GetRunLock () 3630254721Semaste { 3631254721Semaste if (Host::GetCurrentThread() == m_private_state_thread) 3632254721Semaste return m_private_run_lock; 3633254721Semaste else 3634254721Semaste return m_public_run_lock; 3635254721Semaste } 3636254721Semaste 3637254721Semasteprotected: 3638254721Semaste //------------------------------------------------------------------ 3639254721Semaste // NextEventAction provides a way to register an action on the next 3640254721Semaste // event that is delivered to this process. There is currently only 3641254721Semaste // one next event action allowed in the process at one time. If a 3642254721Semaste // new "NextEventAction" is added while one is already present, the 3643254721Semaste // old action will be discarded (with HandleBeingUnshipped called 3644254721Semaste // after it is discarded.) 3645254721Semaste // 3646254721Semaste // If you want to resume the process as a result of a resume action, 3647254721Semaste // call RequestResume, don't call Resume directly. 3648254721Semaste //------------------------------------------------------------------ 3649254721Semaste class NextEventAction 3650254721Semaste { 3651254721Semaste public: 3652254721Semaste typedef enum EventActionResult 3653254721Semaste { 3654254721Semaste eEventActionSuccess, 3655254721Semaste eEventActionRetry, 3656254721Semaste eEventActionExit 3657254721Semaste } EventActionResult; 3658254721Semaste 3659254721Semaste NextEventAction (Process *process) : 3660254721Semaste m_process(process) 3661254721Semaste { 3662254721Semaste } 3663254721Semaste 3664254721Semaste virtual 3665254721Semaste ~NextEventAction() 3666254721Semaste { 3667254721Semaste } 3668254721Semaste 3669254721Semaste virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0; 3670254721Semaste virtual void HandleBeingUnshipped () {} 3671254721Semaste virtual EventActionResult HandleBeingInterrupted () = 0; 3672254721Semaste virtual const char *GetExitString() = 0; 3673254721Semaste void RequestResume() 3674254721Semaste { 3675254721Semaste m_process->m_resume_requested = true; 3676254721Semaste } 3677254721Semaste protected: 3678254721Semaste Process *m_process; 3679254721Semaste }; 3680254721Semaste 3681254721Semaste void SetNextEventAction (Process::NextEventAction *next_event_action) 3682254721Semaste { 3683254721Semaste if (m_next_event_action_ap.get()) 3684254721Semaste m_next_event_action_ap->HandleBeingUnshipped(); 3685254721Semaste 3686254721Semaste m_next_event_action_ap.reset(next_event_action); 3687254721Semaste } 3688254721Semaste 3689254721Semaste // This is the completer for Attaching: 3690254721Semaste class AttachCompletionHandler : public NextEventAction 3691254721Semaste { 3692254721Semaste public: 3693254721Semaste AttachCompletionHandler (Process *process, uint32_t exec_count) : 3694254721Semaste NextEventAction (process), 3695254721Semaste m_exec_count (exec_count) 3696254721Semaste { 3697254721Semaste } 3698254721Semaste 3699254721Semaste virtual 3700254721Semaste ~AttachCompletionHandler() 3701254721Semaste { 3702254721Semaste } 3703254721Semaste 3704254721Semaste virtual EventActionResult PerformAction (lldb::EventSP &event_sp); 3705254721Semaste virtual EventActionResult HandleBeingInterrupted (); 3706254721Semaste virtual const char *GetExitString(); 3707254721Semaste private: 3708254721Semaste uint32_t m_exec_count; 3709254721Semaste std::string m_exit_string; 3710254721Semaste }; 3711254721Semaste 3712254721Semaste bool 3713254721Semaste HijackPrivateProcessEvents (Listener *listener); 3714254721Semaste 3715254721Semaste void 3716254721Semaste RestorePrivateProcessEvents (); 3717254721Semaste 3718254721Semaste bool 3719254721Semaste PrivateStateThreadIsValid () const 3720254721Semaste { 3721254721Semaste return IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); 3722254721Semaste } 3723269024Semaste 3724269024Semaste void 3725269024Semaste ForceNextEventDelivery() 3726269024Semaste { 3727269024Semaste m_force_next_event_delivery = true; 3728269024Semaste } 3729254721Semaste 3730254721Semaste //------------------------------------------------------------------ 3731254721Semaste // Type definitions 3732254721Semaste //------------------------------------------------------------------ 3733254721Semaste typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection; 3734254721Semaste 3735254721Semaste struct PreResumeCallbackAndBaton 3736254721Semaste { 3737254721Semaste bool (*callback) (void *); 3738254721Semaste void *baton; 3739254721Semaste PreResumeCallbackAndBaton (PreResumeActionCallback in_callback, void *in_baton) : 3740254721Semaste callback (in_callback), 3741254721Semaste baton (in_baton) 3742254721Semaste { 3743254721Semaste } 3744254721Semaste }; 3745254721Semaste 3746254721Semaste //------------------------------------------------------------------ 3747254721Semaste // Member variables 3748254721Semaste //------------------------------------------------------------------ 3749254721Semaste Target & m_target; ///< The target that owns this process. 3750254721Semaste ThreadSafeValue<lldb::StateType> m_public_state; 3751254721Semaste ThreadSafeValue<lldb::StateType> m_private_state; // The actual state of our process 3752254721Semaste Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. 3753254721Semaste Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. 3754254721Semaste Listener m_private_state_listener; // This is the listener for the private state thread. 3755254721Semaste Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. 3756254721Semaste lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events 3757254721Semaste ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations. 3758254721Semaste uint32_t m_process_unique_id; ///< Each lldb_private::Process class that is created gets a unique integer ID that increments with each new instance 3759254721Semaste uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. 3760254721Semaste std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map; 3761254721Semaste int m_exit_status; ///< The exit status of the process, or -1 if not set. 3762254721Semaste std::string m_exit_string; ///< A textual description of why a process exited. 3763254721Semaste Mutex m_thread_mutex; 3764254721Semaste ThreadList m_thread_list_real; ///< The threads for this process as are known to the protocol we are debugging with 3765254721Semaste ThreadList m_thread_list; ///< The threads for this process as the user will see them. This is usually the same as 3766254721Semaste ///< m_thread_list_real, but might be different if there is an OS plug-in creating memory threads 3767263367Semaste ThreadList m_extended_thread_list; ///< Owner for extended threads that may be generated, cleared on natural stops 3768263367Semaste uint32_t m_extended_thread_stop_id; ///< The natural stop id when extended_thread_list was last updated 3769269024Semaste QueueList m_queue_list; ///< The list of libdispatch queues at a given stop point 3770269024Semaste uint32_t m_queue_list_stop_id; ///< The natural stop id when queue list was last fetched 3771254721Semaste std::vector<Notifications> m_notifications; ///< The list of notifications that this process can deliver. 3772254721Semaste std::vector<lldb::addr_t> m_image_tokens; 3773254721Semaste Listener &m_listener; 3774254721Semaste BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend to insert in the target. 3775254721Semaste std::unique_ptr<DynamicLoader> m_dyld_ap; 3776254721Semaste std::unique_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. 3777254721Semaste std::unique_ptr<OperatingSystem> m_os_ap; 3778263363Semaste std::unique_ptr<SystemRuntime> m_system_runtime_ap; 3779254721Semaste UnixSignals m_unix_signals; /// This is the current signal set for this process. 3780254721Semaste lldb::ABISP m_abi_sp; 3781269024Semaste lldb::IOHandlerSP m_process_input_reader; 3782254721Semaste Communication m_stdio_communication; 3783254721Semaste Mutex m_stdio_communication_mutex; 3784254721Semaste std::string m_stdout_data; 3785254721Semaste std::string m_stderr_data; 3786254721Semaste Mutex m_profile_data_comm_mutex; 3787254721Semaste std::vector<std::string> m_profile_data; 3788254721Semaste MemoryCache m_memory_cache; 3789254721Semaste AllocatedMemoryCache m_allocated_memory_cache; 3790254721Semaste bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach? 3791254721Semaste LanguageRuntimeCollection m_language_runtimes; 3792254721Semaste std::unique_ptr<NextEventAction> m_next_event_action_ap; 3793254721Semaste std::vector<PreResumeCallbackAndBaton> m_pre_resume_actions; 3794254721Semaste ProcessRunLock m_public_run_lock; 3795254721Semaste ProcessRunLock m_private_run_lock; 3796254721Semaste Predicate<bool> m_currently_handling_event; // This predicate is set in HandlePrivateEvent while all its business is being done. 3797254721Semaste bool m_currently_handling_do_on_removals; 3798254721Semaste bool m_resume_requested; // If m_currently_handling_event or m_currently_handling_do_on_removals are true, Resume will only request a resume, using this flag to check. 3799254721Semaste bool m_finalize_called; 3800254721Semaste bool m_clear_thread_plans_on_stop; 3801269024Semaste bool m_force_next_event_delivery; 3802254721Semaste lldb::StateType m_last_broadcast_state; /// This helps with the Public event coalescing in ShouldBroadcastEvent. 3803269024Semaste std::map<lldb::addr_t,lldb::addr_t> m_resolved_indirect_addresses; 3804254721Semaste bool m_destroy_in_process; 3805254721Semaste 3806254721Semaste enum { 3807254721Semaste eCanJITDontKnow= 0, 3808254721Semaste eCanJITYes, 3809254721Semaste eCanJITNo 3810254721Semaste } m_can_jit; 3811254721Semaste 3812254721Semaste size_t 3813254721Semaste RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; 3814254721Semaste 3815254721Semaste void 3816254721Semaste SynchronouslyNotifyStateChanged (lldb::StateType state); 3817254721Semaste 3818254721Semaste void 3819254721Semaste SetPublicState (lldb::StateType new_state, bool restarted); 3820254721Semaste 3821254721Semaste void 3822254721Semaste SetPrivateState (lldb::StateType state); 3823254721Semaste 3824254721Semaste bool 3825254721Semaste StartPrivateStateThread (bool force = false); 3826254721Semaste 3827254721Semaste void 3828254721Semaste StopPrivateStateThread (); 3829254721Semaste 3830254721Semaste void 3831254721Semaste PausePrivateStateThread (); 3832254721Semaste 3833254721Semaste void 3834254721Semaste ResumePrivateStateThread (); 3835254721Semaste 3836263363Semaste static lldb::thread_result_t 3837254721Semaste PrivateStateThread (void *arg); 3838254721Semaste 3839263363Semaste lldb::thread_result_t 3840254721Semaste RunPrivateStateThread (); 3841254721Semaste 3842254721Semaste void 3843254721Semaste HandlePrivateEvent (lldb::EventSP &event_sp); 3844254721Semaste 3845254721Semaste lldb::StateType 3846254721Semaste WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 3847254721Semaste 3848254721Semaste // This waits for both the state change broadcaster, and the control broadcaster. 3849254721Semaste // If control_only, it only waits for the control broadcaster. 3850254721Semaste 3851254721Semaste bool 3852254721Semaste WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); 3853254721Semaste 3854254721Semaste lldb::StateType 3855254721Semaste WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 3856254721Semaste 3857254721Semaste lldb::StateType 3858254721Semaste WaitForState (const TimeValue *timeout, 3859254721Semaste const lldb::StateType *match_states, 3860254721Semaste const uint32_t num_match_states); 3861254721Semaste 3862254721Semaste size_t 3863254721Semaste WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); 3864254721Semaste 3865254721Semaste void 3866254721Semaste AppendSTDOUT (const char *s, size_t len); 3867254721Semaste 3868254721Semaste void 3869254721Semaste AppendSTDERR (const char *s, size_t len); 3870254721Semaste 3871254721Semaste void 3872254721Semaste BroadcastAsyncProfileData(const std::string &one_profile_data); 3873254721Semaste 3874254721Semaste static void 3875254721Semaste STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); 3876254721Semaste 3877254721Semaste void 3878269024Semaste PushProcessIOHandler (); 3879254721Semaste 3880254721Semaste void 3881269024Semaste PopProcessIOHandler (); 3882254721Semaste 3883254721Semaste void 3884269024Semaste ResetProcessIOHandler (); 3885269024Semaste 3886254721Semaste Error 3887254721Semaste HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp); 3888254721Semaste 3889254721Semasteprivate: 3890254721Semaste //------------------------------------------------------------------ 3891254721Semaste // For Process only 3892254721Semaste //------------------------------------------------------------------ 3893254721Semaste void ControlPrivateStateThread (uint32_t signal); 3894254721Semaste 3895254721Semaste DISALLOW_COPY_AND_ASSIGN (Process); 3896254721Semaste 3897254721Semaste}; 3898254721Semaste 3899254721Semaste} // namespace lldb_private 3900254721Semaste 3901254721Semaste#endif // liblldb_Process_h_ 3902