~ubuntu-branches/ubuntu/trusty/kdevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to debuggers/gdb/unittests/gdbtest.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2013-12-09 18:54:59 UTC
  • mfrom: (1.7.19)
  • Revision ID: package-import@ubuntu.com-20131209185459-zlxv7jo7up8gthne
Tags: 4:4.6.0-0ubuntu1
* New upstream release (LP: #1259220)
* Update install files 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
   Copyright 2009 Niko Sams <niko.sams@gmail.com>
 
3
   Copyright 2013 Vlas Puhov <vlas.puhov@mail.ru>
3
4
 
4
5
   This library is free software; you can redistribute it and/or
5
6
   modify it under the terms of the GNU Library General Public
29
30
#include <KSharedConfig>
30
31
#include <KDebug>
31
32
#include <KProcess>
 
33
#include <KStandardDirs>
32
34
#include <qtest_kde.h>
33
35
 
34
36
#include <tests/testcore.h>
38
40
#include <debugger/breakpoint/breakpoint.h>
39
41
#include <debugger/interfaces/ibreakpointcontroller.h>
40
42
#include <interfaces/ilaunchconfiguration.h>
 
43
#include <interfaces/iplugincontroller.h>
41
44
#include <debugger/variable/variablecollection.h>
42
45
#include <debugger/interfaces/ivariablecontroller.h>
43
46
#include <debugger/framestack/framestackmodel.h>
44
47
#include <tests/autotestshell.h>
 
48
#include <execute/iexecuteplugin.h>
45
49
 
46
50
#include "gdbcommand.h"
47
51
#include "debugsession.h"
72
76
{
73
77
    AutoTestShell::init();
74
78
    KDevelop::TestCore::initialize(KDevelop::Core::NoUi);
 
79
 
 
80
    m_iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecutePlugin", "kdevexecute")->extension<IExecutePlugin>();
 
81
    Q_ASSERT(m_iface);
75
82
}
76
83
 
77
84
void GdbTest::cleanupTestCase()
196
203
    QSignalSpy outputSpy(session, SIGNAL(applicationStandardOutputLines(QStringList)));
197
204
 
198
205
    TestLaunchConfiguration cfg;
199
 
    session->startProgram(&cfg);
 
206
    session->startProgram(&cfg, m_iface);
200
207
    WAIT_FOR_STATE(session, KDevelop::IDebugSession::EndedState);
201
208
 
202
209
    {
216
223
    KDevelop::Breakpoint * b = breakpoints()->addCodeBreakpoint(debugeeFileName, 28);
217
224
    QCOMPARE(session->breakpointController()->breakpointState(b), KDevelop::Breakpoint::NotStartedState);
218
225
 
219
 
    session->startProgram(&cfg);
 
226
    session->startProgram(&cfg, m_iface);
220
227
    WAIT_FOR_STATE(session, DebugSession::PausedState);
221
228
    QCOMPARE(session->breakpointController()->breakpointState(b), KDevelop::Breakpoint::CleanState);
222
229
    session->stepInto();
229
236
 
230
237
void GdbTest::testDisableBreakpoint()
231
238
{
 
239
    //Description: We must stop only on the third breakpoint
 
240
 
 
241
    int firstBreakLine=28;
 
242
    int secondBreakLine=23;
 
243
    int thirdBreakLine=24;
 
244
    int fourthBreakLine=31;
 
245
 
232
246
    TestDebugSession *session = new TestDebugSession;
233
247
 
234
248
    TestLaunchConfiguration cfg;
235
249
 
236
250
    KDevelop::Breakpoint *b;
237
251
 
238
 
    //add disabled breakpoint before startProgram
239
 
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, 29);
240
 
    b->setData(KDevelop::Breakpoint::EnableColumn, false);
241
 
 
242
 
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, 21);
243
 
    session->startProgram(&cfg);
 
252
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, firstBreakLine);
 
253
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
 
254
 
 
255
 
 
256
    //this is needed to emulate debug from GUI. If we are in edit mode, the debugSession doesn't exist.
 
257
    KDevelop::ICore::self()->debugController()->breakpointModel()->blockSignals(true);
 
258
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, secondBreakLine);
 
259
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
 
260
    //all disabled breakpoints were added
 
261
 
 
262
    KDevelop::Breakpoint * thirdBreak = breakpoints()->addCodeBreakpoint(debugeeFileName, thirdBreakLine);
 
263
    KDevelop::ICore::self()->debugController()->breakpointModel()->blockSignals(false);
 
264
 
 
265
 
 
266
    session->startProgram(&cfg, m_iface);
244
267
    WAIT_FOR_STATE(session, DebugSession::PausedState);
245
268
 
 
269
    QCOMPARE(session->currentLine(), thirdBreak->line());
 
270
 
246
271
    //disable existing breakpoint
247
 
    b->setData(KDevelop::Breakpoint::EnableColumn, false);
 
272
    thirdBreak->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
248
273
 
249
274
    //add another disabled breakpoint
250
 
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, 31);
 
275
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, fourthBreakLine);
251
276
    QTest::qWait(300);
