breakhandler.cpp 22.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
#include "breakhandler.h"

32
#include "debuggeractions.h"
33
34
35
#include "debuggermanager.h"
#include "stackframe.h"

36
#include <texteditor/basetextmark.h>
hjk's avatar
hjk committed
37

con's avatar
con committed
38
#include <QtCore/QDebug>
Friedemann Kleint's avatar
Friedemann Kleint committed
39
#include <QtCore/QTextStream>
con's avatar
con committed
40
41
42
43
44
45
46
47
48
49
50
51
#include <QtCore/QFileInfo>

using namespace Debugger;
using namespace Debugger::Internal;


//////////////////////////////////////////////////////////////////
//
// BreakpointMarker
//
//////////////////////////////////////////////////////////////////

52
53
54
55
56
57
58
59
60
61
62
63
// Compare file names case insensitively on Windows.
static inline bool fileNameMatch(const QString &f1, const QString &f2)
{
    return f1.compare(f2,
#ifdef Q_OS_WIN
                      Qt::CaseInsensitive
#else
                      Qt::CaseSensitive
#endif
                      ) == 0;
}

con's avatar
con committed
64
65
66
67
68
69
70
71
72
namespace Debugger {
namespace Internal {

// The red blob on the left side in the cpp editor.
class BreakpointMarker : public TextEditor::BaseTextMark
{
    Q_OBJECT
public:
    BreakpointMarker(BreakpointData *data, const QString &fileName, int lineNumber)
73
      : BaseTextMark(fileName, lineNumber)
con's avatar
con committed
74
    {
75
76
77
        m_data = data;
        m_pending = true;
        m_enabled = true;
con's avatar
con committed
78
79
80
81
82
83
84
85
86
87
        //qDebug() << "CREATE MARKER " << fileName << lineNumber;
    }

    ~BreakpointMarker()
    {
        //qDebug() << "REMOVE MARKER ";
        m_data = 0;
    }

    QIcon icon() const
88
    {
89
90
91
92
        const BreakHandler *handler = DebuggerManager::instance()->breakHandler();
        if (!m_enabled)
            return handler->disabledBreakpointIcon();
        return m_pending ? handler->pendingBreakPointIcon() : handler->breakpointIcon();
con's avatar
con committed
93
94
    }

95
    void setPending(bool pending, bool enabled)
con's avatar
con committed
96
    {
97
        if (pending == m_pending && enabled == m_enabled)
con's avatar
con committed
98
99
            return;
        m_pending = pending;
100
        m_enabled = enabled;
con's avatar
con committed
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
        updateMarker();
    }

    void updateBlock(const QTextBlock &)
    {
        //qDebug() << "BREAKPOINT MARKER UPDATE BLOCK";
    }

    void removedFromEditor()
    {
        if (!m_data)
            return;

        BreakHandler *handler = m_data->handler();
        handler->removeBreakpoint(handler->indexOf(m_data));
        handler->saveBreakpoints();
        handler->updateMarkers();
    }

    void updateLineNumber(int lineNumber)
    {
        if (!m_data)
            return;
        //if (m_data->markerLineNumber == lineNumber)
        //    return;
        if (m_data->markerLineNumber != lineNumber) {
            m_data->markerLineNumber = lineNumber;
128
            // FIXME: should we tell gdb about the change?
con's avatar
con committed
129
130
131
132
133
134
135
136
            // Ignore it for now, as we would require re-compilation
            // and debugger re-start anyway.
            if (0 && !m_data->bpLineNumber.isEmpty()) {
                if (!m_data->bpNumber.trimmed().isEmpty()) {
                    m_data->pending = true;
                }
            }
        }
137
        m_data->lineNumber = QByteArray::number(lineNumber);
con's avatar
con committed
138
139
140
141
142
143
        m_data->handler()->updateMarkers();
    }

private:
    BreakpointData *m_data;
    bool m_pending;
144
    bool m_enabled;
con's avatar
con committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
};

} // namespace Internal
} // namespace Debugger



//////////////////////////////////////////////////////////////////
//
// BreakpointData
//
//////////////////////////////////////////////////////////////////

