Skip to content

Conversation

@DhruvSrivastavaX
Copy link
Member

@DhruvSrivastavaX DhruvSrivastavaX commented Nov 25, 2025

This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github.
Complete changes together in this draft:

Description:
Extending Kill and SigchldHandler for NativeProcessAIX.

Ref: AIX ptrace

@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2025

@llvm/pr-subscribers-lldb

Author: Dhruv Srivastava (DhruvSrivastavaX)

Changes

This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github.

The complete changes for porting are present in this draft PR:

Description:
Extending Kill and SigchldHandler for NativeProcessAIX.


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

1 Files Affected:

  • (modified) lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp (+42-1)
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
index cd5e3458e60e8..7f3dbbff18ea2 100644
--- a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -137,6 +137,12 @@ void NativeProcessAIX::Manager::SigchldHandler() {
     auto wait_result = WaitPid();
     if (!wait_result)
       return;
+    lldb::pid_t pid = wait_result->first;
+    WaitStatus status = wait_result->second;
+
+    llvm::any_of(m_processes, [&](NativeProcessAIX *process) {
+      return process->TryHandleWaitStatus(pid, status);
+    });
   }
 }
 
@@ -187,7 +193,41 @@ Status NativeProcessAIX::Signal(int signo) { return Status("unsupported"); }
 
 Status NativeProcessAIX::Interrupt() { return Status("unsupported"); }
 
-Status NativeProcessAIX::Kill() { return Status("unsupported"); }
+Status NativeProcessAIX::Kill() {
+
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid {0}", GetID());
+
+  Status error;
+
+  switch (m_state) {
+  case StateType::eStateInvalid:
+  case StateType::eStateExited:
+  case StateType::eStateCrashed:
+  case StateType::eStateDetached:
+  case StateType::eStateUnloaded:
+    // Nothing to do - the process is already dead.
+    LLDB_LOG(log, "ignored for PID {0} due to current state: {1}", GetID(),
+             m_state);
+    return error;
+
+  case StateType::eStateConnected:
+  case StateType::eStateAttaching:
+  case StateType::eStateLaunching:
+  case StateType::eStateStopped:
+  case StateType::eStateRunning:
+  case StateType::eStateStepping:
+  case StateType::eStateSuspended:
+    // We can try to kill a process in these states.
+    break;
+  }
+
+  llvm::Error result =
+      (PtraceWrapper(PT_KILL, GetID(), nullptr, nullptr, 0)).takeError();
+  if (!result)
+    error.FromErrorString("Kill failed");
+  return error;
+}
 
 Status NativeProcessAIX::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
                                     size_t &bytes_read) {
@@ -237,6 +277,7 @@ llvm::Expected<int> NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid,
   switch (req) {
   case PT_ATTACH:
   case PT_DETACH:
+  case PT_KILL:
     ret = ptrace64(req, pid, 0, 0, nullptr);
     break;
   default:

}

llvm::Error result =
(PtraceWrapper(PT_KILL, GetID(), nullptr, nullptr, 0)).takeError();
Copy link
Member Author

@DhruvSrivastavaX DhruvSrivastavaX Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIGKILL on a traced debuggee does not trigger SIGCHLD, thats why we use PT_KILL on AIX.

(PtraceWrapper(PT_KILL, GetID(), nullptr, nullptr, 0)).takeError();
if (!result)
error.FromErrorString("Kill failed");
return error;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either return the error without modification (assuming there's a Status constructor from llvm::Error), or, if the error back from PTraceWrapper can be formatted, add that to your "Kill failed" message.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see later that the error will be the errno, so you could format that. llvm::Error might have a generic toString type method on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants