This commit is contained in:
Summate 2024-03-21 20:58:08 +10:30 committed by GitHub
commit f0a49e3208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 295 additions and 0 deletions

View File

@ -59,6 +59,7 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="UserInterface\About.cpp" /> <ClCompile Include="UserInterface\About.cpp" />
<ClCompile Include="UserInterface\Debugger\CPULog.cpp" /> <ClCompile Include="UserInterface\Debugger\CPULog.cpp" />
<ClCompile Include="UserInterface\Debugger\Debugger-CopyCommands.cpp" />
<ClCompile Include="UserInterface\Debugger\Debugger-CPULogView.cpp" /> <ClCompile Include="UserInterface\Debugger\Debugger-CPULogView.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="Plugins\PluginList.cpp" /> <ClCompile Include="Plugins\PluginList.cpp" />
@ -156,6 +157,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="UserInterface\About.h" /> <ClInclude Include="UserInterface\About.h" />
<ClInclude Include="UserInterface\Debugger\CPULog.h" /> <ClInclude Include="UserInterface\Debugger\CPULog.h" />
<ClInclude Include="UserInterface\Debugger\Debugger-CopyCommands.h" />
<ClInclude Include="UserInterface\Debugger\Debugger-CPULogView.h" /> <ClInclude Include="UserInterface\Debugger\Debugger-CPULogView.h" />
<ClInclude Include="N64System.h" /> <ClInclude Include="N64System.h" />
<ClInclude Include="Settings\GuiSettings.h" /> <ClInclude Include="Settings\GuiSettings.h" />

View File

@ -333,6 +333,9 @@
<ClCompile Include="UserInterface\Debugger\ScriptWorker.cpp"> <ClCompile Include="UserInterface\Debugger\ScriptWorker.cpp">
<Filter>Source Files\User Interface Source\Debugger Source</Filter> <Filter>Source Files\User Interface Source\Debugger Source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="UserInterface\Debugger\Debugger-CopyCommands.cpp">
<Filter>Source Files\User Interface Source\Debugger Source</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="UserInterface\resource.h"> <ClInclude Include="UserInterface\resource.h">
@ -596,6 +599,9 @@
<ClInclude Include="UserInterface\Debugger\ScriptAPI\N64Image.h"> <ClInclude Include="UserInterface\Debugger\ScriptAPI\N64Image.h">
<Filter>Header Files\User Interface Headers\Debugger Headers\ScriptAPI</Filter> <Filter>Header Files\User Interface Headers\Debugger Headers\ScriptAPI</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="UserInterface\Debugger\Debugger-CopyCommands.h">
<Filter>Header Files\User Interface Headers\Debugger Headers</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="res\divider.cur"> <None Include="res\divider.cur">

View File

