[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-29 Thread Hemang Gadhavi via lldb-commits

HemangGadhavi wrote:

> Could you please disable/revert if the fix is not easy?

@felipepiovezan Done through the commit ID 
cf7301aeb808a13fe882a4b0bf7f1bfe4051c301 by labath 

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-29 Thread Felipe de Azevedo Piovezan via lldb-commits

felipepiovezan wrote:

Could you please disable/revert if the fix is not easy?

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-29 Thread Felipe de Azevedo Piovezan via lldb-commits

felipepiovezan wrote:

Hi, this test is _still_ failing on the macOS bots: 
https://ci.swift.org/view/all/job/llvm.org/job/lldb-cmake/11728/execution/node/111/log/

```
/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/lldb-build/tools/lldb/unittests/Host/./HostTests
 --gtest_filter=HostTest.GetProcessInfo
--
/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/unittests/Host/posix/HostTest.cpp:72:
 Failure
Expected equality of these values:
  HostInfo::GetArchitecture(HostInfo::eArchKindDefault)
Which is: 64-byte object <28-78 38-36 5F-36 34-68 2D-61 70-70 6C-65 2D-6D 
61-63 6F-73 78-00 00-00 26-00 00-00 00-00 00-00 01-00 00-00 09-00 00-00 00-00 
00-00 05-00 00-00 51-00 00-00 04-00 00-00 00-00 00-00 00-00 00-00>
  Info.GetArchitecture()
Which is: 64-byte object <26-78 38-36 5F-36 34-2D 61-70 70-6C 65-2D 6D-61 
63-6F 73-78 00-00 00-00 26-00 00-00 00-00 00-00 01-00 00-00 09-00 00-00 00-00 
00-00 05-00 00-00 50-00 00-00 04-00 00-00 00-00 00-00 F8-7F 00-00>


/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/unittests/Host/posix/HostTest.cpp:72
Expected equality of these values:
  HostInfo::GetArchitecture(HostInfo::eArchKindDefault)
Which is: 64-byte object <28-78 38-36 5F-36 34-68 2D-61 70-70 6C-65 2D-6D 
61-63 6F-73 78-00 00-00 26-00 00-00 00-00 00-00 01-00 00-00 09-00 00-00 00-00 
00-00 05-00 00-00 51-00 00-00 04-00 00-00 00-00 00-00 00-00 00-00>
  Info.GetArchitecture()
Which is: 64-byte object <26-78 38-36 5F-36 34-2D 61-70 70-6C 65-2D 6D-61 
63-6F 73-78 00-00 00-00 26-00 00-00 00-00 00-00 01-00 00-00 09-00 00-00 00-00 
00-00 05-00 00-00 50-00 00-00 04-00 00-00 00-00 00-00 F8-7F 00-00>
```

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-28 Thread via lldb-commits

github-actions[bot] wrote:



@HemangGadhavi Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-28 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX closed 
https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-28 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-24 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/134354

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
Date: Fri, 4 Apr 2025 00:59:17 -0500
Subject: [PATCH 1/6] [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 
+#include 
+#include 
+
 #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(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, e

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Hemang Gadhavi via lldb-commits


@@ -7,17 +7,139 @@
 
//===--===//
 
 #include "lldb/Host/Host.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 
+#include 
 
+using namespace llvm;

HemangGadhavi wrote:

Modified 

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/134354

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
Date: Fri, 4 Apr 2025 00:59:17 -0500
Subject: [PATCH 1/6] [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 
+#include 
+#include 
+
 #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(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, e

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Pavel Labath via lldb-commits


@@ -7,17 +7,139 @@
 
//===--===//
 
 #include "lldb/Host/Host.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 
+#include 
 
+using namespace llvm;

labath wrote:

I'd recommend not getting into the habit of including the whole llvm namespace. 
It may be fine if you have code that's heavily using some llvm objects, but in 
general I think it's more trouble than it's worth -- `llvm` is a big namespace 
and it includes names (e.g. `Module`) which conflict with lldb entities.

I don't think that's the case here, but if you find yourself using a particular 
function/class very often, then I it'd be better to just include that single 
class.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Pavel Labath via lldb-commits


@@ -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 

labath wrote:

```suggestion
#include "llvm/ADT/Twine.h"
#include 
```

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Pavel Labath via lldb-commits


@@ -7,17 +7,139 @@
 
//===--===//
 
 #include "lldb/Host/Host.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 
+#include 
 
+using namespace llvm;
+using namespace lldb;
 using namespace lldb_private;
 
+namespace {
+enum class ProcessState {
+  Unknown,
+  Dead,
+  DiskSleep,
+  Idle,
+  Paging,
+  Parked,
+  Running,
+  Sleeping,
+  TracedOrStopped,
+  Zombie,
+};
+}
+
+ProcessInstanceInfo::timespec convert(pr_timestruc64_t t) {

labath wrote:

```suggestion
static ProcessInstanceInfo::timespec convert(pr_timestruc64_t t) {
```

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-23 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/134354

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
Date: Fri, 4 Apr 2025 00:59:17 -0500
Subject: [PATCH 1/5] [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 
+#include 
+#include 
+
 #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(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, e

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits

HemangGadhavi wrote:

@labath Addressed all your comments, Please have a look once and give your 
comments if any.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits


@@ -7,21 +7,24 @@
 
//===--===//
 
 #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");
   ASSERT_TRUE(BufferOrError);
   ASSERT_TRUE(*BufferOrError);
 }
 #endif /*ifdef LLVM_ENABLE_THREADING */
+#endif /*ifndef _AIX */

HemangGadhavi wrote:

Moved.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits


@@ -7,17 +7,135 @@
 
//===--===//
 
 #include "lldb/Host/Host.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 
+#include 
 
+using namespace llvm;
+using namespace lldb;
 using namespace lldb_private;
 
+namespace {
+enum class ProcessState {
+  Unknown,
+  Dead,
+  DiskSleep,
+  Idle,
+  Paging,
+  Parked,
+  Running,
+  Sleeping,
+  TracedOrStopped,
+  Zombie,
+};
+}
+
+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;
+
+  std::unique_ptr 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 GetExePathAndIds(::pid_t pid, ProcessInstanceInfo &process_info) {
+  struct psinfo psinfoData;
+  auto BufferOrError = getProcFile(pid, "psinfo");
+  if (!BufferOrError)
+return false;
+
+  std::unique_ptr 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]));

HemangGadhavi wrote:

Yes it is always NULL-terminated, But this is more safest way. 
Addressed.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits


@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
 
   ProcessInstanceInfo Info;
+#ifndef _AIX

HemangGadhavi wrote:

Make sense. 
Thanks for the suggestion let me make the changes. 

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
 
   ProcessInstanceInfo Info;
+#ifndef _AIX

labath wrote:

In that case, what would say to filtering this process out inside the AIX 
implementation? (basically add something like `if (pid == 0) return false;`)

In theory, I suppose that someone may want to get the process information of 
the process zero, but i doubt it's an important use case since we normally call 
this while attaching to a process. And it would ensure that 
`GetProcessInfo(LLDB_INVALID_PROCESS_ID)` behaves the same way everywhere (we 
could also change this test to use the LLDB_INVALID_PROCESS_ID macro to make it 
clear that it's checking for an "invalid" process).

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits


@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
 
   ProcessInstanceInfo Info;
+#ifndef _AIX

HemangGadhavi wrote:

This process is basically for swapper/scheduling work. And yes its kernel 
process which is start after `init` only.
But that is sure we can not debugged/attached that process. 

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
 
   ProcessInstanceInfo Info;
+#ifndef _AIX

labath wrote:

I see... Well, that could be a bit tricky (not just for this test, but in 
general), because lldb defines `LLDB_INVALID_PROCESS_ID` to be zero.

What can you tell me about this process? Is it some system/kernel process that 
runs before `init`? Can it even be debugged/attached to?

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Hemang Gadhavi via lldb-commits


@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
 
   ProcessInstanceInfo Info;
+#ifndef _AIX

HemangGadhavi wrote:

Yes process zero exist on AIX. That is the reason disabled for AIX

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -7,21 +7,24 @@
 
//===--===//
 
 #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) {

labath wrote:

And then make this `#ifndef __APPLE__`, as that's the only OS which definitely 
doesn't have proc. It looks like the BSD should mostly have them. If it turns 
out to be  a problem, we opt them out as well.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -7,17 +7,135 @@
 
//===--===//
 
 #include "lldb/Host/Host.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 
+#include 
 
+using namespace llvm;
+using namespace lldb;
 using namespace lldb_private;
 
+namespace {
+enum class ProcessState {
+  Unknown,
+  Dead,
+  DiskSleep,
+  Idle,
+  Paging,
+  Parked,
+  Running,
+  Sleeping,
+  TracedOrStopped,
+  Zombie,
+};
+}
+
+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;
+
+  std::unique_ptr 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 GetExePathAndIds(::pid_t pid, ProcessInstanceInfo &process_info) {
+  struct psinfo psinfoData;
+  auto BufferOrError = getProcFile(pid, "psinfo");
+  if (!BufferOrError)
+return false;
+
+  std::unique_ptr 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]));

labath wrote:

Is this guaranteed to be null-terminated (at least on linux, these kinds of 
fields do not get null-terminated when they're truncated). If it isn't, you may 
want to do something like `StringRef(psinfoData.pr_psargs, 
strnlen(psinfoData.pr_psargs, sizeof(psinfoData.pr_psargs))`

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -7,21 +7,24 @@
 
//===--===//
 
 #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");
   ASSERT_TRUE(BufferOrError);
   ASSERT_TRUE(*BufferOrError);
 }
 #endif /*ifdef LLVM_ENABLE_THREADING */
+#endif /*ifndef _AIX */

labath wrote:

Let's move this into lldb/unittests/Process/Linux/ProcfsTests.cpp since the 
function it's testing is also linux-specific.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

Looks pretty good. Just a couple of details.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -40,8 +40,9 @@ TEST_F(HostTest, GetProcessInfo) {
triple.getEnvironment() == llvm::Triple::EnvironmentType::Android));
 
   ProcessInstanceInfo Info;