BreakpointData::BreakpointData(BreakHandler *handler)
{
    //qDebug() << "CREATE BREAKPOINTDATA" << this;
    m_handler = handler;
162
    enabled = true;
con's avatar
con committed
163
164
165
166
    pending = true;
    marker = 0;
    markerLineNumber = 0;
    bpMultiple = false;
167
168
//#if defined(Q_OS_MAC)
//    // full names do not work on Mac/MI
169
    useFullPath = false;
170
171
//#else
//    //where = m_manager->shortName(data->fileName);
172
//    useFullPath = true;
173
//#endif
con's avatar
con committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
}

BreakpointData::~BreakpointData()
{
    removeMarker();
    //qDebug() << "DESTROY BREAKPOINTDATA" << this;
}

void BreakpointData::removeMarker()
{
    BreakpointMarker *m = marker;
    marker = 0;
    delete m;
}

void BreakpointData::updateMarker()
{
    if (marker && (markerFileName != marker->fileName()
            || markerLineNumber != marker->lineNumber()))
        removeMarker();

    if (!marker && !markerFileName.isEmpty() && markerLineNumber > 0)
        marker = new BreakpointMarker(this, markerFileName, markerLineNumber);

    if (marker)
199
        marker->setPending(pending, enabled);
con's avatar
con committed
200
201
202
203
}

QString BreakpointData::toToolTip() const
{
Friedemann Kleint's avatar
Friedemann Kleint committed
204
205
206
    QString rc;
    QTextStream str(&rc);
    str << "<html><body><table>";
hjk's avatar
hjk committed
207
208
209
210
211
212
213
214
    str << "<tr><td>" << BreakHandler::tr("Marker File:")
        << "</td><td>" << markerFileName << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Marker Line:")
        << "</td><td>" << markerLineNumber << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Breakpoint Number:")
        << "</td><td>" << bpNumber << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Breakpoint Address:")
        << "</td><td>" << bpAddress << "</td></tr>";
Friedemann Kleint's avatar
Friedemann Kleint committed
215
216
217
218
    str << "</table><br><hr><table>";
    str << "<tr><th>" << BreakHandler::tr("Property")
        << "</th><th>" << BreakHandler::tr("Requested")
        << "</th><th>" << BreakHandler::tr("Obtained") << "</th></tr>";
hjk's avatar
hjk committed
219
220
221
222
223
224
225
226
227
228
229
230
    str << "<tr><td>" << BreakHandler::tr("Internal Number:")
        << "</td><td>&mdash;</td><td>" << bpNumber << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("File Name:")
        << "</td><td>" << fileName << "</td><td>" << bpFileName << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Function Name:")
        << "</td><td>" << funcName << "</td><td>" << bpFuncName << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Line Number:")
        << "</td><td>" << lineNumber << "</td><td>" << bpLineNumber << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Condition:")
        << "</td><td>" << condition << "</td><td>" << bpCondition << "</td></tr>";
    str << "<tr><td>" << BreakHandler::tr("Ignore Count:")
        << "</td><td>" << ignoreCount << "</td><td>" << bpIgnoreCount << "</td></tr>";
Friedemann Kleint's avatar
Friedemann Kleint committed
231
232
    str << "</table></body></html>";
    return rc;
con's avatar
con committed
233
234
}

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
QString BreakpointData::toString() const
{
    QString rc;
    QTextStream str(&rc);
    str << BreakHandler::tr("Marker File:") << markerFileName << ' ';
    str << BreakHandler::tr("Marker Line:") << markerLineNumber << ' ';
    str << BreakHandler::tr("Breakpoint Number:") << bpNumber << ' ';
    str << BreakHandler::tr("Breakpoint Address:") << bpAddress << '\n';
    str << BreakHandler::tr("File Name:")
        << fileName << " -- " << bpFileName << '\n';
    str << BreakHandler::tr("Function Name:")
        << funcName << " -- " << bpFuncName << '\n';
    str << BreakHandler::tr("Line Number:")
        << lineNumber << " -- " << bpLineNumber << '\n';
    str << BreakHandler::tr("Condition:")
        << condition << " -- " << bpCondition << '\n';
    str << BreakHandler::tr("Ignore Count:")
        << ignoreCount << " -- " << bpIgnoreCount << '\n';
    return rc;
}

con's avatar
con committed
256
257
258
259
260
261
262
263
264
265
266
bool BreakpointData::isLocatedAt(const QString &fileName_, int lineNumber_) const
{
    /*
    if (lineNumber != QString::number(lineNumber_))
        return false;
    if (fileName == fileName_)
        return true;
    if (fileName_.endsWith(fileName))
        return true;
    return false;
    */
267
    return lineNumber_ == markerLineNumber && fileNameMatch(fileName_, markerFileName);
con's avatar
con committed
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
}

