Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Memorydump update #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/include/cbdebugger_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class DLLIMPORT cbExamineMemoryDlg
virtual void Clear() = 0;
virtual wxString GetBaseAddress() = 0;
virtual int GetBytes() = 0;
virtual int GetCols() = 0;
virtual void AddError(const wxString& err) = 0;
virtual void AddHexByte(const wxString& addr, const wxString& hexbyte) = 0;
virtual void EnableWindow(bool enable) = 0;
Expand Down
68 changes: 44 additions & 24 deletions src/src/examinememorydlg.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
* http://www.gnu.org/licenses/gpl-3.0.html
*
* Modified MicroSourceCode https://github.com/MicroSourceCode
* $Revision$
* $Id$
* $HeadURL$
Expand All @@ -22,11 +22,10 @@
#include "examinememorydlg.h"
#include "debuggermanager.h"

#include <cinttypes> // For PRIx64

BEGIN_EVENT_TABLE(ExamineMemoryDlg, wxPanel)
EVT_BUTTON(XRCID("btnGo"), ExamineMemoryDlg::OnGo)
EVT_COMBOBOX(XRCID("cmbBytes"), ExamineMemoryDlg::OnGo)
EVT_COMBOBOX(XRCID("colSelect"), ExamineMemoryDlg::OnGo)
EVT_TEXT_ENTER(XRCID("txtAddress"), ExamineMemoryDlg::OnGo)
END_EVENT_TABLE()

Expand All @@ -43,12 +42,19 @@ ExamineMemoryDlg::ExamineMemoryDlg(wxWindow* parent) :

ConfigManager *c = Manager::Get()->GetConfigManager(wxT("debugger_common"));
int bytes = c->ReadInt(wxT("/common/examine_memory/size_to_show"), 32);
wxString strBytes;
int bytesCols = c->ReadInt(wxT("/common/examine_memory/columns_to_show"), 8);
wxString strBytes, strCols;
strBytes << bytes;
strCols << bytesCols;

wxComboBox *combo = XRCCTRL(*this, "cmbBytes", wxComboBox);
if (!combo->SetStringSelection(strBytes))
combo->SetSelection(1); // Default is 32 bytes

wxComboBox *combo2 = XRCCTRL(*this, "colSelect", wxComboBox);
if (!combo2->SetStringSelection(strCols))
combo2->SetSelection(3); // Default is 8 columns

Clear();
}

Expand All @@ -60,14 +66,19 @@ void ExamineMemoryDlg::Begin()
void ExamineMemoryDlg::End()
{
m_pText->Thaw();
m_pText->SetInsertionPoint(0); //Scrolling up
}

void ExamineMemoryDlg::Clear()
{
m_ColumnsCtrl = GetCols();
m_pText->Clear();
m_LastRowStartingAddress = 0;
m_ByteCounter = 0;
for (int i = 0; i < 67; ++i)
// (4 column * 2) + 4 column = 12, for 6 is m_PartLength = 18
m_PartLength = (m_ColumnsCtrl * 2) + m_ColumnsCtrl;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Why do you just multiply by 3?


for (int i = 0; i < 128; ++i) //128 is: 32 * 3 + 32
m_LineText[i] = _T(' ');
}

Expand All @@ -83,6 +94,13 @@ int ExamineMemoryDlg::GetBytes()
return a;
}

int ExamineMemoryDlg::GetCols()
{
long a;
XRCCTRL(*this, "colSelect", wxComboBox)->GetValue().ToLong(&a);
return a;
}

