[Debugger] Add basic multi-line support to code editor

This commit is contained in:
shygoo 2020-12-17 13:30:28 -06:00
parent 3f9ac808b3
commit fdb6b25b39
3 changed files with 109 additions and 46 deletions

View File

@ -255,43 +255,6 @@ LRESULT CALLBACK CDebugCommandsView::HookProc(int nCode, WPARAM wParam, LPARAM l
return 0;
}
LRESULT CDebugCommandsView::OnOpKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
if (wParam == VK_UP)
{
m_SelectedAddress -= 4;
BeginOpEdit(m_SelectedAddress);
bHandled = TRUE;
}
else if (wParam == VK_DOWN)
{
m_SelectedAddress += 4;
BeginOpEdit(m_SelectedAddress);
bHandled = TRUE;
}
else if (wParam == VK_RETURN)
{
wchar_t text[256] = { 0 };
m_OpEdit.GetWindowText(text, (sizeof(text) / sizeof(text[0])) - 1);
uint32_t op;
bool bValid = CAssembler::AssembleLine(stdstr().FromUTF16(text).c_str(), &op, m_SelectedAddress);
if (bValid)
{
m_OpEdit.SetWindowText(L"");
EditOp(m_SelectedAddress, op);
m_SelectedAddress += 4;
BeginOpEdit(m_SelectedAddress);
}
bHandled = TRUE;
}
else if (wParam == VK_ESCAPE)
{
EndOpEdit();
bHandled = TRUE;
}
return 1;
}
void CDebugCommandsView::ClearBranchArrows()
{
m_BranchArrows.clear();
@ -1628,7 +1591,7 @@ BOOL CDebugCommandsView::IsOpEdited(uint32_t address)
return FALSE;
}
void CDebugCommandsView::EditOp(uint32_t address, uint32_t op)
void CDebugCommandsView::EditOp(uint32_t address, uint32_t op, bool bRefresh)
{
uint32_t currentOp;
if (!m_Debugger->DebugLoad_VAddr(address, currentOp))
@ -1648,8 +1611,11 @@ void CDebugCommandsView::EditOp(uint32_t address, uint32_t op)
m_EditedOps.push_back({ address, currentOp });
}
if (bRefresh)
{
ShowAddress(m_StartAddress, TRUE);
}
}
void CDebugCommandsView::RestoreOp(uint32_t address)
{
@ -1704,13 +1670,107 @@ void CDebugCommandsView::ToggleHistoryButtons()
// Opcode editor
LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
if (wParam == VK_UP)
{
m_SelectedAddress -= 4;
BeginOpEdit(m_SelectedAddress);
bHandled = TRUE;
}
else if (wParam == VK_DOWN)
{
m_SelectedAddress += 4;
BeginOpEdit(m_SelectedAddress);
bHandled = TRUE;
}
else if (wParam == VK_RETURN)
{
wchar_t text[256] = { 0 };
m_OpEdit.GetWindowText(text, (sizeof(text) / sizeof(text[0])) - 1);
uint32_t op;
bool bValid = CAssembler::AssembleLine(stdstr().FromUTF16(text).c_str(), &op, m_SelectedAddress);
if (bValid)
{
m_OpEdit.SetWindowText(L"");
EditOp(m_SelectedAddress, op);
m_SelectedAddress += 4;
BeginOpEdit(m_SelectedAddress);
}
bHandled = TRUE;
}
else if (wParam == VK_ESCAPE)
{
EndOpEdit();
bHandled = TRUE;
}
return 1;
}
LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/)
{
// handle multiline input
size_t length = m_OpEdit.GetWindowTextLength();
wchar_t* text = new wchar_t[length + 1];
m_OpEdit.GetWindowText(text, length + 1);
if (wcschr(text, L'\n') == NULL)
{
delete[] text;
return FALSE;
}
EndOpEdit();
for (size_t i = 0; i < length; i++)
{
if (text[i] == '\r')
{
text[i] = '\n';
}
}
wchar_t *tokctx;
wchar_t *line = wcstok_s(text, L"\n", &tokctx);
while (line != NULL)
{
if (wcslen(line) != 0)
{
uint32_t op;
bool bValid = CAssembler::AssembleLine(stdstr().FromUTF16(line).c_str(), &op, m_SelectedAddress);
if (bValid)
{
EditOp(m_SelectedAddress, op, false);
m_SelectedAddress += 4;
}
else
{
ShowAddress(m_StartAddress, TRUE);
BeginOpEdit(m_SelectedAddress);
m_OpEdit.SetWindowText(line);
delete[] text;
return FALSE;
}
}
line = wcstok_s(NULL, L"\n", &tokctx);
}
ShowAddress(m_StartAddress, TRUE);
BeginOpEdit(m_SelectedAddress);
delete[] text;
return FALSE;
}
LRESULT CEditOp::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (m_CommandsWindow == NULL)
{
return FALSE;
}
return m_CommandsWindow->OnOpKeyDown(uMsg, wParam, lParam, bHandled);
return m_CommandsWindow->OnOpEditKeyDown(uMsg, wParam, lParam, bHandled);
}
void CEditOp::SetCommandsWindow(CDebugCommandsView* commandsWindow)