bool BreakpointData::conditionsMatch() const
{
    // same versions of gdb "beautify" the passed condition
    QString s1 = condition;
    s1.remove(QChar(' '));
    QString s2 = bpCondition;
    s2.remove(QChar(' '));
    return s1 == s2;
}


//////////////////////////////////////////////////////////////////
//
// BreakHandler
//
//////////////////////////////////////////////////////////////////

287
288
289
290
291
292
293
294
BreakHandler::BreakHandler(DebuggerManager *manager, QObject *parent) :
    QAbstractTableModel(parent),
    m_breakpointIcon(QLatin1String(":/debugger/images/breakpoint.svg")),
    m_disabledBreakpointIcon(QLatin1String(":/debugger/images/breakpoint_disabled.svg")),
    m_pendingBreakPointIcon(QLatin1String(":/debugger/images/breakpoint_pending.svg")),
    m_manager(manager)
{
}
con's avatar
con committed
295

hjk's avatar
hjk committed
296
297
298
299
300
BreakHandler::~BreakHandler()
{
    clear();
}

con's avatar
con committed
301
302
int BreakHandler::columnCount(const QModelIndex &parent) const
{
303
    return parent.isValid() ? 0 : 7;
con's avatar
con committed
304
305
306
307
308
309
310
}

int BreakHandler::rowCount(const QModelIndex &parent) const
{
    return parent.isValid() ? 0 : size();
}

311
312
313
314
315
316
317
318
bool BreakHandler::hasPendingBreakpoints() const
{
    for (int i = size() - 1; i >= 0; i--)
        if (at(i)->pending)
            return true;
    return false;
}

con's avatar
con committed
319
320
321
322
323
324
325
326
327
void BreakHandler::removeAt(int index)
{
    BreakpointData *data = at(index);
    m_bp.removeAt(index);
    delete data;
}

void BreakHandler::clear()
{
328
329
330
331
332
333
    qDeleteAll(m_bp);
    m_bp.clear();
    m_enabled.clear();
    m_disabled.clear();
    m_removed.clear();
    m_inserted.clear();
con's avatar
con committed
334
335
336
337
338
339
340
341
342
343
344
345
}

int BreakHandler::findBreakpoint(const BreakpointData &needle)
{
    // looks for a breakpoint we might refer to
    for (int index = 0; index != size(); ++index) {
        const BreakpointData *data = at(index);
        // clear hit.
        if (data->bpNumber == needle.bpNumber)
            return index;
        // at least at a position we were looking for
        // FIXME: breaks multiple breakpoints at the same location
346
        if (fileNameMatch(data->fileName, needle.bpFileName)
con's avatar
con committed
347
348
349
350
351
352
                && data->lineNumber == needle.bpLineNumber)
            return index;
    }
    return -1;
}

353
354
355
356
357
358
359
360
int BreakHandler::findBreakpoint(const QString &fileName, int lineNumber)
{
    for (int index = 0; index != size(); ++index)
        if (at(index)->isLocatedAt(fileName, lineNumber))
            return index;
    return -1;
}

con's avatar
con committed
361
362
int BreakHandler::findBreakpoint(int bpNumber)
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
363
364
365
    if (!size())
        return -1;
    QString numStr = QString::number(bpNumber);
con's avatar
con committed
366
    for (int index = 0; index != size(); ++index)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
367
        if (at(index)->bpNumber == numStr)
con's avatar
con committed
368
369
370
371
372
373
374
375
376
377
378
            return index;
    return -1;
}

void BreakHandler::saveBreakpoints()
{
    QList<QVariant> list;
    for (int index = 0; index != size(); ++index) {
        const BreakpointData *data = at(index);
        QMap<QString, QVariant> map;
        if (!data->fileName.isEmpty())
379
            map.insert(QLatin1String("filename"), data->fileName);
con's avatar
con committed
380
        if (!data->lineNumber.isEmpty())
381
            map.insert(QLatin1String("linenumber"), data->lineNumber);
con's avatar
con committed
382
        if (!data->funcName.isEmpty())
383
            map.insert(QLatin1String("funcname"), data->funcName);
con's avatar
con committed
384
        if (!data->condition.isEmpty())
385
            map.insert(QLatin1String("condition"), data->condition);
con's avatar
con committed
386
        if (!data->ignoreCount.isEmpty())
387
            map.insert(QLatin1String("ignorecount"), data->ignoreCount);
388
        if (!data->enabled)
389
            map.insert(QLatin1String("disabled"), QLatin1String("1"));
390
        if (data->useFullPath)
391
            map.insert(QLatin1String("usefullpath"), QLatin1String("1"));
con's avatar
con committed
392
393
        list.append(map);
    }
394
    m_manager->setSessionValue("Breakpoints", list);
con's avatar
con committed
395
396
397
398
}

