xref: /llvm-project/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h (revision e64cc756819d567f453467bf7cc16599ad296fdd)
1bee4d6efSMichał Górny //===-- NativeProcessFreeBSD.h -------------------------------- -*- C++ -*-===//
2bee4d6efSMichał Górny //
3bee4d6efSMichał Górny // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4bee4d6efSMichał Górny // See https://llvm.org/LICENSE.txt for license information.
5bee4d6efSMichał Górny // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6bee4d6efSMichał Górny //
7bee4d6efSMichał Górny //===----------------------------------------------------------------------===//
8bee4d6efSMichał Górny 
9bee4d6efSMichał Górny #ifndef liblldb_NativeProcessFreeBSD_H_
10bee4d6efSMichał Górny #define liblldb_NativeProcessFreeBSD_H_
11bee4d6efSMichał Górny 
12bee4d6efSMichał Górny #include "Plugins/Process/POSIX/NativeProcessELF.h"
13bee4d6efSMichał Górny #include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
14bee4d6efSMichał Górny 
15bee4d6efSMichał Górny #include "lldb/Target/MemoryRegionInfo.h"
16bee4d6efSMichał Górny #include "lldb/Utility/ArchSpec.h"
17bee4d6efSMichał Górny #include "lldb/Utility/FileSpec.h"
18bee4d6efSMichał Górny 
19bee4d6efSMichał Górny #include "NativeThreadFreeBSD.h"
20bee4d6efSMichał Górny 
21bee4d6efSMichał Górny namespace lldb_private {
22bee4d6efSMichał Górny namespace process_freebsd {
23bee4d6efSMichał Górny /// \class NativeProcessFreeBSD
24bee4d6efSMichał Górny /// Manages communication with the inferior (debugee) process.
25bee4d6efSMichał Górny ///
26bee4d6efSMichał Górny /// Upon construction, this class prepares and launches an inferior process
27bee4d6efSMichał Górny /// for debugging.
28bee4d6efSMichał Górny ///
29bee4d6efSMichał Górny /// Changes in the inferior process state are broadcasted.
30bee4d6efSMichał Górny class NativeProcessFreeBSD : public NativeProcessELF,
31bee4d6efSMichał Górny                              private NativeProcessSoftwareSingleStep {
32bee4d6efSMichał Górny public:
33*e64cc756SPavel Labath   class Manager : public NativeProcessProtocol::Manager {
34bee4d6efSMichał Górny   public:
35*e64cc756SPavel Labath     using NativeProcessProtocol::Manager::Manager;
36bee4d6efSMichał Górny 
37bee4d6efSMichał Górny     llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
38*e64cc756SPavel Labath     Launch(ProcessLaunchInfo &launch_info,
39*e64cc756SPavel Labath            NativeDelegate &native_delegate) override;
40*e64cc756SPavel Labath 
41*e64cc756SPavel Labath     llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
42*e64cc756SPavel Labath     Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
4365f2a757SMichał Górny 
4465f2a757SMichał Górny     Extension GetSupportedExtensions() const override;
45bee4d6efSMichał Górny   };
46bee4d6efSMichał Górny 
47bee4d6efSMichał Górny   // NativeProcessProtocol Interface
48bee4d6efSMichał Górny   Status Resume(const ResumeActionList &resume_actions) override;
49bee4d6efSMichał Górny 
50bee4d6efSMichał Górny   Status Halt() override;
51bee4d6efSMichał Górny 
52bee4d6efSMichał Górny   Status Detach() override;
53bee4d6efSMichał Górny 
54bee4d6efSMichał Górny   Status Signal(int signo) override;
55bee4d6efSMichał Górny 
56bee4d6efSMichał Górny   Status Interrupt() override;
57bee4d6efSMichał Górny 
58bee4d6efSMichał Górny   Status Kill() override;
59bee4d6efSMichał Górny 
60bee4d6efSMichał Górny   Status GetMemoryRegionInfo(lldb::addr_t load_addr,
61bee4d6efSMichał Górny                              MemoryRegionInfo &range_info) override;
62bee4d6efSMichał Górny 
63bee4d6efSMichał Górny   Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
64bee4d6efSMichał Górny                     size_t &bytes_read) override;
65bee4d6efSMichał Górny 
66bee4d6efSMichał Górny   Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
67bee4d6efSMichał Górny                      size_t &bytes_written) override;
68bee4d6efSMichał Górny 
69bee4d6efSMichał Górny   size_t UpdateThreads() override;
70bee4d6efSMichał Górny 
GetArchitecture()71bee4d6efSMichał Górny   const ArchSpec &GetArchitecture() const override { return m_arch; }
72bee4d6efSMichał Górny 
73bee4d6efSMichał Górny   Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
74bee4d6efSMichał Górny                        bool hardware) override;
75bee4d6efSMichał Górny 
76bee4d6efSMichał Górny   // The two following methods are probably not necessary and probably
77bee4d6efSMichał Górny   // will never be called.  Nevertheless, we implement them right now
78bee4d6efSMichał Górny   // to reduce the differences between different platforms and reduce
79bee4d6efSMichał Górny   // the risk of the lack of implementation actually breaking something,
80bee4d6efSMichał Górny   // at least for the time being.
81bee4d6efSMichał Górny   Status GetLoadedModuleFileSpec(const char *module_path,
82bee4d6efSMichał Górny                                  FileSpec &file_spec) override;
83bee4d6efSMichał Górny   Status GetFileLoadAddress(const llvm::StringRef &file_name,
84bee4d6efSMichał Górny                             lldb::addr_t &load_addr) override;
85bee4d6efSMichał Górny 
86bee4d6efSMichał Górny   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
87bee4d6efSMichał Górny   GetAuxvData() const override;
88bee4d6efSMichał Górny 
89bee4d6efSMichał Górny   // Interface used by NativeRegisterContext-derived classes.
90bee4d6efSMichał Górny   static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
91bee4d6efSMichał Górny                               int data = 0, int *result = nullptr);
92bee4d6efSMichał Górny 
93bee4d6efSMichał Górny   bool SupportHardwareSingleStepping() const;
94bee4d6efSMichał Górny 
95b07803eeSMichał Górny   llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
96b07803eeSMichał Górny 
97bee4d6efSMichał Górny protected:
98bee4d6efSMichał Górny   llvm::Expected<llvm::ArrayRef<uint8_t>>
99bee4d6efSMichał Górny   GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
100bee4d6efSMichał Górny 
101bee4d6efSMichał Górny private:
102bee4d6efSMichał Górny   MainLoop::SignalHandleUP m_sigchld_handle;
103bee4d6efSMichał Górny   ArchSpec m_arch;
10465f2a757SMichał Górny   MainLoop& m_main_loop;
105bee4d6efSMichał Górny   LazyBool m_supports_mem_region = eLazyBoolCalculate;
106bee4d6efSMichał Górny   std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
107bee4d6efSMichał Górny 
108bee4d6efSMichał Górny   // Private Instance Methods
109bee4d6efSMichał Górny   NativeProcessFreeBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
110bee4d6efSMichał Górny                        const ArchSpec &arch, MainLoop &mainloop);
111bee4d6efSMichał Górny 
112bee4d6efSMichał Górny   bool HasThreadNoLock(lldb::tid_t thread_id);
113bee4d6efSMichał Górny 
114bee4d6efSMichał Górny   NativeThreadFreeBSD &AddThread(lldb::tid_t thread_id);
115bee4d6efSMichał Górny   void RemoveThread(lldb::tid_t thread_id);
116bee4d6efSMichał Górny 
117bee4d6efSMichał Górny   void MonitorCallback(lldb::pid_t pid, int signal);
118bee4d6efSMichał Górny   void MonitorExited(lldb::pid_t pid, WaitStatus status);
119bee4d6efSMichał Górny   void MonitorSIGSTOP(lldb::pid_t pid);
120bee4d6efSMichał Górny   void MonitorSIGTRAP(lldb::pid_t pid);
121bee4d6efSMichał Górny   void MonitorSignal(lldb::pid_t pid, int signal);
12265f2a757SMichał Górny   void MonitorClone(::pid_t child_pid, bool is_vfork,
12365f2a757SMichał Górny                     NativeThreadFreeBSD &parent_thread);
124bee4d6efSMichał Górny 
125bee4d6efSMichał Górny   Status PopulateMemoryRegionCache();
126bee4d6efSMichał Górny   void SigchldHandler();
127bee4d6efSMichał Górny 
128bee4d6efSMichał Górny   Status Attach();
129bee4d6efSMichał Górny   Status SetupTrace();
130bee4d6efSMichał Górny   Status ReinitializeThreads();
131bee4d6efSMichał Górny };
132bee4d6efSMichał Górny 
133bee4d6efSMichał Górny } // namespace process_freebsd
134bee4d6efSMichał Górny } // namespace lldb_private
135bee4d6efSMichał Górny 
136bee4d6efSMichał Górny #endif // #ifndef liblldb_NativeProcessFreeBSD_H_
137