[Lldb-commits] [PATCH] D127193: [lldb] [llgs] Fix signo sent with fork/vfork/vforkdone events

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 7 02:00:31 PDT 2022


mgorny created this revision.
mgorny added reviewers: labath, krytarowski, emaste.
Herald added a subscriber: arichardson.
Herald added a project: All.
mgorny requested review of this revision.

Fix sending stop reasons to include SIGTRAP as the signal number for
fork/vfork/vforkdone events.  Since signo is not included in the details
for these stop information structures, the current code incidentally
referenced the wrong union member, resulting in wrong signo being sent.

Sponsored by: The FreeBSD Foundation


https://reviews.llvm.org/D127193

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py


Index: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
@@ -16,7 +16,7 @@
         self.reset_test_sequence()
 
         # continue and expect fork
-        fork_regex = "[$]T.*;fork:p([0-9a-f]+)[.]([0-9a-f]+).*"
+        fork_regex = "[$]T05.*;fork:p([0-9a-f]+)[.]([0-9a-f]+).*"
         self.test_sequence.add_log_lines([
             "read packet: $c#00",
             {"direction": "send", "regex": fork_regex,
@@ -50,7 +50,7 @@
         self.reset_test_sequence()
 
         # continue and expect fork
-        fork_regex = "[$]T.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)
+        fork_regex = "[$]T05.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)
         self.test_sequence.add_log_lines([
             "read packet: $c#00",
             {"direction": "send", "regex": fork_regex,
@@ -86,7 +86,7 @@
         # resume the parent
         self.test_sequence.add_log_lines([
             "read packet: $c#00",
-            {"direction": "send", "regex": r"[$]T.*vforkdone.*"},
+            {"direction": "send", "regex": r"[$]T05.*vforkdone.*"},
             "read packet: $c#00",
             {"direction": "send", "regex": r"[$]W00;process:[0-9a-f]+#.*"},
         ], True)
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -694,6 +694,16 @@
   return nullptr;
 }
 
+static int GetSignalForStopReason(const struct ThreadStopInfo &tid_stop_info) {
+  if (tid_stop_info.reason == eStopReasonException)
+    return SIGTRAP; // TODO: does this make sense?
+  if (tid_stop_info.reason == eStopReasonFork ||
+      tid_stop_info.reason == eStopReasonVFork ||
+      tid_stop_info.reason == eStopReasonVForkDone)
+    return SIGTRAP;
+  return tid_stop_info.details.signal.signo;
+}
+
 static llvm::Expected<json::Array>
 GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
   Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread);
@@ -715,7 +725,7 @@
       return llvm::make_error<llvm::StringError>(
           "failed to get stop reason", llvm::inconvertibleErrorCode());
 
-    const int signum = tid_stop_info.details.signal.signo;
+    const int signum = GetSignalForStopReason(tid_stop_info);
     if (log) {
       LLDB_LOGF(log,
                 "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
@@ -799,7 +809,7 @@
   StreamString response;
   // Output the T packet with the thread
   response.PutChar('T');
-  int signum = tid_stop_info.details.signal.signo;
+  int signum = GetSignalForStopReason(tid_stop_info);
   LLDB_LOG(
       log,
       "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127193.434738.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220607/a6242278/attachment-0001.bin>


More information about the lldb-commits mailing list