1 //===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_NativeProcessNetBSD_H_
10 #define liblldb_NativeProcessNetBSD_H_
12 #include "Plugins/Process/POSIX/NativeProcessELF.h"
13 #include "lldb/Target/MemoryRegionInfo.h"
14 #include "lldb/Utility/ArchSpec.h"
15 #include "lldb/Utility/FileSpec.h"
17 #include "NativeThreadNetBSD.h"
19 namespace lldb_private
{
20 namespace process_netbsd
{
21 /// \class NativeProcessNetBSD
22 /// Manages communication with the inferior (debugee) process.
24 /// Upon construction, this class prepares and launches an inferior process
27 /// Changes in the inferior process state are broadcasted.
28 class NativeProcessNetBSD
: public NativeProcessELF
{
30 class Manager
: public NativeProcessProtocol::Manager
{
32 using NativeProcessProtocol::Manager::Manager
;
34 llvm::Expected
<std::unique_ptr
<NativeProcessProtocol
>>
35 Launch(ProcessLaunchInfo
&launch_info
,
36 NativeDelegate
&native_delegate
) override
;
38 llvm::Expected
<std::unique_ptr
<NativeProcessProtocol
>>
39 Attach(lldb::pid_t pid
, NativeDelegate
&native_delegate
) override
;
41 Extension
GetSupportedExtensions() const override
;
44 // NativeProcessProtocol Interface
45 Status
Resume(const ResumeActionList
&resume_actions
) override
;
47 Status
Halt() override
;
49 Status
Detach() override
;
51 Status
Signal(int signo
) override
;
53 Status
Interrupt() override
;
55 Status
Kill() override
;
57 Status
GetMemoryRegionInfo(lldb::addr_t load_addr
,
58 MemoryRegionInfo
&range_info
) override
;
60 Status
ReadMemory(lldb::addr_t addr
, void *buf
, size_t size
,
61 size_t &bytes_read
) override
;
63 Status
WriteMemory(lldb::addr_t addr
, const void *buf
, size_t size
,
64 size_t &bytes_written
) override
;
66 lldb::addr_t
GetSharedLibraryInfoAddress() override
;
68 size_t UpdateThreads() override
;
70 const ArchSpec
&GetArchitecture() const override
{ return m_arch
; }
72 Status
SetBreakpoint(lldb::addr_t addr
, uint32_t size
,
73 bool hardware
) override
;
75 // The two following methods are probably not necessary and probably
76 // will never be called. Nevertheless, we implement them right now
77 // to reduce the differences between different platforms and reduce
78 // the risk of the lack of implementation actually breaking something,
79 // at least for the time being.
80 Status
GetLoadedModuleFileSpec(const char *module_path
,
81 FileSpec
&file_spec
) override
;
82 Status
GetFileLoadAddress(const llvm::StringRef
&file_name
,
83 lldb::addr_t
&load_addr
) override
;
85 llvm::ErrorOr
<std::unique_ptr
<llvm::MemoryBuffer
>>
86 GetAuxvData() const override
;
88 // Interface used by NativeRegisterContext-derived classes.
89 static Status
PtraceWrapper(int req
, lldb::pid_t pid
, void *addr
= nullptr,
90 int data
= 0, int *result
= nullptr);
92 llvm::Expected
<std::string
> SaveCore(llvm::StringRef path_hint
) override
;
95 MainLoop::SignalHandleUP m_sigchld_handle
;
97 MainLoop
& m_main_loop
;
98 LazyBool m_supports_mem_region
= eLazyBoolCalculate
;
99 std::vector
<std::pair
<MemoryRegionInfo
, FileSpec
>> m_mem_region_cache
;
101 // Private Instance Methods
102 NativeProcessNetBSD(::pid_t pid
, int terminal_fd
, NativeDelegate
&delegate
,
103 const ArchSpec
&arch
, MainLoop
&mainloop
);
105 bool HasThreadNoLock(lldb::tid_t thread_id
);
107 NativeThreadNetBSD
&AddThread(lldb::tid_t thread_id
);
108 void RemoveThread(lldb::tid_t thread_id
);
110 void MonitorCallback(lldb::pid_t pid
, int signal
);
111 void MonitorExited(lldb::pid_t pid
, WaitStatus status
);
112 void MonitorSIGSTOP(lldb::pid_t pid
);
113 void MonitorSIGTRAP(lldb::pid_t pid
);
114 void MonitorSignal(lldb::pid_t pid
, int signal
);
115 void MonitorClone(::pid_t child_pid
, bool is_vfork
,
116 NativeThreadNetBSD
&parent_thread
);
118 Status
PopulateMemoryRegionCache();
119 void SigchldHandler();
123 Status
ReinitializeThreads();
126 } // namespace process_netbsd
127 } // namespace lldb_private
129 #endif // #ifndef liblldb_NativeProcessNetBSD_H_