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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "debuggerplugin.h"
#include "debuggeractions.h"
#include "debuggerinternalconstants.h"
#include "debuggercore.h"
#include "debuggerkitconfigwidget.h"
#include "debuggerdialogs.h"
#include "debuggerengine.h"
#include "debuggericons.h"
#include "debuggeritem.h"
#include "debuggeritemmanager.h"
#include "debuggermainwindow.h"
#include "debuggerrunconfigurationaspect.h"
#include "debuggerruncontrol.h"
#include "debuggerkitinformation.h"
#include "memoryagent.h"
#include "breakhandler.h"
#include "disassemblerlines.h"
#include "logwindow.h"
#include "moduleshandler.h"
#include "stackhandler.h"
#include "stackwindow.h"
#include "watchhandler.h"
#include "watchwindow.h"
#include "watchutils.h"
#include "unstartedappwatcherdialog.h"
#include "debuggertooltipmanager.h"
#include "localsandexpressionswindow.h"
#include "loadcoredialog.h"
#include "sourceutils.h"
#include "snapshothandler.h"
#include "shared/hostutils.h"
#include "console/console.h"
#include "snapshothandler.h"
#include "threadshandler.h"
#include "commonoptionspage.h"
#include "analyzer/analyzerconstants.h"
#include "analyzer/analyzermanager.h"
#include <app/app_version.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/find/itemviewfind.h>
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
#include <coreplugin/messagebox.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h>
#include <coreplugin/rightpane.h>
#include <extensionsystem/pluginmanager.h>
#include <cppeditor/cppeditorconstants.h>
#include <qmljseditor/qmljseditorconstants.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
#include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <projectexplorer/itaskhandler.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorericons.h>
#include <projectexplorer/projectexplorersettings.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <projectexplorer/toolchain.h>
#include <ssh/sshconnection.h>
#include <texteditor/texteditor.h>
#include <texteditor/textdocument.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <utils/algorithm.h>
#include <utils/appmainwindow.h>
#include <utils/basetreeview.h>
#include <utils/checkablemessagebox.h>
#include <utils/fancymainwindow.h>
#include <utils/hostosinfo.h>
#include <utils/proxyaction.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <utils/statuslabel.h>
#include <utils/styledbar.h>
#include <utils/temporarydirectory.h>
#include <utils/utilsicons.h>
#include <utils/winutils.h>
#include <QAction>
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDebug>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDockWidget>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
#include <QPointer>
#include <QPushButton>
#include <QSettings>
#include <QStackedWidget>
#include <QTextBlock>
#include <QToolButton>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <QVariant>
#include <QJsonDocument>
#include <QJsonObject>
#include <QtPlugin>
#ifdef WITH_TESTS
#include <cpptools/cpptoolstestcase.h>
#include <cpptools/projectinfo.h>
#include <utils/executeondestruction.h>
#include <QTest>
#include <QSignalSpy>
#include <QTestEventLoop>
//#define WITH_BENCHMARK
#ifdef WITH_BENCHMARK
#include <valgrind/callgrind.h>
#endif
#endif // WITH_TESTS
#include <climits>
#define DEBUG_STATE 1
#ifdef DEBUG_STATE
//# define STATE_DEBUG(s)
// do { QString msg; QTextStream ts(&msg); ts << s;
// showMessage(msg, LogDebug); } while (0)
# define STATE_DEBUG(s) do { qDebug() << s; } while (0)
#else
# define STATE_DEBUG(s)
#endif
/*!
\namespace Debugger
Debugger plugin namespace
*/
/*!
\namespace Debugger::Internal
Internal namespace of the Debugger plugin
\internal
*/
/*!
\class Debugger::DebuggerEngine
\brief The DebuggerEngine class is the base class of a debugger engine.
\note The Debugger process itself and any helper processes like
gdbserver are referred to as 'Engine', whereas the debugged process
is referred to as 'Inferior'.
Transitions marked by '---' are done in the individual engines.
Transitions marked by '+-+' are done in the base DebuggerEngine.
Transitions marked by '*' are done asynchronously.
The GdbEngine->setupEngine() function is described in more detail below.
The engines are responsible for local roll-back to the last
acknowledged state before calling notify*Failed. I.e. before calling
notifyEngineSetupFailed() any process started during setupEngine()
so far must be terminated.
\code
DebuggerNotReady
progressmanager/progressmanager.cpp +
EngineSetupRequested
+
(calls *Engine->setupEngine())
| |
| |
{notify- {notify-
Engine- Engine-
SetupOk} SetupFailed}
+ +
+ `+-+-+> EngineSetupFailed
+ +
+ [calls RunControl->startFailed]
+ +
+ DebuggerFinished
v
EngineSetupOk
+
[calls RunControl->StartSuccessful]
+
+
EngineRunRequested
+
(calls *Engine->runEngine())
/ | | \
/ | | \
| (core) | (attach) | |
| | | |
{notify- {notifyER&- {notifyER&- {notify-
Inferior- Inferior- Inferior- EngineRun-
Unrunnable} StopOk} RunOk} Failed}
+ + + +
InferiorUnrunnable + InferiorRunOk +
+ +
InferiorStopOk EngineRunFailed
+
`-+-+-+-+-+-+-+-+-+-+-+>-+
+
+
#Interrupt@InferiorRunOk# +
+ +
InferiorStopRequested +
#SpontaneousStop + +
@InferiorRunOk# (calls *Engine-> +
+ interruptInferior()) +
{notify- | | +
Spontaneous- {notify- {notify- +
Inferior- Inferior- Inferior- +
StopOk} StopOk} StopFailed} +
+ + + +
+ + + +
InferiorStopOk + +
+ + +
+ + +
+ + +
#Stop@InferiorUnrunnable# + +
#Creator Close Event# + +
+ + +
InferiorShutdownRequested +
+ +
(calls *Engine->shutdownInferior()) +
| +
{notifyInferiorShutdownFinished} +
+ +
+ +
#Inferior exited# + +
| + +
{notifyInferior- + +
Exited} + +
+ + +
+ + +
+ + +
InferiorShutdownFinished +
* +
EngineShutdownRequested +
+ +
(calls *Engine->shutdownEngine()) <+-+-+-+-+-+-+-+-+-+-+-+-+-+'
|
|
{notifyEngineShutdownFinished}
+
EngineShutdownFinished
*
DebuggerFinished
\endcode */
/* Here is a matching graph as a GraphViz graph. View it using
* \code
grep "^sg1:" debuggerplugin.cpp | cut -c5- | dot -osg1.ps -Tps && gv sg1.ps
sg1: digraph DebuggerStates {
sg1: DebuggerNotReady -> EngineSetupRequested
sg1: EngineSetupRequested -> EngineSetupOk [ label="notifyEngineSetupOk", style="dashed" ];
sg1: EngineSetupRequested -> EngineSetupFailed [ label= "notifyEngineSetupFailed", style="dashed"];
sg1: EngineSetupFailed -> DebuggerFinished [ label= "RunControl::StartFailed" ];
sg1: EngineSetupOk -> EngineRunRequested [ label= "RunControl::StartSuccessful" ];
sg1: EngineRunRequested -> InferiorUnrunnable [ label="notifyInferiorUnrunnable", style="dashed" ];
sg1: EngineRunRequested -> InferiorStopOk [ label="notifyEngineRunAndInferiorStopOk", style="dashed" ];
sg1: EngineRunRequested -> InferiorRunOk [ label="notifyEngineRunAndInferiorRunOk", style="dashed" ];
sg1: EngineRunRequested -> EngineRunFailed [ label="notifyEngineRunFailed", style="dashed" ];
sg1: EngineRunFailed -> EngineShutdownRequested
sg1: InferiorRunOk -> InferiorStopOk [ label="SpontaneousStop\nnotifyInferiorSpontaneousStop", style="dashed" ];
sg1: InferiorRunOk -> InferiorStopRequested [ label="User stop\nEngine::interruptInferior", style="dashed"];
sg1: InferiorStopRequested -> InferiorStopOk [ label="notifyInferiorStopOk", style="dashed" ];
sg1: InferiorStopRequested -> InferiorShutdownRequested [ label="notifyInferiorStopFailed", style="dashed" ];
sg1: InferiorStopOk -> InferiorRunRequested [ label="User\nEngine::continueInferior" ];
sg1: InferiorRunRequested -> InferiorRunOk [ label="notifyInferiorRunOk", style="dashed"];
sg1: InferiorRunRequested -> InferiorRunFailed [ label="notifyInferiorRunFailed", style="dashed"];
sg1: InferiorRunFailed -> InferiorStopOk
sg1: InferiorStopOk -> InferiorShutdownRequested [ label="Close event" ];
sg1: InferiorUnrunnable -> InferiorShutdownRequested [ label="Close event" ];
sg1: InferiorShutdownRequested -> InferiorShutdownFinished [ label= "Engine::shutdownInferior\nnotifyInferiorShutdownFinished", style="dashed" ];
sg1: InferiorExited -> InferiorExitOk [ label="notifyInferiorExited", style="dashed"];
sg1: InferiorExitOk -> InferiorShutdownOk
sg1: InferiorShutdownFinished -> EngineShutdownRequested
sg1: EngineShutdownRequested -> EngineShutdownFinished [ label="Engine::shutdownEngine\nnotifyEngineShutdownFinished", style="dashed" ];
sg1: EngineShutdownFinished -> DebuggerFinished [ style = "dotted" ];
sg1: }
* \endcode */
// Additional signalling: {notifyInferiorIll} {notifyEngineIll}
/*!
\class Debugger::Internal::GdbEngine
\brief The GdbEngine class implements Debugger::Engine driving a GDB
executable.
GdbEngine specific startup. All happens in EngineSetupRequested state:
\list
\li Transitions marked by '---' are done in the individual adapters.
\li Transitions marked by '+-+' are done in the GdbEngine.
\endlist
\code
GdbEngine::setupEngine()
+
(calls *Adapter->startAdapter())
| |
| `---> handleAdapterStartFailed()
| +
| {notifyEngineSetupFailed}
|
handleAdapterStarted()
+
{notifyEngineSetupOk}
GdbEngine::setupInferior()
+
(calls *Adapter->prepareInferior())
| |
| `---> handlePrepareInferiorFailed()
| +
| {notifyInferiorSetupFailed}
|
handleInferiorPrepared()
+
{notifyInferiorSetupOk}
\endcode */
using namespace Core;
using namespace Core::Constants;
using namespace Debugger::Constants;
using namespace Debugger::Internal;
using namespace ExtensionSystem;
using namespace ProjectExplorer;
using namespace TextEditor;
using namespace Utils;
namespace CC = Core::Constants;
namespace PE = ProjectExplorer::Constants;
namespace Debugger {
namespace Internal {
void addCdbOptionPages(QList<IOptionsPage*> *opts);
void addGdbOptionPages(QList<IOptionsPage*> *opts);
static QIcon startIcon(bool toolBarStyle)
{
const static QIcon sidebarIcon =
Icon::sideBarIcon(ProjectExplorer::Icons::DEBUG_START, ProjectExplorer::Icons::DEBUG_START_FLAT);
const static QIcon icon =
Icon::combinedIcon({ProjectExplorer::Icons::DEBUG_START_SMALL.icon(), sidebarIcon});
const static QIcon iconToolBar =
Icon::combinedIcon({ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR.icon(), sidebarIcon});
return toolBarStyle ? iconToolBar : icon;
}
static QIcon continueIcon(bool toolBarStyle)
{
const static QIcon sidebarIcon =
Icon::sideBarIcon(Icons::CONTINUE, Icons::CONTINUE_FLAT);
const static QIcon icon =
Icon::combinedIcon({Icons::DEBUG_CONTINUE_SMALL.icon(), sidebarIcon});
const static QIcon iconToolBar =
Icon::combinedIcon({Icons::DEBUG_CONTINUE_SMALL_TOOLBAR.icon(), sidebarIcon});
return toolBarStyle ? iconToolBar : icon;
}
static QIcon interruptIcon(bool toolBarStyle)
{
const static QIcon sidebarIcon =
Icon::sideBarIcon(Icons::INTERRUPT, Icons::INTERRUPT_FLAT);
const static QIcon icon =
Icon::combinedIcon({Icons::DEBUG_INTERRUPT_SMALL.icon(), sidebarIcon});
const static QIcon iconToolBar =
Icon::combinedIcon({Icons::DEBUG_INTERRUPT_SMALL_TOOLBAR.icon(), sidebarIcon});
return toolBarStyle ? iconToolBar : icon;
}
QAction *addAction(QMenu *menu, const QString &display, bool on,
const std::function<void()> &onTriggered)
{
QAction *act = menu->addAction(display);
act->setEnabled(on);
QObject::connect(act, &QAction::triggered, onTriggered);
return act;
};
QAction *addAction(QMenu *menu, const QString &d1, const QString &d2, bool on,
const std::function<void()> &onTriggered)
{
return on ? addAction(menu, d1, true, onTriggered) : addAction(menu, d2, false);
};
QAction *addCheckableAction(QMenu *menu, const QString &display, bool on, bool checked,
const std::function<void()> &onTriggered)
{
QAction *act = addAction(menu, display, on, onTriggered);
act->setCheckable(true);
act->setChecked(checked);
return act;
}
///////////////////////////////////////////////////////////////////////
//
// DebugMode
//
///////////////////////////////////////////////////////////////////////
class DebugMode : public IMode
{
public:
DebugMode()
{
setObjectName(QLatin1String("DebugMode"));
setContext(Context(C_DEBUGMODE, CC::C_NAVIGATION_PANE));
setDisplayName(DebuggerPlugin::tr("Debug"));
setIcon(Utils::Icon::modeIcon(Icons::MODE_DEBUGGER_CLASSIC,
Icons::MODE_DEBUGGER_FLAT, Icons::MODE_DEBUGGER_FLAT_ACTIVE));
setPriority(85);
setId(MODE_DEBUG);
}
};
///////////////////////////////////////////////////////////////////////
//
// Misc
//
///////////////////////////////////////////////////////////////////////
QWidget *addSearch(BaseTreeView *treeView)
{
QAction *act = action(UseAlternatingRowColors);
treeView->setAlternatingRowColors(act->isChecked());
QObject::connect(act, &QAction::toggled,
treeView, &BaseTreeView::setAlternatingRowColors);
return ItemViewFind::createSearchableWrapper(treeView);
}
static Kit::Predicate cdbPredicate(char wordWidth = 0)
{
return [wordWidth](const Kit *k) -> bool {
if (DebuggerKitInformation::engineType(k) != CdbEngineType
|| DebuggerKitInformation::configurationErrors(k)) {
return false;
}
if (wordWidth)
return ToolChainKitInformation::targetAbi(k).wordWidth() == wordWidth;
return true;
};
}
// Find a CDB kit for debugging unknown processes.
// On a 64bit OS, prefer a 64bit debugger.
static Kit *findUniversalCdbKit()
{
if (Utils::is64BitWindowsSystem()) {
if (Kit *cdb64Kit = KitManager::kit(cdbPredicate(64)))
return cdb64Kit;
}
return KitManager::kit(cdbPredicate());
}
///////////////////////////////////////////////////////////////////////
//
// Debuginfo Taskhandler
//
///////////////////////////////////////////////////////////////////////
class DebugInfoTaskHandler : public ITaskHandler
{
public:
bool canHandle(const Task &task) const final
{
return m_debugInfoTasks.contains(task.taskId);
}
void handle(const Task &task) final
{
QString cmd = m_debugInfoTasks.value(task.taskId);
QProcess::startDetached(cmd);
}
void addTask(unsigned id, const QString &cmd)
{
m_debugInfoTasks[id] = cmd;
}
QAction *createAction(QObject *parent) const final
{
QAction *action = new QAction(DebuggerPlugin::tr("Install &Debug Information"), parent);
action->setToolTip(DebuggerPlugin::tr("Tries to install missing debug information."));
return action;
}
private:
QHash<unsigned, QString> m_debugInfoTasks;
};
///////////////////////////////////////////////////////////////////////
//
// DebuggerPluginPrivate
//
///////////////////////////////////////////////////////////////////////
static DebuggerPluginPrivate *dd = nullptr;
/*!
\class Debugger::Internal::DebuggerCore
This is the "internal" interface of the debugger plugin that's
used by debugger views and debugger engines. The interface is
implemented in DebuggerPluginPrivate.
*/
/*!
\class Debugger::Internal::DebuggerPluginPrivate
Implementation of DebuggerCore.
*/
struct Callback
{
Callback()
: cb([]{})
{}
Callback(void (DebuggerEngine::*func)())
: cb([func] { if (DebuggerEngine *engine = EngineManager::currentEngine()) (engine->*func)(); })
{}
std::function<void()> cb;
};
struct Action : public QAction
{
Action(const QString &name, const QIcon &icon = {}) : QAction(name) { setIcon(icon); }
Action(const QString &name, const QIcon &icon, Callback cb, const QString &toolTip = {})
: Action(name, icon)
{
m_cb = cb;
setToolTip(toolTip);
connect(this, &QAction::triggered, this, &Action::onTriggered);
}
void onTriggered()
{
m_cb.cb();
}
Callback m_cb;
};
class DebuggerPluginPrivate : public QObject
{
Q_OBJECT
public:
explicit DebuggerPluginPrivate(DebuggerPlugin *plugin);
~DebuggerPluginPrivate() override;
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
void aboutToShutdown();
void doShutdown();
RunControl *attachToRunningProcess(Kit *kit, DeviceProcessItem process, bool contAfterAttach);
void writeSettings()
{
m_debuggerSettings->writeSettings();
// writeWindowSettings();
}
void breakpointSetMarginActionTriggered(bool isMessageOnly, const ContextData &data)
{
QString message;
if (isMessageOnly) {
if (data.type == LocationByAddress) {
//: Message tracepoint: Address hit.
message = tr("0x%1 hit").arg(data.address, 0, 16);
} else {
//: Message tracepoint: %1 file, %2 line %3 function hit.
message = tr("%1:%2 %3() hit").arg(FileName::fromString(data.fileName).fileName()).
arg(data.lineNumber).
arg(cppFunctionAt(data.fileName, data.lineNumber));
}
QInputDialog dialog; // Create wide input dialog.
dialog.setWindowFlags(dialog.windowFlags()
& ~(Qt::WindowContextHelpButtonHint|Qt::MSWindowsFixedSizeDialogHint));
dialog.resize(600, dialog.height());
dialog.setWindowTitle(tr("Add Message Tracepoint"));
dialog.setLabelText (tr("Message:"));
dialog.setTextValue(message);
if (dialog.exec() != QDialog::Accepted || dialog.textValue().isEmpty())
return;
message = dialog.textValue();
}
BreakpointManager::toggleBreakpoint(data, message);
}
void editorOpened(IEditor *editor);
void updateBreakMenuItem(IEditor *editor);
void requestMark(TextEditorWidget *widget, int lineNumber,
TextMarkRequestKind kind);
void requestContextMenu(TextEditorWidget *widget,
int lineNumber, QMenu *menu);
void toggleBreakpointHelper();
void onModeChanged(Id mode);
void updateDebugWithoutDeployMenu();
void startRemoteCdbSession();
void attachToRunningApplication();
void attachToUnstartedApplicationDialog();
void attachToQmlPort();
void runScheduled();
void attachCore();
void runControlFinished(DebuggerRunTool *runTool);
void remoteCommand(const QStringList &options);
void dumpLog();
void setInitialState();
void onStartupProjectChanged(Project *project);
void sessionLoaded();
void aboutToUnloadSession();
void aboutToSaveSession();
void handleOperateByInstructionTriggered(bool operateByInstructionTriggered);
bool parseArgument(QStringList::const_iterator &it,
const QStringList::const_iterator &cend, QString *errorMessage);
bool parseArguments(const QStringList &args, QString *errorMessage);
void parseCommandLineArguments();
void updatePresetState();
public:
QPointer<DebuggerMainWindow> m_mainWindow;
QPointer<QWidget> m_modeWindow;
QPointer<DebugMode> m_mode;
ActionContainer *m_menu = nullptr;
QVector<DebuggerRunTool *> m_scheduledStarts;
ProxyAction m_visibleStartAction; // The fat debug button
ProxyAction m_hiddenStopAction;
QAction m_undisturbableAction;
OptionalAction m_startAction;
QAction m_debugWithoutDeployAction{tr("Start Debugging Without Deployment")};
QAction m_startAndDebugApplicationAction{tr("Start and Debug External Application...")};
QAction m_attachToRunningApplication{tr("Attach to Running Application...")};
QAction m_attachToUnstartedApplication{tr("Attach to Unstarted Application...")};
QAction m_attachToQmlPortAction{tr("Attach to QML Port...")};
QAction m_attachToRemoteServerAction{tr("Attach to Running Debug Server...")};
QAction m_startRemoteCdbAction{tr("Attach to Remote CDB Session...")};
QAction m_attachToCoreAction{tr("Load Core File...")};
Action m_detachAction{tr("Detach Debugger"), {}, &DebuggerEngine::handleExecDetach};
Action m_continueAction{tr("Continue"), continueIcon(false), &DebuggerEngine::handleExecContinue};
// On application output button if "Stop" is possible
Action m_exitAction{tr("Stop Debugger"), Icons::DEBUG_EXIT_SMALL.icon(), &DebuggerEngine::quitDebugger};
// On the fat debug button if "Pause" is possible
Action m_interruptAction{tr("Interrupt"), interruptIcon(false), &DebuggerEngine::handleExecInterrupt};
Action m_abortAction{tr("Abort Debugging"), {}, &DebuggerEngine::abortDebugger,
tr("Aborts debugging and resets the debugger to the initial state.")};
QAction m_stepAction{tr("Step Into")};
Action m_stepOutAction{tr("Step Out"), Icons::STEP_OUT.icon(), &DebuggerEngine::handleExecStepOut};
Action m_runToLineAction{tr("Run to Line"), {}, &DebuggerEngine::handleExecRunToLine};
Action m_runToSelectedFunctionAction{tr("Run to Selected Function"), {}, &DebuggerEngine::handleExecRunToSelectedFunction};
Action m_jumpToLineAction{tr("Jump to Line"), {}, &DebuggerEngine::handleExecJumpToLine};
// In the Debug menu.
Action m_returnFromFunctionAction{tr("Immediately Return From Inner Function"), {}, &DebuggerEngine::executeReturn};
QAction m_nextAction{tr("Step Over")};
Action m_watchAction{tr("Add Expression Evaluator"), {}, &DebuggerEngine::handleAddToWatchWindow};
Command *m_watchCommand = nullptr;
QAction m_breakAction{tr("Toggle Breakpoint")};
Action m_frameUpAction{tr("Move to Calling Frame"), {}, &DebuggerEngine::handleFrameDown};
Action m_frameDownAction{tr("Move to Called Frame"), {}, &DebuggerEngine::handleFrameUp};
Action m_resetAction{tr("Restart Debugging"), Icons::RESTART_TOOLBAR.icon(), &DebuggerEngine::handleReset,
tr("Restart the debugging session.")};
Action m_openMemoryEditorAction{tr("Memory..."), {}, &DebuggerEngine::openMemoryEditor};
BreakpointManager m_breakpointManager;
QPointer<BaseTreeView> m_breakpointManagerView;
QPointer<QWidget> m_breakpointManagerWindow;
QPointer<BaseTreeView> m_engineManagerView;
QPointer<QWidget> m_engineManagerWindow;
QPointer<GlobalLogWindow> m_globalLogWindow;
QString m_lastPermanentStatusMessage;
DebuggerPlugin *m_plugin = nullptr;
EngineManager m_engineManager;
QTimer m_shutdownTimer;
bool m_shuttingDown = false;
DebuggerSettings *m_debuggerSettings = nullptr;
QStringList m_arguments;
DebuggerToolTipManager m_toolTipManager;
const QSharedPointer<GlobalDebuggerOptions> m_globalDebuggerOptions;
DebuggerItemManager m_debuggerItemManager;
QList<IOptionsPage *> m_optionPages;
IContext m_debugModeContext;
DebugInfoTaskHandler m_debugInfoTaskHandler;
};
DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin)
: m_globalDebuggerOptions(new GlobalDebuggerOptions)
{
qRegisterMetaType<ContextData>("ContextData");
qRegisterMetaType<DebuggerRunParameters>("DebuggerRunParameters");
QTC_CHECK(!dd);
dd = this;
m_plugin = plugin;
debuggerConsole(); // ensure Debugger Console is created before settings are taken into account
}
DebuggerPluginPrivate::~DebuggerPluginPrivate()
{
destroyDebuggerConsole();
qDeleteAll(m_optionPages);
m_optionPages.clear();
delete m_debuggerSettings;
m_debuggerSettings = nullptr;
}
static QString msgParameterMissing(const QString &a)
{
return DebuggerPlugin::tr("Option \"%1\" is missing the parameter.").arg(a);
}
static Kit *guessKitFromAbis(const QList<Abi> &abis)
{
Kit *kit = nullptr;
// Try to find a kit via ABI.
if (!abis.isEmpty()) {
// Try exact abis.
kit = KitManager::kit([abis](const Kit *k) {
const Abi tcAbi = ToolChainKitInformation::targetAbi(k);
return abis.contains(tcAbi) && !DebuggerKitInformation::configurationErrors(k);
});
if (!kit) {
// Or something compatible.
kit = KitManager::kit([abis](const Kit *k) {
const Abi tcAbi = ToolChainKitInformation::targetAbi(k);
return !DebuggerKitInformation::configurationErrors(k)
&& Utils::contains(abis, [tcAbi](const Abi &a) { return a.isCompatibleWith(tcAbi); });
});
}
}
if (!kit)
kit = KitManager::defaultKit();
return kit;
}
bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
const QStringList::const_iterator &cend, QString *errorMessage)
{
const QString &option = *it;
// '-debug <pid>'
// '-debug <exe>[,server=<server:port>][,core=<core>][,kit=<kit>][,terminal={0,1}]'
if (*it == "-debug") {
++it;
if (it == cend) {
*errorMessage = msgParameterMissing(*it);
return false;
}
const qulonglong pid = it->toULongLong();
const QStringList args = it->split(',');
Kit *kit = nullptr;
DebuggerStartMode startMode = StartExternal;
QString executable;
QString remoteChannel;
QString coreFile;
bool useTerminal = false;
if (!pid) {
for (const QString &arg : args) {
const QString key = arg.section('=', 0, 0);
const QString val = arg.section('=', 1, 1);
if (val.isEmpty()) {
if (key.isEmpty()) {
continue;
} else if (executable.isEmpty()) {
executable = key;
} else {
*errorMessage = DebuggerPlugin::tr("Only one executable allowed.");
return false;
}
} else if (key == "kit") {
kit = KitManager::kit(Id::fromString(val));
if (!kit)
kit = KitManager::kit(Utils::equal(&Kit::displayName, val));
} else if (key == "server") {
startMode = AttachToRemoteServer;
remoteChannel = val;
} else if (key == "core") {
startMode = AttachCore;
coreFile = val;
} else if (key == "terminal") {
useTerminal = true;
}
}
}
if (!kit)
kit = guessKitFromAbis(Abi::abisOfBinary(FileName::fromString(executable)));
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, kit);
debugger->setInferiorExecutable(executable);
if (pid) {
debugger->setStartMode(AttachExternal);
debugger->setCloseMode(DetachAtClose);
debugger->setAttachPid(pid);
debugger->setRunControlName(tr("Process %1").arg(pid));
debugger->setStartMessage(tr("Attaching to local process %1.").arg(pid));
} else if (startMode == AttachToRemoteServer) {
debugger->setStartMode(AttachToRemoteServer);
debugger->setRemoteChannel(remoteChannel);
debugger->setRunControlName(tr("Remote: \"%1\"").arg(remoteChannel));
debugger->setStartMessage(tr("Attaching to remote server %1.").arg(remoteChannel));
} else if (startMode == AttachCore) {
debugger->setStartMode(AttachCore);
debugger->setCloseMode(DetachAtClose);
debugger->setCoreFileName(coreFile);
debugger->setRunControlName(tr("Core file \"%1\"").arg(coreFile));
debugger->setStartMessage(tr("Attaching to core file %1.").arg(coreFile));
} else {
debugger->setStartMode(StartExternal);
debugger->setRunControlName(tr("Executable file \"%1\"").arg(executable));
debugger->setStartMessage(tr("Debugging file %1.").arg(executable));
}
debugger->setUseTerminal(useTerminal);
m_scheduledStarts.append(debugger);
return true;
}
// -wincrashevent <event-handle>:<pid>. A handle used for
// a handshake when attaching to a crashed Windows process.
// This is created by $QTC/src/tools/qtcdebugger/main.cpp:
// args << QLatin1String("-wincrashevent")
// << QString::fromLatin1("%1:%2").arg(argWinCrashEvent).arg(argProcessId);
if (*it == "-wincrashevent") {
++it;
if (it == cend) {
*errorMessage = msgParameterMissing(*it);
return false;
}
qint64 pid = it->section(':', 1, 1).toULongLong();
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, findUniversalCdbKit());
debugger->setStartMode(AttachCrashedExternal);
debugger->setCrashParameter(it->section(':', 0, 0));
debugger->setAttachPid(pid);
debugger->setRunControlName(tr("Crashed process %1").arg(pid));
debugger->setStartMessage(tr("Attaching to crashed process %1").arg(pid));
if (pid < 1) {
*errorMessage = DebuggerPlugin::tr("The parameter \"%1\" of option \"%2\" "
"does not match the pattern <handle>:<pid>.").arg(*it, option);
return false;
}
m_scheduledStarts.append(debugger);
return true;
}
*errorMessage = DebuggerPlugin::tr("Invalid debugger option: %1").arg(option);
return false;
}
bool DebuggerPluginPrivate::parseArguments(const QStringList &args,
QString *errorMessage)
{
const QStringList::const_iterator cend = args.constEnd();
for (QStringList::const_iterator it = args.constBegin(); it != cend; ++it)
if (!parseArgument(it, cend, errorMessage))
return false;
return true;
}
void DebuggerPluginPrivate::parseCommandLineArguments()
{
QString errorMessage;
if (!parseArguments(m_arguments, &errorMessage)) {
errorMessage = tr("Error evaluating command line arguments: %1")
.arg(errorMessage);
qWarning("%s\n", qPrintable(errorMessage));
MessageManager::write(errorMessage);
}
if (!m_scheduledStarts.isEmpty())
QTimer::singleShot(0, this, &DebuggerPluginPrivate::runScheduled);
}
bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
QString *errorMessage)
{
Q_UNUSED(errorMessage);
m_arguments = arguments;
if (!m_arguments.isEmpty())
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::finishedInitialization,
this, &DebuggerPluginPrivate::parseCommandLineArguments);
m_mainWindow = new DebuggerMainWindow;
// Menus
m_menu = ActionManager::createMenu(M_DEBUG_ANALYZER);
m_menu->menu()->setTitle(tr("&Analyze"));
m_menu->menu()->setEnabled(true);
m_menu->appendGroup(G_ANALYZER_CONTROL);
m_menu->appendGroup(G_ANALYZER_TOOLS);
m_menu->appendGroup(G_ANALYZER_REMOTE_TOOLS);
m_menu->appendGroup(G_ANALYZER_OPTIONS);
ActionContainer *menubar = ActionManager::actionContainer(MENU_BAR);
ActionContainer *mtools = ActionManager::actionContainer(M_TOOLS);
menubar->addMenu(mtools, m_menu);
m_menu->addSeparator(G_ANALYZER_TOOLS);
m_menu->addSeparator(G_ANALYZER_REMOTE_TOOLS);
m_menu->addSeparator(G_ANALYZER_OPTIONS);
// Populate Windows->Views menu with standard actions.
Context debugcontext(Constants::C_DEBUGMODE);
Command *cmd = ActionManager::registerAction(&m_openMemoryEditorAction,
"Debugger.Views.OpenMemoryEditor", debugcontext);
cmd->setAttribute(Command::CA_Hide);
TaskHub::addCategory(TASK_CATEGORY_DEBUGGER_DEBUGINFO,
tr("Debug Information"));
TaskHub::addCategory(TASK_CATEGORY_DEBUGGER_RUNTIME,
tr("Debugger Runtime"));
QSettings *settings = ICore::settings();
m_debuggerSettings = new DebuggerSettings;
m_debuggerSettings->readSettings();
const Context cppDebuggercontext(C_CPPDEBUGGER);
const Context qmljsDebuggercontext(C_QMLDEBUGGER);
m_breakpointManagerView = new BaseTreeView;
m_breakpointManagerView->setIconSize(QSize(10, 10));
m_breakpointManagerView->setWindowIcon(Icons::BREAKPOINTS.icon());
m_breakpointManagerView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_breakpointManagerView->setSettings(settings, "Debugger.BreakWindow");
m_breakpointManagerView->setRootIsDecorated(true);
m_breakpointManagerView->setModel(BreakpointManager::model());
m_breakpointManagerWindow = addSearch(m_breakpointManagerView);
m_breakpointManagerWindow->setWindowTitle(tr("Breakpoint Preset"));
m_breakpointManagerWindow->setObjectName(DOCKWIDGET_BREAKPOINTMANAGER);
// Snapshot
m_engineManagerView = new BaseTreeView;
m_engineManagerView->setWindowTitle(tr("Running Debuggers"));
m_engineManagerView->setSettings(settings, "Debugger.SnapshotView");
m_engineManagerView->setIconSize(QSize(10, 10));
m_engineManagerView->setModel(m_engineManager.model());
m_engineManagerWindow = addSearch(m_engineManagerView);
m_engineManagerWindow->setWindowTitle(tr("Snapshots"));
m_engineManagerWindow->setObjectName(DOCKWIDGET_ENGINEMANAGER);
//act = m_snapshotAction = new QAction(tr("Create Snapshot"), this);
//act->setProperty(Role, RequestCreateSnapshotRole);
//act->setIcon(Icons::SNAPSHOT.icon());
// connect(act, &QAction::triggered,
// this, &DebuggerPluginPrivate::handleOperateByInstructionTriggered);
// Logging
m_globalLogWindow = new GlobalLogWindow;
ActionContainer *debugMenu = ActionManager::actionContainer(PE::M_DEBUG);
RunConfiguration::registerAspect<DebuggerRunConfigurationAspect>();
// The main "Start Debugging" action. Acts as "Continue" at times.
connect(&m_startAction, &QAction::triggered, this, [] {
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, false);
});
connect(&m_debugWithoutDeployAction, &QAction::triggered, this, [] {
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, true);
});
connect(&m_startAndDebugApplicationAction, &QAction::triggered,
this, &StartApplicationDialog::startAndDebugApplication);
connect(&m_attachToCoreAction, &QAction::triggered,
this, &DebuggerPluginPrivate::attachCore);
connect(&m_attachToRemoteServerAction, &QAction::triggered,
this, &StartApplicationDialog::attachToRemoteServer);
connect(&m_attachToRunningApplication, &QAction::triggered,
this, &DebuggerPluginPrivate::attachToRunningApplication);
connect(&m_attachToUnstartedApplication, &QAction::triggered,
this, &DebuggerPluginPrivate::attachToUnstartedApplicationDialog);
connect(&m_attachToQmlPortAction, &QAction::triggered,
this, &DebuggerPluginPrivate::attachToQmlPort);
connect(&m_startRemoteCdbAction, &QAction::triggered,
this, &DebuggerPluginPrivate::startRemoteCdbSession);
// "Start Debugging" sub-menu
// groups:
// G_DEFAULT_ONE
// G_START_LOCAL
// G_START_REMOTE
// G_START_QML
ActionContainer *mstart = ActionManager::actionContainer(PE::M_DEBUG_STARTDEBUGGING);
cmd = ActionManager::registerAction(&m_visibleStartAction, Constants::DEBUG);
cmd->setDescription(tr("Start Debugging or Continue"));
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Ctrl+Y") : tr("F5")));
cmd->setAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateIcon);
//mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = ActionManager::registerAction(&m_startAction, "Debugger.Start");
cmd->setDescription(tr("Start Debugging"));
cmd->setAttribute(Command::CA_UpdateText);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
m_visibleStartAction.initialize(&m_startAction);
m_visibleStartAction.setAttribute(ProxyAction::UpdateText);
m_visibleStartAction.setAction(&m_startAction);
m_visibleStartAction.setIcon(startIcon(true));
ModeManager::addAction(&m_visibleStartAction, Constants::P_ACTION_DEBUG);
cmd = ActionManager::registerAction(&m_debugWithoutDeployAction,
"Debugger.DebugWithoutDeploy");
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = ActionManager::registerAction(&m_attachToRunningApplication,
"Debugger.AttachToRemoteProcess");
cmd->setDescription(tr("Attach to Running Application"));
mstart->addAction(cmd, G_GENERAL);
cmd = ActionManager::registerAction(&m_attachToUnstartedApplication,
"Debugger.AttachToUnstartedProcess");
cmd->setDescription(tr("Attach to Unstarted Application"));
mstart->addAction(cmd, G_GENERAL);
cmd = ActionManager::registerAction(&m_startAndDebugApplicationAction,
"Debugger.StartAndDebugApplication");
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, G_GENERAL);
cmd = ActionManager::registerAction(&m_attachToCoreAction,
"Debugger.AttachCore");
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_GENERAL);
cmd = ActionManager::registerAction(&m_attachToRemoteServerAction,
"Debugger.AttachToRemoteServer");
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_SPECIAL);
if (HostOsInfo::isWindowsHost()) {
cmd = ActionManager::registerAction(&m_startRemoteCdbAction,
"Debugger.AttachRemoteCdb");
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_SPECIAL);
}
mstart->addSeparator(Context(CC::C_GLOBAL), Constants::G_START_QML);
cmd = ActionManager::registerAction(&m_attachToQmlPortAction, "Debugger.AttachToQmlPort");
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_START_QML);
cmd = ActionManager::registerAction(&m_detachAction, "Debugger.Detach");
cmd->setAttribute(Command::CA_Hide);
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = ActionManager::registerAction(&m_interruptAction, Constants::INTERRUPT);
cmd->setDescription(tr("Interrupt Debugger"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = ActionManager::registerAction(&m_continueAction, Constants::CONTINUE);
// cmd->setDefaultKeySequence(debugKey);
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = ActionManager::registerAction(&m_exitAction, Constants::STOP);
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
m_hiddenStopAction.initialize(cmd->action());
m_hiddenStopAction.setAttribute(ProxyAction::UpdateText);
m_hiddenStopAction.setAttribute(ProxyAction::UpdateIcon);
cmd = ActionManager::registerAction(&m_hiddenStopAction, Constants::HIDDEN_STOP);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Shift+Ctrl+Y") : tr("Shift+F5")));
cmd = ActionManager::registerAction(&m_abortAction, Constants::ABORT);
cmd->setDescription(tr("Reset Debugger"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = ActionManager::registerAction(&m_resetAction, Constants::RESET);
cmd->setDescription(tr("Restart Debugging"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
debugMenu->addSeparator();
cmd = ActionManager::registerAction(&m_nextAction, Constants::NEXT);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Ctrl+Shift+O") : tr("F10")));
cmd->setAttribute(Command::CA_Hide);
cmd->setAttribute(Command::CA_UpdateText);
debugMenu->addAction(cmd);
m_nextAction.setIcon(Icons::STEP_OVER.icon());
connect(&m_nextAction, &QAction::triggered, this, [this] {
if (DebuggerEngine *engine = EngineManager::currentEngine()) {
engine->executeNext();
} else {
DebuggerRunTool::setBreakOnMainNextTime();
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, false);
}
});
cmd = ActionManager::registerAction(&m_stepAction, Constants::STEP);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Ctrl+Shift+I") : tr("F11")));
cmd->setAttribute(Command::CA_Hide);
cmd->setAttribute(Command::CA_UpdateText);
debugMenu->addAction(cmd);
m_stepAction.setIcon(Icons::STEP_OVER.icon());
connect(&m_stepAction, &QAction::triggered, this, [this] {
if (DebuggerEngine *engine = EngineManager::currentEngine()) {
engine->executeStep();
} else {
DebuggerRunTool::setBreakOnMainNextTime();
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, false);
}
});
cmd = ActionManager::registerAction(&m_stepOutAction, Constants::STEPOUT);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Ctrl+Shift+T") : tr("Shift+F11")));
cmd->setAttribute(Command::CA_Hide);
debugMenu->addAction(cmd);
cmd = ActionManager::registerAction(&m_runToLineAction,
"Debugger.RunToLine", cppDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Shift+F8") : tr("Ctrl+F10")));
cmd->setAttribute(Command::CA_Hide);
debugMenu->addAction(cmd);
cmd = ActionManager::registerAction(&m_runToSelectedFunctionAction,
"Debugger.RunToSelectedFunction", cppDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F6")));
cmd->setAttribute(Command::CA_Hide);
// Don't add to menu by default as keeping its enabled state
// and text up-to-date is a lot of hassle.
// debugMenu->addAction(cmd);
cmd = ActionManager::registerAction(&m_jumpToLineAction,
"Debugger.JumpToLine", cppDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
debugMenu->addAction(cmd);
cmd = ActionManager::registerAction(&m_returnFromFunctionAction,
"Debugger.ReturnFromFunction", cppDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
debugMenu->addAction(cmd);
debugMenu->addSeparator();
//cmd = ActionManager::registerAction(m_snapshotAction,
// "Debugger.Snapshot", cppDebuggercontext);
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+D,Ctrl+S")));
//cmd->setAttribute(Command::CA_Hide);
//debugMenu->addAction(cmd);
ActionManager::registerAction(&m_frameDownAction,
"Debugger.FrameDown", cppDebuggercontext);
ActionManager::registerAction(&m_frameUpAction,
"Debugger.FrameUp", cppDebuggercontext);
cmd = ActionManager::registerAction(action(OperateByInstruction),
Constants::OPERATE_BY_INSTRUCTION, cppDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
debugMenu->addAction(cmd);
cmd = ActionManager::registerAction(&m_breakAction, "Debugger.ToggleBreak");
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("F8") : tr("F9")));
debugMenu->addAction(cmd);
connect(&m_breakAction, &QAction::triggered,
this, &DebuggerPluginPrivate::toggleBreakpointHelper);
debugMenu->addSeparator();
// currently broken
// auto qmlUpdateOnSaveDummyAction = new QAction(tr("Apply Changes on Save"), this);
// qmlUpdateOnSaveDummyAction->setCheckable(true);
// qmlUpdateOnSaveDummyAction->setIcon(Icons::APPLY_ON_SAVE.icon());
// qmlUpdateOnSaveDummyAction->setEnabled(false);
// cmd = ActionManager::registerAction(qmlUpdateOnSaveDummyAction, Constants::QML_UPDATE_ON_SAVE);
// debugMenu->addAction(cmd);
auto qmlShowAppOnTopDummyAction = new QAction(tr("Show Application on Top"), this);
qmlShowAppOnTopDummyAction->setCheckable(true);
qmlShowAppOnTopDummyAction->setIcon(Icons::APP_ON_TOP.icon());
qmlShowAppOnTopDummyAction->setEnabled(false);
cmd = ActionManager::registerAction(qmlShowAppOnTopDummyAction, Constants::QML_SHOW_APP_ON_TOP);
debugMenu->addAction(cmd);
auto qmlSelectDummyAction = new QAction(tr("Select"), this);
qmlSelectDummyAction->setCheckable(true);
qmlSelectDummyAction->setIcon(Icons::SELECT.icon());
qmlSelectDummyAction->setEnabled(false);
cmd = ActionManager::registerAction(qmlSelectDummyAction, Constants::QML_SELECTTOOL);
debugMenu->addAction(cmd);
debugMenu->addSeparator();
cmd = m_watchCommand = ActionManager::registerAction(&m_watchAction, "Debugger.AddToWatch",
Context(CppEditor::Constants::CPPEDITOR_ID, QmlJSEditor::Constants::C_QMLJSEDITOR_ID));
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+D,Ctrl+W")));
debugMenu->addAction(cmd);
addGdbOptionPages(&m_optionPages);
addCdbOptionPages(&m_optionPages);
m_optionPages.append(new LocalsAndExpressionsOptionsPage);
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
this, &DebuggerPluginPrivate::onModeChanged);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::settingsChanged,
this, &DebuggerPluginPrivate::updateDebugWithoutDeployMenu);
// Debug mode setup
m_mode = new DebugMode;
m_modeWindow = createModeWindow(Constants::MODE_DEBUG, m_mainWindow);
m_mode->setWidget(m_modeWindow);
m_debugModeContext.setContext(Context(CC::C_EDITORMANAGER));
m_debugModeContext.setWidget(m_modeWindow);
ICore::addContextObject(&m_debugModeContext);
//
// Connections
//
// Core
connect(ICore::instance(), &ICore::saveSettingsRequested,
this, &DebuggerPluginPrivate::writeSettings);
// TextEditor
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
[this](const FontSettings &settings) {
if (!boolSetting(FontSizeFollowsEditor))
return;
qreal size = settings.fontZoom() * settings.fontSize() / 100.;
QFont font = m_breakpointManagerWindow->font();
font.setPointSizeF(size);
m_breakpointManagerWindow->setFont(font);
m_globalLogWindow->setFont(font);
// m_snapshotWindow->setFont(font);
});
// ProjectExplorer
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &DebuggerPluginPrivate::sessionLoaded);
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession,
this, &DebuggerPluginPrivate::aboutToSaveSession);
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
this, &DebuggerPluginPrivate::aboutToUnloadSession);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
this, &DebuggerPluginPrivate::updatePresetState);
// EditorManager
connect(EditorManager::instance(), &EditorManager::editorOpened,
this, &DebuggerPluginPrivate::editorOpened);
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
this, &DebuggerPluginPrivate::updateBreakMenuItem);
// Application interaction
connect(action(SettingsDialog), &QAction::triggered,
[] { ICore::showOptionsDialog(DEBUGGER_COMMON_SETTINGS_ID); });
auto perspective = new Perspective(Constants::PRESET_PERSPRECTIVE_ID, tr("Debugger"));
Debugger::registerPerspective(perspective);
perspective->addToolBarWidget(EngineManager::engineChooser());
perspective->addToolBarAction(&m_startAction);
// QAction *operateByInstructionAction = action(OperateByInstruction);
// operateByInstructionAction->setText(tr("Start in Operate by Instruction mode"));
// QAction *enableReverseDebuggingAction = action(EnableReverseDebugging);
// enableReverseDebuggingAction->setText(tr("Start with recording information to reverse step if possible"));
//// Icons::SINGLE_INSTRUCTION_MODE.icon()};
// Action m_enableReverseDebuggingAction{tr("Start with recording information to reverse step if possible"),
// Icons::REVERSE_MODE.icon()}
// perspective->addToolbarAction(operateByInstructionAction);
perspective->addWindow(m_breakpointManagerWindow, Perspective::SplitVertical, nullptr);
perspective->addWindow(m_globalLogWindow, Perspective::SplitHorizontal, m_breakpointManagerWindow);
perspective->addWindow(m_engineManagerWindow, Perspective::AddToTab, m_globalLogWindow);
// connect(action(EnableReverseDebugging), &SavedAction::valueChanged,
// this, &DebuggerPluginPrivate::enableReverseDebuggingTriggered);
setInitialState();
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
this, &DebuggerPluginPrivate::onStartupProjectChanged);
connect(EngineManager::instance(), &EngineManager::engineStateChanged,
this, &DebuggerPluginPrivate::updatePresetState);
connect(EngineManager::instance(), &EngineManager::currentEngineChanged,
this, &DebuggerPluginPrivate::updatePresetState);
m_optionPages.append(new CommonOptionsPage(m_globalDebuggerOptions));
m_globalDebuggerOptions->fromSettings();
return true;
}
void setConfigValue(const QString &name, const QVariant &value)
{
ICore::settings()->setValue("DebugMode/" + name, value);
}
QVariant configValue(const QString &name)
{
return ICore::settings()->value("DebugMode/" + name);
}
void DebuggerPluginPrivate::updatePresetState()
{
if (m_shuttingDown)
return;
Project *startupProject = SessionManager::startupProject();
RunConfiguration *startupRunConfig = RunConfiguration::startupRunConfiguration();
DebuggerEngine *currentEngine = EngineManager::currentEngine();
QString whyNot;
const bool canRun = startupProject
&& ProjectExplorerPlugin::canRunStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, &whyNot);
if (!currentEngine || !currentEngine->isStartupRunConfiguration()) {
// No engine running -- or -- we have a running engine but it does not
// correspond to the current start up project.
QString startupRunConfigName;
if (startupRunConfig)
startupRunConfigName = startupRunConfig->displayName();
if (startupRunConfigName.isEmpty() && startupProject)
startupRunConfigName = startupProject->displayName();
QString startToolTip = canRun ? tr("Start debugging of \"%1\"").arg(startupRunConfigName) : whyNot;
QString stepToolTip = canRun ? tr("Start \"%1\" and break at function \"main\"").arg(startupRunConfigName) : whyNot;
// Step into/next: Start and break at 'main' unless a debugger is running.
m_stepAction.setEnabled(canRun);
m_stepAction.setToolTip(stepToolTip);
m_nextAction.setEnabled(canRun);
m_nextAction.setToolTip(stepToolTip);
m_startAction.setEnabled(canRun);
m_startAction.setToolTip(startToolTip);
m_startAction.setText(startToolTip);
m_startAction.setIcon(startIcon(false));
m_startAction.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_startAction.setVisible(true);
m_interruptAction.setEnabled(false);
m_continueAction.setEnabled(false);
m_exitAction.setEnabled(false);
m_debugWithoutDeployAction.setEnabled(canRun);
m_visibleStartAction.setIcon(startIcon(true));
m_hiddenStopAction.setAction(&m_undisturbableAction);
m_detachAction.setEnabled(false);
m_jumpToLineAction.setEnabled(false);
m_returnFromFunctionAction.setEnabled(false);
return;
}
QTC_ASSERT(currentEngine, return);
// We have a current engine, and it belongs to the startup runconfig.
m_stepAction.setToolTip(QString());
m_nextAction.setToolTip(QString());
// The 'state' bits only affect the fat debug button, not the preset start button.
m_startAction.setText(QString());
m_startAction.setToolTip(whyNot);
m_startAction.setIcon(startIcon(false));
m_startAction.setEnabled(false);
m_startAction.setVisible(false);
QString currentDisplayName = currentEngine->displayName();
m_interruptAction.setToolTip(tr("Interrupt \"%1\"").arg(currentDisplayName));
m_continueAction.setToolTip(tr("Continue \"%1\"").arg(currentDisplayName));
m_debugWithoutDeployAction.setEnabled(canRun);
// Global actions are redirected to running, active engine if possible.
const bool isCore = currentEngine->runParameters().startMode == AttachCore;
const DebuggerState state = currentEngine->state();
const bool companionPreventsAction = currentEngine->companionPreventsActions();
if (state == InferiorStopOk) {
// F5 continues, Shift-F5 kills. It is "continuable".
m_startAction.setEnabled(false);
m_interruptAction.setEnabled(false);
m_continueAction.setEnabled(!companionPreventsAction);
m_exitAction.setEnabled(true);
m_debugWithoutDeployAction.setEnabled(false);
m_visibleStartAction.setAction(&m_continueAction);
m_visibleStartAction.setIcon(continueIcon(true));
m_hiddenStopAction.setAction(&m_exitAction);
m_stepAction.setEnabled(!companionPreventsAction);
m_nextAction.setEnabled(!companionPreventsAction);
m_jumpToLineAction.setEnabled(currentEngine->hasCapability(JumpToLineCapability));
m_returnFromFunctionAction.setEnabled(currentEngine->hasCapability(ReturnFromFunctionCapability));
m_detachAction.setEnabled(!isCore);
m_abortAction.setEnabled(true);
m_resetAction.setEnabled(currentEngine->hasCapability(ResetInferiorCapability));
m_stepOutAction.setEnabled(!companionPreventsAction);
m_runToLineAction.setEnabled(currentEngine->hasCapability(RunToLineCapability));
m_runToSelectedFunctionAction.setEnabled(true);
} else if (state == InferiorRunOk) {
// Shift-F5 interrupts. It is also "interruptible".
m_startAction.setEnabled(false);
m_interruptAction.setEnabled(!companionPreventsAction);
m_continueAction.setEnabled(false);
m_exitAction.setEnabled(true);
m_debugWithoutDeployAction.setEnabled(false);
m_visibleStartAction.setAction(&m_interruptAction);
m_visibleStartAction.setIcon(interruptIcon(true));
m_hiddenStopAction.setAction(&m_interruptAction);
m_stepAction.setEnabled(false);
m_nextAction.setEnabled(false);
m_jumpToLineAction.setEnabled(false);
m_returnFromFunctionAction.setEnabled(false);
m_detachAction.setEnabled(false);
m_abortAction.setEnabled(true);
m_resetAction.setEnabled(false);
m_stepOutAction.setEnabled(false);
m_runToLineAction.setEnabled(false);
m_runToSelectedFunctionAction.setEnabled(false);
} else if (state == DebuggerFinished) {
// We don't want to do anything anymore.
m_startAction.setEnabled(canRun);
m_interruptAction.setEnabled(false);
m_continueAction.setEnabled(false);
m_exitAction.setEnabled(false);
m_debugWithoutDeployAction.setEnabled(canRun);
m_visibleStartAction.setAction(&m_startAction);
m_visibleStartAction.setIcon(startIcon(true));
m_hiddenStopAction.setAction(&m_undisturbableAction);
m_stepAction.setEnabled(false);
m_nextAction.setEnabled(false);
m_jumpToLineAction.setEnabled(false);
m_returnFromFunctionAction.setEnabled(false);
m_detachAction.setEnabled(false);
m_abortAction.setEnabled(false);
m_resetAction.setEnabled(false);
m_stepOutAction.setEnabled(false);
m_runToLineAction.setEnabled(false);
m_runToSelectedFunctionAction.setEnabled(false);
} else if (state == InferiorUnrunnable) {
// We don't want to do anything anymore.
m_startAction.setEnabled(false);
m_interruptAction.setEnabled(false);
m_continueAction.setEnabled(false);
m_exitAction.setEnabled(true);
m_debugWithoutDeployAction.setEnabled(false);
m_visibleStartAction.setAction(&m_undisturbableAction);
m_visibleStartAction.setIcon(startIcon(true));
m_hiddenStopAction.setAction(&m_exitAction);
m_stepAction.setEnabled(false);
m_nextAction.setEnabled(false);
m_jumpToLineAction.setEnabled(false);
m_returnFromFunctionAction.setEnabled(false);
m_detachAction.setEnabled(false);
m_abortAction.setEnabled(true);
m_resetAction.setEnabled(false);
m_stepOutAction.setEnabled(false);
m_runToLineAction.setEnabled(false);
m_runToSelectedFunctionAction.setEnabled(false);
} else if (state == DebuggerNotReady) {
// The startup phase should be over once we are here
QTC_CHECK(false);
} else {
// Everything else is "undisturbable".
m_startAction.setEnabled(false);
m_interruptAction.setEnabled(false);
m_continueAction.setEnabled(false);
m_exitAction.setEnabled(false);
m_debugWithoutDeployAction.setEnabled(false);
m_visibleStartAction.setAction(&m_undisturbableAction);
m_visibleStartAction.setIcon(startIcon(true));
m_hiddenStopAction.setAction(&m_undisturbableAction);
m_stepAction.setEnabled(false);
m_nextAction.setEnabled(false);
m_jumpToLineAction.setEnabled(false);
m_returnFromFunctionAction.setEnabled(false);
m_detachAction.setEnabled(false);
m_abortAction.setEnabled(true);
m_resetAction.setEnabled(false);
m_stepOutAction.setEnabled(false);
m_runToLineAction.setEnabled(false);
m_runToSelectedFunctionAction.setEnabled(false);
}
// FIXME: Decentralize the actions below
const bool actionsEnabled = currentEngine->debuggerActionsEnabled();
const bool canDeref = actionsEnabled && currentEngine->hasCapability(AutoDerefPointersCapability);
action(AutoDerefPointers)->setEnabled(canDeref);
action(AutoDerefPointers)->setEnabled(true);
action(ExpandStack)->setEnabled(actionsEnabled);
m_startAndDebugApplicationAction.setEnabled(true);
m_attachToQmlPortAction.setEnabled(true);
m_attachToCoreAction.setEnabled(true);
m_attachToRemoteServerAction.setEnabled(true);
m_attachToRunningApplication.setEnabled(true);
m_attachToUnstartedApplication.setEnabled(true);
m_watchAction.setEnabled(true);
m_breakAction.setEnabled(true);
}
void DebuggerPluginPrivate::onStartupProjectChanged(Project *project)
{
RunConfiguration *activeRc = nullptr;
if (project) {
Target *target = project->activeTarget();
if (target)
activeRc = target->activeRunConfiguration();
if (!activeRc)
return;
}
for (DebuggerEngine *engine : EngineManager::engines()) {
// Run controls might be deleted during exit.
engine->updateState(false);
}
updatePresetState();
}
void DebuggerPluginPrivate::attachCore()
{
AttachCoreDialog dlg(ICore::dialogParent());
const QString lastExternalKit = configValue("LastExternalKit").toString();
if (!lastExternalKit.isEmpty())
dlg.setKitId(Id::fromString(lastExternalKit));
dlg.setLocalExecutableFile(configValue("LastExternalExecutableFile").toString());
dlg.setLocalCoreFile(configValue("LastLocalCoreFile").toString());
dlg.setRemoteCoreFile(configValue("LastRemoteCoreFile").toString());
dlg.setOverrideStartScript(configValue("LastExternalStartScript").toString());
dlg.setForceLocalCoreFile(configValue("LastForceLocalCoreFile").toBool());
if (dlg.exec() != QDialog::Accepted)
return;
setConfigValue("LastExternalExecutableFile", dlg.localExecutableFile());
setConfigValue("LastLocalCoreFile", dlg.localCoreFile());
setConfigValue("LastRemoteCoreFile", dlg.remoteCoreFile());
setConfigValue("LastExternalKit", dlg.kit()->id().toSetting());
setConfigValue("LastExternalStartScript", dlg.overrideStartScript());
setConfigValue("LastForceLocalCoreFile", dlg.forcesLocalCoreFile());
IDevice::ConstPtr device = DeviceKitInformation::device(dlg.kit());
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, dlg.kit());
debugger->setInferiorExecutable(dlg.localExecutableFile());
debugger->setCoreFileName(dlg.localCoreFile());
debugger->setRunControlName(tr("Core file \"%1\"")
.arg(dlg.useLocalCoreFile() ? dlg.localCoreFile() : dlg.remoteCoreFile()));
debugger->setStartMode(AttachCore);
debugger->setCloseMode(DetachAtClose);
debugger->setOverrideStartScript(dlg.overrideStartScript());
debugger->startRunControl();
}
void DebuggerPluginPrivate::startRemoteCdbSession()
{
const QString connectionKey = "CdbRemoteConnection";
Kit *kit = findUniversalCdbKit();
QTC_ASSERT(kit, return);
StartRemoteCdbDialog dlg(ICore::dialogParent());
QString previousConnection = configValue(connectionKey).toString();
if (previousConnection.isEmpty())
previousConnection = "localhost:1234";
dlg.setConnection(previousConnection);
if (dlg.exec() != QDialog::Accepted)
return;
setConfigValue(connectionKey, dlg.connection());
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, kit);
debugger->setStartMode(AttachToRemoteServer);
debugger->setCloseMode(KillAtClose);
debugger->setRemoteChannel(dlg.connection());
debugger->startRunControl();
}
class RemoteAttachRunner : public DebuggerRunTool
{
public:
RemoteAttachRunner(RunControl *runControl, Kit *kit, int pid)
: DebuggerRunTool(runControl, kit)
{
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
setDisplayName("AttachToRunningProcess");
setUsePortsGatherer(true, false);
portsGatherer()->setDevice(device);
auto gdbServer = new GdbServerRunner(runControl, portsGatherer());
gdbServer->setUseMulti(false);
gdbServer->setDevice(device);
gdbServer->setAttachPid(ProcessHandle(pid));
addStartDependency(gdbServer);
setStartMode(AttachToRemoteProcess);
setCloseMode(DetachAtClose);
// setInferiorExecutable(localExecutable);
setUseContinueInsteadOfRun(true);
setContinueAfterAttach(false);
}
};
void DebuggerPluginPrivate::attachToRunningApplication()
{
auto kitChooser = new DebuggerKitChooser(DebuggerKitChooser::AnyDebugging);
auto dlg = new DeviceProcessesDialog(kitChooser, ICore::dialogParent());
dlg->addAcceptButton(DeviceProcessesDialog::tr("&Attach to Process"));
dlg->showAllDevices();
if (dlg->exec() == QDialog::Rejected) {
delete dlg;
return;
}
dlg->setAttribute(Qt::WA_DeleteOnClose);
Kit *kit = kitChooser->currentKit();
QTC_ASSERT(kit, return);
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device, return);
DeviceProcessItem process = dlg->currentProcess();
if (device->type() == PE::DESKTOP_DEVICE_TYPE) {
attachToRunningProcess(kit, process, false);
} else {
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new RemoteAttachRunner(runControl, kit, process.pid);
debugger->startRunControl();
}
}
void DebuggerPluginPrivate::attachToUnstartedApplicationDialog()
{
auto dlg = new UnstartedAppWatcherDialog(ICore::dialogParent());
connect(dlg, &QDialog::finished, dlg, &QObject::deleteLater);
connect(dlg, &UnstartedAppWatcherDialog::processFound, this, [this, dlg] {
RunControl *rc = attachToRunningProcess(dlg->currentKit(),
dlg->currentProcess(),
dlg->continueOnAttach());
if (!rc)
return;
if (dlg->hideOnAttach())
connect(rc, &RunControl::stopped, dlg, &UnstartedAppWatcherDialog::startWatching);
});
dlg->show();
}
RunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
DeviceProcessItem process, bool contAfterAttach)
{
QTC_ASSERT(kit, return nullptr);
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device, return nullptr);
if (process.pid == 0) {
AsynchronousMessageBox::warning(tr("Warning"), tr("Cannot attach to process with PID 0"));
return nullptr;
}
const Abi tcAbi = ToolChainKitInformation::targetAbi(kit);
const bool isWindows = (tcAbi.os() == Abi::WindowsOS);
if (isWindows && isWinProcessBeingDebugged(process.pid)) {
AsynchronousMessageBox::warning(
tr("Process Already Under Debugger Control"),
tr("The process %1 is already under the control of a debugger.\n"
"%2 cannot attach to it.").arg(process.pid)
.arg(Core::Constants::IDE_DISPLAY_NAME));
return nullptr;
}
if (device->type() != PE::DESKTOP_DEVICE_TYPE) {
AsynchronousMessageBox::warning(tr("Not a Desktop Device Type"),
tr("It is only possible to attach to a locally running process."));
return nullptr;
}
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, kit);
debugger->setAttachPid(ProcessHandle(process.pid));
debugger->setRunControlName(tr("Process %1").arg(process.pid));
debugger->setInferiorExecutable(process.exe);
debugger->setInferiorDevice(device);
debugger->setStartMode(AttachExternal);
debugger->setCloseMode(DetachAtClose);
debugger->setContinueAfterAttach(contAfterAttach);
debugger->startRunControl();
return debugger->runControl();
}
void DebuggerPlugin::attachExternalApplication(RunControl *rc)
{
ProcessHandle pid = rc->applicationProcessHandle();
RunConfiguration *runConfig = rc->runConfiguration();
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, guessKitFromAbis({rc->abi()}), false);
debugger->setAttachPid(pid);
debugger->setRunControlName(tr("Process %1").arg(pid.pid()));
debugger->setStartMode(AttachExternal);
debugger->setCloseMode(DetachAtClose);
debugger->startRunControl();
}
void DebuggerPlugin::getEnginesState(QByteArray *json) const
{
QTC_ASSERT(json, return);
QVariantMap result {
{"version", 1}
};
QVariantMap states;
int i = 0;
DebuggerEngine *currentEngine = EngineManager::currentEngine();
for (DebuggerEngine *engine : EngineManager::engines()) {
states[QString::number(i)] = QVariantMap({
{"current", engine == currentEngine},
{"pid", engine->inferiorPid()},
{"state", engine->state()}
});
++i;
}
if (!states.isEmpty())
result["states"] = states;
*json = QJsonDocument(QJsonObject::fromVariantMap(result)).toJson();
}
void DebuggerPluginPrivate::attachToQmlPort()
{
AttachToQmlPortDialog dlg(ICore::mainWindow());
const QVariant qmlServerPort = configValue("LastQmlServerPort");
if (qmlServerPort.isValid())
dlg.setPort(qmlServerPort.toInt());
else
dlg.setPort(-1);
const Id kitId = Id::fromSetting(configValue("LastProfile"));
if (kitId.isValid())
dlg.setKitId(kitId);
if (dlg.exec() != QDialog::Accepted)
return;
Kit *kit = dlg.kit();
QTC_ASSERT(kit, return);
setConfigValue("LastQmlServerPort", dlg.port());
setConfigValue("LastProfile", kit->id().toSetting());
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device, return);
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, kit);
QUrl qmlServer = device->toolControlChannel(IDevice::QmlControlChannel);
qmlServer.setPort(dlg.port());
debugger->setQmlServer(qmlServer);
QSsh::SshConnectionParameters sshParameters = device->sshParameters();
debugger->setRemoteChannel(sshParameters.host(), sshParameters.port());
debugger->setStartMode(AttachToQmlServer);
debugger->startRunControl();
}
void DebuggerPluginPrivate::runScheduled()
{
for (DebuggerRunTool *debugger : m_scheduledStarts)
debugger->startRunControl();
}
void DebuggerPluginPrivate::editorOpened(IEditor *editor)
{
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
connect(widget, &TextEditorWidget::markRequested,
this, &DebuggerPluginPrivate::requestMark);
connect(widget, &TextEditorWidget::markContextMenuRequested,
this, &DebuggerPluginPrivate::requestContextMenu);
}
}
void DebuggerPluginPrivate::updateBreakMenuItem(IEditor *editor)
{
BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
m_breakAction.setEnabled(textEditor != nullptr);
}
void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget,
int lineNumber, QMenu *menu)
{
GlobalBreakpoint gbp;
TextDocument *document = widget->textDocument();
ContextData args = getLocationContext(document, lineNumber);
if (args.type == LocationByAddress) {
BreakpointParameters needle;
needle.type = BreakpointByAddress;
needle.address = args.address;
needle.lineNumber = -1;
gbp = BreakpointManager::findSimilarBreakpoint(needle);
} else if (args.type == LocationByFile) {
gbp = BreakpointManager::findBreakpointByLocation(args);
}
if (gbp) {
// Remove existing breakpoint.
auto act = menu->addAction(tr("Remove Breakpoint"));
connect(act, &QAction::triggered, [gbp] { gbp->deleteBreakpoint(); });
// // Enable/disable existing breakpoint.
// if (gbp->isEnabled()) {
// act = menu->addAction(tr("Disable Breakpoint %1").arg(id));
// connect(act, &QAction::triggered, [gbp] { gbp.setEnabled(false); });
// } else {
// act = menu->addAction(tr("Enable Breakpoint %1").arg(id));
// connect(act, &QAction::triggered, [gbp] { gbp.setEnabled(true); });
// }
// // Edit existing breakpoint.
// act = menu->addAction(tr("Edit Breakpoint %1...").arg(id));
// connect(act, &QAction::triggered, [gbp] {
// globalBreakHandler()->editBreakpoint(gbp, ICore::dialogParent());
// });
} else {
// Handle non-existing breakpoint.
const QString text = args.address
? tr("Set Breakpoint at 0x%1").arg(args.address, 0, 16)
: tr("Set Breakpoint at Line %1").arg(lineNumber);
auto act = menu->addAction(text);
act->setEnabled(args.isValid());
connect(act, &QAction::triggered, [this, args] {
breakpointSetMarginActionTriggered(false, args);
});
// Message trace point
const QString tracePointText = args.address
? tr("Set Message Tracepoint at 0x%1...").arg(args.address, 0, 16)
: tr("Set Message Tracepoint at Line %1...").arg(lineNumber);
act = menu->addAction(tracePointText);
act->setEnabled(args.isValid());
connect(act, &QAction::triggered, [this, args] {
breakpointSetMarginActionTriggered(true, args);
});
}
// Run to, jump to line below in stopped state.
for (const QPointer<DebuggerEngine> engine : EngineManager::engines()) {
if (engine->state() == InferiorStopOk && args.isValid()) {
menu->addSeparator();
if (engine->hasCapability(RunToLineCapability)) {
auto act = menu->addAction(args.address
? DebuggerEngine::tr("Run to Address 0x%1").arg(args.address, 0, 16)
: DebuggerEngine::tr("Run to Line %1").arg(args.lineNumber));
connect(act, &QAction::triggered, this, [args, engine] {
QTC_ASSERT(engine, return);
engine->executeRunToLine(args);
});
}
if (engine->hasCapability(JumpToLineCapability)) {
auto act = menu->addAction(args.address
? DebuggerEngine::tr("Jump to Address 0x%1").arg(args.address, 0, 16)
: DebuggerEngine::tr("Jump to Line %1").arg(args.lineNumber));
connect(act, &QAction::triggered, this, [args, engine] {
QTC_ASSERT(engine, return);
engine->executeJumpToLine(args);
});
}
// Disassemble current function in stopped state.
if (engine->hasCapability(DisassemblerCapability)) {
StackFrame frame;
frame.function = cppFunctionAt(args.fileName, lineNumber, 1);
frame.line = 42; // trick gdb into mixed mode.
if (!frame.function.isEmpty()) {
const QString text = tr("Disassemble Function \"%1\"")
.arg(frame.function);
auto act = new QAction(text, menu);
connect(act, &QAction::triggered, this, [frame, engine] {
QTC_ASSERT(engine, return);
engine->openDisassemblerView(Location(frame));
});
menu->addAction(act);
}
}
}
}
}
void DebuggerPluginPrivate::toggleBreakpointHelper()
{
BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor();
QTC_ASSERT(textEditor, return);
const int lineNumber = textEditor->currentLine();
ContextData location = getLocationContext(textEditor->textDocument(), lineNumber);
if (location.isValid())
BreakpointManager::toggleBreakpoint(location);
}
void DebuggerPluginPrivate::requestMark(TextEditorWidget *widget, int lineNumber,
TextMarkRequestKind kind)
{
if (kind == BreakpointRequest) {
ContextData location = getLocationContext(widget->textDocument(), lineNumber);
if (location.isValid())
BreakpointManager::toggleBreakpoint(location);
}
}
void DebuggerPluginPrivate::setInitialState()
{
m_toolTipManager.closeAllToolTips();
m_startAndDebugApplicationAction.setEnabled(true);
m_attachToQmlPortAction.setEnabled(true);
m_attachToCoreAction.setEnabled(true);
m_attachToRemoteServerAction.setEnabled(true);
m_attachToRunningApplication.setEnabled(true);
m_attachToUnstartedApplication.setEnabled(true);
m_detachAction.setEnabled(false);
m_watchAction.setEnabled(true);
m_breakAction.setEnabled(false);
//m_snapshotAction.setEnabled(false);
action(OperateByInstruction)->setChecked(false);
m_exitAction.setEnabled(false);
m_abortAction.setEnabled(false);
m_resetAction.setEnabled(false);
m_interruptAction.setEnabled(false);
m_continueAction.setEnabled(false);
m_stepAction.setEnabled(true);
m_stepOutAction.setEnabled(false);
m_runToLineAction.setEnabled(false);
m_runToSelectedFunctionAction.setEnabled(true);
m_returnFromFunctionAction.setEnabled(false);
m_jumpToLineAction.setEnabled(false);
m_nextAction.setEnabled(true);
action(AutoDerefPointers)->setEnabled(true);
action(ExpandStack)->setEnabled(false);
}
void DebuggerPluginPrivate::updateDebugWithoutDeployMenu()
{
const bool state = ProjectExplorerPlugin::projectExplorerSettings().deployBeforeRun;
m_debugWithoutDeployAction.setVisible(state);
}
void DebuggerPluginPrivate::dumpLog()
{
DebuggerEngine *engine = EngineManager::currentEngine();
if (!engine)
return;
LogWindow *logWindow = engine->logWindow();
QTC_ASSERT(logWindow, return);
QString fileName = QFileDialog::getSaveFileName(ICore::mainWindow(),
tr("Save Debugger Log"), Utils::TemporaryDirectory::masterDirectoryPath());
if (fileName.isEmpty())
return;
FileSaver saver(fileName);
if (!saver.hasError()) {
QTextStream ts(saver.file());
ts << logWindow->inputContents();
ts << "\n\n=======================================\n\n";
ts << logWindow->combinedContents();
saver.setResult(&ts);
}
saver.finalize(ICore::mainWindow());
}
void DebuggerPluginPrivate::sessionLoaded()
{
BreakpointManager::loadSessionData();
WatchHandler::loadSessionData();
DebuggerToolTipManager::loadSessionData();
}
void DebuggerPluginPrivate::aboutToUnloadSession()
{
BreakpointManager::aboutToUnloadSession();
m_toolTipManager.sessionAboutToChange();
}
void DebuggerPluginPrivate::aboutToSaveSession()
{
WatchHandler::saveSessionData();
BreakpointManager::saveSessionData();
DebuggerToolTipManager::saveSessionData();
}
void DebuggerPluginPrivate::aboutToShutdown()
{
m_shuttingDown = true;
disconnect(SessionManager::instance(), &SessionManager::startupProjectChanged, this, nullptr);
m_shutdownTimer.setInterval(0);
m_shutdownTimer.setSingleShot(true);
connect(&m_shutdownTimer, &QTimer::timeout, this, &DebuggerPluginPrivate::doShutdown);
for (DebuggerEngine *engine : m_engineManager.engines()) {
if (engine && engine->state() != Debugger::DebuggerNotReady) {
engine->abortDebugger();
m_shutdownTimer.setInterval(3000);
}
}
m_shutdownTimer.start();
}
void setSessionValue(const QByteArray &key, const QVariant &value)
{
SessionManager::setValue(QString::fromUtf8(key), value);
}
QVariant sessionValue(const QByteArray &key)
{
return SessionManager::value(QString::fromUtf8(key));
}
static void createNewDock(QWidget *widget)
{
auto dockWidget = new QDockWidget;
dockWidget->setWidget(widget);
dockWidget->setWindowTitle(widget->windowTitle());
dockWidget->setFeatures(QDockWidget::DockWidgetClosable);
dockWidget->show();
}
void DebuggerPluginPrivate::remoteCommand(const QStringList &options)
{
if (options.isEmpty())
return;
QString errorMessage;
if (!parseArguments(options, &errorMessage)) {
qWarning("%s", qPrintable(errorMessage));
return;
}
runScheduled();
}
QMessageBox *showMessageBox(int icon, const QString &title,
const QString &text, int buttons)
{
QMessageBox *mb = new QMessageBox(QMessageBox::Icon(icon),
title, text, QMessageBox::StandardButtons(buttons),
ICore::mainWindow());
mb->setAttribute(Qt::WA_DeleteOnClose);
mb->setTextInteractionFlags(Qt::TextSelectableByMouse);
mb->show();
return mb;
}
void addDebugInfoTask(unsigned id, const QString &cmd)
{
dd->m_debugInfoTaskHandler.addTask(id, cmd);
}
bool isReverseDebuggingEnabled()
{
return true;
static bool enabled = qEnvironmentVariableIsSet("QTC_DEBUGGER_ENABLE_REVERSE");
return enabled;
}
void DebuggerPluginPrivate::extensionsInitialized()
{
// If the CppEditor or QmlJS editor plugin is there, we want to add something to
// the editor context menu.
for (Id menuId : { CppEditor::Constants::M_CONTEXT, QmlJSEditor::Constants::M_CONTEXT }) {
if (ActionContainer *editorContextMenu = ActionManager::actionContainer(menuId)) {
auto cmd = editorContextMenu->addSeparator(m_watchCommand->context());
cmd->setAttribute(Command::CA_Hide);
cmd = m_watchCommand;
cmd->action()->setEnabled(true);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
cmd->setAttribute(Command::CA_NonConfigurable);
}
}
auto constraint = [](RunConfiguration *runConfig) {
Runnable runnable = runConfig->runnable();
if (runnable.device && runnable.device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
return true;
if (DeviceTypeKitInformation::deviceTypeId(runConfig->target()->kit())
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
return true;
QString mainScript = runConfig->property("mainScript").toString();
const bool isDebuggableScript = mainScript.endsWith(".py"); // Only Python for now.
return isDebuggableScript;
};
RunControl::registerWorker<DebuggerRunTool>
(ProjectExplorer::Constants::DEBUG_RUN_MODE, constraint);
}
SavedAction *action(int code)
{
return dd->m_debuggerSettings->item(code);
}
bool boolSetting(int code)
{
return dd->m_debuggerSettings->item(code)->value().toBool();
}
QString stringSetting(int code)
{
return dd->m_debuggerSettings->item(code)->value().toString();
}
QStringList stringListSetting(int code)
{
return dd->m_debuggerSettings->item(code)->value().toStringList();
}
void showModuleSymbols(const QString &moduleName, const Symbols &symbols)
{
auto w = new QTreeWidget;
w->setUniformRowHeights(true);
w->setColumnCount(5);
w->setRootIsDecorated(false);
w->setAlternatingRowColors(true);
w->setSortingEnabled(true);
w->setObjectName(QLatin1String("Symbols.") + moduleName);
QStringList header;
header.append(DebuggerPlugin::tr("Symbol"));
header.append(DebuggerPlugin::tr("Address"));
header.append(DebuggerPlugin::tr("Code"));
header.append(DebuggerPlugin::tr("Section"));
header.append(DebuggerPlugin::tr("Name"));
w->setHeaderLabels(header);
w->setWindowTitle(DebuggerPlugin::tr("Symbols in \"%1\"").arg(moduleName));
for (const Symbol &s : symbols) {
auto it = new QTreeWidgetItem;
it->setData(0, Qt::DisplayRole, s.name);
it->setData(1, Qt::DisplayRole, s.address);
it->setData(2, Qt::DisplayRole, s.state);
it->setData(3, Qt::DisplayRole, s.section);
it->setData(4, Qt::DisplayRole, s.demangled);
w->addTopLevelItem(it);
}
createNewDock(w);
}
void showModuleSections(const QString &moduleName, const Sections §ions)
{
auto w = new QTreeWidget;
w->setUniformRowHeights(true);
w->setColumnCount(5);
w->setRootIsDecorated(false);
w->setAlternatingRowColors(true);
w->setSortingEnabled(true);
w->setObjectName(QLatin1String("Sections.") + moduleName);
QStringList header;
header.append(DebuggerPlugin::tr("Name"));
header.append(DebuggerPlugin::tr("From"));
header.append(DebuggerPlugin::tr("To"));
header.append(DebuggerPlugin::tr("Address"));
header.append(DebuggerPlugin::tr("Flags"));
w->setHeaderLabels(header);
w->setWindowTitle(DebuggerPlugin::tr("Sections in \"%1\"").arg(moduleName));
for (const Section &s : sections) {
auto it = new QTreeWidgetItem;
it->setData(0, Qt::DisplayRole, s.name);
it->setData(1, Qt::DisplayRole, s.from);
it->setData(2, Qt::DisplayRole, s.to);
it->setData(3, Qt::DisplayRole, s.address);
it->setData(4, Qt::DisplayRole, s.flags);
w->addTopLevelItem(it);
}
createNewDock(w);
}
void DebuggerPluginPrivate::doShutdown()
{
m_shutdownTimer.stop();
delete m_mainWindow;
m_mainWindow = nullptr;
delete m_modeWindow;
m_modeWindow = nullptr;
delete m_mode;
m_mode = nullptr;
emit m_plugin->asynchronousShutdownFinished();
}
void openTextEditor(const QString &titlePattern0, const QString &contents)
{
if (dd->m_shuttingDown)
return;
QString titlePattern = titlePattern0;
IEditor *editor = EditorManager::openEditorWithContents(
CC::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, contents.toUtf8(), QString(),
EditorManager::IgnoreNavigationHistory);
if (auto textEditor = qobject_cast<BaseTextEditor *>(editor)) {
QString suggestion = titlePattern;
if (!suggestion.contains(QLatin1Char('.')))
suggestion.append(QLatin1String(".txt"));
textEditor->textDocument()->setFallbackSaveAsFileName(suggestion);
}
QTC_ASSERT(editor, return);
}
QWidget *mainWindow()
{
return dd->m_mainWindow;
}
QSharedPointer<Internal::GlobalDebuggerOptions> globalDebuggerOptions()
{
return dd->m_globalDebuggerOptions;
}
///////////////////////////////////////////////////////////////////////
//
// DebuggerPlugin
//
///////////////////////////////////////////////////////////////////////
/*!
\class Debugger::DebuggerPlugin
This is the "external" interface of the debugger plugin that's visible
from Qt Creator core. The internal interface to global debugger
functionality that is used by debugger views and debugger engines
is DebuggerCore, implemented in DebuggerPluginPrivate.
*/
static DebuggerPlugin *m_instance = nullptr;
DebuggerPlugin::DebuggerPlugin()
{
setObjectName(QLatin1String("DebuggerPlugin"));
m_instance = this;
}
DebuggerPlugin::~DebuggerPlugin()
{
delete dd;
dd = nullptr;
m_instance = nullptr;
}
DebuggerPlugin *DebuggerPlugin::instance()
{
return m_instance;
}
bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
dd = new DebuggerPluginPrivate(this);
// Needed for call from AppOutputPane::attachToRunControl() and GammarayIntegration.
ExtensionSystem::PluginManager::addObject(this);
// Menu groups
ActionContainer *mstart = ActionManager::actionContainer(PE::M_DEBUG_STARTDEBUGGING);
mstart->appendGroup(Constants::G_GENERAL);
mstart->appendGroup(Constants::G_SPECIAL);
mstart->appendGroup(Constants::G_START_QML);
// Separators
mstart->addSeparator(Constants::G_GENERAL);
mstart->addSeparator(Constants::G_SPECIAL);
KitManager::registerKitInformation<DebuggerKitInformation>();
// Task integration.
//: Category under which Analyzer tasks are listed in Issues view
ProjectExplorer::TaskHub::addCategory(Debugger::Constants::ANALYZERTASK_ID, tr("Debugger"));
return dd->initialize(arguments, errorMessage);
}
IPlugin::ShutdownFlag DebuggerPlugin::aboutToShutdown()
{
ExtensionSystem::PluginManager::removeObject(this);
dd->aboutToShutdown();
return AsynchronousShutdown;
}
QObject *DebuggerPlugin::remoteCommand(const QStringList &options,
const QString &workingDirectory,
const QStringList &list)
{
Q_UNUSED(workingDirectory);
Q_UNUSED(list);
dd->remoteCommand(options);
return nullptr;
}
void DebuggerPlugin::extensionsInitialized()
{
dd->extensionsInitialized();
}
void DebuggerPluginPrivate::onModeChanged(Id mode)
{
m_mainWindow->onModeChanged(mode);
// FIXME: This one gets always called, even if switching between modes
// different then the debugger mode. E.g. Welcome and Help mode and
// also on shutdown.
if (mode == MODE_DEBUG) {
// if (EngineManager::engines().isEmpty())
// m_mainWindow->restorePerspective(Constants::PRESET_PERSPRECTIVE_ID);
EngineManager::selectUiForCurrentEngine();
if (IEditor *editor = EditorManager::currentEditor())
editor->widget()->setFocus();
m_toolTipManager.debugModeEntered();
} else {
m_toolTipManager.leavingDebugMode();
}
}
} // namespace Internal
static bool buildTypeAccepted(QFlags<ToolMode> toolMode, BuildConfiguration::BuildType buildType)
{
if (buildType == BuildConfiguration::Unknown)
return true;
if (buildType == BuildConfiguration::Debug && (toolMode & DebugMode))
return true;
if (buildType == BuildConfiguration::Release && (toolMode & ReleaseMode))
return true;
if (buildType == BuildConfiguration::Profile && (toolMode & ProfileMode))
return true;
return false;
}
static BuildConfiguration::BuildType startupBuildType()
{
BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown;
if (RunConfiguration *runConfig = RunConfiguration::startupRunConfiguration()) {
if (const BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration())
buildType = buildConfig->buildType();
}
return buildType;
}
void showCannotStartDialog(const QString &text)
{
auto errorDialog = new QMessageBox(ICore::mainWindow());
errorDialog->setAttribute(Qt::WA_DeleteOnClose);
errorDialog->setIcon(QMessageBox::Warning);
errorDialog->setWindowTitle(text);
errorDialog->setText(DebuggerPlugin::tr("Cannot start %1 without a project. Please open the project "
"and try again.").arg(text));
errorDialog->setStandardButtons(QMessageBox::Ok);
errorDialog->setDefaultButton(QMessageBox::Ok);
errorDialog->show();
}
bool wantRunTool(ToolMode toolMode, const QString &toolName)
{
// Check the project for whether the build config is in the correct mode
// if not, notify the user and urge him to use the correct mode.
BuildConfiguration::BuildType buildType = startupBuildType();
if (!buildTypeAccepted(toolMode, buildType)) {
QString currentMode;
switch (buildType) {
case BuildConfiguration::Debug:
currentMode = DebuggerPlugin::tr("Debug");
break;
case BuildConfiguration::Profile:
currentMode = DebuggerPlugin::tr("Profile");
break;
case BuildConfiguration::Release:
currentMode = DebuggerPlugin::tr("Release");
break;
default:
QTC_CHECK(false);
}
QString toolModeString;
switch (toolMode) {
case DebugMode:
toolModeString = DebuggerPlugin::tr("in Debug mode");
break;
case ProfileMode:
toolModeString = DebuggerPlugin::tr("in Profile mode");
break;
case ReleaseMode:
toolModeString = DebuggerPlugin::tr("in Release mode");
break;
case SymbolsMode:
toolModeString = DebuggerPlugin::tr("with debug symbols (Debug or Profile mode)");
break;
case OptimizedMode:
toolModeString = DebuggerPlugin::tr("on optimized code (Profile or Release mode)");
break;
default:
QTC_CHECK(false);
}
const QString title = DebuggerPlugin::tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode);
const QString message = DebuggerPlugin::tr("<html><head/><body><p>You are trying "
"to run the tool \"%1\" on an application in %2 mode. "
"The tool is designed to be used %3.</p><p>"
"Run-time characteristics differ significantly between "
"optimized and non-optimized binaries. Analytical "
"findings for one mode may or may not be relevant for "
"the other.</p><p>"
"Running tools that need debug symbols on binaries that "
"don't provide any may lead to missing function names "
"or otherwise insufficient output.</p><p>"
"Do you want to continue and run the tool in %2 mode?</p></body></html>")
.arg(toolName).arg(currentMode).arg(toolModeString);
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(),
title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning"))
!= QDialogButtonBox::Yes)
return false;
}
return true;
}
QAction *createStartAction()
{
auto action = new QAction(DebuggerMainWindow::tr("Start"), DebuggerPlugin::instance());
action->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL_TOOLBAR.icon());
action->setEnabled(true);
return action;
}
QAction *createStopAction()
{
auto action = new QAction(DebuggerMainWindow::tr("Stop"), DebuggerPlugin::instance());
action->setIcon(Utils::Icons::STOP_SMALL_TOOLBAR.icon());
action->setEnabled(true);
return action;
}
void registerPerspective(Perspective *perspective)
{
dd->m_mainWindow->registerPerspective(perspective);
}
void selectPerspective(const QByteArray &perspectiveId)
{
if (auto perspective = dd->m_mainWindow->findPerspective(perspectiveId))
perspective->select();
}
QWidget *mainWindow()
{
return dd->m_mainWindow;
}
void enableMainWindow(bool on)
{
dd->m_mainWindow->setEnabled(on);
}
void showStatusMessage(const QString &message, int timeoutMS)
{
dd->m_mainWindow->showStatusMessage(message, timeoutMS);
}
void showPermanentStatusMessage(const QString &message)
{
dd->m_mainWindow->showStatusMessage(message, -1);
}
namespace Internal {
static bool s_testRun = false;
bool isTestRun() { return s_testRun; }
#ifdef WITH_TESTS
class DebuggerUnitTests : public QObject
{
Q_OBJECT
public:
DebuggerUnitTests() = default;
private slots:
void initTestCase();
void cleanupTestCase();
void testDebuggerMatching_data();
void testDebuggerMatching();
void testBenchmark();
void testStateMachine();
private:
CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
};
void DebuggerUnitTests::initTestCase()
{
// const QList<Kit *> allKits = KitManager::kits();
// if (allKits.count() != 1)
// QSKIP("This test requires exactly one kit to be present");
// const ToolChain * const toolchain = ToolChainKitInformation::toolChain(allKits.first());
// if (!toolchain)
// QSKIP("This test requires that there is a kit with a toolchain.");
// bool hasClangExecutable;
// clangExecutableFromSettings(toolchain->typeId(), &hasClangExecutable);
// if (!hasClangExecutable)
// QSKIP("No clang suitable for analyzing found");
s_testRun = true;
m_tmpDir = new CppTools::Tests::TemporaryCopiedDir(QLatin1String(":/unit-tests"));
QVERIFY(m_tmpDir->isValid());
}
void DebuggerUnitTests::cleanupTestCase()
{
delete m_tmpDir;
}
void DebuggerUnitTests::testStateMachine()
{
QString proFile = m_tmpDir->absolutePath("simple/simple.pro");
CppTools::Tests::ProjectOpenerAndCloser projectManager;
const CppTools::ProjectInfo projectInfo = projectManager.open(proFile, true);
QVERIFY(projectInfo.isValid());
QEventLoop loop;
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
&loop, &QEventLoop::quit);
ProjectExplorerPlugin::buildProject(SessionManager::startupProject());
loop.exec();
ExecuteOnDestruction guard([] { EditorManager::closeAllEditors(false); });
Target *t = SessionManager::startupProject()->activeTarget();
QVERIFY(t);
RunConfiguration *rc = t->activeRunConfiguration();
QVERIFY(rc);
auto runControl = new RunControl(rc, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl);
debugger->setInferior(rc->runnable());
debugger->setTestCase(TestNoBoundsOfCurrentFunction);
connect(debugger, &DebuggerRunTool::stopped,
&QTestEventLoop::instance(), &QTestEventLoop::exitLoop);
debugger->startRunControl();
QTestEventLoop::instance().enterLoop(5);
}
enum FakeEnum { FakeDebuggerCommonSettingsId };
void DebuggerUnitTests::testBenchmark()
{
#ifdef WITH_BENCHMARK
CALLGRIND_START_INSTRUMENTATION;
volatile Id id1 = Id(DEBUGGER_COMMON_SETTINGS_ID);
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
CALLGRIND_START_INSTRUMENTATION;
volatile FakeEnum id2 = FakeDebuggerCommonSettingsId;
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
#endif
}
void DebuggerUnitTests::testDebuggerMatching_data()
{
QTest::addColumn<QStringList>("debugger");
QTest::addColumn<QString>("target");
QTest::addColumn<int>("result");
QTest::newRow("Invalid data")
<< QStringList()
<< QString()
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Invalid debugger")
<< QStringList()
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Invalid target")
<< QStringList("x86-linux-generic-elf-32bit")
<< QString()
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Fuzzy match 1")
<< QStringList("unknown-unknown-unknown-unknown-0bit")
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::MatchesWell); // Is this the expected behavior?
QTest::newRow("Fuzzy match 2")
<< QStringList("unknown-unknown-unknown-unknown-0bit")
<< QString::fromLatin1("arm-windows-msys-pe-64bit")
<< int(DebuggerItem::MatchesWell); // Is this the expected behavior?
QTest::newRow("Architecture mismatch")
<< QStringList("x86-linux-generic-elf-32bit")
<< QString::fromLatin1("arm-linux-generic-elf-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("OS mismatch")
<< QStringList("x86-linux-generic-elf-32bit")
<< QString::fromLatin1("x86-macosx-generic-elf-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Format mismatch")
<< QStringList("x86-linux-generic-elf-32bit")
<< QString::fromLatin1("x86-linux-generic-pe-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Linux perfect match")
<< QStringList("x86-linux-generic-elf-32bit")
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::MatchesWell);
QTest::newRow("Linux match")
<< QStringList("x86-linux-generic-elf-64bit")
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::MatchesSomewhat);
QTest::newRow("Windows perfect match 1")
<< QStringList("x86-windows-msvc2013-pe-64bit")
<< QString::fromLatin1("x86-windows-msvc2013-pe-64bit")
<< int(DebuggerItem::MatchesWell);
QTest::newRow("Windows perfect match 2")
<< QStringList("x86-windows-msvc2013-pe-64bit")
<< QString::fromLatin1("x86-windows-msvc2012-pe-64bit")
<< int(DebuggerItem::MatchesWell);
QTest::newRow("Windows match 1")
<< QStringList("x86-windows-msvc2013-pe-64bit")
<< QString::fromLatin1("x86-windows-msvc2013-pe-32bit")
<< int(DebuggerItem::MatchesSomewhat);
QTest::newRow("Windows match 2")
<< QStringList("x86-windows-msvc2013-pe-64bit")
<< QString::fromLatin1("x86-windows-msvc2012-pe-32bit")
<< int(DebuggerItem::MatchesSomewhat);
QTest::newRow("Windows mismatch on word size")
<< QStringList("x86-windows-msvc2013-pe-32bit")
<< QString::fromLatin1("x86-windows-msvc2013-pe-64bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Windows mismatch on osflavor 1")
<< QStringList("x86-windows-msvc2013-pe-32bit")
<< QString::fromLatin1("x86-windows-msys-pe-64bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Windows mismatch on osflavor 2")
<< QStringList("x86-windows-msys-pe-32bit")
<< QString::fromLatin1("x86-windows-msvc2010-pe-64bit")
<< int(DebuggerItem::DoesNotMatch);
}
void DebuggerUnitTests::testDebuggerMatching()
{
QFETCH(QStringList, debugger);
QFETCH(QString, target);
QFETCH(int, result);
auto expectedLevel = static_cast<DebuggerItem::MatchLevel>(result);
QList<Abi> debuggerAbis;
foreach (const QString &abi, debugger)
debuggerAbis << Abi::fromString(abi);
DebuggerItem item;
item.setAbis(debuggerAbis);
DebuggerItem::MatchLevel level = item.matchTarget(Abi::fromString(target));
if (level == DebuggerItem::MatchesPerfectly)
level = DebuggerItem::MatchesWell;
QCOMPARE(expectedLevel, level);
}
QList<QObject *> DebuggerPlugin::createTestObjects() const
{
return {new DebuggerUnitTests};
}
#else // ^-- if WITH_TESTS else --v
QList<QObject *> DebuggerPlugin::createTestObjects() const
{
return {};
}
#endif // if WITH_TESTS
} // namespace Internal
} // namespace Debugger
#include "debuggerplugin.moc"
|