JDevlieghere created this revision.
JDevlieghere added reviewers: labath, teemperor, LLDB.

While debugging why `TestProcessList.py` failed during passive replay, I 
remembered that we don't serialize the arguments for ProcessInfo. This is 
necessary to make the test pass and to make `platform process list -v` behave 
the same during capture and replay.

  $ ./bin/lldb --capture
  (lldb) platform process list -v
  303 matching processes were found on "host"
  PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE              
           ARGUMENTS
  ====== ====== ========== ========== ========== ========== 
============================== ============================
  40118  40116  jonas      staff      jonas      staff      x86_64-apple-macosx 
            -fish
  40116  2502   jonas      staff      jonas      staff      x86_64-apple-macosx 
            fish -c reattach-to-user-namespace -l fish
  ...

  $./bin/lldb --replay 
/var/folders/n4/g9s84l4125s3x9fqjjmncxzh0000gn/T/reproducer-71d635
  (lldb) platform process list -v
  303 matching processes were found on "host"
  PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE              
           ARGUMENTS
  ====== ====== ========== ========== ========== ========== 
============================== ============================
  40118  40116  jonas      staff      jonas      staff      x86_64-apple-macosx
  40116  2502   jonas      staff      jonas      staff      x86_64-apple-macosx


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D79646

Files:
  lldb/include/lldb/Utility/Args.h
  lldb/source/Utility/Args.cpp
  lldb/source/Utility/ProcessInfo.cpp
  lldb/test/Shell/Reproducer/TestProcessList.test


Index: lldb/test/Shell/Reproducer/TestProcessList.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Reproducer/TestProcessList.test
@@ -0,0 +1,21 @@
+# UNSUPPORTED: system-freebsd
+
+# Test that ProcessInfo is correctly serialized by comparing the output of
+# 'platform process list -v' during capture and replay. The test assumes that
+# there's at least two processes.
+
+# RUN: %lldb -x -b -o 'platform process list -v' -o 'reproducer generate' 
--capture --capture-path %t.repro > %t.log
+# RUN: %lldb --replay %t.repro >> %t.log
+# RUN: cat %t.log | FileCheck %s
+
+# CHECK: [[PROCS:[0-9]+]] matching processes were found
+# CHECK: PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE      
                   ARGUMENTS
+# CHECK-NEXT: ====== ====== ========== ========== ========== ========== 
============================== ============================
+# CHECK-NEXT: [[PID0:[0-9]+]] [[PROC0:.*]]
+# CHECK-NEXT: [[PID1:[0-9]+]] [[PROC1:.*]]
+# CHECK: Reproducer written to
+# CHECK: [[PROCS]] matching processes were found
+# CHECK: PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE      
                   ARGUMENTS
+# CHECK-NEXT: ====== ====== ========== ========== ========== ========== 
============================== ============================
+# CHECK-NEXT: [[PID0]] [[PROC0]]
+# CHECK-NEXT: [[PID1]] [[PROC1]]
Index: lldb/source/Utility/ProcessInfo.cpp
===================================================================
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -337,6 +337,7 @@
     IO &io, ProcessInstanceInfo &Info) {
   io.mapRequired("executable", Info.m_executable);
   io.mapRequired("arg0", Info.m_arg0);
+  io.mapRequired("args", Info.m_arguments);
   io.mapRequired("arch", Info.m_arch);
   io.mapRequired("uid", Info.m_uid);
   io.mapRequired("gid", Info.m_gid);
Index: lldb/source/Utility/Args.cpp
===================================================================
--- lldb/source/Utility/Args.cpp
+++ lldb/source/Utility/Args.cpp
@@ -684,3 +684,16 @@
     m_suffix = std::string(original_args);
   }
 }
+
+void llvm::yaml::ScalarTraits<Args>::output(const Args &Val, void *,
+                                            llvm::raw_ostream &Out) {
+  std::string str;
+  Val.GetCommandString(str);
+  Out << str;
+}
+
+llvm::StringRef llvm::yaml::ScalarTraits<Args>::input(llvm::StringRef Scalar,
+                                                      void *, Args &Val) {
+  Val.SetCommandString(Scalar);
+  return {};
+}
Index: lldb/include/lldb/Utility/Args.h
===================================================================
--- lldb/include/lldb/Utility/Args.h
+++ lldb/include/lldb/Utility/Args.h
@@ -14,6 +14,7 @@
 #include "lldb/lldb-types.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/YAMLTraits.h"
 #include <string>
 #include <utility>
 #include <vector>