252
 
    b->setData(KDevelop::Breakpoint::EnableColumn, false);
 
277
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
253
278
 
254
279
    QTest::qWait(300);
255
280
    session->run();
256
281
    WAIT_FOR_STATE(session, DebugSession::EndedState);
257
 
 
258
282
}
259
283
 
260
284
void GdbTest::testChangeLocationBreakpoint()
265
289
 
266
290
    KDevelop::Breakpoint *b = breakpoints()->addCodeBreakpoint(debugeeFileName, 27);
267
291
 
268
 
    session->startProgram(&cfg);
 
292
    session->startProgram(&cfg, m_iface);
269
293
    WAIT_FOR_STATE(session, DebugSession::PausedState);
270
294
    QCOMPARE(session->line(), 27);
271
295
 
306
330
 
307
331
    breakpoints()->addCodeBreakpoint(debugeeFileName, 22);
308
332
 
309
 
    session->startProgram(&cfg);
 
333
    session->startProgram(&cfg, m_iface);
310
334
    WAIT_FOR_STATE(session, DebugSession::PausedState);
311
335
    breakpoints()->removeRow(0);
312
336
    QTest::qWait(100);
325
349
    KDevelop::Breakpoint * b = breakpoints()->addCodeBreakpoint(findSourceFile("/gdbtest.cpp"), 10);
326
350
    QCOMPARE(session->breakpointController()->breakpointState(b), KDevelop::Breakpoint::NotStartedState);
327
351
 
328
 
    session->startProgram(&cfg);
 
352
    session->startProgram(&cfg, m_iface);
329
353
    WAIT_FOR_STATE(session, DebugSession::PausedState);
330
354
    QCOMPARE(session->breakpointController()->breakpointState(b), KDevelop::Breakpoint::PendingState);
331
355
    session->run();
340
364
    KDevelop::Breakpoint * b = breakpoints()->addCodeBreakpoint(debugeeFileName, 28);
341
365
    QCOMPARE(KDevelop::ICore::self()->debugController()->breakpointModel()->rowCount(), 2);
342
366
 
343
 
    session->startProgram(&cfg);
 
367
    session->startProgram(&cfg, m_iface);
344
368
 
345
369
    //insert custom command as user might do it using GDB console
346
370
    session->addCommand(new UserCommand(GDBMI::NonMI, "break "+debugeeFileName+":28"));
367
391
 
368
392
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, 22);
369
393
 
370
 
    session->startProgram(&cfg);
 
394
    session->startProgram(&cfg, m_iface);
371
395
 
372
396
    WAIT_FOR_STATE(session, DebugSession::PausedState);
373
397
    QTest::qWait(100);
391
415
 
392
416
    b = breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
393
417
 
394
 
    session->startProgram(&cfg);
 
418
    session->startProgram(&cfg, m_iface);
395
419
 
396
420
    WAIT_FOR_STATE(session, DebugSession::PausedState);
397
421
    QCOMPARE(session->line(), 24);
414
438
    
415
439
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
416
440
 
417
 
    session->startProgram(&cfg);
 
441
    session->startProgram(&cfg, m_iface);
418
442
 
419
443
    WAIT_FOR_STATE(session, DebugSession::PausedState);
420
444
    QCOMPARE(session->line(), 24);
439
463
 
440
464
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
441
465
 
442
 
    session->startProgram(&cfg);
 
466
    session->startProgram(&cfg, m_iface);
443
467
 
444
468
    WAIT_FOR_STATE(session, DebugSession::PausedState);
445
469
    QCOMPARE(session->line(), 24);
468
492
 
469
493
    KDevelop::Breakpoint *b = breakpoints()->addReadWatchpoint("foo::i");
470
494
 
471
 
    session->startProgram(&cfg);
 
495
    session->startProgram(&cfg, m_iface);
472
496
 
473
497
    WAIT_FOR_STATE(session, DebugSession::PausedState);
474
498
    QCOMPARE(session->line(), 23);
484
508
 
485
509
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
486
510
 
487
 
    session->startProgram(&cfg);
 
511
    session->startProgram(&cfg, m_iface);
488
512
 
489
513
    WAIT_FOR_STATE(session, DebugSession::PausedState);
490
514
    QCOMPARE(session->line(), 24);
510
534
 
511
535
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
512
536
 
513
 
    session->startProgram(&cfg);
 
537
    session->startProgram(&cfg, m_iface);
514
538
 
515
539
    WAIT_FOR_STATE(session, DebugSession::PausedState);
516
540
    QCOMPARE(session->line(), 24);
540
564
    TestLaunchConfiguration cfg(findExecutable("debugeeslow"));
541
565
    QString fileName = findSourceFile("debugeeslow.cpp");
542
566
 
543
 
    session->startProgram(&cfg);
 
567
    session->startProgram(&cfg, m_iface);
544
568
 
545
569
    WAIT_FOR_STATE(session, DebugSession::ActiveState);
546
570
    QTest::qWait(2000);
560
584
    TestLaunchConfiguration cfg(findExecutable("debugeeslow"));
561
585
    QString fileName = findSourceFile("debugeeslow.cpp");
