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