forked from OSchip/llvm-project
[XRay] Attempt to fix failure on Windows
Original version of the code relied on implementation-defined order of bitfields. Follow-up on D51210. llvm-svn: 341194
This commit is contained in:
parent
a26a364e75
commit
7a07a41cbb
llvm
|
@ -21,9 +21,8 @@ namespace {
|
|||
struct alignas(32) FileHeader {
|
||||
uint16_t Version;
|
||||
uint16_t Type;
|
||||
bool ConstantTSC : 1;
|
||||
bool NonstopTSC : 1;
|
||||
alignas(8) uint64_t CycleFrequency;
|
||||
uint32_t BitField;
|
||||
uint64_t CycleFrequency;
|
||||
char FreeForm[16];
|
||||
};
|
||||
|
||||
|
@ -65,7 +64,7 @@ template <size_t Index> struct IndexedMemcpy {
|
|||
};
|
||||
|
||||
template <uint8_t Kind, class... Values>
|
||||
Error writeMetadata(raw_ostream &OS, Values&&... Ds) {
|
||||
Error writeMetadata(raw_ostream &OS, Values &&... Ds) {
|
||||
MetadataBlob B;
|
||||
B.Type = 1;
|
||||
B.RecordKind = Kind;
|
||||
|
@ -85,8 +84,7 @@ FDRTraceWriter::FDRTraceWriter(raw_ostream &O, const XRayFileHeader &H)
|
|||
FileHeader Raw;
|
||||
Raw.Version = H.Version;
|
||||
Raw.Type = H.Type;
|
||||
Raw.ConstantTSC = H.ConstantTSC;
|
||||
Raw.NonstopTSC = H.NonstopTSC;
|
||||
Raw.BitField = (H.ConstantTSC ? 0x01 : 0x0) | (H.NonstopTSC ? 0x02 : 0x0);
|
||||
Raw.CycleFrequency = H.CycleFrequency;
|
||||
memcpy(&Raw.FreeForm, H.FreeFormData, 16);
|
||||
OS.write(reinterpret_cast<const char *>(&Raw), sizeof(XRayFileHeader));
|
||||
|
|
|
@ -135,6 +135,11 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) {
|
|||
std::memcpy(H.FreeFormData, reinterpret_cast<const char *>(&BufferSize),
|
||||
sizeof(BufferSize));
|
||||
FDRTraceWriter Writer(OS, H);
|
||||
OS.flush();
|
||||
|
||||
// Ensure that at this point the Data buffer has the file header serialized
|
||||
// size.
|
||||
ASSERT_THAT(Data.size(), Eq(32u));
|
||||
auto L = LogBuilder()
|
||||
.add<NewBufferRecord>(1)
|
||||
.add<WallclockRecord>(1, 1)
|
||||
|
@ -150,6 +155,10 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) {
|
|||
OS.write_zeros(4016);
|
||||
OS.flush();
|
||||
|
||||
// For version 1 of the log, we need the whole buffer to be the size of the
|
||||
// file header plus 32.
|
||||
ASSERT_THAT(Data.size(), Eq(BufferSize + 32));
|
||||
|
||||
// Then from here we load the Trace file.
|
||||
DataExtractor DE(Data, true, 8);
|
||||
auto TraceOrErr = loadTrace(DE, true);
|
||||
|
|
Loading…
Reference in New Issue