https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/130582
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 base file - aix/Host.cpp for Process info >From 21fe9850c99b3eae4be65ac34c1f4f9c2d06ab2c Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava <dhruv.srivast...@ibm.com> Date: Mon, 10 Mar 2025 05:39:52 -0500 Subject: [PATCH 1/2] Host.cpp base for AIX --- lldb/source/Host/CMakeLists.txt | 1 + lldb/source/Host/aix/Host.cpp | 126 ++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 lldb/source/Host/aix/Host.cpp diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 9be0c06a516ba..52ef67feeb6ab 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -135,6 +135,7 @@ else() elseif (CMAKE_SYSTEM_NAME MATCHES "AIX") add_host_subdirectory(aix + aix/Host.cpp aix/HostInfoAIX.cpp ) endif() diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp new file mode 100644 index 0000000000000..a410899dc2a50 --- /dev/null +++ b/lldb/source/Host/aix/Host.cpp @@ -0,0 +1,126 @@ +//===-- source/Host/aix/Host.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/Host.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/ProcessInfo.h" +#include "lldb/Utility/Status.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Object/ELF.h" +#include "llvm/Support/ScopedPrinter.h" +#include <cerrno> +#include <cstdio> +#include <cstring> +#include <dirent.h> +#include <fcntl.h> +#include <sstream> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/utsname.h> +#include <unistd.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, +}; +} + +namespace lldb_private { +class ProcessLaunchInfo; +} + +static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo, + ProcessState &State, ::pid_t &TracerPid, + ::pid_t &Tgid) { + return false; +} + +static void GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {} + +static bool GetProcessAndStatInfo(::pid_t pid, + ProcessInstanceInfo &process_info, + ProcessState &State, ::pid_t &tracerpid) { + return false; +} + +uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info, + ProcessInstanceInfoList &process_infos) { + 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) { + + lldb::pid_t pid = atoi(direntry->d_name); + + // Skip this process. + if (pid == our_pid) + continue; + + ::pid_t tracerpid; + ProcessState State; + ProcessInstanceInfo process_info; + + if (!GetProcessAndStatInfo(pid, process_info, State, tracerpid)) + continue; + + // Skip if process is being debugged. + if (tracerpid != 0) + continue; + + if (State == ProcessState::Zombie) + 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) { + ::pid_t tracerpid; + ProcessState State; + return GetProcessAndStatInfo(pid, process_info, State, tracerpid); +} + +Environment Host::GetEnvironment() { return Environment(environ); } + +Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) { + return Status("unimplemented"); +} >From 4a9ff1d56b0210e4f2130394a81dfdd414457475 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava <dhruv.srivast...@ibm.com> Date: Mon, 10 Mar 2025 06:02:02 -0500 Subject: [PATCH 2/2] cleanup --- lldb/source/Host/aix/Host.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp index a410899dc2a50..38c77b4959ead 100644 --- a/lldb/source/Host/aix/Host.cpp +++ b/lldb/source/Host/aix/Host.cpp @@ -7,25 +7,9 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/Host.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" -#include "lldb/Utility/LLDBLog.h" -#include "lldb/Utility/Log.h" #include "lldb/Utility/ProcessInfo.h" #include "lldb/Utility/Status.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/Object/ELF.h" -#include "llvm/Support/ScopedPrinter.h" -#include <cerrno> -#include <cstdio> -#include <cstring> #include <dirent.h> -#include <fcntl.h> -#include <sstream> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/utsname.h> -#include <unistd.h> using namespace llvm; using namespace lldb; @@ -102,9 +86,8 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info, if (!all_users && (our_uid != 0) && (process_info.GetUserID() != our_uid)) continue; - if (match_info.Matches(process_info)) { + if (match_info.Matches(process_info)) process_infos.push_back(process_info); - } } closedir(dirproc); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits