2
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3
* http://www.gnu.org/licenses/gpl-3.0.html
11
#include "examinememorydlg.h"
12
#include "debuggergdb.h"
14
#include <wx/xrc/xmlres.h>
15
#include <wx/textctrl.h>
16
#include <wx/combobox.h>
17
#include <wx/button.h>
19
BEGIN_EVENT_TABLE(ExamineMemoryDlg, wxPanel)
20
EVT_BUTTON(XRCID("btnGo"), ExamineMemoryDlg::OnGo)
21
EVT_COMBOBOX(XRCID("cmbBytes"), ExamineMemoryDlg::OnGo)
22
EVT_TEXT_ENTER(XRCID("txtAddress"), ExamineMemoryDlg::OnGo)
25
ExamineMemoryDlg::ExamineMemoryDlg(wxWindow* parent, DebuggerGDB* debugger)
27
m_LastRowStartingAddress(0)
30
wxXmlResource::Get()->LoadPanel(this, parent, _T("MemoryDumpPanel"));
31
m_pText = XRCCTRL(*this, "txtDump", wxTextCtrl);
33
wxFont font(8, wxMODERN, wxNORMAL, wxNORMAL);
34
m_pText->SetFont(font);
39
ExamineMemoryDlg::~ExamineMemoryDlg()
44
void ExamineMemoryDlg::Begin()
49
void ExamineMemoryDlg::End()
54
void ExamineMemoryDlg::Clear()
57
m_LastRowStartingAddress = 0;
59
for (int i = 0; i < 67; ++i)
60
m_LineText[i] = _T(' ');
63
wxString ExamineMemoryDlg::GetBaseAddress()
65
return XRCCTRL(*this, "txtAddress", wxTextCtrl)->GetValue();
68
int ExamineMemoryDlg::GetBytes()
71
XRCCTRL(*this, "cmbBytes", wxComboBox)->GetValue().ToLong(&a);
75
void ExamineMemoryDlg::AddError(const wxString& err)
77
m_pText->AppendText(err + _T('\n'));
80
void ExamineMemoryDlg::AddHexByte(const wxString& addr, const wxString& hexbyte)
82
// m_pDbg->Log(_T("AddHexByte(") + addr + _T(", ") + hexbyte + _T(')'));
83
int bcmod = m_ByteCounter % 16;
85
if (m_LastRowStartingAddress == 0)
87
// because we 'll be appending each row *after* we have consumed it
88
// and then "addr" will point to the next row's starting address,
89
// we 'll keep the current row's starting address in "m_LastRowStartingAddress".
91
// if it's zero (i.e this is the first row), keep "addr" as starting address for this row.
92
// m_LastRowStartingAddress will be set again when we 've consumed this row...
93
addr.ToLong(&m_LastRowStartingAddress, 16);
96
#define HEX_OFFSET(a) (a*3)
97
#define CHAR_OFFSET(a) (16*3 + 3 + a)
100
hexbyte.ToLong(&hb, 16);
101
// m_pDbg->Log(wxString::Format(_T("hb=%d, [0]=%c, [1]=%c"), hb, hexbyte[0], hexbyte[1]));
102
// m_pDbg->Log(wxString::Format(_T("HEX_OFFSET(bcmod)=%d, CHAR_OFFSET(bcmod)=%d"), HEX_OFFSET(bcmod), CHAR_OFFSET(bcmod)));
103
m_LineText[HEX_OFFSET(bcmod)] = hexbyte[0];
104
m_LineText[HEX_OFFSET(bcmod) + 1] = hexbyte[1];
105
m_LineText[CHAR_OFFSET(bcmod)] = hb >= 32 ? wxChar(hb) : wxChar(_T('.'));
108
// flush every 16 bytes
109
if (m_ByteCounter != 0 && m_ByteCounter % 16 == 0)
111
// filled 16 bytes window; append text and reset accumulator array
112
if (m_ByteCounter != 16) // after the first line,
113
m_pText->AppendText(_T('\n')); // prepend a newline
114
m_LineText[23] = _T('|'); // put a "separator" in the middle (just to ease reading a bit)
118
m_pText->AppendText(wxString::Format(_T("0x%x: %s"), m_LastRowStartingAddress, m_LineText));
119
for (int i = 0; i < 67; ++i)
120
m_LineText[i] = _T(' ');
121
// update starting address for next row
122
// add 8 bytes: addr is the start address of the second 8-byte chunk of this line, so next line is +8
123
m_LastRowStartingAddress = a + 8;
127
void ExamineMemoryDlg::OnGo(wxCommandEvent& event)
129
m_pDbg->MemoryDump();