void BreakHandler::loadBreakpoints()
{
399
    QVariant value = m_manager->sessionValue("Breakpoints");
con's avatar
con committed
400
401
402
403
404
    QList<QVariant> list = value.toList();
    clear();
    foreach (const QVariant &var, list) {
        const QMap<QString, QVariant> map = var.toMap();
        BreakpointData *data = new BreakpointData(this);
405
406
407
408
409
        QVariant v = map.value(QLatin1String("filename"));
        if (v.isValid())
            data->fileName = v.toString();
        v = map.value(QLatin1String("linenumber"));
        if (v.isValid())
410
            data->lineNumber = v.toString().toLatin1();
411
412
        v = map.value(QLatin1String("condition"));
        if (v.isValid())
413
            data->condition = v.toString().toLatin1();
414
415
        v = map.value(QLatin1String("ignorecount"));
        if (v.isValid())
416
            data->ignoreCount = v.toString().toLatin1();
417
418
419
420
421
422
423
424
425
        v = map.value(QLatin1String("funcname"));
        if (v.isValid())
            data->funcName = v.toString();
        v = map.value(QLatin1String("disabled"));
        if (v.isValid())
            data->enabled = !v.toInt();
        v = map.value(QLatin1String("usefullpath"));
        if (v.isValid())
            data->useFullPath = bool(v.toInt());
con's avatar
con committed
426
427
428
429
430
431
432
433
434
435
436
        data->markerFileName = data->fileName;
        data->markerLineNumber = data->lineNumber.toInt();
        append(data);
    }
}

void BreakHandler::resetBreakpoints()
{
    for (int index = size(); --index >= 0;) {
        BreakpointData *data = at(index);
        data->pending = true;
437
438
        data->bpMultiple = false;
        data->bpEnabled = true;
con's avatar
con committed
439
440
441
442
443
444
        data->bpNumber.clear();
        data->bpFuncName.clear();
        data->bpFileName.clear();
        data->bpLineNumber.clear();
        data->bpCondition.clear();
        data->bpIgnoreCount.clear();
445
        data->bpAddress.clear();
con's avatar
con committed
446
447
448
449
450
451
        // keep marker data if it was primary
        if (data->markerFileName != data->fileName)
            data->markerFileName.clear();
        if (data->markerLineNumber != data->lineNumber.toInt())
            data->markerLineNumber = 0;
    }
452
453
454
455
    m_enabled.clear();
    m_disabled.clear();
    m_removed.clear();
    m_inserted.clear();
con's avatar
con committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
}

void BreakHandler::updateMarkers()
{
    for (int index = 0; index != size(); ++index)
        at(index)->updateMarker();
    emit layoutChanged();
}

QVariant BreakHandler::headerData(int section,
    Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
        static QString headers[] = {
            tr("Number"),  tr("Function"), tr("File"), tr("Line"),
471
            tr("Condition"), tr("Ignore"), tr("Address")
con's avatar
con committed
472
473
474
475
476
477
478
479
480
481
        };
        return headers[section];
    }
    return QVariant();
}

