JDevlieghere created this revision.
JDevlieghere added a reviewer: labath.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
JDevlieghere added a parent revision: D76002: [lldb] Add YAML traits for 
ConstString and FileSpec.

Add YAML traits for ArchSpec and ProcessInstanceInfo so they can be serialized 
for the reproducers.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D76004

Files:
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/include/lldb/Utility/ProcessInfo.h
  lldb/source/Utility/ArchSpec.cpp
  lldb/source/Utility/ProcessInfo.cpp
  lldb/unittests/Utility/ArchSpecTest.cpp
  lldb/unittests/Utility/ProcessInstanceInfoTest.cpp

Index: lldb/unittests/Utility/ProcessInstanceInfoTest.cpp
===================================================================
--- lldb/unittests/Utility/ProcessInstanceInfoTest.cpp
+++ lldb/unittests/Utility/ProcessInstanceInfoTest.cpp
@@ -108,3 +108,30 @@
   EXPECT_TRUE(match.Matches(info_bar));
   EXPECT_TRUE(match.Matches(info_empty));
 }
+
+TEST(ProcessInstanceInfoMatch, Yaml) {
+  std::string buffer;
+  llvm::raw_string_ostream os(buffer);
+
+  // Serialize.
+  ProcessInstanceInfo info("a.out", ArchSpec("x86_64-pc-linux"), 47);
+  info.SetUserID(1);
+  info.SetEffectiveUserID(2);
+  info.SetGroupID(3);
+  info.SetEffectiveGroupID(4);
+  llvm::yaml::Output yout(os);
+  yout << info;
+  os.flush();
+
+  // Deserialize.
+  ProcessInstanceInfo deserialized;
+  llvm::yaml::Input yin(buffer);
+  yin >> deserialized;
+
+  EXPECT_EQ(deserialized.GetNameAsStringRef(), info.GetNameAsStringRef());
+  EXPECT_EQ(deserialized.GetArchitecture(), info.GetArchitecture());
+  EXPECT_EQ(deserialized.GetUserID(), info.GetUserID());
+  EXPECT_EQ(deserialized.GetGroupID(), info.GetGroupID());
+  EXPECT_EQ(deserialized.GetEffectiveUserID(), info.GetEffectiveUserID());
+  EXPECT_EQ(deserialized.GetEffectiveGroupID(), info.GetEffectiveGroupID());
+}
Index: lldb/unittests/Utility/ArchSpecTest.cpp
===================================================================
--- lldb/unittests/Utility/ArchSpecTest.cpp
+++ lldb/unittests/Utility/ArchSpecTest.cpp
@@ -9,8 +9,9 @@
 #include "gtest/gtest.h"
 
 #include "lldb/Utility/ArchSpec.h"
-#include "llvm/BinaryFormat/MachO.h"
 #include "llvm/BinaryFormat/ELF.h"
+#include "llvm/BinaryFormat/MachO.h"
+#include "llvm/Support/YAMLParser.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -200,14 +201,14 @@
 
     EXPECT_TRUE(A.IsValid());
     EXPECT_TRUE(B.IsValid());
-    
+
     EXPECT_EQ(llvm::Triple::ArchType::arm, B.GetTriple().getArch());
     EXPECT_EQ(llvm::Triple::VendorType::UnknownVendor,
               B.GetTriple().getVendor());
     EXPECT_EQ(llvm::Triple::OSType::Linux, B.GetTriple().getOS());
     EXPECT_EQ(llvm::Triple::EnvironmentType::UnknownEnvironment,
               B.GetTriple().getEnvironment());
-    
+
     A.MergeFrom(B);
     EXPECT_EQ(llvm::Triple::ArchType::arm, A.GetTriple().getArch());
     EXPECT_EQ(llvm::Triple::VendorType::UnknownVendor,
@@ -406,3 +407,23 @@
     ASSERT_TRUE(D.TripleEnvironmentWasSpecified());
   }
 }
+
+TEST(ArchSpecTest, YAML) {
+  std::string buffer;
+  llvm::raw_string_ostream os(buffer);
+
+  // Serialize.
+  llvm::yaml::Output yout(os);
+  std::vector<ArchSpec> archs = {ArchSpec("x86_64-pc-linux"),
+                                 ArchSpec("x86_64-apple-macosx10.12"),
+                                 ArchSpec("i686-pc-windows")};
+  yout << archs;
+  os.flush();
+
+  // Deserialize.
+  std::vector<ArchSpec> deserialized;
+  llvm::yaml::Input yin(buffer);
+  yin >> deserialized;
+
+  EXPECT_EQ(archs, deserialized);
+}
Index: lldb/source/Utility/ProcessInfo.cpp
===================================================================
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -331,3 +331,21 @@
   m_name_match_type = NameMatch::Ignore;
   m_match_all_users = false;
 }