562
586
 
563
 
    session->startProgram(&cfg);
 
587
    session->startProgram(&cfg, m_iface);
564
588
 
565
589
    WAIT_FOR_STATE(session, DebugSession::ActiveState);
566
590
    QTest::qWait(2000);
586
610
 
587
611
    breakpoints()->addCodeBreakpoint("main");
588
612
 
589
 
    session->startProgram(&cfg);
 
613
    session->startProgram(&cfg, m_iface);
590
614
    WAIT_FOR_STATE(session, DebugSession::PausedState);
591
615
    QCOMPARE(session->line(), 27);
592
616
    session->run();
603
627
    TestLaunchConfiguration cfg;
604
628
 
605
629
    breakpoints()->addCodeBreakpoint(debugeeFileName, 29);
606
 
    session->startProgram(&cfg);
 
630
    session->startProgram(&cfg, m_iface);
607
631
    WAIT_FOR_STATE(session, DebugSession::PausedState);
608
632
    session->stepInto();
609
633
    WAIT_FOR_STATE(session, DebugSession::PausedState);
636
660
    TestFrameStackModel *stackModel = session->frameStackModel();
637
661
    
638
662
    breakpoints()->addCodeBreakpoint(debugeeFileName, 21);
639
 
    QVERIFY(session->startProgram(&cfg));
 
663
    QVERIFY(session->startProgram(&cfg, m_iface));
640
664
    WAIT_FOR_STATE(session, DebugSession::PausedState);
641
665
 
642
666
    QModelIndex tIdx = stackModel->index(0,0);    
678
702
    TestFrameStackModel *stackModel = session->frameStackModel();
679
703
 
680
704
    breakpoints()->addCodeBreakpoint(fileName, 25);
681
 
    QVERIFY(session->startProgram(&cfg));
 
705
    QVERIFY(session->startProgram(&cfg, m_iface));
682
706
    WAIT_FOR_STATE(session, DebugSession::PausedState);
683
707
    QCOMPARE(session->frameStackModel()->fetchFramesCalled, 1);
684
708
 
713
737
    stackModel->fetchMoreFrames();
714
738
    QTest::qWait(200);
715
739
    QCOMPARE(stackModel->fetchFramesCalled, 3);
716
 
    QCOMPARE(stackModel->rowCount(tIdx), 61);
 
740
    QCOMPARE(stackModel->rowCount(tIdx), 121);
717
741
    COMPARE_DATA(tIdx.child(40, 0), "40");
718
742
    COMPARE_DATA(tIdx.child(41, 0), "41");
719
743
    COMPARE_DATA(tIdx.child(42, 0), "42");
720
 
    COMPARE_DATA(tIdx.child(60, 0), "60");
 
744
    COMPARE_DATA(tIdx.child(119, 0), "119");
 
745
    COMPARE_DATA(tIdx.child(120, 0), "120");
721
746
 
722
747
    stackModel->fetchMoreFrames();
723
748
    QTest::qWait(200);
724
749
    QCOMPARE(stackModel->fetchFramesCalled, 4);
725
 
    QCOMPARE(stackModel->rowCount(tIdx), 81);
726
 
 
727
 
    stackModel->fetchMoreFrames();
728
 
    QTest::qWait(200);
729
 
    QCOMPARE(stackModel->fetchFramesCalled, 5);
730
 
    QCOMPARE(stackModel->rowCount(tIdx), 101);
731
 
    COMPARE_DATA(tIdx.child(100, 0), "100");
732
 
    COMPARE_DATA(tIdx.child(100, 1), "main");
733
 
    COMPARE_DATA(tIdx.child(100, 2), fileName+":30");
 
750
    QCOMPARE(stackModel->rowCount(tIdx), 301);
 
751
    COMPARE_DATA(tIdx.child(120, 0), "120");
 
752
    COMPARE_DATA(tIdx.child(121, 0), "121");
 
753
    COMPARE_DATA(tIdx.child(122, 0), "122");
 
754
    COMPARE_DATA(tIdx.child(300, 0), "300");
 
755
    COMPARE_DATA(tIdx.child(300, 1), "main");
 
756
    COMPARE_DATA(tIdx.child(300, 2), fileName+":30");
734
757
 
735
758
    stackModel->fetchMoreFrames(); //nothing to fetch, we are at the end
736
759
    QTest::qWait(200);
737
 
    QCOMPARE(stackModel->fetchFramesCalled, 5);
738
 
    QCOMPARE(stackModel->rowCount(tIdx), 101);
 
760
    QCOMPARE(stackModel->fetchFramesCalled, 4);
 
761
    QCOMPARE(stackModel->rowCount(tIdx), 301);
739
762
 
740
763
    session->run();
741
764
    WAIT_FOR_STATE(session, DebugSession::EndedState);
749
772
    TestFrameStackModel *stackModel = session->frameStackModel();
750
773
 
751
774
    breakpoints()->addCodeBreakpoint(debugeeFileName, 21);
752
 
    QVERIFY(session->startProgram(&cfg));
 
775
    QVERIFY(session->startProgram(&cfg, m_iface));
