~ubuntu-branches/ubuntu/utopic/openmsx-debugger/utopic

« back to all changes in this revision

Viewing changes to src/DebuggerData.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Joost Yervante Damad
  • Date: 2009-12-06 07:40:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091206074002-kssfkg1d6xbp6w9e
Tags: 0.0.0.svn20091206-1
New svn snapshot (Closes: #559612)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: DebuggerData.cpp 102 2006-05-15 22:23:16Z m9710797 $
 
1
// $Id: DebuggerData.cpp 9347 2009-03-06 22:47:13Z m9710797 $
2
2
 
3
3
#include "DebuggerData.h"
4
4
#include <QStringList>
5
5
 
6
6
 
7
 
//
8
 
// MemoryLayout
9
 
//
 
7
// class MemoryLayout
10
8
 
11
9
MemoryLayout::MemoryLayout()
12
10
{
21
19
        }
22
20
}
23
21
 
24
 
//
25
 
// Breakpoints
26
 
//
 
22
 
 
23
// class Breakpoints
27
24
 
28
25
Breakpoints::Breakpoints()
29
26
        : memLayout(NULL)
30
27
{
31
28
}
32
29
 
 
30
void Breakpoints::clear()
 
31
{
 
32
        breakpoints.clear();
 
33
}
 
34
 
