LLDB  mainline
Process.h
Go to the documentation of this file.
1 //===-- Process.h -----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_Process_h_
10 #define liblldb_Process_h_
11 
12 #include "lldb/Host/Config.h"
13 
14 #include <limits.h>
15 
16 #include <chrono>
17 #include <list>
18 #include <memory>
19 #include <mutex>
20 #include <string>
21 #include <unordered_set>
22 #include <vector>
23 
30 #include "lldb/Host/HostThread.h"
34 #include "lldb/Symbol/ObjectFile.h"
37 #include "lldb/Target/Memory.h"
38 #include "lldb/Target/QueueList.h"
39 #include "lldb/Target/ThreadList.h"
40 #include "lldb/Utility/ArchSpec.h"
42 #include "lldb/Utility/Event.h"
43 #include "lldb/Utility/Listener.h"
46 #include "lldb/Utility/Status.h"
50 #include "lldb/lldb-private.h"
51 
52 #include "llvm/ADT/ArrayRef.h"
53 #include "llvm/Support/VersionTuple.h"
54 
55 namespace lldb_private {
56 
57 template <typename B, typename S> struct Range;
58 
59 // ProcessProperties
60 class ProcessProperties : public Properties {
61 public:
62  // Pass nullptr for "process" if the ProcessProperties are to be the global
63  // copy
65 
66  ~ProcessProperties() override;
67 
68  bool GetDisableMemoryCache() const;
69  uint64_t GetMemoryCacheLineSize() const;
71  void SetExtraStartupCommands(const Args &args);
73  void SetPythonOSPluginPath(const FileSpec &file);
75  void SetIgnoreBreakpointsInExpressions(bool ignore);
76  bool GetUnwindOnErrorInExpressions() const;
77  void SetUnwindOnErrorInExpressions(bool ignore);
78  bool GetStopOnSharedLibraryEvents() const;
79  void SetStopOnSharedLibraryEvents(bool stop);
80  bool GetDetachKeepsStopped() const;
81  void SetDetachKeepsStopped(bool keep_stopped);
82  bool GetWarningsOptimization() const;
83  bool GetStopOnExec() const;
84  std::chrono::seconds GetUtilityExpressionTimeout() const;
85 
86 protected:
87  static void OptionValueChangedCallback(void *baton,
88  OptionValue *option_value);
89 
90  Process *m_process; // Can be nullptr for global ProcessProperties
91 };
92 
93 typedef std::shared_ptr<ProcessProperties> ProcessPropertiesSP;
94 
95 // ProcessAttachInfo
96 //
97 // Describes any information that is required to attach to a process.
98 
100 public:
102  : ProcessInstanceInfo(), m_listener_sp(), m_hijack_listener_sp(),
103  m_plugin_name(), m_resume_count(0), m_wait_for_launch(false),
104  m_ignore_existing(true), m_continue_once_attached(false),
105  m_detach_on_error(true), m_async(false) {}
106 
108  : ProcessInstanceInfo(), m_listener_sp(), m_hijack_listener_sp(),
109  m_plugin_name(), m_resume_count(0), m_wait_for_launch(false),
110  m_ignore_existing(true), m_continue_once_attached(false),
111  m_detach_on_error(true), m_async(false) {
112  ProcessInfo::operator=(launch_info);
113  SetProcessPluginName(launch_info.GetProcessPluginName());
114  SetResumeCount(launch_info.GetResumeCount());
115  SetListener(launch_info.GetListener());
116  SetHijackListener(launch_info.GetHijackListener());
117  m_detach_on_error = launch_info.GetDetachOnError();
118  }
119 
120  bool GetWaitForLaunch() const { return m_wait_for_launch; }
121 
122  void SetWaitForLaunch(bool b) { m_wait_for_launch = b; }
123 
124  bool GetAsync() const { return m_async; }
125 
126  void SetAsync(bool b) { m_async = b; }
127 
128  bool GetIgnoreExisting() const { return m_ignore_existing; }
129 
130  void SetIgnoreExisting(bool b) { m_ignore_existing = b; }
131 
132  bool GetContinueOnceAttached() const { return m_continue_once_attached; }
133 
134  void SetContinueOnceAttached(bool b) { m_continue_once_attached = b; }
135 
136  uint32_t GetResumeCount() const { return m_resume_count; }
137 
138  void SetResumeCount(uint32_t c) { m_resume_count = c; }
139 
140  const char *GetProcessPluginName() const {
141  return (m_plugin_name.empty() ? nullptr : m_plugin_name.c_str());
142  }
143 
144  void SetProcessPluginName(llvm::StringRef plugin) { m_plugin_name = plugin; }
145 
146  void Clear() {
148  m_plugin_name.clear();
149  m_resume_count = 0;
150  m_wait_for_launch = false;
151  m_ignore_existing = true;
152  m_continue_once_attached = false;
153  }
154 
155  bool ProcessInfoSpecified() const {
156  if (GetExecutableFile())
157  return true;
158  if (GetProcessID() != LLDB_INVALID_PROCESS_ID)
159  return true;
160  if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID)
161  return true;
162  return false;
163  }
164 
165  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
166 
167  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
168  m_hijack_listener_sp = listener_sp;
169  }
170 
171  bool GetDetachOnError() const { return m_detach_on_error; }
172 
173  void SetDetachOnError(bool enable) { m_detach_on_error = enable; }
174 
175  // Get and set the actual listener that will be used for the process events
176  lldb::ListenerSP GetListener() const { return m_listener_sp; }
177 
178  void SetListener(const lldb::ListenerSP &listener_sp) {
179  m_listener_sp = listener_sp;
180  }
181 
182  lldb::ListenerSP GetListenerForProcess(Debugger &debugger);
183 
184 protected:
185  lldb::ListenerSP m_listener_sp;
186  lldb::ListenerSP m_hijack_listener_sp;
187  std::string m_plugin_name;
188  uint32_t m_resume_count; // How many times do we resume after launching
191  bool m_continue_once_attached; // Supports the use-case scenario of
192  // immediately continuing the process once
193  // attached.
194  bool m_detach_on_error; // If we are debugging remotely, instruct the stub to
195  // detach rather than killing the target on error.
196  bool m_async; // Use an async attach where we start the attach and return
197  // immediately (used by GUI programs with --waitfor so they can
198  // call SBProcess::Stop() to cancel attach)
199 };
200 
202 public:
204  // Keep default values of all options in one place: OptionParsingStarting
205  // ()
206  OptionParsingStarting(nullptr);
207  }
208 
209  ~ProcessLaunchCommandOptions() override = default;
210 
211  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
212  ExecutionContext *execution_context) override;
213 
214  void OptionParsingStarting(ExecutionContext *execution_context) override {
215  launch_info.Clear();
216  disable_aslr = eLazyBoolCalculate;
217  }
218 
219  llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
220 
221  // Instance variables to hold the values for command options.
222 
225 };
226 
227 // This class tracks the Modification state of the process. Things that can
228 // currently modify the program are running the program (which will up the
229 // StopID) and writing memory (which will up the MemoryID.)
230 // FIXME: Should we also include modification of register states?
231 
233  friend bool operator==(const ProcessModID &lhs, const ProcessModID &rhs);
234 
235 public:
237  : m_stop_id(0), m_last_natural_stop_id(0), m_resume_id(0), m_memory_id(0),
238  m_last_user_expression_resume(0), m_running_user_expression(false),
239  m_running_utility_function(0) {}
240 
242  : m_stop_id(rhs.m_stop_id), m_memory_id(rhs.m_memory_id) {}
243 
244  const ProcessModID &operator=(const ProcessModID &rhs) {
245  if (this != &rhs) {
246  m_stop_id = rhs.m_stop_id;
247  m_memory_id = rhs.m_memory_id;
248  }
249  return *this;
250  }
251 
252  ~ProcessModID() = default;
253 
254  void BumpStopID() {
255  m_stop_id++;
256  if (!IsLastResumeForUserExpression())
257  m_last_natural_stop_id++;
258  }
259 
260  void BumpMemoryID() { m_memory_id++; }
261 
262  void BumpResumeID() {
263  m_resume_id++;
264  if (m_running_user_expression > 0)
265  m_last_user_expression_resume = m_resume_id;
266  }
267 
269  return m_running_utility_function > 0;
270  }
271 
272  uint32_t GetStopID() const { return m_stop_id; }
273  uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; }
274  uint32_t GetMemoryID() const { return m_memory_id; }
275  uint32_t GetResumeID() const { return m_resume_id; }
277  return m_last_user_expression_resume;
278  }
279 
280  bool MemoryIDEqual(const ProcessModID &compare) const {
281  return m_memory_id == compare.m_memory_id;
282  }
283 
284  bool StopIDEqual(const ProcessModID &compare) const {
285  return m_stop_id == compare.m_stop_id;
286  }
287 
288  void SetInvalid() { m_stop_id = UINT32_MAX; }
289 
290  bool IsValid() const { return m_stop_id != UINT32_MAX; }
291 
293  // If we haven't yet resumed the target, then it can't be for a user
294  // expression...
295  if (m_resume_id == 0)
296  return false;
297 
298  return m_resume_id == m_last_user_expression_resume;
299  }
300 
301  void SetRunningUserExpression(bool on) {
302  if (on)
303  m_running_user_expression++;
304  else
305  m_running_user_expression--;
306  }
307 
309  if (on)
310  m_running_utility_function++;
311  else {
312  assert(m_running_utility_function > 0 &&
313  "Called SetRunningUtilityFunction(false) without calling "
314  "SetRunningUtilityFunction(true) before?");
315  m_running_utility_function--;
316  }
317  }
318 
319  void SetStopEventForLastNaturalStopID(lldb::EventSP event_sp) {
320  m_last_natural_stop_event = event_sp;
321  }
322 
323  lldb::EventSP GetStopEventForStopID(uint32_t stop_id) const {
324  if (stop_id == m_last_natural_stop_id)
325  return m_last_natural_stop_event;
326  return lldb::EventSP();
327  }
328 
329 private:
330  uint32_t m_stop_id;
331  uint32_t m_last_natural_stop_id;
332  uint32_t m_resume_id;
333  uint32_t m_memory_id;
334  uint32_t m_last_user_expression_resume;
335  uint32_t m_running_user_expression;
336  uint32_t m_running_utility_function;
337  lldb::EventSP m_last_natural_stop_event;
338 };
339 
340 inline bool operator==(const ProcessModID &lhs, const ProcessModID &rhs) {
341  if (lhs.StopIDEqual(rhs) && lhs.MemoryIDEqual(rhs))
342  return true;
343  else
344  return false;
345 }
346 
347 inline bool operator!=(const ProcessModID &lhs, const ProcessModID &rhs) {
348  return (!lhs.StopIDEqual(rhs) || !lhs.MemoryIDEqual(rhs));
349 }
350 
351 /// \class Process Process.h "lldb/Target/Process.h"
352 /// A plug-in interface definition class for debugging a process.
353 class Process : public std::enable_shared_from_this<Process>,
354  public ProcessProperties,
355  public UserID,
356  public Broadcaster,
357  public ExecutionContextScope,
358  public PluginInterface {
359  friend class FunctionCaller; // For WaitForStateChangeEventsPrivate
360  friend class Debugger; // For PopProcessIOHandler and ProcessIOHandlerIsActive
361  friend class DynamicLoader; // For LoadOperatingSystemPlugin
362  friend class ProcessEventData;
363  friend class StopInfo;
364  friend class Target;
365  friend class ThreadList;
366 
367 public:
368  /// Broadcaster event bits definitions.
369  enum {
370  eBroadcastBitStateChanged = (1 << 0),
371  eBroadcastBitInterrupt = (1 << 1),
372  eBroadcastBitSTDOUT = (1 << 2),
373  eBroadcastBitSTDERR = (1 << 3),
374  eBroadcastBitProfileData = (1 << 4),
375  eBroadcastBitStructuredData = (1 << 5),
376  };
377 
378  enum {
379  eBroadcastInternalStateControlStop = (1 << 0),
380  eBroadcastInternalStateControlPause = (1 << 1),
381  eBroadcastInternalStateControlResume = (1 << 2)
382  };
383 
384  /// Process warning types.
385  enum Warnings { eWarningsOptimization = 1 };
386 
388  // We use a read/write lock to allow on or more clients to access the process
389  // state while the process is stopped (reader). We lock the write lock to
390  // control access to the process while it is running (readers, or clients
391  // that want the process stopped can block waiting for the process to stop,
392  // or just try to lock it to see if they can immediately access the stopped
393  // process. If the try read lock fails, then the process is running.
395 
396  // These two functions fill out the Broadcaster interface:
397 
398  static ConstString &GetStaticBroadcasterClass();
399 
400  ConstString &GetBroadcasterClass() const override {
401  return GetStaticBroadcasterClass();
402  }
403 
404 /// A notification structure that can be used by clients to listen
405 /// for changes in a process's lifetime.
406 ///
407 /// \see RegisterNotificationCallbacks (const Notifications&) @see
408 /// UnregisterNotificationCallbacks (const Notifications&)
409  typedef struct {
410  void *baton;
411  void (*initialize)(void *baton, Process *process);
412  void (*process_state_changed)(void *baton, Process *process,
413  lldb::StateType state);
414  } Notifications;
415 
416  class ProcessEventData : public EventData {
417  friend class Process;
418 
419  public:
421  ProcessEventData(const lldb::ProcessSP &process, lldb::StateType state);
422 
423  ~ProcessEventData() override;
424 
425  static ConstString GetFlavorString();
426 
427  ConstString GetFlavor() const override;
428 
429  lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
430 
431  lldb::StateType GetState() const { return m_state; }
432  bool GetRestarted() const { return m_restarted; }
433 
434  size_t GetNumRestartedReasons() { return m_restarted_reasons.size(); }
435 
436  const char *GetRestartedReasonAtIndex(size_t idx) {
437  return ((idx < m_restarted_reasons.size())
438  ? m_restarted_reasons[idx].c_str()
439  : nullptr);
440  }
441 
442  bool GetInterrupted() const { return m_interrupted; }
443 
444  void Dump(Stream *s) const override;
445 
446  void DoOnRemoval(Event *event_ptr) override;
447 
448  static const Process::ProcessEventData *
449  GetEventDataFromEvent(const Event *event_ptr);
450 
451  static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr);
452 
453  static lldb::StateType GetStateFromEvent(const Event *event_ptr);
454 
455  static bool GetRestartedFromEvent(const Event *event_ptr);
456 
457  static size_t GetNumRestartedReasons(const Event *event_ptr);
458 
459  static const char *GetRestartedReasonAtIndex(const Event *event_ptr,
460  size_t idx);
461 
462  static void AddRestartedReason(Event *event_ptr, const char *reason);
463 
464  static void SetRestartedInEvent(Event *event_ptr, bool new_value);
465 
466  static bool GetInterruptedFromEvent(const Event *event_ptr);
467 
468  static void SetInterruptedInEvent(Event *event_ptr, bool new_value);
469 
470  static bool SetUpdateStateOnRemoval(Event *event_ptr);
471 
472  private:
473  void SetUpdateStateOnRemoval() { m_update_state++; }
474 
475  void SetRestarted(bool new_value) { m_restarted = new_value; }
476 
477  void SetInterrupted(bool new_value) { m_interrupted = new_value; }
478 
479  void AddRestartedReason(const char *reason) {
480  m_restarted_reasons.push_back(reason);
481  }
482 
483  lldb::ProcessWP m_process_wp;
484  lldb::StateType m_state;
485  std::vector<std::string> m_restarted_reasons;
486  bool m_restarted; // For "eStateStopped" events, this is true if the target
487  // was automatically restarted.
488  int m_update_state;
489  bool m_interrupted;
490 
491  DISALLOW_COPY_AND_ASSIGN(ProcessEventData);
492  };
493 
494  /// Construct with a shared pointer to a target, and the Process listener.
495  /// Uses the Host UnixSignalsSP by default.
496  Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
497 
498  /// Construct with a shared pointer to a target, the Process listener, and
499  /// the appropriate UnixSignalsSP for the process.
500  Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
501  const lldb::UnixSignalsSP &unix_signals_sp);
502 
503  /// Destructor.
504  ///
505  /// The destructor is virtual since this class is designed to be inherited
506  /// from by the plug-in instance.
507  ~Process() override;
508 
509  static void SettingsInitialize();
510 
511  static void SettingsTerminate();
512 
513  static const ProcessPropertiesSP &GetGlobalProperties();
514 
515  /// Find a Process plug-in that can debug \a module using the currently
516  /// selected architecture.
517  ///
518  /// Scans all loaded plug-in interfaces that implement versions of the
519  /// Process plug-in interface and returns the first instance that can debug
520  /// the file.
521  ///
522  /// \param[in] module_sp
523  /// The module shared pointer that this process will debug.
524  ///
525  /// \param[in] plugin_name
526  /// If nullptr, select the best plug-in for the binary. If non-nullptr
527  /// then look for a plugin whose PluginInfo's name matches
528  /// this string.
529  ///
530  /// \see Process::CanDebug ()
531  static lldb::ProcessSP FindPlugin(lldb::TargetSP target_sp,
532  llvm::StringRef plugin_name,
533  lldb::ListenerSP listener_sp,
534  const FileSpec *crash_file_path);
535 
536  /// Static function that can be used with the \b host function
537  /// Host::StartMonitoringChildProcess ().
538  ///
539  /// This function can be used by lldb_private::Process subclasses when they
540  /// want to watch for a local process and have its exit status automatically
541  /// set when the host child process exits. Subclasses should call
542  /// Host::StartMonitoringChildProcess () with:
543  /// callback = Process::SetHostProcessExitStatus
544  /// pid = Process::GetID()
545  /// monitor_signals = false
546  static bool
547  SetProcessExitStatus(lldb::pid_t pid, // The process ID we want to monitor
548  bool exited,
549  int signo, // Zero for no signal
550  int status); // Exit value of process if signal is zero
551 
552  lldb::ByteOrder GetByteOrder() const;
553 
554  uint32_t GetAddressByteSize() const;
555 
556  uint32_t GetUniqueID() const { return m_process_unique_id; }
557 
558  /// Check if a plug-in instance can debug the file in \a module.
559  ///
560  /// Each plug-in is given a chance to say whether it can debug the file in
561  /// \a module. If the Process plug-in instance can debug a file on the
562  /// current system, it should return \b true.
563  ///
564  /// \return
565  /// Returns \b true if this Process plug-in instance can
566  /// debug the executable, \b false otherwise.
567  virtual bool CanDebug(lldb::TargetSP target,
568  bool plugin_specified_by_name) = 0;
569 
570  /// This object is about to be destroyed, do any necessary cleanup.
571  ///
572  /// Subclasses that override this method should always call this superclass
573  /// method.
574  virtual void Finalize();
575 
576  /// Return whether this object is valid (i.e. has not been finalized.)
577  ///
578  /// \return
579  /// Returns \b true if this Process has not been finalized
580  /// and \b false otherwise.
581  bool IsValid() const { return !m_finalize_called; }
582 
583  /// Return a multi-word command object that can be used to expose plug-in
584  /// specific commands.
585  ///
586  /// This object will be used to resolve plug-in commands and can be
587  /// triggered by a call to:
588  ///
589  /// (lldb) process command <args>
590  ///
591  /// \return
592  /// A CommandObject which can be one of the concrete subclasses
593  /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
594  /// or CommandObjectMultiword.
595  virtual CommandObject *GetPluginCommandObject() { return nullptr; }
596 
597  /// Launch a new process.
598  ///
599  /// Launch a new process by spawning a new process using the target object's
600  /// executable module's file as the file to launch.
601  ///
602  /// This function is not meant to be overridden by Process subclasses. It
603  /// will first call Process::WillLaunch (Module *) and if that returns \b
604  /// true, Process::DoLaunch (Module*, char const *[],char const *[],const
605  /// char *,const char *, const char *) will be called to actually do the
606  /// launching. If DoLaunch returns \b true, then Process::DidLaunch() will
607  /// be called.
608  ///
609  /// \param[in] launch_info
610  /// Details regarding the environment, STDIN/STDOUT/STDERR
611  /// redirection, working path, etc. related to the requested launch.
612  ///
613  /// \return
614  /// An error object. Call GetID() to get the process ID if
615  /// the error object is success.
616  virtual Status Launch(ProcessLaunchInfo &launch_info);
617 
618  virtual Status LoadCore();
619 
620  virtual Status DoLoadCore() {
621  Status error;
623  "error: %s does not support loading core files.",
624  GetPluginName().GetCString());
625  return error;
626  }
627 
628  // FUTURE WORK: GetLoadImageUtilityFunction are the first use we've
629  // had of having other plugins cache data in the Process. This is handy for
630  // long-living plugins - like the Platform - which manage interactions whose
631  // lifetime is governed by the Process lifetime. If we find we need to do
632  // this more often, we should construct a general solution to the problem.
633  // The consensus suggestion was that we have a token based registry in the
634  // Process. Some undecided questions are (1) who manages the tokens. It's
635  // probably best that you add the element and get back a token that
636  // represents it. That will avoid collisions. But there may be some utility
637  // in the registerer controlling the token? (2) whether the thing added
638  // should be simply owned by Process, and just go away when it does (3)
639  // whether the registree should be notified of the Process' demise.
640  //
641  // We are postponing designing this till we have at least a second use case.
642  /// Get the cached UtilityFunction that assists in loading binary images
643  /// into the process.
644  ///
645  /// \param[in] platform
646  /// The platform fetching the UtilityFunction.
647  /// \param[in] factory
648  /// A function that will be called only once per-process in a
649  /// thread-safe way to create the UtilityFunction if it has not
650  /// been initialized yet.
651  ///
652  /// \return
653  /// The cached utility function or null if the platform is not the
654  /// same as the target's platform.
655  UtilityFunction *GetLoadImageUtilityFunction(
656  Platform *platform,
657  llvm::function_ref<std::unique_ptr<UtilityFunction>()> factory);
658 
659  /// Get the dynamic loader plug-in for this process.
660  ///
661  /// The default action is to let the DynamicLoader plug-ins check the main
662  /// executable and the DynamicLoader will select itself automatically.
663  /// Subclasses can override this if inspecting the executable is not
664  /// desired, or if Process subclasses can only use a specific DynamicLoader
665  /// plug-in.
666  virtual DynamicLoader *GetDynamicLoader();
667 
668  // Returns AUXV structure found in many ELF-based environments.
669  //
670  // The default action is to return an empty data buffer.
671  //
672  // \return
673  // A data buffer containing the contents of the AUXV data.
674  virtual const lldb::DataBufferSP GetAuxvData();
675 
676  /// Sometimes processes know how to retrieve and load shared libraries. This
677  /// is normally done by DynamicLoader plug-ins, but sometimes the connection
678  /// to the process allows retrieving this information. The dynamic loader
679  /// plug-ins can use this function if they can't determine the current
680  /// shared library load state.
681  ///
682  /// \return
683  /// The number of shared libraries that were loaded
684  virtual size_t LoadModules() { return 0; }
685 
686  virtual size_t LoadModules(LoadedModuleInfoList &) { return 0; }
687 
688 protected:
689  virtual JITLoaderList &GetJITLoaders();
690 
691 public:
692  /// Get the system runtime plug-in for this process.
693  ///
694  /// \return
695  /// Returns a pointer to the SystemRuntime plugin for this Process
696  /// if one is available. Else returns nullptr.
697  virtual SystemRuntime *GetSystemRuntime();
698 
699  /// Attach to an existing process using the process attach info.
700  ///
701  /// This function is not meant to be overridden by Process subclasses. It
702  /// will first call WillAttach (lldb::pid_t) or WillAttach (const char *),
703  /// and if that returns \b true, DoAttach (lldb::pid_t) or DoAttach (const
704  /// char *) will be called to actually do the attach. If DoAttach returns \b
705  /// true, then Process::DidAttach() will be called.
706  ///
707  /// \param[in] pid
708  /// The process ID that we should attempt to attach to.
709  ///
710  /// \return
711  /// Returns \a pid if attaching was successful, or
712  /// LLDB_INVALID_PROCESS_ID if attaching fails.
713  virtual Status Attach(ProcessAttachInfo &attach_info);
714 
715  /// Attach to a remote system via a URL
716  ///
717  /// \param[in] strm
718  /// A stream where output intended for the user
719  /// (if the driver has a way to display that) generated during
720  /// the connection. This may be nullptr if no output is needed.A
721  ///
722  /// \param[in] remote_url
723  /// The URL format that we are connecting to.
724  ///
725  /// \return
726  /// Returns an error object.
727  virtual Status ConnectRemote(Stream *strm, llvm::StringRef remote_url);
728 
729  bool GetShouldDetach() const { return m_should_detach; }
730 
731  void SetShouldDetach(bool b) { m_should_detach = b; }
732 
733  /// Get the image information address for the current process.
734  ///
735  /// Some runtimes have system functions that can help dynamic loaders locate
736  /// the dynamic loader information needed to observe shared libraries being
737  /// loaded or unloaded. This function is in the Process interface (as
738  /// opposed to the DynamicLoader interface) to ensure that remote debugging
739  /// can take advantage of this functionality.
740  ///
741  /// \return
742  /// The address of the dynamic loader information, or
743  /// LLDB_INVALID_ADDRESS if this is not supported by this
744  /// interface.
745  virtual lldb::addr_t GetImageInfoAddress();
746 
747  /// Called when the process is about to broadcast a public stop.
748  ///
749  /// There are public and private stops. Private stops are when the process
750  /// is doing things like stepping and the client doesn't need to know about
751  /// starts and stop that implement a thread plan. Single stepping over a
752  /// source line in code might end up being implemented by one or more
753  /// process starts and stops. Public stops are when clients will be notified
754  /// that the process is stopped. These events typically trigger UI updates
755  /// (thread stack frames to be displayed, variables to be displayed, and
756  /// more). This function can be overriden and allows process subclasses to
757  /// do something before the eBroadcastBitStateChanged event is sent to
758  /// public clients.
759  virtual void WillPublicStop() {}
760 
761 /// Register for process and thread notifications.
762 ///
763 /// Clients can register notification callbacks by filling out a
764 /// Process::Notifications structure and calling this function.
765 ///
766 /// \param[in] callbacks
767 /// A structure that contains the notification baton and
768 /// callback functions.
769 ///
770 /// \see Process::Notifications
771  void RegisterNotificationCallbacks(const Process::Notifications &callbacks);
772 
773 /// Unregister for process and thread notifications.
774 ///
775 /// Clients can unregister notification callbacks by passing a copy of the
776 /// original baton and callbacks in \a callbacks.
777 ///
778 /// \param[in] callbacks
779 /// A structure that contains the notification baton and
780 /// callback functions.
781 ///
782 /// \return
783 /// Returns \b true if the notification callbacks were
784 /// successfully removed from the process, \b false otherwise.
785 ///
786 /// \see Process::Notifications
787  bool UnregisterNotificationCallbacks(const Process::Notifications &callbacks);
788 
789  //==================================================================
790  // Built in Process Control functions
791  //==================================================================
792  /// Resumes all of a process's threads as configured using the Thread run
793  /// control functions.
794  ///
795  /// Threads for a process should be updated with one of the run control
796  /// actions (resume, step, or suspend) that they should take when the
797  /// process is resumed. If no run control action is given to a thread it
798  /// will be resumed by default.
799  ///
800  /// This function is not meant to be overridden by Process subclasses. This
801  /// function will take care of disabling any breakpoints that threads may be
802  /// stopped at, single stepping, and re-enabling breakpoints, and enabling
803  /// the basic flow control that the plug-in instances need not worry about.
804  ///
805  /// N.B. This function also sets the Write side of the Run Lock, which is
806  /// unset when the corresponding stop event is pulled off the Public Event
807  /// Queue. If you need to resume the process without setting the Run Lock,
808  /// use PrivateResume (though you should only do that from inside the
809  /// Process class.
810  ///
811  /// \return
812  /// Returns an error object.
813  ///
814  /// \see Thread:Resume()
815  /// \see Thread:Step()
816  /// \see Thread:Suspend()
817  Status Resume();
818 
819  Status ResumeSynchronous(Stream *stream);
820 
821  /// Halts a running process.
822  ///
823  /// This function is not meant to be overridden by Process subclasses. If
824  /// the process is successfully halted, a eStateStopped process event with
825  /// GetInterrupted will be broadcast. If false, we will halt the process
826  /// with no events generated by the halt.
827  ///
828  /// \param[in] clear_thread_plans
829  /// If true, when the process stops, clear all thread plans.
830  ///
831  /// \param[in] use_run_lock
832  /// Whether to release the run lock after the stop.
833  ///
834  /// \return
835  /// Returns an error object. If the error is empty, the process is
836  /// halted.
837  /// otherwise the halt has failed.
838  Status Halt(bool clear_thread_plans = false, bool use_run_lock = true);
839 
840  /// Detaches from a running or stopped process.
841  ///
842  /// This function is not meant to be overridden by Process subclasses.
843  ///
844  /// \param[in] keep_stopped
845  /// If true, don't resume the process on detach.
846  ///
847  /// \return
848  /// Returns an error object.
849  Status Detach(bool keep_stopped);
850 
851  /// Kills the process and shuts down all threads that were spawned to track
852  /// and monitor the process.
853  ///
854  /// This function is not meant to be overridden by Process subclasses.
855  ///
856  /// \param[in] force_kill
857  /// Whether lldb should force a kill (instead of a detach) from
858  /// the inferior process. Normally if lldb launched a binary and
859  /// Destory is called, lldb kills it. If lldb attached to a
860  /// running process and Destory is called, lldb detaches. If
861  /// this behavior needs to be over-ridden, this is the bool that
862  /// can be used.
863  ///
864  /// \return
865  /// Returns an error object.
866  Status Destroy(bool force_kill);
867 
868  /// Sends a process a UNIX signal \a signal.
869  ///
870  /// This function is not meant to be overridden by Process subclasses.
871  ///
872  /// \return
873  /// Returns an error object.
874  Status Signal(int signal);
875 
876  void SetUnixSignals(lldb::UnixSignalsSP &&signals_sp);
877 
878  const lldb::UnixSignalsSP &GetUnixSignals();
879 
880  //==================================================================
881  // Plug-in Process Control Overrides
882  //==================================================================
883 
884  /// Called before attaching to a process.
885  ///
886  /// Allow Process plug-ins to execute some code before attaching a process.
887  ///
888  /// \return
889  /// Returns an error object.
891 
892  /// Called before attaching to a process.
893  ///
894  /// Allow Process plug-ins to execute some code before attaching a process.
895  ///
896  /// \return
897  /// Returns an error object.
898  virtual Status WillAttachToProcessWithName(const char *process_name,
899  bool wait_for_launch) {
900  return Status();
901  }
902 
903  /// Attach to a remote system via a URL
904  ///
905  /// \param[in] strm
906  /// A stream where output intended for the user
907  /// (if the driver has a way to display that) generated during
908  /// the connection. This may be nullptr if no output is needed.A
909  ///
910  /// \param[in] remote_url
911  /// The URL format that we are connecting to.
912  ///
913  /// \return
914  /// Returns an error object.
915  virtual Status DoConnectRemote(Stream *strm, llvm::StringRef remote_url) {
916  Status error;
917  error.SetErrorString("remote connections are not supported");
918  return error;
919  }
920 
921  /// Attach to an existing process using a process ID.
922  ///
923  /// \param[in] pid
924  /// The process ID that we should attempt to attach to.
925  ///
926  /// \param[in] attach_info
927  /// Information on how to do the attach. For example, GetUserID()
928  /// will return the uid to attach as.
929  ///
930  /// \return
931  /// Returns a successful Status attaching was successful, or
932  /// an appropriate (possibly platform-specific) error code if
933  /// attaching fails.
934  /// hanming : need flag
936  const ProcessAttachInfo &attach_info) {
937  Status error;
939  "error: %s does not support attaching to a process by pid",
940  GetPluginName().GetCString());
941  return error;
942  }
943 
944  /// Attach to an existing process using a partial process name.
945  ///
946  /// \param[in] process_name
947  /// The name of the process to attach to.
948  ///
949  /// \param[in] attach_info
950  /// Information on how to do the attach. For example, GetUserID()
951  /// will return the uid to attach as.
952  ///
953  /// \return
954  /// Returns a successful Status attaching was successful, or
955  /// an appropriate (possibly platform-specific) error code if
956  /// attaching fails.
957  virtual Status
958  DoAttachToProcessWithName(const char *process_name,
959  const ProcessAttachInfo &attach_info) {
960  Status error;
961  error.SetErrorString("attach by name is not supported");
962  return error;
963  }
964 
965  /// Called after attaching a process.
966  ///
967  /// \param[in] process_arch
968  /// If you can figure out the process architecture after attach, fill it
969  /// in here.
970  ///
971  /// Allow Process plug-ins to execute some code after attaching to a
972  /// process.
973  virtual void DidAttach(ArchSpec &process_arch) { process_arch.Clear(); }
974 
975  /// Called after a process re-execs itself.
976  ///
977  /// Allow Process plug-ins to execute some code after a process has exec'ed
978  /// itself. Subclasses typically should override DoDidExec() as the
979  /// lldb_private::Process class needs to remove its dynamic loader, runtime,
980  /// ABI and other plug-ins, as well as unload all shared libraries.
981  virtual void DidExec();
982 
983  /// Subclasses of Process should implement this function if they need to do
984  /// anything after a process exec's itself.
985  virtual void DoDidExec() {}
986 
987  /// Called before launching to a process.
988  ///
989  /// Allow Process plug-ins to execute some code before launching a process.
990  ///
991  /// \return
992  /// Returns an error object.
993  virtual Status WillLaunch(Module *module) { return Status(); }
994 
995  /// Launch a new process.
996  ///
997  /// Launch a new process by spawning a new process using \a exe_module's
998  /// file as the file to launch. Launch details are provided in \a
999  /// launch_info.
1000  ///
1001  /// \param[in] exe_module
1002  /// The module from which to extract the file specification and
1003  /// launch.
1004  ///
1005  /// \param[in] launch_info
1006  /// Details (e.g. arguments, stdio redirection, etc.) for the
1007  /// requested launch.
1008  ///
1009  /// \return
1010  /// An Status instance indicating success or failure of the
1011  /// operation.
1012  virtual Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) {
1013  Status error;
1015  "error: %s does not support launching processes",
1016  GetPluginName().GetCString());
1017  return error;
1018  }
1019 
1020  /// Called after launching a process.
1021  ///
1022  /// Allow Process plug-ins to execute some code after launching a process.
1023  virtual void DidLaunch() {}
1024 
1025  /// Called before resuming to a process.
1026  ///
1027  /// Allow Process plug-ins to execute some code before resuming a process.
1028  ///
1029  /// \return
1030  /// Returns an error object.
1031  virtual Status WillResume() { return Status(); }
1032 
1033  /// Resumes all of a process's threads as configured using the Thread run
1034  /// control functions.
1035  ///
1036  /// Threads for a process should be updated with one of the run control
1037  /// actions (resume, step, or suspend) that they should take when the
1038  /// process is resumed. If no run control action is given to a thread it
1039  /// will be resumed by default.
1040  ///
1041  /// \return
1042  /// Returns \b true if the process successfully resumes using
1043  /// the thread run control actions, \b false otherwise.
1044  ///
1045  /// \see Thread:Resume()
1046  /// \see Thread:Step()
1047  /// \see Thread:Suspend()
1048  virtual Status DoResume() {
1049  Status error;
1051  "error: %s does not support resuming processes",
1052  GetPluginName().GetCString());
1053  return error;
1054  }
1055 
1056  /// Called after resuming a process.
1057  ///
1058  /// Allow Process plug-ins to execute some code after resuming a process.
1059  virtual void DidResume() {}
1060 
1061  /// Called before halting to a process.
1062  ///
1063  /// Allow Process plug-ins to execute some code before halting a process.
1064  ///
1065  /// \return
1066  /// Returns an error object.
1067  virtual Status WillHalt() { return Status(); }
1068 
1069  /// Halts a running process.
1070  ///
1071  /// DoHalt must produce one and only one stop StateChanged event if it
1072  /// actually stops the process. If the stop happens through some natural
1073  /// event (for instance a SIGSTOP), then forwarding that event will do.
1074  /// Otherwise, you must generate the event manually. This function is called
1075  /// from the context of the private state thread.
1076  ///
1077  /// \param[out] caused_stop
1078  /// If true, then this Halt caused the stop, otherwise, the
1079  /// process was already stopped.
1080  ///
1081  /// \return
1082  /// Returns \b true if the process successfully halts, \b false
1083  /// otherwise.
1084  virtual Status DoHalt(bool &caused_stop) {
1085  Status error;
1087  "error: %s does not support halting processes",
1088  GetPluginName().GetCString());
1089  return error;
1090  }
1091 
1092  /// Called after halting a process.
1093  ///
1094  /// Allow Process plug-ins to execute some code after halting a process.
1095  virtual void DidHalt() {}
1096 
1097  /// Called before detaching from a process.
1098  ///
1099  /// Allow Process plug-ins to execute some code before detaching from a
1100  /// process.
1101  ///
1102  /// \return
1103  /// Returns an error object.
1104  virtual Status WillDetach() { return Status(); }
1105 
1106  /// Detaches from a running or stopped process.
1107  ///
1108  /// \return
1109  /// Returns \b true if the process successfully detaches, \b
1110  /// false otherwise.
1111  virtual Status DoDetach(bool keep_stopped) {
1112  Status error;
1114  "error: %s does not support detaching from processes",
1115  GetPluginName().GetCString());
1116  return error;
1117  }
1118 
1119  /// Called after detaching from a process.
1120  ///
1121  /// Allow Process plug-ins to execute some code after detaching from a
1122  /// process.
1123  virtual void DidDetach() {}
1124 
1125  virtual bool DetachRequiresHalt() { return false; }
1126 
1127  /// Called before sending a signal to a process.
1128  ///
1129  /// Allow Process plug-ins to execute some code before sending a signal to a
1130  /// process.
1131  ///
1132  /// \return
1133  /// Returns no error if it is safe to proceed with a call to
1134  /// Process::DoSignal(int), otherwise an error describing what
1135  /// prevents the signal from being sent.
1136  virtual Status WillSignal() { return Status(); }
1137 
1138  /// Sends a process a UNIX signal \a signal.
1139  ///
1140  /// \return
1141  /// Returns an error object.
1142  virtual Status DoSignal(int signal) {
1143  Status error;
1145  "error: %s does not support sending signals to processes",
1146  GetPluginName().GetCString());
1147  return error;
1148  }
1149 
1150  virtual Status WillDestroy() { return Status(); }
1151 
1152  virtual Status DoDestroy() = 0;
1153 
1154  virtual void DidDestroy() {}
1155 
1156  virtual bool DestroyRequiresHalt() { return true; }
1157 
1158  /// Called after sending a signal to a process.
1159  ///
1160  /// Allow Process plug-ins to execute some code after sending a signal to a
1161  /// process.
1162  virtual void DidSignal() {}
1163 
1164  /// Currently called as part of ShouldStop.
1165  /// FIXME: Should really happen when the target stops before the
1166  /// event is taken from the queue...
1167  ///
1168  /// This callback is called as the event
1169  /// is about to be queued up to allow Process plug-ins to execute some code
1170  /// prior to clients being notified that a process was stopped. Common
1171  /// operations include updating the thread list, invalidating any thread
1172  /// state (registers, stack, etc) prior to letting the notification go out.
1173  ///
1174  virtual void RefreshStateAfterStop() = 0;
1175 
1176  /// Sometimes the connection to a process can detect the host OS version
1177  /// that the process is running on. The current platform should be checked
1178  /// first in case the platform is connected, but clients can fall back onto
1179  /// this function if the platform fails to identify the host OS version. The
1180  /// platform should be checked first in case you are running a simulator
1181  /// platform that might itself be running natively, but have different
1182  /// heuristics for figuring out which OS is is emulating.
1183  ///
1184  /// \return
1185  /// Returns the version tuple of the host OS. In case of failure an empty
1186  /// VersionTuple is returner.
1187  virtual llvm::VersionTuple GetHostOSVersion() { return llvm::VersionTuple(); }
1188 
1189  /// Get the target object pointer for this module.
1190  ///
1191  /// \return
1192  /// A Target object pointer to the target that owns this
1193  /// module.
1194  Target &GetTarget() { return *m_target_wp.lock(); }
1195 
1196  /// Get the const target object pointer for this module.
1197  ///
1198  /// \return
1199  /// A const Target object pointer to the target that owns this
1200  /// module.
1201  const Target &GetTarget() const { return *m_target_wp.lock(); }
1202 
1203  /// Flush all data in the process.
1204  ///
1205  /// Flush the memory caches, all threads, and any other cached data in the
1206  /// process.
1207  ///
1208  /// This function can be called after a world changing event like adding a
1209  /// new symbol file, or after the process makes a large context switch (from
1210  /// boot ROM to booted into an OS).
1211  void Flush();
1212 
1213  /// Get accessor for the current process state.
1214  ///
1215  /// \return
1216  /// The current state of the process.
1217  ///
1218  /// \see lldb::StateType
1219  lldb::StateType GetState();
1220 
1222  RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp,
1223  const EvaluateExpressionOptions &options,
1224  DiagnosticManager &diagnostic_manager);
1225 
1226  static const char *ExecutionResultAsCString(lldb::ExpressionResults result);
1227 
1228  void GetStatus(Stream &ostrm);
1229 
1230  size_t GetThreadStatus(Stream &ostrm, bool only_threads_with_stop_reason,
1231  uint32_t start_frame, uint32_t num_frames,
1232  uint32_t num_frames_with_source,
1233  bool stop_format);
1234 
1235  void SendAsyncInterrupt();
1236 
1237  // Notify this process class that modules got loaded.
1238  //
1239  // If subclasses override this method, they must call this version before
1240  // doing anything in the subclass version of the function.
1241  virtual void ModulesDidLoad(ModuleList &module_list);
1242 
1243  /// Retrieve the list of shared libraries that are loaded for this process
1244  /// This method is used on pre-macOS 10.12, pre-iOS 10, pre-tvOS 10, pre-
1245  /// watchOS 3 systems. The following two methods are for newer versions of
1246  /// those OSes.
1247  ///
1248  /// For certain platforms, the time it takes for the DynamicLoader plugin to
1249  /// read all of the shared libraries out of memory over a slow communication
1250  /// channel may be too long. In that instance, the gdb-remote stub may be
1251  /// able to retrieve the necessary information about the solibs out of
1252  /// memory and return a concise summary sufficient for the DynamicLoader
1253  /// plugin.
1254  ///
1255  /// \param [in] image_list_address
1256  /// The address where the table of shared libraries is stored in memory,
1257  /// if that is appropriate for this platform. Else this may be
1258  /// passed as LLDB_INVALID_ADDRESS.
1259  ///
1260  /// \param [in] image_count
1261  /// The number of shared libraries that are present in this process, if
1262  /// that is appropriate for this platofrm Else this may be passed as
1263  /// LLDB_INVALID_ADDRESS.
1264  ///
1265  /// \return
1266  /// A StructureDataSP object which, if non-empty, will contain the
1267  /// information the DynamicLoader needs to get the initial scan of
1268  /// solibs resolved.
1271  lldb::addr_t image_count) {
1272  return StructuredData::ObjectSP();
1273  }
1274 
1275  // On macOS 10.12, tvOS 10, iOS 10, watchOS 3 and newer, debugserver can
1276  // return the full list of loaded shared libraries without needing any input.
1279  return StructuredData::ObjectSP();
1280  }
1281 
1282  // On macOS 10.12, tvOS 10, iOS 10, watchOS 3 and newer, debugserver can
1283  // return information about binaries given their load addresses.
1285  const std::vector<lldb::addr_t> &load_addresses) {
1286  return StructuredData::ObjectSP();
1287  }
1288 
1289  // Get information about the library shared cache, if that exists
1290  //
1291  // On macOS 10.12, tvOS 10, iOS 10, watchOS 3 and newer, debugserver can
1292  // return information about the library shared cache (a set of standard
1293  // libraries that are loaded at the same location for all processes on a
1294  // system) in use.
1296  return StructuredData::ObjectSP();
1297  }
1298 
1299  /// Print a user-visible warning about a module being built with
1300  /// optimization
1301  ///
1302  /// Prints a async warning message to the user one time per Module where a
1303  /// function is found that was compiled with optimization, per Process.
1304  ///
1305  /// \param [in] sc
1306  /// A SymbolContext with eSymbolContextFunction and eSymbolContextModule
1307  /// pre-computed.
1308  void PrintWarningOptimization(const SymbolContext &sc);
1309 
1310  virtual bool GetProcessInfo(ProcessInstanceInfo &info);
1311 
1312 public:
1313  /// Get the exit status for a process.
1314  ///
1315  /// \return
1316  /// The process's return code, or -1 if the current process
1317  /// state is not eStateExited.
1318  int GetExitStatus();
1319 
1320  /// Get a textual description of what the process exited.
1321  ///
1322  /// \return
1323  /// The textual description of why the process exited, or nullptr
1324  /// if there is no description available.
1325  const char *GetExitDescription();
1326 
1327  virtual void DidExit() {}
1328 
1329  /// Get the Modification ID of the process.
1330  ///
1331  /// \return
1332  /// The modification ID of the process.
1333  ProcessModID GetModID() const { return m_mod_id; }
1334 
1335  const ProcessModID &GetModIDRef() const { return m_mod_id; }
1336 
1337  uint32_t GetStopID() const { return m_mod_id.GetStopID(); }
1338 
1339  uint32_t GetResumeID() const { return m_mod_id.GetResumeID(); }
1340 
1342  return m_mod_id.GetLastUserExpressionResumeID();
1343  }
1344 
1346  return m_mod_id.GetLastNaturalStopID();
1347  }
1348 
1349  lldb::EventSP GetStopEventForStopID(uint32_t stop_id) const {
1350  return m_mod_id.GetStopEventForStopID(stop_id);
1351  }
1352 
1353  /// Set accessor for the process exit status (return code).
1354  ///
1355  /// Sometimes a child exits and the exit can be detected by global functions
1356  /// (signal handler for SIGCHLD for example). This accessor allows the exit
1357  /// status to be set from an external source.
1358  ///
1359  /// Setting this will cause a eStateExited event to be posted to the process
1360  /// event queue.
1361  ///
1362  /// \param[in] exit_status
1363  /// The value for the process's return code.
1364  ///
1365  /// \see lldb::StateType
1366  virtual bool SetExitStatus(int exit_status, const char *cstr);
1367 
1368  /// Check if a process is still alive.
1369  ///
1370  /// \return
1371  /// Returns \b true if the process is still valid, \b false
1372  /// otherwise.
1373  virtual bool IsAlive();
1374 
1375  /// Before lldb detaches from a process, it warns the user that they are
1376  /// about to lose their debug session. In some cases, this warning doesn't
1377  /// need to be emitted -- for instance, with core file debugging where the
1378  /// user can reconstruct the "state" by simply re-running the debugger on
1379  /// the core file.
1380  ///
1381  /// \return
1382  // true if the user should be warned about detaching from this process.
1383  virtual bool WarnBeforeDetach() const { return true; }
1384 
1385  /// Actually do the reading of memory from a process.
1386  ///
1387  /// Subclasses must override this function and can return fewer bytes than
1388  /// requested when memory requests are too large. This class will break up
1389  /// the memory requests and keep advancing the arguments along as needed.
1390  ///
1391  /// \param[in] vm_addr
1392  /// A virtual load address that indicates where to start reading
1393  /// memory from.
1394  ///
1395  /// \param[in] size
1396  /// The number of bytes to read.
1397  ///
1398  /// \param[out] buf
1399  /// A byte buffer that is at least \a size bytes long that
1400  /// will receive the memory bytes.
1401  ///
1402  /// \param[out] error
1403  /// An error that indicates the success or failure of this
1404  /// operation. If error indicates success (error.Success()),
1405  /// then the value returned can be trusted, otherwise zero
1406  /// will be returned.
1407  ///
1408  /// \return
1409  /// The number of bytes that were actually read into \a buf.
1410  /// Zero is returned in the case of an error.
1411  virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
1412  Status &error) = 0;
1413 
1414  /// Read of memory from a process.
1415  ///
1416  /// This function will read memory from the current process's address space
1417  /// and remove any traps that may have been inserted into the memory.
1418  ///
1419  /// This function is not meant to be overridden by Process subclasses, the
1420  /// subclasses should implement Process::DoReadMemory (lldb::addr_t, size_t,
1421  /// void *).
1422  ///
1423  /// \param[in] vm_addr
1424  /// A virtual load address that indicates where to start reading
1425  /// memory from.
1426  ///
1427  /// \param[out] buf
1428  /// A byte buffer that is at least \a size bytes long that
1429  /// will receive the memory bytes.
1430  ///
1431  /// \param[in] size
1432  /// The number of bytes to read.
1433  ///
1434  /// \param[out] error
1435  /// An error that indicates the success or failure of this
1436  /// operation. If error indicates success (error.Success()),
1437  /// then the value returned can be trusted, otherwise zero
1438  /// will be returned.
1439  ///
1440  /// \return
1441  /// The number of bytes that were actually read into \a buf. If
1442  /// the returned number is greater than zero, yet less than \a
1443  /// size, then this function will get called again with \a
1444  /// vm_addr, \a buf, and \a size updated appropriately. Zero is
1445  /// returned in the case of an error.
1446  virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
1447  Status &error);
1448 
1449  /// Read of memory from a process.
1450  ///
1451  /// This function has the same semantics of ReadMemory except that it
1452  /// bypasses caching.
1453  ///
1454  /// \param[in] vm_addr
1455  /// A virtual load address that indicates where to start reading
1456  /// memory from.
1457  ///
1458  /// \param[out] buf
1459  /// A byte buffer that is at least \a size bytes long that
1460  /// will receive the memory bytes.
1461  ///
1462  /// \param[in] size
1463  /// The number of bytes to read.
1464  ///
1465  /// \param[out] error
1466  /// An error that indicates the success or failure of this
1467  /// operation. If error indicates success (error.Success()),
1468  /// then the value returned can be trusted, otherwise zero
1469  /// will be returned.
1470  ///
1471  /// \return
1472  /// The number of bytes that were actually read into \a buf. If
1473  /// the returned number is greater than zero, yet less than \a
1474  /// size, then this function will get called again with \a
1475  /// vm_addr, \a buf, and \a size updated appropriately. Zero is
1476  /// returned in the case of an error.
1477  size_t ReadMemoryFromInferior(lldb::addr_t vm_addr, void *buf, size_t size,
1478  Status &error);
1479 
1480  /// Read a NULL terminated string from memory
1481  ///
1482  /// This function will read a cache page at a time until a NULL string
1483  /// terminator is found. It will stop reading if an aligned sequence of NULL
1484  /// termination \a type_width bytes is not found before reading \a
1485  /// cstr_max_len bytes. The results are always guaranteed to be NULL
1486  /// terminated, and that no more than (max_bytes - type_width) bytes will be
1487  /// read.
1488  ///
1489  /// \param[in] vm_addr
1490  /// The virtual load address to start the memory read.
1491  ///
1492  /// \param[in] str
1493  /// A character buffer containing at least max_bytes.
1494  ///
1495  /// \param[in] max_bytes
1496  /// The maximum number of bytes to read.
1497  ///
1498  /// \param[in] error
1499  /// The error status of the read operation.
1500  ///
1501  /// \param[in] type_width
1502  /// The size of the null terminator (1 to 4 bytes per
1503  /// character). Defaults to 1.
1504  ///
1505  /// \return
1506  /// The error status or the number of bytes prior to the null terminator.
1507  size_t ReadStringFromMemory(lldb::addr_t vm_addr, char *str, size_t max_bytes,
1508  Status &error, size_t type_width = 1);
1509 
1510  /// Read a NULL terminated C string from memory
1511  ///
1512  /// This function will read a cache page at a time until the NULL
1513  /// C string terminator is found. It will stop reading if the NULL
1514  /// termination byte isn't found before reading \a cstr_max_len bytes, and
1515  /// the results are always guaranteed to be NULL terminated (at most
1516  /// cstr_max_len - 1 bytes will be read).
1517  size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr,
1518  size_t cstr_max_len, Status &error);
1519 
1520  size_t ReadCStringFromMemory(lldb::addr_t vm_addr, std::string &out_str,
1521  Status &error);
1522 
1523  /// Reads an unsigned integer of the specified byte size from process
1524  /// memory.
1525  ///
1526  /// \param[in] load_addr
1527  /// A load address of the integer to read.
1528  ///
1529  /// \param[in] byte_size
1530  /// The size in byte of the integer to read.
1531  ///
1532  /// \param[in] fail_value
1533  /// The value to return if we fail to read an integer.
1534  ///
1535  /// \param[out] error
1536  /// An error that indicates the success or failure of this
1537  /// operation. If error indicates success (error.Success()),
1538  /// then the value returned can be trusted, otherwise zero
1539  /// will be returned.
1540  ///
1541  /// \return
1542  /// The unsigned integer that was read from the process memory
1543  /// space. If the integer was smaller than a uint64_t, any
1544  /// unused upper bytes will be zero filled. If the process
1545  /// byte order differs from the host byte order, the integer
1546  /// value will be appropriately byte swapped into host byte
1547  /// order.
1548  uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr,
1549  size_t byte_size, uint64_t fail_value,
1550  Status &error);
1551 
1552  int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size,
1553  int64_t fail_value, Status &error);
1554 
1555  lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error);
1556 
1557  bool WritePointerToMemory(lldb::addr_t vm_addr, lldb::addr_t ptr_value,
1558  Status &error);
1559 
1560  /// Actually do the writing of memory to a process.
1561  ///
1562  /// \param[in] vm_addr
1563  /// A virtual load address that indicates where to start writing
1564  /// memory to.
1565  ///
1566  /// \param[in] buf
1567  /// A byte buffer that is at least \a size bytes long that
1568  /// contains the data to write.
1569  ///
1570  /// \param[in] size
1571  /// The number of bytes to write.
1572  ///
1573  /// \param[out] error
1574  /// An error value in case the memory write fails.
1575  ///
1576  /// \return
1577  /// The number of bytes that were actually written.
1578  virtual size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
1579  size_t size, Status &error) {
1581  "error: %s does not support writing to processes",
1582  GetPluginName().GetCString());
1583  return 0;
1584  }
1585 
1586  /// Write all or part of a scalar value to memory.
1587  ///
1588  /// The value contained in \a scalar will be swapped to match the byte order
1589  /// of the process that is being debugged. If \a size is less than the size
1590  /// of scalar, the least significant \a size bytes from scalar will be
1591  /// written. If \a size is larger than the byte size of scalar, then the
1592  /// extra space will be padded with zeros and the scalar value will be
1593  /// placed in the least significant bytes in memory.
1594  ///
1595  /// \param[in] vm_addr
1596  /// A virtual load address that indicates where to start writing
1597  /// memory to.
1598  ///
1599  /// \param[in] scalar
1600  /// The scalar to write to the debugged process.
1601  ///
1602  /// \param[in] size
1603  /// This value can be smaller or larger than the scalar value
1604  /// itself. If \a size is smaller than the size of \a scalar,
1605  /// the least significant bytes in \a scalar will be used. If
1606  /// \a size is larger than the byte size of \a scalar, then
1607  /// the extra space will be padded with zeros. If \a size is
1608  /// set to UINT32_MAX, then the size of \a scalar will be used.
1609  ///
1610  /// \param[out] error
1611  /// An error value in case the memory write fails.
1612  ///
1613  /// \return
1614  /// The number of bytes that were actually written.
1615  size_t WriteScalarToMemory(lldb::addr_t vm_addr, const Scalar &scalar,
1616  size_t size, Status &error);
1617 
1618  size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size,
1619  bool is_signed, Scalar &scalar,
1620  Status &error);
1621 
1622  /// Write memory to a process.
1623  ///
1624  /// This function will write memory to the current process's address space
1625  /// and maintain any traps that might be present due to software
1626  /// breakpoints.
1627  ///
1628  /// This function is not meant to be overridden by Process subclasses, the
1629  /// subclasses should implement Process::DoWriteMemory (lldb::addr_t,
1630  /// size_t, void *).
1631  ///
1632  /// \param[in] vm_addr
1633  /// A virtual load address that indicates where to start writing
1634  /// memory to.
1635  ///
1636  /// \param[in] buf
1637  /// A byte buffer that is at least \a size bytes long that
1638  /// contains the data to write.
1639  ///
1640  /// \param[in] size
1641  /// The number of bytes to write.
1642  ///
1643  /// \return
1644  /// The number of bytes that were actually written.
1645  // TODO: change this to take an ArrayRef<uint8_t>
1646  size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
1647  Status &error);
1648 
1649  /// Actually allocate memory in the process.
1650  ///
1651  /// This function will allocate memory in the process's address space. This
1652  /// can't rely on the generic function calling mechanism, since that
1653  /// requires this function.
1654  ///
1655  /// \param[in] size
1656  /// The size of the allocation requested.
1657  ///
1658  /// \return
1659  /// The address of the allocated buffer in the process, or
1660  /// LLDB_INVALID_ADDRESS if the allocation failed.
1661 
1662  virtual lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
1663  Status &error) {
1665  "error: %s does not support allocating in the debug process",
1666  GetPluginName().GetCString());
1667  return LLDB_INVALID_ADDRESS;
1668  }
1669 
1670  virtual Status WriteObjectFile(std::vector<ObjectFile::LoadableData> entries);
1671 
1672  /// The public interface to allocating memory in the process.
1673  ///
1674  /// This function will allocate memory in the process's address space. This
1675  /// can't rely on the generic function calling mechanism, since that
1676  /// requires this function.
1677  ///
1678  /// \param[in] size
1679  /// The size of the allocation requested.
1680  ///
1681  /// \param[in] permissions
1682  /// Or together any of the lldb::Permissions bits. The permissions on
1683  /// a given memory allocation can't be changed after allocation. Note
1684  /// that a block that isn't set writable can still be written on from
1685  /// lldb,
1686  /// just not by the process itself.
1687  ///
1688  /// \param[in,out] error
1689  /// An error object to fill in if things go wrong.
1690  /// \return
1691  /// The address of the allocated buffer in the process, or
1692  /// LLDB_INVALID_ADDRESS if the allocation failed.
1693  lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, Status &error);
1694 
1695  /// The public interface to allocating memory in the process, this also
1696  /// clears the allocated memory.
1697  ///
1698  /// This function will allocate memory in the process's address space. This
1699  /// can't rely on the generic function calling mechanism, since that
1700  /// requires this function.
1701  ///
1702  /// \param[in] size
1703  /// The size of the allocation requested.
1704  ///
1705  /// \param[in] permissions
1706  /// Or together any of the lldb::Permissions bits. The permissions on
1707  /// a given memory allocation can't be changed after allocation. Note
1708  /// that a block that isn't set writable can still be written on from
1709  /// lldb,
1710  /// just not by the process itself.
1711  ///
1712  /// \param[in/out] error
1713  /// An error object to fill in if things go wrong.
1714  /// \return
1715  /// The address of the allocated buffer in the process, or
1716  /// LLDB_INVALID_ADDRESS if the allocation failed.
1717 
1718  lldb::addr_t CallocateMemory(size_t size, uint32_t permissions,
1719  Status &error);
1720 
1721  /// Resolve dynamically loaded indirect functions.
1722  ///
1723  /// \param[in] address
1724  /// The load address of the indirect function to resolve.
1725  ///
1726  /// \param[out] error
1727  /// An error value in case the resolve fails.
1728  ///
1729  /// \return
1730  /// The address of the resolved function.
1731  /// LLDB_INVALID_ADDRESS if the resolution failed.
1732  virtual lldb::addr_t ResolveIndirectFunction(const Address *address,
1733  Status &error);
1734 
1735  /// Locate the memory region that contains load_addr.
1736  ///
1737  /// If load_addr is within the address space the process has mapped
1738  /// range_info will be filled in with the start and end of that range as
1739  /// well as the permissions for that range and range_info.GetMapped will
1740  /// return true.
1741  ///
1742  /// If load_addr is outside any mapped region then range_info will have its
1743  /// start address set to load_addr and the end of the range will indicate
1744  /// the start of the next mapped range or be set to LLDB_INVALID_ADDRESS if
1745  /// there are no valid mapped ranges between load_addr and the end of the
1746  /// process address space.
1747  ///
1748  /// GetMemoryRegionInfo will only return an error if it is unimplemented for
1749  /// the current process.
1750  ///
1751  /// \param[in] load_addr
1752  /// The load address to query the range_info for.
1753  ///
1754  /// \param[out] range_info
1755  /// An range_info value containing the details of the range.
1756  ///
1757  /// \return
1758  /// An error value.
1760  MemoryRegionInfo &range_info) {
1761  Status error;
1762  error.SetErrorString("Process::GetMemoryRegionInfo() not supported");
1763  return error;
1764  }
1765 
1766  /// Obtain all the mapped memory regions within this process.
1767  ///
1768  /// \param[out] region_list
1769  /// A vector to contain MemoryRegionInfo objects for all mapped
1770  /// ranges.
1771  ///
1772  /// \return
1773  /// An error value.
1774  virtual Status
1775  GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list);
1776 
1778  Status error;
1779  num = 0;
1780  error.SetErrorString("Process::GetWatchpointSupportInfo() not supported");
1781  return error;
1782  }
1783 
1784  virtual Status GetWatchpointSupportInfo(uint32_t &num, bool &after) {
1785  Status error;
1786  num = 0;
1787  after = true;
1788  error.SetErrorString("Process::GetWatchpointSupportInfo() not supported");
1789  return error;
1790  }
1791 
1792  lldb::ModuleSP ReadModuleFromMemory(const FileSpec &file_spec,
1793  lldb::addr_t header_addr,
1794  size_t size_to_read = 512);
1795 
1796  /// Attempt to get the attributes for a region of memory in the process.
1797  ///
1798  /// It may be possible for the remote debug server to inspect attributes for
1799  /// a region of memory in the process, such as whether there is a valid page
1800  /// of memory at a given address or whether that page is
1801  /// readable/writable/executable by the process.
1802  ///
1803  /// \param[in] load_addr
1804  /// The address of interest in the process.
1805  ///
1806  /// \param[out] permissions
1807  /// If this call returns successfully, this bitmask will have
1808  /// its Permissions bits set to indicate whether the region is
1809  /// readable/writable/executable. If this call fails, the
1810  /// bitmask values are undefined.
1811  ///
1812  /// \return
1813  /// Returns true if it was able to determine the attributes of the
1814  /// memory region. False if not.
1815  virtual bool GetLoadAddressPermissions(lldb::addr_t load_addr,
1816  uint32_t &permissions);
1817 
1818  /// Determines whether executing JIT-compiled code in this process is
1819  /// possible.
1820  ///
1821  /// \return
1822  /// True if execution of JIT code is possible; false otherwise.
1823  bool CanJIT();
1824 
1825  /// Sets whether executing JIT-compiled code in this process is possible.
1826  ///
1827  /// \param[in] can_jit
1828  /// True if execution of JIT code is possible; false otherwise.
1829  void SetCanJIT(bool can_jit);
1830 
1831  /// Determines whether executing function calls using the interpreter is
1832  /// possible for this process.
1833  ///
1834  /// \return
1835  /// True if possible; false otherwise.
1836  bool CanInterpretFunctionCalls() { return m_can_interpret_function_calls; }
1837 
1838  /// Sets whether executing function calls using the interpreter is possible
1839  /// for this process.
1840  ///
1841  /// \param[in] can_interpret_function_calls
1842  /// True if possible; false otherwise.
1843  void SetCanInterpretFunctionCalls(bool can_interpret_function_calls) {
1844  m_can_interpret_function_calls = can_interpret_function_calls;
1845  }
1846 
1847  /// Sets whether executing code in this process is possible. This could be
1848  /// either through JIT or interpreting.
1849  ///
1850  /// \param[in] can_run_code
1851  /// True if execution of code is possible; false otherwise.
1852  void SetCanRunCode(bool can_run_code);
1853 
1854  /// Actually deallocate memory in the process.
1855  ///
1856  /// This function will deallocate memory in the process's address space that
1857  /// was allocated with AllocateMemory.
1858  ///
1859  /// \param[in] ptr
1860  /// A return value from AllocateMemory, pointing to the memory you
1861  /// want to deallocate.
1862  ///
1863  /// \return
1864  /// \btrue if the memory was deallocated, \bfalse otherwise.
1866  Status error;
1868  "error: %s does not support deallocating in the debug process",
1869  GetPluginName().GetCString());
1870  return error;
1871  }
1872 
1873  /// The public interface to deallocating memory in the process.
1874  ///
1875  /// This function will deallocate memory in the process's address space that
1876  /// was allocated with AllocateMemory.
1877  ///
1878  /// \param[in] ptr
1879  /// A return value from AllocateMemory, pointing to the memory you
1880  /// want to deallocate.
1881  ///
1882  /// \return
1883  /// \btrue if the memory was deallocated, \bfalse otherwise.
1884  Status DeallocateMemory(lldb::addr_t ptr);
1885 
1886  /// Get any available STDOUT.
1887  ///
1888  /// Calling this method is a valid operation only if all of the following
1889  /// conditions are true: 1) The process was launched, and not attached to.
1890  /// 2) The process was not launched with eLaunchFlagDisableSTDIO. 3) The
1891  /// process was launched without supplying a valid file path
1892  /// for STDOUT.
1893  ///
1894  /// Note that the implementation will probably need to start a read thread
1895  /// in the background to make sure that the pipe is drained and the STDOUT
1896  /// buffered appropriately, to prevent the process from deadlocking trying
1897  /// to write to a full buffer.
1898  ///
1899  /// Events will be queued indicating that there is STDOUT available that can
1900  /// be retrieved using this function.
1901  ///
1902  /// \param[out] buf
1903  /// A buffer that will receive any STDOUT bytes that are
1904  /// currently available.
1905  ///
1906  /// \param[in] buf_size
1907  /// The size in bytes for the buffer \a buf.
1908  ///
1909  /// \return
1910  /// The number of bytes written into \a buf. If this value is
1911  /// equal to \a buf_size, another call to this function should
1912  /// be made to retrieve more STDOUT data.
1913  virtual size_t GetSTDOUT(char *buf, size_t buf_size, Status &error);
1914 
1915  /// Get any available STDERR.
1916  ///
1917  /// Calling this method is a valid operation only if all of the following
1918  /// conditions are true: 1) The process was launched, and not attached to.
1919  /// 2) The process was not launched with eLaunchFlagDisableSTDIO. 3) The
1920  /// process was launched without supplying a valid file path
1921  /// for STDERR.
1922  ///
1923  /// Note that the implementation will probably need to start a read thread
1924  /// in the background to make sure that the pipe is drained and the STDERR
1925  /// buffered appropriately, to prevent the process from deadlocking trying
1926  /// to write to a full buffer.
1927  ///
1928  /// Events will be queued indicating that there is STDERR available that can
1929  /// be retrieved using this function.
1930  ///
1931  /// \param[in] buf
1932  /// A buffer that will receive any STDERR bytes that are
1933  /// currently available.
1934  ///
1935  /// \param[out] buf_size
1936  /// The size in bytes for the buffer \a buf.
1937  ///
1938  /// \return
1939  /// The number of bytes written into \a buf. If this value is
1940  /// equal to \a buf_size, another call to this function should
1941  /// be made to retrieve more STDERR data.
1942  virtual size_t GetSTDERR(char *buf, size_t buf_size, Status &error);
1943 
1944  /// Puts data into this process's STDIN.
1945  ///
1946  /// Calling this method is a valid operation only if all of the following
1947  /// conditions are true: 1) The process was launched, and not attached to.
1948  /// 2) The process was not launched with eLaunchFlagDisableSTDIO. 3) The
1949  /// process was launched without supplying a valid file path
1950  /// for STDIN.
1951  ///
1952  /// \param[in] buf
1953  /// A buffer that contains the data to write to the process's STDIN.
1954  ///
1955  /// \param[in] buf_size
1956  /// The size in bytes for the buffer \a buf.
1957  ///
1958  /// \return
1959  /// The number of bytes written into \a buf. If this value is
1960  /// less than \a buf_size, another call to this function should
1961  /// be made to write the rest of the data.
1962  virtual size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) {
1963  error.SetErrorString("stdin unsupported");
1964  return 0;
1965  }
1966 
1967  /// Get any available profile data.
1968  ///
1969  /// \param[out] buf
1970  /// A buffer that will receive any profile data bytes that are
1971  /// currently available.
1972  ///
1973  /// \param[out] buf_size
1974  /// The size in bytes for the buffer \a buf.
1975  ///
1976  /// \return
1977  /// The number of bytes written into \a buf. If this value is
1978  /// equal to \a buf_size, another call to this function should
1979  /// be made to retrieve more profile data.
1980  virtual size_t GetAsyncProfileData(char *buf, size_t buf_size, Status &error);
1981 
1982  // Process Breakpoints
1983  size_t GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site);
1984 
1986  Status error;
1988  "error: %s does not support enabling breakpoints",
1989  GetPluginName().GetCString());
1990  return error;
1991  }
1992 
1994  Status error;
1996  "error: %s does not support disabling breakpoints",
1997  GetPluginName().GetCString());
1998  return error;
1999  }
2000 
2001  // This is implemented completely using the lldb::Process API. Subclasses
2002  // don't need to implement this function unless the standard flow of read
2003  // existing opcode, write breakpoint opcode, verify breakpoint opcode doesn't
2004  // work for a specific process plug-in.
2005  virtual Status EnableSoftwareBreakpoint(BreakpointSite *bp_site);
2006 
2007  // This is implemented completely using the lldb::Process API. Subclasses
2008  // don't need to implement this function unless the standard flow of
2009  // restoring original opcode in memory and verifying the restored opcode
2010  // doesn't work for a specific process plug-in.
2011  virtual Status DisableSoftwareBreakpoint(BreakpointSite *bp_site);
2012 
2013  BreakpointSiteList &GetBreakpointSiteList();
2014 
2015  const BreakpointSiteList &GetBreakpointSiteList() const;
2016 
2017  void DisableAllBreakpointSites();
2018 
2019  Status ClearBreakpointSiteByID(lldb::user_id_t break_id);
2020 
2021  lldb::break_id_t CreateBreakpointSite(const lldb::BreakpointLocationSP &owner,
2022  bool use_hardware);
2023 
2024  Status DisableBreakpointSiteByID(lldb::user_id_t break_id);
2025 
2026  Status EnableBreakpointSiteByID(lldb::user_id_t break_id);
2027 
2028  // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove themselves
2029  // from the owner's list of this breakpoint sites.
2030  void RemoveOwnerFromBreakpointSite(lldb::user_id_t owner_id,
2031  lldb::user_id_t owner_loc_id,
2032  lldb::BreakpointSiteSP &bp_site_sp);
2033 
2034  // Process Watchpoints (optional)
2035  virtual Status EnableWatchpoint(Watchpoint *wp, bool notify = true);
2036 
2037  virtual Status DisableWatchpoint(Watchpoint *wp, bool notify = true);
2038 
2039  // Thread Queries
2040  virtual bool UpdateThreadList(ThreadList &old_thread_list,
2041  ThreadList &new_thread_list) = 0;
2042 
2043  void UpdateThreadListIfNeeded();
2044 
2045  ThreadList &GetThreadList() { return m_thread_list; }
2046 
2047  // When ExtendedBacktraces are requested, the HistoryThreads that are created
2048  // need an owner -- they're saved here in the Process. The threads in this
2049  // list are not iterated over - driver programs need to request the extended
2050  // backtrace calls starting from a root concrete thread one by one.
2051  ThreadList &GetExtendedThreadList() { return m_extended_thread_list; }
2052 
2053  ThreadList::ThreadIterable Threads() { return m_thread_list.Threads(); }
2054 
2055  uint32_t GetNextThreadIndexID(uint64_t thread_id);
2056 
2057  lldb::ThreadSP CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context);
2058 
2059  // Returns true if an index id has been assigned to a thread.
2060  bool HasAssignedIndexIDToThread(uint64_t sb_thread_id);
2061 
2062  // Given a thread_id, it will assign a more reasonable index id for display
2063  // to the user. If the thread_id has previously been assigned, the same index
2064  // id will be used.
2065  uint32_t AssignIndexIDToThread(uint64_t thread_id);
2066 
2067  // Queue Queries
2068 
2069  void UpdateQueueListIfNeeded();
2070 
2072  UpdateQueueListIfNeeded();
2073  return m_queue_list;
2074  }
2075 
2077  UpdateQueueListIfNeeded();
2078  return m_queue_list.Queues();
2079  }
2080 
2081  // Event Handling
2082  lldb::StateType GetNextEvent(lldb::EventSP &event_sp);
2083 
2084  // Returns the process state when it is stopped. If specified, event_sp_ptr
2085  // is set to the event which triggered the stop. If wait_always = false, and
2086  // the process is already stopped, this function returns immediately. If the
2087  // process is hijacked and use_run_lock is true (the default), then this
2088  // function releases the run lock after the stop. Setting use_run_lock to
2089  // false will avoid this behavior.
2091  WaitForProcessToStop(const Timeout<std::micro> &timeout,
2092  lldb::EventSP *event_sp_ptr = nullptr,
2093  bool wait_always = true,
2094  lldb::ListenerSP hijack_listener = lldb::ListenerSP(),
2095  Stream *stream = nullptr, bool use_run_lock = true);
2096 
2097  uint32_t GetIOHandlerID() const { return m_iohandler_sync.GetValue(); }
2098 
2099  /// Waits for the process state to be running within a given msec timeout.
2100  ///
2101  /// The main purpose of this is to implement an interlock waiting for
2102  /// HandlePrivateEvent to push an IOHandler.
2103  ///
2104  /// \param[in] timeout
2105  /// The maximum time length to wait for the process to transition to the
2106  /// eStateRunning state.
2107  void SyncIOHandler(uint32_t iohandler_id, const Timeout<std::micro> &timeout);
2108 
2109  lldb::StateType GetStateChangedEvents(
2110  lldb::EventSP &event_sp, const Timeout<std::micro> &timeout,
2111  lldb::ListenerSP
2112  hijack_listener); // Pass an empty ListenerSP to use builtin listener
2113 
2114  /// Centralize the code that handles and prints descriptions for process
2115  /// state changes.
2116  ///
2117  /// \param[in] event_sp
2118  /// The process state changed event
2119  ///
2120  /// \param[in] stream
2121  /// The output stream to get the state change description
2122  ///
2123  /// \param[in,out] pop_process_io_handler
2124  /// If this value comes in set to \b true, then pop the Process IOHandler
2125  /// if needed.
2126  /// Else this variable will be set to \b true or \b false to indicate if
2127  /// the process
2128  /// needs to have its process IOHandler popped.
2129  ///
2130  /// \return
2131  /// \b true if the event describes a process state changed event, \b false
2132  /// otherwise.
2133  static bool HandleProcessStateChangedEvent(const lldb::EventSP &event_sp,
2134  Stream *stream,
2135  bool &pop_process_io_handler);
2136 
2137  Event *PeekAtStateChangedEvents();
2138 
2140  public:
2141  ProcessEventHijacker(Process &process, lldb::ListenerSP listener_sp)
2142  : m_process(process) {
2143  m_process.HijackProcessEvents(listener_sp);
2144  }
2145 
2147 
2148  private:
2149  Process &m_process;
2150  };
2151 
2152  friend class ProcessEventHijacker;
2153  friend class ProcessProperties;
2154  /// If you need to ensure that you and only you will hear about some public
2155  /// event, then make a new listener, set to listen to process events, and
2156  /// then call this with that listener. Then you will have to wait on that
2157  /// listener explicitly for events (rather than using the GetNextEvent &
2158  /// WaitFor* calls above. Be sure to call RestoreProcessEvents when you are
2159  /// done.
2160  ///
2161  /// \param[in] listener
2162  /// This is the new listener to whom all process events will be delivered.
2163  ///
2164  /// \return
2165  /// Returns \b true if the new listener could be installed,
2166  /// \b false otherwise.
2167  bool HijackProcessEvents(lldb::ListenerSP listener_sp);
2168 
2169  /// Restores the process event broadcasting to its normal state.
2170  ///
2171  void RestoreProcessEvents();
2172 
2173  bool StateChangedIsHijackedForSynchronousResume();
2174 
2175  bool StateChangedIsExternallyHijacked();
2176 
2177  const lldb::ABISP &GetABI();
2178 
2179  OperatingSystem *GetOperatingSystem() { return m_os_up.get(); }
2180 
2181  virtual LanguageRuntime *GetLanguageRuntime(lldb::LanguageType language,
2182  bool retry_if_null = true);
2183 
2184  virtual CPPLanguageRuntime *GetCPPLanguageRuntime(bool retry_if_null = true);
2185 
2186  virtual ObjCLanguageRuntime *
2187  GetObjCLanguageRuntime(bool retry_if_null = true);
2188 
2189  bool IsPossibleDynamicValue(ValueObject &in_value);
2190 
2191  bool IsRunning() const;
2192 
2194  return m_dynamic_checkers_up.get();
2195  }
2196 
2197  void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers);
2198 
2199  /// Call this to set the lldb in the mode where it breaks on new thread
2200  /// creations, and then auto-restarts. This is useful when you are trying
2201  /// to run only one thread, but either that thread or the kernel is creating
2202  /// new threads in the process. If you stop when the thread is created, you
2203  /// can immediately suspend it, and keep executing only the one thread you
2204  /// intend.
2205  ///
2206  /// \return
2207  /// Returns \b true if we were able to start up the notification
2208  /// \b false otherwise.
2209  virtual bool StartNoticingNewThreads() { return true; }
2210 
2211  /// Call this to turn off the stop & notice new threads mode.
2212  ///
2213  /// \return
2214  /// Returns \b true if we were able to start up the notification
2215  /// \b false otherwise.
2216  virtual bool StopNoticingNewThreads() { return true; }
2217 
2218  void SetRunningUserExpression(bool on);
2219  void SetRunningUtilityFunction(bool on);
2220 
2221  // lldb::ExecutionContextScope pure virtual functions
2222  lldb::TargetSP CalculateTarget() override;
2223 
2224  lldb::ProcessSP CalculateProcess() override { return shared_from_this(); }
2225 
2226  lldb::ThreadSP CalculateThread() override { return lldb::ThreadSP(); }
2227 
2228  lldb::StackFrameSP CalculateStackFrame() override {
2229  return lldb::StackFrameSP();
2230  }
2231 
2232  void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
2233 
2234  void SetSTDIOFileDescriptor(int file_descriptor);
2235 
2236  // Add a permanent region of memory that should never be read or written to.
2237  // This can be used to ensure that memory reads or writes to certain areas of
2238  // memory never end up being sent to the DoReadMemory or DoWriteMemory
2239  // functions which can improve performance.
2240  void AddInvalidMemoryRegion(const LoadRange &region);
2241 
2242  // Remove a permanent region of memory that should never be read or written
2243  // to that was previously added with AddInvalidMemoryRegion.
2244  bool RemoveInvalidMemoryRange(const LoadRange &region);
2245 
2246  // If the setup code of a thread plan needs to do work that might involve
2247  // calling a function in the target, it should not do that work directly in
2248  // one of the thread plan functions (DidPush/WillResume) because such work
2249  // needs to be handled carefully. Instead, put that work in a
2250  // PreResumeAction callback, and register it with the process. It will get
2251  // done before the actual "DoResume" gets called.
2252 
2253  typedef bool(PreResumeActionCallback)(void *);
2254 
2255  void AddPreResumeAction(PreResumeActionCallback callback, void *baton);
2256 
2257  bool RunPreResumeActions();
2258 
2259  void ClearPreResumeActions();
2260 
2261  void ClearPreResumeAction(PreResumeActionCallback callback, void *baton);
2262 
2263  ProcessRunLock &GetRunLock();
2264 
2265  virtual Status SendEventData(const char *data) {
2266  Status return_error("Sending an event is not supported for this process.");
2267  return return_error;
2268  }
2269 
2270  lldb::ThreadCollectionSP GetHistoryThreads(lldb::addr_t addr);
2271 
2272  lldb::InstrumentationRuntimeSP
2273  GetInstrumentationRuntime(lldb::InstrumentationRuntimeType type);
2274 
2275  /// Try to fetch the module specification for a module with the given file
2276  /// name and architecture. Process sub-classes have to override this method
2277  /// if they support platforms where the Platform object can't get the module
2278  /// spec for all module.
2279  ///
2280  /// \param[in] module_file_spec
2281  /// The file name of the module to get specification for.
2282  ///
2283  /// \param[in] arch
2284  /// The architecture of the module to get specification for.
2285  ///
2286  /// \param[out] module_spec
2287  /// The fetched module specification if the return value is
2288  /// \b true, unchanged otherwise.
2289  ///
2290  /// \return
2291  /// Returns \b true if the module spec fetched successfully,
2292  /// \b false otherwise.
2293  virtual bool GetModuleSpec(const FileSpec &module_file_spec,
2294  const ArchSpec &arch, ModuleSpec &module_spec);
2295 
2296  virtual void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
2297  const llvm::Triple &triple) {}
2298 
2299  /// Try to find the load address of a file.
2300  /// The load address is defined as the address of the first memory region
2301  /// what contains data mapped from the specified file.
2302  ///
2303  /// \param[in] file
2304  /// The name of the file whose load address we are looking for
2305  ///
2306  /// \param[out] is_loaded
2307  /// \b True if the file is loaded into the memory and false
2308  /// otherwise.
2309  ///
2310  /// \param[out] load_addr
2311  /// The load address of the file if it is loaded into the
2312  /// processes address space, LLDB_INVALID_ADDRESS otherwise.
2313  virtual Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
2314  lldb::addr_t &load_addr) {
2315  return Status("Not supported");
2316  }
2317 
2318  size_t AddImageToken(lldb::addr_t image_ptr);
2319 
2320  lldb::addr_t GetImagePtrFromToken(size_t token) const;
2321 
2322  void ResetImageToken(size_t token);
2323 
2324  /// Find the next branch instruction to set a breakpoint on
2325  ///
2326  /// When instruction stepping through a source line, instead of stepping
2327  /// through each instruction, we can put a breakpoint on the next branch
2328  /// instruction (within the range of instructions we are stepping through)
2329  /// and continue the process to there, yielding significant performance
2330  /// benefits over instruction stepping.
2331  ///
2332  /// \param[in] default_stop_addr
2333  /// The address of the instruction where lldb would put a
2334  /// breakpoint normally.
2335  ///
2336  /// \param[in] range_bounds
2337  /// The range which the breakpoint must be contained within.
2338  /// Typically a source line.
2339  ///
2340  /// \return
2341  /// The address of the next branch instruction, or the end of
2342  /// the range provided in range_bounds. If there are any
2343  /// problems with the disassembly or getting the instructions,
2344  /// the original default_stop_addr will be returned.
2345  Address AdvanceAddressToNextBranchInstruction(Address default_stop_addr,
2346  AddressRange range_bounds);
2347 
2348  /// Configure asynchronous structured data feature.
2349  ///
2350  /// Each Process type that supports using an asynchronous StructuredData
2351  /// feature should implement this to enable/disable/configure the feature.
2352  /// The default implementation here will always return an error indiciating
2353  /// the feature is unsupported.
2354  ///
2355  /// StructuredDataPlugin implementations will call this to configure a
2356  /// feature that has been reported as being supported.
2357  ///
2358  /// \param[in] type_name
2359  /// The StructuredData type name as previously discovered by
2360  /// the Process-derived instance.
2361  ///
2362  /// \param[in] config
2363  /// Configuration data for the feature being enabled. This config
2364  /// data, which may be null, will be passed along to the feature
2365  /// to process. The feature will dictate whether this is a dictionary,
2366  /// an array or some other object. If the feature needs to be
2367  /// set up properly before it can be enabled, then the config should
2368  /// also take an enable/disable flag.
2369  ///
2370  /// \return
2371  /// Returns the result of attempting to configure the feature.
2372  virtual Status
2373  ConfigureStructuredData(ConstString type_name,
2374  const StructuredData::ObjectSP &config_sp);
2375 
2376  /// Broadcasts the given structured data object from the given plugin.
2377  ///
2378  /// StructuredDataPlugin instances can use this to optionally broadcast any
2379  /// of their data if they want to make it available for clients. The data
2380  /// will come in on the structured data event bit
2381  /// (eBroadcastBitStructuredData).
2382  ///
2383  /// \param[in] object_sp
2384  /// The structured data object to broadcast.
2385  ///
2386  /// \param[in] plugin_sp
2387  /// The plugin that will be reported in the event's plugin
2388  /// parameter.
2389  void BroadcastStructuredData(const StructuredData::ObjectSP &object_sp,
2390  const lldb::StructuredDataPluginSP &plugin_sp);
2391 
2392  /// Returns the StructuredDataPlugin associated with a given type name, if
2393  /// there is one.
2394  ///
2395  /// There will only be a plugin for a given StructuredDataType if the
2396  /// debugged process monitor claims that the feature is supported. This is
2397  /// one way to tell whether a feature is available.
2398  ///
2399  /// \return
2400  /// The plugin if one is available for the specified feature;
2401  /// otherwise, returns an empty shared pointer.
2402  lldb::StructuredDataPluginSP
2403  GetStructuredDataPlugin(ConstString type_name) const;
2404 
2405  /// Starts tracing with the configuration provided in options. To enable
2406  /// tracing on the complete process the thread_id in the options should be
2407  /// set to LLDB_INVALID_THREAD_ID. The API returns a user_id which is needed
2408  /// by other API's that manipulate the trace instance. The handling of
2409  /// erroneous or unsupported configuration is left to the trace technology
2410  /// implementations in the server, as they could be returned as an error, or
2411  /// rounded to a valid configuration to start tracing. In the later case the
2412  /// GetTraceConfig should supply the actual used trace configuration.
2413  virtual lldb::user_id_t StartTrace(const TraceOptions &options,
2414  Status &error) {
2415  error.SetErrorString("Not implemented");
2416  return LLDB_INVALID_UID;
2417  }
2418 
2419  /// Stops the tracing instance leading to deletion of the trace data. The
2420  /// tracing instance is identified by the user_id which is obtained when
2421  /// tracing was started from the StartTrace. In case tracing of the complete
2422  /// process needs to be stopped the thread_id should be set to
2423  /// LLDB_INVALID_THREAD_ID. In the other case that tracing on an individual
2424  /// thread needs to be stopped a thread_id can be supplied.
2425  virtual Status StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id) {
2426  return Status("Not implemented");
2427  }
2428 
2429  /// Provides the trace data as raw bytes. A buffer needs to be supplied to
2430  /// copy the trace data. The exact behavior of this API may vary across
2431  /// trace technology, as some may support partial reading of the trace data
2432  /// from a specified offset while some may not. The thread_id should be used
2433  /// to select a particular thread for trace extraction.
2434  virtual Status GetData(lldb::user_id_t uid, lldb::tid_t thread_id,
2435  llvm::MutableArrayRef<uint8_t> &buffer,
2436  size_t offset = 0) {
2437  return Status("Not implemented");
2438  }
2439 
2440  /// Similar API as above except for obtaining meta data
2442  llvm::MutableArrayRef<uint8_t> &buffer,
2443  size_t offset = 0) {
2444  return Status("Not implemented");
2445  }
2446 
2447  /// API to obtain the trace configuration used by a trace instance.
2448  /// Configurations that may be specific to some trace technology should be
2449  /// stored in the custom parameters. The options are transported to the
2450  /// server, which shall interpret accordingly. The thread_id can be
2451  /// specified in the options to obtain the configuration used by a specific
2452  /// thread. The thread_id specified should also match the uid otherwise an
2453  /// error will be returned.
2455  return Status("Not implemented");
2456  }
2457 
2458 protected:
2459  void SetState(lldb::EventSP &event_sp);
2460 
2461  lldb::StateType GetPrivateState();
2462 
2463  /// The "private" side of resuming a process. This doesn't alter the state
2464  /// of m_run_lock, but just causes the process to resume.
2465  ///
2466  /// \return
2467  /// An Status object describing the success or failure of the resume.
2468  Status PrivateResume();
2469 
2470  // Called internally
2471  void CompleteAttach();
2472 
2473  /// Print a user-visible warning one time per Process
2474  ///
2475  /// A facility for printing a warning to the user once per repeat_key.
2476  ///
2477  /// warning_type is from the Process::Warnings enums. repeat_key is a
2478  /// pointer value that will be used to ensure that the warning message is
2479  /// not printed multiple times. For instance, with a warning about a
2480  /// function being optimized, you can pass the CompileUnit pointer to have
2481  /// the warning issued for only the first function in a CU, or the Function
2482  /// pointer to have it issued once for every function, or a Module pointer
2483  /// to have it issued once per Module.
2484  ///
2485  /// Classes outside Process should call a specific PrintWarning method so
2486  /// that the warning strings are all centralized in Process, instead of
2487  /// calling PrintWarning() directly.
2488  ///
2489  /// \param [in] warning_type
2490  /// One of the types defined in Process::Warnings.
2491  ///
2492  /// \param [in] repeat_key
2493  /// A pointer value used to ensure that the warning is only printed once.
2494  /// May be nullptr, indicating that the warning is printed unconditionally
2495  /// every time.
2496  ///
2497  /// \param [in] fmt
2498  /// printf style format string
2499  void PrintWarning(uint64_t warning_type, const void *repeat_key,
2500  const char *fmt, ...) __attribute__((format(printf, 4, 5)));
2501 
2502  // NextEventAction provides a way to register an action on the next event
2503  // that is delivered to this process. There is currently only one next event
2504  // action allowed in the process at one time. If a new "NextEventAction" is
2505  // added while one is already present, the old action will be discarded (with
2506  // HandleBeingUnshipped called after it is discarded.)
2507  //
2508  // If you want to resume the process as a result of a resume action, call
2509  // RequestResume, don't call Resume directly.
2511  public:
2512  typedef enum EventActionResult {
2515  eEventActionExit
2517 
2518  NextEventAction(Process *process) : m_process(process) {}
2519 
2520  virtual ~NextEventAction() = default;
2521 
2522  virtual EventActionResult PerformAction(lldb::EventSP &event_sp) = 0;
2523  virtual void HandleBeingUnshipped() {}
2524  virtual EventActionResult HandleBeingInterrupted() = 0;
2525  virtual const char *GetExitString() = 0;
2527 
2528  protected:
2530  };
2531 
2533  if (m_next_event_action_up.get())
2534  m_next_event_action_up->HandleBeingUnshipped();
2535 
2536  m_next_event_action_up.reset(next_event_action);
2537  }
2538 
2539  // This is the completer for Attaching:
2541  public:
2542  AttachCompletionHandler(Process *process, uint32_t exec_count);
2543 
2544  ~AttachCompletionHandler() override = default;
2545 
2546  EventActionResult PerformAction(lldb::EventSP &event_sp) override;
2547  EventActionResult HandleBeingInterrupted() override;
2548  const char *GetExitString() override;
2549 
2550  private:
2551  uint32_t m_exec_count;
2552  std::string m_exit_string;
2553  };
2554 
2556  lldb::StateType state = m_private_state.GetValue();
2557  return state != lldb::eStateInvalid && state != lldb::eStateDetached &&
2558  state != lldb::eStateExited && m_private_state_thread.IsJoinable();
2559  }
2560 
2561  void ForceNextEventDelivery() { m_force_next_event_delivery = true; }
2562 
2563  /// Loads any plugins associated with asynchronous structured data and maps
2564  /// the relevant supported type name to the plugin.
2565  ///
2566  /// Processes can receive asynchronous structured data from the process
2567  /// monitor. This method will load and map any structured data plugins that
2568  /// support the given set of supported type names. Later, if any of these
2569  /// features are enabled, the process monitor is free to generate
2570  /// asynchronous structured data. The data must come in as a single \b
2571  /// StructuredData::Dictionary. That dictionary must have a string field
2572  /// named 'type', with a value that equals the relevant type name string
2573  /// (one of the values in \b supported_type_names).
2574  ///
2575  /// \param[in] supported_type_names
2576  /// An array of zero or more type names. Each must be unique.
2577  /// For each entry in the list, a StructuredDataPlugin will be
2578  /// searched for that supports the structured data type name.
2579  void MapSupportedStructuredDataPlugins(
2580  const StructuredData::Array &supported_type_names);
2581 
2582  /// Route the incoming structured data dictionary to the right plugin.
2583  ///
2584  /// The incoming structured data must be a dictionary, and it must have a
2585  /// key named 'type' that stores a string value. The string value must be
2586  /// the name of the structured data feature that knows how to handle it.
2587  ///
2588  /// \param[in] object_sp
2589  /// When non-null and pointing to a dictionary, the 'type'
2590  /// key's string value is used to look up the plugin that
2591  /// was registered for that structured data type. It then
2592  /// calls the following method on the StructuredDataPlugin
2593  /// instance:
2594  ///
2595  /// virtual void
2596  /// HandleArrivalOfStructuredData(Process &process,
2597  /// ConstString type_name,
2598  /// const StructuredData::ObjectSP
2599  /// &object_sp)
2600  ///
2601  /// \return
2602  /// True if the structured data was routed to a plugin; otherwise,
2603  /// false.
2604  bool RouteAsyncStructuredData(const StructuredData::ObjectSP object_sp);
2605 
2606  // Type definitions
2607  typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP>
2609  typedef std::unordered_set<const void *> WarningsPointerSet;
2610  typedef std::map<uint64_t, WarningsPointerSet> WarningsCollection;
2611 
2613  bool (*callback)(void *);
2614  void *baton;
2615  PreResumeCallbackAndBaton(PreResumeActionCallback in_callback,
2616  void *in_baton)
2617  : callback(in_callback), baton(in_baton) {}
2619  return callback == rhs.callback && baton == rhs.baton;
2620  }
2621  };
2622 
2623  using StructuredDataPluginMap =
2624  std::map<ConstString, lldb::StructuredDataPluginSP>;
2625 
2626  // Member variables
2627  std::weak_ptr<Target> m_target_wp; ///< The target that owns this process.
2630  m_private_state; // The actual state of our process
2631  Broadcaster m_private_state_broadcaster; // This broadcaster feeds state
2632  // changed events into the private
2633  // state thread's listener.
2635  // broadcaster, used to
2636  // pause, resume & stop the
2637  // private state thread.
2638  lldb::ListenerSP m_private_state_listener_sp; // This is the listener for the
2639  // private state thread.
2640  HostThread m_private_state_thread; ///< Thread ID for the thread that watches
2641  ///internal state events
2642  ProcessModID m_mod_id; ///< Tracks the state of the process over stops and
2643  ///other alterations.
2644  uint32_t m_process_unique_id; ///< Each lldb_private::Process class that is
2645  ///created gets a unique integer ID that
2646  ///increments with each new instance
2647  uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index
2648  ///that won't get re-used.
2649  std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map;
2650  int m_exit_status; ///< The exit status of the process, or -1 if not set.
2651  std::string m_exit_string; ///< A textual description of why a process exited.
2652  std::mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can
2653  ///be safely accessed from multiple threads
2654  std::recursive_mutex m_thread_mutex;
2655  ThreadList m_thread_list_real; ///< The threads for this process as are known
2656  ///to the protocol we are debugging with
2657  ThreadList m_thread_list; ///< The threads for this process as the user will
2658  ///see them. This is usually the same as
2659  ///< m_thread_list_real, but might be different if there is an OS plug-in
2660  ///creating memory threads
2661  ThreadList m_extended_thread_list; ///< Owner for extended threads that may be
2662  ///generated, cleared on natural stops
2663  uint32_t m_extended_thread_stop_id; ///< The natural stop id when
2664  ///extended_thread_list was last updated
2665  QueueList
2666  m_queue_list; ///< The list of libdispatch queues at a given stop point
2667  uint32_t m_queue_list_stop_id; ///< The natural stop id when queue list was
2668  ///last fetched
2669  std::vector<Notifications> m_notifications; ///< The list of notifications
2670  ///that this process can deliver.
2671  std::vector<lldb::addr_t> m_image_tokens;
2672  lldb::ListenerSP m_listener_sp; ///< Shared pointer to the listener used for
2673  ///public events. Can not be empty.
2674  BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint
2675  ///locations we intend to insert in
2676  ///the target.
2677  lldb::DynamicLoaderUP m_dyld_up;
2678  lldb::JITLoaderListUP m_jit_loaders_up;
2679  lldb::DynamicCheckerFunctionsUP m_dynamic_checkers_up; ///< The functions used
2680  /// by the expression
2681  /// parser to validate
2682  /// data that
2683  /// expressions use.
2684  lldb::OperatingSystemUP m_os_up;
2685  lldb::SystemRuntimeUP m_system_runtime_up;
2686  lldb::UnixSignalsSP
2687  m_unix_signals_sp; /// This is the current signal set for this process.
2688  lldb::ABISP m_abi_sp;
2689  lldb::IOHandlerSP m_process_input_reader;
2691  std::recursive_mutex m_stdio_communication_mutex;
2692  bool m_stdin_forward; /// Remember if stdin must be forwarded to remote debug
2693  /// server
2694  std::string m_stdout_data;
2695  std::string m_stderr_data;
2696  std::recursive_mutex m_profile_data_comm_mutex;
2697  std::vector<std::string> m_profile_data;
2701  bool m_should_detach; /// Should we detach if the process object goes away
2702  /// with an explicit call to Kill or Detach?
2705  std::unique_ptr<NextEventAction> m_next_event_action_up;
2706  std::vector<PreResumeCallbackAndBaton> m_pre_resume_actions;
2710  bool m_resume_requested; // If m_currently_handling_event or
2711  // m_currently_handling_do_on_removals are true,
2712  // Resume will only request a resume, using this
2713  // flag to check.
2714  bool m_finalizing; // This is set at the beginning of Process::Finalize() to
2715  // stop functions from looking up or creating things
2716  // during a finalize call
2717  bool m_finalize_called; // This is set at the end of Process::Finalize()
2720  lldb::StateType m_last_broadcast_state; /// This helps with the Public event
2721  /// coalescing in
2722  /// ShouldBroadcastEvent.
2723  std::map<lldb::addr_t, lldb::addr_t> m_resolved_indirect_addresses;
2725  bool m_can_interpret_function_calls; // Some targets, e.g the OSX kernel,
2726  // don't support the ability to modify
2727  // the stack.
2728  WarningsCollection m_warnings_issued; // A set of object pointers which have
2729  // already had warnings printed
2732 
2733  enum { eCanJITDontKnow = 0, eCanJITYes, eCanJITNo } m_can_jit;
2734 
2735  std::unique_ptr<UtilityFunction> m_dlopen_utility_func_up;
2737 
2738  size_t RemoveBreakpointOpcodesFromBuffer(lldb::addr_t addr, size_t size,
2739  uint8_t *buf) const;
2740 
2741  void SynchronouslyNotifyStateChanged(lldb::StateType state);
2742 
2743  void SetPublicState(lldb::StateType new_state, bool restarted);
2744 
2745  void SetPrivateState(lldb::StateType state);
2746 
2747  bool StartPrivateStateThread(bool is_secondary_thread = false);
2748 
2749  void StopPrivateStateThread();
2750 
2751  void PausePrivateStateThread();
2752 
2753  void ResumePrivateStateThread();
2754 
2755 private:
2756  struct PrivateStateThreadArgs {
2757  PrivateStateThreadArgs(Process *p, bool s)
2758  : process(p), is_secondary_thread(s){};
2759  Process *process;
2760  bool is_secondary_thread;
2761  };
2762 
2763  // arg is a pointer to a new'ed PrivateStateThreadArgs structure.
2764  // PrivateStateThread will free it for you.
2765  static lldb::thread_result_t PrivateStateThread(void *arg);
2766 
2767  // The starts up the private state thread that will watch for events from the
2768  // debugee. Pass true for is_secondary_thread in the case where you have to
2769  // temporarily spin up a secondary state thread to handle events from a hand-
2770  // called function on the primary private state thread.
2771 
2772  lldb::thread_result_t RunPrivateStateThread(bool is_secondary_thread);
2773 
2774 protected:
2775  void HandlePrivateEvent(lldb::EventSP &event_sp);
2776 
2777  Status HaltPrivate();
2778 
2779  lldb::StateType WaitForProcessStopPrivate(lldb::EventSP &event_sp,
2780  const Timeout<std::micro> &timeout);
2781 
2782  // This waits for both the state change broadcaster, and the control
2783  // broadcaster. If control_only, it only waits for the control broadcaster.
2784 
2785  bool GetEventsPrivate(lldb::EventSP &event_sp,
2786  const Timeout<std::micro> &timeout, bool control_only);
2787 
2789  GetStateChangedEventsPrivate(lldb::EventSP &event_sp,
2790  const Timeout<std::micro> &timeout);
2791 
2792  size_t WriteMemoryPrivate(lldb::addr_t addr, const void *buf, size_t size,
2793  Status &error);
2794 
2795  void AppendSTDOUT(const char *s, size_t len);
2796 
2797  void AppendSTDERR(const char *s, size_t len);
2798 
2799  void BroadcastAsyncProfileData(const std::string &one_profile_data);
2800 
2801  static void STDIOReadThreadBytesReceived(void *baton, const void *src,
2802  size_t src_len);
2803 
2804  bool PushProcessIOHandler();
2805 
2806  bool PopProcessIOHandler();
2807 
2808  bool ProcessIOHandlerIsActive();
2809 
2810  bool ProcessIOHandlerExists() const {
2811  return static_cast<bool>(m_process_input_reader);
2812  }
2813 
2814  Status StopForDestroyOrDetach(lldb::EventSP &exit_event_sp);
2815 
2816  virtual Status UpdateAutomaticSignalFiltering();
2817 
2818  void LoadOperatingSystemPlugin(bool flush);
2819 
2820 private:
2821  /// This is the part of the event handling that for a process event. It
2822  /// decides what to do with the event and returns true if the event needs to
2823  /// be propagated to the user, and false otherwise. If the event is not
2824  /// propagated, this call will most likely set the target to executing
2825  /// again. There is only one place where this call should be called,
2826  /// HandlePrivateEvent. Don't call it from anywhere else...
2827  ///
2828  /// \param[in] event_ptr
2829  /// This is the event we are handling.
2830  ///
2831  /// \return
2832  /// Returns \b true if the event should be reported to the
2833  /// user, \b false otherwise.
2834  bool ShouldBroadcastEvent(Event *event_ptr);
2835 
2836  void ControlPrivateStateThread(uint32_t signal);
2837 
2838  DISALLOW_COPY_AND_ASSIGN(Process);
2839 };
2840 
2841 /// RAII guard that should be aquired when an utility function is called within
2842 /// a given process.
2844  Process *m_process;
2845 
2846 public:
2847  UtilityFunctionScope(Process *p) : m_process(p) {
2848  if (m_process)
2849  m_process->SetRunningUtilityFunction(true);
2850  }
2852  if (m_process)
2853  m_process->SetRunningUtilityFunction(false);
2854  }
2855 };
2856 
2857 } // namespace lldb_private
2858 
2859 #endif // liblldb_Process_h_
ThreadSafeValue< lldb::StateType > m_public_state
Definition: Process.h:2628
static const DynamicLoaderDarwinKernelPropertiesSP & GetGlobalProperties()
std::shared_ptr< ProcessProperties > ProcessPropertiesSP
Definition: Process.h:93
A class to manage flag bits.
Definition: Debugger.h:82
virtual lldb::user_id_t StartTrace(const TraceOptions &options, Status &error)
Starts tracing with the configuration provided in options.
Definition: Process.h:2413
Class that manages the actual breakpoint that will be inserted into the running program.
virtual void WillPublicStop()
Called when the process is about to broadcast a public stop.
Definition: Process.h:759
std::unique_ptr< NextEventAction > m_next_event_action_up
Definition: Process.h:2705
std::string m_stdout_data
Remember if stdin must be forwarded to remote debug server.
Definition: Process.h:2694
A command line argument class.
Definition: Args.h:32
virtual Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded, lldb::addr_t &load_addr)
Try to find the load address of a file.
Definition: Process.h:2313
lldb_private::LazyBool disable_aslr
Definition: Process.h:224
std::vector< lldb::addr_t > m_image_tokens
Definition: Process.h:2671
ThreadList & GetExtendedThreadList()
Definition: Process.h:2051
virtual Status WillAttachToProcessWithName(const char *process_name, bool wait_for_launch)
Called before attaching to a process.
Definition: Process.h:898
uint32_t m_process_unique_id
Each lldb_private::Process class that is created gets a unique integer ID that increments with each n...
Definition: Process.h:2644
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
uint32_t GetUniqueID() const
Definition: Process.h:556
WarningsCollection m_warnings_issued
Definition: Process.h:2728
int32_t break_id_t
Definition: lldb-types.h:88
virtual Status WillLaunch(Module *module)
Called before launching to a process.
Definition: Process.h:993
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
ProcessModID(const ProcessModID &rhs)
Definition: Process.h:241
bool GetWarningsOptimization() const
Definition: Process.cpp:275
OperatingSystem * GetOperatingSystem()
Definition: Process.h:2179
void SetIgnoreBreakpointsInExpressions(bool ignore)
Definition: Process.cpp:237
void SetDetachKeepsStopped(bool keep_stopped)
Definition: Process.cpp:270
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
std::unordered_set< const void * > WarningsPointerSet
Definition: Process.h:2609
bool CanInterpretFunctionCalls()
Determines whether executing function calls using the interpreter is possible for this process...
Definition: Process.h:1836
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:92
ProcessRunLock m_public_run_lock
Definition: Process.h:2707
std::vector< Notifications > m_notifications
The list of notifications that this process can deliver.
Definition: Process.h:2669
virtual lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(const std::vector< lldb::addr_t > &load_addresses)
Definition: Process.h:1284
lldb::ThreadSP CalculateThread() override
Definition: Process.h:2226
uint32_t GetLastUserExpressionResumeID() const
Definition: Process.h:1341
virtual Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info)
Launch a new process.
Definition: Process.h:1012
uint32_t GetIOHandlerID() const
Definition: Process.h:2097
virtual Status WillDetach()
Called before detaching from a process.
Definition: Process.h:1104
std::weak_ptr< Target > m_target_wp
The target that owns this process.
Definition: Process.h:2627
Broadcaster m_private_state_broadcaster
Definition: Process.h:2631
virtual void DidSignal()
Called after sending a signal to a process.
Definition: Process.h:1162
virtual size_t LoadModules(LoadedModuleInfoList &)
Definition: Process.h:686
std::string m_stderr_data
Definition: Process.h:2695
virtual Status StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id)
Stops the tracing instance leading to deletion of the trace data.
Definition: Process.h:2425
bool IsValid() const
Definition: Process.h:290
void SetDetachOnError(bool enable)
Definition: Process.h:173
A mix in class that contains a generic user ID.
Definition: UserID.h:33
A file utility class.
Definition: FileSpec.h:55
An architecture specification class.
Definition: ArchSpec.h:32
ThreadList & GetThreadList()
Definition: Process.h:2045
virtual Status GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id, llvm::MutableArrayRef< uint8_t > &buffer, size_t offset=0)
Similar API as above except for obtaining meta data.
Definition: Process.h:2441
AllocatedMemoryCache m_allocated_memory_cache
Definition: Process.h:2700
void SetIgnoreExisting(bool b)
Definition: Process.h:130
A class used to prevent the process from starting while other threads are accessing its data...
bool GetContinueOnceAttached() const
Definition: Process.h:132
std::map< lldb::addr_t, lldb::addr_t > m_resolved_indirect_addresses
This helps with the Public event coalescing in ShouldBroadcastEvent.
Definition: Process.h:2723
uint32_t GetStopID() const
Definition: Process.h:272
An event broadcasting class.
Definition: Broadcaster.h:250
virtual void PrefetchModuleSpecs(llvm::ArrayRef< FileSpec > module_file_specs, const llvm::Triple &triple)
Definition: Process.h:2296
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
virtual size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error)
Actually do the writing of memory to a process.
Definition: Process.h:1578
virtual lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos()
Definition: Process.h:1278
PreResumeCallbackAndBaton(PreResumeActionCallback in_callback, void *in_baton)
Definition: Process.h:2615
ProcessProperties(lldb_private::Process *process)
Definition: Process.cpp:167
lldb::EventSP GetStopEventForStopID(uint32_t stop_id) const
Definition: Process.h:1349
bool IsRunningUtilityFunction() const
Definition: Process.h:268
A notification structure that can be used by clients to listen for changes in a process&#39;s lifetime...
Definition: Process.h:409
LanguageRuntimeCollection m_language_runtimes
Should we detach if the process object goes away with an explicit call to Kill or Detach...
Definition: Process.h:2703
std::map< lldb::InstrumentationRuntimeType, lldb::InstrumentationRuntimeSP > InstrumentationRuntimeCollection
bool GetShouldDetach() const
Definition: Process.h:729
lldb::ListenerSP GetListener() const
virtual Status DoDetach(bool keep_stopped)
Detaches from a running or stopped process.
Definition: Process.h:1111
std::vector< std::string > m_profile_data
Definition: Process.h:2697
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Process.h:214
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
lldb::ListenerSP m_listener_sp
Shared pointer to the listener used for public events.
Definition: Process.h:2672
bool IsValid() const
Return whether this object is valid (i.e.
Definition: Process.h:581
virtual void DidDetach()
Called after detaching from a process.
Definition: Process.h:1123
virtual void DidLaunch()
Called after launching a process.
Definition: Process.h:1023
uint32_t m_queue_list_stop_id
The natural stop id when queue list was last fetched.
Definition: Process.h:2667
ProcessAttachInfo(const ProcessLaunchInfo &launch_info)
Definition: Process.h:107
virtual bool DestroyRequiresHalt()
Definition: Process.h:1156
const char * GetProcessPluginName() const
Definition: Process.h:140
uint64_t GetMemoryCacheLineSize() const
Definition: Process.cpp:203
A plug-in interface definition class for halted OS helpers.
ProcessRunLock m_private_run_lock
Definition: Process.h:2708
FileSpec GetPythonOSPluginPath() const
Definition: Process.cpp:221
virtual llvm::VersionTuple GetHostOSVersion()
Sometimes the connection to a process can detect the host OS version that the process is running on...
Definition: Process.h:1187
void Clear()
Clears the object state.
Definition: ArchSpec.cpp:580
bool GetIgnoreExisting() const
Definition: Process.h:128
void SetCanInterpretFunctionCalls(bool can_interpret_function_calls)
Sets whether executing function calls using the interpreter is possible for this process.
Definition: Process.h:1843
virtual Status WillDestroy()
Definition: Process.h:1150
std::map< uint64_t, uint32_t > m_thread_id_to_index_id_map
Definition: Process.h:2649
virtual Status WillSignal()
Called before sending a signal to a process.
Definition: Process.h:1136
Process has exited and can&#39;t be examined.
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:973
"lldb/Expression/IRDynamicChecks.h" Encapsulates dynamic check functions used by expressions.
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb::ProcessSP CalculateProcess() override
Definition: Process.h:2224
void SetNextEventAction(Process::NextEventAction *next_event_action)
Definition: Process.h:2532
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
void SetStopEventForLastNaturalStopID(lldb::EventSP event_sp)
Definition: Process.h:319
std::string m_exit_string
A textual description of why a process exited.
Definition: Process.h:2651
uint64_t user_id_t
Definition: lldb-types.h:84
LanguageType
Programming language type.
virtual bool DetachRequiresHalt()
Definition: Process.h:1125
bool m_force_next_event_delivery
Definition: Process.h:2719
void SetPythonOSPluginPath(const FileSpec &file)
Definition: Process.cpp:226
lldb::ABISP m_abi_sp
This is the current signal set for this process.
Definition: Process.h:2688
std::map< lldb::LanguageType, lldb::LanguageRuntimeSP > LanguageRuntimeCollection
Definition: Process.h:2608
lldb::DynamicCheckerFunctionsUP m_dynamic_checkers_up
The functions used by the expression parser to validate data that expressions use.
Definition: Process.h:2679
lldb::ProcessSP GetProcessSP() const
Definition: Process.h:429
uint32_t GetStopID() const
Definition: Process.h:1337
virtual bool StopNoticingNewThreads()
Call this to turn off the stop & notice new threads mode.
Definition: Process.h:2216
bool m_clear_thread_plans_on_stop
Definition: Process.h:2718
virtual Status GetWatchpointSupportInfo(uint32_t &num, bool &after)
Definition: Process.h:1784
std::recursive_mutex m_profile_data_comm_mutex
Definition: Process.h:2696
void SetShouldDetach(bool b)
Definition: Process.h:731
ProcessModID m_mod_id
Tracks the state of the process over stops and other alterations.
Definition: Process.h:2642
lldb::ListenerSP m_private_state_listener_sp
Definition: Process.h:2638
InstrumentationRuntimeType
void SetListener(const lldb::ListenerSP &listener_sp)
Definition: Process.h:178
A collection class for Module objects.
Definition: ModuleList.h:91
uint32_t GetMemoryID() const
Definition: Process.h:274
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:109
lldb::IOHandlerSP m_process_input_reader
Definition: Process.h:2689
ThreadList m_thread_list_real
The threads for this process as are known to the protocol we are debugging with.
Definition: Process.h:2655
void SetResumeCount(uint32_t c)
Definition: Process.h:138
Process has been detached and can&#39;t be examined.
virtual void DoDidExec()
Subclasses of Process should implement this function if they need to do anything after a process exec...
Definition: Process.h:985
static size_t ReadCStringFromMemory(ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
Definition: Address.cpp:189
lldb::StateType GetState() const
Definition: Process.h:431
bool ProcessInfoSpecified() const
Definition: Process.h:155
StructuredDataPluginMap m_structured_data_plugin_map
Definition: Process.h:2731
void SetRunningUtilityFunction(bool on)
Definition: Process.cpp:1535
bool StopIDEqual(const ProcessModID &compare) const
Definition: Process.h:284
uint64_t tid_t
Definition: lldb-types.h:86
Encapsulates a function that can be called.
QueueList m_queue_list
The list of libdispatch queues at a given stop point.
Definition: Process.h:2666
virtual Status DoSignal(int signal)
Sends a process a UNIX signal signal.
Definition: Process.h:1142
bool GetStopOnSharedLibraryEvents() const
Definition: Process.cpp:253
lldb::ListenerSP m_hijack_listener_sp
Definition: Process.h:186
lldb::ListenerSP m_listener_sp
Definition: Process.h:185
bool MemoryIDEqual(const ProcessModID &compare) const
Definition: Process.h:280
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
lldb::OperatingSystemUP m_os_up
Definition: Process.h:2684
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
Warnings
Process warning types.
Definition: Process.h:385
bool HijackProcessEvents(lldb::ListenerSP listener_sp)
If you need to ensure that you and only you will hear about some public event, then make a new listen...
Definition: Process.cpp:1037
virtual Status DoLoadCore()
Definition: Process.h:620
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
uint32_t m_extended_thread_stop_id
The natural stop id when extended_thread_list was last updated.
Definition: Process.h:2663
virtual size_t PutSTDIN(const char *buf, size_t buf_size, Status &error)
Puts data into this process&#39;s STDIN.
Definition: Process.h:1962
const Target & GetTarget() const
Get the const target object pointer for this module.
Definition: Process.h:1201
lldb::JITLoaderListUP m_jit_loaders_up
Definition: Process.h:2678
virtual bool WarnBeforeDetach() const
Before lldb detaches from a process, it warns the user that they are about to lose their debug sessio...
Definition: Process.h:1383
A plug-in interface definition class for debug platform that includes many platform abilities such as...
Definition: Platform.h:67
std::recursive_mutex m_thread_mutex
Definition: Process.h:2654
virtual bool StartNoticingNewThreads()
Call this to set the lldb in the mode where it breaks on new thread creations, and then auto-restarts...
Definition: Process.h:2209
bool GetDetachKeepsStopped() const
Definition: Process.cpp:264
DynamicCheckerFunctions * GetDynamicCheckers()
Definition: Process.h:2193
void SetStopOnSharedLibraryEvents(bool stop)
Definition: Process.cpp:259
virtual size_t LoadModules()
Sometimes processes know how to retrieve and load shared libraries.
Definition: Process.h:684
Range< lldb::addr_t, lldb::addr_t > LoadRange
Definition: Process.h:387
uint32_t GetResumeID() const
Definition: Process.h:275
A section + offset based address class.
Definition: Address.h:80
void SetHijackListener(const lldb::ListenerSP &listener_sp)
Definition: Process.h:167
virtual Status GetTraceConfig(lldb::user_id_t uid, TraceOptions &options)
API to obtain the trace configuration used by a trace instance.
Definition: Process.h:2454
virtual Status WillHalt()
Called before halting to a process.
Definition: Process.h:1067
bool PrivateStateThreadIsValid() const
Definition: Process.h:2555
Predicate< uint32_t > m_iohandler_sync
Definition: Process.h:2698
ThreadList m_extended_thread_list
Owner for extended threads that may be generated, cleared on natural stops.
Definition: Process.h:2661
virtual Status GetData(lldb::user_id_t uid, lldb::tid_t thread_id, llvm::MutableArrayRef< uint8_t > &buffer, size_t offset=0)
Provides the trace data as raw bytes.
Definition: Process.h:2434
static size_t DoReadMemory(lldb::pid_t pid, lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:979
int m_exit_status
The exit status of the process, or -1 if not set.
Definition: Process.h:2650
std::vector< PreResumeCallbackAndBaton > m_pre_resume_actions
Definition: Process.h:2706
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:64
virtual Status SendEventData(const char *data)
Definition: Process.h:2265
std::mutex m_exit_status_mutex
Mutex so m_exit_status m_exit_string can be safely accessed from multiple threads.
Definition: Process.h:2652
std::chrono::seconds GetUtilityExpressionTimeout() const
Definition: Process.cpp:287
lldb::StateType m_last_broadcast_state
Definition: Process.h:2720
virtual void DidResume()
Called after resuming a process.
Definition: Process.h:1059
An abstract communications class.
Definition: Communication.h:91
virtual CommandObject * GetPluginCommandObject()
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition: Process.h:595
ThreadSafeValue< lldb::StateType > m_private_state
Definition: Process.h:2630
uint32_t m_thread_index_id
Each thread is created with a 1 based index that won&#39;t get re-used.
Definition: Process.h:2647
const ProcessModID & GetModIDRef() const
Definition: Process.h:1335
uint32_t GetLastNaturalStopID() const
Definition: Process.h:273
std::map< ConstString, lldb::StructuredDataPluginSP > StructuredDataPluginMap
Definition: Process.h:2624
std::map< uint64_t, WarningsPointerSet > WarningsCollection
Definition: Process.h:2610
void SetRunningUserExpression(bool on)
Definition: Process.h:301
A command line option parsing protocol class.
Definition: Options.h:62
std::once_flag m_dlopen_utility_func_flag_once
Definition: Process.h:2736
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1194
uint32_t GetResumeCount() const
Definition: Process.h:136
virtual Status WillResume()
Called before resuming to a process.
Definition: Process.h:1031
BreakpointSiteList m_breakpoint_site_list
This is the list of breakpoint locations we intend to insert in the target.
Definition: Process.h:2674
uint64_t addr_t
Definition: lldb-types.h:83
virtual void DidHalt()
Called after halting a process.
Definition: Process.h:1095
virtual void DidExit()
Definition: Process.h:1327
bool m_can_interpret_function_calls
Definition: Process.h:2725
void SetExtraStartupCommands(const Args &args)
Definition: Process.cpp:216
A uniqued constant string class.
Definition: ConstString.h:38
QueueList::QueueIterable Queues()
Definition: Process.h:2076
InstrumentationRuntimeCollection m_instrumentation_runtimes
Definition: Process.h:2704
MemoryCache m_memory_cache
Definition: Process.h:2699
virtual void DidAttach(ArchSpec &process_arch)
Called after attaching a process.
Definition: Process.h:973
HostThread m_private_state_thread
Thread ID for the thread that watches internal state events.
Definition: Process.h:2640
void SetProcessPluginName(llvm::StringRef plugin)
Definition: Process.h:144
void SetUnwindOnErrorInExpressions(bool ignore)
Definition: Process.cpp:248
virtual Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Locate the memory region that contains load_addr.
Definition: Process.h:1759
ProcessModID GetModID() const
Get the Modification ID of the process.
Definition: Process.h:1333
virtual void DidDestroy()
Definition: Process.h:1154
lldb::EventSP GetStopEventForStopID(uint32_t stop_id) const
Definition: Process.h:323
bool GetUnwindOnErrorInExpressions() const
Definition: Process.cpp:242
uint32_t GetLastNaturalStopID() const
Definition: Process.h:1345
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition: Process.h:2657
virtual Status GetWatchpointSupportInfo(uint32_t &num)
Definition: Process.h:1777
QueueList & GetQueueList()
Definition: Process.h:2071
std::mutex m_run_thread_plan_lock
Definition: Process.h:2730
uint64_t pid_t
Definition: lldb-types.h:85
virtual Status DoDeallocateMemory(lldb::addr_t ptr)
Actually deallocate memory in the process.
Definition: Process.h:1865
Class used by the Process to hold a list of its JITLoaders.
Definition: JITLoaderList.h:22
bool GetDisableMemoryCache() const
Definition: Process.cpp:197
Args GetExtraStartupCommands() const
Definition: Process.cpp:209
void ForceNextEventDelivery()
Definition: Process.h:2561
std::shared_ptr< Object > ObjectSP
ProcessEventHijacker(Process &process, lldb::ListenerSP listener_sp)
Definition: Process.h:2141
lldb::ListenerSP GetHijackListener() const
bool IsLastResumeForUserExpression() const
Definition: Process.h:292
bool m_currently_handling_do_on_removals
Definition: Process.h:2709
std::recursive_mutex m_stdio_communication_mutex
Definition: Process.h:2691
virtual lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(lldb::addr_t image_list_address, lldb::addr_t image_count)
Retrieve the list of shared libraries that are loaded for this process This method is used on pre-mac...
Definition: Process.h:1270
lldb::StackFrameSP CalculateStackFrame() override
Definition: Process.h:2228
lldb::UnixSignalsSP m_unix_signals_sp
Definition: Process.h:2687
virtual Status DoResume()
Resumes all of a process&#39;s threads as configured using the Thread run control functions.
Definition: Process.h:1048
virtual lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, Status &error)
Actually allocate memory in the process.
Definition: Process.h:1662
virtual Status EnableBreakpointSite(BreakpointSite *bp_site)
Definition: Process.h:1985
bool GetIgnoreBreakpointsInExpressions() const
Definition: Process.cpp:231
uint32_t GetResumeID() const
Definition: Process.h:1339
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
ProcessRunLock::ProcessRunLocker StopLocker
Definition: Process.h:394
virtual Status DoHalt(bool &caused_stop)
Halts a running process.
Definition: Process.h:1084
void RestoreProcessEvents()
Restores the process event broadcasting to its normal state.
Definition: Process.cpp:1045
const char * GetRestartedReasonAtIndex(size_t idx)
Definition: Process.h:436
virtual Status DoAttachToProcessWithID(lldb::pid_t pid, const ProcessAttachInfo &attach_info)
Attach to an existing process using a process ID.
Definition: Process.h:935
"lldb/Expression/UtilityFunction.h" Encapsulates a bit of source code that provides a function that i...
"lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of BreakpointSite shared pointers...
std::unique_ptr< UtilityFunction > m_dlopen_utility_func_up
Definition: Process.h:2735
static void OptionValueChangedCallback(void *baton, OptionValue *option_value)
Definition: Process.cpp:190
const ProcessModID & operator=(const ProcessModID &rhs)
Definition: Process.h:244
void SetRunningUtilityFunction(bool on)
Definition: Process.h:308
void SetContinueOnceAttached(bool b)
Definition: Process.h:134
Communication m_stdio_communication
Definition: Process.h:2690
A section + offset based address range class.
Definition: AddressRange.h:32
bool ProcessIOHandlerExists() const
Definition: Process.h:2810
lldb::ListenerSP GetHijackListener() const
Definition: Process.h:165
virtual lldb_private::StructuredData::ObjectSP GetSharedCacheInfo()
Definition: Process.h:1295
RAII guard that should be aquired when an utility function is called within a given process...
Definition: Process.h:2843
ConstString & GetBroadcasterClass() const override
Definition: Process.h:400
virtual Status DoAttachToProcessWithName(const char *process_name, const ProcessAttachInfo &attach_info)
Attach to an existing process using a partial process name.
Definition: Process.h:958
Broadcaster m_private_state_control_broadcaster
Definition: Process.h:2634
ThreadList::ThreadIterable Threads()
Definition: Process.h:2053
const char * GetProcessPluginName() const
lldb::DynamicLoaderUP m_dyld_up
Definition: Process.h:2677
virtual Status WillAttachToProcessWithID(lldb::pid_t pid)
Called before attaching to a process.
Definition: Process.h:890
An error handling class.
Definition: Status.h:44
void * thread_result_t
Definition: lldb-types.h:62
lldb::ListenerSP GetListener() const
Definition: Process.h:176
uint32_t GetLastUserExpressionResumeID() const
Definition: Process.h:276
A plug-in interface definition class for system runtimes.
Definition: SystemRuntime.h:42
virtual Status DoConnectRemote(Stream *strm, llvm::StringRef remote_url)
Attach to a remote system via a URL.
Definition: Process.h:915
virtual Status DisableBreakpointSite(BreakpointSite *bp_site)
Definition: Process.h:1993
lldb::SystemRuntimeUP m_system_runtime_up
Definition: Process.h:2685