+#ifndef _AIX

labath wrote:

Why is that? Does process zero exist on AIX?

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits


@@ -15,10 +15,10 @@ set (FILES
   XMLTest.cpp
 )
 
-if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
+if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android|AIX")

labath wrote:

```suggestion
if (UNIX)
```

If individual tests fail on some systems. We can disable them there.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-22 Thread Pavel Labath via lldb-commits

https://github.com/labath edited 
https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-15 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/134354

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
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 
+#include 
+#include 
+
 #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(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, e

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-14 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi edited 
https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-14 Thread Hemang Gadhavi via lldb-commits


@@ -7,21 +7,24 @@
 
//===--===//
 
 #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");

HemangGadhavi wrote:

I have changed from `maps` to `status` to test `getProcFile()`
and here its only testing the `getProcFile()` functions. 
because `/proc/pid/status` is there in all the Linux, AIX and Android.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-14 Thread Hemang Gadhavi via lldb-commits

HemangGadhavi wrote:

> > > We have a tests for this function in `unittests/Host/linux/HostTest.cpp` 
> > > and it looks like at least some of it should apply to other systems as 
> > > well. We could move it to the "posix" folder so that it applies to your 
> > > code as well. Depending on the size of linux-specific parts, we could 
> > > either keep them in the "linux" folder, or `#ifdef` them out
> > 
> > 
> > Okay, we will create new PR to either move it to posix or we can create 
> > `HostTest.cpp` for aix separately. @labath or you want me to drop the 
> > testcase changes in same PR ?
> 
> Let's do that here. The PR is small (as it should be) and it's good to have 
> tests together with the code being tested.