void ExamineMemoryDlg::AddError(const wxString& err)
{
m_pText->AppendText(err + _T('\n'));
Expand All @@ -91,9 +109,9 @@ void ExamineMemoryDlg::AddError(const wxString& err)
void ExamineMemoryDlg::AddHexByte(const wxString& addr, const wxString& hexbyte)
{
// m_pDbg->Log(_T("AddHexByte(") + addr + _T(", ") + hexbyte + _T(')'));
int bcmod = m_ByteCounter % 16;
int bcmod = m_ByteCounter % m_ColumnsCtrl;

if (m_ByteCounter == 0)
if (m_LastRowStartingAddress == 0)
{
// because we 'll be appending each row *after* we have consumed it
// and then "addr" will point to the next row's starting address,
Expand All @@ -104,42 +122,44 @@ void ExamineMemoryDlg::AddHexByte(const wxString& addr, const wxString& hexbyte)
m_LastRowStartingAddress = cbDebuggerStringToAddress(addr);
}

#define HEX_OFFSET(a) (a*3)
#define CHAR_OFFSET(a) (16*3 + 3 + a)
#define HEX_OFFSET(a) (a*3)
//#define CHAR_OFFSET(a) (16*3 + 3 + a)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use this any more you better remove this.


unsigned long hb;
hexbyte.ToULong(&hb, 16);
// m_pDbg->Log(wxString::Format(_T("hb=%d, [0]=%c, [1]=%c"), hb, hexbyte[0], hexbyte[1]));
// m_pDbg->Log(wxString::Format(_T("HEX_OFFSET(bcmod)=%d, CHAR_OFFSET(bcmod)=%d"), HEX_OFFSET(bcmod), CHAR_OFFSET(bcmod)));

m_LineText[HEX_OFFSET(bcmod)] = hexbyte[0];
m_LineText[HEX_OFFSET(bcmod) + 1] = hexbyte[1];
m_LineText[CHAR_OFFSET(bcmod)] = hb >= 32 ? wxChar(hb) : wxChar(_T('.'));
m_LineText[(m_PartLength + bcmod)] = hb >= 32 ? wxChar(hb) : wxChar(_T('.'));
++m_ByteCounter;

// flush every 16 bytes
if (m_ByteCounter != 0 && m_ByteCounter % 16 == 0)
// flush every m_ColumnsCtrl bytes
if (m_ByteCounter != 0 && m_ByteCounter % m_ColumnsCtrl == 0)
{
// filled 16 bytes window; append text and reset accumulator array
if (m_ByteCounter != 16) // after the first line,
m_pText->AppendText(_T('\n')); // prepend a newline
m_LineText[23] = _T('|'); // put a "separator" in the middle (just to ease reading a bit)

m_pText->AppendText(wxString::Format(_T("0x%" PRIx64 ": %.67s"), m_LastRowStartingAddress, m_LineText));
for (int i = 0; i < 67; ++i)
m_LineText[i] = _T(' ');
// update starting address for next row every 16 bytes
m_LastRowStartingAddress += 16;
// filled m_ColumnsCtrl bytes window; append text and reset accumulator array
if (m_ByteCounter != m_ColumnsCtrl) // after the first line,
m_pText->AppendText(_T('\n')); // prepend a newline

m_pText->AppendText(wxString::Format(_T("0x%lx: "), m_LastRowStartingAddress));
for (unsigned i = 0; i < (m_PartLength + m_ColumnsCtrl); ++i)
m_pText->AppendText(m_LineText[i]);
// update starting address for next row every m_ColumnsCtrl bytes
m_LastRowStartingAddress += m_ColumnsCtrl;
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty space?

void ExamineMemoryDlg::OnGo(cb_unused wxCommandEvent& event)
{
cbDebuggerPlugin *plugin = Manager::Get()->GetDebuggerManager()->GetActiveDebugger();

// Save the value of the bytes combo box in the config,
// Save the values of the bytes combo box in the config,
// so it is the same next time the dialog is used.
ConfigManager *c = Manager::Get()->GetConfigManager(wxT("debugger_common"));
c->Write(wxT("/common/examine_memory/size_to_show"), GetBytes());
c->Write(wxT("/common/examine_memory/columns_to_show"), GetCols());

if (plugin)
plugin->RequestUpdate(cbDebuggerPlugin::ExamineMemory);
Expand Down
6 changes: 5 additions & 1 deletion src/src/examinememorydlg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
* http://www.gnu.org/licenses/gpl-3.0.html
* Modified MicroSourceCode https://github.com/MicroSourceCode
*/

#ifndef EXAMINEMEMORYDLG_H
Expand All @@ -26,6 +27,7 @@ class ExamineMemoryDlg : public wxPanel, public cbExamineMemoryDlg
wxString GetBaseAddress() override;
void SetBaseAddress(const wxString &addr) override;
int GetBytes() override;
int GetCols() override;
void AddError(const wxString& err) override;
void AddHexByte(const wxString& addr, const wxString& hexbyte) override;
void EnableWindow(bool enable) override;
Expand All @@ -35,7 +37,9 @@ class ExamineMemoryDlg : public wxPanel, public cbExamineMemoryDlg
private:
wxTextCtrl* m_pText;
size_t m_ByteCounter;
wxChar m_LineText[67]; // 16*3 "7F " + 3 " " + 16 "."
unsigned m_ColumnsCtrl;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming something ctrl means it is the actual variable to the control. Please use just m_Columns or m_NumColumns.

unsigned m_PartLength;
wxChar m_LineText[128]; //128 is: 32 * 3 + 32
uint64_t m_LastRowStartingAddress;
private:
DECLARE_EVENT_TABLE()
Expand Down
50 changes: 41 additions & 9 deletions src/src/resources/memdump.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
<object class="wxBoxSizer">
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT1">
<label>Address:</label>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't abbreviate things. The abbreviation of "address" is more common to be "addr" also.

<label>Adr:</label>
</object>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>4</border>
<border>2</border>
</object>
<object class="sizeritem">
<object class="wxTextCtrl" name="txtAddress">
<value>0x0</value>
<style>wxTE_PROCESS_ENTER</style>
</object>
<flag>wxLEFT|wxALIGN_CENTER_VERTICAL</flag>
<border>4</border>
<flag>wxEXPAND</flag>
<border>2</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT2">
<label>Bytes:</label>
</object>
<flag>wxLEFT|wxALIGN_CENTER_VERTICAL</flag>
<border>4</border>
<border>2</border>
</object>
<object class="sizeritem">
<object class="wxComboBox" name="cmbBytes">
Expand All @@ -44,15 +44,47 @@
<selection>1</selection>
<style>wxCB_READONLY</style>
</object>
<flag>wxLEFT|wxALIGN_CENTER_VERTICAL</flag>
<border>4</border>
<flag>wxRIGHT|wxEXPAND</flag>
<border>2</border>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="ID_STATICTEXT4">
<label>Col:</label>
</object>
<flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>2</border>
</object>
<object class="sizeritem">
<object class="wxComboBox" name="colSelect">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use wxChoice they work better on wxGTK.

<content>
<item>2</item>
<item>4</item>
<item>6</item>
<item>8</item>
<item>10</item>
<item>12</item>
<item>14</item>
<item>16</item>
<item>18</item>
<item>20</item>
<item>22</item>
<item>24</item>
<item>26</item>
<item>28</item>
<item>30</item>
<item>32</item>
</content>
<style>wxCB_READONLY</style>
</object>
<flag>wxRIGHT|wxEXPAND</flag>
<border>2</border>
</object>
<object class="sizeritem">
<object class="wxButton" name="btnGo">
<label>Go</label>
</object>
<flag>wxLEFT|wxALIGN_CENTER_VERTICAL</flag>
<border>4</border>
<flag>wxLEFT|wxEXPAND</flag>
<border>2</border>
</object>
</object>
<flag>wxTOP|wxLEFT|wxRIGHT|wxEXPAND</flag>
Expand Down