QVariant BreakHandler::data(const QModelIndex &mi, int role) const
{
    static const QString empty = QString(QLatin1Char('-'));

hjk's avatar
hjk committed
482
    QTC_ASSERT(mi.isValid(), return QVariant());
con's avatar
con committed
483
484
485
486
487
488
489
490

    if (mi.row() >= size())
        return QVariant();

    const BreakpointData *data = at(mi.row());
    switch (mi.column()) {
        case 0:
            if (role == Qt::DisplayRole) {
491
                const QString str = data->bpNumber;
con's avatar
con committed
492
493
                return str.isEmpty() ? empty : str;
            }
494
495
            if (role == Qt::UserRole)
                return data->enabled;
496
497
498
499
500
            if (role == Qt::DecorationRole) {
                if (!data->enabled)
                    return m_disabledBreakpointIcon;
                return data->pending ? m_pendingBreakPointIcon : m_breakpointIcon;
            }
con's avatar
con committed
501
502
503
            break;
        case 1:
            if (role == Qt::DisplayRole) {
504
                const QString str = data->pending ? data->funcName : data->bpFuncName;
con's avatar
con committed
505
506
507
508
509
510
511
                return str.isEmpty() ? empty : str;
            }
            break;
        case 2:
            if (role == Qt::DisplayRole) {
                QString str = data->pending ? data->fileName : data->bpFileName;
                str = QFileInfo(str).fileName();
hjk's avatar
hjk committed
512
513
514
                // FIXME: better?
                //if (data->bpMultiple && str.isEmpty() && !data->markerFileName.isEmpty())
                //    str = data->markerFileName;
515
516
                str = str.isEmpty() ? empty : str;
                if (data->useFullPath)
517
                    str = "/.../" + str;
518
                return str;
con's avatar
con committed
519
            }
520
521
            if (role == Qt::UserRole)
                return data->useFullPath;
con's avatar
con committed
522
523
524
            break;
        case 3:
            if (role == Qt::DisplayRole) {
hjk's avatar
hjk committed
525
526
527
                // FIXME: better?
                //if (data->bpMultiple && str.isEmpty() && !data->markerFileName.isEmpty())
                //    str = data->markerLineNumber;
528
                const QString str = data->pending ? data->lineNumber : data->bpLineNumber;
con's avatar
con committed
529
530
531
532
533
534
535
536
537
538
539
540
541
542
                return str.isEmpty() ? empty : str;
            }
            break;
        case 4:
            if (role == Qt::DisplayRole)
                return data->pending ? data->condition : data->bpCondition;
            if (role == Qt::ToolTipRole)
                return tr("Breakpoint will only be hit if this condition is met.");
            break;
        case 5:
            if (role == Qt::DisplayRole)
                return data->pending ? data->ignoreCount : data->bpIgnoreCount;
            if (role == Qt::ToolTipRole)
                return tr("Breakpoint will only be hit after being ignored so many times.");
543
544
545
        case 6:
            if (role == Qt::DisplayRole)
                return data->bpAddress;
con's avatar
con committed
546
547
548
            break;
    }
    if (role == Qt::ToolTipRole)
549
        return theDebuggerBoolSetting(UseToolTipsInBreakpointsView)
550
                ? data->toToolTip() : QVariant();
con's avatar
con committed
551
552
553
    return QVariant();
}

554
555
556
557
558
559
Qt::ItemFlags BreakHandler::flags(const QModelIndex &mi) const
{
    switch (mi.column()) {
        //case 0:
        //    return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
        default:
560
            return QAbstractTableModel::flags(mi);
561
562
563
    }
}

con's avatar
con committed
564
565
566
567
568
569
570
bool BreakHandler::setData(const QModelIndex &mi, const QVariant &value, int role)
{
    if (role != Qt::EditRole)
        return false;

    BreakpointData *data = at(mi.row());
    switch (mi.column()) {
571
572
573
574
575
576
577
        case 0: {
            if (data->enabled != value.toBool()) {
                toggleBreakpointEnabled(data);
                dataChanged(mi, mi);
            }
            return true;
        }
578
579
580
581
582
583
584
        case 2: {
            if (data->useFullPath != value.toBool()) {
                data->useFullPath = value.toBool();
                dataChanged(mi, mi);
            }
            return true;
        }
con's avatar
con committed
585
586
587
        case 4: {
            QString val = value.toString();
            if (val != data->condition) {
588
                data->condition = val.toLatin1();
con's avatar
con committed
589
590
591
592
593
594
595
                dataChanged(mi, mi);
            }
            return true;
        }
        case 5: {
            QString val = value.toString();
            if (val != data->ignoreCount) {
596
                data->ignoreCount = val.toLatin1();
con's avatar
con committed
597
598
599
600
                dataChanged(mi, mi);
            }
            return true;
        }
601
        default: {
con's avatar
con committed
602
603
604
605
606
            return false;
        }
    }
}

Friedemann Kleint's avatar
Friedemann Kleint committed
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
void BreakHandler::append(BreakpointData *data)
{
    m_bp.append(data);
    m_inserted.append(data);
}

QList<BreakpointData *> BreakHandler::insertedBreakpoints() const
{
    return m_inserted;
}

void BreakHandler::takeInsertedBreakPoint(BreakpointData *d)
{
    m_inserted.removeAll(d);
}

