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