diff options
Diffstat (limited to 'llvm/lib/XRay/Trace.cpp')
| -rw-r--r-- | llvm/lib/XRay/Trace.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/llvm/lib/XRay/Trace.cpp b/llvm/lib/XRay/Trace.cpp index 35a3033f435..69ac825f519 100644 --- a/llvm/lib/XRay/Trace.cpp +++ b/llvm/lib/XRay/Trace.cpp @@ -601,6 +601,19 @@ Error processFDRFunctionRecord(FDRState &State, DataExtractor &RecordExtractor, Records.emplace_back(); auto &Record = Records.back(); Record.RecordType = 0; // Record is type NORMAL. + // Back up one byte to re-read the first byte, which is important for + // computing the function id for a record. + --OffsetPtr; + + auto PreReadOffset = OffsetPtr; + uint32_t FuncIdBitField = RecordExtractor.getU32(&OffsetPtr); + if (OffsetPtr == PreReadOffset) + return createStringError( + std::make_error_code(std::errc::executable_format_error), + "Failed reading truncated function id field at offset %d.", + OffsetPtr); + + FirstByte = FuncIdBitField & 0xffu; // Strip off record type bit and use the next three bits. auto T = (FirstByte >> 1) & 0x07; switch (T) { @@ -626,23 +639,11 @@ Error processFDRFunctionRecord(FDRState &State, DataExtractor &RecordExtractor, Record.TId = State.ThreadId; Record.PId = State.ProcessId; - // Back up one byte to re-read the first byte, which is important for - // computing the function id for a record. - --OffsetPtr; - // Despite function Id being a signed int on XRayRecord, // when it is written to an FDR format, the top bits are truncated, // so it is effectively an unsigned value. When we shift off the // top four bits, we want the shift to be logical, so we read as // uint32_t. - auto PreReadOffset = OffsetPtr; - uint32_t FuncIdBitField = RecordExtractor.getU32(&OffsetPtr); - if (OffsetPtr == PreReadOffset) - return createStringError( - std::make_error_code(std::errc::executable_format_error), - "Failed reading truncated function id field at offset %d.", - OffsetPtr); - Record.FuncId = FuncIdBitField >> 4; // FunctionRecords have a 32 bit delta from the previous absolute TSC |