753
776
    WAIT_FOR_STATE(session, DebugSession::PausedState);
754
777
 
755
778
    QModelIndex tIdx = stackModel->index(0,0);
778
801
    TestFrameStackModel *stackModel = session->frameStackModel();
779
802
 
780
803
    breakpoints()->addCodeBreakpoint(fileName, 38);
781
 
    QVERIFY(session->startProgram(&cfg));
 
804
    QVERIFY(session->startProgram(&cfg, m_iface));
782
805
    QTest::qWait(500);
783
806
    WAIT_FOR_STATE(session, DebugSession::PausedState);
784
807
 
804
827
 
805
828
void GdbTest::testAttach()
806
829
{
 
830
    // if on linux, ensure we can actually attach
 
831
    QFile canRun("/proc/sys/kernel/yama/ptrace_scope");
 
832
    if (canRun.exists()) {
 
833
        QVERIFY(canRun.open(QIODevice::ReadOnly));
 
834
        if (canRun.read(1).toInt() != 0) {
 
835
            QSKIP("ptrace attaching not allows, skipping test. To enable it, set /proc/sys/kernel/yama/ptrace_scope to 0.", SkipAll);
 
836
        }
 
837
    }
 
838
 
807
839
    QString fileName = findSourceFile("debugeeslow.cpp");
808
840
 
809
841
    KProcess debugeeProcess;
821
853
    session->run();
822
854
    QTest::qWait(2000);
823
855
    WAIT_FOR_STATE(session, DebugSession::PausedState);
824
 
    QCOMPARE(session->line(), 34);
 
856
    if (session->line() < 34 || session->line() < 35) {
 
857
        QCOMPARE(session->line(), 34);
 
858
    }
825
859
 
826
860
    session->run();
827
861
    WAIT_FOR_STATE(session, DebugSession::EndedState);
872
906
    TestLaunchConfiguration cfg;
873
907
 
874
908
    breakpoints()->addCodeBreakpoint(debugeeFileName, 22);
875
 
    QVERIFY(session->startProgram(&cfg));
 
909
    QVERIFY(session->startProgram(&cfg, m_iface));
876
910
    WAIT_FOR_STATE(session, DebugSession::PausedState);
877
911
    QTest::qWait(1000);
878
912
 
899
933
    TestLaunchConfiguration cfg;
900
934
 
901
935
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
902
 
    QVERIFY(session->startProgram(&cfg));
 
936
    QVERIFY(session->startProgram(&cfg, m_iface));
903
937
    WAIT_FOR_STATE(session, DebugSession::PausedState);
904
938
    QTest::qWait(1000);
905
939
 
945
979
    TestLaunchConfiguration cfg;
946
980
 
947
981
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
948
 
    QVERIFY(session->startProgram(&cfg));
 
982
    QVERIFY(session->startProgram(&cfg, m_iface));
949
983
    WAIT_FOR_STATE(session, DebugSession::PausedState);
950
984
    
951
985
    variableCollection()->watches()->add("ts");
988
1022
    const QString quotedTestString("\"" + testString + "\"");
989
1023
 
990
1024
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
991
 
    QVERIFY(session->startProgram(&cfg));
 
1025
    QVERIFY(session->startProgram(&cfg, m_iface));
992
1026
    WAIT_FOR_STATE(session, DebugSession::PausedState);
993
1027
 
994
1028
    variableCollection()->watches()->add(quotedTestString); //just a constant string
1026
1060
    TestLaunchConfiguration cfg;
1027
1061
 
1028
1062
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
1029
 
    QVERIFY(session->startProgram(&cfg));
 
1063
    QVERIFY(session->startProgram(&cfg, m_iface));
1030
1064
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1031
1065
    
1032
1066
    variableCollection()->watches()->add("ts");
1050
1084
    //start a second debug session
1051
1085
    session = new TestDebugSession;
1052
1086
    session->variableController()->setAutoUpdate(KDevelop::IVariableController::UpdateWatches);
1053
 
    QVERIFY(session->startProgram(&cfg));
 
1087
    QVERIFY(session->startProgram(&cfg, m_iface));
1054
1088
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1055
1089
    QTest::qWait(300);
1056
1090
 
1082
1116
    TestLaunchConfiguration cfg;
1083
1117
 
1084
1118
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
1085
 
    QVERIFY(session->startProgram(&cfg));
 
1119
    QVERIFY(session->startProgram(&cfg, m_iface));
1086
1120
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1087
1121
 
1088
1122
    session->stopDebugger();
1098
1132
    TestLaunchConfiguration cfg;
1099
1133
 
1100
1134
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
1101
 
    QVERIFY(session->startProgram(&cfg));
 
1135
    QVERIFY(session->startProgram(&cfg, m_iface));
1102
1136
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1103
1137
 
1104
1138
    session = new TestDebugSession;
1105
1139
    session->variableController()->setAutoUpdate(KDevelop::IVariableController::UpdateLocals);
1106
1140
 
1107
1141
    breakpoints()->addCodeBreakpoint(debugeeFileName, 38);
1108
 
    QVERIFY(session->startProgram(&cfg));
 
1142
    QVERIFY(session->startProgram(&cfg, m_iface));
1109
1143
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1110
1144
 
1111
1145
    session->run();
1121
1155
    TestFrameStackModel *stackModel = session->frameStackModel();
1122
1156
 
1123
1157
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
1124
 
    QVERIFY(session->startProgram(&cfg));
 
1158
    QVERIFY(session->startProgram(&cfg, m_iface));
1125
1159
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1126
1160
    QTest::qWait(500);
1127
1161
 
1154
1188
    TestFrameStackModel *stackModel = session->frameStackModel();
1155
1189
 
1156
1190
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
1157
 
    QVERIFY(session->startProgram(&cfg));
 
1191
    QVERIFY(session->startProgram(&cfg, m_iface));
1158
1192
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1159
1193
    QTest::qWait(500);
1160
1194
 
1200
1234
 
1201
1235
    breakpoints()->addCodeBreakpoint(fileName, 23);
1202
1236
 
1203
 
    QVERIFY(session->startProgram(&cfg));
 
1237
    QVERIFY(session->startProgram(&cfg, m_iface));
1204
1238
 
1205
1239
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1206
1240
    QCOMPARE(session->line(), 23);
1222
1256
    TestFrameStackModel *stackModel = session->frameStackModel();
1223
1257
 
1224
1258
    breakpoints()->addCodeBreakpoint(debugeeFileName, 24);
1225
 
    QVERIFY(session->startProgram(&cfg));
 
1259
    QVERIFY(session->startProgram(&cfg, m_iface));
1226
1260
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1227
1261
    QCOMPARE(stackModel->currentFrame(), 0);
1228
1262
    stackModel->setCurrentFrame(1);
1244
1278
    TestLaunchConfiguration cfg(findExecutable("debugeeslow"));
1245
1279
    QString fileName = findSourceFile("debugeeslow.cpp");
1246
1280
 
1247
 
    session->startProgram(&cfg);
 
1281
    session->startProgram(&cfg, m_iface);
1248
1282
 
1249
1283
    WAIT_FOR_STATE(session, DebugSession::ActiveState);
1250
1284
    QTest::qWait(2000);
1262
1296
    TestLaunchConfiguration cfg(findExecutable("debugeeqt"));
1263
1297
 
1264
1298
    breakpoints()->addCodeBreakpoint("main");
1265
 
    QVERIFY(session->startProgram(&cfg));
 
1299
    QVERIFY(session->startProgram(&cfg, m_iface));
1266
1300
    for(int i=0; i<20; i++) {
1267
1301
        session->stepInto();
1268
1302
    }
1278
1312
    TestLaunchConfiguration cfg;
1279
1313
 
1280
1314
    breakpoints()->addCodeBreakpoint("main");
1281
 
    QVERIFY(session->startProgram(&cfg));
 
1315
    QVERIFY(session->startProgram(&cfg, m_iface));
1282
1316
    session->addCommand(GDBMI::NonMI, "break debugee.cpp:32");
1283
1317
    session->stepInto();
1284
1318
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1299
1333
    TestLaunchConfiguration cfg;
1300
1334
 
1301
1335
    breakpoints()->addCodeBreakpoint(KUrl("debugee.cpp"), 31);
1302
 
    QVERIFY(session->startProgram(&cfg));
 
1336
    breakpoints()->addCodeBreakpoint(KUrl("debugee.cpp"), 21);
 
1337
    QVERIFY(session->startProgram(&cfg, m_iface));
1303
1338
 
1304
1339
    //inject here, so it behaves similar like a command from .gdbinit
1305
1340
    session->addCommandToFront(new GDBCommand(GDBMI::NonMI, "break debugee.cpp:32"));
 
1341
    session->addCommandToFront(new GDBCommand(GDBMI::NonMI, "break foo"));
1306
1342
 
1307
1343
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1308
1344
 
1309
1345
    session->stepInto();
1310
1346
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1311
1347
    QTest::qWait(1000); //wait for breakpoints update
1312
 
    QCOMPARE(breakpoints()->breakpoints().count(), 1);
1313
 
    QCOMPARE(breakpoints()->rowCount(), 1+1);
 
1348
    QCOMPARE(breakpoints()->breakpoints().count(), 2);
1314
1349
 
1315
1350
    KDevelop::Breakpoint *b = breakpoints()->breakpoint(0);
1316
1351
    QVERIFY(b);
1317
1352
    QCOMPARE(b->line(), 31); //we start with 0, gdb with 1
1318
1353
    QCOMPARE(b->url().url(), QString("debugee.cpp"));
 
1354
 
 
1355
    b = breakpoints()->breakpoint(1);
 
1356
    QVERIFY(b);
 
1357
    QCOMPARE(b->line(), 21);
 
1358
    QCOMPARE(b->url().url(), QString("debugee.cpp"));
1319
1359
}
1320
1360
 
