cpu-minor: Check pc valid before printing (#107)

In https://gem5-review.googlesource.com/c/public/gem5/+/52047 inst.pc
was changed from an object to a pointer. It is possible that this
pointer is null (e.g., if there is an interrupt and there is a bubble).
Make sure to check that it's not null before printing.

I believe that other places this pointer is dereferenced without an
explicit null check are safe, but I'm not certain.

Should fix #97 

Change-Id: Idbe246cfdb62d4d75416d41b451fb3c076233bbc
This commit is contained in:
Bobby R. Bruce
2023-07-25 17:14:38 -07:00
committed by GitHub

View File

@@ -112,6 +112,11 @@ MinorDynInst::reportData(std::ostream &os) const
std::ostream &
operator <<(std::ostream &os, const MinorDynInst &inst)
{
if (!inst.pc) {
os << inst.id << " pc: 0x???????? (bubble)";
return os;
}
os << inst.id << " pc: 0x"
<< std::hex << inst.pc->instAddr() << std::dec << " (";
@@ -169,7 +174,7 @@ MinorDynInst::minorTraceInst(const Named &named_object) const
{
if (isFault()) {
minorInst(named_object, "id=F;%s addr=0x%x fault=\"%s\"\n",
id, pc->instAddr(), fault->name());
id, pc ? pc->instAddr() : 0, fault->name());
} else {
unsigned int num_src_regs = staticInst->numSrcRegs();
unsigned int num_dest_regs = staticInst->numDestRegs();
@@ -209,7 +214,7 @@ MinorDynInst::minorTraceInst(const Named &named_object) const
minorInst(named_object, "id=%s addr=0x%x inst=\"%s\" class=%s"
" flags=\"%s\"%s%s\n",
id, pc->instAddr(),
id, pc ? pc->instAddr() : 0,
(staticInst->opClass() == No_OpClass ?
"(invalid)" : staticInst->disassemble(0,NULL)),
enums::OpClassStrings[staticInst->opClass()],