1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/***************************************************************************
begin : Tues Jan 3 2000
copyright : (C) 2000 by John Birch
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "disassemblewidget.h"
#include "gdbcontroller.h"
#include "gdbcommand.h"
#include <kdebug.h>
#include <kdeversion.h>
#include <ktextedit.h>
#include <kglobalsettings.h>
#include <qdict.h>
#include <qheader.h>
#include <qtextedit.h>
#include <stdlib.h>
namespace GDBDebugger
{
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
DisassembleWidget::DisassembleWidget(GDBController* controller, QWidget *parent, const char *name)
: QTextEdit(parent, name), controller_(controller),
active_(false),
lower_(0),
upper_(0),
address_(0)
{
setFont(KGlobalSettings::fixedFont());
setReadOnly(true);
}
/***************************************************************************/
DisassembleWidget::~DisassembleWidget()
{}
/***************************************************************************/
bool DisassembleWidget::displayCurrent()
{
Q_ASSERT(address_ >= lower_ || address_ <= upper_);
int line;
for (line=0; line < paragraphs(); line++)
{
unsigned long address = strtoul(text(line).latin1(), 0, 0);
if (address == address_)
{
// put cursor at start of line and highlight the line
setCursorPosition(line, 0);
setSelection(line,0,line+1,0,0);
return true;
}
}
return false;
}
/***************************************************************************/
void DisassembleWidget::slotActivate(bool activate)
{
kdDebug(9012) << "Disassemble widget active: " << activate << endl;
if (active_ != activate)
{
active_ = activate;
if (active_ && address_)
{
if (address_ < lower_ || address_ > upper_ || !displayCurrent())
getNextDisplay();
}
}
}
/***************************************************************************/
void DisassembleWidget::slotShowStepInSource( const QString &, int,
const QString ¤tAddress)
{
kdDebug(9012) << "DisasssembleWidget::slotShowStepInSource()" << endl;
currentAddress_ = currentAddress;
address_ = strtoul(currentAddress.latin1(), 0, 0);
if (!active_)
return;
if (address_ < lower_ || address_ > upper_ || !displayCurrent())
getNextDisplay();
}
/***************************************************************************/
void DisassembleWidget::getNextDisplay()
{
kdDebug(9012) << "DisasssembleWidget::getNextDisplay()" << endl;
if (address_)
{
Q_ASSERT(!currentAddress_.isNull());
QString cmd = QString("-data-disassemble -s $pc -e \"$pc + 128\" -- 0");
controller_->addCommandToFront(
new GDBCommand( cmd, this, &DisassembleWidget::memoryRead ) );
}
}
/***************************************************************************/
void DisassembleWidget::memoryRead(const GDBMI::ResultRecord& r)
{
const GDBMI::Value& content = r["asm_insns"];
QString rawdata;
clear();
for(unsigned i = 0; i < content.size(); ++i)
{
const GDBMI::Value& line = content[i];
QString addr = line["address"].literal();
QString fct = line["func-name"].literal();
QString offs = line["offset"].literal();
QString inst = line["inst"].literal();
rawdata += QString(addr + " " + fct+"+"+offs + " " + inst + "\n");
if (i == 0) {
lower_ = strtoul(addr.latin1(), 0, 0);
} else if (i == content.size()-1) {
upper_ = strtoul(addr.latin1(), 0, 0);
}
}
append(rawdata);
displayCurrent();
}
void DisassembleWidget::showEvent(QShowEvent*)
{
slotActivate(true);
}
void DisassembleWidget::hideEvent(QHideEvent*)
{
slotActivate(false);
}
/***************************************************************************/
}
#include "disassemblewidget.moc"
|