1321
1361
void GdbTest::testRunGdbScript()
1334
1374
    KConfigGroup grp = cfg.config();
1335
1375
    grp.writeEntry(GDBDebugger::remoteGdbRunEntry, KUrl(runScript.fileName()));
1336
1376
 
1337
 
    QVERIFY(session->startProgram(&cfg));
 
1377
    QVERIFY(session->startProgram(&cfg, m_iface));
1338
1378
 
1339
1379
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1340
1380
 
1346
1386
 
1347
1387
void GdbTest::testRemoteDebug()
1348
1388
{
 
1389
    const QString gdbserverExecutable = KStandardDirs::findExe("gdbserver");
 
1390
    if (gdbserverExecutable.isEmpty()) {
 
1391
        QSKIP("Skipping, gdbserver not available", SkipSingle);
 
1392
    }
 
1393
 
1349
1394
    TestDebugSession *session = new TestDebugSession;
1350
1395
 
1351
1396
    QTemporaryFile shellScript(QDir::currentPath()+"/shellscript");
1368
1413
    grp.writeEntry(GDBDebugger::remoteGdbShellEntry, KUrl(shellScript.fileName()+"-copy"));
1369
1414
    grp.writeEntry(GDBDebugger::remoteGdbRunEntry, KUrl(runScript.fileName()));
1370
1415
 
1371
 
    QVERIFY(session->startProgram(&cfg));
 
1416
    QVERIFY(session->startProgram(&cfg, m_iface));
1372
1417
 
1373
1418
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1374
1419
 
1382
1427
 
1383
1428
void GdbTest::testRemoteDebugInsertBreakpoint()
1384
1429
{
 
1430
    const QString gdbserverExecutable = KStandardDirs::findExe("gdbserver");
 
1431
    if (gdbserverExecutable.isEmpty()) {
 
1432
        QSKIP("Skipping, gdbserver not available", SkipSingle);
 
1433
    }
 
1434
 
1385
1435
    TestDebugSession *session = new TestDebugSession;
1386
1436
 
1387
1437
    breakpoints()->addCodeBreakpoint(debugeeFileName, 35);
1406
1456
    grp.writeEntry(GDBDebugger::remoteGdbShellEntry, KUrl(shellScript.fileName()+"-copy"));
1407
1457
    grp.writeEntry(GDBDebugger::remoteGdbRunEntry, KUrl(runScript.fileName()));
1408
1458
 
1409
 
    QVERIFY(session->startProgram(&cfg));
 
1459
    QVERIFY(session->startProgram(&cfg, m_iface));
1410
1460
 
1411
1461
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1412
1462
 
1428
1478
 
1429
1479
void GdbTest::testRemoteDebugInsertBreakpointPickupOnlyOnce()
1430
1480
{
 
1481
    const QString gdbserverExecutable = KStandardDirs::findExe("gdbserver");
 
1482
    if (gdbserverExecutable.isEmpty()) {
 
1483
        QSKIP("Skipping, gdbserver not available", SkipSingle);
 
1484
    }
 
1485
 
1431
1486
    TestDebugSession *session = new TestDebugSession;
1432
1487
 
1433
1488
    breakpoints()->addCodeBreakpoint(debugeeFileName, 35);
1452
1507
    grp.writeEntry(GDBDebugger::remoteGdbShellEntry, KUrl(shellScript.fileName()+"-copy"));
1453
1508
    grp.writeEntry(GDBDebugger::remoteGdbRunEntry, KUrl(runScript.fileName()));
1454
1509
 
1455
 
    QVERIFY(session->startProgram(&cfg));
 
1510
    QVERIFY(session->startProgram(&cfg, m_iface));
1456
1511
 
1457
1512
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1458
1513
 
1470
1525
 
1471
1526
    //************************** second session
1472
1527
    session = new TestDebugSession;
1473
 
    QVERIFY(session->startProgram(&cfg));
 
1528
    QVERIFY(session->startProgram(&cfg, m_iface));
1474
1529
 
1475
1530
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1476
1531
 
1500
1555
    KDevelop::Breakpoint * b = breakpoints()->addCodeBreakpoint(fileName, 20);
1501
1556
    QCOMPARE(session->breakpointController()->breakpointState(b), KDevelop::Breakpoint::NotStartedState);
1502
1557
 
1503
 
    session->startProgram(&cfg);
 
1558
    session->startProgram(&cfg, m_iface);
1504
1559
    WAIT_FOR_STATE_FAIL(session, DebugSession::PausedState);
1505
1560
    QCOMPARE(session->line(), 20);
1506
1561
    session->run();
1519
1574
    KDevelop::Breakpoint* b = breakpoints()->addCodeBreakpoint(debugeeFileName, 31);
1520
1575
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
1521
1576
 
1522
 
    session->startProgram(&cfg);
 
1577
    session->startProgram(&cfg, m_iface);
1523
1578
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1524
1579
    QCOMPARE(session->line(), 29);
1525
1580
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Checked);
1539
1594
 
1540
1595
    breakpoints()->addCodeBreakpoint(findSourceFile("debugeeexception.cpp"), 29);
1541
1596
 
1542
 
    session->startProgram(&cfg);
 
1597
    session->startProgram(&cfg, m_iface);
1543
1598
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1544
1599
    QTest::qWait(1000);
1545
1600
    TestFrameStackModel* fsModel = session->frameStackModel();
1546
1601
    QCOMPARE(fsModel->currentFrame(), 0);
1547
1602
    QCOMPARE(session->line(), 29);
1548
1603
 
1549
 
    QModelIndex i = variableCollection()->index(1, 0);
1550
 
    COMPARE_DATA(i, "Locals");
1551
 
    qDebug() << variableCollection()->index(0, 1, i);
1552
 
    qDebug() << variableCollection()->index(1, 1, i);
1553
 
    QCOMPARE(variableCollection()->rowCount(i), 2);
1554
 
 
1555
1604
    session->addCommand(new GDBCommand(GDBMI::NonMI, "catch throw"));
1556
1605
    session->run();
1557
1606
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1558
1607
    QTest::qWait(1000);
1559
 
    QCOMPARE(fsModel->currentFrame(), 1); //first frame skiped because somewhere inside stdlib
1560
 
    QCOMPARE(session->line(), 22);
1561
 
 
1562
 
    qDebug() << variableCollection()->index(0, 1, i);
1563
 
    qDebug() << variableCollection()->index(1, 1, i);
1564
 
    QCOMPARE(variableCollection()->rowCount(i), 1);
1565
 
    COMPARE_DATA(variableCollection()->index(0, 0, i), "i");
1566
 
    COMPARE_DATA(variableCollection()->index(0, 1, i), "20");
 
1608
 
 
1609
    // TODO: Fix API in FrameStackModel? At least introduce FrameStackModel::frames(int)
 
1610
    typedef KDevelop::IFrameStackModel::FrameItem FrameItem;
 
1611
    QVector<FrameItem> frames;
 
1612
    const QModelIndex thread1Index = fsModel->index(0, 0);
 
1613
    for (int i = 0; i < fsModel->rowCount(thread1Index); ++i) {
 
1614
        FrameItem frame = fsModel->frame(fsModel->index(i, 0, thread1Index));
 
1615
        frames << frame;
 
1616
        qDebug() << frame.file << frame.line;
 
1617
    }
 
1618
 
 
1619
    QVERIFY(frames.size() >= 2);
 
1620
    // frame 0 is somewhere inside libstdc++
 
1621
    QCOMPARE(frames[1].file, KUrl(findSourceFile("debugeeexception.cpp")));
 
1622
    QCOMPARE(frames[1].line, 22);
1567
1623
 
1568
1624
    session->run();
1569
1625
    WAIT_FOR_STATE(session, DebugSession::EndedState);
1570
 
 
1571
1626
}
1572
1627
 
 
1628
//TODO: figure out why do we need this test? And do we need it at all??
1573
1629
void GdbTest::testThreadAndFrameInfo()
1574
1630
{
1575
1631
    TestDebugSession *session = new TestDebugSession;
1576
1632
    TestLaunchConfiguration cfg(findExecutable("debugeethreads"));
1577
1633
    QString fileName = findSourceFile("debugeethreads.cpp");
 
1634
 
 
1635
    breakpoints()->addCodeBreakpoint(fileName, 38);
 
1636
    QVERIFY(session->startProgram(&cfg, m_iface));
 
1637
    WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1638
    QTest::qWait(1000);
 
1639
 
1578
1640
    QSignalSpy outputSpy(session, SIGNAL(gdbUserCommandStdout(QString)));
1579
1641
 
1580
 
    breakpoints()->addCodeBreakpoint(fileName, 38);
1581
 
    QVERIFY(session->startProgram(&cfg));
1582
 
    session->frameStackModel()->fetchThreads();
 
1642
    session->addCommand(
 
1643
                new UserCommand(GDBMI::ThreadInfo,""));
1583
1644
    session->addCommand(new UserCommand(GDBMI::StackListLocals, QLatin1String("0")));
1584
 
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1585
1645
    QTest::qWait(1000);
1586
 
 
1587
 
    QVERIFY(outputSpy.count() == 2);
 
1646
    QCOMPARE(outputSpy.count(), 2);
1588
1647
    QVERIFY(outputSpy.last().at(0).toString().contains(QLatin1String("--thread 1")));
1589
1648
 
1590
1649
    session->run();
1629
1688
 
1630
1689
    //TODO check if the additional location breakpoint is added
1631
1690
 
1632
 
    session->startProgram(&cfg);
 
1691
    session->startProgram(&cfg, m_iface);
1633
1692
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1634
1693
    QCOMPARE(session->line(), 19);
1635
1694
 
1650
1709
 
1651
1710
    breakpoints()->addCodeBreakpoint(debugeeFileName, 28);
1652
1711
 
1653
 
    session->startProgram(&cfg);
 
1712
    session->startProgram(&cfg, m_iface);
1654
1713
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1655
1714
 
1656
1715
    variableCollection()->watches()->add("argc");
1668
1727
    session = new TestDebugSession;
1669
1728
    session->variableController()->setAutoUpdate(KDevelop::IVariableController::UpdateWatches);
1670
1729
 
1671
 
    session->startProgram(&cfg);
 
1730
    session->startProgram(&cfg, m_iface);
1672
1731
    WAIT_FOR_STATE(session, DebugSession::PausedState);
1673
1732
 
1674
1733
    QTest::qWait(300);
1682
1741
    WAIT_FOR_STATE(session, DebugSession::EndedState);
1683
1742
}
1684
1743
 
 
1744
void GdbTest::testMultipleBreakpoint()
 
1745
{
 
1746
        TestDebugSession *session = new TestDebugSession;
 
1747
 
 
1748
        //there'll be about 3-4 breakpoints, but we treat it like one.
 
1749
        TestLaunchConfiguration c(findExecutable("debugeemultiplebreakpoint"));
 
1750
        KDevelop::Breakpoint *b = breakpoints()->addCodeBreakpoint("debugeemultiplebreakpoint.cpp:52");
 
1751
        session->startProgram(&c, m_iface);
 
1752
        WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1753
        QCOMPARE(breakpoints()->breakpoints().count(), 1);
 
1754
 
 
1755
        b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
 
1756
        session->run();
 
1757
        WAIT_FOR_STATE(session, DebugSession::EndedState);
 
1758
}
 
1759
 
 
1760
void GdbTest::testRegularExpressionBreakpoint()
 
1761
{
 
1762
        TestDebugSession *session = new TestDebugSession;
 
1763
 
 
1764
        TestLaunchConfiguration c(findExecutable("debugeemultilocbreakpoint"));
 
1765
        breakpoints()->addCodeBreakpoint("main");
 
1766
        session->startProgram(&c, m_iface);
 
1767
        WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1768
        session->addCommand(new GDBCommand(GDBMI::NonMI, "rbreak .*aPl.*B"));
 
1769
        QTest::qWait(100);
 
1770
        session->run();
 
1771
        WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1772
        QCOMPARE(breakpoints()->breakpoints().count(), 3);
 
1773
 
 
1774
        session->addCommand(new GDBCommand(GDBMI::BreakDelete, ""));
 
1775
        session->run();
 
1776
        WAIT_FOR_STATE(session, DebugSession::EndedState);
 
1777
}
 
1778
 
 
1779
void GdbTest::testChangeBreakpointWhileRunning() {
 
1780
 
 
1781
    TestDebugSession *session = new TestDebugSession;
 
1782
 
 
1783
    TestLaunchConfiguration c(findExecutable("debugeeslow"));
 
1784
    KDevelop::Breakpoint* b = breakpoints()->addCodeBreakpoint("debugeeslow.cpp:25");
 
1785
    session->startProgram(&c, m_iface);
 
1786
    
 
1787
    WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1788
    QVERIFY(session->currentLine() >= 24 && session->currentLine() <= 26 );
 
1789
    session->run();
 
1790
    WAIT_FOR_STATE(session, DebugSession::ActiveState);
 
1791
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
 
1792
    //to make one loop
 
1793
    QTest::qWait(2000);
 
1794
    WAIT_FOR_STATE(session, DebugSession::ActiveState);
 
1795
    
 
1796
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Checked);
 
1797
    QTest::qWait(100);
 
1798
    WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1799
    b->setData(KDevelop::Breakpoint::EnableColumn, Qt::Unchecked);
 
1800
    session->run();
 
1801
    QTest::qWait(100);
 
1802
    WAIT_FOR_STATE(session, DebugSession::EndedState);
 
1803
}
 
