cpu-minor: Check pc valid before printing

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.

Change-Id: Idbe246cfdb62d4d75416d41b451fb3c076233bbc
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
Jason Lowe-Power
2023-07-20 13:23:16 -07:00
committed by Bobby R. Bruce
parent 41abc6ab77
commit 4516a00593

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()],