From 1b339f1e99abd9728e2632a74458ec1642c4f397 Mon Sep 17 00:00:00 2001 From: Brett Dutro Date: Fri, 8 Mar 2024 11:20:45 -0600 Subject: [PATCH] Properly handle ProcessIDExtRecord in STFWriter --- lib/stf_writer.cpp | 14 +++++++++++++- stf-inc/stf_writer.hpp | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/stf_writer.cpp b/lib/stf_writer.cpp index 8279a0c..0cfde40 100644 --- a/lib/stf_writer.cpp +++ b/lib/stf_writer.cpp @@ -22,6 +22,11 @@ namespace stf { vlen_config_ = STFRecord::make(vlen); } + // cppcheck-suppress unusedFunction + void STFWriter::setHeaderProcessID(uint32_t hw_thread_id, uint32_t pid, uint32_t tid) { + initial_process_id_ = STFRecord::make(hw_thread_id, pid, tid); + } + void STFWriter::flushHeader() { stf_assert(!header_finalized_, "Cannot write anything else to the header after it has been finalized"); @@ -69,6 +74,12 @@ namespace stf { trace_features_written_ = true; } + // Initial process ID is optional + if(!initial_process_id_written_ && initial_process_id_) { + *this << *initial_process_id_; + initial_process_id_written_ = true; + } + if(!initial_pc_written_ && initial_pc_) { stf_assert(isa_written_, "ISA record must come before FORCE_PC record"); stf_assert(initial_iem_written_, "IEM record must come before FORCE_PC record"); @@ -156,6 +167,7 @@ namespace stf { ((wrote_page_table_walk_ || wrote_reg_) && desc == descriptors::internal::Descriptor::STF_INST_PC_TARGET) || (wrote_page_table_walk_ && desc == descriptors::internal::Descriptor::STF_INST_REG) || (desc == descriptors::internal::Descriptor::STF_COMMENT) || + (desc == descriptors::internal::Descriptor::STF_PROCESS_ID_EXT) || (desc == descriptors::internal::Descriptor::STF_FORCE_PC), "Attempted out of order write. " << desc << " should come before " << last_desc_); switch(desc) { @@ -169,10 +181,10 @@ namespace stf { case descriptors::internal::Descriptor::STF_ISA: case descriptors::internal::Descriptor::STF_TRACE_INFO: case descriptors::internal::Descriptor::STF_TRACE_INFO_FEATURE: - case descriptors::internal::Descriptor::STF_PROCESS_ID_EXT: case descriptors::internal::Descriptor::STF_VLEN_CONFIG: case descriptors::internal::Descriptor::STF_END_HEADER: stf_assert(!headerFinalized(), "Attempted to write " << desc << " record outside of the header"); //FALLTHRU + case descriptors::internal::Descriptor::STF_PROCESS_ID_EXT: case descriptors::internal::Descriptor::STF_INST_IEM: case descriptors::internal::Descriptor::STF_FORCE_PC: stf_assert(headerStarted(), "Attempted to write " << desc << " before the header has started"); diff --git a/stf-inc/stf_writer.hpp b/stf-inc/stf_writer.hpp index a25f610..4b28e5d 100644 --- a/stf-inc/stf_writer.hpp +++ b/stf-inc/stf_writer.hpp @@ -18,6 +18,7 @@ namespace stf { class ISARecord; class InstIEMRecord; class ForcePCRecord; + class ProcessIDExtRecord; class VLenConfigRecord; /** @@ -38,6 +39,9 @@ namespace stf { STFRecord::Handle initial_pc_; bool initial_pc_written_ = false; + STFRecord::Handle initial_process_id_; + bool initial_process_id_written_ = false; + STFRecord::Handle vlen_config_; bool vlen_config_written_ = false; @@ -83,6 +87,14 @@ namespace stf { */ void setHeaderPC(const uint64_t pc); + /** + * Sets header PC + * \param hw_thread_id Hardware thread/core ID + * \param pid Process ID + * \param tid Thread ID + */ + void setHeaderProcessID(const uint32_t hw_thread_id, const uint32_t pid, const uint32_t tid); + /** * Removes trace feature from header * \param trace_feature feature to remove