[XRay] Use correct type for PID records
authorDean Michael Berris <dberris@google.com>
Fri, 31 Aug 2018 19:32:46 +0000 (19:32 +0000)
committerDean Michael Berris <dberris@google.com>
Fri, 31 Aug 2018 19:32:46 +0000 (19:32 +0000)
Previously we've been reading and writing the wrong types which only
worked in little endian implementations. This time we're writing the
same typed values the runtime is using, and reading them appropriately
as well.

llvm-svn: 341241

llvm/include/llvm/XRay/FDRRecords.h
llvm/lib/XRay/Trace.cpp
llvm/unittests/XRay/FDRTraceWriterTest.cpp

index aaa0985..ab98a03 100644 (file)
@@ -185,16 +185,16 @@ public:
 };
 
 class PIDRecord : public MetadataRecord {
-  uint64_t PID = 0;
+  int32_t PID = 0;
   friend class RecordInitializer;
 
 public:
   PIDRecord() = default;
-  explicit PIDRecord(uint64_t P) : MetadataRecord(), PID(P) {}
+  explicit PIDRecord(int32_t P) : MetadataRecord(), PID(P) {}
 
   MetadataType metadataType() const override { return MetadataType::PIDEntry; }
 
-  uint64_t pid() const { return PID; }
+  int32_t pid() const { return PID; }
 
   Error apply(RecordVisitor &V) override;
 };
index f92385a..45b266d 100644 (file)
@@ -396,7 +396,7 @@ Error processFDRPidRecord(FDRState &State, DataExtractor &RecordExtractor,
             fdrStateToTwine(State.Expects),
         std::make_error_code(std::errc::executable_format_error));
   auto PreReadOffset = OffsetPtr;
-  State.ProcessId = RecordExtractor.getU32(&OffsetPtr);
+  State.ProcessId = RecordExtractor.getSigned(&OffsetPtr, 4);
   if (OffsetPtr == PreReadOffset)
     return createStringError(
         std::make_error_code(std::errc::executable_format_error),
index 215a2d2..e9a35fe 100644 (file)
@@ -63,15 +63,15 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion3) {
   auto &Trace = TraceOrErr.get();
 
   ASSERT_THAT(Trace, Not(IsEmpty()));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::FuncId, Eq(1)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::FuncId, Eq(1)),
                                  Field(&XRayRecord::FuncId, Eq(1))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::TId, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::TId, Eq(1u)),
                                  Field(&XRayRecord::TId, Eq(1u))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::PId, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::PId, Eq(1u)),
                                  Field(&XRayRecord::PId, Eq(1u))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::CPU, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::CPU, Eq(1u)),
                                  Field(&XRayRecord::CPU, Eq(1u))));
-  ASSERT_THAT(Trace,
+  EXPECT_THAT(Trace,
               ElementsAre(Field(&XRayRecord::Type, Eq(RecordTypes::ENTER)),
                           Field(&XRayRecord::Type, Eq(RecordTypes::EXIT))));
 }
@@ -108,13 +108,13 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion2) {
   auto &Trace = TraceOrErr.get();
 
   ASSERT_THAT(Trace, Not(IsEmpty()));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::FuncId, Eq(1)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::FuncId, Eq(1)),
                                  Field(&XRayRecord::FuncId, Eq(1))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::TId, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::TId, Eq(1u)),
                                  Field(&XRayRecord::TId, Eq(1u))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::CPU, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::CPU, Eq(1u)),
                                  Field(&XRayRecord::CPU, Eq(1u))));
-  ASSERT_THAT(Trace,
+  EXPECT_THAT(Trace,
               ElementsAre(Field(&XRayRecord::Type, Eq(RecordTypes::ENTER)),
                           Field(&XRayRecord::Type, Eq(RecordTypes::EXIT))));
 }
@@ -167,14 +167,13 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) {
   auto &Trace = TraceOrErr.get();
 
   ASSERT_THAT(Trace, Not(IsEmpty()));
-  ASSERT_THAT(Trace, Not(IsEmpty()));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::FuncId, Eq(1)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::FuncId, Eq(1)),
                                  Field(&XRayRecord::FuncId, Eq(1))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::TId, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::TId, Eq(1u)),
                                  Field(&XRayRecord::TId, Eq(1u))));
-  ASSERT_THAT(Trace, ElementsAre(Field(&XRayRecord::CPU, Eq(1u)),
+  EXPECT_THAT(Trace, ElementsAre(Field(&XRayRecord::CPU, Eq(1u)),
                                  Field(&XRayRecord::CPU, Eq(1u))));
-  ASSERT_THAT(Trace,
+  EXPECT_THAT(Trace,
               ElementsAre(Field(&XRayRecord::Type, Eq(RecordTypes::ENTER)),
                           Field(&XRayRecord::Type, Eq(RecordTypes::EXIT))));
 }