-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb][AIX] Added Kill() implementation #169454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-lldb Author: Dhruv Srivastava (DhruvSrivastavaX) ChangesThis 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: Full diff: https://github.com/llvm/llvm-project/pull/169454.diff 1 Files Affected:
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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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