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