[Lldb-commits] [lldb] 0ce3b71 - [lldb] Add YAML traits for ArchSpec and ProcessInstanceInfo
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 12 14:44:34 PDT 2020
Author: Jonas Devlieghere
Date: 2020-03-12T14:38:37-07:00
New Revision: 0ce3b710b49c7b9ab837d220547aec92564dd78d
URL: https://github.com/llvm/llvm-project/commit/0ce3b710b49c7b9ab837d220547aec92564dd78d
DIFF: https://github.com/llvm/llvm-project/commit/0ce3b710b49c7b9ab837d220547aec92564dd78d.diff
LOG: [lldb] Add YAML traits for ArchSpec and ProcessInstanceInfo
Add YAML traits for ArchSpec and ProcessInstanceInfo so they can be
serialized for the reproducers.
Differential revision: https://reviews.llvm.org/D76004
Added:
Modified:
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
Removed:
################################################################################
diff --git a/lldb/include/lldb/Utility/ArchSpec.h b/lldb/include/lldb/Utility/ArchSpec.h
index ca6d7e0ca0e4..5466e573c1a5 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/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 @@ bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch);
} // 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
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h b/lldb/include/lldb/Utility/ProcessInfo.h
index d2ad40487224..0d631d06d2df 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/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 @@ class ProcessInfo {
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
diff ers from
@@ -150,6 +150,7 @@ class ProcessInstanceInfo : public ProcessInfo {
bool verbose) const;
protected:
+ friend struct llvm::yaml::MappingTraits<ProcessInstanceInfo>;
uint32_t m_euid;
uint32_t m_egid;
lldb::pid_t m_parent_pid;
@@ -216,4 +217,14 @@ class ProcessInstanceInfoMatch {
} // 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);
+};
+} // namespace yaml
+} // namespace llvm
+
#endif // LLDB_UTILITY_PROCESSINFO_H
diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp
index bb4771c6488c..ca1ce4b3d378 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -1467,3 +1467,15 @@ void ArchSpec::DumpTriple(llvm::raw_ostream &s) const {
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 {};
+}
diff --git a/lldb/source/Utility/ProcessInfo.cpp b/lldb/source/Utility/ProcessInfo.cpp
index c78e62c394ff..450e62d8c5d6 100644
--- a/lldb/source/Utility/ProcessInfo.cpp
+++ b/lldb/source/Utility/ProcessInfo.cpp
@@ -331,3 +331,16 @@ void ProcessInstanceInfoMatch::Clear() {
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);
+}
diff --git a/lldb/unittests/Utility/ArchSpecTest.cpp b/lldb/unittests/Utility/ArchSpecTest.cpp
index f939399c7e4a..a5ad68b6bbad 100644
--- a/lldb/unittests/Utility/ArchSpecTest.cpp
+++ b/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 @@ TEST(ArchSpecTest, MergeFrom) {
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 @@ TEST(ArchSpecTest, TripleComponentsWereSpecified) {
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);
+}
diff --git a/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp b/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp
index 413969066bbe..a3f850cfb9b4 100644
--- a/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp
+++ b/lldb/unittests/Utility/ProcessInstanceInfoTest.cpp
@@ -108,3 +108,60 @@ TEST(ProcessInstanceInfoMatch, Name) {
EXPECT_TRUE(match.Matches(info_bar));
EXPECT_TRUE(match.Matches(info_empty));
}
+
+TEST(ProcessInstanceInfo, 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());
+}
+
+TEST(ProcessInstanceInfoList, 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);
+ ProcessInstanceInfoList list;
+ list.push_back(info);
+ llvm::yaml::Output yout(os);
+ yout << list;
+ os.flush();
+
+ // Deserialize.
+ ProcessInstanceInfoList deserialized;
+ llvm::yaml::Input yin(buffer);
+ yin >> deserialized;
+
+ ASSERT_EQ(deserialized.size(), static_cast<size_t>(1));
+ EXPECT_EQ(deserialized[0].GetNameAsStringRef(), info.GetNameAsStringRef());
+ EXPECT_EQ(deserialized[0].GetArchitecture(), info.GetArchitecture());
+ EXPECT_EQ(deserialized[0].GetUserID(), info.GetUserID());
+ EXPECT_EQ(deserialized[0].GetGroupID(), info.GetGroupID());
+ EXPECT_EQ(deserialized[0].GetEffectiveUserID(), info.GetEffectiveUserID());
+ EXPECT_EQ(deserialized[0].GetEffectiveGroupID(), info.GetEffectiveGroupID());
+}
More information about the lldb-commits
mailing list