@@ -373,4 +374,14 @@
 
 } // namespace lldb_private
 
+namespace llvm {
+namespace yaml {
+template <> struct ScalarTraits<lldb_private::Args> {
+  static void output(const lldb_private::Args &, void *, raw_ostream &);
+  static StringRef input(StringRef, void *, lldb_private::Args &);
+  static QuotingType mustQuote(StringRef S) { return QuotingType::Double; }
+};
+} // namespace yaml
+} // namespace llvm
+
 #endif // LLDB_UTILITY_ARGS_H


Index: lldb/test/Shell/Reproducer/TestProcessList.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Reproducer/TestProcessList.test
@@ -0,0 +1,21 @@
+# UNSUPPORTED: system-freebsd
+
+# Test that ProcessInfo is correctly serialized by comparing the output of
+# 'platform process list -v' during capture and replay. The test assumes that
+# there's at least two processes.
+
+# RUN: %lldb -x -b -o 'platform process list -v' -o 'reproducer generate' --capture --capture-path %t.repro > %t.log
+# RUN: %lldb --replay %t.repro >> %t.log
+# RUN: cat %t.log | FileCheck %s
+
+# CHECK: [[PROCS:[0-9]+]] matching processes were found
+# CHECK: PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE                         ARGUMENTS
+# CHECK-NEXT: ====== ====== ========== ========== ========== ========== ============================== ============================
+# CHECK-NEXT: [[PID0:[0-9]+]] [[PROC0:.*]]
+# CHECK-NEXT: [[PID1:[0-9]+]] [[PROC1:.*]]
+# CHECK: Reproducer written to
+# CHECK: [[PROCS]] matching processes were found
+# CHECK: PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE                         ARGUMENTS
+# CHECK-NEXT: ====== ====== ========== ========== ========== ========== ============================== ============================
+# CHECK-NEXT: [[PID0]] [[PROC0]]
+# CHECK-NEXT: [[PID1]] [[PROC1]]
Index: lldb/source/Utility/ProcessInfo.cpp
===================================================================
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -337,6 +337,7 @@
     IO &io, ProcessInstanceInfo &Info) {
   io.mapRequired("executable", Info.m_executable);
   io.mapRequired("arg0", Info.m_arg0);
+  io.mapRequired("args", Info.m_arguments);
   io.mapRequired("arch", Info.m_arch);
   io.mapRequired("uid", Info.m_uid);
   io.mapRequired("gid", Info.m_gid);
Index: lldb/source/Utility/Args.cpp
===================================================================
--- lldb/source/Utility/Args.cpp
+++ lldb/source/Utility/Args.cpp
@@ -684,3 +684,16 @@
     m_suffix = std::string(original_args);
   }
 }
+
+void llvm::yaml::ScalarTraits<Args>::output(const Args &Val, void *,
+                                            llvm::raw_ostream &Out) {
+  std::string str;
+  Val.GetCommandString(str);
+  Out << str;
+}
+
+llvm::StringRef llvm::yaml::ScalarTraits<Args>::input(llvm::StringRef Scalar,
+                                                      void *, Args &Val) {
+  Val.SetCommandString(Scalar);
+  return {};
+}
Index: lldb/include/lldb/Utility/Args.h
===================================================================
--- lldb/include/lldb/Utility/Args.h
+++ lldb/include/lldb/Utility/Args.h
@@ -14,6 +14,7 @@
 #include "lldb/lldb-types.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/YAMLTraits.h"
 #include <string>
 #include <utility>
 #include <vector>
@@ -373,4 +374,14 @@
 
 } // namespace lldb_private
 
+namespace llvm {
+namespace yaml {
+template <> struct ScalarTraits<lldb_private::Args> {
+  static void output(const lldb_private::Args &, void *, raw_ostream &);
+  static StringRef input(StringRef, void *, lldb_private::Args &);
+  static QuotingType mustQuote(StringRef S) { return QuotingType::Double; }
+};
+} // namespace yaml
+} // namespace llvm
+
 #endif // LLDB_UTILITY_ARGS_H
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to