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
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);
104 bool GetDetachKeepsStopped() const;
105 void SetDetachKeepsStopped(bool keep_stopped);
106 bool GetWarningsOptimization() const;
108 bool GetStopOnExec() const;
109 std::chrono::seconds GetUtilityExpressionTimeout() const;
110 std::chrono::seconds GetInterruptTimeout() const;
111 bool GetOSPluginReportsAllThreads() const;
112 void SetOSPluginReportsAllThreads(bool does_report);
113 bool GetSteppingRunsAllThreads() const;
116 bool TrackMemoryCacheChanges() const;
117
118protected:
119 Process *m_process; // Can be nullptr for global ProcessProperties
120 std::unique_ptr<ProcessExperimentalProperties> m_experimental_properties_up;
121};
122
123// ProcessAttachInfo
124//
125// Describes any information that is required to attach to a process.
126
128public:
129 ProcessAttachInfo() = default;
130
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
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; }
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
315 void Dump(Stream &stream) const {
316 stream.Format("ProcessModID:\n"
317 " m_stop_id: {0}\n m_last_natural_stop_id: {1}\n"
318 " m_resume_id: {2}\n m_memory_id: {3}\n"
319 " m_last_user_expression_resume: {4}\n"
320 " m_running_user_expression: {5}\n"
321 " m_running_utility_function: {6}\n",
325 }
326
327private:
328 uint32_t m_stop_id = 0;
330 uint32_t m_resume_id = 0;
331 uint32_t m_memory_id = 0;
336};
337
338inline bool operator==(const ProcessModID &lhs, const ProcessModID &rhs) {
339 if (lhs.StopIDEqual(rhs) && lhs.MemoryIDEqual(rhs))
340 return true;
341 else
342 return false;
343}
344
345inline bool operator!=(const ProcessModID &lhs, const ProcessModID &rhs) {
346 return (!lhs.StopIDEqual(rhs) || !lhs.MemoryIDEqual(rhs));
347}
348
349/// \class Process Process.h "lldb/Target/Process.h"
350/// A plug-in interface definition class for debugging a process.
351class Process : public std::enable_shared_from_this<Process>,
352 public ProcessProperties,
353 public Broadcaster,
355 public PluginInterface {
356 friend class FunctionCaller; // For WaitForStateChangeEventsPrivate
357 friend class Debugger; // For PopProcessIOHandler and ProcessIOHandlerIsActive
358 friend class DynamicLoader; // For LoadOperatingSystemPlugin
359 friend class ProcessEventData;
360 friend class StopInfo;
361 friend class Target;
362 friend class ThreadList;
363
364public:
365 /// Broadcaster event bits definitions.
366 enum {
373 };
374 // This is all the event bits the public process broadcaster broadcasts.
375 // The process shadow listener signs up for all these bits...
376 static constexpr int g_all_event_bits =
380
381 enum {
385 };
386
388 // We use a read/write lock to allow on or more clients to access the process
389 // state while the process is stopped (reader). We lock the write lock to
390 // control access to the process while it is running (readers, or clients
391 // that want the process stopped can block waiting for the process to stop,
392 // or just try to lock it to see if they can immediately access the stopped
393 // process. If the try read lock fails, then the process is running.
395
396 // These two functions fill out the Broadcaster interface:
397
398 static llvm::StringRef GetStaticBroadcasterClass();
399
400 static constexpr llvm::StringRef AttachSynchronousHijackListenerName =
401 "lldb.internal.Process.AttachSynchronous.hijack";
402 static constexpr llvm::StringRef LaunchSynchronousHijackListenerName =
403 "lldb.internal.Process.LaunchSynchronous.hijack";
404 static constexpr llvm::StringRef ResumeSynchronousHijackListenerName =
405 "lldb.internal.Process.ResumeSynchronous.hijack";
406
407 llvm::StringRef GetBroadcasterClass() const override {
409 }
410
411/// A notification structure that can be used by clients to listen
412/// for changes in a process's lifetime.
413///
414/// \see RegisterNotificationCallbacks (const Notifications&) @see
415/// UnregisterNotificationCallbacks (const Notifications&)
416 typedef struct {
417 void *baton;
418 void (*initialize)(void *baton, Process *process);
419 void (*process_state_changed)(void *baton, Process *process,
420 lldb::StateType state);
422
424 friend class Process;
425
426 public:
428 ProcessEventData(const lldb::ProcessSP &process, lldb::StateType state);
429
431
432 static llvm::StringRef GetFlavorString();
433
434 llvm::StringRef GetFlavor() const override;
435
436 lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
437
438 lldb::StateType GetState() const { return m_state; }
439 bool GetRestarted() const { return m_restarted; }
440
441 size_t GetNumRestartedReasons() { return m_restarted_reasons.size(); }
442
443 const char *GetRestartedReasonAtIndex(size_t idx) {
444 return ((idx < m_restarted_reasons.size())
445 ? m_restarted_reasons[idx].c_str()
446 : nullptr);
447 }
448
449 bool GetInterrupted() const { return m_interrupted; }
450
451 void Dump(Stream *s) const override;
452
453 virtual bool ShouldStop(Event *event_ptr, bool &found_valid_stopinfo);
454
455 void DoOnRemoval(Event *event_ptr) override;
456
457 static const Process::ProcessEventData *
458 GetEventDataFromEvent(const Event *event_ptr);
459
460 static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr);
461
462 static lldb::StateType GetStateFromEvent(const Event *event_ptr);
463
464 static bool GetRestartedFromEvent(const Event *event_ptr);
465
466 static size_t GetNumRestartedReasons(const Event *event_ptr);
467
468 static const char *GetRestartedReasonAtIndex(const Event *event_ptr,
469 size_t idx);
470
471 static void AddRestartedReason(Event *event_ptr, const char *reason);
472
473 static void SetRestartedInEvent(Event *event_ptr, bool new_value);
474
475 static bool GetInterruptedFromEvent(const Event *event_ptr);
476
477 static void SetInterruptedInEvent(Event *event_ptr, bool new_value);
478
479 static bool SetUpdateStateOnRemoval(Event *event_ptr);
480
481 private:
482 bool ForwardEventToPendingListeners(Event *event_ptr) override;
483
485
486 void SetRestarted(bool new_value) { m_restarted = new_value; }
487
488 void SetInterrupted(bool new_value) { m_interrupted = new_value; }
489
490 void AddRestartedReason(const char *reason) {
491 m_restarted_reasons.push_back(reason);
492 }
493
496 std::vector<std::string> m_restarted_reasons;
497 bool m_restarted = false; // For "eStateStopped" events, this is true if the
498 // target was automatically restarted.
500 bool m_interrupted = false;
501
504 };
505
506 /// Destructor.
507 ///
508 /// The destructor is virtual since this class is designed to be inherited
509 /// from by the plug-in instance.
510 ~Process() override;
511
512 static void SettingsInitialize();
513
514 static void SettingsTerminate();
515
517
518 /// Find a Process plug-in that can debug \a module using the currently
519 /// selected architecture.
520 ///
521 /// Scans all loaded plug-in interfaces that implement versions of the
522 /// Process plug-in interface and returns the first instance that can debug
523 /// the file.
524 ///
525 /// \see Process::CanDebug ()
527 llvm::StringRef plugin_name,
528 lldb::ListenerSP listener_sp,
529 const FileSpec *crash_file_path,
530 bool can_connect);
531
533
534 uint32_t GetAddressByteSize() const;
535
536 /// Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is
537 /// no known pid.
538 lldb::pid_t GetID() const { return m_pid; }
539
540 /// Sets the stored pid.
541 ///
542 /// This does not change the pid of underlying process.
543 void SetID(lldb::pid_t new_pid) { m_pid = new_pid; }
544
545 uint32_t GetUniqueID() const { return m_process_unique_id; }
546
547 /// Check if a plug-in instance can debug the file in \a module.
548 ///
549 /// Each plug-in is given a chance to say whether it can debug the file in
550 /// \a module. If the Process plug-in instance can debug a file on the
551 /// current system, it should return \b true.
552 ///
553 /// \return
554 /// Returns \b true if this Process plug-in instance can
555 /// debug the executable, \b false otherwise.
556 virtual bool CanDebug(lldb::TargetSP target,
557 bool plugin_specified_by_name) = 0;
558
559 /// This object is about to be destroyed, do any necessary cleanup.
560 ///
561 /// Subclasses that override this method should always call this superclass
562 /// method.
563 /// If you are running Finalize in your Process subclass Destructor, pass
564 /// \b true. If we are in the destructor, shared_from_this will no longer
565 /// work, so we have to avoid doing anything that might trigger that.
566 virtual void Finalize(bool destructing);
567
568 /// Return whether this object is valid (i.e. has not been finalized.)
569 ///
570 /// \return
571 /// Returns \b true if this Process has not been finalized
572 /// and \b false otherwise.
573 bool IsValid() const { return !m_finalizing; }
574
575 /// Return a multi-word command object that can be used to expose plug-in
576 /// specific commands.
577 ///
578 /// This object will be used to resolve plug-in commands and can be
579 /// triggered by a call to:
580 ///
581 /// (lldb) process command <args>
582 ///
583 /// \return
584 /// A CommandObject which can be one of the concrete subclasses
585 /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
586 /// or CommandObjectMultiword.
587 virtual CommandObject *GetPluginCommandObject() { return nullptr; }
588
589 /// The underlying plugin might store the low-level communication history for
590 /// this session. Dump it into the provided stream.
591 virtual void DumpPluginHistory(Stream &s) {}
592
593 /// Launch a new process.
594 ///
595 /// Launch a new process by spawning a new process using the target object's
596 /// executable module's file as the file to launch.
597 ///
598 /// This function is not meant to be overridden by Process subclasses. It
599 /// will first call Process::WillLaunch (Module *) and if that returns \b
600 /// true, Process::DoLaunch (Module*, char const *[],char const *[],const
601 /// char *,const char *, const char *) will be called to actually do the
602 /// launching. If DoLaunch returns \b true, then Process::DidLaunch() will
603 /// be called.
604 ///
605 /// \param[in] launch_info
606 /// Details regarding the environment, STDIN/STDOUT/STDERR
607 /// redirection, working path, etc. related to the requested launch.
608 ///
609 /// \return
610 /// An error object. Call GetID() to get the process ID if
611 /// the error object is success.
612 virtual Status Launch(ProcessLaunchInfo &launch_info);
613
614 virtual Status LoadCore();
615
616 virtual Status DoLoadCore() {
618 "error: {0} does not support loading core files.", GetPluginName());
619 }
620
621 /// The "ShadowListener" for a process is just an ordinary Listener that
622 /// listens for all the Process event bits. It's convenient because you can
623 /// specify it in the LaunchInfo or AttachInfo, so it will get events from
624 /// the very start of the process.
625 void SetShadowListener(lldb::ListenerSP shadow_listener_sp) {
626 if (shadow_listener_sp)
627 AddListener(shadow_listener_sp, g_all_event_bits);
628 }
629
630 // FUTURE WORK: GetLoadImageUtilityFunction are the first use we've
631 // had of having other plugins cache data in the Process. This is handy for
632 // long-living plugins - like the Platform - which manage interactions whose
633 // lifetime is governed by the Process lifetime. If we find we need to do
634 // this more often, we should construct a general solution to the problem.
635 // The consensus suggestion was that we have a token based registry in the
636 // Process. Some undecided questions are (1) who manages the tokens. It's
637 // probably best that you add the element and get back a token that
638 // represents it. That will avoid collisions. But there may be some utility
639 // in the registerer controlling the token? (2) whether the thing added
640 // should be simply owned by Process, and just go away when it does (3)
641 // whether the registree should be notified of the Process' demise.
642 //
643 // We are postponing designing this till we have at least a second use case.
644 /// Get the cached UtilityFunction that assists in loading binary images
645 /// into the process.
646 ///
647 /// \param[in] platform
648 /// The platform fetching the UtilityFunction.
649 /// \param[in] factory
650 /// A function that will be called only once per-process in a
651 /// thread-safe way to create the UtilityFunction if it has not
652 /// been initialized yet.
653 ///
654 /// \return
655 /// The cached utility function or null if the platform is not the
656 /// same as the target's platform.
658 Platform *platform,
659 llvm::function_ref<std::unique_ptr<UtilityFunction>()> factory);
660
661 /// Get the dynamic loader plug-in for this process.
662 ///
663 /// The default action is to let the DynamicLoader plug-ins check the main
664 /// executable and the DynamicLoader will select itself automatically.
665 /// Subclasses can override this if inspecting the executable is not
666 /// desired, or if Process subclasses can only use a specific DynamicLoader
667 /// plug-in.
669
671
672 // Returns AUXV structure found in many ELF-based environments.
673 //
674 // The default action is to return an empty data buffer.
675 //
676 // \return
677 // A data extractor containing the contents of the AUXV data.
678 virtual DataExtractor GetAuxvData();
679
680 /// Sometimes processes know how to retrieve and load shared libraries. This
681 /// is normally done by DynamicLoader plug-ins, but sometimes the connection
682 /// to the process allows retrieving this information. The dynamic loader
683 /// plug-ins can use this function if they can't determine the current
684 /// shared library load state.
685 ///
686 /// \return
687 /// A status object indicating if the operation was sucessful or not.
688 virtual llvm::Error LoadModules() {
689 return llvm::createStringError("Not implemented.");
690 }
691
692 /// Query remote GDBServer for a detailed loaded library list
693 /// \return
694 /// The list of modules currently loaded by the process, or an error.
695 virtual llvm::Expected<LoadedModuleInfoList> GetLoadedModuleList() {
696 return llvm::createStringError(llvm::inconvertibleErrorCode(),
697 "Not implemented");
698 }
699
700 /// Save core dump into the specified file.
701 ///
702 /// \param[in] outfile
703 /// Path to store core dump in.
704 ///
705 /// \return
706 /// true if saved successfully, false if saving the core dump
707 /// is not supported by the plugin, error otherwise.
708 virtual llvm::Expected<bool> SaveCore(llvm::StringRef outfile);
709
710 /// Helper function for Process::SaveCore(...) that calculates the address
711 /// ranges that should be saved. This allows all core file plug-ins to save
712 /// consistent memory ranges given a \a core_style.
714 CoreFileMemoryRanges &ranges);
715
716 /// Helper function for Process::SaveCore(...) that calculates the thread list
717 /// based upon options set within a given \a core_options object.
718 /// \note If there is no thread list defined, all threads will be saved.
719 std::vector<lldb::ThreadSP>
720 CalculateCoreFileThreadList(const SaveCoreOptions &core_options);
721
722protected:
723 virtual JITLoaderList &GetJITLoaders();
724
725public:
726 /// Get the system architecture for this process.
727 virtual ArchSpec GetSystemArchitecture() { return {}; }
728
729 /// Get the system runtime plug-in for this process.
730 ///
731 /// \return
732 /// Returns a pointer to the SystemRuntime plugin for this Process
733 /// if one is available. Else returns nullptr.
735
736 /// Attach to an existing process using the process attach info.
737 ///
738 /// This function is not meant to be overridden by Process subclasses. It
739 /// will first call WillAttach (lldb::pid_t) or WillAttach (const char *),
740 /// and if that returns \b true, DoAttach (lldb::pid_t) or DoAttach (const
741 /// char *) will be called to actually do the attach. If DoAttach returns \b
742 /// true, then Process::DidAttach() will be called.
743 ///
744 /// \param[in] attach_info
745 /// The process attach info.
746 ///
747 /// \return
748 /// Returns \a pid if attaching was successful, or
749 /// LLDB_INVALID_PROCESS_ID if attaching fails.
750 virtual Status Attach(ProcessAttachInfo &attach_info);
751
752 /// Attach to a remote system via a URL
753 ///
754 /// \param[in] remote_url
755 /// The URL format that we are connecting to.
756 ///
757 /// \return
758 /// Returns an error object.
759 virtual Status ConnectRemote(llvm::StringRef remote_url);
760
761 bool GetShouldDetach() const { return m_should_detach; }
762
763 void SetShouldDetach(bool b) { m_should_detach = b; }
764
765 /// Get the image vector for the current process.
766 ///
767 /// \return
768 /// The constant reference to the member m_image_tokens.
769 const std::vector<lldb::addr_t>& GetImageTokens() { return m_image_tokens; }
770
771 /// Get the image information address for the current process.
772 ///
773 /// Some runtimes have system functions that can help dynamic loaders locate
774 /// the dynamic loader information needed to observe shared libraries being
775 /// loaded or unloaded. This function is in the Process interface (as
776 /// opposed to the DynamicLoader interface) to ensure that remote debugging
777 /// can take advantage of this functionality.
778 ///
779 /// \return
780 /// The address of the dynamic loader information, or
781 /// LLDB_INVALID_ADDRESS if this is not supported by this
782 /// interface.
784
785 /// Called when the process is about to broadcast a public stop.
786 ///
787 /// There are public and private stops. Private stops are when the process
788 /// is doing things like stepping and the client doesn't need to know about
789 /// starts and stop that implement a thread plan. Single stepping over a
790 /// source line in code might end up being implemented by one or more
791 /// process starts and stops. Public stops are when clients will be notified
792 /// that the process is stopped. These events typically trigger UI updates
793 /// (thread stack frames to be displayed, variables to be displayed, and
794 /// more). This function can be overriden and allows process subclasses to
795 /// do something before the eBroadcastBitStateChanged event is sent to
796 /// public clients.
797 virtual void WillPublicStop() {}
798
799/// Register for process and thread notifications.
800///
801/// Clients can register notification callbacks by filling out a
802/// Process::Notifications structure and calling this function.
803///
804/// \param[in] callbacks
805/// A structure that contains the notification baton and
806/// callback functions.
807///
808/// \see Process::Notifications
810
811/// Unregister for process and thread notifications.
812///
813/// Clients can unregister notification callbacks by passing a copy of the
814/// original baton and callbacks in \a callbacks.
815///
816/// \param[in] callbacks
817/// A structure that contains the notification baton and
818/// callback functions.
819///
820/// \return
821/// Returns \b true if the notification callbacks were
822/// successfully removed from the process, \b false otherwise.
823///
824/// \see Process::Notifications
826
827 //==================================================================
828 // Built in Process Control functions
829 //==================================================================
830 /// Resumes all of a process's threads as configured using the Thread run
831 /// control functions.
832 ///
833 /// Threads for a process should be updated with one of the run control
834 /// actions (resume, step, or suspend) that they should take when the
835 /// process is resumed. If no run control action is given to a thread it
836 /// will be resumed by default.
837 ///
838 /// This function is not meant to be overridden by Process subclasses. This
839 /// function will take care of disabling any breakpoints that threads may be
840 /// stopped at, single stepping, and re-enabling breakpoints, and enabling
841 /// the basic flow control that the plug-in instances need not worry about.
842 ///
843 /// N.B. This function also sets the Write side of the Run Lock, which is
844 /// unset when the corresponding stop event is pulled off the Public Event
845 /// Queue. If you need to resume the process without setting the Run Lock,
846 /// use PrivateResume (though you should only do that from inside the
847 /// Process class.
848 ///
849 /// \return
850 /// Returns an error object.
851 ///
852 /// \see Thread:Resume()
853 /// \see Thread:Step()
854 /// \see Thread:Suspend()
855 Status Resume();
856
857 /// Resume a process, and wait for it to stop.
859
860 /// Halts a running process.
861 ///
862 /// This function is not meant to be overridden by Process subclasses. If
863 /// the process is successfully halted, a eStateStopped process event with
864 /// GetInterrupted will be broadcast. If false, we will halt the process
865 /// with no events generated by the halt.
866 ///
867 /// \param[in] clear_thread_plans
868 /// If true, when the process stops, clear all thread plans.
869 ///
870 /// \param[in] use_run_lock
871 /// Whether to release the run lock after the stop.
872 ///
873 /// \return
874 /// Returns an error object. If the error is empty, the process is
875 /// halted.
876 /// otherwise the halt has failed.
877 Status Halt(bool clear_thread_plans = false, bool use_run_lock = true);
878
879 /// Detaches from a running or stopped process.
880 ///
881 /// This function is not meant to be overridden by Process subclasses.
882 ///
883 /// \param[in] keep_stopped
884 /// If true, don't resume the process on detach.
885 ///
886 /// \return
887 /// Returns an error object.
888 Status Detach(bool keep_stopped);
889
890 /// Kills the process and shuts down all threads that were spawned to track
891 /// and monitor the process.
892 ///
893 /// This function is not meant to be overridden by Process subclasses.
894 ///
895 /// \param[in] force_kill
896 /// Whether lldb should force a kill (instead of a detach) from
897 /// the inferior process. Normally if lldb launched a binary and
898 /// Destroy is called, lldb kills it. If lldb attached to a
899 /// running process and Destroy is called, lldb detaches. If
900 /// this behavior needs to be over-ridden, this is the bool that
901 /// can be used.
902 ///
903 /// \return
904 /// Returns an error object.
905 Status Destroy(bool force_kill);
906
907 /// Sends a process a UNIX signal \a signal.
908 ///
909 /// This function is not meant to be overridden by Process subclasses.
910 ///
911 /// \return
912 /// Returns an error object.
913 Status Signal(int signal);
914
915 void SetUnixSignals(lldb::UnixSignalsSP &&signals_sp);
916
918
919 //==================================================================
920 // Plug-in Process Control Overrides
921 //==================================================================
922
923 /// Called before attaching to a process.
924 ///
925 /// \return
926 /// Returns an error object.
928
929 /// Called before attaching to a process.
930 ///
931 /// Allow Process plug-ins to execute some code before attaching a process.
932 ///
933 /// \return
934 /// Returns an error object.
936 return Status();
937 }
938
939 /// Called before attaching to a process.
940 ///
941 /// \return
942 /// Returns an error object.
943 Status WillAttachToProcessWithName(const char *process_name,
944 bool wait_for_launch);
945
946 /// Called before attaching to a process.
947 ///
948 /// Allow Process plug-ins to execute some code before attaching a process.
949 ///
950 /// \return
951 /// Returns an error object.
952 virtual Status DoWillAttachToProcessWithName(const char *process_name,
953 bool wait_for_launch) {
954 return Status();
955 }
956
957 /// Attach to a remote system via a URL
958 ///
959 /// \param[in] remote_url
960 /// The URL format that we are connecting to.
961 ///
962 /// \return
963 /// Returns an error object.
964 virtual Status DoConnectRemote(llvm::StringRef remote_url) {
965 return Status::FromErrorString("remote connections are not supported");
966 }
967
968 /// Attach to an existing process using a process ID.
969 ///
970 /// \param[in] pid
971 /// The process ID that we should attempt to attach to.
972 ///
973 /// \param[in] attach_info
974 /// Information on how to do the attach. For example, GetUserID()
975 /// will return the uid to attach as.
976 ///
977 /// \return
978 /// Returns a successful Status attaching was successful, or
979 /// an appropriate (possibly platform-specific) error code if
980 /// attaching fails.
981 /// hanming : need flag
983 const ProcessAttachInfo &attach_info) {
985 "error: {0} does not support attaching to a process by pid",
986 GetPluginName());
987 }
988
989 /// Attach to an existing process using a partial process name.
990 ///
991 /// \param[in] process_name
992 /// The name of the process to attach to.
993 ///
994 /// \param[in] attach_info
995 /// Information on how to do the attach. For example, GetUserID()
996 /// will return the uid to attach as.
997 ///
998 /// \return
999 /// Returns a successful Status attaching was successful, or
1000 /// an appropriate (possibly platform-specific) error code if
1001 /// attaching fails.
1002 virtual Status
1003 DoAttachToProcessWithName(const char *process_name,
1004 const ProcessAttachInfo &attach_info) {
1005 return Status::FromErrorString("attach by name is not supported");
1006 }
1007
1008 /// Called after attaching a process.
1009 ///
1010 /// \param[in] process_arch
1011 /// If you can figure out the process architecture after attach, fill it
1012 /// in here.
1013 ///
1014 /// Allow Process plug-ins to execute some code after attaching to a
1015 /// process.
1016 virtual void DidAttach(ArchSpec &process_arch) { process_arch.Clear(); }
1017
1018 /// Called after a process re-execs itself.
1019 ///
1020 /// Allow Process plug-ins to execute some code after a process has exec'ed
1021 /// itself. Subclasses typically should override DoDidExec() as the
1022 /// lldb_private::Process class needs to remove its dynamic loader, runtime,
1023 /// ABI and other plug-ins, as well as unload all shared libraries.
1024 virtual void DidExec();
1025
1026 /// Subclasses of Process should implement this function if they need to do
1027 /// anything after a process exec's itself.
1028 virtual void DoDidExec() {}
1029
1030 /// Called after a reported fork.
1031 virtual void DidFork(lldb::pid_t child_pid, lldb::tid_t child_tid) {}
1032
1033 /// Called after a reported vfork.
1034 virtual void DidVFork(lldb::pid_t child_pid, lldb::tid_t child_tid) {}
1035
1036 /// Called after reported vfork completion.
1037 virtual void DidVForkDone() {}
1038
1039 /// Called before launching to a process.
1040 /// \return
1041 /// Returns an error object.
1042 Status WillLaunch(Module *module);
1043
1044 /// Called before launching to a process.
1045 ///
1046 /// Allow Process plug-ins to execute some code before launching a process.
1047 ///
1048 /// \return
1049 /// Returns an error object.
1050 virtual Status DoWillLaunch(Module *module) { return Status(); }
1051
1052 /// Launch a new process.
1053 ///
1054 /// Launch a new process by spawning a new process using \a exe_module's
1055 /// file as the file to launch. Launch details are provided in \a
1056 /// launch_info.
1057 ///
1058 /// \param[in] exe_module
1059 /// The module from which to extract the file specification and
1060 /// launch.
1061 ///
1062 /// \param[in] launch_info
1063 /// Details (e.g. arguments, stdio redirection, etc.) for the
1064 /// requested launch.
1065 ///
1066 /// \return
1067 /// An Status instance indicating success or failure of the
1068 /// operation.
1069 virtual Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) {
1071 "error: {0} does not support launching processes", GetPluginName());
1072 }
1073
1074 /// Called after launching a process.
1075 ///
1076 /// Allow Process plug-ins to execute some code after launching a process.
1077 virtual void DidLaunch() {}
1078
1079 /// Called before resuming to a process.
1080 ///
1081 /// Allow Process plug-ins to execute some code before resuming a process.
1082 ///
1083 /// \return
1084 /// Returns an error object.
1085 virtual Status WillResume() { return Status(); }
1086
1087 /// Reports whether this process supports reverse execution.
1088 ///
1089 /// \return
1090 /// Returns true if the process supports reverse execution (at least
1091 /// under some circumstances).
1092 virtual bool SupportsReverseDirection() { return false; }
1093
1094 /// Resumes all of a process's threads as configured using the Thread run
1095 /// control functions.
1096 ///
1097 /// Threads for a process should be updated with one of the run control
1098 /// actions (resume, step, or suspend) that they should take when the
1099 /// process is resumed. If no run control action is given to a thread it
1100 /// will be resumed by default.
1101 ///
1102 /// \return
1103 /// Returns \b true if the process successfully resumes using
1104 /// the thread run control actions, \b false otherwise.
1105 ///
1106 /// \see Thread:Resume()
1107 /// \see Thread:Step()
1108 /// \see Thread:Suspend()
1110 if (direction == lldb::RunDirection::eRunForward)
1112 "{0} does not support resuming processes", GetPluginName());
1114 "{0} does not support reverse execution of processes", GetPluginName());
1115 }
1116
1117 /// Called after resuming a process.
1118 ///
1119 /// Allow Process plug-ins to execute some code after resuming a process.
1120 virtual void DidResume() {}
1121
1122 /// Called before halting to a process.
1123 ///
1124 /// Allow Process plug-ins to execute some code before halting a process.
1125 ///
1126 /// \return
1127 /// Returns an error object.
1128 virtual Status WillHalt() { return Status(); }
1129
1130 /// Halts a running process.
1131 ///
1132 /// DoHalt must produce one and only one stop StateChanged event if it
1133 /// actually stops the process. If the stop happens through some natural
1134 /// event (for instance a SIGSTOP), then forwarding that event will do.
1135 /// Otherwise, you must generate the event manually. This function is called
1136 /// from the context of the private state thread.
1137 ///
1138 /// \param[out] caused_stop
1139 /// If true, then this Halt caused the stop, otherwise, the
1140 /// process was already stopped.
1141 ///
1142 /// \return
1143 /// Returns \b true if the process successfully halts, \b false
1144 /// otherwise.
1145 virtual Status DoHalt(bool &caused_stop) {
1147 "error: {0} does not support halting processes", GetPluginName());
1148 }
1149
1150 /// Called after halting a process.
1151 ///
1152 /// Allow Process plug-ins to execute some code after halting a process.
1153 virtual void DidHalt() {}
1154
1155 /// Called before detaching from a process.
1156 ///
1157 /// Allow Process plug-ins to execute some code before detaching from a
1158 /// process.
1159 ///
1160 /// \return
1161 /// Returns an error object.
1162 virtual Status WillDetach() { return Status(); }
1163
1164 /// Detaches from a running or stopped process.
1165 ///
1166 /// \return
1167 /// Returns \b true if the process successfully detaches, \b
1168 /// false otherwise.
1169 virtual Status DoDetach(bool keep_stopped) {
1171 "error: {0} does not support detaching from processes",
1172 GetPluginName());
1173 }
1174
1175 /// Called after detaching from a process.
1176 ///
1177 /// Allow Process plug-ins to execute some code after detaching from a
1178 /// process.
1179 virtual void DidDetach() {}
1180
1181 virtual bool DetachRequiresHalt() { return false; }
1182
1183 /// Called before sending a signal to a process.
1184 ///
1185 /// Allow Process plug-ins to execute some code before sending a signal to a
1186 /// process.
1187 ///
1188 /// \return
1189 /// Returns no error if it is safe to proceed with a call to
1190 /// Process::DoSignal(int), otherwise an error describing what
1191 /// prevents the signal from being sent.
1192 virtual Status WillSignal() { return Status(); }
1193
1194 /// Sends a process a UNIX signal \a signal.
1195 ///
1196 /// \return
1197 /// Returns an error object.
1198 virtual Status DoSignal(int signal) {
1200 "error: {0} does not support sending signals to processes",
1201 GetPluginName());
1202 }
1203
1204 virtual Status WillDestroy() { return Status(); }
1205
1206 virtual Status DoDestroy() = 0;
1207
1208 virtual void DidDestroy() {}
1209
1210 virtual bool DestroyRequiresHalt() { return true; }
1211
1212 /// Called after sending a signal to a process.
1213 ///
1214 /// Allow Process plug-ins to execute some code after sending a signal to a
1215 /// process.
1216 virtual void DidSignal() {}
1217
1218 /// Currently called as part of ShouldStop.
1219 /// FIXME: Should really happen when the target stops before the
1220 /// event is taken from the queue...
1221 ///
1222 /// This callback is called as the event
1223 /// is about to be queued up to allow Process plug-ins to execute some code
1224 /// prior to clients being notified that a process was stopped. Common
1225 /// operations include updating the thread list, invalidating any thread
1226 /// state (registers, stack, etc) prior to letting the notification go out.
1227 ///
1228 virtual void RefreshStateAfterStop() = 0;
1229
1230 /// Sometimes the connection to a process can detect the host OS version
1231 /// that the process is running on. The current platform should be checked
1232 /// first in case the platform is connected, but clients can fall back onto
1233 /// this function if the platform fails to identify the host OS version. The
1234 /// platform should be checked first in case you are running a simulator
1235 /// platform that might itself be running natively, but have different
1236 /// heuristics for figuring out which OS is emulating.
1237 ///
1238 /// \return
1239 /// Returns the version tuple of the host OS. In case of failure an empty
1240 /// VersionTuple is returner.
1241 virtual llvm::VersionTuple GetHostOSVersion() { return llvm::VersionTuple(); }
1242
1243 /// \return the macCatalyst version of the host OS.
1244 virtual llvm::VersionTuple GetHostMacCatalystVersion() { return {}; }
1245
1246 /// Get the target object pointer for this module.
1247 ///
1248 /// \return
1249 /// A Target object pointer to the target that owns this
1250 /// module.
1251 Target &GetTarget() { return *m_target_wp.lock(); }
1252
1253 /// Get the const target object pointer for this module.
1254 ///
1255 /// \return
1256 /// A const Target object pointer to the target that owns this
1257 /// module.
1258 const Target &GetTarget() const { return *m_target_wp.lock(); }
1259
1260 /// Flush all data in the process.
1261 ///
1262 /// Flush the memory caches, all threads, and any other cached data in the
1263 /// process.
1264 ///
1265 /// This function can be called after a world changing event like adding a
1266 /// new symbol file, or after the process makes a large context switch (from
1267 /// boot ROM to booted into an OS).
1268 void Flush();
1269
1270 /// Get accessor for the current process state.
1271 ///
1272 /// \return
1273 /// The current state of the process.
1274 ///
1275 /// \see lldb::StateType
1277
1279 RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp,
1280 const EvaluateExpressionOptions &options,
1281 DiagnosticManager &diagnostic_manager);
1282
1283 void GetStatus(Stream &ostrm);
1284
1285 size_t GetThreadStatus(Stream &ostrm, bool only_threads_with_stop_reason,
1286 uint32_t start_frame, uint32_t num_frames,
1287 uint32_t num_frames_with_source, bool stop_format);
1288
1289 /// Send an async interrupt request.
1290 ///
1291 /// If \a thread is specified the async interrupt stop will be attributed to
1292 /// the specified thread.
1293 ///
1294 /// \param[in] thread
1295 /// The thread the async interrupt will be attributed to.
1296 void SendAsyncInterrupt(Thread *thread = nullptr);
1297
1298 // Notify this process class that modules got loaded.
1299 //
1300 // If subclasses override this method, they must call this version before
1301 // doing anything in the subclass version of the function.
1302 virtual void ModulesDidLoad(ModuleList &module_list);
1303
1304 /// Retrieve the list of shared libraries that are loaded for this process
1305 /// This method is used on pre-macOS 10.12, pre-iOS 10, pre-tvOS 10, pre-
1306 /// watchOS 3 systems. The following two methods are for newer versions of
1307 /// those OSes.
1308 ///
1309 /// For certain platforms, the time it takes for the DynamicLoader plugin to
1310 /// read all of the shared libraries out of memory over a slow communication
1311 /// channel may be too long. In that instance, the gdb-remote stub may be
1312 /// able to retrieve the necessary information about the solibs out of
1313 /// memory and return a concise summary sufficient for the DynamicLoader
1314 /// plugin.
1315 ///
1316 /// \param [in] image_list_address
1317 /// The address where the table of shared libraries is stored in memory,
1318 /// if that is appropriate for this platform. Else this may be
1319 /// passed as LLDB_INVALID_ADDRESS.
1320 ///
1321 /// \param [in] image_count
1322 /// The number of shared libraries that are present in this process, if
1323 /// that is appropriate for this platofrm Else this may be passed as
1324 /// LLDB_INVALID_ADDRESS.
1325 ///
1326 /// \return
1327 /// A StructuredDataSP object which, if non-empty, will contain the
1328 /// information the DynamicLoader needs to get the initial scan of
1329 /// solibs resolved.
1332 lldb::addr_t image_count) {
1333 return StructuredData::ObjectSP();
1334 }
1335
1336 /// Retrieve a StructuredData dictionary about all of the binaries
1337 /// loaded in the process at this time.
1338 /// A Darwin target specific behavior, only supported by debugserver,
1339 /// response will include load address, filepath, uuid, and may also
1340 /// include the fully parsed mach header and load commands.
1341 ///
1342 /// \param [in] information_level
1343 /// How much information about each binary should be returned;
1344 /// there may be performance reasons to retrieve a minimal set
1345 /// of information about all binaries, and then retrieve the
1346 /// full information for a subset of the whole group.
1347 ///
1348 /// \return
1349 /// A StructuredData object with the information that could be
1350 /// retrieved.
1355
1356 /// Retrieve a StructuredData dictionary about the binaries at
1357 /// the provided load addresses.
1358 /// A Darwin target specific behavior, only supported by debugserver,
1359 /// response will include load address, filepath, uuid, fully parsed
1360 /// mach header and load commands.
1361 ///
1362 /// \param [in] information_level
1363 /// How much information about each binary should be returned;
1364 /// there may be performance reasons to retrieve a minimal set
1365 /// of information about all binaries, and then retrieve the
1366 /// full information for a subset of the whole group.
1367 ///
1368 /// \param [in] load_addresses
1369 /// The virtual address of the start of binaries to fetch
1370 /// information.
1371 ///
1372 /// \return
1373 /// A StructuredData object with the information that could be
1374 /// retrieved..
1377 const std::vector<lldb::addr_t> &load_addresses) {
1378 return StructuredData::ObjectSP();
1379 }
1380
1381 // Get information about the library shared cache, if that exists
1382 //
1383 // On macOS 10.12, tvOS 10, iOS 10, watchOS 3 and newer, debugserver can
1384 // return information about the library shared cache (a set of standard
1385 // libraries that are loaded at the same location for all processes on a
1386 // system) in use.
1390
1391 // Get information about the launch state of the process, if possible.
1392 //
1393 // On Darwin systems, libdyld can report on process state, most importantly
1394 // the startup stages where the system library is not yet initialized.
1397 return {};
1398 }
1399
1400 /// Print a user-visible warning about a module being built with
1401 /// optimization
1402 ///
1403 /// Prints a async warning message to the user one time per Module where a
1404 /// function is found that was compiled with optimization, per Process.
1405 ///
1406 /// \param [in] sc
1407 /// A SymbolContext with eSymbolContextFunction and eSymbolContextModule
1408 /// pre-computed.
1410
1411 /// Print a user-visible warning about a function written in a
1412 /// language that this version of LLDB doesn't support.
1413 ///
1414 /// \see PrintWarningOptimization
1416
1417 virtual bool GetProcessInfo(ProcessInstanceInfo &info);
1418
1419 virtual lldb_private::UUID FindModuleUUID(const llvm::StringRef path);
1420
1421 /// Get the exit status for a process.
1422 ///
1423 /// \return
1424 /// The process's return code, or -1 if the current process
1425 /// state is not eStateExited.
1426 int GetExitStatus();
1427
1428 /// Get a textual description of what the process exited.
1429 ///
1430 /// \return
1431 /// The textual description of why the process exited, or nullptr
1432 /// if there is no description available.
1433 const char *GetExitDescription();
1434
1435 virtual void DidExit() {}
1436
1437 /// Get the current address mask in the Process
1438 ///
1439 /// This mask can used to set/clear non-address bits in an addr_t.
1440 ///
1441 /// \return
1442 /// The current address mask.
1443 /// Bits which are set to 1 are not used for addressing.
1444 /// An address mask of 0 means all bits are used for addressing.
1445 /// An address mask of LLDB_INVALID_ADDRESS_MASK (all 1's) means
1446 /// that no mask has been set.
1449
1450 /// The highmem masks are for targets where we may have different masks
1451 /// for low memory versus high memory addresses, and they will be left
1452 /// as LLDB_INVALID_ADDRESS_MASK normally, meaning the base masks
1453 /// should be applied to all addresses.
1456
1457 void SetCodeAddressMask(lldb::addr_t code_address_mask);
1458 void SetDataAddressMask(lldb::addr_t data_address_mask);
1459
1460 void SetHighmemCodeAddressMask(lldb::addr_t code_address_mask);
1461 void SetHighmemDataAddressMask(lldb::addr_t data_address_mask);
1462
1463 /// Some targets might use bits in a code address to indicate a mode switch,
1464 /// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
1465 /// plug-ins would strip those bits.
1466 /// Or use the high bits to authenticate a pointer value.
1469
1470 /// Use this method when you do not know, or do not care what kind of address
1471 /// you are fixing. On platforms where there would be a difference between the
1472 /// two types, it will pick the safest option.
1473 ///
1474 /// Its purpose is to signal that no specific choice was made and provide an
1475 /// alternative to randomly picking FixCode/FixData address. Which could break
1476 /// platforms where there is a difference (only Arm Thumb at this time).
1478
1479 /// Get the Modification ID of the process.
1480 ///
1481 /// \return
1482 /// The modification ID of the process.
1483 ProcessModID GetModID() const { return m_mod_id; }
1484
1485 const ProcessModID &GetModIDRef() const { return m_mod_id; }
1486
1487 uint32_t GetStopID() const { return m_mod_id.GetStopID(); }
1488
1489 uint32_t GetResumeID() const { return m_mod_id.GetResumeID(); }
1490
1492 return m_mod_id.GetLastUserExpressionResumeID();
1493 }
1494
1495 uint32_t GetLastNaturalStopID() const {
1496 return m_mod_id.GetLastNaturalStopID();
1497 }
1498
1499 lldb::EventSP GetStopEventForStopID(uint32_t stop_id) const {
1500 return m_mod_id.GetStopEventForStopID(stop_id);
1501 }
1502
1503 /// Set accessor for the process exit status (return code).
1504 ///
1505 /// Sometimes a child exits and the exit can be detected by global functions
1506 /// (signal handler for SIGCHLD for example). This accessor allows the exit
1507 /// status to be set from an external source.
1508 ///
1509 /// Setting this will cause a eStateExited event to be posted to the process
1510 /// event queue.
1511 ///
1512 /// \param[in] exit_status
1513 /// The value for the process's return code.
1514 ///
1515 /// \param[in] exit_string
1516 /// A StringRef containing the reason for exiting. May be empty.
1517 ///
1518 /// \return
1519 /// Returns \b false if the process was already in an exited state, \b
1520 /// true otherwise.
1521 virtual bool SetExitStatus(int exit_status, llvm::StringRef exit_string);
1522
1523 /// Check if a process is still alive.
1524 ///
1525 /// \return
1526 /// Returns \b true if the process is still valid, \b false
1527 /// otherwise.
1528 virtual bool IsAlive();
1529
1530 /// Check if a process is a live debug session, or a corefile/post-mortem.
1531 virtual bool IsLiveDebugSession() const { return true; };
1532
1533 /// Provide a way to retrieve the core dump file that is loaded for debugging.
1534 /// Only available if IsLiveDebugSession() returns false.
1535 ///
1536 /// \return
1537 /// File path to the core file.
1538 virtual FileSpec GetCoreFile() const { return {}; }
1539
1540 /// Before lldb detaches from a process, it warns the user that they are
1541 /// about to lose their debug session. In some cases, this warning doesn't
1542 /// need to be emitted -- for instance, with core file debugging where the
1543 /// user can reconstruct the "state" by simply re-running the debugger on
1544 /// the core file.
1545 ///
1546 /// \return
1547 /// Returns \b true if the user should be warned about detaching from
1548 /// this process.
1549 virtual bool WarnBeforeDetach() const { return true; }
1550
1551 /// Read of memory from a process.
1552 ///
1553 /// This function will read memory from the current process's address space
1554 /// and remove any traps that may have been inserted into the memory.
1555 ///
1556 /// This function is not meant to be overridden by Process subclasses, the
1557 /// subclasses should implement Process::DoReadMemory (lldb::addr_t, size_t,
1558 /// void *).
1559 ///
1560 /// \param[in] vm_addr
1561 /// A virtual load address that indicates where to start reading
1562 /// memory from.
1563 ///
1564 /// \param[out] buf
1565 /// A byte buffer that is at least \a size bytes long that
1566 /// will receive the memory bytes.
1567 ///
1568 /// \param[in] size
1569 /// The number of bytes to read.
1570 ///
1571 /// \param[out] error
1572 /// An error that indicates the success or failure of this
1573 /// operation. If error indicates success (error.Success()),
1574 /// then the value returned can be trusted, otherwise zero
1575 /// will be returned.
1576 ///
1577 /// \return
1578 /// The number of bytes that were actually read into \a buf. If
1579 /// the returned number is greater than zero, yet less than \a
1580 /// size, then this function will get called again with \a
1581 /// vm_addr, \a buf, and \a size updated appropriately. Zero is
1582 /// returned in the case of an error.
1583 virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
1584 Status &error);
1585
1586 /// Read from multiple memory ranges and write the results into buffer.
1587 /// This calls ReadMemoryFromInferior multiple times, once per range,
1588 /// bypassing the read cache. Process implementations that can perform this
1589 /// operation more efficiently should override this.
1590 ///
1591 /// \param[in] ranges
1592 /// A collection of ranges (base address + size) to read from.
1593 ///
1594 /// \param[out] buffer
1595 /// A buffer where the read memory will be written to. It must be at least
1596 /// as long as the sum of the sizes of each range.
1597 ///
1598 /// \return
1599 /// A vector of MutableArrayRef, where each MutableArrayRef is a slice of
1600 /// the input buffer into which the memory contents were copied. The size
1601 /// of the slice indicates how many bytes were read successfully. Partial
1602 /// reads are always performed from the start of the requested range,
1603 /// never from the middle or end.
1604 virtual llvm::SmallVector<llvm::MutableArrayRef<uint8_t>>
1605 ReadMemoryRanges(llvm::ArrayRef<Range<lldb::addr_t, size_t>> ranges,
1606 llvm::MutableArrayRef<uint8_t> buffer);
1607
1608 /// Read of memory from a process.
1609 ///
1610 /// This function has the same semantics of ReadMemory except that it
1611 /// bypasses caching.
1612 ///
1613 /// \param[in] vm_addr
1614 /// A virtual load address that indicates where to start reading
1615 /// memory from.
1616 ///
1617 /// \param[out] buf
1618 /// A byte buffer that is at least \a size bytes long that
1619 /// will receive the memory bytes.
1620 ///
1621 /// \param[in] size
1622 /// The number of bytes to read.
1623 ///
1624 /// \param[out] error
1625 /// An error that indicates the success or failure of this
1626 /// operation. If error indicates success (error.Success()),
1627 /// then the value returned can be trusted, otherwise zero
1628 /// will be returned.
1629 ///
1630 /// \return
1631 /// The number of bytes that were actually read into \a buf. If
1632 /// the returned number is greater than zero, yet less than \a
1633 /// size, then this function will get called again with \a
1634 /// vm_addr, \a buf, and \a size updated appropriately. Zero is
1635 /// returned in the case of an error.
1636 size_t ReadMemoryFromInferior(lldb::addr_t vm_addr, void *buf, size_t size,
1637 Status &error);
1638
1639 // Callback definition for read Memory in chunks
1640 //
1641 // Status, the status returned from ReadMemoryFromInferior
1642 // addr_t, the bytes_addr, start + bytes read so far.
1643 // void*, pointer to the bytes read
1644 // bytes_size, the count of bytes read for this chunk
1645 typedef std::function<IterationAction(
1646 lldb_private::Status &error, lldb::addr_t bytes_addr, const void *bytes,
1647 lldb::offset_t bytes_size)>
1649
1650 /// Read of memory from a process in discrete chunks, terminating
1651 /// either when all bytes are read, or the supplied callback returns
1652 /// IterationAction::Stop
1653 ///
1654 /// \param[in] vm_addr
1655 /// A virtual load address that indicates where to start reading
1656 /// memory from.
1657 ///
1658 /// \param[in] buf
1659 /// If NULL, a buffer of \a chunk_size will be created and used for the
1660 /// callback. If non NULL, this buffer must be at least \a chunk_size bytes
1661 /// and will be used for storing chunked memory reads.
1662 ///
1663 /// \param[in] chunk_size
1664 /// The minimum size of the byte buffer, and the chunk size of memory
1665 /// to read.
1666 ///
1667 /// \param[in] total_size
1668 /// The total number of bytes to read.
1669 ///
1670 /// \param[in] callback
1671 /// The callback to invoke when a chunk is read from memory.
1672 ///
1673 /// \return
1674 /// The number of bytes that were actually read into \a buf and
1675 /// written to the provided callback.
1676 /// If the returned number is greater than zero, yet less than \a
1677 /// size, then this function will get called again with \a
1678 /// vm_addr, \a buf, and \a size updated appropriately. Zero is
1679 /// returned in the case of an error.
1681 lldb::addr_t chunk_size,
1682 lldb::offset_t total_size,
1683 ReadMemoryChunkCallback callback);
1684
1685 /// Read a NULL terminated C string from memory
1686 ///
1687 /// This function will read a cache page at a time until the NULL
1688 /// C string terminator is found. It will stop reading if the NULL
1689 /// termination byte isn't found before reading \a cstr_max_len bytes, and
1690 /// the results are always guaranteed to be NULL terminated (at most
1691 /// cstr_max_len - 1 bytes will be read).
1692 size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr,
1693 size_t cstr_max_len, Status &error);
1694
1695 size_t ReadCStringFromMemory(lldb::addr_t vm_addr, std::string &out_str,
1696 Status &error);
1697
1698 llvm::SmallVector<std::optional<std::string>>
1699 ReadCStringsFromMemory(llvm::ArrayRef<lldb::addr_t> addresses);
1700
1701 /// Reads an unsigned integer of the specified byte size from process
1702 /// memory.
1703 ///
1704 /// \param[in] load_addr
1705 /// A load address of the integer to read.
1706 ///
1707 /// \param[in] byte_size
1708 /// The size in byte of the integer to read.
1709 ///
1710 /// \param[in] fail_value
1711 /// The value to return if we fail to read an integer.
1712 ///
1713 /// \param[out] error
1714 /// An error that indicates the success or failure of this
1715 /// operation. If error indicates success (error.Success()),
1716 /// then the value returned can be trusted, otherwise zero
1717 /// will be returned.
1718 ///
1719 /// \return
1720 /// The unsigned integer that was read from the process memory
1721 /// space. If the integer was smaller than a uint64_t, any
1722 /// unused upper bytes will be zero filled. If the process
1723 /// byte order differs from the host byte order, the integer
1724 /// value will be appropriately byte swapped into host byte
1725 /// order.
1727 size_t byte_size, uint64_t fail_value,
1728 Status &error);
1729
1730 /// Use Process::ReadMemoryRanges to efficiently read multiple unsigned
1731 /// integers from memory at once.
1732 llvm::SmallVector<std::optional<uint64_t>>
1733 ReadUnsignedIntegersFromMemory(llvm::ArrayRef<lldb::addr_t> addresses,
1734 unsigned byte_size);
1735
1736 int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size,
1737 int64_t fail_value, Status &error);
1738
1740
1741 /// Use Process::ReadMemoryRanges to efficiently read multiple pointers from
1742 /// memory at once.
1743 llvm::SmallVector<std::optional<lldb::addr_t>>
1744 ReadPointersFromMemory(llvm::ArrayRef<lldb::addr_t> ptr_locs);
1745
1746 bool WritePointerToMemory(lldb::addr_t vm_addr, lldb::addr_t ptr_value,
1747 Status &error);
1748
1749 /// Actually do the writing of memory to a process.
1750 ///
1751 /// \param[in] vm_addr
1752 /// A virtual load address that indicates where to start writing
1753 /// memory to.
1754 ///
1755 /// \param[in] buf
1756 /// A byte buffer that is at least \a size bytes long that
1757 /// contains the data to write.
1758 ///
1759 /// \param[in] size
1760 /// The number of bytes to write.
1761 ///
1762 /// \param[out] error
1763 /// An error value in case the memory write fails.
1764 ///
1765 /// \return
1766 /// The number of bytes that were actually written.
1767 virtual size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
1768 size_t size, Status &error) {
1770 "error: {0} does not support writing to processes", GetPluginName());
1771 return 0;
1772 }
1773
1774 /// Write all or part of a scalar value to memory.
1775 ///
1776 /// The value contained in \a scalar will be swapped to match the byte order
1777 /// of the process that is being debugged. If \a size is less than the size
1778 /// of scalar, the least significant \a size bytes from scalar will be
1779 /// written. If \a size is larger than the byte size of scalar, then the
1780 /// extra space will be padded with zeros and the scalar value will be
1781 /// placed in the least significant bytes in memory.
1782 ///
1783 /// \param[in] vm_addr
1784 /// A virtual load address that indicates where to start writing
1785 /// memory to.
1786 ///
1787 /// \param[in] scalar
1788 /// The scalar to write to the debugged process.
1789 ///
1790 /// \param[in] size
1791 /// This value can be smaller or larger than the scalar value
1792 /// itself. If \a size is smaller than the size of \a scalar,
1793 /// the least significant bytes in \a scalar will be used. If
1794 /// \a size is larger than the byte size of \a scalar, then
1795 /// the extra space will be padded with zeros. If \a size is
1796 /// set to UINT32_MAX, then the size of \a scalar will be used.
1797 ///
1798 /// \param[out] error
1799 /// An error value in case the memory write fails.
1800 ///
1801 /// \return
1802 /// The number of bytes that were actually written.
1803 size_t WriteScalarToMemory(lldb::addr_t vm_addr, const Scalar &scalar,
1804 size_t size, Status &error);
1805
1806 size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size,
1807 bool is_signed, Scalar &scalar,
1808 Status &error);
1809
1810 /// Write memory to a process.
1811 ///
1812 /// This function will write memory to the current process's address space
1813 /// and maintain any traps that might be present due to software
1814 /// breakpoints.
1815 ///
1816 /// This function is not meant to be overridden by Process subclasses, the
1817 /// subclasses should implement Process::DoWriteMemory (lldb::addr_t,
1818 /// size_t, void *).
1819 ///
1820 /// \param[in] vm_addr
1821 /// A virtual load address that indicates where to start writing
1822 /// memory to.
1823 ///
1824 /// \param[in] buf
1825 /// A byte buffer that is at least \a size bytes long that
1826 /// contains the data to write.
1827 ///
1828 /// \param[in] size
1829 /// The number of bytes to write.
1830 ///
1831 /// \return
1832 /// The number of bytes that were actually written.
1833 // TODO: change this to take an ArrayRef<uint8_t>
1834 size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
1835 Status &error);
1836
1837 /// Actually allocate memory in the process.
1838 ///
1839 /// This function will allocate memory in the process's address space. This
1840 /// can't rely on the generic function calling mechanism, since that
1841 /// requires this function.
1842 ///
1843 /// \param[in] size
1844 /// The size of the allocation requested.
1845 ///
1846 /// \return
1847 /// The address of the allocated buffer in the process, or
1848 /// LLDB_INVALID_ADDRESS if the allocation failed.
1849
1850 virtual lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
1851 Status &error) {
1853 "error: {0} does not support allocating in the debug process",
1854 GetPluginName());
1855 return LLDB_INVALID_ADDRESS;
1856 }
1857
1858 virtual Status WriteObjectFile(std::vector<ObjectFile::LoadableData> entries);
1859
1860 /// The public interface to allocating memory in the process.
1861 ///
1862 /// This function will allocate memory in the process's address space. This
1863 /// can't rely on the generic function calling mechanism, since that
1864 /// requires this function.
1865 ///
1866 /// \param[in] size
1867 /// The size of the allocation requested.
1868 ///
1869 /// \param[in] permissions
1870 /// Or together any of the lldb::Permissions bits. The permissions on
1871 /// a given memory allocation can't be changed after allocation. Note
1872 /// that a block that isn't set writable can still be written on from
1873 /// lldb,
1874 /// just not by the process itself.
1875 ///
1876 /// \param[in,out] error
1877 /// An error object to fill in if things go wrong.
1878 /// \return
1879 /// The address of the allocated buffer in the process, or
1880 /// LLDB_INVALID_ADDRESS if the allocation failed.
1881 lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, Status &error);
1882
1883 /// The public interface to allocating memory in the process, this also
1884 /// clears the allocated memory.
1885 ///
1886 /// This function will allocate memory in the process's address space. This
1887 /// can't rely on the generic function calling mechanism, since that
1888 /// requires this function.
1889 ///
1890 /// \param[in] size
1891 /// The size of the allocation requested.
1892 ///
1893 /// \param[in] permissions
1894 /// Or together any of the lldb::Permissions bits. The permissions on
1895 /// a given memory allocation can't be changed after allocation. Note
1896 /// that a block that isn't set writable can still be written on from
1897 /// lldb,
1898 /// just not by the process itself.
1899 ///
1900 /// \param[in,out] error
1901 /// An error object to fill in if things go wrong.
1902 ///
1903 /// \return
1904 /// The address of the allocated buffer in the process, or
1905 /// LLDB_INVALID_ADDRESS if the allocation failed.
1906
1907 lldb::addr_t CallocateMemory(size_t size, uint32_t permissions,
1908 Status &error);
1909
1910 /// If this architecture and process supports memory tagging, return a tag
1911 /// manager that can be used to maniupulate those memory tags.
1912 ///
1913 /// \return
1914 /// Either a valid pointer to a tag manager or an error describing why one
1915 /// could not be provided.
1916 llvm::Expected<const MemoryTagManager *> GetMemoryTagManager();
1917
1918 /// Read memory tags for the range addr to addr+len. It is assumed
1919 /// that this range has already been granule aligned.
1920 /// (see MemoryTagManager::MakeTaggedRange)
1921 ///
1922 /// This calls DoReadMemoryTags to do the target specific operations.
1923 ///
1924 /// \param[in] addr
1925 /// Start of memory range to read tags for.
1926 ///
1927 /// \param[in] len
1928 /// Length of memory range to read tags for (in bytes).
1929 ///
1930 /// \return
1931 /// If this architecture or process does not support memory tagging,
1932 /// an error saying so.
1933 /// If it does, either the memory tags or an error describing a
1934 /// failure to read or unpack them.
1935 virtual llvm::Expected<std::vector<lldb::addr_t>>
1936 ReadMemoryTags(lldb::addr_t addr, size_t len);
1937
1938 /// Write memory tags for a range of memory.
1939 /// (calls DoWriteMemoryTags to do the target specific work)
1940 ///
1941 /// \param[in] addr
1942 /// The address to start writing tags from. It is assumed that this
1943 /// address is granule aligned.
1944 ///
1945 /// \param[in] len
1946 /// The size of the range to write tags for. It is assumed that this
1947 /// is some multiple of the granule size. This len can be different
1948 /// from (number of tags * granule size) in the case where you want
1949 /// lldb-server to repeat tags across the range.
1950 ///
1951 /// \param[in] tags
1952 /// Allocation tags to be written. Since lldb-server can repeat tags for a
1953 /// range, the number of tags doesn't have to match the number of granules
1954 /// in the range. (though most of the time it will)
1955 ///
1956 /// \return
1957 /// A Status telling you if the write succeeded or not.
1958 Status WriteMemoryTags(lldb::addr_t addr, size_t len,
1959 const std::vector<lldb::addr_t> &tags);
1960
1961 /// Resolve dynamically loaded indirect functions.
1962 ///
1963 /// \param[in] address
1964 /// The load address of the indirect function to resolve.
1965 ///
1966 /// \param[out] error
1967 /// An error value in case the resolve fails.
1968 ///
1969 /// \return
1970 /// The address of the resolved function.
1971 /// LLDB_INVALID_ADDRESS if the resolution failed.
1972 virtual lldb::addr_t ResolveIndirectFunction(const Address *address,
1973 Status &error);
1974
1975 /// Locate the memory region that contains load_addr.
1976 ///
1977 /// If load_addr is within the address space the process has mapped
1978 /// range_info will be filled in with the start and end of that range as
1979 /// well as the permissions for that range and range_info. GetMapped will
1980 /// return true.
1981 ///
1982 /// If load_addr is outside any mapped region then range_info will have its
1983 /// start address set to load_addr and the end of the range will indicate
1984 /// the start of the next mapped range or be set to LLDB_INVALID_ADDRESS if
1985 /// there are no valid mapped ranges between load_addr and the end of the
1986 /// process address space.
1987 ///
1988 /// GetMemoryRegionInfo calls DoGetMemoryRegionInfo. Override that function in
1989 /// process subclasses.
1990 ///
1991 /// \param[in] load_addr
1992 /// The load address to query the range_info for. May include non
1993 /// address bits, these will be removed by the ABI plugin if there is
1994 /// one.
1995 ///
1996 /// \param[out] range_info
1997 /// An range_info value containing the details of the range.
1998 ///
1999 /// \return
2000 /// An error value.
2002 MemoryRegionInfo &range_info);
2003
2004 /// Obtain all the mapped memory regions within this process.
2005 ///
2006 /// \param[out] region_list
2007 /// A vector to contain MemoryRegionInfo objects for all mapped
2008 /// ranges.
2009 ///
2010 /// \return
2011 /// An error value.
2012 virtual Status
2014
2015 /// Get the number of watchpoints supported by this target.
2016 ///
2017 /// We may be able to determine the number of watchpoints available
2018 /// on this target; retrieve this value if possible.
2019 ///
2020 /// This number may be less than the number of watchpoints a user
2021 /// can specify. This is because a single user watchpoint may require
2022 /// multiple watchpoint slots to implement. Due to the size
2023 /// and/or alignment of objects.
2024 ///
2025 /// \return
2026 /// Returns the number of watchpoints, if available.
2027 virtual std::optional<uint32_t> GetWatchpointSlotCount() {
2028 return std::nullopt;
2029 }
2030
2031 /// Whether lldb will be notified about watchpoints after
2032 /// the instruction has completed executing, or if the
2033 /// instruction is rolled back and it is notified before it
2034 /// executes.
2035 /// The default behavior is "exceptions received after instruction
2036 /// has executed", except for certain CPU architectures.
2037 /// Process subclasses may override this if they have additional
2038 /// information.
2039 ///
2040 /// \return
2041 /// Returns true for targets where lldb is notified after
2042 /// the instruction has completed executing.
2044
2045 /// Creates and populates a module using an in-memory object file.
2046 ///
2047 /// \param[in] file_spec
2048 /// The name or path to the module file. May be empty.
2049 ///
2050 /// \param[in] header_addr
2051 /// The address pointing to the beginning of the object file's header.
2052 ///
2053 /// \param[in] size_to_read
2054 /// The number of bytes to read from memory. This should be large enough to
2055 /// identify the object file format. Defaults to 512.
2056 llvm::Expected<lldb::ModuleSP>
2057 ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr,
2058 size_t size_to_read = 512);
2059
2060 /// Attempt to get the attributes for a region of memory in the process.
2061 ///
2062 /// It may be possible for the remote debug server to inspect attributes for
2063 /// a region of memory in the process, such as whether there is a valid page
2064 /// of memory at a given address or whether that page is
2065 /// readable/writable/executable by the process.
2066 ///
2067 /// \param[in] load_addr
2068 /// The address of interest in the process.
2069 ///
2070 /// \param[out] permissions
2071 /// If this call returns successfully, this bitmask will have
2072 /// its Permissions bits set to indicate whether the region is
2073 /// readable/writable/executable. If this call fails, the
2074 /// bitmask values are undefined.
2075 ///
2076 /// \return
2077 /// Returns true if it was able to determine the attributes of the
2078 /// memory region. False if not.
2079 virtual bool GetLoadAddressPermissions(lldb::addr_t load_addr,
2080 uint32_t &permissions);
2081
2082 /// Determines whether executing JIT-compiled code in this process is
2083 /// possible.
2084 ///
2085 /// \return
2086 /// True if execution of JIT code is possible; false otherwise.
2087 bool CanJIT();
2088
2089 /// Sets whether executing JIT-compiled code in this process is possible.
2090 ///
2091 /// \param[in] can_jit
2092 /// True if execution of JIT code is possible; false otherwise.
2093 void SetCanJIT(bool can_jit);
2094
2095 /// Determines whether executing function calls using the interpreter is
2096 /// possible for this process.
2097 ///
2098 /// \return
2099 /// True if possible; false otherwise.
2101
2102 /// Sets whether executing function calls using the interpreter is possible
2103 /// for this process.
2104 ///
2105 /// \param[in] can_interpret_function_calls
2106 /// True if possible; false otherwise.
2107 void SetCanInterpretFunctionCalls(bool can_interpret_function_calls) {
2108 m_can_interpret_function_calls = can_interpret_function_calls;
2109 }
2110
2111 /// Sets whether executing code in this process is possible. This could be
2112 /// either through JIT or interpreting.
2113 ///
2114 /// \param[in] can_run_code
2115 /// True if execution of code is possible; false otherwise.
2116 void SetCanRunCode(bool can_run_code);
2117
2118 /// Actually deallocate memory in the process.
2119 ///
2120 /// This function will deallocate memory in the process's address space that
2121 /// was allocated with AllocateMemory.
2122 ///
2123 /// \param[in] ptr
2124 /// A return value from AllocateMemory, pointing to the memory you
2125 /// want to deallocate.
2126 ///
2127 /// \return
2128 /// \b true if the memory was deallocated, \b false otherwise.
2131 "error: {0} does not support deallocating in the debug process",
2132 GetPluginName());
2133 }
2134
2135 /// The public interface to deallocating memory in the process.
2136 ///
2137 /// This function will deallocate memory in the process's address space that
2138 /// was allocated with AllocateMemory.
2139 ///
2140 /// \param[in] ptr
2141 /// A return value from AllocateMemory, pointing to the memory you
2142 /// want to deallocate.
2143 ///
2144 /// \return
2145 /// \b true if the memory was deallocated, \b false otherwise.
2147
2148 /// Get any available STDOUT.
2149 ///
2150 /// Calling this method is a valid operation only if all of the following
2151 /// conditions are true: 1) The process was launched, and not attached to.
2152 /// 2) The process was not launched with eLaunchFlagDisableSTDIO. 3) The
2153 /// process was launched without supplying a valid file path
2154 /// for STDOUT.
2155 ///
2156 /// Note that the implementation will probably need to start a read thread
2157 /// in the background to make sure that the pipe is drained and the STDOUT
2158 /// buffered appropriately, to prevent the process from deadlocking trying
2159 /// to write to a full buffer.
2160 ///
2161 /// Events will be queued indicating that there is STDOUT available that can
2162 /// be retrieved using this function.
2163 ///
2164 /// \param[out] buf
2165 /// A buffer that will receive any STDOUT bytes that are
2166 /// currently available.
2167 ///
2168 /// \param[in] buf_size
2169 /// The size in bytes for the buffer \a buf.
2170 ///
2171 /// \return
2172 /// The number of bytes written into \a buf. If this value is
2173 /// equal to \a buf_size, another call to this function should
2174 /// be made to retrieve more STDOUT data.
2175 virtual size_t GetSTDOUT(char *buf, size_t buf_size, Status &error);
2176
2177 /// Get any available STDERR.
2178 ///
2179 /// Calling this method is a valid operation only if all of the following
2180 /// conditions are true: 1) The process was launched, and not attached to.
2181 /// 2) The process was not launched with eLaunchFlagDisableSTDIO. 3) The
2182 /// process was launched without supplying a valid file path
2183 /// for STDERR.
2184 ///
2185 /// Note that the implementation will probably need to start a read thread
2186 /// in the background to make sure that the pipe is drained and the STDERR
2187 /// buffered appropriately, to prevent the process from deadlocking trying
2188 /// to write to a full buffer.
2189 ///
2190 /// Events will be queued indicating that there is STDERR available that can
2191 /// be retrieved using this function.
2192 ///
2193 /// \param[in] buf
2194 /// A buffer that will receive any STDERR bytes that are
2195 /// currently available.
2196 ///
2197 /// \param[out] buf_size
2198 /// The size in bytes for the buffer \a buf.
2199 ///
2200 /// \return
2201 /// The number of bytes written into \a buf. If this value is
2202 /// equal to \a buf_size, another call to this function should
2203 /// be made to retrieve more STDERR data.
2204 virtual size_t GetSTDERR(char *buf, size_t buf_size, Status &error);
2205
2206 /// Puts data into this process's STDIN.
2207 ///
2208 /// Calling this method is a valid operation only if all of the following
2209 /// conditions are true: 1) The process was launched, and not attached to.
2210 /// 2) The process was not launched with eLaunchFlagDisableSTDIO. 3) The
2211 /// process was launched without supplying a valid file path
2212 /// for STDIN.
2213 ///
2214 /// \param[in] buf
2215 /// A buffer that contains the data to write to the process's STDIN.
2216 ///
2217 /// \param[in] buf_size
2218 /// The size in bytes for the buffer \a buf.
2219 ///
2220 /// \return
2221 /// The number of bytes written into \a buf. If this value is
2222 /// less than \a buf_size, another call to this function should
2223 /// be made to write the rest of the data.
2224 virtual size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) {
2225 error = Status::FromErrorString("stdin unsupported");
2226 return 0;
2227 }
2228
2229 /// Get any available profile data.
2230 ///
2231 /// \param[out] buf
2232 /// A buffer that will receive any profile data bytes that are
2233 /// currently available.
2234 ///
2235 /// \param[out] buf_size
2236 /// The size in bytes for the buffer \a buf.
2237 ///
2238 /// \return
2239 /// The number of bytes written into \a buf. If this value is
2240 /// equal to \a buf_size, another call to this function should
2241 /// be made to retrieve more profile data.
2242 virtual size_t GetAsyncProfileData(char *buf, size_t buf_size, Status &error);
2243
2244 // Process Breakpoints
2246
2249 "error: {0} does not support enabling breakpoints", GetPluginName());
2250 }
2251
2254 "error: {0} does not support disabling breakpoints", GetPluginName());
2255 }
2256
2257 // This is implemented completely using the lldb::Process API. Subclasses
2258 // don't need to implement this function unless the standard flow of read
2259 // existing opcode, write breakpoint opcode, verify breakpoint opcode doesn't
2260 // work for a specific process plug-in.
2262
2263 // This is implemented completely using the lldb::Process API. Subclasses
2264 // don't need to implement this function unless the standard flow of
2265 // restoring original opcode in memory and verifying the restored opcode
2266 // doesn't work for a specific process plug-in.
2268
2270
2272 GetBreakpointSiteList() const;
2273
2275
2277
2279 bool use_hardware);
2280
2282
2284
2285 // BreakpointLocations use RemoveConstituentFromBreakpointSite to remove
2286 // themselves from the constituent's list of this breakpoint sites.
2288 lldb::user_id_t constituent_id,
2289 lldb::BreakpointSiteSP &bp_site_sp);
2290
2291 // Process Watchpoints (optional)
2292 virtual Status EnableWatchpoint(lldb::WatchpointSP wp_sp, bool notify = true);
2293
2295 bool notify = true);
2296
2297 // Thread Queries
2298
2299 /// Update the thread list.
2300 ///
2301 /// This method performs some general clean up before invoking
2302 /// \a DoUpdateThreadList, which should be implemented by each
2303 /// process plugin.
2304 ///
2305 /// \return
2306 /// \b true if the new thread list could be generated, \b false otherwise.
2307 bool UpdateThreadList(ThreadList &old_thread_list,
2308 ThreadList &new_thread_list);
2309
2311
2313
2318
2319 // When ExtendedBacktraces are requested, the HistoryThreads that are created
2320 // need an owner -- they're saved here in the Process. The threads in this
2321 // list are not iterated over - driver programs need to request the extended
2322 // backtrace calls starting from a root concrete thread one by one.
2324
2326
2327 uint32_t GetNextThreadIndexID(uint64_t thread_id);
2328
2330
2331 // Returns true if an index id has been assigned to a thread.
2332 bool HasAssignedIndexIDToThread(uint64_t sb_thread_id);
2333
2334 // Given a thread_id, it will assign a more reasonable index id for display
2335 // to the user. If the thread_id has previously been assigned, the same index
2336 // id will be used.
2337 uint32_t AssignIndexIDToThread(uint64_t thread_id);
2338
2339 // Queue Queries
2340
2341 virtual void UpdateQueueListIfNeeded();
2342
2347
2352
2353 // Event Handling
2355
2356 // Returns the process state when it is stopped. If specified, event_sp_ptr
2357 // is set to the event which triggered the stop. If wait_always = false, and
2358 // the process is already stopped, this function returns immediately. If the
2359 // process is hijacked and use_run_lock is true (the default), then this
2360 // function releases the run lock after the stop. Setting use_run_lock to
2361 // false will avoid this behavior.
2362 // If we are waiting to stop that will return control to the user,
2363 // then we also want to run SelectMostRelevantFrame, which is controlled
2364 // by "select_most_relevant".
2367 lldb::EventSP *event_sp_ptr = nullptr,
2368 bool wait_always = true,
2369 lldb::ListenerSP hijack_listener = lldb::ListenerSP(),
2370 Stream *stream = nullptr, bool use_run_lock = true,
2371 SelectMostRelevant select_most_relevant =
2373
2374 uint32_t GetIOHandlerID() const { return m_iohandler_sync.GetValue(); }
2375
2376 /// Waits for the process state to be running within a given msec timeout.
2377 ///
2378 /// The main purpose of this is to implement an interlock waiting for
2379 /// HandlePrivateEvent to push an IOHandler.
2380 ///
2381 /// \param[in] timeout
2382 /// The maximum time length to wait for the process to transition to the
2383 /// eStateRunning state.
2384 void SyncIOHandler(uint32_t iohandler_id, const Timeout<std::micro> &timeout);
2385
2387 lldb::EventSP &event_sp, const Timeout<std::micro> &timeout,
2389 hijack_listener); // Pass an empty ListenerSP to use builtin listener
2390
2391 /// Centralize the code that handles and prints descriptions for process
2392 /// state changes.
2393 ///
2394 /// \param[in] event_sp
2395 /// The process state changed event
2396 ///
2397 /// \param[in] stream
2398 /// The output stream to get the state change description
2399 ///
2400 /// \param[in,out] pop_process_io_handler
2401 /// If this value comes in set to \b true, then pop the Process IOHandler
2402 /// if needed.
2403 /// Else this variable will be set to \b true or \b false to indicate if
2404 /// the process
2405 /// needs to have its process IOHandler popped.
2406 ///
2407 /// \return
2408 /// \b true if the event describes a process state changed event, \b false
2409 /// otherwise.
2410 static bool
2411 HandleProcessStateChangedEvent(const lldb::EventSP &event_sp, Stream *stream,
2412 SelectMostRelevant select_most_relevant,
2413 bool &pop_process_io_handler);
2414
2416
2418 public:
2420 : m_process(process) {
2421 m_process.HijackProcessEvents(std::move(listener_sp));
2422 }
2423
2424 ~ProcessEventHijacker() { m_process.RestoreProcessEvents(); }
2425
2426 private:
2428 };
2429
2431 friend class ProcessProperties;
2432 /// If you need to ensure that you and only you will hear about some public
2433 /// event, then make a new listener, set to listen to process events, and
2434 /// then call this with that listener. Then you will have to wait on that
2435 /// listener explicitly for events (rather than using the GetNextEvent &
2436 /// WaitFor* calls above. Be sure to call RestoreProcessEvents when you are
2437 /// done.
2438 ///
2439 /// \param[in] listener_sp
2440 /// This is the new listener to whom all process events will be delivered.
2441 ///
2442 /// \return
2443 /// Returns \b true if the new listener could be installed,
2444 /// \b false otherwise.
2445 bool HijackProcessEvents(lldb::ListenerSP listener_sp);
2446
2447 /// Restores the process event broadcasting to its normal state.
2448 ///
2449 void RestoreProcessEvents();
2450
2452
2454
2455 const lldb::ABISP &GetABI();
2456
2458
2459 std::vector<LanguageRuntime *> GetLanguageRuntimes();
2460
2462
2463 bool IsPossibleDynamicValue(ValueObject &in_value);
2464
2465 bool IsRunning() const;
2466
2470
2471 void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers);
2472
2473/// Prune ThreadPlanStacks for unreported threads.
2474///
2475/// \param[in] tid
2476/// The tid whose Plan Stack we are seeking to prune.
2477///
2478/// \return
2479/// \b true if the TID is found or \b false if not.
2481
2482/// Prune ThreadPlanStacks for all unreported threads.
2483void PruneThreadPlans();
2484
2485 /// Find the thread plan stack associated with thread with \a tid.
2486 ///
2487 /// \param[in] tid
2488 /// The tid whose Plan Stack we are seeking.
2489 ///
2490 /// \return
2491 /// Returns a ThreadPlan if the TID is found or nullptr if not.
2493
2494 /// Dump the thread plans associated with thread with \a tid.
2495 ///
2496 /// \param[in,out] strm
2497 /// The stream to which to dump the output
2498 ///
2499 /// \param[in] tid
2500 /// The tid whose Plan Stack we are dumping
2501 ///
2502 /// \param[in] desc_level
2503 /// How much detail to dump
2504 ///
2505 /// \param[in] internal
2506 /// If \b true dump all plans, if false only user initiated plans
2507 ///
2508 /// \param[in] condense_trivial
2509 /// If true, only dump a header if the plan stack is just the base plan.
2510 ///
2511 /// \param[in] skip_unreported_plans
2512 /// If true, only dump a plan if it is currently backed by an
2513 /// lldb_private::Thread *.
2514 ///
2515 /// \return
2516 /// Returns \b true if TID was found, \b false otherwise
2518 lldb::DescriptionLevel desc_level, bool internal,
2519 bool condense_trivial, bool skip_unreported_plans);
2520
2521 /// Dump all the thread plans for this process.
2522 ///
2523 /// \param[in,out] strm
2524 /// The stream to which to dump the output
2525 ///
2526 /// \param[in] desc_level
2527 /// How much detail to dump
2528 ///
2529 /// \param[in] internal
2530 /// If \b true dump all plans, if false only user initiated plans
2531 ///
2532 /// \param[in] condense_trivial
2533 /// If true, only dump a header if the plan stack is just the base plan.
2534 ///
2535 /// \param[in] skip_unreported_plans
2536 /// If true, skip printing all thread plan stacks that don't currently
2537 /// have a backing lldb_private::Thread *.
2538 void DumpThreadPlans(Stream &strm, lldb::DescriptionLevel desc_level,
2539 bool internal, bool condense_trivial,
2540 bool skip_unreported_plans);
2541
2542 /// Call this to set the lldb in the mode where it breaks on new thread
2543 /// creations, and then auto-restarts. This is useful when you are trying
2544 /// to run only one thread, but either that thread or the kernel is creating
2545 /// new threads in the process. If you stop when the thread is created, you
2546 /// can immediately suspend it, and keep executing only the one thread you
2547 /// intend.
2548 ///
2549 /// \return
2550 /// Returns \b true if we were able to start up the notification
2551 /// \b false otherwise.
2552 virtual bool StartNoticingNewThreads() { return true; }
2553
2554 /// Call this to turn off the stop & notice new threads mode.
2555 ///
2556 /// \return
2557 /// Returns \b true if we were able to start up the notification
2558 /// \b false otherwise.
2559 virtual bool StopNoticingNewThreads() { return true; }
2560
2561 void SetRunningUserExpression(bool on);
2562 void SetRunningUtilityFunction(bool on);
2563
2564 // lldb::ExecutionContextScope pure virtual functions
2566
2567 lldb::ProcessSP CalculateProcess() override { return shared_from_this(); }
2568
2570
2574
2575 void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
2576
2577#ifdef _WIN32
2578 /// Associates a ConPTY read and write HANDLEs with the process' STDIO
2579 /// handling and configures an asynchronous reading of that ConPTY's stdout
2580 /// HANDLE.
2581 ///
2582 /// This method installs a ConnectionGenericFile for the passed ConPTY and
2583 /// starts a dedicated read thread. If the read thread starts successfully,
2584 /// the method also ensures that an IOHandlerProcessSTDIOWindows is created to
2585 /// manage user input to the process.
2586 ///
2587 /// When data is successfully read from the ConPTY, it is stored in
2588 /// m_stdout_data. There is no differentiation between stdout and stderr.
2589 ///
2590 /// \see lldb_private::Process::STDIOReadThreadBytesReceived()
2591 /// \see lldb_private::IOHandlerProcessSTDIOWindows
2592 /// \see lldb_private::PseudoConsole
2593 virtual void SetPseudoConsoleHandle() {};
2594#endif
2595
2596 /// Associates a file descriptor with the process' STDIO handling
2597 /// and configures an asynchronous reading of that descriptor.
2598 ///
2599 /// This method installs a ConnectionFileDescriptor for the passed file
2600 /// descriptor and starts a dedicated read thread. If the read thread starts
2601 /// successfully, the method also ensures that an IOHandlerProcessSTDIO is
2602 /// created to manage user input to the process.
2603 ///
2604 /// The descriptor's ownership is transferred to the underlying
2605 /// ConnectionFileDescriptor.
2606 ///
2607 /// When data is successfully read from the file descriptor, it is stored in
2608 /// m_stdout_data. There is no differentiation between stdout and stderr.
2609 ///
2610 /// \param[in] fd
2611 /// The file descriptor to use for process STDIO communication. It's
2612 /// assumed to be valid and will be managed by the newly created
2613 /// connection.
2614 ///
2615 /// \see lldb_private::Process::STDIOReadThreadBytesReceived()
2616 /// \see lldb_private::IOHandlerProcessSTDIO
2617 /// \see lldb_private::ConnectionFileDescriptor
2618 void SetSTDIOFileDescriptor(int file_descriptor);
2619
2620 // Add a permanent region of memory that should never be read or written to.
2621 // This can be used to ensure that memory reads or writes to certain areas of
2622 // memory never end up being sent to the DoReadMemory or DoWriteMemory
2623 // functions which can improve performance.
2624 void AddInvalidMemoryRegion(const LoadRange &region);
2625
2626 // Remove a permanent region of memory that should never be read or written
2627 // to that was previously added with AddInvalidMemoryRegion.
2628 bool RemoveInvalidMemoryRange(const LoadRange &region);
2629
2630 // If the setup code of a thread plan needs to do work that might involve
2631 // calling a function in the target, it should not do that work directly in
2632 // one of the thread plan functions (DidPush/WillResume) because such work
2633 // needs to be handled carefully. Instead, put that work in a
2634 // PreResumeAction callback, and register it with the process. It will get
2635 // done before the actual "DoResume" gets called.
2636
2638
2639 void AddPreResumeAction(PreResumeActionCallback callback, void *baton);
2640
2641 bool RunPreResumeActions();
2642
2643 void ClearPreResumeActions();
2644
2645 void ClearPreResumeAction(PreResumeActionCallback callback, void *baton);
2646
2648
2650
2652
2653 virtual Status SendEventData(const char *data) {
2655 "Sending an event is not supported for this process.");
2656 }
2657
2659
2662
2663 /// Try to fetch the module specification for a module with the given file
2664 /// name and architecture. Process sub-classes have to override this method
2665 /// if they support platforms where the Platform object can't get the module
2666 /// spec for all module.
2667 ///
2668 /// \param[in] module_file_spec
2669 /// The file name of the module to get specification for.
2670 ///
2671 /// \param[in] arch
2672 /// The architecture of the module to get specification for.
2673 ///
2674 /// \param[out] module_spec
2675 /// The fetched module specification if the return value is
2676 /// \b true, unchanged otherwise.
2677 ///
2678 /// \return
2679 /// Returns \b true if the module spec fetched successfully,
2680 /// \b false otherwise.
2681 virtual bool GetModuleSpec(const FileSpec &module_file_spec,
2682 const ArchSpec &arch, ModuleSpec &module_spec);
2683
2684 virtual void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
2685 const llvm::Triple &triple) {}
2686
2687 /// Try to find the load address of a file.
2688 /// The load address is defined as the address of the first memory region
2689 /// what contains data mapped from the specified file.
2690 ///
2691 /// \param[in] file
2692 /// The name of the file whose load address we are looking for
2693 ///
2694 /// \param[out] is_loaded
2695 /// \b True if the file is loaded into the memory and false
2696 /// otherwise.
2697 ///
2698 /// \param[out] load_addr
2699 /// The load address of the file if it is loaded into the
2700 /// processes address space, LLDB_INVALID_ADDRESS otherwise.
2701 virtual Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
2702 lldb::addr_t &load_addr) {
2703 return Status::FromErrorString("Not supported");
2704 }
2705
2706 /// Fetch process defined metadata.
2707 ///
2708 /// \return
2709 /// A StructuredDataSP object which, if non-empty, will contain the
2710 /// information related to the process.
2711 virtual StructuredData::DictionarySP GetMetadata() { return nullptr; }
2712
2713 /// Fetch extended crash information held by the process. This will never be
2714 /// an empty shared pointer, it will always have a dict, though it may be
2715 /// empty.
2717 assert(m_crash_info_dict_sp && "We always have a valid dictionary");
2718 return m_crash_info_dict_sp;
2719 }
2720
2722 // StructuredData::Dictionary is add only, so we have to make a new one:
2723 m_crash_info_dict_sp = std::make_shared<StructuredData::Dictionary>();
2724 }
2725
2726 size_t AddImageToken(lldb::addr_t image_ptr);
2727
2728 lldb::addr_t GetImagePtrFromToken(size_t token) const;
2729
2730 void ResetImageToken(size_t token);
2731
2732 /// Find the next branch instruction to set a breakpoint on
2733 ///
2734 /// When instruction stepping through a source line, instead of stepping
2735 /// through each instruction, we can put a breakpoint on the next branch
2736 /// instruction (within the range of instructions we are stepping through)
2737 /// and continue the process to there, yielding significant performance
2738 /// benefits over instruction stepping.
2739 ///
2740 /// \param[in] default_stop_addr
2741 /// The address of the instruction where lldb would put a
2742 /// breakpoint normally.
2743 ///
2744 /// \param[in] range_bounds
2745 /// The range which the breakpoint must be contained within.
2746 /// Typically a source line.
2747 ///
2748 /// \return
2749 /// The address of the next branch instruction, or the end of
2750 /// the range provided in range_bounds. If there are any
2751 /// problems with the disassembly or getting the instructions,
2752 /// the original default_stop_addr will be returned.
2754 AddressRange range_bounds);
2755
2756 /// Configure asynchronous structured data feature.
2757 ///
2758 /// Each Process type that supports using an asynchronous StructuredData
2759 /// feature should implement this to enable/disable/configure the feature.
2760 /// The default implementation here will always return an error indiciating
2761 /// the feature is unsupported.
2762 ///
2763 /// StructuredDataPlugin implementations will call this to configure a
2764 /// feature that has been reported as being supported.
2765 ///
2766 /// \param[in] type_name
2767 /// The StructuredData type name as previously discovered by
2768 /// the Process-derived instance.
2769 ///
2770 /// \param[in] config_sp
2771 /// Configuration data for the feature being enabled. This config
2772 /// data, which may be null, will be passed along to the feature
2773 /// to process. The feature will dictate whether this is a dictionary,
2774 /// an array or some other object. If the feature needs to be
2775 /// set up properly before it can be enabled, then the config should
2776 /// also take an enable/disable flag.
2777 ///
2778 /// \return
2779 /// Returns the result of attempting to configure the feature.
2780 virtual Status
2781 ConfigureStructuredData(llvm::StringRef type_name,
2782 const StructuredData::ObjectSP &config_sp);
2783
2784 /// Broadcasts the given structured data object from the given plugin.
2785 ///
2786 /// StructuredDataPlugin instances can use this to optionally broadcast any
2787 /// of their data if they want to make it available for clients. The data
2788 /// will come in on the structured data event bit
2789 /// (eBroadcastBitStructuredData).
2790 ///
2791 /// \param[in] object_sp
2792 /// The structured data object to broadcast.
2793 ///
2794 /// \param[in] plugin_sp
2795 /// The plugin that will be reported in the event's plugin
2796 /// parameter.
2798 const lldb::StructuredDataPluginSP &plugin_sp);
2799
2800 /// Returns the StructuredDataPlugin associated with a given type name, if
2801 /// there is one.
2802 ///
2803 /// There will only be a plugin for a given StructuredDataType if the
2804 /// debugged process monitor claims that the feature is supported. This is
2805 /// one way to tell whether a feature is available.
2806 ///
2807 /// \return
2808 /// The plugin if one is available for the specified feature;
2809 /// otherwise, returns an empty shared pointer.
2811 GetStructuredDataPlugin(llvm::StringRef type_name) const;
2812
2813 virtual void *GetImplementation() { return nullptr; }
2814
2816
2820
2821 /// Find a pattern within a memory region.
2822 ///
2823 /// This function searches for a pattern represented by the provided buffer
2824 /// within the memory range specified by the low and high addresses. It uses
2825 /// a bad character heuristic to optimize the search process.
2826 ///
2827 /// \param[in] low The starting address of the memory region to be searched.
2828 /// (inclusive)
2829 ///
2830 /// \param[in] high The ending address of the memory region to be searched.
2831 /// (exclusive)
2832 ///
2833 /// \param[in] buf A pointer to the buffer containing the pattern to be
2834 /// searched.
2835 ///
2836 /// \param[in] buffer_size The size of the buffer in bytes.
2837 ///
2838 /// \return The address where the pattern was found or LLDB_INVALID_ADDRESS if
2839 /// not found.
2841 const uint8_t *buf, size_t size);
2842
2843 AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
2844 const AddressRanges &ranges,
2845 size_t alignment, size_t max_matches,
2846 Status &error);
2847
2848 lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
2849 const AddressRange &range, size_t alignment,
2850 Status &error);
2851
2852 /// Get the base run direction for the process.
2853 /// The base direction is the direction the process will execute in
2854 /// (forward or backward) if no thread plan overrides the direction.
2856 /// Set the base run direction for the process.
2857 /// As a side-effect, if this changes the base direction, then we
2858 /// discard all non-base thread plans to ensure that when execution resumes
2859 /// we definitely execute in the requested direction.
2860 /// FIXME: this is overkill. In some situations ensuring the latter
2861 /// would not require discarding all non-base thread plans.
2862 void SetBaseDirection(lldb::RunDirection direction);
2863
2864protected:
2865 friend class Trace;
2866
2867 /// Construct with a shared pointer to a target, and the Process listener.
2868 /// Uses the Host UnixSignalsSP by default.
2869 Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
2870
2871 /// Construct with a shared pointer to a target, the Process listener, and
2872 /// the appropriate UnixSignalsSP for the process.
2873 Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
2874 const lldb::UnixSignalsSP &unix_signals_sp);
2875
2876 /// Get the processor tracing type supported for this process.
2877 /// Responses might be different depending on the architecture and
2878 /// capabilities of the underlying OS.
2879 ///
2880 /// \return
2881 /// The supported trace type or an \a llvm::Error if tracing is
2882 /// not supported for the inferior.
2883 virtual llvm::Expected<TraceSupportedResponse> TraceSupported();
2884
2885 /// Start tracing a process or its threads.
2886 ///
2887 /// \param[in] request
2888 /// JSON object with the information necessary to start tracing. In the
2889 /// case of gdb-remote processes, this JSON object should conform to the
2890 /// jLLDBTraceStart packet.
2891 ///
2892 /// \return
2893 /// \a llvm::Error::success if the operation was successful, or
2894 /// \a llvm::Error otherwise.
2895 virtual llvm::Error TraceStart(const llvm::json::Value &request) {
2896 return llvm::make_error<UnimplementedError>();
2897 }
2898
2899 /// Stop tracing a live process or its threads.
2900 ///
2901 /// \param[in] request
2902 /// The information determining which threads or process to stop tracing.
2903 ///
2904 /// \return
2905 /// \a llvm::Error::success if the operation was successful, or
2906 /// \a llvm::Error otherwise.
2907 virtual llvm::Error TraceStop(const TraceStopRequest &request) {
2908 return llvm::make_error<UnimplementedError>();
2909 }
2910
2911 /// Get the current tracing state of the process and its threads.
2912 ///
2913 /// \param[in] type
2914 /// Tracing technology type to consider.
2915 ///
2916 /// \return
2917 /// A JSON object string with custom data depending on the trace
2918 /// technology, or an \a llvm::Error in case of errors.
2919 virtual llvm::Expected<std::string> TraceGetState(llvm::StringRef type) {
2920 return llvm::make_error<UnimplementedError>();
2921 }
2922
2923 /// Get binary data given a trace technology and a data identifier.
2924 ///
2925 /// \param[in] request
2926 /// Object with the params of the requested data.
2927 ///
2928 /// \return
2929 /// A vector of bytes with the requested data, or an \a llvm::Error in
2930 /// case of failures.
2931 virtual llvm::Expected<std::vector<uint8_t>>
2933 return llvm::make_error<UnimplementedError>();
2934 }
2935
2936 // This calls a function of the form "void * (*)(void)".
2937 bool CallVoidArgVoidPtrReturn(const Address *address,
2938 lldb::addr_t &returned_func,
2939 bool trap_exceptions = false);
2940
2941 /// Update the thread list following process plug-in's specific logic.
2942 ///
2943 /// This method should only be invoked by \a UpdateThreadList.
2944 ///
2945 /// \return
2946 /// \b true if the new thread list could be generated, \b false otherwise.
2947 virtual bool DoUpdateThreadList(ThreadList &old_thread_list,
2948 ThreadList &new_thread_list) = 0;
2949
2950 /// Actually do the reading of memory from a process.
2951 ///
2952 /// Subclasses must override this function and can return fewer bytes than
2953 /// requested when memory requests are too large. This class will break up
2954 /// the memory requests and keep advancing the arguments along as needed.
2955 ///
2956 /// \param[in] vm_addr
2957 /// A virtual load address that indicates where to start reading
2958 /// memory from.
2959 ///
2960 /// \param[in] size
2961 /// The number of bytes to read.
2962 ///
2963 /// \param[out] buf
2964 /// A byte buffer that is at least \a size bytes long that
2965 /// will receive the memory bytes.
2966 ///
2967 /// \param[out] error
2968 /// An error that indicates the success or failure of this
2969 /// operation. If error indicates success (error.Success()),
2970 /// then the value returned can be trusted, otherwise zero
2971 /// will be returned.
2972 ///
2973 /// \return
2974 /// The number of bytes that were actually read into \a buf.
2975 /// Zero is returned in the case of an error.
2976 virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
2977 Status &error) = 0;
2978
2979 virtual void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
2980 const uint8_t *buf, size_t size,
2981 AddressRanges &matches, size_t alignment,
2982 size_t max_matches);
2983
2984 /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
2985 /// removed non address bits from load_addr. Override this method in
2986 /// subclasses of Process.
2987 ///
2988 /// See GetMemoryRegionInfo for details of the logic.
2989 ///
2990 /// \param[in] load_addr
2991 /// The load address to query the range_info for. (non address bits
2992 /// removed)
2993 ///
2994 /// \param[out] range_info
2995 /// An range_info value containing the details of the range.
2996 ///
2997 /// \return
2998 /// An error value.
3000 MemoryRegionInfo &range_info) {
3002 "Process::DoGetMemoryRegionInfo() not supported");
3003 }
3004
3005 /// Provide an override value in the subclass for lldb's
3006 /// CPU-based logic for whether watchpoint exceptions are
3007 /// received before or after an instruction executes.
3008 ///
3009 /// If a Process subclass needs to override this architecture-based
3010 /// result, it may do so by overriding this method.
3011 ///
3012 /// \return
3013 /// No boolean returned means there is no override of the
3014 /// default architecture-based behavior.
3015 /// true is returned for targets where watchpoints are reported
3016 /// after the instruction has completed.
3017 /// false is returned for targets where watchpoints are reported
3018 /// before the instruction executes.
3019 virtual std::optional<bool> DoGetWatchpointReportedAfter() {
3020 return std::nullopt;
3021 }
3022
3023 /// Handle thread specific async interrupt and return the original thread
3024 /// that requested the async interrupt. It can be null if original thread
3025 /// has exited.
3026 ///
3027 /// \param[in] description
3028 /// Returns the stop reason description of the async interrupt.
3029 virtual lldb::ThreadSP
3030 HandleThreadAsyncInterrupt(uint8_t signo, const std::string &description) {
3031 return lldb::ThreadSP();
3032 }
3033
3034 /// The "private" side of resuming a process. This doesn't alter the state
3035 /// of m_run_lock, but just causes the process to resume.
3036 ///
3037 /// \return
3038 /// An Status object describing the success or failure of the resume.
3040
3041 // Called internally
3042 void CompleteAttach();
3043
3044 // NextEventAction provides a way to register an action on the next event
3045 // that is delivered to this process. There is currently only one next event
3046 // action allowed in the process at one time. If a new "NextEventAction" is
3047 // added while one is already present, the old action will be discarded (with
3048 // HandleBeingUnshipped called after it is discarded.)
3049 //
3050 // If you want to resume the process as a result of a resume action, call
3051 // RequestResume, don't call Resume directly.
3053 public:
3059
3060 NextEventAction(Process *process) : m_process(process) {}
3061
3062 virtual ~NextEventAction() = default;
3063
3065 virtual void HandleBeingUnshipped() {}
3067 virtual const char *GetExitString() = 0;
3068 void RequestResume() { m_process->m_resume_requested = true; }
3069
3070 protected:
3072 };
3073
3076 m_next_event_action_up->HandleBeingUnshipped();
3077
3078 m_next_event_action_up.reset(next_event_action);
3079 }
3080
3081 // This is the completer for Attaching:
3083 public:
3084 AttachCompletionHandler(Process *process, uint32_t exec_count);
3085
3086 ~AttachCompletionHandler() override = default;
3087
3088 EventActionResult PerformAction(lldb::EventSP &event_sp) override;
3090 const char *GetExitString() override;
3091
3092 private:
3094 std::string m_exit_string;
3095 };
3096
3100 return false;
3101
3102 lldb::StateType state =
3103 m_current_private_state_thread_sp->GetPrivateState();
3104 return state != lldb::eStateInvalid && state != lldb::eStateDetached &&
3105 state != lldb::eStateExited;
3106 }
3107
3109
3110 /// Loads any plugins associated with asynchronous structured data and maps
3111 /// the relevant supported type name to the plugin.
3112 ///
3113 /// Processes can receive asynchronous structured data from the process
3114 /// monitor. This method will load and map any structured data plugins that
3115 /// support the given set of supported type names. Later, if any of these
3116 /// features are enabled, the process monitor is free to generate
3117 /// asynchronous structured data. The data must come in as a single \b
3118 /// StructuredData::Dictionary. That dictionary must have a string field
3119 /// named 'type', with a value that equals the relevant type name string
3120 /// (one of the values in \b supported_type_names).
3121 ///
3122 /// \param[in] supported_type_names
3123 /// An array of zero or more type names. Each must be unique.
3124 /// For each entry in the list, a StructuredDataPlugin will be
3125 /// searched for that supports the structured data type name.
3127 const StructuredData::Array &supported_type_names);
3128
3129 /// Route the incoming structured data dictionary to the right plugin.
3130 ///
3131 /// The incoming structured data must be a dictionary, and it must have a
3132 /// key named 'type' that stores a string value. The string value must be
3133 /// the name of the structured data feature that knows how to handle it.
3134 ///
3135 /// \param[in] object_sp
3136 /// When non-null and pointing to a dictionary, the 'type'
3137 /// key's string value is used to look up the plugin that
3138 /// was registered for that structured data type. It then
3139 /// calls the following method on the StructuredDataPlugin
3140 /// instance:
3141 ///
3142 /// virtual void
3143 /// HandleArrivalOfStructuredData(Process &process,
3144 /// llvm::StringRef type_name,
3145 /// const StructuredData::ObjectSP
3146 /// &object_sp)
3147 ///
3148 /// \return
3149 /// True if the structured data was routed to a plugin; otherwise,
3150 /// false.
3152
3153 /// Check whether the process supports memory tagging.
3154 ///
3155 /// \return
3156 /// true if the process supports memory tagging,
3157 /// false otherwise.
3158 virtual bool SupportsMemoryTagging() { return false; }
3159
3160 /// Does the final operation to read memory tags. E.g. sending a GDB packet.
3161 /// It assumes that ReadMemoryTags has checked that memory tagging is enabled
3162 /// and has expanded the memory range as needed.
3163 ///
3164 /// \param[in] addr
3165 /// Start of address range to read memory tags for.
3166 ///
3167 /// \param[in] len
3168 /// Length of the memory range to read tags for (in bytes).
3169 ///
3170 /// \param[in] type
3171 /// Type of tags to read (get this from a MemoryTagManager)
3172 ///
3173 /// \return
3174 /// The packed tag data received from the remote or an error
3175 /// if the read failed.
3176 virtual llvm::Expected<std::vector<uint8_t>>
3177 DoReadMemoryTags(lldb::addr_t addr, size_t len, int32_t type) {
3178 return llvm::createStringError(
3179 llvm::inconvertibleErrorCode(),
3180 llvm::formatv("{0} does not support reading memory tags",
3181 GetPluginName()));
3182 }
3183
3184 /// Does the final operation to write memory tags. E.g. sending a GDB packet.
3185 /// It assumes that WriteMemoryTags has checked that memory tagging is enabled
3186 /// and has packed the tag data.
3187 ///
3188 /// \param[in] addr
3189 /// Start of address range to write memory tags for.
3190 ///
3191 /// \param[in] len
3192 /// Length of the memory range to write tags for (in bytes).
3193 ///
3194 /// \param[in] type
3195 /// Type of tags to read (get this from a MemoryTagManager)
3196 ///
3197 /// \param[in] tags
3198 /// Packed tags to be written.
3199 ///
3200 /// \return
3201 /// Status telling you whether the write succeeded.
3202 virtual Status DoWriteMemoryTags(lldb::addr_t addr, size_t len, int32_t type,
3203 const std::vector<uint8_t> &tags) {
3205 "{0} does not support writing memory tags", GetPluginName());
3206 }
3207
3208 // Type definitions
3209 typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP>
3211
3213 bool (*callback)(void *);
3214 void *baton;
3216 void *in_baton)
3217 : callback(in_callback), baton(in_baton) {}
3219 return callback == rhs.callback && baton == rhs.baton;
3220 }
3221 };
3222
3223 /// The PrivateStateThread struct gathers all the bits of state needed to
3224 /// manage handling Process events, from receiving them on the Private State
3225 /// to signaling when process events are broadcase publicly, to determining
3226 /// when various actors can act on the process. It also holds the current
3227 /// private state thread.
3228 /// These need to be swappable as a group to manage the temporary modal
3229 /// private state thread that we spin up when we need to run an expression on
3230 /// the private state thread.
3233 lldb::StateType private_state,
3234 llvm::StringRef thread_name, bool is_override = false)
3235 : m_process(process), m_public_state(public_state),
3236 m_private_state(private_state), m_is_override(is_override),
3237 m_thread_name(thread_name) {}
3238 // This returns false if we couldn't start up the thread. If that happens,
3239 // you won't be doing any debugging today.
3240 bool StartupThread();
3241
3242 bool IsOnThread(const HostThread &thread) const;
3243
3244 bool IsJoinable() { return m_private_state_thread.IsJoinable(); }
3245
3247 lldb::thread_result_t result = {};
3248 m_private_state_thread.Join(&result);
3249 m_private_state_thread.Reset();
3250 m_is_running = false;
3251 }
3252
3253 bool IsRunning() { return m_is_running; }
3254
3255 bool IsOverride() const { return m_is_override; }
3256
3257 void SetThreadName(llvm::StringRef new_name) { m_thread_name = new_name; }
3258
3260 return m_private_state.GetValue();
3261 }
3262
3263 lldb::StateType GetPublicState() const { return m_public_state.GetValue(); }
3264
3266 m_public_state.SetValue(new_value);
3267 }
3268
3270 m_private_state.SetValue(new_value);
3271 }
3272
3273 std::recursive_mutex &GetPrivateStateMutex() {
3274 return m_private_state.GetMutex();
3275 }
3276
3278 return m_private_state.GetValueNoLock();
3279 }
3280
3282 m_private_state.SetValueNoLock(new_state);
3283 }
3284
3286 m_public_state.SetValueNoLock(new_state);
3287 }
3288
3289 bool SetPublicRunLockToRunning() { return m_public_run_lock.SetRunning(); }
3290
3292 return m_private_run_lock.SetRunning();
3293 }
3294
3295 bool SetPublicRunLockToStopped() { return m_public_run_lock.SetStopped(); }
3296
3298 return m_private_run_lock.SetStopped();
3299 }
3300
3303 return m_private_run_lock;
3304 else
3305 return m_public_run_lock;
3306 }
3307
3309 ///< The process state that we show to client code. This will often differ
3310 ///< from the actual process state, for instance when we've stopped in the
3311 ///< middle of a ThreadPlan's operations, before we've decided to stop or
3312 ///< continue.
3314 ///< The actual state of our process
3316 ///< HostThread for the thread that watches for internal state events
3318 //< These are the locks that client code acquires both to wait on the
3319 //< process stopping, and then to ensure that it stays in the stopped state
3320 //< while the client code is operating on it. Again, we need a parallel
3321 //set, < one for public client code and one for code working on behalf of
3322 //the < private state management.
3325 bool m_is_running = false;
3326 bool m_is_override = false;
3327 ///< This will be the thread name given to the Private State HostThread when
3328 ///< it gets spun up.
3329 std::string m_thread_name;
3330 };
3331
3335 return m_current_private_state_thread_sp->SetPrivateRunLockToStopped();
3336 return false;
3337 }
3341 return m_current_private_state_thread_sp->SetPrivateRunLockToRunning();
3342 return false;
3343 }
3347 return m_current_private_state_thread_sp->SetPublicRunLockToStopped();
3348 return false;
3349 }
3353 return m_current_private_state_thread_sp->SetPublicRunLockToRunning();
3354 return false;
3355 }
3356
3357 std::recursive_mutex &GetPrivateStateMutex() {
3359 return m_current_private_state_thread_sp->GetPrivateStateMutex();
3360 }
3361
3367
3373
3376 return lldb::eStateUnloaded;
3377 return m_current_private_state_thread_sp->GetPrivateStateNoLock();
3378 }
3379
3382 m_current_private_state_thread_sp->SetPrivateStateNoLock(new_state);
3383 }
3384
3385 // Member variables
3386 std::weak_ptr<Target> m_target_wp; ///< The target that owns this process.
3388 Broadcaster m_private_state_broadcaster; // This broadcaster feeds state
3389 // changed events into the private
3390 // state thread's listener.
3392 // broadcaster, used to
3393 // pause, resume & stop the
3394 // private state thread.
3395 lldb::ListenerSP m_private_state_listener_sp; // This is the listener for the
3396 // private state thread.
3397 /// This is filled on construction with the "main" private state which will
3398 /// be exposed to clients of this process. It won't have a running private
3399 /// state thread until you call StartupThread. This needs to be a pointer
3400 /// so I can transparently swap it out for the modal one, but there will
3401 /// always be a private state thread in this slot.
3402 std::shared_ptr<PrivateStateThread> m_current_private_state_thread_sp;
3403
3404 ProcessModID m_mod_id; ///< Tracks the state of the process over stops and
3405 ///other alterations.
3406 uint32_t m_process_unique_id; ///< Each lldb_private::Process class that is
3407 ///created gets a unique integer ID that
3408 ///increments with each new instance
3409 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index
3410 ///that won't get re-used.
3411 std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map;
3412 int m_exit_status; ///< The exit status of the process, or -1 if not set.
3413 std::string m_exit_string; ///< A textual description of why a process exited.
3414 std::mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can
3415 ///be safely accessed from multiple threads
3416 std::recursive_mutex m_thread_mutex;
3417 ThreadList m_thread_list_real; ///< The threads for this process as are known
3418 ///to the protocol we are debugging with
3419 ThreadList m_thread_list; ///< The threads for this process as the user will
3420 ///see them. This is usually the same as
3421 ///< m_thread_list_real, but might be different if there is an OS plug-in
3422 ///creating memory threads
3423 ThreadPlanStackMap m_thread_plans; ///< This is the list of thread plans for
3424 /// threads in m_thread_list, as well as
3425 /// threads we knew existed, but haven't
3426 /// determined that they have died yet.
3428 m_extended_thread_list; ///< Constituent for extended threads that may be
3429 /// generated, cleared on natural stops
3430 lldb::RunDirection m_base_direction; ///< ThreadPlanBase run direction
3431 uint32_t m_extended_thread_stop_id; ///< The natural stop id when
3432 ///extended_thread_list was last updated
3433 QueueList
3434 m_queue_list; ///< The list of libdispatch queues at a given stop point
3435 uint32_t m_queue_list_stop_id; ///< The natural stop id when queue list was
3436 ///last fetched
3438 m_watchpoint_resource_list; ///< Watchpoint resources currently in use.
3439 std::vector<Notifications> m_notifications; ///< The list of notifications
3440 ///that this process can deliver.
3441 std::vector<lldb::addr_t> m_image_tokens;
3443 m_breakpoint_site_list; ///< This is the list of breakpoint
3444 /// locations we intend to insert in
3445 /// the target.
3449 /// by the expression
3450 /// parser to validate
3451 /// data that
3452 /// expressions use.
3456 m_unix_signals_sp; /// This is the current signal set for this process.
3461 std::recursive_mutex m_stdio_communication_mutex;
3462 bool m_stdin_forward; /// Remember if stdin must be forwarded to remote debug
3463 /// server
3464 std::string m_stdout_data;
3465 std::string m_stderr_data;
3466 std::recursive_mutex m_profile_data_comm_mutex;
3467 std::vector<std::string> m_profile_data;
3471 bool m_should_detach; /// Should we detach if the process object goes away
3472 /// with an explicit call to Kill or Detach?
3474 std::recursive_mutex m_language_runtimes_mutex;
3476 std::unique_ptr<NextEventAction> m_next_event_action_up;
3477 std::vector<PreResumeCallbackAndBaton> m_pre_resume_actions;
3479 bool m_resume_requested; // If m_currently_handling_event or
3480 // m_currently_handling_do_on_removals are true,
3481 // Resume will only request a resume, using this
3482 // flag to check.
3483
3484 lldb::tid_t m_interrupt_tid; /// The tid of the thread that issued the async
3485 /// interrupt, used by thread plan timeout. It
3486 /// can be LLDB_INVALID_THREAD_ID to indicate
3487 /// user level async interrupt.
3488
3489 /// This is set at the beginning of Process::Finalize() to stop functions
3490 /// from looking up or creating things during or after a finalize call.
3491 std::atomic<bool> m_finalizing;
3492 // When we are "Finalizing" we need to do some cleanup. But if the Finalize
3493 // call is coming in the Destructor, we can't do any actual work in the
3494 // process because that is likely to call "shared_from_this" which crashes
3495 // if run while destructing. We use this flag to determine that.
3496 std::atomic<bool> m_destructing;
3497
3498 /// Mask for code an data addresses.
3499 /// The default value LLDB_INVALID_ADDRESS_MASK means no mask has been set,
3500 /// and addresses values should not be modified.
3501 /// In these masks, the bits are set to 1 indicate bits that are not
3502 /// significant for addressing.
3503 /// The highmem masks are for targets where we may have different masks
3504 /// for low memory versus high memory addresses, and they will be left
3505 /// as LLDB_INVALID_ADDRESS_MASK normally, meaning the base masks
3506 /// should be applied to all addresses.
3507 /// @{
3512 /// @}
3513
3516 lldb::StateType m_last_broadcast_state; /// This helps with the Public event
3517 /// coalescing in
3518 /// ShouldBroadcastEvent.
3519 std::map<lldb::addr_t, lldb::addr_t> m_resolved_indirect_addresses;
3521 bool m_can_interpret_function_calls; // Some targets, e.g the OSX kernel,
3522 // don't support the ability to modify
3523 // the stack.
3525 llvm::StringMap<lldb::StructuredDataPluginSP> m_structured_data_plugin_map;
3526
3528
3529 std::unique_ptr<UtilityFunction> m_dlopen_utility_func_up;
3531
3532 /// Per process source file cache.
3534
3535 /// A repository for extra crash information, consulted in
3536 /// GetExtendedCrashInformation.
3538
3539 size_t RemoveBreakpointOpcodesFromBuffer(lldb::addr_t addr, size_t size,
3540 uint8_t *buf) const;
3541
3543
3544 void SetPublicState(lldb::StateType new_state, bool restarted);
3545
3546 void SetPrivateState(lldb::StateType state);
3547
3548 // Starts the private state thread and assigns it to
3549 // m_current_private_state_thread_sp. If backup_ptr is non-null, this is
3550 // a "secondary" thread, and the current thread will be backed up into
3551 // backup_ptr before being replaced by the new thread. Pass a non-null
3552 // backup_ptr in the case where you have to temporarily spin up a secondary
3553 // state thread to handle events from a hand-called function on the primary
3554 // private state thread.
3556 lldb::StateType state, bool run_lock_is_running,
3557 std::shared_ptr<PrivateStateThread> *backup_ptr = nullptr);
3558
3560
3562
3564
3565private:
3566 // Starts up the private state thread that will watch for events from the
3567 // debugee.
3568
3570
3571protected:
3572 void HandlePrivateEvent(lldb::EventSP &event_sp);
3573
3575
3577 const Timeout<std::micro> &timeout);
3578
3579 // This waits for both the state change broadcaster, and the control
3580 // broadcaster. If control_only, it only waits for the control broadcaster.
3581
3582 bool GetEventsPrivate(lldb::EventSP &event_sp,
3583 const Timeout<std::micro> &timeout, bool control_only);
3584
3587 const Timeout<std::micro> &timeout);
3588
3589 size_t WriteMemoryPrivate(lldb::addr_t addr, const void *buf, size_t size,
3590 Status &error);
3591
3592 void AppendSTDOUT(const char *s, size_t len);
3593
3594 void AppendSTDERR(const char *s, size_t len);
3595
3596 void BroadcastAsyncProfileData(const std::string &one_profile_data);
3597
3598 static void STDIOReadThreadBytesReceived(void *baton, const void *src,
3599 size_t src_len);
3600
3601 bool PushProcessIOHandler();
3602
3603 bool PopProcessIOHandler();
3604
3606
3608 std::lock_guard<std::mutex> guard(m_process_input_reader_mutex);
3609 return static_cast<bool>(m_process_input_reader);
3610 }
3611
3613
3615
3616 void LoadOperatingSystemPlugin(bool flush);
3617
3619
3620private:
3621 Status DestroyImpl(bool force_kill);
3622
3623 /// This is the part of the event handling that for a process event. It
3624 /// decides what to do with the event and returns true if the event needs to
3625 /// be propagated to the user, and false otherwise. If the event is not
3626 /// propagated, this call will most likely set the target to executing
3627 /// again. There is only one place where this call should be called,
3628 /// HandlePrivateEvent. Don't call it from anywhere else...
3629 ///
3630 /// \param[in] event_ptr
3631 /// This is the event we are handling.
3632 ///
3633 /// \return
3634 /// Returns \b true if the event should be reported to the
3635 /// user, \b false otherwise.
3636 bool ShouldBroadcastEvent(Event *event_ptr);
3637
3638 void ControlPrivateStateThread(uint32_t signal);
3639
3641 lldb::EventSP &event_sp);
3642
3643 lldb::EventSP CreateEventFromProcessState(uint32_t event_type);
3644
3645 Process(const Process &) = delete;
3646 const Process &operator=(const Process &) = delete;
3647};
3648
3649/// RAII guard that should be acquired when an utility function is called within
3650/// a given process.
3653
3654public:
3656 if (m_process)
3657 m_process->SetRunningUtilityFunction(true);
3658 }
3660 if (m_process)
3661 m_process->SetRunningUtilityFunction(false);
3662 }
3663};
3664
3665/// RAII guard that marks the current thread as a private state thread.
3666///
3667/// When RunThreadPlan detects it is running on the private state thread, it
3668/// spins up an override thread and reassigns m_current_private_state_thread_sp
3669/// to it. The original PST continues processing events via DoOnRemoval
3670/// callbacks, but CurrentThreadIsPrivateStateThread() no longer recognizes it.
3671/// This guard sets a thread_local flag so that GetStackFrameList can identify
3672/// the original PST and return parent frames instead of provider-augmented
3673/// frames.
3686
3687} // namespace lldb_private
3688
3689#endif // LLDB_TARGET_PROCESS_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address range class.
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:32
void Clear()
Clears the object state.
Definition ArchSpec.cpp:538
A command line argument class.
Definition Args.h:33
Class that manages the actual breakpoint that will be inserted into the running program.
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Listen for any events specified by event_mask.
Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name)
Construct with a broadcaster with a name.
An data extractor class.
A class to manage flag bits.
Definition Debugger.h:100
Encapsulates dynamic check functions used by expressions.
A plug-in interface definition class for dynamic loaders.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition FileSpec.h:57
static lldb::thread_t GetCurrentThread()
Get the thread token (the one returned by ThreadCreate when the thread was created) for the calling t...
Class used by the Process to hold a list of its JITLoaders.
A collection class for Module objects.
Definition ModuleList.h:125
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
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:79
virtual llvm::StringRef GetPluginName()=0
A C++ wrapper class for providing threaded access to a value of type T.
Definition Predicate.h:42
void SetDetachOnError(bool enable)
Definition Process.h:187
bool ProcessInfoSpecified() const
Definition Process.h:175
ProcessAttachInfo(const ProcessLaunchInfo &launch_info)
Definition Process.h:131
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
lldb::ListenerSP GetListenerForProcess(Debugger &debugger)
Definition Process.cpp:3068
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
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:338
uint32_t m_running_utility_function
Definition Process.h:334
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:333
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:329
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:332
uint32_t GetLastNaturalStopID() const
Definition Process.h:252
lldb::EventSP m_last_natural_stop_event
Definition Process.h:335
uint32_t GetLastUserExpressionResumeID() const
Definition Process.h:255
bool MemoryIDEqual(const ProcessModID &compare) const
Definition Process.h:259
void Dump(Stream &stream) const
Definition Process.h:315
bool StopIDEqual(const ProcessModID &compare) const
Definition Process.h:263
void SetRunningUtilityFunction(bool on)
Definition Process.h:294
bool GetSteppingRunsAllThreads() const
Definition Process.cpp:339
void SetStopOnSharedLibraryEvents(bool stop)
Definition Process.cpp:270
std::unique_ptr< ProcessExperimentalProperties > m_experimental_properties_up
Definition Process.h:120
FollowForkMode GetFollowForkMode() const
Definition Process.cpp:376
uint32_t GetVirtualAddressableBits() const
Definition Process.cpp:215
void SetIgnoreBreakpointsInExpressions(bool ignore)
Definition Process.cpp:248
bool GetUnwindOnErrorInExpressions() const
Definition Process.cpp:253
std::chrono::seconds GetInterruptTimeout() const
Definition Process.cpp:332
bool GetDisableLangRuntimeUnwindPlans() const
Definition Process.cpp:275
void SetDetachKeepsStopped(bool keep_stopped)
Definition Process.cpp:302
void SetDisableLangRuntimeUnwindPlans(bool disable)
Definition Process.cpp:281
std::chrono::seconds GetUtilityExpressionTimeout() const
Definition Process.cpp:325
void SetVirtualAddressableBits(uint32_t bits)
Definition Process.cpp:221
bool GetStopOnSharedLibraryEvents() const
Definition Process.cpp:264
void SetHighmemVirtualAddressableBits(uint32_t bits)
Definition Process.cpp:232
void SetOSPluginReportsAllThreads(bool does_report)
Definition Process.cpp:366
void SetUnwindOnErrorInExpressions(bool ignore)
Definition Process.cpp:259
FileSpec GetPythonOSPluginPath() const
Definition Process.cpp:210
void SetPythonOSPluginPath(const FileSpec &file)
Definition Process.cpp:237
void SetExtraStartupCommands(const Args &args)
Definition Process.cpp:205
bool GetOSPluginReportsAllThreads() const
Definition Process.cpp:352
bool GetWarningsUnsupportedLanguage() const
Definition Process.cpp:313
uint32_t GetHighmemVirtualAddressableBits() const
Definition Process.cpp:226
bool GetIgnoreBreakpointsInExpressions() const
Definition Process.cpp:242
uint64_t GetMemoryCacheLineSize() const
Definition Process.cpp:192
ProcessProperties(lldb_private::Process *process)
Definition Process.cpp:153
A class used to prevent the process from starting while other threads are accessing its data,...
EventActionResult HandleBeingInterrupted() override
Definition Process.cpp:3060
EventActionResult PerformAction(lldb::EventSP &event_sp) override
Definition Process.cpp:3003
AttachCompletionHandler(Process *process, uint32_t exec_count)
Definition Process.cpp:2992
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:4599
virtual bool ShouldStop(Event *event_ptr, bool &found_valid_stopinfo)
Definition Process.cpp:4372
static void AddRestartedReason(Event *event_ptr, const char *reason)
Definition Process.cpp:4636
void SetInterrupted(bool new_value)
Definition Process.h:488
lldb::ProcessSP GetProcessSP() const
Definition Process.h:436
std::vector< std::string > m_restarted_reasons
Definition Process.h:496
void SetRestarted(bool new_value)
Definition Process.h:486
static void SetRestartedInEvent(Event *event_ptr, bool new_value)
Definition Process.cpp:4607
const ProcessEventData & operator=(const ProcessEventData &)=delete
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Process.cpp:4583
static void SetInterruptedInEvent(Event *event_ptr, bool new_value)
Definition Process.cpp:4653
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:4476
ProcessEventData(const ProcessEventData &)=delete
llvm::StringRef GetFlavor() const override
Definition Process.cpp:4368
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition Process.cpp:4644
const char * GetRestartedReasonAtIndex(size_t idx)
Definition Process.h:443
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition Process.cpp:4591
lldb::StateType GetState() const
Definition Process.h:438
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Process.cpp:4572
static llvm::StringRef GetFlavorString()
Definition Process.cpp:4364
void DoOnRemoval(Event *event_ptr) override
Definition Process.cpp:4487
void AddRestartedReason(const char *reason)
Definition Process.h:490
void Dump(Stream *s) const override
Definition Process.cpp:4559
ProcessEventHijacker(Process &process, lldb::ListenerSP listener_sp)
Definition Process.h:2419
A plug-in interface definition class for debugging a process.
Definition Process.h:355
virtual Status EnableBreakpointSite(BreakpointSite *bp_site)
Definition Process.h:2247
Status WillAttachToProcessWithName(const char *process_name, bool wait_for_launch)
Called before attaching to a process.
Definition Process.cpp:3083
virtual llvm::Expected< TraceSupportedResponse > TraceSupported()
Get the processor tracing type supported for this process.
Definition Process.cpp:6586
lldb::IOHandlerSP m_process_input_reader
Definition Process.h:3458
friend class ProcessProperties
Definition Process.h:2431
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:6576
virtual void DidVForkDone()
Called after reported vfork completion.
Definition Process.h:1037
virtual void DidFork(lldb::pid_t child_pid, lldb::tid_t child_tid)
Called after a reported fork.
Definition Process.h:1031
virtual Status DoSignal(int signal)
Sends a process a UNIX signal signal.
Definition Process.h:1198
virtual Status WillResume()
Called before resuming to a process.
Definition Process.h:1085
std::mutex m_process_input_reader_mutex
Definition Process.h:3459
lldb::addr_t m_code_address_mask
Mask for code an data addresses.
Definition Process.h:3508
StopPointSiteList< lldb_private::BreakpointSite > & GetBreakpointSiteList()
Definition Process.cpp:1538
std::vector< lldb::addr_t > m_image_tokens
Definition Process.h:3441
virtual Status DoHalt(bool &caused_stop)
Halts a running process.
Definition Process.h:1145
virtual void DidLaunch()
Called after launching a process.
Definition Process.h:1077
virtual Status DisableSoftwareBreakpoint(BreakpointSite *bp_site)
Definition Process.cpp:1814
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition Process.h:538
lldb::EventSP GetStopEventForStopID(uint32_t stop_id) const
Definition Process.h:1499
lldb::break_id_t CreateBreakpointSite(const lldb::BreakpointLocationSP &owner, bool use_hardware)
Definition Process.cpp:1649
virtual Status WillSignal()
Called before sending a signal to a process.
Definition Process.h:1192
void ResetImageToken(size_t token)
Definition Process.cpp:6360
lldb::JITLoaderListUP m_jit_loaders_up
Definition Process.h:3447
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:2572
void SetNextEventAction(Process::NextEventAction *next_event_action)
Definition Process.h:3074
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:3669
virtual Status WillDetach()
Called before detaching from a process.
Definition Process.h:1162
virtual Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info)
Launch a new process.
Definition Process.h:1069
virtual size_t PutSTDIN(const char *buf, size_t buf_size, Status &error)
Puts data into this process's STDIN.
Definition Process.h:2224
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:3443
void ControlPrivateStateThread(uint32_t signal)
Definition Process.cpp:4030
ThreadList & GetThreadList()
Definition Process.h:2312
void SetAddressableBitMasks(AddressableBits bit_masks)
Definition Process.cpp:7004
virtual DataExtractor GetAuxvData()
Definition Process.cpp:2972
virtual std::optional< uint32_t > GetWatchpointSlotCount()
Get the number of watchpoints supported by this target.
Definition Process.h:2027
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:625
Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
Construct with a shared pointer to a target, and the Process listener.
Definition Process.cpp:432
lldb::ExpressionResults RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager)
Definition Process.cpp:5149
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:6285
Status LaunchPrivate(ProcessLaunchInfo &launch_info, lldb::StateType &state, lldb::EventSP &event_sp)
Definition Process.cpp:2771
std::vector< std::string > m_profile_data
Definition Process.h:3467
bool m_can_interpret_function_calls
Definition Process.h:3521
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition Process.cpp:1309
void PruneThreadPlans()
Prune ThreadPlanStacks for all unreported threads.
Definition Process.cpp:1203
void SetUnixSignals(lldb::UnixSignalsSP &&signals_sp)
Definition Process.cpp:3760
virtual void DidExit()
Definition Process.h:1435
std::string m_stdout_data
Remember if stdin must be forwarded to remote debug server.
Definition Process.h:3464
bool RemoveInvalidMemoryRange(const LoadRange &region)
Definition Process.cpp:6036
uint32_t GetNextThreadIndexID(uint64_t thread_id)
Definition Process.cpp:1241
Status PrivateResume()
The "private" side of resuming a process.
Definition Process.cpp:3396
void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers)
Definition Process.cpp:1534
QueueList::QueueIterable Queues()
Definition Process.h:2348
void SendAsyncInterrupt(Thread *thread=nullptr)
Send an async interrupt request.
Definition Process.cpp:4078
uint32_t GetResumeID() const
Definition Process.h:1489
void AddInvalidMemoryRegion(const LoadRange &region)
Definition Process.cpp:6032
virtual void ModulesDidLoad(ModuleList &module_list)
Definition Process.cpp:6243
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:1549
InstrumentationRuntimeCollection m_instrumentation_runtimes
Definition Process.h:3475
std::atomic< bool > m_destructing
Definition Process.h:3496
std::shared_ptr< PrivateStateThread > m_current_private_state_thread_sp
This is filled on construction with the "main" private state which will be exposed to clients of this...
Definition Process.h:3402
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:2999
@ eBroadcastInternalStateControlResume
Definition Process.h:384
@ eBroadcastInternalStateControlStop
Definition Process.h:382
@ eBroadcastInternalStateControlPause
Definition Process.h:383
int GetExitStatus()
Get the exit status for a process.
Definition Process.cpp:1009
OperatingSystem * GetOperatingSystem()
Definition Process.h:2457
Status WillAttachToProcessWithID(lldb::pid_t pid)
Called before attaching to a process.
Definition Process.cpp:3079
virtual Status DoDetach(bool keep_stopped)
Detaches from a running or stopped process.
Definition Process.h:1169
std::unique_ptr< UtilityFunction > m_dlopen_utility_func_up
Definition Process.h:3529
void SetRunningUtilityFunction(bool on)
Definition Process.cpp:1453
void DisableAllBreakpointSites()
Definition Process.cpp:1547
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:3406
int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, int64_t fail_value, Status &error)
Definition Process.cpp:2366
Address AdvanceAddressToNextBranchInstruction(Address default_stop_addr, AddressRange range_bounds)
Find the next branch instruction to set a breakpoint on.
Definition Process.cpp:6366
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:2673
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:737
bool SetPublicRunLockToRunning()
Definition Process.h:3350
virtual size_t GetAsyncProfileData(char *buf, size_t buf_size, Status &error)
Get any available profile data.
Definition Process.cpp:4742
lldb::addr_t FixDataAddress(lldb::addr_t pc)
Definition Process.cpp:6165
lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, Status &error)
The public interface to allocating memory in the process.
Definition Process.cpp:2561
std::unique_ptr< NextEventAction > m_next_event_action_up
Definition Process.h:3476
void SetHighmemDataAddressMask(lldb::addr_t data_address_mask)
Definition Process.cpp:6152
bool PruneThreadPlansForTID(lldb::tid_t tid)
Prune ThreadPlanStacks for unreported threads.
Definition Process.cpp:1199
virtual void DidDetach()
Called after detaching from a process.
Definition Process.h:1179
std::function< IterationAction(lldb_private::Status &error, lldb::addr_t bytes_addr, const void *bytes, lldb::offset_t bytes_size)> ReadMemoryChunkCallback
Definition Process.h:1648
Status EnableBreakpointSiteByID(lldb::user_id_t break_id)
Definition Process.cpp:1577
ProcessModID GetModID() const
Get the Modification ID of the process.
Definition Process.h:1483
lldb::RunDirection GetBaseDirection() const
Get the base run direction for the process.
Definition Process.h:2855
size_t ReadMemoryFromInferior(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2243
size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Status &error)
Definition Process.cpp:2518
virtual Status Launch(ProcessLaunchInfo &launch_info)
Launch a new process.
Definition Process.cpp:2732
DynamicCheckerFunctions * GetDynamicCheckers()
Definition Process.h:2467
std::mutex m_run_thread_plan_lock
Definition Process.h:3524
static void SettingsInitialize()
Definition Process.cpp:5012
virtual StructuredData::DictionarySP GetMetadata()
Fetch process defined metadata.
Definition Process.h:2711
virtual void DumpPluginHistory(Stream &s)
The underlying plugin might store the low-level communication history for this session.
Definition Process.h:591
static constexpr llvm::StringRef AttachSynchronousHijackListenerName
Definition Process.h:400
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:4726
void Flush()
Flush all data in the process.
Definition Process.cpp:6092
bool m_clear_thread_plans_on_stop
Definition Process.h:3514
lldb::ProcessSP CalculateProcess() override
Definition Process.h:2567
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:2197
void ResumePrivateStateThread()
Definition Process.cpp:4012
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:6474
bool GetEventsPrivate(lldb::EventSP &event_sp, const Timeout< std::micro > &timeout, bool control_only)
Definition Process.cpp:992
lldb::ABISP m_abi_sp
This is the current signal set for this process.
Definition Process.h:3457
virtual void DidSignal()
Called after sending a signal to a process.
Definition Process.h:1216
virtual SystemRuntime * GetSystemRuntime()
Get the system runtime plug-in for this process.
Definition Process.cpp:2986
std::map< uint64_t, uint32_t > m_thread_id_to_index_id_map
Definition Process.h:3411
lldb::StateType GetPrivateState() const
Definition Process.h:3368
void SetPrivateStateNoLock(lldb::StateType new_state)
Definition Process.h:3380
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:1207
lldb::ListenerSP m_private_state_listener_sp
Definition Process.h:3395
uint32_t m_extended_thread_stop_id
The natural stop id when extended_thread_list was last updated.
Definition Process.h:3431
bool PreResumeActionCallback(void *)
Definition Process.h:2637
lldb::RunDirection m_base_direction
ThreadPlanBase run direction.
Definition Process.h:3430
Range< lldb::addr_t, lldb::addr_t > LoadRange
Definition Process.h:387
static constexpr llvm::StringRef ResumeSynchronousHijackListenerName
Definition Process.h:404
bool WritePointerToMemory(lldb::addr_t vm_addr, lldb::addr_t ptr_value, Status &error)
Definition Process.cpp:2391
QueueList m_queue_list
The list of libdispatch queues at a given stop point.
Definition Process.h:3434
void ClearPreResumeAction(PreResumeActionCallback callback, void *baton)
Definition Process.cpp:6060
virtual Status WillDestroy()
Definition Process.h:1204
lldb::ThreadSP CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context)
Definition Process.cpp:1234
std::vector< PreResumeCallbackAndBaton > m_pre_resume_actions
Definition Process.h:3477
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition Process.cpp:2611
lldb::StateType GetStateChangedEventsPrivate(lldb::EventSP &event_sp, const Timeout< std::micro > &timeout)
Definition Process.cpp:974
void LoadOperatingSystemPlugin(bool flush)
Definition Process.cpp:2723
lldb::StructuredDataPluginSP GetStructuredDataPlugin(llvm::StringRef type_name) const
Returns the StructuredDataPlugin associated with a given type name, if there is one.
Definition Process.cpp:4734
lldb::DynamicLoaderUP m_dyld_up
Definition Process.h:3446
ThreadList & GetExtendedThreadList()
Definition Process.h:2323
void ResetExtendedCrashInfoDict()
Definition Process.h:2721
AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size, const AddressRanges &ranges, size_t alignment, size_t max_matches, Status &error)
Definition Process.cpp:2029
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:6343
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:1767
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:2932
virtual Status WriteObjectFile(std::vector< ObjectFile::LoadableData > entries)
Definition Process.cpp:2550
std::recursive_mutex m_stdio_communication_mutex
Definition Process.h:3461
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:389
std::map< lldb::LanguageType, lldb::LanguageRuntimeSP > LanguageRuntimeCollection
Definition Process.h:3210
virtual bool SupportsReverseDirection()
Reports whether this process supports reverse execution.
Definition Process.h:1092
StopPointSiteList< lldb_private::WatchpointResource > m_watchpoint_resource_list
Watchpoint resources currently in use.
Definition Process.h:3438
Status DisableBreakpointSiteByID(lldb::user_id_t break_id)
Definition Process.cpp:1563
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:6651
~Process() override
Destructor.
Definition Process.cpp:523
virtual llvm::Expected< LoadedModuleInfoList > GetLoadedModuleList()
Query remote GDBServer for a detailed loaded library list.
Definition Process.h:695
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:3202
friend class StopInfo
Definition Process.h:360
std::recursive_mutex m_profile_data_comm_mutex
Definition Process.h:3466
lldb::InstrumentationRuntimeSP GetInstrumentationRuntime(lldb::InstrumentationRuntimeType type)
Definition Process.cpp:6334
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:394
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition Process.cpp:1326
virtual Status SendEventData(const char *data)
Definition Process.h:2653
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:6171
lldb::thread_result_t RunPrivateStateThread(bool is_override)
Definition Process.cpp:4212
virtual Status DoWillLaunch(Module *module)
Called before launching to a process.
Definition Process.h:1050
virtual Status ConnectRemote(llvm::StringRef remote_url)
Attach to a remote system via a URL.
Definition Process.cpp:3345
void AppendSTDOUT(const char *s, size_t len)
Definition Process.cpp:4705
llvm::StringMap< lldb::StructuredDataPluginSP > m_structured_data_plugin_map
Definition Process.h:3525
SourceManager::SourceFileCache m_source_file_cache
Per process source file cache.
Definition Process.h:3533
virtual Status DisableBreakpointSite(BreakpointSite *bp_site)
Definition Process.h:2252
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:5986
void CalculateExecutionContext(ExecutionContext &exe_ctx) override
Reconstruct the object's execution context into sc.
Definition Process.cpp:4673
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:1911
Event * PeekAtStateChangedEvents()
Definition Process.cpp:957
std::vector< Notifications > m_notifications
The list of notifications that this process can deliver.
Definition Process.h:3439
bool HasAssignedIndexIDToThread(uint64_t sb_thread_id)
Definition Process.cpp:1245
llvm::SmallVector< std::optional< uint64_t > > ReadUnsignedIntegersFromMemory(llvm::ArrayRef< lldb::addr_t > addresses, unsigned byte_size)
Use Process::ReadMemoryRanges to efficiently read multiple unsigned integers from memory at once.
Definition Process.cpp:2328
size_t AddImageToken(lldb::addr_t image_ptr)
Definition Process.cpp:6349
lldb::StateType GetPrivateStateNoLock() const
Definition Process.h:3374
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:1998
virtual bool DestroyRequiresHalt()
Definition Process.h:1210
lldb::EventSP CreateEventFromProcessState(uint32_t event_type)
Definition Process.cpp:4699
StructuredData::DictionarySP m_crash_info_dict_sp
A repository for extra crash information, consulted in GetExtendedCrashInformation.
Definition Process.h:3537
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:6935
lldb::ThreadSP CalculateThread() override
Definition Process.h:2569
lldb::TargetSP CalculateTarget() override
Definition Process.cpp:4671
bool SetPublicRunLockToStopped()
Definition Process.h:3344
void SetHighmemCodeAddressMask(lldb::addr_t code_address_mask)
Definition Process.cpp:6145
virtual lldb_private::StructuredData::ObjectSP GetSharedCacheInfo()
Definition Process.h:1387
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:1331
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3770
Status Detach(bool keep_stopped)
Detaches from a running or stopped process.
Definition Process.cpp:3617
virtual void DidVFork(lldb::pid_t child_pid, lldb::tid_t child_tid)
Called after a reported vfork.
Definition Process.h:1034
void UpdateThreadListIfNeeded()
Definition Process.cpp:1108
static constexpr llvm::StringRef LaunchSynchronousHijackListenerName
Definition Process.h:402
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:6670
bool IsValid() const
Return whether this object is valid (i.e.
Definition Process.h:573
virtual void DidResume()
Called after resuming a process.
Definition Process.h:1120
virtual void DidExec()
Called after a process re-execs itself.
Definition Process.cpp:6177
void SetCodeAddressMask(lldb::addr_t code_address_mask)
Definition Process.cpp:6133
AllocatedMemoryCache m_allocated_memory_cache
Definition Process.h:3470
ThreadList::ThreadIterable Threads()
Definition Process.h:2325
virtual Status LoadCore()
Definition Process.cpp:2903
uint32_t GetUniqueID() const
Definition Process.h:545
std::mutex m_exit_status_mutex
Mutex so m_exit_status m_exit_string can be safely accessed from multiple threads.
Definition Process.h:3414
Status Signal(int signal)
Sends a process a UNIX signal signal.
Definition Process.cpp:3750
void SetDynamicLoader(lldb::DynamicLoaderUP dyld)
Definition Process.cpp:2968
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:3423
std::recursive_mutex m_thread_mutex
Definition Process.h:3416
virtual Status ConfigureStructuredData(llvm::StringRef type_name, const StructuredData::ObjectSP &config_sp)
Configure asynchronous structured data feature.
Definition Process.cpp:6466
virtual Status DoWillAttachToProcessWithName(const char *process_name, bool wait_for_launch)
Called before attaching to a process.
Definition Process.h:952
bool m_currently_handling_do_on_removals
Definition Process.h:3478
void HandlePrivateEvent(lldb::EventSP &event_sp)
Definition Process.cpp:4090
void BroadcastAsyncProfileData(const std::string &one_profile_data)
Definition Process.cpp:4719
lldb::StateType GetState()
Get accessor for the current process state.
Definition Process.cpp:1259
virtual Status DoWillAttachToProcessWithID(lldb::pid_t pid)
Called before attaching to a process.
Definition Process.h:935
ProcessRunLock & GetRunLock()
Definition Process.cpp:6070
virtual Status DoLoadCore()
Definition Process.h:616
Predicate< uint32_t > m_iohandler_sync
Definition Process.h:3468
virtual llvm::Error TraceStop(const TraceStopRequest &request)
Stop tracing a live process or its threads.
Definition Process.h:2907
LanguageRuntimeCollection m_language_runtimes
Should we detach if the process object goes away with an explicit call to Kill or Detach?
Definition Process.h:3473
virtual Status GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list)
Obtain all the mapped memory regions within this process.
Definition Process.cpp:6429
size_t WriteMemoryPrivate(lldb::addr_t addr, const void *buf, size_t size, Status &error)
Definition Process.cpp:2403
virtual bool StopNoticingNewThreads()
Call this to turn off the stop & notice new threads mode.
Definition Process.h:2559
void GetStatus(Stream &ostrm)
Definition Process.cpp:5966
virtual llvm::VersionTuple GetHostMacCatalystVersion()
Definition Process.h:1244
void SetRunningUserExpression(bool on)
Definition Process.cpp:1449
enum lldb_private::Process::@120260360120067272255351105340035202127223005263 m_can_jit
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition Process.cpp:1513
uint32_t GetIOHandlerID() const
Definition Process.h:2374
llvm::Expected< lldb::ModuleSP > ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Creates and populates a module using an in-memory object file.
Definition Process.cpp:2648
bool CurrentThreadPosesAsPrivateStateThread()
Definition Process.cpp:6082
Process(const Process &)=delete
const Target & GetTarget() const
Get the const target object pointer for this module.
Definition Process.h:1258
virtual FileSpec GetCoreFile() const
Provide a way to retrieve the core dump file that is loaded for debugging.
Definition Process.h:1538
virtual llvm::Error TraceStart(const llvm::json::Value &request)
Start tracing a process or its threads.
Definition Process.h:2895
void RemoveConstituentFromBreakpointSite(lldb::user_id_t site_id, lldb::user_id_t constituent_id, lldb::BreakpointSiteSP &bp_site_sp)
Definition Process.cpp:1684
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:3509
lldb::OperatingSystemUP m_os_up
Definition Process.h:3453
StructuredData::DictionarySP GetExtendedCrashInfoDict()
Fetch extended crash information held by the process.
Definition Process.h:2716
uint32_t GetLastNaturalStopID() const
Definition Process.h:1495
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:669
virtual void ForceScriptedState(lldb::StateType state)
Definition Process.h:2815
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:3030
lldb::UnixSignalsSP m_unix_signals_sp
Definition Process.h:3456
bool StateChangedIsHijackedForSynchronousResume()
Definition Process.cpp:1370
const char * GetExitDescription()
Get a textual description of what the process exited.
Definition Process.cpp:1017
void SetPublicState(lldb::StateType new_state, bool restarted)
Definition Process.cpp:1269
lldb::tid_t m_interrupt_tid
Definition Process.h:3484
void SetDataAddressMask(lldb::addr_t data_address_mask)
Definition Process.cpp:6139
virtual Status DoConnectRemote(llvm::StringRef remote_url)
Attach to a remote system via a URL.
Definition Process.h:964
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:2316
llvm::once_flag m_dlopen_utility_func_flag_once
Definition Process.h:3530
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:1241
virtual void UpdateQueueListIfNeeded()
Definition Process.cpp:1221
virtual Status UpdateAutomaticSignalFiltering()
Definition Process.cpp:6570
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
Definition Process.cpp:1457
std::map< lldb::addr_t, lldb::addr_t > m_resolved_indirect_addresses
This helps with the Public event coalescing in ShouldBroadcastEvent.
Definition Process.h:3519
virtual Status DoAttachToProcessWithID(lldb::pid_t pid, const ProcessAttachInfo &attach_info)
Attach to an existing process using a process ID.
Definition Process.h:982
llvm::SmallVector< std::optional< std::string > > ReadCStringsFromMemory(llvm::ArrayRef< lldb::addr_t > addresses)
Definition Process.cpp:2122
void SetCanRunCode(bool can_run_code)
Sets whether executing code in this process is possible.
Definition Process.cpp:2615
Status ClearBreakpointSiteByID(lldb::user_id_t break_id)
Definition Process.cpp:1554
virtual Status EnableSoftwareBreakpoint(BreakpointSite *bp_site)
Definition Process.cpp:1734
void AppendSTDERR(const char *s, size_t len)
Definition Process.cpp:4712
bool GetShouldDetach() const
Definition Process.h:761
static llvm::StringRef GetStaticBroadcasterClass()
Definition Process.cpp:427
uint32_t m_thread_index_id
Each thread is created with a 1 based index that won't get re-used.
Definition Process.h:3409
bool ProcessIOHandlerExists() const
Definition Process.h:3607
virtual Status DoResume(lldb::RunDirection direction)
Resumes all of a process's threads as configured using the Thread run control functions.
Definition Process.h:1109
bool RouteAsyncStructuredData(const StructuredData::ObjectSP object_sp)
Route the incoming structured data dictionary to the right plugin.
Definition Process.cpp:6541
virtual void DidDestroy()
Definition Process.h:1208
lldb::offset_t ReadMemoryInChunks(lldb::addr_t vm_addr, void *buf, lldb::addr_t chunk_size, lldb::offset_t total_size, ReadMemoryChunkCallback callback)
Read of memory from a process in discrete chunks, terminating either when all bytes are read,...
Definition Process.cpp:2272
virtual void WillPublicStop()
Called when the process is about to broadcast a public stop.
Definition Process.h:797
friend class Trace
Definition Process.h:2865
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition Process.cpp:2377
virtual void PrefetchModuleSpecs(llvm::ArrayRef< FileSpec > module_file_specs, const llvm::Triple &triple)
Definition Process.h:2684
Broadcaster m_private_state_control_broadcaster
Definition Process.h:3391
const std::vector< lldb::addr_t > & GetImageTokens()
Get the image vector for the current process.
Definition Process.h:769
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:6115
bool IsRunning() const
Definition Process.cpp:1005
size_t RemoveBreakpointOpcodesFromBuffer(lldb::addr_t addr, size_t size, uint8_t *buf) const
Definition Process.cpp:1697
Broadcaster m_private_state_broadcaster
Definition Process.h:3388
const Process & operator=(const Process &)=delete
virtual bool DetachRequiresHalt()
Definition Process.h:1181
virtual lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(lldb::BinaryInformationLevel info_level)
Retrieve a StructuredData dictionary about all of the binaries loaded in the process at this time.
Definition Process.h:1352
virtual bool IsAlive()
Check if a process is still alive.
Definition Process.cpp:1083
ThreadList m_thread_list_real
The threads for this process as are known to the protocol we are debugging with.
Definition Process.h:3417
lldb::addr_t m_data_address_mask
Definition Process.h:3509
virtual ArchSpec GetSystemArchitecture()
Get the system architecture for this process.
Definition Process.h:727
Status DeallocateMemory(lldb::addr_t ptr)
The public interface to deallocating memory in the process.
Definition Process.cpp:2620
virtual Status DisableWatchpoint(lldb::WatchpointSP wp_sp, bool notify=true)
Definition Process.cpp:2695
void RegisterNotificationCallbacks(const Process::Notifications &callbacks)
Register for process and thread notifications.
Definition Process.cpp:597
virtual void DidAttach(ArchSpec &process_arch)
Called after attaching a process.
Definition Process.h:1016
virtual lldb::addr_t ResolveIndirectFunction(const Address *address, Status &error)
Resolve dynamically loaded indirect functions.
Definition Process.cpp:6213
lldb::StateType m_last_broadcast_state
Definition Process.h:3516
LanguageRuntime * GetLanguageRuntime(lldb::LanguageType language)
Definition Process.cpp:1485
ProcessModID m_mod_id
Tracks the state of the process over stops and other alterations.
Definition Process.h:3404
virtual CommandObject * GetPluginCommandObject()
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition Process.h:587
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition Process.h:543
friend class Target
Definition Process.h:361
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:2701
virtual JITLoaderList & GetJITLoaders()
Definition Process.cpp:2978
uint32_t AssignIndexIDToThread(uint64_t thread_id)
Definition Process.cpp:1250
virtual bool SetExitStatus(int exit_status, llvm::StringRef exit_string)
Set accessor for the process exit status (return code).
Definition Process.cpp:1025
uint32_t m_queue_list_stop_id
The natural stop id when queue list was last fetched.
Definition Process.h:3435
void PrintWarningOptimization(const SymbolContext &sc)
Print a user-visible warning about a module being built with optimization.
Definition Process.cpp:6277
friend class FunctionCaller
Definition Process.h:356
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:3019
static ProcessProperties & GetGlobalProperties()
Definition Process.cpp:534
lldb::addr_t m_highmem_code_address_mask
Definition Process.h:3510
lldb::addr_t GetImagePtrFromToken(size_t token) const
Definition Process.cpp:6354
int m_exit_status
The exit status of the process, or -1 if not set.
Definition Process.h:3412
std::vector< LanguageRuntime * > GetLanguageRuntimes()
Definition Process.cpp:1465
void SetShouldDetach(bool b)
Definition Process.h:763
virtual lldb_private::StructuredData::ObjectSP GetDynamicLoaderProcessState()
Definition Process.h:1396
bool StartPrivateStateThread(lldb::StateType state, bool run_lock_is_running, std::shared_ptr< PrivateStateThread > *backup_ptr=nullptr)
Definition Process.cpp:3955
MemoryCache m_memory_cache
Definition Process.h:3469
static void STDIOReadThreadBytesReceived(void *baton, const void *src, size_t src_len)
Definition Process.cpp:4805
virtual bool GetProcessInfo(ProcessInstanceInfo &info)
Definition Process.cpp:6303
virtual void DidHalt()
Called after halting a process.
Definition Process.h:1153
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:6159
lldb::StateType WaitForProcessStopPrivate(lldb::EventSP &event_sp, const Timeout< std::micro > &timeout)
Definition Process.cpp:2702
void RestoreProcessEvents()
Restores the process event broadcasting to its normal state.
Definition Process.cpp:931
virtual bool SupportsMemoryTagging()
Check whether the process supports memory tagging.
Definition Process.h:3158
bool SetPrivateRunLockToRunning()
Definition Process.h:3338
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:1214
uint32_t GetAddressByteSize() const
Definition Process.cpp:3774
uint32_t GetStopID() const
Definition Process.h:1487
void SetPrivateState(lldb::StateType state)
Definition Process.cpp:1379
lldb::addr_t m_highmem_data_address_mask
Definition Process.h:3511
virtual Status DoDestroy()=0
Status StopForDestroyOrDetach(lldb::EventSP &exit_event_sp)
Definition Process.cpp:3565
virtual llvm::Error LoadModules()
Sometimes processes know how to retrieve and load shared libraries.
Definition Process.h:688
bool GetWatchpointReportedAfter()
Whether lldb will be notified about watchpoints after the instruction has completed executing,...
Definition Process.cpp:2629
SourceManager::SourceFileCache & GetSourceFileCache()
Definition Process.h:2817
lldb::StateType GetNextEvent(lldb::EventSP &event_sp)
Definition Process.cpp:637
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:3177
bool StateChangedIsExternallyHijacked()
Definition Process.cpp:1361
void SetCanInterpretFunctionCalls(bool can_interpret_function_calls)
Sets whether executing function calls using the interpreter is possible for this process.
Definition Process.h:2107
lldb::StateType GetPublicState() const
Definition Process.h:3362
virtual size_t GetSTDERR(char *buf, size_t buf_size, Status &error)
Get any available STDERR.
Definition Process.cpp:4786
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error)
Write memory to a process.
Definition Process.cpp:2419
virtual llvm::Expected< bool > SaveCore(llvm::StringRef outfile)
Save core dump into the specified file.
Definition Process.cpp:2974
bool ProcessIOHandlerIsActive()
Definition Process.cpp:4975
Status DestroyImpl(bool force_kill)
Definition Process.cpp:3677
bool m_force_next_event_delivery
Definition Process.h:3515
lldb::SystemRuntimeUP m_system_runtime_up
Definition Process.h:3454
virtual Status WillHalt()
Called before halting to a process.
Definition Process.h:1128
bool ShouldBroadcastEvent(Event *event_ptr)
This is the part of the event handling that for a process event.
Definition Process.cpp:3778
virtual DynamicLoader * GetDynamicLoader()
Get the dynamic loader plug-in for this process.
Definition Process.cpp:2962
std::string m_exit_string
A textual description of why a process exited.
Definition Process.h:3413
lldb::DynamicCheckerFunctionsUP m_dynamic_checkers_up
The functions used by the expression parser to validate data that expressions use.
Definition Process.h:3448
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:648
void ForceNextEventDelivery()
Definition Process.h:3108
ThreadPlanStack * FindThreadPlans(lldb::tid_t tid)
Find the thread plan stack associated with thread with tid.
Definition Process.cpp:1195
void SetSTDIOFileDescriptor(int file_descriptor)
Associates a file descriptor with the process' STDIO handling and configures an asynchronous reading ...
Definition Process.cpp:4956
virtual Status Attach(ProcessAttachInfo &attach_info)
Attach to an existing process using the process attach info.
Definition Process.cpp:3088
virtual void Finalize(bool destructing)
This object is about to be destroyed, do any necessary cleanup.
Definition Process.cpp:542
lldb::addr_t GetDataAddressMask()
Definition Process.cpp:6108
std::recursive_mutex & GetPrivateStateMutex()
Definition Process.h:3357
void SynchronouslyNotifyStateChanged(lldb::StateType state)
Definition Process.cpp:616
bool SetPrivateRunLockToStopped()
Definition Process.h:3332
bool CanJIT()
Determines whether executing JIT-compiled code in this process is possible.
Definition Process.cpp:2582
StopPointSiteList< lldb_private::WatchpointResource > & GetWatchpointResourceList()
Definition Process.h:2315
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:407
virtual lldb_private::UUID FindModuleUUID(const llvm::StringRef path)
Definition Process.cpp:6313
virtual Status DoAttachToProcessWithName(const char *process_name, const ProcessAttachInfo &attach_info)
Attach to an existing process using a partial process name.
Definition Process.h:1003
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition Process.h:3419
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:2552
bool UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
Update the thread list.
Definition Process.cpp:1102
virtual lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(lldb::BinaryInformationLevel info_level, const std::vector< lldb::addr_t > &load_addresses)
Retrieve a StructuredData dictionary about the binaries at the provided load addresses.
Definition Process.h:1375
const lldb::UnixSignalsSP & GetUnixSignals()
Definition Process.cpp:3765
void SetBaseDirection(lldb::RunDirection direction)
Set the base run direction for the process.
Definition Process.cpp:3389
Status WriteMemoryTags(lldb::addr_t addr, size_t len, const std::vector< lldb::addr_t > &tags)
Write memory tags for a range of memory.
Definition Process.cpp:6686
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
Check if a process is a live debug session, or a corefile/post-mortem.
Definition Process.h:1531
std::weak_ptr< Target > m_target_wp
The target that owns this process.
Definition Process.h:3386
virtual void DoDidExec()
Subclasses of Process should implement this function if they need to do anything after a process exec...
Definition Process.h:1028
llvm::SmallVector< std::optional< lldb::addr_t > > ReadPointersFromMemory(llvm::ArrayRef< lldb::addr_t > ptr_locs)
Use Process::ReadMemoryRanges to efficiently read multiple pointers from memory at once.
Definition Process.cpp:2386
virtual void RefreshStateAfterStop()=0
Currently called as part of ShouldStop.
virtual llvm::SmallVector< llvm::MutableArrayRef< uint8_t > > ReadMemoryRanges(llvm::ArrayRef< Range< lldb::addr_t, size_t > > ranges, llvm::MutableArrayRef< uint8_t > buffer)
Read from multiple memory ranges and write the results into buffer.
Definition Process.cpp:1956
lldb::addr_t GetCodeAddressMask()
Get the current address mask in the Process.
Definition Process.cpp:6101
bool UnregisterNotificationCallbacks(const Process::Notifications &callbacks)
Unregister for process and thread notifications.
Definition Process.cpp:603
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:923
QueueList & GetQueueList()
Definition Process.h:2343
virtual Status DoDeallocateMemory(lldb::addr_t ptr)
Actually deallocate memory in the process.
Definition Process.h:2129
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Locate the memory region that contains load_addr.
Definition Process.cpp:6417
friend class DynamicLoader
Definition Process.h:358
static void SettingsTerminate()
Definition Process.cpp:5014
virtual void * GetImplementation()
Definition Process.h:2813
lldb::addr_t GetHighmemDataAddressMask()
Definition Process.cpp:6124
ThreadList m_extended_thread_list
Constituent for extended threads that may be generated, cleared on natural stops.
Definition Process.h:3428
bool CallVoidArgVoidPtrReturn(const Address *address, lldb::addr_t &returned_func, bool trap_exceptions=false)
Definition Process.cpp:6593
bool CurrentThreadIsPrivateStateThread()
Definition Process.cpp:6074
void AddPreResumeAction(PreResumeActionCallback callback, void *baton)
Definition Process.cpp:6041
size_t GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site)
Definition Process.cpp:1727
Status Halt(bool clear_thread_plans=false, bool use_run_lock=true)
Halts a running process.
Definition Process.cpp:3463
lldb::pid_t m_pid
Definition Process.h:3387
const lldb::ABISP & GetABI()
Definition Process.cpp:1459
friend class Debugger
Definition Process.h:357
Status WillLaunch(Module *module)
Called before launching to a process.
Definition Process.cpp:3075
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:6993
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:2500
uint32_t GetLastUserExpressionResumeID() const
Definition Process.h:1491
virtual size_t GetSTDOUT(char *buf, size_t buf_size, Status &error)
Get any available STDOUT.
Definition Process.cpp:4767
lldb::ThreadCollectionSP GetHistoryThreads(lldb::addr_t addr)
Definition Process.cpp:6317
bool PrivateStateThreadIsRunning() const
Definition Process.h:3097
const ProcessModID & GetModIDRef() const
Definition Process.h:1485
lldb::StateType GetStateChangedEvents(lldb::EventSP &event_sp, const Timeout< std::micro > &timeout, lldb::ListenerSP hijack_listener)
Definition Process.cpp:933
ThreadedCommunication m_stdio_communication
Definition Process.h:3460
lldb::StackFrameSP CalculateStackFrame() override
Definition Process.h:2571
static constexpr int g_all_event_bits
Definition Process.h:376
virtual lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, Status &error)
Actually allocate memory in the process.
Definition Process.h:1850
std::atomic< bool > m_finalizing
The tid of the thread that issued the async interrupt, used by thread plan timeout.
Definition Process.h:3491
virtual llvm::Expected< std::string > TraceGetState(llvm::StringRef type)
Get the current tracing state of the process and its threads.
Definition Process.h:2919
bool CanInterpretFunctionCalls()
Determines whether executing function calls using the interpreter is possible for this process.
Definition Process.h:2100
std::recursive_mutex m_language_runtimes_mutex
Definition Process.h:3474
std::string m_stderr_data
Definition Process.h:3465
friend class ThreadList
Definition Process.h:362
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1251
virtual Status EnableWatchpoint(lldb::WatchpointSP wp_sp, bool notify=true)
Definition Process.cpp:2689
LockingAdaptedIterable< std::mutex, collection > QueueIterable
Definition QueueList.h:51
The SourceFileCache class separates the source manager from the cache of source files.
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:367
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
A plug-in interface definition class for system runtimes.
LockingAdaptedIterable< std::recursive_mutex, collection > ThreadIterable
"lldb/Core/ThreadedCommunication.h" Variation of Communication that supports threaded reads.
Represents UUID's of various sizes.
Definition UUID.h:27
"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...
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
#define LLDB_INVALID_PROCESS_ID
@ 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:1016
llvm::APFloat::cmpResult compare(Scalar lhs, Scalar rhs)
Definition Scalar.cpp:872
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
bool operator==(const Address &lhs, const Address &rhs)
Definition Address.cpp:1010
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
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::unique_ptr< lldb_private::SystemRuntime > SystemRuntimeUP
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
RunDirection
Execution directions.
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
std::unique_ptr< lldb_private::OperatingSystem > OperatingSystemUP
std::shared_ptr< lldb_private::Thread > ThreadSP
void * thread_result_t
Definition lldb-types.h:62
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
uint64_t offset_t
Definition lldb-types.h:85
std::unique_ptr< lldb_private::DynamicCheckerFunctions > DynamicCheckerFunctionsUP
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ 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
int32_t break_id_t
Definition lldb-types.h:87
std::shared_ptr< lldb_private::Process > ProcessSP
InstrumentationRuntimeType
std::shared_ptr< lldb_private::Event > EventSP
std::unique_ptr< lldb_private::DynamicLoader > DynamicLoaderUP
std::unique_ptr< lldb_private::JITLoaderList > JITLoaderListUP
uint64_t pid_t
Definition lldb-types.h:83
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::weak_ptr< lldb_private::Process > ProcessWP
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
BinaryInformationLevel
When the Process plugin can retrieve information about all binaries loaded in the target process,...
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP
static thread_local bool g_is_private_state_thread
Definition Process.h:3684
PrivateStateThreadGuard & operator=(const PrivateStateThreadGuard &)=delete
PrivateStateThreadGuard(const PrivateStateThreadGuard &)=delete
A notification structure that can be used by clients to listen for changes in a process's lifetime.
Definition Process.h:416
void(* process_state_changed)(void *baton, Process *process, lldb::StateType state)
Definition Process.h:419
void(* initialize)(void *baton, Process *process)
Definition Process.h:418
bool operator==(const PreResumeCallbackAndBaton &rhs)
Definition Process.h:3218
PreResumeCallbackAndBaton(PreResumeActionCallback in_callback, void *in_baton)
Definition Process.h:3215
lldb::StateType GetPublicState() const
Definition Process.h:3263
ThreadSafeValue< lldb::StateType > m_private_state
HostThread for the thread that watches for internal state events.
Definition Process.h:3315
void SetThreadName(llvm::StringRef new_name)
Definition Process.h:3257
lldb::StateType GetPrivateState() const
Definition Process.h:3259
ThreadSafeValue< lldb::StateType > m_public_state
The actual state of our process.
Definition Process.h:3313
Process & m_process
The process state that we show to client code.
Definition Process.h:3308
bool IsOnThread(const HostThread &thread) const
Definition Process.cpp:3951
std::recursive_mutex & GetPrivateStateMutex()
Definition Process.h:3273
void SetPublicState(lldb::StateType new_value)
Definition Process.h:3265
void SetPrivateState(lldb::StateType new_value)
Definition Process.h:3269
void SetPublicStateNoLock(lldb::StateType new_state)
Definition Process.h:3285
PrivateStateThread(Process &process, lldb::StateType public_state, lldb::StateType private_state, llvm::StringRef thread_name, bool is_override=false)
Definition Process.h:3232
bool m_is_override
This will be the thread name given to the Private State HostThread when it gets spun up.
Definition Process.h:3326
void SetPrivateStateNoLock(lldb::StateType new_state)
Definition Process.h:3281
lldb::StateType GetPrivateStateNoLock() const
Definition Process.h:3277
jLLDBTraceGetBinaryData gdb-remote packet
jLLDBTraceStop gdb-remote packet