Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement requested debugger features #17042

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions Windows/Debugger/CtrlDisAsmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ CtrlDisAsmView::~CtrlDisAsmView()
manager.clear();
}

COLORREF scaleColor(COLORREF color, float factor)
static COLORREF scaleColor(COLORREF color, float factor)
{
unsigned char r = color & 0xFF;
unsigned char g = (color >> 8) & 0xFF;
Expand Down Expand Up @@ -315,7 +315,7 @@ void CtrlDisAsmView::assembleOpcode(u32 address, std::string defaultText)
// try to assemble the input if it failed
}

result = MIPSAsm::MipsAssembleOpcode(op.c_str(),debugger,address);
result = MIPSAsm::MipsAssembleOpcode(op.c_str(), debugger, address);
Reporting::NotifyDebugger();
if (result == true)
{
Expand All @@ -331,7 +331,6 @@ void CtrlDisAsmView::assembleOpcode(u32 address, std::string defaultText)
}
}


void CtrlDisAsmView::drawBranchLine(HDC hdc, std::map<u32,int> &addressPositions, const BranchLine &line) {
HPEN pen;
u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
Expand Down Expand Up @@ -725,7 +724,7 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam)
break;
case 'c':
case VK_INSERT:
copyInstructions(selectRangeStart, selectRangeEnd, true);
CopyInstructions(selectRangeStart, selectRangeEnd, CopyInstructionsMode::DISASM);
break;
case 'x':
disassembleToFile();
Expand Down Expand Up @@ -906,10 +905,8 @@ void CtrlDisAsmView::onMouseDown(WPARAM wParam, LPARAM lParam, int button)
redraw();
}

void CtrlDisAsmView::copyInstructions(u32 startAddr, u32 endAddr, bool withDisasm)
{
if (withDisasm == false)
{
void CtrlDisAsmView::CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode) {
if (mode != CopyInstructionsMode::DISASM) {
int instructionSize = debugger->getInstructionSize(0);
int count = (endAddr - startAddr) / instructionSize;
int space = count * 32;
Expand All @@ -918,21 +915,31 @@ void CtrlDisAsmView::copyInstructions(u32 startAddr, u32 endAddr, bool withDisas
char *p = temp, *end = temp + space;
for (u32 pos = startAddr; pos < endAddr && p < end; pos += instructionSize)
{
p += snprintf(p, end - p, "%08X", debugger->readMemory(pos));
u32 data = mode == CopyInstructionsMode::OPCODES ? debugger->readMemory(pos) : pos;
p += snprintf(p, end - p, "%08X", data);

// Don't leave a trailing newline.
if (pos + instructionSize < endAddr && p < end)
p += snprintf(p, end - p, "\r\n");
}
W32Util::CopyTextToClipboard(wnd, temp);
delete [] temp;
} else
{
} else {
std::string disassembly = disassembleRange(startAddr,endAddr-startAddr);
W32Util::CopyTextToClipboard(wnd, disassembly.c_str());
}
}

void CtrlDisAsmView::NopInstructions(u32 selectRangeStart, u32 selectRangeEnd) {
for (u32 addr = selectRangeStart; addr < selectRangeEnd; addr += 4) {
Memory::Write_U32(0, addr);
}

if (currentMIPS) {
currentMIPS->InvalidateICache(selectRangeStart, selectRangeEnd - selectRangeStart);
}
}

void CtrlDisAsmView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
{
if (button == 1)
Expand All @@ -956,14 +963,17 @@ void CtrlDisAsmView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
assembleOpcode(curAddress,"");
break;
case ID_DISASM_COPYINSTRUCTIONDISASM:
copyInstructions(selectRangeStart, selectRangeEnd, true);
CopyInstructions(selectRangeStart, selectRangeEnd, CopyInstructionsMode::DISASM);
break;
case ID_DISASM_COPYADDRESS:
{
char temp[16];
sprintf(temp,"%08X",curAddress);
W32Util::CopyTextToClipboard(wnd, temp);
}
CopyInstructions(selectRangeStart, selectRangeEnd, CopyInstructionsMode::ADDRESSES);
break;
case ID_DISASM_COPYINSTRUCTIONHEX:
CopyInstructions(selectRangeStart, selectRangeEnd, CopyInstructionsMode::OPCODES);
break;
case ID_DISASM_NOPINSTRUCTION:
NopInstructions(selectRangeStart, selectRangeEnd);
redraw();
break;
case ID_DISASM_SETPCTOHERE:
debugger->setPC(curAddress);
Expand All @@ -972,9 +982,6 @@ void CtrlDisAsmView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
case ID_DISASM_FOLLOWBRANCH:
followBranch();
break;
case ID_DISASM_COPYINSTRUCTIONHEX:
copyInstructions(selectRangeStart, selectRangeEnd, false);
break;
case ID_DISASM_RUNTOHERE:
{
SendMessage(GetParent(wnd), WM_COMMAND, ID_DEBUG_RUNTOLINE, 0);
Expand Down
9 changes: 8 additions & 1 deletion Windows/Debugger/CtrlDisAsmView.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class CtrlDisAsmView
bool dontRedraw;
bool keyTaken;

enum class CopyInstructionsMode {
OPCODES,
DISASM,
ADDRESSES,
};

void assembleOpcode(u32 address, std::string defaultText);
std::string disassembleRange(u32 start, u32 size);
void disassembleToFile();
Expand All @@ -73,7 +79,8 @@ class CtrlDisAsmView
bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData);
void updateStatusBarText();
void drawBranchLine(HDC hdc, std::map<u32, int> &addressPositions, const BranchLine &line);
void copyInstructions(u32 startAddr, u32 endAddr, bool withDisasm);
void CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode);
void NopInstructions(u32 startAddr, u32 endAddr);
std::set<std::string> getSelectedLineArguments();
void drawArguments(HDC hdc, const DisassemblyLineInfo &line, int x, int y, int textColor, const std::set<std::string> &currentArguments);

Expand Down
1 change: 1 addition & 0 deletions Windows/ppsspp.rc
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ BEGIN
MENUITEM "Rename Function...", ID_DISASM_RENAMEFUNCTION
MENUITEM "Remove Function", ID_DISASM_REMOVEFUNCTION
MENUITEM "Add Function Here", ID_DISASM_ADDFUNCTION
MENUITEM "NOP instruction(s)", ID_DISASM_NOPINSTRUCTION
END
POPUP "reglist"
BEGIN
Expand Down
1 change: 1 addition & 0 deletions Windows/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
#define ID_GEDBG_COPY_IMAGE_ALPHA 40225
#define ID_GEDBG_TRACK_PIXEL 40226
#define ID_GEDBG_TRACK_PIXEL_STOP 40227
#define ID_DISASM_NOPINSTRUCTION 40228


// Dummy option to let the buffered rendering hotkey cycle through all the options.
Expand Down