This revision was automatically updated to reflect the committed changes.
Closed by commit rG287ce6b51675: [lldb] [Commands] Implement "thread 
siginfo" (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118473/new/

https://reviews.llvm.org/D118473

Files:
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/test/Shell/Commands/Inputs/sigchld.c
  lldb/test/Shell/Commands/command-thread-siginfo.test

Index: lldb/test/Shell/Commands/command-thread-siginfo.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Commands/command-thread-siginfo.test
@@ -0,0 +1,19 @@
+# REQUIRES: system-linux
+# RUN: %clang_host -g %S/Inputs/sigchld.c -o %t
+# RUN: %lldb %t -b -s %s | FileCheck %s
+
+process launch -s
+process handle SIGCHLD -s true
+process continue
+# CHECK: signo = [[SIGNO:[0-9]+]]
+# CHECK: code = [[CODE:[0-9]+]]
+# CHECK: child_pid = [[PID:[0-9]+]]
+# CHECK: uid = [[UID:[0-9]+]]
+# CHECK: stop reason = signal SIGCHLD
+thread siginfo
+# CHECK-DAG: si_signo = [[SIGNO]]
+# CHECK-DAG: si_errno = 0
+# CHECK-DAG: si_code = [[CODE]]
+# CHECK-DAG: si_pid = [[PID]]
+# CHECK-DAG: si_uid = [[UID]]
+# CHECK-DAG: si_status = 14
Index: lldb/test/Shell/Commands/Inputs/sigchld.c
===================================================================
--- /dev/null
+++ lldb/test/Shell/Commands/Inputs/sigchld.c
@@ -0,0 +1,31 @@
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+void handler(int signo) {
+  printf("SIGCHLD\n");
+}
+
+int main() {
+  void *ret = signal(SIGINT, handler);
+  assert (ret != SIG_ERR);
+
+  pid_t child_pid = fork();
+  assert (child_pid != -1);
+
+  if (child_pid == 0) {
+    sleep(1);
+    _exit(14);
+  }
+
+  printf("signo = %d\n", SIGCHLD);
+  printf("code = %d\n", CLD_EXITED);
+  printf("child_pid = %d\n", child_pid);
+  printf("uid = %d\n", getuid());
+  pid_t waited = wait(NULL);
+  assert(waited == child_pid);
+
+  return 0;
+}
Index: lldb/source/Commands/CommandObjectThread.cpp
===================================================================
--- lldb/source/Commands/CommandObjectThread.cpp
+++ lldb/source/Commands/CommandObjectThread.cpp
@@ -1320,6 +1320,53 @@
   }
 };
 
+class CommandObjectThreadSiginfo : public CommandObjectIterateOverThreads {
+public:
+  CommandObjectThreadSiginfo(CommandInterpreter &interpreter)
+      : CommandObjectIterateOverThreads(
+            interpreter, "thread siginfo",
+            "Display the current siginfo object for a thread. Defaults to "
+            "the current thread.",
+            "thread siginfo",
+            eCommandRequiresProcess | eCommandTryTargetAPILock |
+                eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
+
+  ~CommandObjectThreadSiginfo() override = default;
+
+  void
+  HandleArgumentCompletion(CompletionRequest &request,
+                           OptionElementVector &opt_element_vector) override {
+    CommandCompletions::InvokeCommonCompletionCallbacks(
+        GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+        request, nullptr);
+  }
+
+  bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
+    ThreadSP thread_sp =
+        m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
+    if (!thread_sp) {
+      result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
+                                   tid);
+      return false;
+    }
+
+    Stream &strm = result.GetOutputStream();
+    if (!thread_sp->GetDescription(strm, eDescriptionLevelFull, false, false)) {
+      result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
+                                   thread_sp->GetIndexID());
+      return false;
+    }
+    ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
+    if (exception_object_sp)
+      exception_object_sp->Dump(strm);
+    else
+      strm.Printf("(no siginfo)\n");
+    strm.PutChar('\n');
+
+    return true;
+  }
+};
+
 // CommandObjectThreadReturn
 #define LLDB_OPTIONS_thread_return
 #include "CommandOptions.inc"
@@ -2293,6 +2340,8 @@
                  CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
   LoadSubCommand("exception", CommandObjectSP(new CommandObjectThreadException(
                                   interpreter)));
+  LoadSubCommand("siginfo",
+                 CommandObjectSP(new CommandObjectThreadSiginfo(interpreter)));
   LoadSubCommand("step-in",
                  CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
                      interpreter, "thread step-in",
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to