Hi @labath 
I moved the `unittests/Host/linux/HostTest.cpp` &  `SupportTest.cpp` under the 
`unittests/Host/posix/`, so that unix-like system can used it. 
Also I have `#ifdef` out some of the tests, which are not applicable for AIX 
and tested on Linux/AIX all testcases are passed .
Please review it and give you comments.
Thanks


https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-14 Thread Hemang Gadhavi via lldb-commits


@@ -141,6 +141,7 @@ else()
 add_host_subdirectory(aix
   aix/Host.cpp
   aix/HostInfoAIX.cpp
+  linux/Support.cpp

HemangGadhavi wrote:

Hey @labath 
Made the changes as per the discussion, I have added the common 
`posix/Support.cpp` for unix-like system,  And kept as it as for three-arg 
overload linux specific and changed wherever it requires for getProcFile()
Please review once and give your comments. 
Thanks


https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-14 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi edited 
https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-14 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/134354

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
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 
+#include 
+#include 
+
 #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(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, e

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread Pavel Labath via lldb-commits


@@ -141,6 +141,7 @@ else()
 add_host_subdirectory(aix
   aix/Host.cpp
   aix/HostInfoAIX.cpp
+  linux/Support.cpp

labath wrote:

This PR is small enough, so I think you can just do it here. At least it will 
have context for why you're doing this.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi updated 
https://github.com/llvm/llvm-project/pull/134354

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
Date: Fri, 4 Apr 2025 00:59:17 -0500
Subject: [PATCH 1/3] [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 
+#include 
+#include 
+
 #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(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, e

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread Pavel Labath via lldb-commits

labath wrote:

> > We have a tests for this function in `unittests/Host/linux/HostTest.cpp` 
> > and it looks like at least some of it should apply to other systems as 
> > well. We could move it to the "posix" folder so that it applies to your 
> > code as well. Depending on the size of linux-specific parts, we could 
> > either keep them in the "linux" folder, or `#ifdef` them out
> 
> Okay, we will create new PR to either move it to posix or we can create 
> `HostTest.cpp` for aix separately. @labath or you want me to drop the 
> testcase changes in same PR ?

Let's do that here. The PR is small (as it should be) and it's good to have 
tests together with the code being tested.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread Dhruv Srivastava via lldb-commits

DhruvSrivastavaX wrote:

Please re-run clang-format on the changes.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread Hemang Gadhavi via lldb-commits

HemangGadhavi wrote:

> We have a tests for this function in `unittests/Host/linux/HostTest.cpp` and 
> it looks like at least some of it should apply to other systems as well. We 
> could move it to the "posix" folder so that it applies to your code as well. 
> Depending on the size of linux-specific parts, we could either keep them in 
> the "linux" folder, or `#ifdef` them out

Okay, we will create new PR to either move it to posix or we can create 
`HostTest.cpp` for aix separately.  @labath or you want me to drop the tescase 
in same PR ?

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- 
lldb/source/Host/aix/Host.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
index 6f2b2ac16..4defd6686 100644
--- a/lldb/source/Host/aix/Host.cpp
+++ b/lldb/source/Host/aix/Host.cpp
@@ -6,9 +6,6 @@
 //
 
//===--===//
 
-#include 
-#include 
-#include 
 #include "lldb/Host/Host.h"
 #include "lldb/Host/linux/Support.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -16,6 +13,9 @@
 #include "lldb/Utility/ProcessInfo.h"
 #include "lldb/Utility/Status.h"
 #include "llvm/BinaryFormat/XCOFF.h"
+#include 
+#include 
+#include 
 
 using namespace llvm;
 using namespace lldb;
@@ -101,12 +101,12 @@ static bool GetExePathAndArch(::pid_t pid, 
ProcessInstanceInfo &process_info) {
   auto BufferOrError = getProcFile(pid, "psinfo");
   if (!BufferOrError)
 return false;
-  
+
   std::unique_ptr 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 +128,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))

``




https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-10 Thread Hemang Gadhavi via lldb-commits


@@ -141,6 +141,7 @@ else()
 add_host_subdirectory(aix
   aix/Host.cpp
   aix/HostInfoAIX.cpp
+  linux/Support.cpp

HemangGadhavi wrote:

@labath This is a great suggestion. Thanks for suggestion.
we will create the new PR for the same and create the common Support.cpp under 
`posix` .


https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Dhruv Srivastava via lldb-commits


@@ -6,18 +6,172 @@
 //
 
//===--===//
 
+#include 
+#include 
+#include 
+
 #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(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;
+

DhruvSrivastavaX wrote:

Delete the extra blank lines.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Pavel Labath via lldb-commits


@@ -141,6 +141,7 @@ else()
 add_host_subdirectory(aix
   aix/Host.cpp
   aix/HostInfoAIX.cpp
+  linux/Support.cpp

labath wrote:

I'd move those functions into the `posix` folder given that other systems have 
similar functionality (besides AIX, freebsd also seems to have something 
similar, albeit deprecated). The functions don't do anything unless they are 
called, and they're quite simple, so it shouldn't hurt having them even if not 
all OSes have that functionality.

We might want to keep the three-arg overload (with pid+tid) linux specific -- I 
don't know if any other system has that.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Pavel Labath via lldb-commits

https://github.com/labath edited 
https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Pavel Labath via lldb-commits


@@ -6,18 +6,172 @@
 //
 
//===--===//
 
+#include 
+#include 
+#include 
+
 #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(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);

labath wrote:

cwd??

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Pavel Labath via lldb-commits


@@ -6,18 +6,172 @@
 //
 
//===--===//
 
+#include 
+#include 
+#include 
+
 #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(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);

labath wrote:

This could be done with `getProcFile`, right?

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

We have a tests for this function in `unittests/Host/linux/HostTest.cpp` and it 
looks like at least some of it should apply to other systems as well. We could 
move it to the "posix" folder so that it applies to your code as well. 
Depending on the size of linux-specific parts, we could either keep them in the 
"linux" folder, or `#ifdef` them out

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Dhruv Srivastava via lldb-commits


@@ -6,18 +6,172 @@
 //
 
//===--===//
 
+#include 
+#include 
+#include 
+

DhruvSrivastavaX wrote:

You can remove this blank line and run clang format once to keep all the 
includes together in order.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Dhruv Srivastava via lldb-commits


@@ -141,6 +141,7 @@ else()
 add_host_subdirectory(aix
   aix/Host.cpp
   aix/HostInfoAIX.cpp
+  linux/Support.cpp

DhruvSrivastavaX wrote:

In the original draft PR, we have a copy file from linux for aix as well. 
Shall we use the linux version to avoid redundant code, or create a new one for 
aix? 
For the NativeProcessAIX, we are using the linux/Support.cpp as of now.

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Dhruv Srivastava via lldb-commits

DhruvSrivastavaX wrote:

Hi Team, 

@HemangGadhavi from my ibm aix team will be helping me out in some of the 
merging process, as per our decided guidelines. Please provide your review.

Thanks!
Dhruv Srivastava

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Hemang Gadhavi (HemangGadhavi)


Changes

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. (GetProcessInfo()) 
(Information like : executable path, arch, process status etc.)
[@DavidSpickett](https://github.com/DavidSpickett) [@labath](https://github.com/labath) [@DhruvSrivastavaX](https://github.com/DhruvSrivastavaX)

---
Full diff: https://github.com/llvm/llvm-project/pull/134354.diff


2 Files Affected:

- (modified) lldb/source/Host/CMakeLists.txt (+1) 
- (modified) lldb/source/Host/aix/Host.cpp (+155-1) 


``diff
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 
+#include 
+#include 
+
 #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(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);
+
+  

[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread via lldb-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/134354
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][AIX] get host info for AIX (PR #134354)

2025-04-04 Thread Hemang Gadhavi via lldb-commits

https://github.com/HemangGadhavi created 
https://github.com/llvm/llvm-project/pull/134354

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. (GetProcessInfo()) 
(Information like : executable path, arch, process status etc.)
[@DavidSpickett](https://github.com/DavidSpickett) 
[@labath](https://github.com/labath) 
[@DhruvSrivastavaX](https://github.com/DhruvSrivastavaX)

>From e7b3d8d95477f96b4c1b1a2bbec5cce49f4c15cd Mon Sep 17 00:00:00 2001
From: HemangGadhavi 
Date: Fri, 4 Apr 2025 00:59:17 -0500
Subject: [PATCH] [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 
+#include 
+#include 
+
 #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(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")