1//===-- NativeProcessAIX.h ---------------------------------- -*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_AIX_NATIVEPROCESSAIX_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_AIX_NATIVEPROCESSAIX_H
11
12#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
13#include "lldb/Host/Debug.h"
14#include "lldb/Host/common/NativeProcessProtocol.h"
15#include "lldb/Host/posix/Support.h"
16#include "lldb/Target/MemoryRegionInfo.h"
17#include "lldb/Utility/ArchSpec.h"
18#include "lldb/Utility/FileSpec.h"
19#include "lldb/lldb-types.h"
20#include "llvm/ADT/SmallPtrSet.h"
21#include <csignal>
22#include <unordered_set>
23
24namespace lldb_private::process_aix {
25/// \class NativeProcessAIX
26/// Manages communication with the inferior (debugee) process.
27///
28/// Upon construction, this class prepares and launches an inferior process
29/// for debugging.
30///
31/// Changes in the inferior process state are broadcasted.
32class NativeProcessAIX : public NativeProcessProtocol {
33public:
34 class Manager : public NativeProcessProtocol::Manager {
35 public:
36 Manager(MainLoop &mainloop);
37
38 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
39 Launch(ProcessLaunchInfo &launch_info,
40 NativeDelegate &native_delegate) override;
41
42 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
43 Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
44
45 void AddProcess(NativeProcessAIX &process) { m_processes.insert(Ptr: &process); }
46
47 void RemoveProcess(NativeProcessAIX &process) {
48 m_processes.erase(Ptr: &process);
49 }
50
51 // Collect an event for the given tid, waiting for it if necessary.
52 void CollectThread(::pid_t tid);
53
54 private:
55 MainLoop::SignalHandleUP m_sigchld_handle;
56
57 llvm::SmallPtrSet<NativeProcessAIX *, 2> m_processes;
58
59 void SigchldHandler();
60 };
61
62 // NativeProcessProtocol Interface
63
64 ~NativeProcessAIX() override { m_manager.RemoveProcess(process&: *this); }
65
66 Status Resume(const ResumeActionList &resume_actions) override;
67
68 Status Halt() override;
69
70 Status Detach() override;
71
72 Status Signal(int signo) override;
73
74 Status Interrupt() override;
75
76 Status Kill() override;
77
78 lldb::addr_t GetSharedLibraryInfoAddress() override;
79
80 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
81 size_t &bytes_read) override;
82
83 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
84 size_t &bytes_written) override;
85
86 size_t UpdateThreads() override;
87
88 const ArchSpec &GetArchitecture() const override { return m_arch; }
89
90 Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
91 bool hardware) override;
92
93 Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
94
95 Status GetLoadedModuleFileSpec(const char *module_path,
96 FileSpec &file_spec) override;
97
98 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
99 GetAuxvData() const override {
100 return getProcFile(pid: GetID(), file: "auxv");
101 }
102
103 Status GetFileLoadAddress(const llvm::StringRef &file_name,
104 lldb::addr_t &load_addr) override;
105
106 static llvm::Expected<int> PtraceWrapper(int req, lldb::pid_t pid,
107 void *addr = nullptr,
108 void *data = nullptr,
109 size_t data_size = 0);
110
111 bool SupportHardwareSingleStepping() const;
112
113private:
114 Manager &m_manager;
115 ArchSpec m_arch;
116
117 // Private Instance Methods
118 NativeProcessAIX(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
119 const ArchSpec &arch, Manager &manager,
120 llvm::ArrayRef<::pid_t> tids);
121
122 bool TryHandleWaitStatus(lldb::pid_t pid, WaitStatus status);
123
124 // Returns a list of process threads that we have attached to.
125 static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
126
127 llvm::Error Detach(lldb::tid_t tid);
128
129 void SigchldHandler();
130};
131
132} // namespace lldb_private::process_aix
133
134#endif // #ifndef LLDB_SOURCE_PLUGINS_PROCESS_AIX_NATIVEPROCESSAIX_H
135

source code of lldb/source/Plugins/Process/AIX/NativeProcessAIX.h