[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)
Dhruv Srivastava via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 12 20:13:50 PDT 2025
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/118160
>From 03a290e9c748540b69ca6df7fa9c4481f9cdd3d0 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 30 Nov 2024 01:14:15 -0600
Subject: [PATCH 01/11] Added base files for NativeProcess for AIX
---
.../source/Plugins/Process/AIX/CMakeLists.txt | 14 +
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 288 ++++++++++++++++++
.../Plugins/Process/AIX/NativeProcessAIX.h | 134 ++++++++
lldb/source/Plugins/Process/CMakeLists.txt | 3 +
4 files changed, 439 insertions(+)
create mode 100644 lldb/source/Plugins/Process/AIX/CMakeLists.txt
create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
diff --git a/lldb/source/Plugins/Process/AIX/CMakeLists.txt b/lldb/source/Plugins/Process/AIX/CMakeLists.txt
new file mode 100644
index 0000000000000..4fabbe9302287
--- /dev/null
+++ b/lldb/source/Plugins/Process/AIX/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_lldb_library(lldbPluginProcessAIX
+ NativeProcessAIX.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ lldbSymbol
+ lldbTarget
+ lldbUtility
+ lldbPluginProcessPOSIX
+ lldbPluginProcessUtility
+ LINK_COMPONENTS
+ Support
+ )
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
new file mode 100644
index 0000000000000..6661693b2fc02
--- /dev/null
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -0,0 +1,288 @@
+//===-- NativeProcessAIX.cpp --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "NativeProcessAIX.h"
+
+#include <cerrno>
+#include <cstdint>
+#include <cstring>
+#include <unistd.h>
+#include <fstream>
+#include <mutex>
+#include <optional>
+#include <sstream>
+#include <string>
+#include <unordered_map>
+#include "NativeThreadAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/PseudoTerminal.h"
+#include "lldb/Host/ThreadLauncher.h"
+#include "lldb/Host/common/NativeRegisterContext.h"
+#include "lldb/Host/aix/Ptrace.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/RegisterValue.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StringExtractor.h"
+#include "llvm/ADT/ScopeExit.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
+#include <sys/reg.h>
+#include <sys/ptrace.h>
+#include <sys/ldr.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#ifdef __aarch64__
+#include <asm/hwcap.h>
+#include <sys/auxv.h>
+#endif
+
+// Support hardware breakpoints in case it has not been defined
+#ifndef TRAP_HWBKPT
+#define TRAP_HWBKPT 4
+#endif
+
+#ifndef HWCAP2_MTE
+#define HWCAP2_MTE (1 << 18)
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+ "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static Status EnsureFDFlags(int fd, int flags) {
+ Status error;
+
+ int status = fcntl(fd, F_GETFL);
+ if (status == -1) {
+ error = Status::FromErrno();
+ return error;
+ }
+
+ if (fcntl(fd, F_SETFL, status | flags) == -1) {
+ error = Status::FromErrno();
+ return error;
+ }
+
+ return error;
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+ : NativeProcessProtocol::Manager(mainloop) {
+ Status status;
+ m_sigchld_handle = mainloop.RegisterSignal(
+ SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+ assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+ NativeDelegate &native_delegate) {
+ Log *log = GetLog(POSIXLog::Process);
+
+ Status status;
+ ::pid_t pid = ProcessLauncherPosixFork()
+ .LaunchProcess(launch_info, status)
+ .GetProcessId();
+ LLDB_LOG(log, "pid = {0:x}", pid);
+ if (status.Fail()) {
+ LLDB_LOG(log, "failed to launch process: {0}", status);
+ return status.ToError();
+ }
+
+ // Wait for the child process to trap on its call to execve.
+ int wstatus = 0;
+ ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+ assert(wpid == pid);
+ UNUSED_IF_ASSERT_DISABLED(wpid);
+ if (!WIFSTOPPED(wstatus)) {
+ LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+ return llvm::make_error<StringError>("Could not sync with inferior process",
+ llvm::inconvertibleErrorCode());
+ }
+ LLDB_LOG(log, "inferior started, now in stopped state");
+
+ ProcessInstanceInfo Info;
+ if (!Host::GetProcessInfo(pid, Info)) {
+ return llvm::make_error<StringError>("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+ }
+
+ // Set the architecture to the exe architecture.
+ LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+ Info.GetArchitecture().GetArchitectureName());
+
+ return std::unique_ptr<NativeProcessAIX>(new NativeProcessAIX(
+ pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate,
+ Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessAIX::Manager::Attach(
+ lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+ Log *log = GetLog(POSIXLog::Process);
+ LLDB_LOG(log, "pid = {0:x}", pid);
+
+ ProcessInstanceInfo Info;
+ if (!Host::GetProcessInfo(pid, Info)) {
+ return llvm::make_error<StringError>("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+ }
+ auto tids_or = NativeProcessAIX::Attach(pid);
+ if (!tids_or)
+ return tids_or.takeError();
+
+ return std::unique_ptr<NativeProcessAIX>(
+ new NativeProcessAIX(pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+ NativeProcessAIX::Extension supported =
+ Extension::multiprocess | Extension::fork | Extension::vfork |
+ Extension::pass_signals | Extension::auxv | Extension::libraries_svr4 |
+ Extension::siginfo_read;
+
+ return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {
+}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {
+}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+ NativeDelegate &delegate,
+ const ArchSpec &arch, Manager &manager,
+ llvm::ArrayRef<::pid_t> tids)
+ : NativeProcessProtocol(pid, terminal_fd, delegate), m_manager(manager),
+ m_arch(arch) {
+ manager.AddProcess(*this);
+ if (m_terminal_fd != -1) {
+ Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
+ assert(status.Success());
+ }
+
+ // Let our process instance know the thread has stopped.
+ SetCurrentThreadID(tids[0]);
+ SetState(StateType::eStateStopped, false);
+}
+
+llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
+
+ Status status;
+ if ((status = PtraceWrapper(PT_ATTACH, pid)).Fail()) {
+ return status.ToError();
+ }
+
+ std::vector<::pid_t> tids;
+ tids.push_back(pid);
+ return std::move(tids);
+}
+
+void NativeProcessAIX::MonitorSIGTRAP(const WaitStatus status,
+ NativeThreadAIX &thread) {
+}
+
+void NativeProcessAIX::MonitorBreakpoint(NativeThreadAIX &thread) {
+}
+
+bool NativeProcessAIX::SupportHardwareSingleStepping() const {
+ return false;
+}
+
+Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
+ return Status();
+}
+
+Status NativeProcessAIX::Halt() {
+ Status error;
+ return error;
+}
+
+Status NativeProcessAIX::Detach() {
+ Status error;
+ return error;
+}
+
+Status NativeProcessAIX::Signal(int signo) {
+ Status error;
+ return error;
+}
+
+Status NativeProcessAIX::Interrupt() {
+ return Status();
+}
+
+Status NativeProcessAIX::Kill() {
+ Status error;
+ return error;
+}
+
+Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) {
+ if (hardware)
+ return SetHardwareBreakpoint(addr, size);
+ else
+ return SetSoftwareBreakpoint(addr, size);
+}
+
+Status NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
+ if (hardware)
+ return RemoveHardwareBreakpoint(addr);
+ else
+ return NativeProcessProtocol::RemoveBreakpoint(addr);
+}
+
+int8_t NativeProcessAIX::GetSignalInfo(WaitStatus wstatus) const {
+ return wstatus.status;
+}
+
+Status NativeProcessAIX::Detach(lldb::tid_t tid) {
+ if (tid == LLDB_INVALID_THREAD_ID)
+ return Status();
+
+ return PtraceWrapper(PT_DETACH, tid);
+}
+
+// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
+// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
+Status NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
+ void *data, size_t data_size,
+ long *result) {
+ Status error;
+ return error;
+}
+
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
new file mode 100644
index 0000000000000..2c07ba420d3fe
--- /dev/null
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -0,0 +1,134 @@
+//===-- NativeProcessAIX.h ---------------------------------- -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_NativeProcessAIX_H_
+#define liblldb_NativeProcessAIX_H_
+
+#include <csignal>
+#include <unordered_set>
+
+#include "lldb/Host/Debug.h"
+#include "lldb/Host/HostThread.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/lldb-types.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "lldb/Host/aix/Support.h"
+
+#include "NativeThreadAIX.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
+#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
+
+namespace lldb_private {
+class Status;
+class Scalar;
+
+namespace process_aix {
+/// \class NativeProcessAIX
+/// Manages communication with the inferior (debugee) process.
+///
+/// Upon construction, this class prepares and launches an inferior process
+/// for debugging.
+///
+/// Changes in the inferior process state are broadcasted.
+class NativeProcessAIX : public NativeProcessProtocol,
+ private NativeProcessSoftwareSingleStep {
+public:
+ class Manager : public NativeProcessProtocol::Manager {
+ public:
+ Manager(MainLoop &mainloop);
+
+ llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+ Launch(ProcessLaunchInfo &launch_info,
+ NativeDelegate &native_delegate) override;
+
+ llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+ Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
+
+ Extension GetSupportedExtensions() const override;
+
+ void AddProcess(NativeProcessAIX &process) {
+ m_processes.insert(&process);
+ }
+
+ void RemoveProcess(NativeProcessAIX &process) {
+ m_processes.erase(&process);
+ }
+
+ // Collect an event for the given tid, waiting for it if necessary.
+ void CollectThread(::pid_t tid);
+
+ private:
+ MainLoop::SignalHandleUP m_sigchld_handle;
+
+ llvm::SmallPtrSet<NativeProcessAIX *, 2> m_processes;
+
+ void SigchldHandler();
+ };
+
+ // NativeProcessProtocol Interface
+
+ ~NativeProcessAIX() override { m_manager.RemoveProcess(*this); }
+
+ Status Resume(const ResumeActionList &resume_actions) override;
+
+ Status Halt() override;
+
+ Status Detach() override;
+
+ Status Signal(int signo) override;
+
+ Status Interrupt() override;
+
+ Status Kill() override;
+
+ const ArchSpec &GetArchitecture() const override { return m_arch; }
+
+ Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) override;
+
+ Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
+
+ Status GetFileLoadAddress(const llvm::StringRef &file_name,
+ lldb::addr_t &load_addr) override;
+
+ static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
+ void *data = nullptr, size_t data_size = 0,
+ long *result = nullptr);
+
+// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
+
+private:
+ Manager &m_manager;
+ /*MainLoop::SignalHandleUP m_sigchld_handle;*/
+ ArchSpec m_arch;
+ /*MainLoop& m_main_loop;*/
+
+ // Private Instance Methods
+ NativeProcessAIX(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
+ const ArchSpec &arch, Manager &manager,
+ llvm::ArrayRef<::pid_t> tids);
+
+ // Returns a list of process threads that we have attached to.
+ static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
+
+ void MonitorSIGTRAP(const WaitStatus status, NativeThreadAIX &thread);
+
+ void MonitorBreakpoint(NativeThreadAIX &thread);
+
+ Status Detach(lldb::tid_t tid);
+
+ void SigchldHandler();
+
+};
+
+} // namespace process_aix
+} // namespace lldb_private
+
+#endif // #ifndef liblldb_NativeProcessAIX_H_
diff --git a/lldb/source/Plugins/Process/CMakeLists.txt b/lldb/source/Plugins/Process/CMakeLists.txt
index a51d0f7afd175..01bb5f462eba4 100644
--- a/lldb/source/Plugins/Process/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/CMakeLists.txt
@@ -7,6 +7,9 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
add_subdirectory(NetBSD)
add_subdirectory(POSIX)
+elseif (CMAKE_SYSTEM_NAME MATCHES "AIX")
+ add_subdirectory(AIX)
+ add_subdirectory(POSIX)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_subdirectory(Windows/Common)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
>From 3462b9263d4f268a89baf4b956b8dc851858fe0a Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 30 Nov 2024 01:32:53 -0600
Subject: [PATCH 02/11] Added base files for NativeProcess for AIX
---
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 31 -------------------
1 file changed, 31 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index 6661693b2fc02..a8d54483239ad 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "NativeProcessAIX.h"
-
#include <cerrno>
#include <cstdint>
#include <cstring>
@@ -20,50 +19,20 @@
#include <unordered_map>
#include "NativeThreadAIX.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
-#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/ProcessLaunchInfo.h"
-#include "lldb/Host/PseudoTerminal.h"
-#include "lldb/Host/ThreadLauncher.h"
-#include "lldb/Host/common/NativeRegisterContext.h"
-#include "lldb/Host/aix/Ptrace.h"
-#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/LLDBLog.h"
-#include "lldb/Utility/RegisterValue.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StringExtractor.h"
-#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Threading.h"
-#include <sys/reg.h>
-#include <sys/ptrace.h>
-#include <sys/ldr.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/user.h>
-#include <sys/wait.h>
-#include <sys/mman.h>
-#ifdef __aarch64__
-#include <asm/hwcap.h>
-#include <sys/auxv.h>
-#endif
-
-// Support hardware breakpoints in case it has not been defined
-#ifndef TRAP_HWBKPT
-#define TRAP_HWBKPT 4
-#endif
-
-#ifndef HWCAP2_MTE
-#define HWCAP2_MTE (1 << 18)
-#endif
using namespace lldb;
using namespace lldb_private;
>From e76b37b681150f7cf7ad498f405e9535d6be234e Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 30 Nov 2024 01:55:36 -0600
Subject: [PATCH 03/11] Added base files for NativeProcess for AIX
---
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 79 ++++++++-----------
1 file changed, 35 insertions(+), 44 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index a8d54483239ad..28f5623853878 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -7,16 +7,6 @@
//===----------------------------------------------------------------------===//
#include "NativeProcessAIX.h"
-#include <cerrno>
-#include <cstdint>
-#include <cstring>
-#include <unistd.h>
-#include <fstream>
-#include <mutex>
-#include <optional>
-#include <sstream>
-#include <string>
-#include <unordered_map>
#include "NativeThreadAIX.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "lldb/Host/Host.h"
@@ -33,6 +23,16 @@
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
+#include <cerrno>
+#include <cstdint>
+#include <cstring>
+#include <fstream>
+#include <mutex>
+#include <optional>
+#include <sstream>
+#include <string>
+#include <unistd.h>
+#include <unordered_map>
using namespace lldb;
using namespace lldb_private;
@@ -74,7 +74,7 @@ NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
- NativeDelegate &native_delegate) {
+ NativeDelegate &native_delegate) {
Log *log = GetLog(POSIXLog::Process);
Status status;
@@ -102,13 +102,13 @@ NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
ProcessInstanceInfo Info;
if (!Host::GetProcessInfo(pid, Info)) {
- return llvm::make_error<StringError>("Cannot get process architectrue",
- llvm::inconvertibleErrorCode());
- }
+ return llvm::make_error<StringError>("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+ }
- // Set the architecture to the exe architecture.
- LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
- Info.GetArchitecture().GetArchitectureName());
+ // Set the architecture to the exe architecture.
+ LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+ Info.GetArchitecture().GetArchitectureName());
return std::unique_ptr<NativeProcessAIX>(new NativeProcessAIX(
pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate,
@@ -117,21 +117,21 @@ NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
NativeProcessAIX::Manager::Attach(
- lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+ lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
Log *log = GetLog(POSIXLog::Process);
LLDB_LOG(log, "pid = {0:x}", pid);
ProcessInstanceInfo Info;
if (!Host::GetProcessInfo(pid, Info)) {
- return llvm::make_error<StringError>("Cannot get process architectrue",
- llvm::inconvertibleErrorCode());
- }
+ return llvm::make_error<StringError>("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+ }
auto tids_or = NativeProcessAIX::Attach(pid);
if (!tids_or)
return tids_or.takeError();
- return std::unique_ptr<NativeProcessAIX>(
- new NativeProcessAIX(pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+ return std::unique_ptr<NativeProcessAIX>(new NativeProcessAIX(
+ pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
}
NativeProcessAIX::Extension
@@ -144,18 +144,16 @@ NativeProcessAIX::Manager::GetSupportedExtensions() const {
return supported;
}
-void NativeProcessAIX::Manager::SigchldHandler() {
-}
+void NativeProcessAIX::Manager::SigchldHandler() {}
-void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {
-}
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
// Public Instance Methods
NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
- NativeDelegate &delegate,
- const ArchSpec &arch, Manager &manager,
- llvm::ArrayRef<::pid_t> tids)
+ NativeDelegate &delegate,
+ const ArchSpec &arch, Manager &manager,
+ llvm::ArrayRef<::pid_t> tids)
: NativeProcessProtocol(pid, terminal_fd, delegate), m_manager(manager),
m_arch(arch) {
manager.AddProcess(*this);
@@ -182,15 +180,11 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
}
void NativeProcessAIX::MonitorSIGTRAP(const WaitStatus status,
- NativeThreadAIX &thread) {
-}
+ NativeThreadAIX &thread) {}
-void NativeProcessAIX::MonitorBreakpoint(NativeThreadAIX &thread) {
-}
+void NativeProcessAIX::MonitorBreakpoint(NativeThreadAIX &thread) {}
-bool NativeProcessAIX::SupportHardwareSingleStepping() const {
- return false;
-}
+bool NativeProcessAIX::SupportHardwareSingleStepping() const { return false; }
Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
return Status();
@@ -211,9 +205,7 @@ Status NativeProcessAIX::Signal(int signo) {
return error;
}
-Status NativeProcessAIX::Interrupt() {
- return Status();
-}
+Status NativeProcessAIX::Interrupt() { return Status(); }
Status NativeProcessAIX::Kill() {
Status error;
@@ -221,7 +213,7 @@ Status NativeProcessAIX::Kill() {
}
Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
- bool hardware) {
+ bool hardware) {
if (hardware)
return SetHardwareBreakpoint(addr, size);
else
@@ -249,9 +241,8 @@ Status NativeProcessAIX::Detach(lldb::tid_t tid) {
// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
Status NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
- void *data, size_t data_size,
- long *result) {
+ void *data, size_t data_size,
+ long *result) {
Status error;
return error;
}
-
>From 1284f0b9099fcd9bb89bcfed29af3ab9904e69e8 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 30 Nov 2024 02:08:55 -0600
Subject: [PATCH 04/11] added missing format
---
.../Plugins/Process/AIX/NativeProcessAIX.h | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
index 2c07ba420d3fe..3532f1c1cacd4 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -19,11 +19,10 @@
#include "lldb/Utility/FileSpec.h"
#include "lldb/lldb-types.h"
#include "llvm/ADT/SmallPtrSet.h"
-#include "lldb/Host/aix/Support.h"
#include "NativeThreadAIX.h"
-#include "lldb/Host/common/NativeProcessProtocol.h"
#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
namespace lldb_private {
class Status;
@@ -38,7 +37,7 @@ namespace process_aix {
///
/// Changes in the inferior process state are broadcasted.
class NativeProcessAIX : public NativeProcessProtocol,
- private NativeProcessSoftwareSingleStep {
+ private NativeProcessSoftwareSingleStep {
public:
class Manager : public NativeProcessProtocol::Manager {
public:
@@ -46,16 +45,14 @@ class NativeProcessAIX : public NativeProcessProtocol,
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Launch(ProcessLaunchInfo &launch_info,
- NativeDelegate &native_delegate) override;
+ NativeDelegate &native_delegate) override;
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
Extension GetSupportedExtensions() const override;
- void AddProcess(NativeProcessAIX &process) {
- m_processes.insert(&process);
- }
+ void AddProcess(NativeProcessAIX &process) { m_processes.insert(&process); }
void RemoveProcess(NativeProcessAIX &process) {
m_processes.erase(&process);
@@ -102,7 +99,7 @@ class NativeProcessAIX : public NativeProcessProtocol,
void *data = nullptr, size_t data_size = 0,
long *result = nullptr);
-// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
+ // Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
private:
Manager &m_manager;
@@ -112,8 +109,8 @@ class NativeProcessAIX : public NativeProcessProtocol,
// Private Instance Methods
NativeProcessAIX(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
- const ArchSpec &arch, Manager &manager,
- llvm::ArrayRef<::pid_t> tids);
+ const ArchSpec &arch, Manager &manager,
+ llvm::ArrayRef<::pid_t> tids);
// Returns a list of process threads that we have attached to.
static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
@@ -125,7 +122,6 @@ class NativeProcessAIX : public NativeProcessProtocol,
Status Detach(lldb::tid_t tid);
void SigchldHandler();
-
};
} // namespace process_aix
>From 6d2ef7e5a53217793ff32cf49a5b49f118e7a365 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Tue, 10 Dec 2024 05:08:33 -0600
Subject: [PATCH 05/11] Addressing comments
---
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 95 +++++++++++--------
.../Plugins/Process/AIX/NativeProcessAIX.h | 27 ++----
2 files changed, 64 insertions(+), 58 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index 28f5623853878..5f3d41fac0322 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -7,32 +7,21 @@
//===----------------------------------------------------------------------===//
#include "NativeProcessAIX.h"
-#include "NativeThreadAIX.h"
-#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Symbol/ObjectFile.h"
-#include "lldb/Target/Process.h"
-#include "lldb/Target/Target.h"
-#include "lldb/Utility/LLDBAssert.h"
-#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/Status.h"
-#include "lldb/Utility/StringExtractor.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
-#include "llvm/Support/FileSystem.h"
#include <cerrno>
#include <cstdint>
#include <cstring>
-#include <fstream>
-#include <mutex>
-#include <optional>
#include <sstream>
#include <string>
#include <unistd.h>
-#include <unordered_map>
using namespace lldb;
using namespace lldb_private;
@@ -45,17 +34,17 @@ static_assert(sizeof(long) >= k_ptrace_word_size,
// Simple helper function to ensure flags are enabled on the given file
// descriptor.
-static Status EnsureFDFlags(int fd, int flags) {
- Status error;
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+ Error error;
int status = fcntl(fd, F_GETFL);
if (status == -1) {
- error = Status::FromErrno();
+ error = errorCodeToError(errnoAsErrorCode());
return error;
}
if (fcntl(fd, F_SETFL, status | flags) == -1) {
- error = Status::FromErrno();
+ error = errorCodeToError(errnoAsErrorCode());
return error;
}
@@ -136,10 +125,7 @@ NativeProcessAIX::Manager::Attach(
NativeProcessAIX::Extension
NativeProcessAIX::Manager::GetSupportedExtensions() const {
- NativeProcessAIX::Extension supported =
- Extension::multiprocess | Extension::fork | Extension::vfork |
- Extension::pass_signals | Extension::auxv | Extension::libraries_svr4 |
- Extension::siginfo_read;
+ NativeProcessAIX::Extension supported = {};
return supported;
}
@@ -169,11 +155,18 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
- Status status;
+ Error status;
if ((status = PtraceWrapper(PT_ATTACH, pid)).Fail()) {
- return status.ToError();
+ return errorCodeToError(errnoAsErrorCode());
}
+ int wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, nullptr, WNOHANG);
+ if (wpid <= 0) {
+ return llvm::errorCodeToError(
+ std::error_code(errno, std::generic_category()));
+ }
+ LLDB_LOG(log, "adding pid = {0}", pid);
+
std::vector<::pid_t> tids;
tids.push_back(pid);
return std::move(tids);
@@ -190,37 +183,37 @@ Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
return Status();
}
-Status NativeProcessAIX::Halt() {
- Status error;
+Error NativeProcessAIX::Halt() {
+ Error error;
return error;
}
-Status NativeProcessAIX::Detach() {
- Status error;
+Error NativeProcessAIX::Detach() {
+ Error error;
return error;
}
-Status NativeProcessAIX::Signal(int signo) {
- Status error;
+Error NativeProcessAIX::Signal(int signo) {
+ Error error;
return error;
}
-Status NativeProcessAIX::Interrupt() { return Status(); }
+Error NativeProcessAIX::Interrupt() { return Status(); }
-Status NativeProcessAIX::Kill() {
- Status error;
+Error NativeProcessAIX::Kill() {
+ Error error;
return error;
}
-Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
- bool hardware) {
+Error NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) {
if (hardware)
return SetHardwareBreakpoint(addr, size);
else
return SetSoftwareBreakpoint(addr, size);
}
-Status NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
+Error NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
if (hardware)
return RemoveHardwareBreakpoint(addr);
else
@@ -231,7 +224,7 @@ int8_t NativeProcessAIX::GetSignalInfo(WaitStatus wstatus) const {
return wstatus.status;
}
-Status NativeProcessAIX::Detach(lldb::tid_t tid) {
+Error NativeProcessAIX::Detach(lldb::tid_t tid) {
if (tid == LLDB_INVALID_THREAD_ID)
return Status();
@@ -240,9 +233,33 @@ Status NativeProcessAIX::Detach(lldb::tid_t tid) {
// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
-Status NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
- void *data, size_t data_size,
- long *result) {
- Status error;
+Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
+ void *data, size_t data_size,
+ long *result) {
+ Error error;
+ long int ret;
+
+ Log *log = GetLog(POSIXLog::Ptrace);
+ errno = 0;
+ if (req < PT_COMMAND_MAX) {
+ if (req == PT_ATTACH) {
+ ptrace64(req, pid, 0, 0, nullptr);
+ } else if (req == PT_DETACH) {
+ ptrace64(req, pid, 0, 0, nullptr);
+ }
+ } else {
+ assert(0 && "Not supported yet.");
+ }
+
+ if (errno) {
+ error = errorCodeToError(errnoAsErrorCode());
+ ret = -1;
+ }
+
+ LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3}, {4})={5:x}", req, pid, addr, data,
+ data_size, ret);
+ if (error.Fail())
+ LLDB_LOG(log, "ptrace() failed: {0}", error);
+
return error;
}
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
index 3532f1c1cacd4..2948d97dd39a6 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -6,27 +6,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef liblldb_NativeProcessAIX_H_
-#define liblldb_NativeProcessAIX_H_
-
-#include <csignal>
-#include <unordered_set>
+#ifndef LIBLLDB_NATIVEPROCESSAIX_H_
+#define LIBLLDB_NATIVEPROCESSAIX_H_
+#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
#include "lldb/Host/Debug.h"
-#include "lldb/Host/HostThread.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/lldb-types.h"
#include "llvm/ADT/SmallPtrSet.h"
-
-#include "NativeThreadAIX.h"
-#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
-#include "lldb/Host/common/NativeProcessProtocol.h"
+#include <csignal>
+#include <unordered_set>
namespace lldb_private {
-class Status;
-class Scalar;
namespace process_aix {
/// \class NativeProcessAIX
@@ -36,8 +30,7 @@ namespace process_aix {
/// for debugging.
///
/// Changes in the inferior process state are broadcasted.
-class NativeProcessAIX : public NativeProcessProtocol,
- private NativeProcessSoftwareSingleStep {
+class NativeProcessAIX : public NativeProcessProtocol {
public:
class Manager : public NativeProcessProtocol::Manager {
public:
@@ -99,13 +92,9 @@ class NativeProcessAIX : public NativeProcessProtocol,
void *data = nullptr, size_t data_size = 0,
long *result = nullptr);
- // Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
-
private:
Manager &m_manager;
- /*MainLoop::SignalHandleUP m_sigchld_handle;*/
ArchSpec m_arch;
- /*MainLoop& m_main_loop;*/
// Private Instance Methods
NativeProcessAIX(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
@@ -127,4 +116,4 @@ class NativeProcessAIX : public NativeProcessProtocol,
} // namespace process_aix
} // namespace lldb_private
-#endif // #ifndef liblldb_NativeProcessAIX_H_
+#endif // #ifndef LIBLLDB_NATIVEPROCESSAIX_H_
>From 66bdca4a7f20f7a2aa895e45fab3a7d95c4e25b3 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 22 Feb 2025 10:11:17 -0600
Subject: [PATCH 06/11] Updated after building lldb-server
---
lldb/cmake/modules/LLDBConfig.cmake | 2 +-
.../source/Plugins/Process/AIX/CMakeLists.txt | 2 +
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 85 ++++++++++++-------
.../Plugins/Process/AIX/NativeProcessAIX.h | 36 ++++++--
lldb/tools/lldb-server/CMakeLists.txt | 4 +
5 files changed, 89 insertions(+), 40 deletions(-)
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index 747f7e6038181..e1116fbb30853 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -292,7 +292,7 @@ endif()
# Figure out if lldb could use lldb-server. If so, then we'll
# ensure we build lldb-server when an lldb target is being built.
-if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")
+if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows|AIX")
set(LLDB_CAN_USE_LLDB_SERVER ON)
else()
set(LLDB_CAN_USE_LLDB_SERVER OFF)
diff --git a/lldb/source/Plugins/Process/AIX/CMakeLists.txt b/lldb/source/Plugins/Process/AIX/CMakeLists.txt
index 4fabbe9302287..9a3c77bd2ffeb 100644
--- a/lldb/source/Plugins/Process/AIX/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/AIX/CMakeLists.txt
@@ -12,3 +12,5 @@ add_lldb_library(lldbPluginProcessAIX
LINK_COMPONENTS
Support
)
+
+target_compile_definitions(lldbPluginProcessAIX PRIVATE "-D_ALL_SOURCE")
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index 5f3d41fac0322..a46c7a9311834 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -7,9 +7,11 @@
//===----------------------------------------------------------------------===//
#include "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/State.h"
@@ -21,6 +23,7 @@
#include <cstring>
#include <sstream>
#include <string>
+#include <sys/ptrace.h>
#include <unistd.h>
using namespace lldb;
@@ -34,17 +37,17 @@ static_assert(sizeof(long) >= k_ptrace_word_size,
// Simple helper function to ensure flags are enabled on the given file
// descriptor.
-static llvm::Error EnsureFDFlags(int fd, int flags) {
- Error error;
+static Status EnsureFDFlags(int fd, int flags) {
+ Status error;
int status = fcntl(fd, F_GETFL);
if (status == -1) {
- error = errorCodeToError(errnoAsErrorCode());
+ error = Status::FromErrno();
return error;
}
if (fcntl(fd, F_SETFL, status | flags) == -1) {
- error = errorCodeToError(errnoAsErrorCode());
+ error = Status::FromErrno();
return error;
}
@@ -123,6 +126,10 @@ NativeProcessAIX::Manager::Attach(
pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
}
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+ return LLDB_INVALID_ADDRESS;
+}
+
NativeProcessAIX::Extension
NativeProcessAIX::Manager::GetSupportedExtensions() const {
NativeProcessAIX::Extension supported = {};
@@ -155,7 +162,8 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
- Error status;
+ Log *log = GetLog(POSIXLog::Process);
+ Status status;
if ((status = PtraceWrapper(PT_ATTACH, pid)).Fail()) {
return errorCodeToError(errnoAsErrorCode());
}
@@ -172,59 +180,76 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
return std::move(tids);
}
-void NativeProcessAIX::MonitorSIGTRAP(const WaitStatus status,
- NativeThreadAIX &thread) {}
-
-void NativeProcessAIX::MonitorBreakpoint(NativeThreadAIX &thread) {}
-
bool NativeProcessAIX::SupportHardwareSingleStepping() const { return false; }
Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
return Status();
}
-Error NativeProcessAIX::Halt() {
- Error error;
+Status NativeProcessAIX::Halt() {
+ Status error;
return error;
}
-Error NativeProcessAIX::Detach() {
- Error error;
+Status NativeProcessAIX::Detach() {
+ Status error;
return error;
}
-Error NativeProcessAIX::Signal(int signo) {
- Error error;
+Status NativeProcessAIX::Signal(int signo) {
+ Status error;
return error;
}
-Error NativeProcessAIX::Interrupt() { return Status(); }
+Status NativeProcessAIX::Interrupt() { return Status(); }
-Error NativeProcessAIX::Kill() {
- Error error;
+Status NativeProcessAIX::Kill() {
+ Status error;
return error;
}
-Error NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
- bool hardware) {
+Status NativeProcessAIX::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+ size_t &bytes_read) {
+ return Status();
+}
+
+Status NativeProcessAIX::WriteMemory(lldb::addr_t addr, const void *buf,
+ size_t size, size_t &bytes_written) {
+ return Status();
+}
+
+size_t NativeProcessAIX::UpdateThreads() {
+ // The NativeProcessAIX monitoring threads are always up to date with
+ // respect to thread state and they keep the thread list populated properly.
+ // All this method needs to do is return the thread count.
+ return m_threads.size();
+}
+
+Status NativeProcessAIX::GetLoadedModuleFileSpec(const char *module_path,
+ FileSpec &file_spec) {
+ return Status();
+}
+
+Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) {
if (hardware)
return SetHardwareBreakpoint(addr, size);
else
return SetSoftwareBreakpoint(addr, size);
}
-Error NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
+Status NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
if (hardware)
return RemoveHardwareBreakpoint(addr);
else
return NativeProcessProtocol::RemoveBreakpoint(addr);
}
-int8_t NativeProcessAIX::GetSignalInfo(WaitStatus wstatus) const {
- return wstatus.status;
+Status NativeProcessAIX::GetSignalInfo(lldb::tid_t tid, void *siginfo) const {
+ return Status();
}
-Error NativeProcessAIX::Detach(lldb::tid_t tid) {
+Status NativeProcessAIX::Detach(lldb::tid_t tid) {
if (tid == LLDB_INVALID_THREAD_ID)
return Status();
@@ -233,10 +258,10 @@ Error NativeProcessAIX::Detach(lldb::tid_t tid) {
// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
-Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
- void *data, size_t data_size,
- long *result) {
- Error error;
+Status NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
+ void *data, size_t data_size,
+ long *result) {
+ Status error;
long int ret;
Log *log = GetLog(POSIXLog::Ptrace);
@@ -252,7 +277,7 @@ Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
}
if (errno) {
- error = errorCodeToError(errnoAsErrorCode());
+ error = Status::FromErrno();
ret = -1;
}
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
index 2948d97dd39a6..180ecba3621a8 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -12,6 +12,7 @@
#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
#include "lldb/Host/Debug.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
+#include "lldb/Host/linux/Support.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
@@ -20,9 +21,7 @@
#include <csignal>
#include <unordered_set>
-namespace lldb_private {
-
-namespace process_aix {
+namespace lldb_private::process_aix {
/// \class NativeProcessAIX
/// Manages communication with the inferior (debugee) process.
///
@@ -78,6 +77,16 @@ class NativeProcessAIX : public NativeProcessProtocol {
Status Kill() override;
+ lldb::addr_t GetSharedLibraryInfoAddress() override;
+
+ Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+ size_t &bytes_read) override;
+
+ Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
+ size_t &bytes_written) override;
+
+ size_t UpdateThreads() override;
+
const ArchSpec &GetArchitecture() const override { return m_arch; }
Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
@@ -85,6 +94,14 @@ class NativeProcessAIX : public NativeProcessProtocol {
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
+ Status GetLoadedModuleFileSpec(const char *module_path,
+ FileSpec &file_spec) override;
+
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ GetAuxvData() const override {
+ return getProcFile(GetID(), "auxv");
+ }
+
Status GetFileLoadAddress(const llvm::StringRef &file_name,
lldb::addr_t &load_addr) override;
@@ -92,6 +109,12 @@ class NativeProcessAIX : public NativeProcessProtocol {
void *data = nullptr, size_t data_size = 0,
long *result = nullptr);
+ bool SupportHardwareSingleStepping() const;
+
+ /// Writes a siginfo_t structure corresponding to the given thread ID to the
+ /// memory region pointed to by \p siginfo.
+ Status GetSignalInfo(lldb::tid_t tid, void *siginfo) const;
+
private:
Manager &m_manager;
ArchSpec m_arch;
@@ -104,16 +127,11 @@ class NativeProcessAIX : public NativeProcessProtocol {
// Returns a list of process threads that we have attached to.
static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
- void MonitorSIGTRAP(const WaitStatus status, NativeThreadAIX &thread);
-
- void MonitorBreakpoint(NativeThreadAIX &thread);
-
Status Detach(lldb::tid_t tid);
void SigchldHandler();
};
-} // namespace process_aix
-} // namespace lldb_private
+} // namespace lldb_private::process_aix
#endif // #ifndef LIBLLDB_NATIVEPROCESSAIX_H_
diff --git a/lldb/tools/lldb-server/CMakeLists.txt b/lldb/tools/lldb-server/CMakeLists.txt
index 8d6843ec5ddd8..0135b367fcc21 100644
--- a/lldb/tools/lldb-server/CMakeLists.txt
+++ b/lldb/tools/lldb-server/CMakeLists.txt
@@ -8,6 +8,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
list(APPEND LLDB_PLUGINS lldbPluginProcessLinux)
endif()
+if(CMAKE_SYSTEM_NAME MATCHES "AIX")
+ list(APPEND LLDB_PLUGINS lldbPluginProcessAIX)
+endif()
+
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
list(APPEND LLDB_PLUGINS lldbPluginProcessFreeBSD)
endif()
>From 4e21ddbbd93f3131ae742431199893a4bee98968 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Tue, 11 Mar 2025 07:36:50 -0500
Subject: [PATCH 07/11] Updated files
---
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 69 +++++++------------
.../Plugins/Process/AIX/NativeProcessAIX.h | 15 ++--
2 files changed, 34 insertions(+), 50 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index a46c7a9311834..1e5192a3a0718 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -37,21 +37,13 @@ static_assert(sizeof(long) >= k_ptrace_word_size,
// Simple helper function to ensure flags are enabled on the given file
// descriptor.
-static Status EnsureFDFlags(int fd, int flags) {
- Status error;
-
+static llvm::Error EnsureFDFlags(int fd, int flags) {
int status = fcntl(fd, F_GETFL);
- if (status == -1) {
- error = Status::FromErrno();
- return error;
- }
-
- if (fcntl(fd, F_SETFL, status | flags) == -1) {
- error = Status::FromErrno();
- return error;
- }
-
- return error;
+ if (status == -1)
+ return errorCodeToError(errnoAsErrorCode());
+ if (fcntl(fd, F_SETFL, status | flags) == -1)
+ return errorCodeToError(errnoAsErrorCode());
+ return Error::success();
}
NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
@@ -151,8 +143,8 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
m_arch(arch) {
manager.AddProcess(*this);
if (m_terminal_fd != -1) {
- Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
- assert(status.Success());
+ llvm::Error error = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
+ assert(!error && "terminal fd invalid");
}
// Let our process instance know the thread has stopped.
@@ -161,12 +153,10 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
}
llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
-
Log *log = GetLog(POSIXLog::Process);
Status status;
- if ((status = PtraceWrapper(PT_ATTACH, pid)).Fail()) {
+ if (PtraceWrapper(PT_ATTACH, pid))
return errorCodeToError(errnoAsErrorCode());
- }
int wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, nullptr, WNOHANG);
if (wpid <= 0) {
@@ -234,57 +224,50 @@ Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
bool hardware) {
if (hardware)
return SetHardwareBreakpoint(addr, size);
- else
- return SetSoftwareBreakpoint(addr, size);
+ return SetSoftwareBreakpoint(addr, size);
}
Status NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
if (hardware)
return RemoveHardwareBreakpoint(addr);
- else
- return NativeProcessProtocol::RemoveBreakpoint(addr);
+ return NativeProcessProtocol::RemoveBreakpoint(addr);
}
Status NativeProcessAIX::GetSignalInfo(lldb::tid_t tid, void *siginfo) const {
return Status();
}
-Status NativeProcessAIX::Detach(lldb::tid_t tid) {
+llvm::Error NativeProcessAIX::Detach(lldb::tid_t tid) {
if (tid == LLDB_INVALID_THREAD_ID)
- return Status();
+ return llvm::Error::success();
return PtraceWrapper(PT_DETACH, tid);
}
// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
-Status NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
- void *data, size_t data_size,
- long *result) {
- Status error;
+llvm::Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid,
+ void *addr, void *data,
+ size_t data_size, long *result) {
long int ret;
Log *log = GetLog(POSIXLog::Ptrace);
errno = 0;
- if (req < PT_COMMAND_MAX) {
- if (req == PT_ATTACH) {
- ptrace64(req, pid, 0, 0, nullptr);
- } else if (req == PT_DETACH) {
- ptrace64(req, pid, 0, 0, nullptr);
- }
- } else {
- assert(0 && "Not supported yet.");
+ switch (req) {
+ case PT_ATTACH:
+ case PT_DETACH:
+ ret = ptrace64(req, pid, 0, 0, nullptr);
+ break;
+ default:
+ assert(0 && "PT_ request not supported yet.");
}
if (errno) {
- error = Status::FromErrno();
- ret = -1;
+ *result = -1;
+ LLDB_LOG(log, "ptrace() failed");
}
-
LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3}, {4})={5:x}", req, pid, addr, data,
data_size, ret);
- if (error.Fail())
- LLDB_LOG(log, "ptrace() failed: {0}", error);
- return error;
+ return Error::success();
}
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
index 180ecba3621a8..9f9113a27a9a1 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LIBLLDB_NATIVEPROCESSAIX_H_
-#define LIBLLDB_NATIVEPROCESSAIX_H_
+#ifndef LLDB_SOURCE_PLUGINS_PROCESS_AIX_NATIVEPROCESSAIX_H
+#define LLDB_SOURCE_PLUGINS_PROCESS_AIX_NATIVEPROCESSAIX_H
#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
#include "lldb/Host/Debug.h"
@@ -105,9 +105,10 @@ class NativeProcessAIX : public NativeProcessProtocol {
Status GetFileLoadAddress(const llvm::StringRef &file_name,
lldb::addr_t &load_addr) override;
- static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
- void *data = nullptr, size_t data_size = 0,
- long *result = nullptr);
+ static llvm::Error PtraceWrapper(int req, lldb::pid_t pid,
+ void *addr = nullptr, void *data = nullptr,
+ size_t data_size = 0,
+ long *result = nullptr);
bool SupportHardwareSingleStepping() const;
@@ -127,11 +128,11 @@ class NativeProcessAIX : public NativeProcessProtocol {
// Returns a list of process threads that we have attached to.
static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
- Status Detach(lldb::tid_t tid);
+ llvm::Error Detach(lldb::tid_t tid);
void SigchldHandler();
};
} // namespace lldb_private::process_aix
-#endif // #ifndef LIBLLDB_NATIVEPROCESSAIX_H_
+#endif // #ifndef LLDB_SOURCE_PLUGINS_PROCESS_AIX_NATIVEPROCESSAIX_H
>From b2f3545fb1f5b205babb382e0f2527ab481c1d7c Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Tue, 11 Mar 2025 07:51:23 -0500
Subject: [PATCH 08/11] Updated files
---
lldb/cmake/modules/LLDBConfig.cmake | 2 +-
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 29 +++++--------------
2 files changed, 8 insertions(+), 23 deletions(-)
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index e1116fbb30853..9df71edd8b359 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -292,7 +292,7 @@ endif()
# Figure out if lldb could use lldb-server. If so, then we'll
# ensure we build lldb-server when an lldb target is being built.
-if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows|AIX")
+if (CMAKE_SYSTEM_NAME MATCHES "AIX|Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")
set(LLDB_CAN_USE_LLDB_SERVER ON)
else()
set(LLDB_CAN_USE_LLDB_SERVER OFF)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index 1e5192a3a0718..f89ccf5f789d4 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -142,10 +142,8 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
: NativeProcessProtocol(pid, terminal_fd, delegate), m_manager(manager),
m_arch(arch) {
manager.AddProcess(*this);
- if (m_terminal_fd != -1) {
- llvm::Error error = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
- assert(!error && "terminal fd invalid");
- }
+ if (m_terminal_fd != -1)
+ cantFail(EnsureFDFlags(m_terminal_fd, O_NONBLOCK));
// Let our process instance know the thread has stopped.
SetCurrentThreadID(tids[0]);
@@ -160,8 +158,7 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
int wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, nullptr, WNOHANG);
if (wpid <= 0) {
- return llvm::errorCodeToError(
- std::error_code(errno, std::generic_category()));
+ return llvm::errorCodeToError(errnoAsErrorCode());
}
LLDB_LOG(log, "adding pid = {0}", pid);
@@ -176,27 +173,15 @@ Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
return Status();
}
-Status NativeProcessAIX::Halt() {
- Status error;
- return error;
-}
+Status NativeProcessAIX::Halt() { return Status(); }
-Status NativeProcessAIX::Detach() {
- Status error;
- return error;
-}
+Status NativeProcessAIX::Detach() { return Status(); }
-Status NativeProcessAIX::Signal(int signo) {
- Status error;
- return error;
-}
+Status NativeProcessAIX::Signal(int signo) { return Status(); }
Status NativeProcessAIX::Interrupt() { return Status(); }
-Status NativeProcessAIX::Kill() {
- Status error;
- return error;
-}
+Status NativeProcessAIX::Kill() { return Status(); }
Status NativeProcessAIX::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
size_t &bytes_read) {
>From b180910cd898c3894d6b0d85a6c69db16b9de198 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Tue, 11 Mar 2025 08:39:45 -0500
Subject: [PATCH 09/11] Optimizing
---
lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index f89ccf5f789d4..d1b85f8a00154 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -162,9 +162,7 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
}
LLDB_LOG(log, "adding pid = {0}", pid);
- std::vector<::pid_t> tids;
- tids.push_back(pid);
- return std::move(tids);
+ return std::vector<::pid_t>{pid};
}
bool NativeProcessAIX::SupportHardwareSingleStepping() const { return false; }
>From c26d76ee5efa5cf11abb1179211c807d7a23c8f6 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Wed, 12 Mar 2025 21:53:51 -0500
Subject: [PATCH 10/11] Addressed comments
---
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 121 ++++++++++++++----
.../Plugins/Process/AIX/NativeProcessAIX.h | 11 +-
2 files changed, 102 insertions(+), 30 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index d1b85f8a00154..4c561ecea020f 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -1,4 +1,4 @@
-//===-- NativeProcessAIX.cpp --------------------------------------------===//
+//===-- NativeProcessAIX.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -37,7 +37,7 @@ static_assert(sizeof(long) >= k_ptrace_word_size,
// Simple helper function to ensure flags are enabled on the given file
// descriptor.
-static llvm::Error EnsureFDFlags(int fd, int flags) {
+static llvm::Error SetFDFlags(int fd, int flags) {
int status = fcntl(fd, F_GETFL);
if (status == -1)
return errorCodeToError(errnoAsErrorCode());
@@ -122,16 +122,84 @@ lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
return LLDB_INVALID_ADDRESS;
}
-NativeProcessAIX::Extension
-NativeProcessAIX::Manager::GetSupportedExtensions() const {
- NativeProcessAIX::Extension supported = {};
+static std::optional<std::pair<lldb::pid_t, WaitStatus>> WaitPid() {
+ Log *log = GetLog(POSIXLog::Process);
+
+ int status;
+ ::pid_t wait_pid =
+ llvm::sys::RetryAfterSignal(-1, ::waitpid, -1, &status, WNOHANG);
+
+ if (wait_pid == 0)
+ return std::nullopt;
+
+ if (wait_pid == -1) {
+ Status error(errno, eErrorTypePOSIX);
+ LLDB_LOG(log, "waitpid(-1, &status, _) failed: {0}", error);
+ return std::nullopt;
+ }
- return supported;
+ WaitStatus wait_status = WaitStatus::Decode(status);
+
+ LLDB_LOG(log, "waitpid(-1, &status, _) = {0}, status = {1}", wait_pid,
+ wait_status);
+ return std::make_pair(wait_pid, wait_status);
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {
+ Log *log = GetLog(POSIXLog::Process);
+ while (true) {
+ auto wait_result = WaitPid();
+ if (!wait_result)
+ return;
+ lldb::pid_t pid = wait_result->first;
+ WaitStatus status = wait_result->second;
+
+ // Ask each process whether it wants to handle the event. Each event should
+ // be handled by exactly one process, but thread creation events require
+ // special handling.
+ // Thread creation consists of two events (one on the parent and one on the
+ // child thread) and they can arrive in any order nondeterministically. The
+ // parent event carries the information about the child thread, but not
+ // vice-versa. This means that if the child event arrives first, it may not
+ // be handled by any process (because it doesn't know the thread belongs to
+ // it).
+ bool handled = llvm::any_of(m_processes, [&](NativeProcessAIX *process) {
+ return process->TryHandleWaitStatus(pid, status);
+ });
+ if (!handled) {
+ if (status.type == WaitStatus::Stop && status.status == SIGSTOP) {
+ // Store the thread creation event for later collection.
+ m_unowned_threads.insert(pid);
+ } else {
+ LLDB_LOG(log, "Ignoring waitpid event {0} for pid {1}", status, pid);
+ }
+ }
+ }
}
-void NativeProcessAIX::Manager::SigchldHandler() {}
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {
+ Log *log = GetLog(POSIXLog::Process);
-void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+ if (m_unowned_threads.erase(tid))
+ return; // We've encountered this thread already.
+
+ // The TID is not tracked yet, let's wait for it to appear.
+ int status = -1;
+ LLDB_LOG(log,
+ "received clone event for tid {0}. tid not tracked yet, "
+ "waiting for it to appear...",
+ tid);
+ ::pid_t wait_pid =
+ llvm::sys::RetryAfterSignal(-1, ::waitpid, tid, &status, P_ALL);
+
+ // It's theoretically possible to get other events if the entire process was
+ // SIGKILLed before we got a chance to check this. In that case, we'll just
+ // clean everything up when we get the process exit event.
+
+ LLDB_LOG(log,
+ "waitpid({0}, &status, __WALL) => {1} (errno: {2}, status = {3})",
+ tid, wait_pid, errno, WaitStatus::Decode(status));
+}
// Public Instance Methods
@@ -143,7 +211,7 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
m_arch(arch) {
manager.AddProcess(*this);
if (m_terminal_fd != -1)
- cantFail(EnsureFDFlags(m_terminal_fd, O_NONBLOCK));
+ cantFail(SetFDFlags(m_terminal_fd, O_NONBLOCK));
// Let our process instance know the thread has stopped.
SetCurrentThreadID(tids[0]);
@@ -157,38 +225,47 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
return errorCodeToError(errnoAsErrorCode());
int wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, nullptr, WNOHANG);
- if (wpid <= 0) {
+ if (wpid <= 0)
return llvm::errorCodeToError(errnoAsErrorCode());
- }
LLDB_LOG(log, "adding pid = {0}", pid);
return std::vector<::pid_t>{pid};
}
+bool NativeProcessAIX::TryHandleWaitStatus(lldb::pid_t pid, WaitStatus status) {
+ if (pid == GetID() &&
+ (status.type == WaitStatus::Exit || status.type == WaitStatus::Signal)) {
+ // The process exited. We're done monitoring. Report to delegate.
+ SetExitStatus(status, true);
+ return true;
+ }
+ return false;
+}
+
bool NativeProcessAIX::SupportHardwareSingleStepping() const { return false; }
Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
- return Status();
+ return Status("unsupported");
}
-Status NativeProcessAIX::Halt() { return Status(); }
+Status NativeProcessAIX::Halt() { return Status("unsupported"); }
-Status NativeProcessAIX::Detach() { return Status(); }
+Status NativeProcessAIX::Detach() { return Status("unsupported"); }
-Status NativeProcessAIX::Signal(int signo) { return Status(); }
+Status NativeProcessAIX::Signal(int signo) { return Status("unsupported"); }
-Status NativeProcessAIX::Interrupt() { return Status(); }
+Status NativeProcessAIX::Interrupt() { return Status("unsupported"); }
-Status NativeProcessAIX::Kill() { return Status(); }
+Status NativeProcessAIX::Kill() { return Status("unsupported"); }
Status NativeProcessAIX::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
size_t &bytes_read) {
- return Status();
+ return Status("unsupported");
}
Status NativeProcessAIX::WriteMemory(lldb::addr_t addr, const void *buf,
size_t size, size_t &bytes_written) {
- return Status();
+ return Status("unsupported");
}
size_t NativeProcessAIX::UpdateThreads() {
@@ -200,7 +277,7 @@ size_t NativeProcessAIX::UpdateThreads() {
Status NativeProcessAIX::GetLoadedModuleFileSpec(const char *module_path,
FileSpec &file_spec) {
- return Status();
+ return Status("unsupported");
}
Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
@@ -216,10 +293,6 @@ Status NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
return NativeProcessProtocol::RemoveBreakpoint(addr);
}
-Status NativeProcessAIX::GetSignalInfo(lldb::tid_t tid, void *siginfo) const {
- return Status();
-}
-
llvm::Error NativeProcessAIX::Detach(lldb::tid_t tid) {
if (tid == LLDB_INVALID_THREAD_ID)
return llvm::Error::success();
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
index 9f9113a27a9a1..01e799239d1ac 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -42,8 +42,6 @@ class NativeProcessAIX : public NativeProcessProtocol {
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
- Extension GetSupportedExtensions() const override;
-
void AddProcess(NativeProcessAIX &process) { m_processes.insert(&process); }
void RemoveProcess(NativeProcessAIX &process) {
@@ -58,6 +56,9 @@ class NativeProcessAIX : public NativeProcessProtocol {
llvm::SmallPtrSet<NativeProcessAIX *, 2> m_processes;
+ // Threads (events) which haven't been claimed by any process.
+ llvm::DenseSet<::pid_t> m_unowned_threads;
+
void SigchldHandler();
};
@@ -112,10 +113,6 @@ class NativeProcessAIX : public NativeProcessProtocol {
bool SupportHardwareSingleStepping() const;
- /// Writes a siginfo_t structure corresponding to the given thread ID to the
- /// memory region pointed to by \p siginfo.
- Status GetSignalInfo(lldb::tid_t tid, void *siginfo) const;
-
private:
Manager &m_manager;
ArchSpec m_arch;
@@ -125,6 +122,8 @@ class NativeProcessAIX : public NativeProcessProtocol {
const ArchSpec &arch, Manager &manager,
llvm::ArrayRef<::pid_t> tids);
+ bool TryHandleWaitStatus(lldb::pid_t pid, WaitStatus status);
+
// Returns a list of process threads that we have attached to.
static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
>From 501304c27f3b0732bf690f198c7614a239402d51 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Wed, 12 Mar 2025 22:13:16 -0500
Subject: [PATCH 11/11] Addressed comments
---
.../Plugins/Process/AIX/NativeProcessAIX.cpp | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index 4c561ecea020f..e7d2b1219f257 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -9,6 +9,7 @@
#include "NativeProcessAIX.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
@@ -91,12 +92,13 @@ NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
}
// Set the architecture to the exe architecture.
- LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
- Info.GetArchitecture().GetArchitectureName());
+ LLDB_LOG(
+ log, "pid = {0}, detected architecture {1}", pid,
+ HostInfo::GetArchitecture(HostInfo::eArchKind64).GetArchitectureName());
return std::unique_ptr<NativeProcessAIX>(new NativeProcessAIX(
pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate,
- Info.GetArchitecture(), *this, {pid}));
+ HostInfo::GetArchitecture(HostInfo::eArchKind64), *this, {pid}));
}
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
@@ -115,7 +117,8 @@ NativeProcessAIX::Manager::Attach(
return tids_or.takeError();
return std::unique_ptr<NativeProcessAIX>(new NativeProcessAIX(
- pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+ pid, -1, native_delegate,
+ HostInfo::GetArchitecture(HostInfo::eArchKind64), *this, *tids_or));
}
lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
@@ -300,8 +303,6 @@ llvm::Error NativeProcessAIX::Detach(lldb::tid_t tid) {
return PtraceWrapper(PT_DETACH, tid);
}
-// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
-// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
llvm::Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid,
void *addr, void *data,
size_t data_size, long *result) {
@@ -315,7 +316,7 @@ llvm::Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid,
ret = ptrace64(req, pid, 0, 0, nullptr);
break;
default:
- assert(0 && "PT_ request not supported yet.");
+ llvm_unreachable("PT_ request not supported yet.");
}
if (errno) {
More information about the lldb-commits
mailing list