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