[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)
Hemang Gadhavi via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 15 22:50:55 PDT 2025
https://github.com/HemangGadhavi updated https://github.com/llvm/llvm-project/pull/134354
>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi <hemang.gadhavi at ibm.com>
Date: Fri, 4 Apr 2025 00:59:17 -0500
Subject: [PATCH 1/4] [lldb][AIX] get host info for AIX
---
lldb/source/Host/CMakeLists.txt | 1 +
lldb/source/Host/aix/Host.cpp | 156 +++++++++++++++++++++++++++++++-
2 files changed, 156 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index a2ae6f1430c38..a02b1c104396e 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -141,6 +141,7 @@ else()
add_host_subdirectory(aix
aix/Host.cpp
aix/HostInfoAIX.cpp
+ linux/Support.cpp
)
endif()
endif()
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
index 751c4fbcc9368..6ba3e05348df1 100644
--- a/lldb/source/Host/aix/Host.cpp
+++ b/lldb/source/Host/aix/Host.cpp
@@ -6,18 +6,172 @@
//
//===----------------------------------------------------------------------===//
+#include <fcntl.h>
+#include <sstream>
+#include <sys/procfs.h>
+
#include "lldb/Host/Host.h"
+#include "lldb/Host/linux/Support.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/Status.h"
+#include "llvm/BinaryFormat/XCOFF.h"
+using namespace llvm;
+using namespace lldb;
using namespace lldb_private;
+namespace {
+enum class ProcessState {
+ Unknown,
+ Dead,
+ DiskSleep,
+ Idle,
+ Paging,
+ Parked,
+ Running,
+ Sleeping,
+ TracedOrStopped,
+ Zombie,
+};
+}
+
+static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
+ ProcessState &State, ::pid_t &TracerPid,
+ ::pid_t &Tgid) {
+ Log *log = GetLog(LLDBLog::Host);
+
+ auto BufferOrError = getProcFile(Pid, "status");
+ if (!BufferOrError)
+ return false;
+
+ llvm::StringRef Rest = BufferOrError.get()->getBuffer();
+ while (!Rest.empty()) {
+ llvm::StringRef Line;
+ std::tie(Line, Rest) = Rest.split('\n');
+
+ if (Line.consume_front("Gid:")) {
+ // Real, effective, saved set, and file system GIDs. Read the first two.
+ Line = Line.ltrim();
+ uint32_t RGid, EGid;
+ Line.consumeInteger(10, RGid);
+ Line = Line.ltrim();
+ Line.consumeInteger(10, EGid);
+
+ ProcessInfo.SetGroupID(RGid);
+ ProcessInfo.SetEffectiveGroupID(EGid);
+ } else if (Line.consume_front("Uid:")) {
+ // Real, effective, saved set, and file system UIDs. Read the first two.
+ Line = Line.ltrim();
+ uint32_t RUid, EUid;
+ Line.consumeInteger(10, RUid);
+ Line = Line.ltrim();
+ Line.consumeInteger(10, EUid);
+
+ ProcessInfo.SetUserID(RUid);
+ ProcessInfo.SetEffectiveUserID(EUid);
+ } else if (Line.consume_front("PPid:")) {
+ ::pid_t PPid;
+ Line.ltrim().consumeInteger(10, PPid);
+ ProcessInfo.SetParentProcessID(PPid);
+ } else if (Line.consume_front("State:")) {
+ State = llvm::StringSwitch<ProcessState>(Line.ltrim().take_front(1))
+ .Case("D", ProcessState::DiskSleep)
+ .Case("I", ProcessState::Idle)
+ .Case("R", ProcessState::Running)
+ .Case("S", ProcessState::Sleeping)
+ .CaseLower("T", ProcessState::TracedOrStopped)
+ .Case("W", ProcessState::Paging)
+ .Case("P", ProcessState::Parked)
+ .Case("X", ProcessState::Dead)
+ .Case("Z", ProcessState::Zombie)
+ .Default(ProcessState::Unknown);
+ if (State == ProcessState::Unknown) {
+ LLDB_LOG(log, "Unknown process state {0}", Line);
+ }
+ } else if (Line.consume_front("TracerPid:")) {
+ Line = Line.ltrim();
+ Line.consumeInteger(10, TracerPid);
+ } else if (Line.consume_front("Tgid:")) {
+ Line = Line.ltrim();
+ Line.consumeInteger(10, Tgid);
+ }
+ }
+ return true;
+}
+
+static void GetExePathAndArch(::pid_t pid, ProcessInstanceInfo &process_info) {
+ Log *log = GetLog(LLDBLog::Process);
+ std::string ExePath(PATH_MAX, '\0');
+ struct psinfo psinfoData;
+
+ // We can't use getProcFile here because proc/[pid]/exe is a symbolic link.
+ llvm::SmallString<64> ProcExe;
+ (llvm::Twine("/proc/") + llvm::Twine(pid) + "/cwd").toVector(ProcExe);
+
+ ssize_t len = readlink(ProcExe.c_str(), &ExePath[0], PATH_MAX);
+ if (len > 0) {
+ ExePath.resize(len);
+
+ struct stat statData;
+
+ std::ostringstream oss;
+
+ oss << "/proc/" << std::dec << pid << "/psinfo";
+ assert(stat(oss.str().c_str(), &statData) == 0);
+
+ const int fd = open(oss.str().c_str(), O_RDONLY);
+ assert(fd >= 0);
+
+ ssize_t readNum = read(fd, &psinfoData, sizeof(psinfoData));
+ assert(readNum >= 0);
+
+ close(fd);
+ } else {
+ LLDB_LOG(log, "failed to read link exe link for {0}: {1}", pid,
+ Status(errno, eErrorTypePOSIX));
+ ExePath.resize(0);
+ }
+
+ llvm::StringRef PathRef(&(psinfoData.pr_psargs[0]));
+
+ if (!PathRef.empty()) {
+ process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
+ ArchSpec arch_spec = ArchSpec();
+ arch_spec.SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64,
+ LLDB_INVALID_CPUTYPE, llvm::Triple::AIX);
+ process_info.SetArchitecture(arch_spec);
+ }
+}
+
+static bool GetProcessAndStatInfo(::pid_t pid,
+ ProcessInstanceInfo &process_info,
+ ProcessState &State, ::pid_t &tracerpid) {
+ ::pid_t tgid;
+ tracerpid = 0;
+ process_info.Clear();
+
+ process_info.SetProcessID(pid);
+
+ GetExePathAndArch(pid, process_info);
+
+ // Get User and Group IDs and get tracer pid.
+ if (!GetStatusInfo(pid, process_info, State, tracerpid, tgid))
+ return false;
+
+ return true;
+}
+
uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
return 0;
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
- return false;
+ ::pid_t tracerpid;
+ ProcessState State;
+ return GetProcessAndStatInfo(pid, process_info, State, tracerpid);
}
Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
>From 3ea41b00f9702cd20c1b762432ede2dcc3befbb8 Mon Sep 17 00:00:00 2001
From: HemangGadhavi <hemang.gadhavi at ibm.com>
Date: Thu, 10 Apr 2025 06:16:36 -0500
Subject: [PATCH 2/4] Addressed review comments
---
lldb/source/Host/aix/Host.cpp | 56 ++++++++++-------------------------
1 file changed, 15 insertions(+), 41 deletions(-)
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
index 6ba3e05348df1..6f2b2ac169cfc 100644
--- a/lldb/source/Host/aix/Host.cpp
+++ b/lldb/source/Host/aix/Host.cpp
@@ -9,7 +9,6 @@
#include <fcntl.h>
#include <sstream>
#include <sys/procfs.h>
-
#include "lldb/Host/Host.h"
#include "lldb/Host/linux/Support.h"
#include "lldb/Utility/LLDBLog.h"
@@ -41,7 +40,6 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
ProcessState &State, ::pid_t &TracerPid,
::pid_t &Tgid) {
Log *log = GetLog(LLDBLog::Host);
-
auto BufferOrError = getProcFile(Pid, "status");
if (!BufferOrError)
return false;
@@ -50,7 +48,6 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
while (!Rest.empty()) {
llvm::StringRef Line;
std::tie(Line, Rest) = Rest.split('\n');
-
if (Line.consume_front("Gid:")) {
// Real, effective, saved set, and file system GIDs. Read the first two.
Line = Line.ltrim();
@@ -58,7 +55,6 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
Line.consumeInteger(10, RGid);
Line = Line.ltrim();
Line.consumeInteger(10, EGid);
-
ProcessInfo.SetGroupID(RGid);
ProcessInfo.SetEffectiveGroupID(EGid);
} else if (Line.consume_front("Uid:")) {
@@ -68,7 +64,6 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
Line.consumeInteger(10, RUid);
Line = Line.ltrim();
Line.consumeInteger(10, EUid);
-
ProcessInfo.SetUserID(RUid);
ProcessInfo.SetEffectiveUserID(EUid);
} else if (Line.consume_front("PPid:")) {
@@ -101,48 +96,28 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
return true;
}
-static void GetExePathAndArch(::pid_t pid, ProcessInstanceInfo &process_info) {
- Log *log = GetLog(LLDBLog::Process);
- std::string ExePath(PATH_MAX, '\0');
+static bool GetExePathAndArch(::pid_t pid, ProcessInstanceInfo &process_info) {
struct psinfo psinfoData;
-
- // We can't use getProcFile here because proc/[pid]/exe is a symbolic link.
- llvm::SmallString<64> ProcExe;
- (llvm::Twine("/proc/") + llvm::Twine(pid) + "/cwd").toVector(ProcExe);
-
- ssize_t len = readlink(ProcExe.c_str(), &ExePath[0], PATH_MAX);
- if (len > 0) {
- ExePath.resize(len);
-
- struct stat statData;
-
- std::ostringstream oss;
-
- oss << "/proc/" << std::dec << pid << "/psinfo";
- assert(stat(oss.str().c_str(), &statData) == 0);
-
- const int fd = open(oss.str().c_str(), O_RDONLY);
- assert(fd >= 0);
-
- ssize_t readNum = read(fd, &psinfoData, sizeof(psinfoData));
- assert(readNum >= 0);
-
- close(fd);
- } else {
- LLDB_LOG(log, "failed to read link exe link for {0}: {1}", pid,
- Status(errno, eErrorTypePOSIX));
- ExePath.resize(0);
- }
-
+ auto BufferOrError = getProcFile(pid, "psinfo");
+ if (!BufferOrError)
+ return false;
+
+ std::unique_ptr<llvm::MemoryBuffer> PsinfoBuffer = std::move(*BufferOrError);
+ // Ensure there's enough data for psinfoData
+ if(PsinfoBuffer->getBufferSize() < sizeof(psinfoData))
+ return false;
+
+ std::memcpy(&psinfoData, PsinfoBuffer->getBufferStart(), sizeof(psinfoData));
llvm::StringRef PathRef(&(psinfoData.pr_psargs[0]));
-
if (!PathRef.empty()) {
process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
ArchSpec arch_spec = ArchSpec();
arch_spec.SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64,
LLDB_INVALID_CPUTYPE, llvm::Triple::AIX);
process_info.SetArchitecture(arch_spec);
+ return true;
}
+ return false;
}
static bool GetProcessAndStatInfo(::pid_t pid,
@@ -151,11 +126,10 @@ static bool GetProcessAndStatInfo(::pid_t pid,
::pid_t tgid;
tracerpid = 0;
process_info.Clear();
-
process_info.SetProcessID(pid);
- GetExePathAndArch(pid, process_info);
-
+ if(!GetExePathAndArch(pid, process_info))
+ return false;
// Get User and Group IDs and get tracer pid.
if (!GetStatusInfo(pid, process_info, State, tracerpid, tgid))
return false;
>From f3edd7ccf2f8a38caad9de8fba0cca734b79acfb Mon Sep 17 00:00:00 2001
From: HemangGadhavi <hemang.gadhavi at ibm.com>
Date: Thu, 10 Apr 2025 07:12:46 -0500
Subject: [PATCH 3/4] changes as per the clang-format
---
lldb/source/Host/aix/Host.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
index 6f2b2ac169cfc..d1880ff7d1432 100644
--- a/lldb/source/Host/aix/Host.cpp
+++ b/lldb/source/Host/aix/Host.cpp
@@ -6,9 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#include <fcntl.h>
-#include <sstream>
-#include <sys/procfs.h>
#include "lldb/Host/Host.h"
#include "lldb/Host/linux/Support.h"
#include "lldb/Utility/LLDBLog.h"
@@ -16,6 +13,7 @@
#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/Status.h"
#include "llvm/BinaryFormat/XCOFF.h"
+#include <sys/procfs.h>
using namespace llvm;
using namespace lldb;
@@ -101,12 +99,12 @@ static bool GetExePathAndArch(::pid_t pid, ProcessInstanceInfo &process_info) {
auto BufferOrError = getProcFile(pid, "psinfo");
if (!BufferOrError)
return false;
-
+
std::unique_ptr<llvm::MemoryBuffer> PsinfoBuffer = std::move(*BufferOrError);
// Ensure there's enough data for psinfoData
- if(PsinfoBuffer->getBufferSize() < sizeof(psinfoData))
+ if (PsinfoBuffer->getBufferSize() < sizeof(psinfoData))
return false;
-
+
std::memcpy(&psinfoData, PsinfoBuffer->getBufferStart(), sizeof(psinfoData));
llvm::StringRef PathRef(&(psinfoData.pr_psargs[0]));
if (!PathRef.empty()) {
@@ -128,7 +126,7 @@ static bool GetProcessAndStatInfo(::pid_t pid,
process_info.Clear();
process_info.SetProcessID(pid);
- if(!GetExePathAndArch(pid, process_info))
+ if (!GetExePathAndArch(pid, process_info))
return false;
// Get User and Group IDs and get tracer pid.
if (!GetStatusInfo(pid, process_info, State, tracerpid, tgid))
>From f434632f089f53eb014027c1da2dd2a0f65218c4 Mon Sep 17 00:00:00 2001
From: HemangGadhavi <hemang.gadhavi at ibm.com>
Date: Mon, 14 Apr 2025 08:54:43 -0400
Subject: [PATCH 4/4] Moved the host support and unittest functions to posix
---
lldb/include/lldb/Host/linux/Support.h | 6 -
lldb/include/lldb/Host/posix/Support.h | 26 ++++
lldb/source/Host/CMakeLists.txt | 2 +-
lldb/source/Host/aix/Host.cpp | 136 +++++++++---------
lldb/source/Host/linux/Host.cpp | 2 +-
lldb/source/Host/linux/Support.cpp | 20 ---
lldb/source/Host/posix/Support.cpp | 32 +++++
.../Plugins/Process/AIX/NativeProcessAIX.h | 2 +-
.../Process/Linux/IntelPTCollector.cpp | 1 -
.../Process/Linux/NativeProcessLinux.h | 1 +
lldb/source/Plugins/Process/Linux/Perf.cpp | 1 -
lldb/source/Plugins/Process/Linux/Procfs.cpp | 2 +-
lldb/unittests/Host/CMakeLists.txt | 6 +-
.../Host/{linux => posix}/HostTest.cpp | 5 +-
.../Host/{linux => posix}/SupportTest.cpp | 5 +-
lldb/unittests/Process/Linux/ProcfsTests.cpp | 2 +-
16 files changed, 139 insertions(+), 110 deletions(-)
create mode 100644 lldb/include/lldb/Host/posix/Support.h
create mode 100644 lldb/source/Host/posix/Support.cpp
rename lldb/unittests/Host/{linux => posix}/HostTest.cpp (98%)
rename lldb/unittests/Host/{linux => posix}/SupportTest.cpp (86%)
diff --git a/lldb/include/lldb/Host/linux/Support.h b/lldb/include/lldb/Host/linux/Support.h
index d1eb7f83d4916..1b8e1e2c26fa7 100644
--- a/lldb/include/lldb/Host/linux/Support.h
+++ b/lldb/include/lldb/Host/linux/Support.h
@@ -18,12 +18,6 @@ namespace lldb_private {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file);
-llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-getProcFile(::pid_t pid, const llvm::Twine &file);
-
-llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-getProcFile(const llvm::Twine &file);
-
} // namespace lldb_private
#endif // #ifndef LLDB_HOST_LINUX_SUPPORT_H
diff --git a/lldb/include/lldb/Host/posix/Support.h b/lldb/include/lldb/Host/posix/Support.h
new file mode 100644
index 0000000000000..c4de260acb26d
--- /dev/null
+++ b/lldb/include/lldb/Host/posix/Support.h
@@ -0,0 +1,26 @@
+//===-- Support.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 LLDB_HOST_POSIX_SUPPORT_H
+#define LLDB_HOST_POSIX_SUPPORT_H
+
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include <memory>
+
+namespace lldb_private {
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+getProcFile(::pid_t pid, const llvm::Twine &file);
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+getProcFile(const llvm::Twine &file);
+
+} // namespace lldb_private
+
+#endif // #ifndef LLDB_HOST_POSIX_SUPPORT_H
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index a02b1c104396e..90814b1bed4c8 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -87,6 +87,7 @@ else()
posix/MainLoopPosix.cpp
posix/PipePosix.cpp
posix/ProcessLauncherPosixFork.cpp
+ posix/Support.cpp
)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
@@ -141,7 +142,6 @@ else()
add_host_subdirectory(aix
aix/Host.cpp
aix/HostInfoAIX.cpp
- linux/Support.cpp
)
endif()
endif()
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
index d1880ff7d1432..6f59cb6e1f281 100644
--- a/lldb/source/Host/aix/Host.cpp
+++ b/lldb/source/Host/aix/Host.cpp
@@ -7,12 +7,13 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/Host.h"
-#include "lldb/Host/linux/Support.h"
+#include "lldb/Host/posix/Support.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/Status.h"
#include "llvm/BinaryFormat/XCOFF.h"
+#include <sys/proc.h>
#include <sys/procfs.h>
using namespace llvm;
@@ -34,67 +35,53 @@ enum class ProcessState {
};
}
-static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
- ProcessState &State, ::pid_t &TracerPid,
- ::pid_t &Tgid) {
- Log *log = GetLog(LLDBLog::Host);
- auto BufferOrError = getProcFile(Pid, "status");
+ProcessInstanceInfo::timespec convert(pr_timestruc64_t t) {
+ ProcessInstanceInfo::timespec ts;
+ ts.tv_sec = t.tv_sec;
+ ts.tv_usec = t.tv_nsec / 1000; // nanos to micros
+ return ts;
+}
+
+static bool GetStatusInfo(::pid_t pid, ProcessInstanceInfo &processInfo,
+ ProcessState &State) {
+ struct pstatus pstatusData;
+ auto BufferOrError = getProcFile(pid, "status");
if (!BufferOrError)
return false;
- llvm::StringRef Rest = BufferOrError.get()->getBuffer();
- while (!Rest.empty()) {
- llvm::StringRef Line;
- std::tie(Line, Rest) = Rest.split('\n');
- if (Line.consume_front("Gid:")) {
- // Real, effective, saved set, and file system GIDs. Read the first two.
- Line = Line.ltrim();
- uint32_t RGid, EGid;
- Line.consumeInteger(10, RGid);
- Line = Line.ltrim();
- Line.consumeInteger(10, EGid);
- ProcessInfo.SetGroupID(RGid);
- ProcessInfo.SetEffectiveGroupID(EGid);
- } else if (Line.consume_front("Uid:")) {
- // Real, effective, saved set, and file system UIDs. Read the first two.
- Line = Line.ltrim();
- uint32_t RUid, EUid;
- Line.consumeInteger(10, RUid);
- Line = Line.ltrim();
- Line.consumeInteger(10, EUid);
- ProcessInfo.SetUserID(RUid);
- ProcessInfo.SetEffectiveUserID(EUid);
- } else if (Line.consume_front("PPid:")) {
- ::pid_t PPid;
- Line.ltrim().consumeInteger(10, PPid);
- ProcessInfo.SetParentProcessID(PPid);
- } else if (Line.consume_front("State:")) {
- State = llvm::StringSwitch<ProcessState>(Line.ltrim().take_front(1))
- .Case("D", ProcessState::DiskSleep)
- .Case("I", ProcessState::Idle)
- .Case("R", ProcessState::Running)
- .Case("S", ProcessState::Sleeping)
- .CaseLower("T", ProcessState::TracedOrStopped)
- .Case("W", ProcessState::Paging)
- .Case("P", ProcessState::Parked)
- .Case("X", ProcessState::Dead)
- .Case("Z", ProcessState::Zombie)
- .Default(ProcessState::Unknown);
- if (State == ProcessState::Unknown) {
- LLDB_LOG(log, "Unknown process state {0}", Line);
- }
- } else if (Line.consume_front("TracerPid:")) {
- Line = Line.ltrim();
- Line.consumeInteger(10, TracerPid);
- } else if (Line.consume_front("Tgid:")) {
- Line = Line.ltrim();
- Line.consumeInteger(10, Tgid);
- }
+ std::unique_ptr<llvm::MemoryBuffer> StatusBuffer = std::move(*BufferOrError);
+ // Ensure there's enough data for psinfoData
+ if (StatusBuffer->getBufferSize() < sizeof(pstatusData))
+ return false;
+
+ std::memcpy(&pstatusData, StatusBuffer->getBufferStart(),
+ sizeof(pstatusData));
+ switch (pstatusData.pr_stat) {
+ case SIDL:
+ State = ProcessState::Idle;
+ break;
+ case SACTIVE:
+ State = ProcessState::Running;
+ break;
+ case SSTOP:
+ State = ProcessState::TracedOrStopped;
+ break;
+ case SZOMB:
+ State = ProcessState::Zombie;
+ break;
+ default:
+ State = ProcessState::Unknown;
+ break;
}
+ processInfo.SetIsZombie(State == ProcessState::Zombie);
+ processInfo.SetUserTime(convert(pstatusData.pr_utime));
+ processInfo.SetSystemTime(convert(pstatusData.pr_stime));
+ processInfo.SetCumulativeUserTime(convert(pstatusData.pr_cutime));
+ processInfo.SetCumulativeSystemTime(convert(pstatusData.pr_cstime));
return true;
}
-static bool GetExePathAndArch(::pid_t pid, ProcessInstanceInfo &process_info) {
+static bool GetExePathAndIds(::pid_t pid, ProcessInstanceInfo &process_info) {
struct psinfo psinfoData;
auto BufferOrError = getProcFile(pid, "psinfo");
if (!BufferOrError)
@@ -107,29 +94,35 @@ static bool GetExePathAndArch(::pid_t pid, ProcessInstanceInfo &process_info) {
std::memcpy(&psinfoData, PsinfoBuffer->getBufferStart(), sizeof(psinfoData));
llvm::StringRef PathRef(&(psinfoData.pr_psargs[0]));
- if (!PathRef.empty()) {
- process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
- ArchSpec arch_spec = ArchSpec();
- arch_spec.SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64,
- LLDB_INVALID_CPUTYPE, llvm::Triple::AIX);
- process_info.SetArchitecture(arch_spec);
- return true;
- }
- return false;
+ if (PathRef.empty())
+ return false;
+
+ process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
+ ArchSpec arch_spec = ArchSpec();
+ arch_spec.SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64,
+ LLDB_INVALID_CPUTYPE, llvm::Triple::AIX);
+ process_info.SetArchitecture(arch_spec);
+ process_info.SetParentProcessID(psinfoData.pr_ppid);
+ process_info.SetGroupID(psinfoData.pr_gid);
+ process_info.SetEffectiveGroupID(psinfoData.pr_egid);
+ process_info.SetUserID(psinfoData.pr_uid);
+ process_info.SetEffectiveUserID(psinfoData.pr_euid);
+ process_info.SetProcessGroupID(psinfoData.pr_pgid);
+ process_info.SetProcessSessionID(psinfoData.pr_sid);
+ return true;
}
static bool GetProcessAndStatInfo(::pid_t pid,
ProcessInstanceInfo &process_info,
- ProcessState &State, ::pid_t &tracerpid) {
- ::pid_t tgid;
- tracerpid = 0;
+ ProcessState &State) {
process_info.Clear();
process_info.SetProcessID(pid);
- if (!GetExePathAndArch(pid, process_info))
+ // Get Executable path/Arch and Get User and Group IDs.
+ if (!GetExePathAndIds(pid, process_info))
return false;
- // Get User and Group IDs and get tracer pid.
- if (!GetStatusInfo(pid, process_info, State, tracerpid, tgid))
+ // Get process status and timing info.
+ if (!GetStatusInfo(pid, process_info, State))
return false;
return true;
@@ -141,9 +134,8 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
- ::pid_t tracerpid;
ProcessState State;
- return GetProcessAndStatInfo(pid, process_info, State, tracerpid);
+ return GetProcessAndStatInfo(pid, process_info, State);
}
Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 25bef9b0e7151..8b475a7ab5003 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -30,7 +30,7 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/linux/Host.h"
-#include "lldb/Host/linux/Support.h"
+#include "lldb/Host/posix/Support.h"
#include "lldb/Utility/DataExtractor.h"
using namespace lldb;
diff --git a/lldb/source/Host/linux/Support.cpp b/lldb/source/Host/linux/Support.cpp
index 8b0decc48c038..c6321e93f4dfa 100644
--- a/lldb/source/Host/linux/Support.cpp
+++ b/lldb/source/Host/linux/Support.cpp
@@ -22,23 +22,3 @@ lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) {
LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
return Ret;
}
-
-llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-lldb_private::getProcFile(::pid_t pid, const llvm::Twine &file) {
- Log *log = GetLog(LLDBLog::Host);
- std::string File = ("/proc/" + llvm::Twine(pid) + "/" + file).str();
- auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
- if (!Ret)
- LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
- return Ret;
-}
-
-llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-lldb_private::getProcFile(const llvm::Twine &file) {
- Log *log = GetLog(LLDBLog::Host);
- std::string File = ("/proc/" + file).str();
- auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
- if (!Ret)
- LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
- return Ret;
-}
diff --git a/lldb/source/Host/posix/Support.cpp b/lldb/source/Host/posix/Support.cpp
new file mode 100644
index 0000000000000..abfcc8ddb2d7f
--- /dev/null
+++ b/lldb/source/Host/posix/Support.cpp
@@ -0,0 +1,32 @@
+//===-- Support.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 "lldb/Host/posix/Support.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+lldb_private::getProcFile(::pid_t pid, const llvm::Twine &file) {
+ Log *log = GetLog(LLDBLog::Host);
+ std::string File = ("/proc/" + llvm::Twine(pid) + "/" + file).str();
+ auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
+ if (!Ret)
+ LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
+ return Ret;
+}
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+lldb_private::getProcFile(const llvm::Twine &file) {
+ Log *log = GetLog(LLDBLog::Host);
+ std::string File = ("/proc/" + file).str();
+ auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
+ if (!Ret)
+ LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
+ return Ret;
+}
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
index 0fd7ff2785123..bc44f2b02af98 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.h
@@ -12,7 +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/Host/posix/Support.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
diff --git a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
index a38b75c9e615f..06551a4ff5a00 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
@@ -10,7 +10,6 @@
#include "Perf.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Procfs.h"
-#include "lldb/Host/linux/Support.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
index 2af6c646332c9..d345f165a75d8 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -15,6 +15,7 @@
#include "lldb/Host/Debug.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/linux/Support.h"
+#include "lldb/Host/posix/Support.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
diff --git a/lldb/source/Plugins/Process/Linux/Perf.cpp b/lldb/source/Plugins/Process/Linux/Perf.cpp
index 097c719b9c1d2..4207364812110 100644
--- a/lldb/source/Plugins/Process/Linux/Perf.cpp
+++ b/lldb/source/Plugins/Process/Linux/Perf.cpp
@@ -9,7 +9,6 @@
#include "Perf.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
-#include "lldb/Host/linux/Support.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
diff --git a/lldb/source/Plugins/Process/Linux/Procfs.cpp b/lldb/source/Plugins/Process/Linux/Procfs.cpp
index 8c279c7ab6533..d3bd396fbaeab 100644
--- a/lldb/source/Plugins/Process/Linux/Procfs.cpp
+++ b/lldb/source/Plugins/Process/Linux/Procfs.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Procfs.h"
-#include "lldb/Host/linux/Support.h"
+#include "lldb/Host/posix/Support.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
diff --git a/lldb/unittests/Host/CMakeLists.txt b/lldb/unittests/Host/CMakeLists.txt
index c959478970d18..1c44de40d5798 100644
--- a/lldb/unittests/Host/CMakeLists.txt
+++ b/lldb/unittests/Host/CMakeLists.txt
@@ -15,10 +15,10 @@ set (FILES
XMLTest.cpp
)
-if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
+if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android|AIX")
list(APPEND FILES
- linux/HostTest.cpp
- linux/SupportTest.cpp
+ posix/HostTest.cpp
+ posix/SupportTest.cpp
)
endif()
diff --git a/lldb/unittests/Host/linux/HostTest.cpp b/lldb/unittests/Host/posix/HostTest.cpp
similarity index 98%
rename from lldb/unittests/Host/linux/HostTest.cpp
rename to lldb/unittests/Host/posix/HostTest.cpp
index d6aefcc7faa25..a581be960ad51 100644
--- a/lldb/unittests/Host/linux/HostTest.cpp
+++ b/lldb/unittests/Host/posix/HostTest.cpp
@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
ProcessInstanceInfo Info;
+#ifndef _AIX
ASSERT_FALSE(Host::GetProcessInfo(0, Info));
-
+#endif /* ifndef _AIX */
ASSERT_TRUE(Host::GetProcessInfo(getpid(), Info));
ASSERT_TRUE(Info.ProcessIDIsValid());
@@ -90,6 +91,7 @@ TEST_F(HostTest, GetProcessInfo) {
ASSERT_TRUE(user_time.tv_sec <= next_user_time.tv_sec ||
user_time.tv_usec <= next_user_time.tv_usec);
+#ifndef _AIX
struct rlimit rlim;
EXPECT_EQ(getrlimit(RLIMIT_NICE, &rlim), 0);
// getpriority can return -1 so we zero errno first
@@ -108,4 +110,5 @@ TEST_F(HostTest, GetProcessInfo) {
}
ASSERT_TRUE(Info.IsZombie().has_value());
ASSERT_FALSE(Info.IsZombie().value());
+#endif /* ifndef _AIX */
}
diff --git a/lldb/unittests/Host/linux/SupportTest.cpp b/lldb/unittests/Host/posix/SupportTest.cpp
similarity index 86%
rename from lldb/unittests/Host/linux/SupportTest.cpp
rename to lldb/unittests/Host/posix/SupportTest.cpp
index 6d1d28cd4caad..9cb364d1ee4ae 100644
--- a/lldb/unittests/Host/linux/SupportTest.cpp
+++ b/lldb/unittests/Host/posix/SupportTest.cpp
@@ -7,17 +7,19 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/linux/Support.h"
+#include "lldb/Host/posix/Support.h"
#include "llvm/Support/Threading.h"
#include "gtest/gtest.h"
using namespace lldb_private;
TEST(Support, getProcFile_Pid) {
- auto BufferOrError = getProcFile(getpid(), "maps");
+ auto BufferOrError = getProcFile(getpid(), "status");
ASSERT_TRUE(BufferOrError);
ASSERT_TRUE(*BufferOrError);
}
+#ifndef _AIX
#ifdef LLVM_ENABLE_THREADING
TEST(Support, getProcFile_Tid) {
auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "comm");
@@ -25,3 +27,4 @@ TEST(Support, getProcFile_Tid) {
ASSERT_TRUE(*BufferOrError);
}
#endif /*ifdef LLVM_ENABLE_THREADING */
+#endif /*ifndef _AIX */
diff --git a/lldb/unittests/Process/Linux/ProcfsTests.cpp b/lldb/unittests/Process/Linux/ProcfsTests.cpp
index d95de649ed578..e050db25b2ed4 100644
--- a/lldb/unittests/Process/Linux/ProcfsTests.cpp
+++ b/lldb/unittests/Process/Linux/ProcfsTests.cpp
@@ -8,7 +8,7 @@
#include "Procfs.h"
-#include "lldb/Host/linux/Support.h"
+#include "lldb/Host/posix/Support.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
More information about the lldb-commits
mailing list