@ -659,6 +659,133 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput
m_CommandList.SetRedraw(TRUE); m_CommandList.SetRedraw(TRUE);
} }
void CDebugCommandsView::CopyCommands(uint32_t address, uint32_t count)
{
const int maximumMnemonicLength = 7 + 1; // The + 1 gets us a space after the mnemonic
std::string buffer;
std::string newline = "\r\n";
std::string noteBuffer = " "; // Used to distance the note from the args visually
bool any = false;
for (int i = 0; i < count; i++)
{
uint32_t opAddr = address + i * 4;
COpInfo OpInfo;
R4300iOpcode & OpCode = OpInfo.m_OpCode;
if (!m_Debugger->DebugLoad_VAddr(opAddr, OpCode.Value))
{
// Not sure what to do with this
continue;
}
if (any) buffer.append(newline);
any = true;
char addrStr[10];
sprintf(addrStr, "%08X ", opAddr);
buffer.append(addrStr);
R4300iInstruction Instruction(opAddr, OpCode.Value);
std::string cmdArgs = Instruction.Param();
CSymbol jalSymbol;
// Show subroutine symbol name for JAL target
if (OpCode.op == R4300i_JAL)
{
uint32_t targetAddr = (m_StartAddress & 0xF0000000) | (OpCode.target << 2);
if (m_Debugger->SymbolTable()->GetSymbolByAddress(targetAddr, &jalSymbol))
{
cmdArgs = jalSymbol.m_Name;
}
}
// Detect reads and writes to mapped registers, cart header data, etc.
const char * annotation = nullptr;
bool bLoadStoreAnnotation = false;
CSymbol memSymbol;
if (OpInfo.IsLoadStoreCommand())
{
for (int offset = -4; offset > -24; offset -= 4)
{
R4300iOpcode OpCodeTest;
if (!m_Debugger->DebugLoad_VAddr(opAddr + offset, OpCodeTest.Value))
{
break;
}
if (OpCodeTest.op != R4300i_LUI)
{
continue;
}
if (OpCodeTest.rt != OpCode.rs)
{
continue;
}
uint32_t memAddr = (OpCodeTest.immediate << 16) + (short)OpCode.offset;
if (m_Debugger->SymbolTable()->GetSymbolByAddress(memAddr, &memSymbol))
{
annotation = memSymbol.m_Name;
}
else
{
annotation = GetDataAddressNotes(memAddr);
}
break;
}
}
if (annotation == nullptr)
{
annotation = GetCodeAddressNotes(opAddr);
}
else
{
bLoadStoreAnnotation = true;
}
std::string instruction = Instruction.Name();
while (instruction.length() < maximumMnemonicLength)
{
instruction.append(" ");
}
buffer.append(instruction);
buffer.append(cmdArgs);
// Show routine symbol name for this address
CSymbol pcSymbol;
if (m_Debugger->SymbolTable()->GetSymbolByAddress(opAddr, &pcSymbol))
{
buffer.append(noteBuffer);
buffer.append(pcSymbol.m_Name);
}
else if (annotation != nullptr)
{
const char * annotationFormat = bLoadStoreAnnotation ? "// (%s)" : "// %s";
buffer.append(noteBuffer);
buffer.append(stdstr_f(annotationFormat, annotation));
}
}
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, buffer.length() + 1);
strncpy((char *)GlobalLock(hMem), buffer.c_str(), buffer.length());
GlobalUnlock(hMem);
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
}
// Highlight command list items and draw branch arrows // Highlight command list items and draw branch arrows
LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR * pNMHDR) LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR * pNMHDR)
{ {
@ -1199,6 +1326,12 @@ LRESULT CDebugCommandsView::OnPopupmenuInsertNOP(WORD /*wNotifyCode*/, WORD /*wI
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuCopyCommands(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{
m_CopyCommandsDlg.DoModal(m_Debugger, m_SelectedAddress);
return FALSE;
}
LRESULT CDebugCommandsView::OnPopupmenuRestore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuRestore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
RestoreOp(m_SelectedAddress); RestoreOp(m_SelectedAddress);

View File

@ -77,6 +77,7 @@ public:
virtual ~CDebugCommandsView(void); virtual ~CDebugCommandsView(void);
void ShowAddress(uint32_t address, bool top, bool bUserInput = false); void ShowAddress(uint32_t address, bool top, bool bUserInput = false);
void CopyCommands(uint32_t address, uint32_t count);
void ShowPIRegTab(); void ShowPIRegTab();
void Reset(); void Reset();
@ -110,6 +111,7 @@ private:
COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel); COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel);
COMMAND_HANDLER(ID_POPUPMENU_EDIT, BN_CLICKED, OnPopupmenuEdit); COMMAND_HANDLER(ID_POPUPMENU_EDIT, BN_CLICKED, OnPopupmenuEdit);
COMMAND_HANDLER(ID_POPUPMENU_INSERTNOP, BN_CLICKED, OnPopupmenuInsertNOP); COMMAND_HANDLER(ID_POPUPMENU_INSERTNOP, BN_CLICKED, OnPopupmenuInsertNOP);
COMMAND_HANDLER(ID_POPUPMENU_COPY_COMMANDS, BN_CLICKED, OnPopupmenuCopyCommands);
COMMAND_HANDLER(ID_POPUPMENU_RESTORE, BN_CLICKED, OnPopupmenuRestore); COMMAND_HANDLER(ID_POPUPMENU_RESTORE, BN_CLICKED, OnPopupmenuRestore);
COMMAND_HANDLER(ID_POPUPMENU_RESTOREALL, BN_CLICKED, OnPopupmenuRestoreAll); COMMAND_HANDLER(ID_POPUPMENU_RESTOREALL, BN_CLICKED, OnPopupmenuRestoreAll);
COMMAND_HANDLER(ID_POPUPMENU_ADDSYMBOL, BN_CLICKED, OnPopupmenuAddSymbol); COMMAND_HANDLER(ID_POPUPMENU_ADDSYMBOL, BN_CLICKED, OnPopupmenuAddSymbol);
@ -205,6 +207,7 @@ private:
LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
LRESULT OnPopupmenuEdit(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnPopupmenuEdit(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
LRESULT OnPopupmenuInsertNOP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnPopupmenuInsertNOP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
LRESULT OnPopupmenuCopyCommands(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
LRESULT OnPopupmenuRestore(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnPopupmenuRestore(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
LRESULT OnPopupmenuRestoreAll(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnPopupmenuRestoreAll(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
LRESULT OnPopupmenuAddSymbol(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnPopupmenuAddSymbol(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled);
@ -265,6 +268,7 @@ private:
CAddBreakpointDlg m_AddBreakpointDlg; CAddBreakpointDlg m_AddBreakpointDlg;
CAddSymbolDlg m_AddSymbolDlg; CAddSymbolDlg m_AddSymbolDlg;
CCopyCommandsDlg m_CopyCommandsDlg;
uint32_t m_StartAddress; uint32_t m_StartAddress;
CEditNumber32 m_PCEdit; CEditNumber32 m_PCEdit;

View File

@ -0,0 +1,87 @@
#include "stdafx.h"
#include "DebuggerUI.h"
#include "Symbols.h"
LRESULT CCopyCommandsDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{
CenterWindow();
m_AddressEdit.Attach(GetDlgItem(IDC_ADDR_EDIT));
m_AddressEdit.SetDisplayType(CEditNumber32::DisplayHex);
m_CountEdit.Attach(GetDlgItem(IDC_COUNT_EDIT));
m_CountEdit.SetDisplayType(CEditNumber32::DisplayDec);
m_AddressEdit.SetWindowText(L"");
m_AddressEdit.SetFocus();
if (m_bHaveAddress)
{
m_AddressEdit.SetValue(m_InitAddress, DisplayMode::ZeroExtend);
m_CountEdit.SetFocus();
}
m_CountEdit.SetValue(m_bHaveCount ? m_InitCount : 1, DisplayMode::None);
return FALSE;
}
LRESULT CCopyCommandsDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{
switch (wID)
{
case IDCANCEL:
EndDialog(0);
break;
case IDOK:
int addrLen = m_AddressEdit.GetWindowTextLength();
if (!addrLen)
{
MessageBox(L"Address required", L"Error", MB_OK);
return 0;
}
int countLen = m_CountEdit.GetWindowTextLength();
if (!countLen)
{
MessageBox(L"Count required", L"Error", MB_OK);
return 0;
}
uint32_t address = m_AddressEdit.GetValue();
uint32_t count = m_CountEdit.GetValue();
m_Debugger->CopyCommands(address, count);
EndDialog(0);
break;
}
return 0;
}
INT_PTR CCopyCommandsDlg::DoModal(CDebuggerUI * debugger)
{
m_Debugger = debugger;
m_bHaveAddress = false;
m_bHaveCount = false;
return CDialogImpl<CCopyCommandsDlg>::DoModal();
}
INT_PTR CCopyCommandsDlg::DoModal(CDebuggerUI * debugger, uint32_t initAddress)
{
m_Debugger = debugger;
m_bHaveAddress = true;
m_bHaveCount = false;
m_InitAddress = initAddress;
return CDialogImpl<CCopyCommandsDlg>::DoModal();
}
INT_PTR CCopyCommandsDlg::DoModal(CDebuggerUI * debugger, uint32_t initAddress, uint32_t initCount)
{
m_Debugger = debugger;
m_bHaveAddress = true;
m_bHaveCount = true;
m_InitAddress = initAddress;
m_InitCount = initCount;
return CDialogImpl<CCopyCommandsDlg>::DoModal();
}

View File

@ -0,0 +1,40 @@
#pragma once
class CCopyCommandsDlg : public CDialogImpl<CCopyCommandsDlg>
{
public:
enum
{
IDD = IDD_Debugger_CopyCommands
};
INT_PTR DoModal(CDebuggerUI * debugger);
INT_PTR DoModal(CDebuggerUI * debugger, uint32_t initAddress);
INT_PTR DoModal(CDebuggerUI * debugger, uint32_t initAddress, uint32_t initCount);
private:
CDebuggerUI * m_Debugger;
bool m_bHaveAddress;
bool m_bHaveCount;
uint32_t m_InitAddress;
uint32_t m_InitCount;
CEditNumber32 m_AddressEdit;
CEditNumber32 m_CountEdit;
LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/);
LRESULT OnDestroy(void)
{
return 0;
}
BEGIN_MSG_MAP_EX(CCopyCommandsDlg)
{
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog);
COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked);
MSG_WM_DESTROY(OnDestroy);
}
END_MSG_MAP()
};

View File

@ -786,6 +786,11 @@ void CDebuggerUI::WaitForStep(void)
g_Settings->SaveBool(Debugger_WaitingForStep, false); g_Settings->SaveBool(Debugger_WaitingForStep, false);
} }
void CDebuggerUI::CopyCommands(uint32_t address, uint32_t count)
{
m_CommandsView->CopyCommands(address, count);
}
void CDebuggerUI::StartAutorunScripts(void) void CDebuggerUI::StartAutorunScripts(void)
{ {
if (m_ScriptSystem == nullptr) if (m_ScriptSystem == nullptr)

View File

@ -5,6 +5,7 @@
#include "DebugDialog.h" #include "DebugDialog.h"
#include "Debugger-AddBreakpoint.h" #include "Debugger-AddBreakpoint.h"
#include "Debugger-AddSymbol.h" #include "Debugger-AddSymbol.h"
#include "Debugger-CopyCommands.h"
#include "Debugger-CPULogView.h" #include "Debugger-CPULogView.h"
#include "Debugger-Commands.h" #include "Debugger-Commands.h"
#include "Debugger-DMALogView.h" #include "Debugger-DMALogView.h"

View File

@ -57,6 +57,7 @@ public:
void OpenCPULogWindow(void); void OpenCPULogWindow(void);
void Debug_RefreshCPULogWindow(void); void Debug_RefreshCPULogWindow(void);
void OpenExcBreakpointsWindow(void); void OpenExcBreakpointsWindow(void);
void CopyCommands(uint32_t address, uint32_t count);
void StartAutorunScripts(); void StartAutorunScripts();

View File

@ -911,6 +911,18 @@ BEGIN
LTEXT "Description",IDC_STATIC,6,30,42,8 LTEXT "Description",IDC_STATIC,6,30,42,8
END END
IDD_Debugger_CopyCommands DIALOGEX 0, 0, 110, 55
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Copy Commands"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_ADDR_EDIT,5,14,45,13,ES_UPPERCASE | ES_AUTOHSCROLL
EDITTEXT IDC_COUNT_EDIT,53,14,49,12, ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,65,35,40,14
LTEXT "Start Address",IDC_STATIC,5,4,31,10
LTEXT "Count",IDC_STATIC,53,4,30,9
END
IDD_Debugger_DMALog DIALOGEX 0, 0, 309, 215 IDD_Debugger_DMALog DIALOGEX 0, 0, 309, 215
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "DMA Log" CAPTION "DMA Log"
@ -2048,6 +2060,7 @@ BEGIN
MENUITEM "Add symbol...", ID_POPUPMENU_ADDSYMBOL MENUITEM "Add symbol...", ID_POPUPMENU_ADDSYMBOL
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Replace with NOP", ID_POPUPMENU_INSERTNOP MENUITEM "Replace with NOP", ID_POPUPMENU_INSERTNOP
MENUITEM "Copy commands...", ID_POPUPMENU_COPY_COMMANDS
MENUITEM "Edit code", ID_POPUPMENU_EDIT MENUITEM "Edit code", ID_POPUPMENU_EDIT
MENUITEM "Restore code", ID_POPUPMENU_RESTORE MENUITEM "Restore code", ID_POPUPMENU_RESTORE
MENUITEM "Restore all code", ID_POPUPMENU_RESTOREALL MENUITEM "Restore all code", ID_POPUPMENU_RESTOREALL

View File

@ -81,6 +81,7 @@
#define IDD_Settings_GameDiskDrive 217 #define IDD_Settings_GameDiskDrive 217
#define IDD_Enhancement_Plugins 218 #define IDD_Enhancement_Plugins 218
#define IDD_Debugger_ScriptsAutorun 225 #define IDD_Debugger_ScriptsAutorun 225
#define IDD_Debugger_CopyCommands 230
#define IDC_MENU_ITEM_TEXT 1000 #define IDC_MENU_ITEM_TEXT 1000
#define IDC_CLOSE_BUTTON 1001 #define IDC_CLOSE_BUTTON 1001
#define IDC_LIST2 1003 #define IDC_LIST2 1003
@ -861,6 +862,7 @@
#define IDC_RDRAM_SIZE_KNOWN 1738 #define IDC_RDRAM_SIZE_KNOWN 1738
#define IDC_MEMORY_SIZE_UNKOWN_TEXT 1739 #define IDC_MEMORY_SIZE_UNKOWN_TEXT 1739
#define IDC_MEMORY_SIZE_KNOWN_TEXT 1740 #define IDC_MEMORY_SIZE_KNOWN_TEXT 1740
#define IDC_COUNT_EDIT 1741
#define ID_POPUPMENU_PLAYGAMEWITHDISK 40008 #define ID_POPUPMENU_PLAYGAMEWITHDISK 40008
#define ID_POPUPMENU_ADDSYMBOL 40013 #define ID_POPUPMENU_ADDSYMBOL 40013
#define ID_POPUPMENU_VIEWDISASM 40017 #define ID_POPUPMENU_VIEWDISASM 40017
@ -871,6 +873,7 @@
#define ID_POPUP_RUN 40024 #define ID_POPUP_RUN 40024
#define ID_POPUP_STOP 40025 #define ID_POPUP_STOP 40025
#define ID_POPUPMENU_INSERTNOP 40026 #define ID_POPUPMENU_INSERTNOP 40026
#define ID_POPUPMENU_COPY_COMMANDS 40200
#define ID_POPUPMENU_RESTORE 40027 #define ID_POPUPMENU_RESTORE 40027
#define ID_POPUPMENU_RESTOREALL 40029 #define ID_POPUPMENU_RESTOREALL 40029
#define ID_POPUPMENU_EDIT 40030 #define ID_POPUPMENU_EDIT 40030