[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (cont..) (PR #138687)
via lldb-commits
lldb-commits at lists.llvm.org
Tue May 6 06:27:44 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Hemang Gadhavi (HemangGadhavi)
<details>
<summary>Changes</summary>
This PR is in reference to porting LLDB on AIX.
Link to discussions on llvm discourse and github:
1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601
- Added changes to get the host information for AIX (info like FindProcessesImpl() GetProgramFileSpec()),
continue from the PR https://github.com/llvm/llvm-project/pull/134354
[@<!-- -->DavidSpickett](https://github.com/DavidSpickett) [@<!-- -->labath](https://github.com/labath) [@<!-- -->DhruvSrivastavaX](https://github.com/DhruvSrivastavaX)
---
Full diff: https://github.com/llvm/llvm-project/pull/138687.diff
2 Files Affected:
- (modified) lldb/source/Host/aix/Host.cpp (+48-1)
- (modified) lldb/source/Host/aix/HostInfoAIX.cpp (+15)
``````````diff
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
index a812e061ccae2..ead8202cbbdef 100644
--- a/lldb/source/Host/aix/Host.cpp
+++ b/lldb/source/Host/aix/Host.cpp
@@ -13,6 +13,7 @@
#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/Status.h"
#include "llvm/BinaryFormat/XCOFF.h"
+#include <dirent.h>
#include <sys/proc.h>
#include <sys/procfs.h>
@@ -41,6 +42,14 @@ static ProcessInstanceInfo::timespec convert(pr_timestruc64_t t) {
return ts;
}
+static bool IsDirNumeric(const char *dname) {
+ for (; *dname; dname++) {
+ if (!isdigit(*dname))
+ return false;
+ }
+ return true;
+}
+
static bool GetStatusInfo(::pid_t pid, ProcessInstanceInfo &processInfo,
ProcessState &State) {
struct pstatus pstatusData;
@@ -133,7 +142,45 @@ static bool GetProcessAndStatInfo(::pid_t pid,
uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
- return 0;
+ static const char procdir[] = "/proc/";
+
+ DIR *dirproc = opendir(procdir);
+ if (dirproc) {
+ struct dirent *direntry = nullptr;
+ const uid_t our_uid = getuid();
+ const lldb::pid_t our_pid = getpid();
+ bool all_users = match_info.GetMatchAllUsers();
+
+ while ((direntry = readdir(dirproc)) != nullptr) {
+ if (!IsDirNumeric(direntry->d_name))
+ continue;
+
+ lldb::pid_t pid = atoi(direntry->d_name);
+ // Skip this process.
+ if (pid == our_pid)
+ continue;
+
+ ProcessState State;
+ ProcessInstanceInfo process_info;
+ if (!GetProcessAndStatInfo(pid, process_info, State))
+ continue;
+
+ if (State == ProcessState::Zombie ||
+ State == ProcessState::TracedOrStopped)
+ continue;
+
+ // Check for user match if we're not matching all users and not running
+ // as root.
+ if (!all_users && (our_uid != 0) && (process_info.GetUserID() != our_uid))
+ continue;
+
+ if (match_info.Matches(process_info)) {
+ process_infos.push_back(process_info);
+ }
+ }
+ closedir(dirproc);
+ }
+ return process_infos.size();
}
bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
diff --git a/lldb/source/Host/aix/HostInfoAIX.cpp b/lldb/source/Host/aix/HostInfoAIX.cpp
index 61b47462dd647..d720f5c52d3b1 100644
--- a/lldb/source/Host/aix/HostInfoAIX.cpp
+++ b/lldb/source/Host/aix/HostInfoAIX.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/aix/HostInfoAIX.h"
+#include "lldb/Host/posix/Support.h"
+#include <sys/procfs.h>
using namespace lldb_private;
@@ -18,5 +20,18 @@ void HostInfoAIX::Terminate() { HostInfoBase::Terminate(); }
FileSpec HostInfoAIX::GetProgramFileSpec() {
static FileSpec g_program_filespec;
+ struct psinfo psinfoData;
+ auto BufferOrError = getProcFile(getpid(), "psinfo");
+ if (BufferOrError) {
+ std::unique_ptr<llvm::MemoryBuffer> PsinfoBuffer =
+ std::move(*BufferOrError);
+ memcpy(&psinfoData, PsinfoBuffer->getBufferStart(), sizeof(psinfoData));
+ llvm::StringRef exe_path(
+ psinfoData.pr_psargs,
+ strnlen(psinfoData.pr_psargs, sizeof(psinfoData.pr_psargs)));
+ if (!exe_path.empty()) {
+ g_program_filespec.SetFile(exe_path, FileSpec::Style::native);
+ }
+ }
return g_program_filespec;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/138687
More information about the lldb-commits
mailing list