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