1804
 
 
1805
void GdbTest::testDebugInExternalTerminal()
 
1806
{
 
1807
    TestLaunchConfiguration cfg;
 
1808
 
 
1809
    foreach (const QString & console, QStringList() << "konsole" << "xterm" << "xfce4-terminal" << "gnome-terminal") {
 
1810
 
 
1811
        TestDebugSession* session = 0;
 
1812
        if (KStandardDirs::findExe(console).isEmpty()) {
 
1813
            continue;
 
1814
        }
 
1815
 
 
1816
        session = new TestDebugSession();
 
1817
 
 
1818
        cfg.config().writeEntry("External Terminal"/*ExecutePlugin::terminalEntry*/, console);
 
1819
        cfg.config().writeEntry("Use External Terminal"/*ExecutePlugin::useTerminalEntry*/, true);
 
1820
 
 
1821
        KDevelop::Breakpoint* b = breakpoints()->addCodeBreakpoint(debugeeFileName, 28);
 
1822
 
 
1823
        session->startProgram(&cfg, m_iface);
 
1824
        WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1825
        QCOMPARE(session->breakpointController()->breakpointState(b), KDevelop::Breakpoint::CleanState);
 
1826
        session->stepInto();
 
1827
        WAIT_FOR_STATE(session, DebugSession::PausedState);
 
1828
        session->run();
 
1829
        WAIT_FOR_STATE(session, DebugSession::EndedState);
 
1830
    }
 
1831
}
 
1832
 
1685
1833
void GdbTest::waitForState(GDBDebugger::DebugSession *session, DebugSession::DebuggerState state,
1686
1834
                            const char *file, int line, bool expectFail)
1687
1835
{