Skip to content

Commit

Permalink
Merge pull request #32 from sparcians/dev/bdutro/process-id-fixes
Browse files Browse the repository at this point in the history
Properly handle ProcessIDExtRecord in STFWriter
  • Loading branch information
bdutro authored Mar 11, 2024
2 parents 2c0770d + 1b339f1 commit 48a3226
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/stf_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace stf {
vlen_config_ = STFRecord::make<VLenConfigRecord>(vlen);
}

// cppcheck-suppress unusedFunction
void STFWriter::setHeaderProcessID(uint32_t hw_thread_id, uint32_t pid, uint32_t tid) {
initial_process_id_ = STFRecord::make<ProcessIDExtRecord>(hw_thread_id, pid, tid);
}

void STFWriter::flushHeader() {
stf_assert(!header_finalized_, "Cannot write anything else to the header after it has been finalized");

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand Down
12 changes: 12 additions & 0 deletions stf-inc/stf_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace stf {
class ISARecord;
class InstIEMRecord;
class ForcePCRecord;
class ProcessIDExtRecord;
class VLenConfigRecord;

/**
Expand All @@ -38,6 +39,9 @@ namespace stf {
STFRecord::Handle<ForcePCRecord> initial_pc_;
bool initial_pc_written_ = false;

STFRecord::Handle<ProcessIDExtRecord> initial_process_id_;
bool initial_process_id_written_ = false;

STFRecord::Handle<VLenConfigRecord> vlen_config_;
bool vlen_config_written_ = false;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 48a3226

Please sign in to comment.