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 1 commit
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
66 changes: 43 additions & 23 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 @@ -38,17 +37,24 @@ ExamineMemoryDlg::ExamineMemoryDlg(wxWindow* parent) :
return;
m_pText = XRCCTRL(*this, "txtDump", wxTextCtrl);

wxFont font(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
wxFont font(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
Copy link
Owner

Choose a reason for hiding this comment

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

Why have you increased the size?

m_pText->SetFont(font);

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);
}

void ExamineMemoryDlg::Clear()
{
m_ColumnsCtrl = GetCols();
m_pText->Clear();
m_LastRowStartingAddress = 0;
m_ByteCounter = 0;
for (int i = 0; i < 67; ++i)

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)
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,34 +122,35 @@ 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)
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,
if (m_ByteCounter != m_ColumnsCtrl) // 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;

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]);

// for (int i = 0; i < (m_PartLength + m_ColumnsCtrl); ++i)
// m_LineText[i] = _T(' ');
Copy link
Owner

Choose a reason for hiding this comment

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

The identation of this block is a mess. Please fix.


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();
Expand All @@ -140,6 +159,7 @@ void ExamineMemoryDlg::OnGo(cb_unused wxCommandEvent& event)
// 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
28 changes: 16 additions & 12 deletions 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 @@ -16,26 +17,29 @@ class ExamineMemoryDlg : public wxPanel, public cbExamineMemoryDlg
public:
ExamineMemoryDlg(wxWindow* parent);

wxWindow* GetWindow() override { return this; }
wxWindow* GetWindow() { return this; }

// used for Freeze()/Thaw() calls
void Begin() override;
void End() override;

void Clear() override;
wxString GetBaseAddress() override;
void SetBaseAddress(const wxString &addr) override;
int GetBytes() override;
void AddError(const wxString& err) override;
void AddHexByte(const wxString& addr, const wxString& hexbyte) override;
void EnableWindow(bool enable) override;
void Begin();
Copy link
Owner

Choose a reason for hiding this comment

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

Why have you removed override?

void End();

void Clear();
wxString GetBaseAddress();
void SetBaseAddress(const wxString &addr);
int GetBytes();
int GetCols();
void AddError(const wxString& err);
void AddHexByte(const wxString& addr, const wxString& hexbyte);
void EnableWindow(bool enable);
protected:
void OnGo(wxCommandEvent& event);

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];
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