~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/debugger/disassemblewidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

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