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