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