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