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