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