+
+void llvm::yaml::MappingTraits<ProcessInstanceInfo>::mapping(
+    IO &io, ProcessInstanceInfo &Info) {
+  io.mapRequired("executable", Info.m_executable);
+  io.mapRequired("arg0", Info.m_arg0);
+  io.mapRequired("arch", Info.m_arch);
+  io.mapRequired("uid", Info.m_uid);
+  io.mapRequired("gid", Info.m_gid);
+  io.mapRequired("pid", Info.m_pid);
+  io.mapRequired("effective-uid", Info.m_euid);
+  io.mapRequired("effective-gid", Info.m_egid);
+  io.mapRequired("parent-pid", Info.m_parent_pid);
+}
+
+void llvm::yaml::MappingTraits<ProcessInstanceInfoList>::mapping(
+    IO &io, ProcessInstanceInfoList &List) {
+  io.mapRequired("processes", List.m_infos);
+}
Index: lldb/source/Utility/ArchSpec.cpp
===================================================================
--- lldb/source/Utility/ArchSpec.cpp
+++ lldb/source/Utility/ArchSpec.cpp
@@ -1467,3 +1467,15 @@
   if (!environ_str.empty())
     s << "-" << environ_str;
 }
+
+void llvm::yaml::ScalarTraits<ArchSpec>::output(const ArchSpec &Val, void *,
+                                                raw_ostream &Out) {
+  Val.DumpTriple(Out);
+}
+
+llvm::StringRef
+llvm::yaml::ScalarTraits<ArchSpec>::input(llvm::StringRef Scalar, void *,
+                                          ArchSpec &Val) {
+  Val = ArchSpec(Scalar);
+  return {};
+}
Index: lldb/include/lldb/Utility/ProcessInfo.h
===================================================================
--- lldb/include/lldb/Utility/ProcessInfo.h
+++ lldb/include/lldb/Utility/ProcessInfo.h
@@ -9,13 +9,12 @@
 #ifndef LLDB_UTILITY_PROCESSINFO_H
 #define LLDB_UTILITY_PROCESSINFO_H
 
-// LLDB headers
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/Environment.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/NameMatches.h"
-
+#include "llvm/Support/YAMLTraits.h"
 #include <vector>
 
 namespace lldb_private {
@@ -89,6 +88,7 @@
   const Environment &GetEnvironment() const { return m_environment; }
 
 protected:
+  template <class T> friend struct llvm::yaml::MappingTraits;
   FileSpec m_executable;
   std::string m_arg0; // argv[0] if supported. If empty, then use m_executable.
   // Not all process plug-ins support specifying an argv[0] that differs from
@@ -150,6 +150,7 @@
                       bool verbose) const;
 
 protected:
+  template <class T> friend struct llvm::yaml::MappingTraits;
   uint32_t m_euid;
   uint32_t m_egid;
   lldb::pid_t m_parent_pid;
@@ -188,6 +189,7 @@
   }
 
 protected:
+  template <class T> friend struct llvm::yaml::MappingTraits;
   std::vector<ProcessInstanceInfo> m_infos;
 };
 
@@ -250,4 +252,20 @@
 
 } // namespace lldb_private
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(lldb_private::ProcessInstanceInfo)
+
+namespace llvm {
+namespace yaml {
+
+template <> struct MappingTraits<lldb_private::ProcessInstanceInfo> {
+  static void mapping(IO &io, lldb_private::ProcessInstanceInfo &PII);
+};
+
+template <> struct MappingTraits<lldb_private::ProcessInstanceInfoList> {
+  static void mapping(IO &io, lldb_private::ProcessInstanceInfoList &PIIL);
+};
+
+} // namespace yaml
+} // namespace llvm
+
 #endif // LLDB_UTILITY_PROCESSINFO_H
Index: lldb/include/lldb/Utility/ArchSpec.h
===================================================================
--- lldb/include/lldb/Utility/ArchSpec.h
+++ lldb/include/lldb/Utility/ArchSpec.h
@@ -16,6 +16,7 @@
 #include "lldb/lldb-private-enumerations.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Support/YAMLTraits.h"
 #include <cstddef>
 #include <cstdint>
 #include <string>
@@ -541,4 +542,16 @@
 
 } // namespace lldb_private
 
+namespace llvm {
+namespace yaml {
+template <> struct ScalarTraits<lldb_private::ArchSpec> {
+  static void output(const lldb_private::ArchSpec &, void *, raw_ostream &);
+  static StringRef input(StringRef, void *, lldb_private::ArchSpec &);
+  static QuotingType mustQuote(StringRef S) { return QuotingType::Double; }
+};
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(lldb_private::ArchSpec)
+
 #endif // LLDB_UTILITY_ARCHSPEC_H
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Jonas Devlieghere via Phabricator via lldb-commits

Reply via email to