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