Merge pull request #15392 from unknownbrackets/debugger-memview

Make debugger memory search more consistent
This commit is contained in:
Henrik Rydgård 2022-02-11 08:39:01 +01:00 committed by GitHub
commit 21736d1ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 61 deletions

View File

@ -1,5 +1,6 @@
// NOTE: Apologies for the quality of this code, this is really from pre-opensource Dolphin - that is, 2003.
#include <cctype>
#include <tchar.h>
#include <math.h>
#include <iomanip>
@ -716,38 +717,74 @@ void CtrlMemView::scrollCursor(int bytes)
redraw();
}
bool CtrlMemView::ParseSearchString(const std::string &query, bool asHex, std::vector<uint8_t> &data) {
data.clear();
if (!asHex) {
for (size_t i = 0; i < query.length(); i++) {
data.push_back(query[i]);
}
return true;
}
std::vector<u32> CtrlMemView::searchString(std::string searchQuery)
{
for (size_t index = 0; index < query.size(); ) {
if (isspace(query[index])) {
index++;
continue;
}
u8 value = 0;
for (int i = 0; i < 2 && index < query.size(); i++) {
char c = tolower(query[index++]);
if (c >= 'a' && c <= 'f') {
value |= (c - 'a' + 10) << (1 - i) * 4;
} else if (c >= '0' && c <= '9') {
value |= (c - '0') << (1 - i) * 4;
} else {
return false;
}
}
data.push_back(value);
}
return true;
}
std::vector<u32> CtrlMemView::searchString(const std::string &searchQuery) {
std::vector<u32> searchResAddrs;
std::vector<u8> searchData;
auto memLock = Memory::Lock();
if (!PSP_IsInited())
return searchResAddrs;
size_t queryLength = searchQuery.length();
if (queryLength == 0)
std::vector<u8> searchData;
if (!ParseSearchString(searchQuery, false, searchData))
return searchResAddrs;
// TODO: Scratchpad, VRAM?
u32 segmentStart = PSP_GetKernelMemoryBase(); //RAM start
const u32 segmentEnd = PSP_GetUserMemoryEnd() - (u32)queryLength; //RAM end
u8* ptr;
if (searchData.empty())
return searchResAddrs;
redraw();
for (segmentStart = PSP_GetKernelMemoryBase(); segmentStart < segmentEnd; segmentStart++) {
if (KeyDownAsync(VK_ESCAPE))
{
return searchResAddrs;
}
std::vector<std::pair<u32, u32>> memoryAreas;
memoryAreas.push_back(std::pair<u32, u32>(PSP_GetScratchpadMemoryBase(), PSP_GetScratchpadMemoryEnd()));
// Ignore the video memory mirrors.
memoryAreas.push_back(std::pair<u32, u32>(PSP_GetVidMemBase(), 0x04200000));
memoryAreas.push_back(std::pair<u32, u32>(PSP_GetKernelMemoryBase(), PSP_GetUserMemoryEnd()));
ptr = Memory::GetPointer(segmentStart);
if (memcmp(ptr, searchQuery.c_str(), queryLength) == 0) {
searchResAddrs.push_back(segmentStart);
for (const auto &area : memoryAreas) {
const u32 segmentStart = area.first;
const u32 segmentEnd = area.second - (u32)searchData.size();
for (u32 pos = segmentStart; pos < segmentEnd; pos++) {
if ((pos % 256) == 0 && KeyDownAsync(VK_ESCAPE)) {
return searchResAddrs;
}
u8 *ptr = Memory::GetPointerUnchecked(pos);
if (memcmp(ptr, searchData.data(), searchData.size()) == 0) {
searchResAddrs.push_back(pos);
}
}
};
redraw();
}
return searchResAddrs;
};
@ -776,46 +813,16 @@ void CtrlMemView::search(bool continueSearch)
}
std::vector<u8> searchData;
if (asciiSelected)
{
for (size_t i = 0; i < searchQuery.length(); i++)
{
char c = searchQuery[i];
searchData.push_back(c);
}
} else {
size_t index = 0;
while (index < searchQuery.size())
{
if (searchQuery[index] == ' ' || searchQuery[index] == '\t')
{
index++;
continue;
}
u8 value = 0;
for (int i = 0; i < 2 && index < searchQuery.size(); i++)
{
char c = tolower(searchQuery[index++]);
if (c >= 'a' && c <= 'f')
{
value |= (c-'a'+10) << (1-i)*4;
} else if (c >= '0' && c <= '9')
{
value |= (c-'0') << (1-i)*4;
} else {
MessageBox(wnd,L"Invalid search text.",L"Error",MB_OK);
return;
}
}
searchData.push_back(value);
}
if (!ParseSearchString(searchQuery, !asciiSelected, searchData)) {
MessageBox(wnd, L"Invalid search text.", L"Error", MB_OK);
return;
}
std::vector<std::pair<u32,u32>> memoryAreas;
memoryAreas.push_back(std::pair<u32,u32>(0x04000000, 0x04200000));
memoryAreas.push_back(std::pair<u32,u32>(0x08000000, 0x0A000000));
std::vector<std::pair<u32, u32>> memoryAreas;
// Ignore the video memory mirrors.
memoryAreas.push_back(std::pair<u32,u32>(PSP_GetVidMemBase(), 0x04200000));
memoryAreas.push_back(std::pair<u32,u32>(PSP_GetKernelMemoryBase(), PSP_GetUserMemoryEnd()));
memoryAreas.push_back(std::pair<u32, u32>(PSP_GetScratchpadMemoryBase(), PSP_GetScratchpadMemoryEnd()));
searching = true;
redraw(); // so the cursor is disabled

View File

@ -18,6 +18,7 @@
//To get a class instance to be able to access it, just use getFrom(HWND wnd).
#include <cstdint>
#include <vector>
#include "Core/Debugger/DebugInterface.h"
#include "Core/Debugger/MemBlockInfo.h"
@ -60,7 +61,6 @@ class CtrlMemView
int matchAddress;
bool searching;
bool searchStringValue;
bool hasFocus;
static wchar_t szClassName[];
@ -87,7 +87,7 @@ public:
{
return debugger;
}
std::vector<u32> searchString(std::string searchQuery);
std::vector<u32> searchString(const std::string &searchQuery);
void onPaint(WPARAM wParam, LPARAM lParam);
void onVScroll(WPARAM wParam, LPARAM lParam);
void onKeyDown(WPARAM wParam, LPARAM lParam);
@ -108,5 +108,7 @@ public:
void setHighlightType(MemBlockFlags flags);
private:
bool ParseSearchString(const std::string &query, bool asHex, std::vector<uint8_t> &data);
bool redrawScheduled_ = false;
};

View File

@ -121,6 +121,7 @@ void CMemoryDlg::searchBoxRedraw(std::vector<u32> results) {
wchar_t temp[256]{};
SendMessage(srcListHdl, WM_SETREDRAW, FALSE, 0);
ListBox_ResetContent(srcListHdl);
SendMessage(srcListHdl, LB_INITSTORAGE, (WPARAM)results.size(), (LPARAM)results.size() * 22);
for (size_t i = 0; i < results.size(); i++) {
wsprintf(temp, L"0x%08X", results[i]);
int index = (int)ListBox_AddString(srcListHdl, temp);

View File

@ -310,7 +310,7 @@ BEGIN
AUTOCHECKBOX "Show Offsets",IDC_SHOWOFFSETS,300,9,55,8
COMBOBOX IDC_REGIONS,95,5,88,139,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_SEARCH_RESULTS,557,14,140,272,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_SEARCH_RESULTS,557,14,140,272,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
EDITTEXT IDC_SEARCH_BOX,397,6,100,13,ES_AUTOHSCROLL
PUSHBUTTON "Search",IDC_BUTTON_SEARCH,504,5,50,14