Skip to content

Commit

Permalink
Crash: Lookup block numbers more efficiently.
Browse files Browse the repository at this point in the history
We only care about the first one in these places anyway.  Also make sure
we don't try to match an invalid block number.
  • Loading branch information
unknownbrackets committed Dec 21, 2022
1 parent c1c8a70 commit a53fd26
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
18 changes: 13 additions & 5 deletions Core/MIPS/ARM64/Arm64Jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,20 @@ bool Arm64Jit::DescribeCodePtr(const u8 *ptr, std::string &name) {
name = "loadStaticRegisters";
else {
u32 addr = blocks.GetAddressFromBlockPtr(ptr);
std::vector<int> numbers;
blocks.GetBlockNumbersFromAddress(addr, &numbers);
if (!numbers.empty()) {
const JitBlock *block = blocks.GetBlock(numbers[0]);
// Returns 0 when it's valid, but unknown.
if (jitAddr == 0) {
name = "(unknown or deleted block)";
return true;
} else if (jitAddr != (u32)-1) {
name = "(outside space)";
return true;
}

int number = blocks.GetBlockNumberFromAddress(addr);
if (number != -1) {
const JitBlock *block = blocks.GetBlock(number);
if (block) {
name = StringFromFormat("(block %d at %08x)", numbers[0], block->originalAddress);
name = StringFromFormat("(block %d at %08x)", number, block->originalAddress);
return true;
}
}
Expand Down
9 changes: 9 additions & 0 deletions Core/MIPS/JitCommon/JitBlockCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ void JitBlockCache::GetBlockNumbersFromAddress(u32 em_address, std::vector<int>
block_numbers->push_back(i);
}

int JitBlockCache::GetBlockNumberFromAddress(u32 em_address) {
for (int i = 0; i < num_blocks_; i++) {
if (blocks_[i].ContainsAddress(em_address))
return i;
}

return -1;
}

u32 JitBlockCache::GetAddressFromBlockPtr(const u8 *ptr) const {
if (!codeBlock_->IsInSpace(ptr))
return (u32)-1;
Expand Down
2 changes: 2 additions & 0 deletions Core/MIPS/JitCommon/JitBlockCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class JitBlockCache : public JitBlockCacheDebugInterface {
// Returns a list of block numbers - only one block can start at a particular address, but they CAN overlap.
// This one is slow so should only be used for one-shots from the debugger UI, not for anything during runtime.
void GetBlockNumbersFromAddress(u32 em_address, std::vector<int> *block_numbers);
// Similar to above, but only the first matching address.
int GetBlockNumberFromAddress(u32 em_address);
int GetBlockNumberFromEmuHackOp(MIPSOpcode inst, bool ignoreBad = false) const;

u32 GetAddressFromBlockPtr(const u8 *ptr) const;
Expand Down
8 changes: 1 addition & 7 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,13 +1145,7 @@ UI::EventReturn JitCompareScreen::OnCurrentBlock(UI::EventParams &e) {
JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache();
if (!blockCache)
return UI::EVENT_DONE;
std::vector<int> blockNum;
blockCache->GetBlockNumbersFromAddress(currentMIPS->pc, &blockNum);
if (blockNum.size() > 0) {
currentBlock_ = blockNum[0];
} else {
currentBlock_ = -1;
}
currentBlock_ = blockCache->GetBlockNumberFromAddress(currentMIPS->pc);
UpdateDisasm();
return UI::EVENT_DONE;
}
Expand Down

0 comments on commit a53fd26

Please sign in to comment.