From 7c68969ae41c4a5dcc25fd1a82af030e860b7dac Mon Sep 17 00:00:00 2001 From: AndrweCottrell Date: Wed, 6 Apr 2022 09:25:44 +1000 Subject: [PATCH 1/3] Add support for address being either an address or a variable. --- MemoryPanel.cpp | 128 +++++++++++++++++++++++++++++++----------------- MemoryPanel.h | 2 +- MemoryPanel.xrc | 8 +-- 3 files changed, 89 insertions(+), 49 deletions(-) diff --git a/MemoryPanel.cpp b/MemoryPanel.cpp index b95dc5e..1cfea65 100644 --- a/MemoryPanel.cpp +++ b/MemoryPanel.cpp @@ -19,17 +19,17 @@ MemoryPanel::MemoryPanel(wxWindow* parent) { //(*Initialize(MemoryPanel) wxXmlResource::Get()->LoadObject(this,parent,_T("MemoryPanel"),_T("wxPanel")); - StaticText1 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT1")); - m_Address = (wxTextCtrl*)FindWindow(XRCID("ID_TEXTCTRL1")); - StaticText2 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT2")); - m_Size = (wxTextCtrl*)FindWindow(XRCID("ID_TEXTCTRL2")); + StaticText1 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT_ADDRESS")); + m_Address = (wxTextCtrl*)FindWindow(XRCID("ID_TEXTCTRL_ADDRESS")); + StaticText2 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT_SIZE")); + m_Size = (wxTextCtrl*)FindWindow(XRCID("ID_TEXTCTRL_SIZE")); m_ByteOutput = (wxTextCtrl*)FindWindow(XRCID("ID_TEXTBYTE")); m_AchiiOutput = (wxTextCtrl*)FindWindow(XRCID("ID_TEXTASCII")); SplitterWindow1 = (wxSplitterWindow*)FindWindow(XRCID("ID_SPLITTERWINDOW1")); ScrollBar1 = (wxScrollBar*)FindWindow(XRCID("ID_SCROLLBAR1")); - Connect(XRCID("ID_TEXTCTRL1"),wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&MemoryPanel::OnTextEnter); - Connect(XRCID("ID_TEXTCTRL2"),wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&MemoryPanel::OnTextEnter); + Connect(XRCID("ID_TEXTCTRL_ADDRESS"),wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&MemoryPanel::OnTextEnter); + Connect(XRCID("ID_TEXTCTRL_SIZE"),wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&MemoryPanel::OnTextEnter); //*) m_ByteOutput->SetFont( wxFont(9, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL) ); @@ -57,21 +57,25 @@ void MemoryPanel::OnTextEnter(wxCommandEvent& event) dbg->DeleteWatch(m_watch); } - uint64_t addr = 0; - uint64_t size = 0; - try + m_sAddress = m_Address->GetValue(); + if (m_sAddress.IsEmpty()) { - addr = std::stoull(std::string(m_Address->GetValue().ToUTF8()), 0, 0); - size = std::stoull(std::string(m_Size->GetValue().ToUTF8()), 0, 0); - } catch (...) + m_ByteOutput->SetValue("Address is invalid..."); + } + else { - m_ByteOutput->SetValue("Size or Address are invalid..."); + wxString sSize = m_Size->GetValue(); + uint64_t llSize; + if (sSize.ToULongLong(&llSize, 10)) + { + m_watch = dbg->AddMemoryRange(m_sAddress, llSize, true); + dbg->UpdateWatch(m_watch); + } + else + { + m_ByteOutput->SetValue("Size is invalid..."); + } } - - m_addr = addr; - - m_watch = dbg->AddMemoryRange( m_addr , size, wxEmptyString, true ); - dbg->UpdateWatch(m_watch); } } @@ -95,8 +99,6 @@ void MemoryPanel::DebuggerCursorChanged() void MemoryPanel::UpdatePanel() { - wxString memory; - wxString ascii; wxString val; @@ -104,42 +106,80 @@ void MemoryPanel::UpdatePanel() return; // WTF is going on? m_watch->GetValue(val); + if (m_watch->GetIsValueErrorMessage()) + { + m_ByteOutput->SetValue(val); + m_AchiiOutput->SetValue(val); + ScrollBar1->SetRange(1); + return; + } + + wxString memory = wxEmptyString; + wxString ascii = wxEmptyString; + + uint64_t llAddress; + wxString sAddress = m_watch->GetAddress(); + sAddress.ToULongLong(&llAddress, 16); - wxCharBuffer buff = val.To8BitData(); - memory << wxT(" "); - ascii << wxT(" "); - for(size_t i = 0; i < 32; ++i) +#if wxCHECK_VERSION(3, 1, 5) + if (wxPlatformInfo::Get().GetBitness() == wxBITNESS_64) +#else + if (wxPlatformInfo::Get().GetArchitecture() == wxARCH_64) +#endif { - memory << wxString::Format(wxT("%02x "),(unsigned int)(0xFF&i)); - ascii << wxString::Format(wxT("%02x "),(unsigned int)(0xFF&i)); - } - memory << wxT("\n"); - memory << wxString::Format(wxT("0x%08llx "),(m_addr)); - ascii << wxT("\n"); - ascii << wxString::Format(wxT("0x%08llx "),(m_addr)); + memory << wxString::Format("%#018llx ", llAddress); // 18 = 0x + 16 digits + ascii << wxString::Format("%#018llx ", llAddress); // 18 = 0x + 16 digits + } + else + { + memory << wxString::Format("%#10llx ", llAddress); // 10 = 0x + 8 digits + ascii << wxString::Format("%#10llx ", llAddress); // 10 = 0x + 8 digits + } + wxString hBuff; + long lBuff; int line = 1; - for(size_t i = 0; i < val.size(); ++i) { - char tmp = buff[i]; - memory << wxString::Format(wxT("%02x "),(unsigned int)(0xFF&tmp)); - if(buff[i] > 31 && buff[i] < 126 && buff[i] != '\n') - ascii << wxString::Format(wxT("%2c "), buff[i]); - else if (buff[i] == '\n') - ascii << wxT("\\n "); + hBuff = val.Mid(i*2,2); + if (!hBuff.ToLong(&lBuff, 16)) + { + lBuff = 0; + } + memory << hBuff << ' '; + if(lBuff > 31 && lBuff < 126 && lBuff != '\n') + { + ascii << wxString::Format("%2c ", lBuff); + } + else if (lBuff == '\n') + { + ascii << "\\n "; + } else + { ascii << wxString::FromUTF8(u8"·· "); + } - - if((i+1) % 32 == 0) + if ((i+1) % 32 == 0) { - memory << wxT("\n"); - ascii << wxT("\n"); - memory << wxString::Format(wxT("0x%08llx "),(m_addr + line * 32)); - ascii << wxString::Format(wxT("0x%08llx "),(m_addr + line * 32)); + uint64_t m_llAddressDisplay = llAddress + line * 32; +#if wxCHECK_VERSION(3, 1, 5) + if (wxPlatformInfo::Get().GetBitness() == wxBITNESS_64) +#else + if (wxPlatformInfo::Get().GetArchitecture() == wxARCH_64) +#endif + { + memory << wxString::Format("\n%#018llx ", m_llAddressDisplay); // 18 = 0x + 16 digits + ascii << wxString::Format("\n%#018llx ", m_llAddressDisplay); // 18 = 0x + 16 digits + } + else + { + memory << wxString::Format("\n%#10llx ", m_llAddressDisplay); // 10 = 0x + 8 digits + ascii << wxString::Format("\n%#10llx ", m_llAddressDisplay); // 10 = 0x + 8 digits + } + line++; } } diff --git a/MemoryPanel.h b/MemoryPanel.h index 69f5e54..cf0fa53 100644 --- a/MemoryPanel.h +++ b/MemoryPanel.h @@ -45,7 +45,7 @@ class MemoryPanel: public wxPanel void OnTextEnter(wxCommandEvent& event); //*) - uint64_t m_addr; + wxString m_sAddress; std::shared_ptr m_watch; DECLARE_EVENT_TABLE() diff --git a/MemoryPanel.xrc b/MemoryPanel.xrc index 2024986..4965f71 100644 --- a/MemoryPanel.xrc +++ b/MemoryPanel.xrc @@ -11,7 +11,7 @@ 4 1 - + wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL @@ -19,7 +19,7 @@ - + 0x0 @@ -28,7 +28,7 @@ - + wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL @@ -36,7 +36,7 @@ - + 32 From 01df51b8a9c251ca0453c929aa7cd688309c7afb Mon Sep 17 00:00:00 2001 From: AndrweCottrell Date: Fri, 8 Apr 2022 12:25:59 +1000 Subject: [PATCH 2/3] Hopefully now compatible with GDB annotations debugger plugin. --- MemoryPanel.cpp | 89 ++++++++++++++++++++++++++++++++++++++----------- MemoryPanel.h | 1 + manifest.xml | 6 ++-- 3 files changed, 74 insertions(+), 22 deletions(-) diff --git a/MemoryPanel.cpp b/MemoryPanel.cpp index 1cfea65..824198f 100644 --- a/MemoryPanel.cpp +++ b/MemoryPanel.cpp @@ -65,10 +65,17 @@ void MemoryPanel::OnTextEnter(wxCommandEvent& event) else { wxString sSize = m_Size->GetValue(); - uint64_t llSize; - if (sSize.ToULongLong(&llSize, 10)) + if (sSize.ToULongLong(&m_llSize, 10)) { - m_watch = dbg->AddMemoryRange(m_sAddress, llSize, true); + uint64_t llAddress; + if (m_sAddress.ToULongLong(&llAddress, 16)) + { + m_watch = dbg->AddMemoryRange(llAddress, m_llSize, wxEmptyString, true); + } + else + { + m_watch = dbg->AddMemoryRange( 0, m_llSize, m_sAddress, true); + } dbg->UpdateWatch(m_watch); } else @@ -99,13 +106,17 @@ void MemoryPanel::DebuggerCursorChanged() void MemoryPanel::UpdatePanel() { - - wxString val; - if(!m_watch) + { + m_ByteOutput->SetValue(_("Cannot find m_watch!")); + m_AchiiOutput->SetValue(_("Cannot find m_watch!")); + ScrollBar1->SetRange(1); return; // WTF is going on? + } + wxString val; m_watch->GetValue(val); + if (m_watch->GetIsValueErrorMessage()) { m_ByteOutput->SetValue(val); @@ -114,14 +125,43 @@ void MemoryPanel::UpdatePanel() return; } - wxString memory = wxEmptyString; - wxString ascii = wxEmptyString; + if(val.IsEmpty()) + { + m_ByteOutput->SetValue(_("No result data found!")); + m_AchiiOutput->SetValue(_("No result data found!")); + ScrollBar1->SetRange(1); + return; // WTF is going on? + } - uint64_t llAddress; - wxString sAddress = m_watch->GetAddress(); - sAddress.ToULongLong(&llAddress, 16); + // ---------------------------------------------------------------------------------------- + // + // (gdb) x/40xb 0x172e750 + // 0x172e750: 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 + // 0x172e758: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + // 0x172e760: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + // 0x172e768: 0xc0 0xe0 0x5b 0x01 0x00 0x00 0x00 0x00 + // 0x172e770: 0xd8 0x00 0x00 0x00 0x29 0x00 0x00 0x00 + // + // ---------------------------------------------------------------------------------------- + // + // GDB/MI "-data-read-memory-bytes %s %d", m_address, m_length); + // memory= + // [ + // { + // begin="0x0000008284fffc40", + // offset="0x0000000000000000", + // end="0x0000008284fffc60", + // contents="000000000154657374204f6e650000000000000000000000000100b501000000" + // } + // ] + // + // ---------------------------------------------------------------------------------------- + wxString memory = wxEmptyString; + wxString ascii = wxEmptyString; + uint64_t llAddress = m_watch->GetAddress(); + int line = 1; #if wxCHECK_VERSION(3, 1, 5) if (wxPlatformInfo::Get().GetBitness() == wxBITNESS_64) #else @@ -138,18 +178,29 @@ void MemoryPanel::UpdatePanel() ascii << wxString::Format("%#10llx ", llAddress); // 10 = 0x + 8 digits } + bool bGDBOldMemoryRead = val.Contains("0x"); + wxCharBuffer buff = val.To8BitData(); wxString hBuff; long lBuff; - int line = 1; + for(size_t i = 0; i < val.size(); ++i) { - hBuff = val.Mid(i*2,2); - if (!hBuff.ToLong(&lBuff, 16)) + if (bGDBOldMemoryRead) { - lBuff = 0; + lBuff = buff[i]; + memory << wxString::Format("%02x ",(unsigned int)(0xFF&lBuff)); } - memory << hBuff << ' '; - if(lBuff > 31 && lBuff < 126 && lBuff != '\n') + else + { + hBuff = val.Mid(i*2,2); + if (!hBuff.ToLong(&lBuff, 16)) + { + lBuff = 0; + } + memory << hBuff << ' '; + } + + if ((lBuff > 31) && (lBuff < 126) && (lBuff != '\n')) { ascii << wxString::Format("%2c ", lBuff); } @@ -159,10 +210,10 @@ void MemoryPanel::UpdatePanel() } else { - ascii << wxString::FromUTF8(u8"·· "); + ascii << wxString::Format("·· "); } - if ((i+1) % 32 == 0) + if((i+1) % 32 == 0) { uint64_t m_llAddressDisplay = llAddress + line * 32; #if wxCHECK_VERSION(3, 1, 5) diff --git a/MemoryPanel.h b/MemoryPanel.h index cf0fa53..fea6707 100644 --- a/MemoryPanel.h +++ b/MemoryPanel.h @@ -46,6 +46,7 @@ class MemoryPanel: public wxPanel //*) wxString m_sAddress; + uint64_t m_llSize; std::shared_ptr m_watch; DECLARE_EVENT_TABLE() diff --git a/manifest.xml b/manifest.xml index 3980b2b..2ee24d2 100644 --- a/manifest.xml +++ b/manifest.xml @@ -1,13 +1,13 @@ - + - + - + From 98b681e3ce445c97c7b144a3c60bb97aa3f79280 Mon Sep 17 00:00:00 2001 From: AndrweCottrell Date: Fri, 8 Apr 2022 15:31:49 +1000 Subject: [PATCH 3/3] Now working with GDB annotations plugin. --- MemoryPanel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MemoryPanel.cpp b/MemoryPanel.cpp index 824198f..89c72d2 100644 --- a/MemoryPanel.cpp +++ b/MemoryPanel.cpp @@ -178,14 +178,14 @@ void MemoryPanel::UpdatePanel() ascii << wxString::Format("%#10llx ", llAddress); // 10 = 0x + 8 digits } - bool bGDBOldMemoryRead = val.Contains("0x"); wxCharBuffer buff = val.To8BitData(); wxString hBuff; long lBuff; + size_t valSize = val.size(); - for(size_t i = 0; i < val.size(); ++i) + for(size_t i = 0; i < valSize; ++i) { - if (bGDBOldMemoryRead) + if (valSize == m_llSize) { lBuff = buff[i]; memory << wxString::Format("%02x ",(unsigned int)(0xFF&lBuff)); @@ -213,7 +213,7 @@ void MemoryPanel::UpdatePanel() ascii << wxString::Format("·· "); } - if((i+1) % 32 == 0) + if (((i+1) % 32 == 0) && (i < valSize-1)) { uint64_t m_llAddressDisplay = llAddress + line * 32; #if wxCHECK_VERSION(3, 1, 5)