33
35
void Breakpoints::setMemoryLayout(MemoryLayout* ml)
34
36
{
35
37
        memLayout = ml;
37
39
 
38
40
void Breakpoints::setBreakpoints(const QString& str)
39
41
{
 
42
        breakpoints.clear();
40
43
        QStringList bps = str.split('\n');
41
 
 
42
 
        breakpoints.clear();
43
44
        for (QStringList::Iterator it = bps.begin(); it != bps.end(); ++it) {
44
45
                Breakpoint newBp;
 
46
                newBp.type = BREAKPOINT;
45
47
                int p = it->indexOf(' ');
46
48
                newBp.id = it->left(p).trimmed();
47
 
                if(newBp.id.isEmpty()) break;
48
 
                int q = it->indexOf(' ', p+1);
 
49
                if (newBp.id.isEmpty()) break;
 
50
                int q = it->indexOf(' ', p + 1);
49
51
                if (q == -1) {
50
 
                        newBp.address = it->mid(p).toUShort(0,0);
 
52
                        newBp.address = it->mid(p).toUShort(0, 0);
51
53
                } else {
52
 
                        newBp.address = it->mid(p, q-p).trimmed().toUShort(0,0);
 
54
                        newBp.address = it->mid(p, q - p).trimmed().toUShort(0, 0);
53
55
                        newBp.condition = it->mid(q).trimmed();
54
56
                }
 
57
                newBp.regionEnd = newBp.address;
55
58
                parseCondition(newBp);
56
59
                insertBreakpoint(newBp);
57
60
        }
58
61
}
59
62
 
 
63
QString Breakpoints::mergeBreakpoints(const QString& str)
 
64
{
 
65
        // copy breakpoints
 
66
        BreakpointList oldBps(breakpoints);
 
67
        // parse new list
 
68
        setBreakpoints(str);
 
69
        // check old list against new one
 
70
        QStringList mergeSet;
 
71
        while (!oldBps.empty()) {
 
72
                Breakpoint& old = oldBps.first();
 
73
                BreakpointList::iterator newit = breakpoints.begin();
 
74
                for (/**/; newit != breakpoints.end(); ++newit) {
 
75
                        // check for identical location
 
76
                        // TODO [wouter]: why is condition not compared?
 
77
                        //      maybe better use some sort of find algorithm?
 
78
                        //      and use BreakPoint::operator==()
 
79
                        if (old.type == newit->type &&
 
80
                            old.address == newit->address &&
 
81
                            old.regionEnd == newit->regionEnd &&
 
82
                            old.ps == newit->ps &&
 
83
                            old.ss == newit->ss &&
 
84
                            old.segment == newit->segment) {
 
85
                                break;
 
86
                        }
 
87
                }
 
88
                if (newit == breakpoints.end()) {
 
89
                        // create command to set this breakpoint again
 
90
                        QString cmd;
 
91
                        cmd.sprintf("debug set_bp %i { [ pc_in_slot %c %c %i ] }",
 
92
                                    old.address, old.ps, old.ss, old.segment);
 
93
                        mergeSet << cmd;
 
94
                }
 
95
                oldBps.removeFirst();
 
96
        }
 
97
        return mergeSet.join(" ; ");
 
98
}
 
99
 
60
100
static QString getNextArgument(QString& data, int& pos)
61
101
{
62
102
        QString result;
63
 
        while (data[pos] == ' ' || data[pos]=='\t') ++pos;
 
103
        while (data[pos] == ' ' || data[pos] == '\t') ++pos;
64
104
        while (true) {
65
105
                if (data[pos] == ' ' || data[pos] == '\t') break;
66
106
                if (data[pos] == '}' || data[pos] == ']') break;
103
143
bool Breakpoints::inCurrentSlot(const Breakpoint& bp)
104
144
{
105
145
        if (memLayout == NULL) return true;
106
 
        
 
146
 
107
147
        int page = (bp.address & 0xC000) >> 14;
108
148
        if (bp.ps == '*' || bp.ps == memLayout->primarySlot[page]) {
109
149
                if (memLayout->isSubslotted[bp.ps & 3]) {
183
223
        // will implement findfirst/findnext scheme for speed
184
224
        return -1;
185
225
}
 
226
 
 
227
 
 
228
void Breakpoints::saveBreakpoints(QXmlStreamWriter& xml)
 
229
{
 
230
        // write symbols
 
231
        for (BreakpointList::iterator it = breakpoints.begin();
 
232
             it != breakpoints.end(); ++it) {
 
233
                xml.writeStartElement("Breakpoint");
 
234
 
 
235
                // type
 
236
                switch (it->type) {
 
237
                case BREAKPOINT:
 
238
                        xml.writeAttribute("type", "breakpoint");
 
239
                        break;
 
240
                case WATCHPOINT_IOREAD:
 
241
                        xml.writeAttribute("type", "ioread");
 
242
                        break;
 
243
                case WATCHPOINT_IOWRITE:
 
244
                        xml.writeAttribute("type", "iowrite");
 
245
                        break;
 
246
                case WATCHPOINT_MEMREAD:
 
247
                        xml.writeAttribute("type", "memread");
 
248
                        break;
 
249
                case WATCHPOINT_MEMWRITE:
 
250
                        xml.writeAttribute("type", "memwrite");
 
251
                        break;
 
252
                }
 
253
 
 
254
                // id
 
255
                xml.writeAttribute("id", it->id);
 
256
 
 
257
                // slot/segment
 
258
                xml.writeAttribute("primarySlot", QString(it->ps));
 
259
                xml.writeAttribute("secondarySlot", QString(it->ss));
 
260
                xml.writeAttribute("segment", QString::number(it->segment));
 
261
 
 
262
                // address
 
263
                if (it->type == BREAKPOINT) {
 
264
                        xml.writeTextElement("address", QString::number(it->address));
 
265
                } else {
 
266
                        xml.writeTextElement("regionStart", QString::number(it->address));
 
267
                        xml.writeTextElement("regionEnd", QString::number(it->regionEnd));
 
268
                }
 
269
 
 
270
                // condition not supported yet
 
271
 
 
272
                // complete
 
273
                xml.writeEndElement();
 
274
        }
 
275
}
 
276
 
 
277
void Breakpoints::loadBreakpoints(QXmlStreamReader& xml)
 
278
{
 
279
        Breakpoint bp;
 
280
        while (!xml.atEnd()) {
 
281
                xml.readNext();
 
282
                // exit if closing of main tag
 
283
                if (xml.isEndElement()) {
 
284
                        if (xml.name() == "Breakpoints") {
 
285
                                break;
 
286
                        } else if (xml.name() == "Breakpoint") {
 
287
                                insertBreakpoint(bp);
 
288
                        }
 
289
                }
 
290
                // begin tag
 
291
                if (xml.isStartElement()) {
 
292
                        if (xml.name() == "Breakpoint") {
 
293
                                // set type
 
294
                                QString type = xml.attributes().value("type").toString().toLower();
 
295
                                if (type == "ioread") {
 
296
                                        bp.type = WATCHPOINT_IOREAD;
 
297
                                } else if (type == "iowrite") {
 
298
                                        bp.type = WATCHPOINT_IOWRITE;
 
299
                                } else if (type == "memread") {
 
300
                                        bp.type = WATCHPOINT_MEMREAD;
 
301
                                } else if (type == "memwrite") {
 
302
                                        bp.type = WATCHPOINT_MEMWRITE;
 
303
                                } else {
 
304
                                        bp.type = BREAKPOINT;
 
305
                                }
 
306
 
 
307
                                // id
 
308
                                bp.id = xml.attributes().value("id").toString();
 
309
 
 
310
                                // slot/segment
 
311
                                bp.ps = xml.attributes().value("primarySlot").at(0).toAscii();
 
312
                                bp.ss = xml.attributes().value("secondarySlot").at(0).toAscii();
 
313
                                bp.segment = xml.attributes().value("segment").toString().toInt();
 
314
 
 
315
                        } else if (xml.name() == "address" || xml.name() == "regionStart") {
 
316
                                // read symbol name
 
317
                                bp.address = xml.readElementText().toInt();
 
318
                                if (bp.type == BREAKPOINT) bp.regionEnd = bp.address;
 
319
 
 
320
                        } else if (xml.name() == "regionEnd") {
 
321
                                // read symbol name
 
322
                                bp.regionEnd = xml.readElementText().toInt();
 
323
                        }
 
324
                }
 
325
        }
 
326
}