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