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