11a3d19ddSKamil Rytarowski //===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
21a3d19ddSKamil Rytarowski //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
61a3d19ddSKamil Rytarowski //
71a3d19ddSKamil Rytarowski //===----------------------------------------------------------------------===//
81a3d19ddSKamil Rytarowski 
91a3d19ddSKamil Rytarowski #ifndef liblldb_NativeProcessNetBSD_H_
101a3d19ddSKamil Rytarowski #define liblldb_NativeProcessNetBSD_H_
111a3d19ddSKamil Rytarowski 
1205e32badSAntonio Afonso #include "Plugins/Process/POSIX/NativeProcessELF.h"
131a3d19ddSKamil Rytarowski #include "lldb/Target/MemoryRegionInfo.h"
142da1b597SPavel Labath #include "lldb/Utility/ArchSpec.h"
155713a05bSZachary Turner #include "lldb/Utility/FileSpec.h"
161a3d19ddSKamil Rytarowski 
171a3d19ddSKamil Rytarowski #include "NativeThreadNetBSD.h"
181a3d19ddSKamil Rytarowski 
191a3d19ddSKamil Rytarowski namespace lldb_private {
201a3d19ddSKamil Rytarowski namespace process_netbsd {
21f05b42e9SAdrian Prantl /// \class NativeProcessNetBSD
22d8f460e8SAdrian Prantl /// Manages communication with the inferior (debugee) process.
231a3d19ddSKamil Rytarowski ///
24d8f460e8SAdrian Prantl /// Upon construction, this class prepares and launches an inferior process
25d8f460e8SAdrian Prantl /// for debugging.
261a3d19ddSKamil Rytarowski ///
271a3d19ddSKamil Rytarowski /// Changes in the inferior process state are broadcasted.
2805e32badSAntonio Afonso class NativeProcessNetBSD : public NativeProcessELF {
29f07a9995SKamil Rytarowski public:
3096e600fcSPavel Labath   class Factory : public NativeProcessProtocol::Factory {
3196e600fcSPavel Labath   public:
3282abefa4SPavel Labath     llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
3396e600fcSPavel Labath     Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
3496e600fcSPavel Labath            MainLoop &mainloop) const override;
3596e600fcSPavel Labath 
3682abefa4SPavel Labath     llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
3796e600fcSPavel Labath     Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
3896e600fcSPavel Labath            MainLoop &mainloop) const override;
3906215023SMichał Górny 
4006215023SMichał Górny     Extension GetSupportedExtensions() const override;
4196e600fcSPavel Labath   };
4296e600fcSPavel Labath 
43f07a9995SKamil Rytarowski   // NativeProcessProtocol Interface
4497206d57SZachary Turner   Status Resume(const ResumeActionList &resume_actions) override;
45f07a9995SKamil Rytarowski 
4697206d57SZachary Turner   Status Halt() override;
47f07a9995SKamil Rytarowski 
4897206d57SZachary Turner   Status Detach() override;
49f07a9995SKamil Rytarowski 
5097206d57SZachary Turner   Status Signal(int signo) override;
51f07a9995SKamil Rytarowski 
5277cc2464SMichał Górny   Status Interrupt() override;
5377cc2464SMichał Górny 
5497206d57SZachary Turner   Status Kill() override;
55f07a9995SKamil Rytarowski 
5697206d57SZachary Turner   Status GetMemoryRegionInfo(lldb::addr_t load_addr,
57f07a9995SKamil Rytarowski                              MemoryRegionInfo &range_info) override;
58f07a9995SKamil Rytarowski 
5997206d57SZachary Turner   Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
60f07a9995SKamil Rytarowski                     size_t &bytes_read) override;
61f07a9995SKamil Rytarowski 
6297206d57SZachary Turner   Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
63f07a9995SKamil Rytarowski                      size_t &bytes_written) override;
64f07a9995SKamil Rytarowski 
65f07a9995SKamil Rytarowski   lldb::addr_t GetSharedLibraryInfoAddress() override;
66f07a9995SKamil Rytarowski 
67f07a9995SKamil Rytarowski   size_t UpdateThreads() override;
68f07a9995SKamil Rytarowski 
GetArchitecture()69578a4258SPavel Labath   const ArchSpec &GetArchitecture() const override { return m_arch; }
70f07a9995SKamil Rytarowski 
7197206d57SZachary Turner   Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
7297206d57SZachary Turner                        bool hardware) override;
73f07a9995SKamil Rytarowski 
74d5317b41SMichał Górny   // The two following methods are probably not necessary and probably
75d5317b41SMichał Górny   // will never be called.  Nevertheless, we implement them right now
76d5317b41SMichał Górny   // to reduce the differences between different platforms and reduce
77d5317b41SMichał Górny   // the risk of the lack of implementation actually breaking something,
78d5317b41SMichał Górny   // at least for the time being.
7997206d57SZachary Turner   Status GetLoadedModuleFileSpec(const char *module_path,
80f07a9995SKamil Rytarowski                                  FileSpec &file_spec) override;
8197206d57SZachary Turner   Status GetFileLoadAddress(const llvm::StringRef &file_name,
82f07a9995SKamil Rytarowski                             lldb::addr_t &load_addr) override;
83f07a9995SKamil Rytarowski 
84f07a9995SKamil Rytarowski   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
85f07a9995SKamil Rytarowski   GetAuxvData() const override;
86f07a9995SKamil Rytarowski 
87f07a9995SKamil Rytarowski   // Interface used by NativeRegisterContext-derived classes.
8897206d57SZachary Turner   static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
89f07a9995SKamil Rytarowski                               int data = 0, int *result = nullptr);
90f07a9995SKamil Rytarowski 
91*37cbd817SMichał Górny   llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
92*37cbd817SMichał Górny 
931a3d19ddSKamil Rytarowski private:
94f07a9995SKamil Rytarowski   MainLoop::SignalHandleUP m_sigchld_handle;
95f07a9995SKamil Rytarowski   ArchSpec m_arch;
9606215023SMichał Górny   MainLoop& m_main_loop;
9796e600fcSPavel Labath   LazyBool m_supports_mem_region = eLazyBoolCalculate;
98f07a9995SKamil Rytarowski   std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
99f07a9995SKamil Rytarowski 
100f07a9995SKamil Rytarowski   // Private Instance Methods
10196e600fcSPavel Labath   NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
10296e600fcSPavel Labath                       const ArchSpec &arch, MainLoop &mainloop);
103f07a9995SKamil Rytarowski 
104269eec03SKamil Rytarowski   bool HasThreadNoLock(lldb::tid_t thread_id);
105269eec03SKamil Rytarowski 
106a5be48b3SPavel Labath   NativeThreadNetBSD &AddThread(lldb::tid_t thread_id);
1078d9400b6SMichał Górny   void RemoveThread(lldb::tid_t thread_id);
108f07a9995SKamil Rytarowski 
109f07a9995SKamil Rytarowski   void MonitorCallback(lldb::pid_t pid, int signal);
1103508fc8cSPavel Labath   void MonitorExited(lldb::pid_t pid, WaitStatus status);
111f07a9995SKamil Rytarowski   void MonitorSIGSTOP(lldb::pid_t pid);
112f07a9995SKamil Rytarowski   void MonitorSIGTRAP(lldb::pid_t pid);
113f07a9995SKamil Rytarowski   void MonitorSignal(lldb::pid_t pid, int signal);
11406215023SMichał Górny   void MonitorClone(::pid_t child_pid, bool is_vfork,
11506215023SMichał Górny                     NativeThreadNetBSD &parent_thread);
116f07a9995SKamil Rytarowski 
11797206d57SZachary Turner   Status PopulateMemoryRegionCache();
118f07a9995SKamil Rytarowski   void SigchldHandler();
119f07a9995SKamil Rytarowski 
12096e600fcSPavel Labath   Status Attach();
121f21e704dSMichał Górny   Status SetupTrace();
12297206d57SZachary Turner   Status ReinitializeThreads();
1231a3d19ddSKamil Rytarowski };
1241a3d19ddSKamil Rytarowski 
1251a3d19ddSKamil Rytarowski } // namespace process_netbsd
1261a3d19ddSKamil Rytarowski } // namespace lldb_private
1271a3d19ddSKamil Rytarowski 
1281a3d19ddSKamil Rytarowski #endif // #ifndef liblldb_NativeProcessNetBSD_H_
129