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 174 175 176 177 178 179 180 181 182 183 184 185
|
/***************************************************************************
begin : Tues Jan 3 2000
copyright : (C) 2000 by John Birch
email : jbb@kdevelop.org
***************************************************************************/
/***************************************************************************
* *
* 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 <kdebug.h>
#include <kdeversion.h>
#if KDE_VERSION > 305
# include <ktextedit.h>
#endif
#include <kglobalsettings.h>
#include <qdict.h>
#include <qheader.h>
#include <qtextedit.h>
#include <stdlib.h>
namespace GDBDebugger
{
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
DisassembleWidget::DisassembleWidget(QWidget *parent, const char *name)
: QTextEdit(parent, name),
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++)
{
int address = strtol(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::slotBPState(const Breakpoint&)
{
if (!active_)
return;
}
/***************************************************************************/
void DisassembleWidget::slotDisassemble(char *buf)
{
if (!active_)
return;
clear();
// Skip the first line (just header info)
char *start = strchr(buf, '\n');
// Make sure there is something there
if (start)
{
append(start+1);
// Skip the last two lines (just trailer info)
removeParagraph(paragraphs()-1);
removeParagraph(paragraphs()-1);
if (paragraphs())
{
lower_ = strtol(text(0).latin1(), 0, 0);
upper_ = strtol(text(paragraphs()-1).latin1(), 0, 0);
displayCurrent();
}
else
{
lower_ = 0;
upper_ = 0;
}
}
}
/***************************************************************************/
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_ = strtol(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());
// restrict this to a managable size - some functions are _big_
QString endAddress;
endAddress.sprintf("0x%x", (uint)address_+128);
emit disassemble(currentAddress_, endAddress);
}
else
emit disassemble("", "");
}
void DisassembleWidget::showEvent(QShowEvent*)
{
slotActivate(true);
}
void DisassembleWidget::hideEvent(QHideEvent*)
{
slotActivate(false);
}
/***************************************************************************/
}
#include "disassemblewidget.moc"
|