From 5888929cacd49e19b9b7374bffea342c6cd5504b Mon Sep 17 00:00:00 2001 From: shygoo Date: Thu, 17 Dec 2020 10:50:09 -0600 Subject: [PATCH 1/3] [Debugger] Fix execution breakpoint toggle from context menu --- .../UserInterface/Debugger/Debugger-Commands.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp index 9673c4370..663e828d7 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp @@ -1286,7 +1286,14 @@ LRESULT CDebugCommandsView::OnPopupmenuViewMemory(WORD /*wNotifyCode*/, WORD /*w LRESULT CDebugCommandsView::OnPopupmenuToggleBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) { - m_Breakpoints->EBPToggle(m_SelectedAddress); + if (m_Breakpoints->ExecutionBPExists(m_SelectedAddress)) + { + m_Breakpoints->RemoveExecution(m_SelectedAddress); + } + else + { + m_Breakpoints->AddExecution(m_SelectedAddress); + } ShowAddress(m_StartAddress, TRUE); return FALSE; } From 3f9ac808b3ce14c80caec341fe705d8c6b8fd545 Mon Sep 17 00:00:00 2001 From: shygoo Date: Thu, 17 Dec 2020 10:58:42 -0600 Subject: [PATCH 2/3] [Debugger] Add socket.close to js api doc --- apidoc.htm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apidoc.htm b/apidoc.htm index fe51e4481..9bfab52c7 100644 --- a/apidoc.htm +++ b/apidoc.htm @@ -121,8 +121,8 @@ span.tag2 {
mem.u8|u16|u32|s8|s16|s32|float|double
- Arrays for reading and modifying values in virtual memory. - Virtual addresses are always used for indeces regardless of type size. + Arrays for reading and writing values in virtual memory. + Virtual addresses are always used for indices regardless of type size.
 var addr_power = 0x8033B21E
 
@@ -281,7 +281,7 @@ events.onexec(0x802CB1C0, function()
 })
 
-events.onexec(ADDR_ANY, function(pc))
+events.onexec(ADDR_ANY, function(pc)
 {
     // Log every step!
     console.log('CPU is executing 0x' + pc.hex())
@@ -843,6 +843,12 @@ server.on('connection', function(socket)
 			Writes data to the socket.
 		
+
+
socket.close()
+
+ Closes the socket. +
+
socket.on('data', callback)
@@ -868,9 +874,9 @@ server.on('connection', function(socket)
 ADDR_ANY              0x00000000 : 0xFFFFFFFF Any 32-bit address
 
-ADDR_ANY_KUSEG        0x00000000 : 0x7FFFFFFF  MIPS user mode TLB mapped segment
-ADDR_ANY_KSEG0        0x80000000 : 0x9FFFFFFF  MIPS cached unmapped segment
-ADDR_ANY_KSEG1        0xA0000000 : 0xBFFFFFFF  MIPS uncached unmapped segment
+ADDR_ANY_KUSEG        0x00000000 : 0x7FFFFFFF MIPS user mode TLB mapped segment
+ADDR_ANY_KSEG0        0x80000000 : 0x9FFFFFFF MIPS cached unmapped segment
+ADDR_ANY_KSEG1        0xA0000000 : 0xBFFFFFFF MIPS uncached unmapped segment
 ADDR_ANY_KSEG2        0xC0000000 : 0xFFFFFFFF MIPS kernel mode TLB mapped segment
 
 ADDR_ANY_RDRAM        0x80000000 : 0x807FFFFF Cached RDRAM

From fdb6b25b3919a1baba8dac1dfc32dffeb8936670 Mon Sep 17 00:00:00 2001
From: shygoo 
Date: Thu, 17 Dec 2020 13:30:28 -0600
Subject: [PATCH 3/3] [Debugger] Add basic multi-line support to code editor

---
 .../Debugger/Debugger-Commands.cpp            | 140 +++++++++++++-----
 .../Debugger/Debugger-Commands.h              |  13 +-
 Source/Project64/UserInterface/UIResources.rc |   2 +-
 3 files changed, 109 insertions(+), 46 deletions(-)

diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp
index 663e828d7..60fc8dcf9 100644
--- a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp
+++ b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp
@@ -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,7 +1611,10 @@ void CDebugCommandsView::EditOp(uint32_t address, uint32_t op)
         m_EditedOps.push_back({ address, currentOp });
     }
 
-    ShowAddress(m_StartAddress, TRUE);
+    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)
diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Commands.h b/Source/Project64/UserInterface/Debugger/Debugger-Commands.h
index 756122547..a8d500d2e 100644
--- a/Source/Project64/UserInterface/Debugger/Debugger-Commands.h
+++ b/Source/Project64/UserInterface/Debugger/Debugger-Commands.h
@@ -60,7 +60,7 @@ private:
         MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
         MESSAGE_HANDLER(WM_KEYUP, OnKeyUp)
         MESSAGE_HANDLER(WM_CHAR, OnKeyUp)
-        END_MSG_MAP()
+    END_MSG_MAP()
 
 public:
     void SetCommandsWindow(CDebugCommandsView* commandsWindow);
@@ -120,12 +120,15 @@ private:
         COMMAND_HANDLER(ID_POPUPMENU_FOLLOWJUMP, BN_CLICKED, OnPopupmenuFollowJump)
         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(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)
         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);
diff --git a/Source/Project64/UserInterface/UIResources.rc b/Source/Project64/UserInterface/UIResources.rc
index d3aab566c..22bd49477 100644
--- a/Source/Project64/UserInterface/UIResources.rc
+++ b/Source/Project64/UserInterface/UIResources.rc
@@ -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