~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/debuggergdb/examinememorydlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
4
 *
 
5
 * $Revision$
 
6
 * $Id$
 
7
 * $HeadURL$
 
8
 */
 
9
 
 
10
#include <sdk.h>
 
11
#include "examinememorydlg.h"
 
12
#include "debuggergdb.h"
 
13
#include <wx/intl.h>
 
14
#include <wx/xrc/xmlres.h>
 
15
#include <wx/textctrl.h>
 
16
#include <wx/combobox.h>
 
17
#include <wx/button.h>
 
18
 
 
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)
 
23
END_EVENT_TABLE()
 
24
 
 
25
ExamineMemoryDlg::ExamineMemoryDlg(wxWindow* parent, DebuggerGDB* debugger)
 
26
    : m_pDbg(debugger),
 
27
    m_LastRowStartingAddress(0)
 
28
{
 
29
    //ctor
 
30
    wxXmlResource::Get()->LoadPanel(this, parent, _T("MemoryDumpPanel"));
 
31
    m_pText = XRCCTRL(*this, "txtDump", wxTextCtrl);
 
32
 
 
33
    wxFont font(8, wxMODERN, wxNORMAL, wxNORMAL);
 
34
    m_pText->SetFont(font);
 
35
 
 
36
    Clear();
 
37
}
 
38
 
 
39
ExamineMemoryDlg::~ExamineMemoryDlg()
 
40
{
 
41
    //dtor
 
42
}
 
43
 
 
44
void ExamineMemoryDlg::Begin()
 
45
{
 
46
    m_pText->Freeze();
 
47
}
 
48
 
 
49
void ExamineMemoryDlg::End()
 
50
{
 
51
    m_pText->Thaw();
 
52
}
 
53
 
 
54
void ExamineMemoryDlg::Clear()
 
55
{
 
56
    m_pText->Clear();
 
57
    m_LastRowStartingAddress = 0;
 
58
    m_ByteCounter = 0;
 
59
    for (int i = 0; i < 67; ++i)
 
60
        m_LineText[i] = _T(' ');
 
61
}
 
62
 
 
63
wxString ExamineMemoryDlg::GetBaseAddress()
 
64
{
 
65
    return XRCCTRL(*this, "txtAddress", wxTextCtrl)->GetValue();
 
66
}
 
67
 
 
68
int ExamineMemoryDlg::GetBytes()
 
69
{
 
70
    long a;
 
71
    XRCCTRL(*this, "cmbBytes", wxComboBox)->GetValue().ToLong(&a);
 
72
    return a;
 
73
}
 
74
 
 
75
void ExamineMemoryDlg::AddError(const wxString& err)
 
76
{
 
77
    m_pText->AppendText(err + _T('\n'));
 
78
}
 
79
 
 
80
void ExamineMemoryDlg::AddHexByte(const wxString& addr, const wxString& hexbyte)
 
81
{
 
82
//    m_pDbg->Log(_T("AddHexByte(") + addr + _T(", ") + hexbyte + _T(')'));
 
83
    int bcmod = m_ByteCounter % 16;
 
84
 
 
85
    if (m_LastRowStartingAddress == 0)
 
86
    {
 
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".
 
90
 
 
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);
 
94
    }
 
95
 
 
96
#define HEX_OFFSET(a) (a*3)
 
97
#define CHAR_OFFSET(a) (16*3 + 3 + a)
 
98
 
 
99
    long hb;
 
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('.'));
 
106
    ++m_ByteCounter;
 
107
 
 
108
    // flush every 16 bytes
 
109
    if (m_ByteCounter != 0 && m_ByteCounter % 16 == 0)
 
110
    {
 
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)
 
115
 
 
116
        long a;
 
117
        addr.ToLong(&a, 16);
 
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;
 
124
    }
 
125
}
 
126
 
 
127
void ExamineMemoryDlg::OnGo(wxCommandEvent& event)
 
128
{
 
129
    m_pDbg->MemoryDump();
 
130
}