View File

@ -121,11 +121,14 @@ private:
COMMAND_HANDLER(ID_POPUPMENU_VIEWMEMORY, BN_CLICKED, OnPopupmenuViewMemory)
COMMAND_HANDLER(ID_POPUPMENU_TOGGLEBP, BN_CLICKED, OnPopupmenuToggleBP)
COMMAND_HANDLER(ID_POPUPMENU_CLEARBPS, BN_CLICKED, OnPopupmenuClearBP)
COMMAND_HANDLER(IDC_OP_EDIT, EN_CHANGE, OnOpEditChanged)
NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_CLICK, OnCommandListClicked)
NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_DBLCLK, OnCommandListDblClicked)
NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_RCLICK, OnCommandListRightClicked)
NOTIFY_HANDLER_EX(IDC_REG_TABS, TCN_SELCHANGE, OnRegisterTabChange)
NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_CUSTOMDRAW, OnCustomDrawList)
MSG_WM_DESTROY(OnDestroy)
CHAIN_MSG_MAP(CDialogResize<CDebugCommandsView>)
MSG_WM_EXITSIZEMOVE(OnExitSizeMove)
@ -207,8 +210,8 @@ private:
LRESULT OnPopupmenuToggleBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled);
LRESULT OnPopupmenuClearBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled);
LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
LRESULT OnOpKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnOpEditChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled);
LRESULT OnOpEditKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCommandListClicked(NMHDR* pNMHDR);
LRESULT OnCommandListDblClicked(NMHDR* pNMHDR);
@ -219,7 +222,7 @@ private:
void OnExitSizeMove(void);
void ClearEditedOps();
void EditOp(uint32_t address, uint32_t op);
void EditOp(uint32_t address, uint32_t op, bool bRefresh = true);
void RestoreOp(uint32_t address);
void RestoreAllOps();
BOOL IsOpEdited(uint32_t address);

View File

@ -652,7 +652,7 @@ BEGIN
CONTROL "",IDC_CMD_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_OWNERDRAWFIXED | LVS_NOSCROLL | LVS_NOSORTHEADER | WS_TABSTOP,0,0,284,327
LISTBOX IDC_BP_LIST,422,17,88,42,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
GROUPBOX "",IDC_OPCODE_BOX,298,14,119,45,0,WS_EX_TRANSPARENT
EDITTEXT IDC_OP_EDIT,458,51,59,12,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_VISIBLE | NOT WS_BORDER
EDITTEXT IDC_OP_EDIT,458,51,59,12,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_VISIBLE | NOT WS_BORDER
SCROLLBAR IDC_SCRL_BAR,284,0,12,327,SBS_VERT
PUSHBUTTON "Copy Tab Registers",IDC_COPYTABREGISTERS_BTN,298,313,70,13
PUSHBUTTON "Copy All Registers",IDC_COPYALLREGISTERS_BTN,370,313,70,13