con's avatar
con committed
623
624
625
626
627
628
629
QList<BreakpointData *> BreakHandler::takeRemovedBreakpoints()
{
    QList<BreakpointData *> result = m_removed;
    m_removed.clear();
    return result;
}

630
631
632
633
634
635
636
637
638
639
640
641
642
643
QList<BreakpointData *> BreakHandler::takeEnabledBreakpoints()
{
    QList<BreakpointData *> result = m_enabled;
    m_enabled.clear();
    return result;
}

QList<BreakpointData *> BreakHandler::takeDisabledBreakpoints()
{
    QList<BreakpointData *> result = m_disabled;
    m_disabled.clear();
    return result;
}

con's avatar
con committed
644
645
646
647
648
649
650
651
652
653
654
655
void BreakHandler::removeBreakpointHelper(int index)
{
    BreakpointData *data = m_bp.at(index);
    m_bp.removeAt(index);
    data->removeMarker();
    m_removed.append(data);
}

void BreakHandler::removeBreakpoint(int index)
{
    if (index < 0 || index >= size())
        return;
656
    removeBreakpointHelper(index);
con's avatar
con committed
657
658
659
660
    emit layoutChanged();
    saveBreakpoints();
}

661
662
663
664
665
666
667
668
669
670
671
672
673
674
void BreakHandler::toggleBreakpointEnabled(BreakpointData *data)
{
    QTC_ASSERT(data, return);
    data->enabled = !data->enabled;
    if (data->enabled) {
        m_enabled.append(data);
        m_disabled.removeAll(data);
    } else {
        m_enabled.removeAll(data);
        m_disabled.append(data);
    }
    saveBreakpoints();
    updateMarkers();
}
con's avatar
con committed
675

676
void BreakHandler::toggleBreakpointEnabled(const QString &fileName, int lineNumber)
con's avatar
con committed
677
{
678
    toggleBreakpointEnabled(at(findBreakpoint(fileName, lineNumber)));
con's avatar
con committed
679
680
681
682
683
684
685
686
}

void BreakHandler::setBreakpoint(const QString &fileName, int lineNumber)
{
    QFileInfo fi(fileName);

    BreakpointData *data = new BreakpointData(this);
    data->fileName = fileName;
687
    data->lineNumber = QByteArray::number(lineNumber);
con's avatar
con committed
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
    data->pending = true;
    data->markerFileName = fileName;
    data->markerLineNumber = lineNumber;
    append(data);
    emit layoutChanged();
    saveBreakpoints();
    updateMarkers();
}

void BreakHandler::removeAllBreakpoints()
{
    for (int index = size(); --index >= 0;)
        removeBreakpointHelper(index);
    emit layoutChanged();
    saveBreakpoints();
    updateMarkers();
}

void BreakHandler::setAllPending()
{
    loadBreakpoints();
    for (int index = size(); --index >= 0;)
        at(index)->pending = true;
    saveBreakpoints();
    updateMarkers();
}

void BreakHandler::saveSessionData()
{
    saveBreakpoints();
    updateMarkers();
}

void BreakHandler::loadSessionData()
{
    //resetBreakpoints();
    loadBreakpoints();
    updateMarkers();
}

728
void BreakHandler::activateBreakpoint(int index)
con's avatar
con committed
729
730
731
{
    const BreakpointData *data = at(index);
    //qDebug() << "BREAKPOINT ACTIVATED: " << data->fileName;
732
733
734
735
736
737
    if (!data->markerFileName.isEmpty()) {
        StackFrame frame;
        frame.file = data->markerFileName;
        frame.line = data->markerLineNumber;
        m_manager->gotoLocation(frame, false);
    }
con's avatar
con committed
738
739
740
741
742
743
744
}

void BreakHandler::breakByFunction(const QString &functionName)
{
    // One per function is enough for now
    for (int index = size(); --index >= 0;) {
        const BreakpointData *data = at(index);
hjk's avatar
hjk committed
745
        QTC_ASSERT(data, break);
con's avatar
con committed
746
747
748
749
750
751
752
753
754
755
756
757
        if (data->funcName == functionName && data->condition.isEmpty()
                && data->ignoreCount.isEmpty())
            return;
    }
    BreakpointData *data = new BreakpointData(this);
    data->funcName = functionName;
    append(data);
    saveBreakpoints();
    updateMarkers();
}

#include "breakhandler.moc"