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
|
//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Target/Target.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointResolver.h"
#include "lldb/Breakpoint/BreakpointResolverAddress.h"
#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
#include "lldb/Breakpoint/BreakpointResolverName.h"
#include "lldb/Breakpoint/WatchpointLocation.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Event.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamAsynchronousIO.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Expression/ClangUserExpression.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/lldb-private-log.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
using namespace lldb;
using namespace lldb_private;
//----------------------------------------------------------------------
// Target constructor
//----------------------------------------------------------------------
Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Broadcaster ("lldb.target"),
ExecutionContextScope (),
TargetInstanceSettings (*GetSettingsController()),
m_debugger (debugger),
m_platform_sp (platform_sp),
m_mutex (Mutex::eMutexTypeRecursive),
m_arch (target_arch),
m_images (),
m_section_load_list (),
m_breakpoint_list (false),
m_internal_breakpoint_list (true),
m_watchpoint_location_list (),
m_process_sp (),
m_search_filter_sp (),
m_image_search_paths (ImageSearchPathsChanged, this),
m_scratch_ast_context_ap (NULL),
m_persistent_variables (),
m_source_manager(*this),
m_stop_hooks (),
m_stop_hook_next_id (0),
m_suppress_stop_hooks (false)
{
SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log)
log->Printf ("%p Target::Target()", this);
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
Target::~Target()
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log)
log->Printf ("%p Target::~Target()", this);
DeleteCurrentProcess ();
}
void
Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
{
// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
if (description_level != lldb::eDescriptionLevelBrief)
{
s->Indent();
s->PutCString("Target\n");
s->IndentMore();
m_images.Dump(s);
m_breakpoint_list.Dump(s);
m_internal_breakpoint_list.Dump(s);
s->IndentLess();
}
else
{
Module *exe_module = GetExecutableModulePointer();
if (exe_module)
s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
else
s->PutCString ("No executable module.");
}
}
void
Target::DeleteCurrentProcess ()
{
if (m_process_sp.get())
{
m_section_load_list.Clear();
if (m_process_sp->IsAlive())
m_process_sp->Destroy();
m_process_sp->Finalize();
// Do any cleanup of the target we need to do between process instances.
// NB It is better to do this before destroying the process in case the
// clean up needs some help from the process.
m_breakpoint_list.ClearAllBreakpointSites();
m_internal_breakpoint_list.ClearAllBreakpointSites();
// Disable watchpoint locations just on the debugger side.
DisableAllWatchpointLocations(false);
m_process_sp.reset();
}
}
const lldb::ProcessSP &
Target::CreateProcess (Listener &listener, const char *plugin_name)
{
DeleteCurrentProcess ();
m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
return m_process_sp;
}
const lldb::ProcessSP &
Target::GetProcessSP () const
{
return m_process_sp;
}
lldb::TargetSP
Target::GetSP()
{
// This object contains an instrusive ref count base class so we can
// easily make a shared pointer to this object
return TargetSP(this);
}
void
Target::Destroy()
{
Mutex::Locker locker (m_mutex);
DeleteCurrentProcess ();
m_platform_sp.reset();
m_arch.Clear();
m_images.Clear();
m_section_load_list.Clear();
const bool notify = false;
m_breakpoint_list.RemoveAll(notify);
m_internal_breakpoint_list.RemoveAll(notify);
m_last_created_breakpoint.reset();
m_last_created_watchpoint_location.reset();
m_search_filter_sp.reset();
m_image_search_paths.Clear(notify);
m_scratch_ast_context_ap.reset();
m_persistent_variables.Clear();
m_stop_hooks.clear();
m_stop_hook_next_id = 0;
m_suppress_stop_hooks = false;
}
BreakpointList &
Target::GetBreakpointList(bool internal)
{
if (internal)
return m_internal_breakpoint_list;
else
return m_breakpoint_list;
}
const BreakpointList &
Target::GetBreakpointList(bool internal) const
{
if (internal)
return m_internal_breakpoint_list;
else
return m_breakpoint_list;
}
BreakpointSP
Target::GetBreakpointByID (break_id_t break_id)
{
BreakpointSP bp_sp;
if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
else
bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
return bp_sp;
}
BreakpointSP
Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
const FileSpecList *source_file_spec_list,
RegularExpression &source_regex,
bool internal)
{
SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
BreakpointSP
Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
{
SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
BreakpointSP
Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
{
Address so_addr;
// Attempt to resolve our load address if possible, though it is ok if
// it doesn't resolve to section/offset.
// Try and resolve as a load address if possible
m_section_load_list.ResolveLoadAddress(addr, so_addr);
if (!so_addr.IsValid())
{
// The address didn't resolve, so just set this as an absolute address
so_addr.SetOffset (addr);
}
BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
return bp_sp;
}
BreakpointSP
Target::CreateBreakpoint (Address &addr, bool internal)
{
TargetSP target_sp = this->GetSP();
SearchFilterSP filter_sp(new SearchFilter (target_sp));
BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
BreakpointSP
Target::CreateBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
const char *func_name,
uint32_t func_name_type_mask,
bool internal,
LazyBool skip_prologue)
{
BreakpointSP bp_sp;
if (func_name)
{
SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
func_name,
func_name_type_mask,
Breakpoint::Exact,
skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
}
return bp_sp;
}
SearchFilterSP
Target::GetSearchFilterForModule (const FileSpec *containingModule)
{
SearchFilterSP filter_sp;
lldb::TargetSP target_sp = this->GetSP();
if (containingModule != NULL)
{
// TODO: We should look into sharing module based search filters
// across many breakpoints like we do for the simple target based one
filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
}
else
{
if (m_search_filter_sp.get() == NULL)
m_search_filter_sp.reset (new SearchFilter (target_sp));
filter_sp = m_search_filter_sp;
}
return filter_sp;
}
SearchFilterSP
Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
{
SearchFilterSP filter_sp;
lldb::TargetSP target_sp = this->GetSP();
if (containingModules && containingModules->GetSize() != 0)
{
// TODO: We should look into sharing module based search filters
// across many breakpoints like we do for the simple target based one
filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules));
}
else
{
if (m_search_filter_sp.get() == NULL)
m_search_filter_sp.reset (new SearchFilter (target_sp));
filter_sp = m_search_filter_sp;
}
return filter_sp;
}
SearchFilterSP
Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles)
{
if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
return GetSearchFilterForModuleList(containingModules);
SearchFilterSP filter_sp;
lldb::TargetSP target_sp = this->GetSP();
if (containingModules == NULL)
{
// We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
// but that will take a little reworking.
filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, FileSpecList(), *containingSourceFiles));
}
else
{
filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, *containingModules, *containingSourceFiles));
}
return filter_sp;
}
BreakpointSP
Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
RegularExpression &func_regex,
bool internal,
LazyBool skip_prologue)
{
SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
func_regex,
skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
BreakpointSP
Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
{
BreakpointSP bp_sp;
if (filter_sp && resolver_sp)
{
bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
resolver_sp->SetBreakpoint (bp_sp.get());
if (internal)
m_internal_breakpoint_list.Add (bp_sp, false);
else
m_breakpoint_list.Add (bp_sp, true);
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
{
StreamString s;
bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
}
bp_sp->ResolveBreakpoint();
}
if (!internal && bp_sp)
{
m_last_created_breakpoint = bp_sp;
}
return bp_sp;
}
bool
Target::ProcessIsValid()
{
return (m_process_sp && m_process_sp->IsAlive());
}
// See also WatchpointLocation::SetWatchpointType(uint32_t type) and
// the OptionGroupWatchpoint::WatchType enum type.
WatchpointLocationSP
Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
__FUNCTION__, addr, size, type);
WatchpointLocationSP wp_loc_sp;
if (!ProcessIsValid())
return wp_loc_sp;
if (addr == LLDB_INVALID_ADDRESS || size == 0)
return wp_loc_sp;
// Currently we only support one watchpoint location per address, with total
// number of watchpoint locations limited by the hardware which the inferior
// is running on.
WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
if (matched_sp)
{
size_t old_size = matched_sp->GetByteSize();
uint32_t old_type =
(matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
(matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
// Return the existing watchpoint location if both size and type match.
if (size == old_size && type == old_type) {
wp_loc_sp = matched_sp;
wp_loc_sp->SetEnabled(false);
} else {
// Nil the matched watchpoint location; we will be creating a new one.
m_process_sp->DisableWatchpoint(matched_sp.get());
m_watchpoint_location_list.Remove(matched_sp->GetID());
}
}
if (!wp_loc_sp) {
WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
if (!new_loc) {
printf("WatchpointLocation ctor failed, out of memory?\n");
return wp_loc_sp;
}
new_loc->SetWatchpointType(type);
new_loc->SetTarget(this);
wp_loc_sp.reset(new_loc);
m_watchpoint_location_list.Add(wp_loc_sp);
}
Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
if (log)
log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
__FUNCTION__,
rc.Success() ? "succeeded" : "failed",
wp_loc_sp->GetID());
if (rc.Fail())
wp_loc_sp.reset();
else
m_last_created_watchpoint_location = wp_loc_sp;
return wp_loc_sp;
}
void
Target::RemoveAllBreakpoints (bool internal_also)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
m_breakpoint_list.RemoveAll (true);
if (internal_also)
m_internal_breakpoint_list.RemoveAll (false);
m_last_created_breakpoint.reset();
}
void
Target::DisableAllBreakpoints (bool internal_also)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
m_breakpoint_list.SetEnabledAll (false);
if (internal_also)
m_internal_breakpoint_list.SetEnabledAll (false);
}
void
Target::EnableAllBreakpoints (bool internal_also)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
m_breakpoint_list.SetEnabledAll (true);
if (internal_also)
m_internal_breakpoint_list.SetEnabledAll (true);
}
bool
Target::RemoveBreakpointByID (break_id_t break_id)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
if (DisableBreakpointByID (break_id))
{
if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
m_internal_breakpoint_list.Remove(break_id, false);
else
{
if (m_last_created_breakpoint)
{
if (m_last_created_breakpoint->GetID() == break_id)
m_last_created_breakpoint.reset();
}
m_breakpoint_list.Remove(break_id, true);
}
return true;
}
return false;
}
bool
Target::DisableBreakpointByID (break_id_t break_id)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
BreakpointSP bp_sp;
if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
else
bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
if (bp_sp)
{
bp_sp->SetEnabled (false);
return true;
}
return false;
}
bool
Target::EnableBreakpointByID (break_id_t break_id)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
__FUNCTION__,
break_id,
LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
BreakpointSP bp_sp;
if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
else
bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
if (bp_sp)
{
bp_sp->SetEnabled (true);
return true;
}
return false;
}
// The flag 'end_to_end', default to true, signifies that the operation is
// performed end to end, for both the debugger and the debuggee.
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list
// for end to end operations.
bool
Target::RemoveAllWatchpointLocations (bool end_to_end)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s\n", __FUNCTION__);
if (!end_to_end) {
m_watchpoint_location_list.RemoveAll();
return true;
}
// Otherwise, it's an end to end operation.
if (!ProcessIsValid())
return false;
size_t num_watchpoints = m_watchpoint_location_list.GetSize();
for (size_t i = 0; i < num_watchpoints; ++i)
{
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
if (!wp_loc_sp)
return false;
Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
if (rc.Fail())
return false;
}
m_watchpoint_location_list.RemoveAll ();
return true; // Success!
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list
// for end to end operations.
bool
Target::DisableAllWatchpointLocations (bool end_to_end)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s\n", __FUNCTION__);
if (!end_to_end) {
m_watchpoint_location_list.SetEnabledAll(false);
return true;
}
// Otherwise, it's an end to end operation.
if (!ProcessIsValid())
return false;
size_t num_watchpoints = m_watchpoint_location_list.GetSize();
for (size_t i = 0; i < num_watchpoints; ++i)
{
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
if (!wp_loc_sp)
return false;
Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
if (rc.Fail())
return false;
}
return true; // Success!
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list
// for end to end operations.
bool
Target::EnableAllWatchpointLocations (bool end_to_end)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s\n", __FUNCTION__);
if (!end_to_end) {
m_watchpoint_location_list.SetEnabledAll(true);
return true;
}
// Otherwise, it's an end to end operation.
if (!ProcessIsValid())
return false;
size_t num_watchpoints = m_watchpoint_location_list.GetSize();
for (size_t i = 0; i < num_watchpoints; ++i)
{
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
if (!wp_loc_sp)
return false;
Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
if (rc.Fail())
return false;
}
return true; // Success!
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list
// during these operations.
bool
Target::IgnoreAllWatchpointLocations (uint32_t ignore_count)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s\n", __FUNCTION__);
if (!ProcessIsValid())
return false;
size_t num_watchpoints = m_watchpoint_location_list.GetSize();
for (size_t i = 0; i < num_watchpoints; ++i)
{
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
if (!wp_loc_sp)
return false;
wp_loc_sp->SetIgnoreCount(ignore_count);
}
return true; // Success!
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list.
bool
Target::DisableWatchpointLocationByID (lldb::watch_id_t watch_id)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
if (!ProcessIsValid())
return false;
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
if (wp_loc_sp)
{
Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
if (rc.Success())
return true;
// Else, fallthrough.
}
return false;
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list.
bool
Target::EnableWatchpointLocationByID (lldb::watch_id_t watch_id)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
if (!ProcessIsValid())
return false;
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
if (wp_loc_sp)
{
Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
if (rc.Success())
return true;
// Else, fallthrough.
}
return false;
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list.
bool
Target::RemoveWatchpointLocationByID (lldb::watch_id_t watch_id)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
if (DisableWatchpointLocationByID (watch_id))
{
m_watchpoint_location_list.Remove(watch_id);
return true;
}
return false;
}
// Assumption: Caller holds the list mutex lock for m_watchpoint_location_list.
bool
Target::IgnoreWatchpointLocationByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
if (log)
log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
if (!ProcessIsValid())
return false;
WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
if (wp_loc_sp)
{
wp_loc_sp->SetIgnoreCount(ignore_count);
return true;
}
return false;
}
ModuleSP
Target::GetExecutableModule ()
{
return m_images.GetModuleAtIndex(0);
}
Module*
Target::GetExecutableModulePointer ()
{
return m_images.GetModulePointerAtIndex(0);
}
void
Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
{
m_images.Clear();
m_scratch_ast_context_ap.reset();
if (executable_sp.get())
{
Timer scoped_timer (__PRETTY_FUNCTION__,
"Target::SetExecutableModule (executable = '%s/%s')",
executable_sp->GetFileSpec().GetDirectory().AsCString(),
executable_sp->GetFileSpec().GetFilename().AsCString());
m_images.Append(executable_sp); // The first image is our exectuable file
// If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
if (!m_arch.IsValid())
m_arch = executable_sp->GetArchitecture();
FileSpecList dependent_files;
ObjectFile *executable_objfile = executable_sp->GetObjectFile();
if (executable_objfile && get_dependent_files)
{
executable_objfile->GetDependentModules(dependent_files);
for (uint32_t i=0; i<dependent_files.GetSize(); i++)
{
FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
FileSpec platform_dependent_file_spec;
if (m_platform_sp)
m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
else
platform_dependent_file_spec = dependent_file_spec;
ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
m_arch));
if (image_module_sp.get())
{
ObjectFile *objfile = image_module_sp->GetObjectFile();
if (objfile)
objfile->GetDependentModules(dependent_files);
}
}
}
}
UpdateInstanceName();
}
bool
Target::SetArchitecture (const ArchSpec &arch_spec)
{
if (m_arch == arch_spec)
{
// If we're setting the architecture to our current architecture, we
// don't need to do anything.
return true;
}
else if (!m_arch.IsValid())
{
// If we haven't got a valid arch spec, then we just need to set it.
m_arch = arch_spec;
return true;
}
else
{
// If we have an executable file, try to reset the executable to the desired architecture
m_arch = arch_spec;
ModuleSP executable_sp = GetExecutableModule ();
m_images.Clear();
m_scratch_ast_context_ap.reset();
// Need to do something about unsetting breakpoints.
if (executable_sp)
{
FileSpec exec_file_spec = executable_sp->GetFileSpec();
Error error = ModuleList::GetSharedModule(exec_file_spec,
arch_spec,
NULL,
NULL,
0,
executable_sp,
NULL,
NULL);
if (!error.Fail() && executable_sp)
{
SetExecutableModule (executable_sp, true);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
void
Target::ModuleAdded (ModuleSP &module_sp)
{
// A module is being added to this target for the first time
ModuleList module_list;
module_list.Append(module_sp);
ModulesDidLoad (module_list);
}
void
Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
{
// A module is replacing an already added module
ModuleList module_list;
module_list.Append (old_module_sp);
ModulesDidUnload (module_list);
module_list.Clear ();
module_list.Append (new_module_sp);
ModulesDidLoad (module_list);
}
void
Target::ModulesDidLoad (ModuleList &module_list)
{
m_breakpoint_list.UpdateBreakpoints (module_list, true);
// TODO: make event data that packages up the module_list
BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
}
void
Target::ModulesDidUnload (ModuleList &module_list)
{
m_breakpoint_list.UpdateBreakpoints (module_list, false);
// Remove the images from the target image list
m_images.Remove(module_list);
// TODO: make event data that packages up the module_list
BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
}
size_t
Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
{
const Section *section = addr.GetSection();
if (section && section->GetModule())
{
ObjectFile *objfile = section->GetModule()->GetObjectFile();
if (objfile)
{
size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
addr.GetOffset(),
dst,
dst_len);
if (bytes_read > 0)
return bytes_read;
else
error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
}
else
{
error.SetErrorString("address isn't from a object file");
}
}
else
{
error.SetErrorString("address doesn't contain a section that points to a section in a object file");
}
return 0;
}
size_t
Target::ReadMemory (const Address& addr,
bool prefer_file_cache,
void *dst,
size_t dst_len,
Error &error,
lldb::addr_t *load_addr_ptr)
{
error.Clear();
// if we end up reading this from process memory, we will fill this
// with the actual load address
if (load_addr_ptr)
*load_addr_ptr = LLDB_INVALID_ADDRESS;
size_t bytes_read = 0;
addr_t load_addr = LLDB_INVALID_ADDRESS;
addr_t file_addr = LLDB_INVALID_ADDRESS;
Address resolved_addr;
if (!addr.IsSectionOffset())
{
if (m_section_load_list.IsEmpty())
{
// No sections are loaded, so we must assume we are not running
// yet and anything we are given is a file address.
file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
m_images.ResolveFileAddress (file_addr, resolved_addr);
}
else
{
// We have at least one section loaded. This can be becuase
// we have manually loaded some sections with "target modules load ..."
// or because we have have a live process that has sections loaded
// through the dynamic loader
load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
}
}
if (!resolved_addr.IsValid())
resolved_addr = addr;
if (prefer_file_cache)
{
bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
if (bytes_read > 0)
return bytes_read;
}
if (ProcessIsValid())
{
if (load_addr == LLDB_INVALID_ADDRESS)
load_addr = resolved_addr.GetLoadAddress (this);
if (load_addr == LLDB_INVALID_ADDRESS)
{
if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
resolved_addr.GetFileAddress(),
resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString());
else
error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
}
else
{
bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
if (bytes_read != dst_len)
{
if (error.Success())
{
if (bytes_read == 0)
error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
else
error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
}
}
if (bytes_read)
{
if (load_addr_ptr)
*load_addr_ptr = load_addr;
return bytes_read;
}
// If the address is not section offset we have an address that
// doesn't resolve to any address in any currently loaded shared
// libaries and we failed to read memory so there isn't anything
// more we can do. If it is section offset, we might be able to
// read cached memory from the object file.
if (!resolved_addr.IsSectionOffset())
return 0;
}
}
if (!prefer_file_cache && resolved_addr.IsSectionOffset())
{
// If we didn't already try and read from the object file cache, then
// try it after failing to read from the process.
return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
}
return 0;
}
size_t
Target::ReadScalarIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
uint32_t byte_size,
bool is_signed,
Scalar &scalar,
Error &error)
{
uint64_t uval;
if (byte_size <= sizeof(uval))
{
size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
if (bytes_read == byte_size)
{
DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
uint32_t offset = 0;
if (byte_size <= 4)
scalar = data.GetMaxU32 (&offset, byte_size);
else
scalar = data.GetMaxU64 (&offset, byte_size);
if (is_signed)
scalar.SignExtend(byte_size * 8);
return bytes_read;
}
}
else
{
error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
}
return 0;
}
uint64_t
Target::ReadUnsignedIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
size_t integer_byte_size,
uint64_t fail_value,
Error &error)
{
Scalar scalar;
if (ReadScalarIntegerFromMemory (addr,
prefer_file_cache,
integer_byte_size,
false,
scalar,
error))
return scalar.ULongLong(fail_value);
return fail_value;
}
bool
Target::ReadPointerFromMemory (const Address& addr,
bool prefer_file_cache,
Error &error,
Address &pointer_addr)
{
Scalar scalar;
if (ReadScalarIntegerFromMemory (addr,
prefer_file_cache,
m_arch.GetAddressByteSize(),
false,
scalar,
error))
{
addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
{
if (m_section_load_list.IsEmpty())
{
// No sections are loaded, so we must assume we are not running
// yet and anything we are given is a file address.
m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
}
else
{
// We have at least one section loaded. This can be becuase
// we have manually loaded some sections with "target modules load ..."
// or because we have have a live process that has sections loaded
// through the dynamic loader
m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
}
// We weren't able to resolve the pointer value, so just return
// an address with no section
if (!pointer_addr.IsValid())
pointer_addr.SetOffset (pointer_vm_addr);
return true;
}
}
return false;
}
ModuleSP
Target::GetSharedModule
(
const FileSpec& file_spec,
const ArchSpec& arch,
const lldb_private::UUID *uuid_ptr,
const ConstString *object_name,
off_t object_offset,
Error *error_ptr
)
{
// Don't pass in the UUID so we can tell if we have a stale value in our list
ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
bool did_create_module = false;
ModuleSP module_sp;
Error error;
// If there are image search path entries, try to use them first to acquire a suitable image.
if (m_image_search_paths.GetSize())
{
FileSpec transformed_spec;
if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
{
transformed_spec.GetFilename() = file_spec.GetFilename();
error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
}
}
// The platform is responsible for finding and caching an appropriate
// module in the shared module cache.
if (m_platform_sp)
{
FileSpec platform_file_spec;
error = m_platform_sp->GetSharedModule (file_spec,
arch,
uuid_ptr,
object_name,
object_offset,
module_sp,
&old_module_sp,
&did_create_module);
}
else
{
error.SetErrorString("no platform is currently set");
}
// If a module hasn't been found yet, use the unmodified path.
if (module_sp)
{
m_images.Append (module_sp);
if (did_create_module)
{
if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
ModuleUpdated(old_module_sp, module_sp);
else
ModuleAdded(module_sp);
}
}
if (error_ptr)
*error_ptr = error;
return module_sp;
}
Target *
Target::CalculateTarget ()
{
return this;
}
Process *
Target::CalculateProcess ()
{
return NULL;
}
Thread *
Target::CalculateThread ()
{
return NULL;
}
StackFrame *
Target::CalculateStackFrame ()
{
return NULL;
}
void
Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
{
exe_ctx.Clear();
exe_ctx.SetTargetPtr(this);
}
PathMappingList &
Target::GetImageSearchPathList ()
{
return m_image_search_paths;
}
void
Target::ImageSearchPathsChanged
(
const PathMappingList &path_list,
void *baton
)
{
Target *target = (Target *)baton;
ModuleSP exe_module_sp (target->GetExecutableModule());
if (exe_module_sp)
{
target->m_images.Clear();
target->SetExecutableModule (exe_module_sp, true);
}
}
ClangASTContext *
Target::GetScratchClangASTContext()
{
// Now see if we know the target triple, and if so, create our scratch AST context:
if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
return m_scratch_ast_context_ap.get();
}
void
Target::SettingsInitialize ()
{
UserSettingsControllerSP &usc = GetSettingsController();
usc.reset (new SettingsController);
UserSettingsController::InitializeSettingsController (usc,
SettingsController::global_settings_table,
SettingsController::instance_settings_table);
// Now call SettingsInitialize() on each 'child' setting of Target
Process::SettingsInitialize ();
}
void
Target::SettingsTerminate ()
{
// Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
Process::SettingsTerminate ();
// Now terminate Target Settings.
UserSettingsControllerSP &usc = GetSettingsController();
UserSettingsController::FinalizeSettingsController (usc);
usc.reset();
}
UserSettingsControllerSP &
Target::GetSettingsController ()
{
static UserSettingsControllerSP g_settings_controller;
return g_settings_controller;
}
ArchSpec
Target::GetDefaultArchitecture ()
{
lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
if (settings_controller_sp)
return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
return ArchSpec();
}
void
Target::SetDefaultArchitecture (const ArchSpec& arch)
{
lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
if (settings_controller_sp)
static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
}
Target *
Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
{
// The target can either exist in the "process" of ExecutionContext, or in
// the "target_sp" member of SymbolContext. This accessor helper function
// will get the target from one of these locations.
Target *target = NULL;
if (sc_ptr != NULL)
target = sc_ptr->target_sp.get();
if (target == NULL && exe_ctx_ptr)
target = exe_ctx_ptr->GetTargetPtr();
return target;
}
void
Target::UpdateInstanceName ()
{
StreamString sstr;
Module *exe_module = GetExecutableModulePointer();
if (exe_module)
{
sstr.Printf ("%s_%s",
exe_module->GetFileSpec().GetFilename().AsCString(),
exe_module->GetArchitecture().GetArchitectureName());
GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
}
}
const char *
Target::GetExpressionPrefixContentsAsCString ()
{
if (m_expr_prefix_contents_sp)
return (const char *)m_expr_prefix_contents_sp->GetBytes();
return NULL;
}
ExecutionResults
Target::EvaluateExpression
(
const char *expr_cstr,
StackFrame *frame,
lldb_private::ExecutionPolicy execution_policy,
bool unwind_on_error,
bool keep_in_memory,
lldb::DynamicValueType use_dynamic,
lldb::ValueObjectSP &result_valobj_sp
)
{
ExecutionResults execution_results = eExecutionSetupError;
result_valobj_sp.reset();
// We shouldn't run stop hooks in expressions.
// Be sure to reset this if you return anywhere within this function.
bool old_suppress_value = m_suppress_stop_hooks;
m_suppress_stop_hooks = true;
ExecutionContext exe_ctx;
if (frame)
{
frame->CalculateExecutionContext(exe_ctx);
Error error;
const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
StackFrame::eExpressionPathOptionsNoSyntheticChildren;
lldb::VariableSP var_sp;
result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
use_dynamic,
expr_path_options,
var_sp,
error);
}
else if (m_process_sp)
{
m_process_sp->CalculateExecutionContext(exe_ctx);
}
else
{
CalculateExecutionContext(exe_ctx);
}
if (result_valobj_sp)
{
execution_results = eExecutionCompleted;
// We got a result from the frame variable expression path above...
ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
lldb::ValueObjectSP const_valobj_sp;
// Check in case our value is already a constant value
if (result_valobj_sp->GetIsConstant())
{
const_valobj_sp = result_valobj_sp;
const_valobj_sp->SetName (persistent_variable_name);
}
else
{
if (use_dynamic != lldb::eNoDynamicValues)
{
ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
if (dynamic_sp)
result_valobj_sp = dynamic_sp;
}
const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
}
lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
result_valobj_sp = const_valobj_sp;
ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
assert (clang_expr_variable_sp.get());
// Set flags and live data as appropriate
const Value &result_value = live_valobj_sp->GetValue();
switch (result_value.GetValueType())
{
case Value::eValueTypeHostAddress:
case Value::eValueTypeFileAddress:
// we don't do anything with these for now
break;
case Value::eValueTypeScalar:
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
break;
case Value::eValueTypeLoadAddress:
clang_expr_variable_sp->m_live_sp = live_valobj_sp;
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
break;
}
}
else
{
// Make sure we aren't just trying to see the value of a persistent
// variable (something like "$0")
lldb::ClangExpressionVariableSP persistent_var_sp;
// Only check for persistent variables the expression starts with a '$'
if (expr_cstr[0] == '$')
persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
if (persistent_var_sp)
{
result_valobj_sp = persistent_var_sp->GetValueObject ();
execution_results = eExecutionCompleted;
}
else
{
const char *prefix = GetExpressionPrefixContentsAsCString();
execution_results = ClangUserExpression::Evaluate (exe_ctx,
execution_policy,
unwind_on_error,
expr_cstr,
prefix,
result_valobj_sp);
}
}
m_suppress_stop_hooks = old_suppress_value;
return execution_results;
}
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
{
addr_t code_addr = load_addr;
switch (m_arch.GetMachine())
{
case llvm::Triple::arm:
case llvm::Triple::thumb:
switch (addr_class)
{
case eAddressClassData:
case eAddressClassDebug:
return LLDB_INVALID_ADDRESS;
case eAddressClassUnknown:
case eAddressClassInvalid:
case eAddressClassCode:
case eAddressClassCodeAlternateISA:
case eAddressClassRuntime:
// Check if bit zero it no set?
if ((code_addr & 1ull) == 0)
{
// Bit zero isn't set, check if the address is a multiple of 2?
if (code_addr & 2ull)
{
// The address is a multiple of 2 so it must be thumb, set bit zero
code_addr |= 1ull;
}
else if (addr_class == eAddressClassCodeAlternateISA)
{
// We checked the address and the address claims to be the alternate ISA
// which means thumb, so set bit zero.
code_addr |= 1ull;
}
}
break;
}
break;
default:
break;
}
return code_addr;
}
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
{
addr_t opcode_addr = load_addr;
switch (m_arch.GetMachine())
{
case llvm::Triple::arm:
case llvm::Triple::thumb:
switch (addr_class)
{
case eAddressClassData:
case eAddressClassDebug:
return LLDB_INVALID_ADDRESS;
case eAddressClassInvalid:
case eAddressClassUnknown:
case eAddressClassCode:
case eAddressClassCodeAlternateISA:
case eAddressClassRuntime:
opcode_addr &= ~(1ull);
break;
}
break;
default:
break;
}
return opcode_addr;
}
lldb::user_id_t
Target::AddStopHook (Target::StopHookSP &new_hook_sp)
{
lldb::user_id_t new_uid = ++m_stop_hook_next_id;
new_hook_sp.reset (new StopHook(GetSP(), new_uid));
m_stop_hooks[new_uid] = new_hook_sp;
return new_uid;
}
bool
Target::RemoveStopHookByID (lldb::user_id_t user_id)
{
size_t num_removed;
num_removed = m_stop_hooks.erase (user_id);
if (num_removed == 0)
return false;
else
return true;
}
void
Target::RemoveAllStopHooks ()
{
m_stop_hooks.clear();
}
Target::StopHookSP
Target::GetStopHookByID (lldb::user_id_t user_id)
{
StopHookSP found_hook;
StopHookCollection::iterator specified_hook_iter;
specified_hook_iter = m_stop_hooks.find (user_id);
if (specified_hook_iter != m_stop_hooks.end())
found_hook = (*specified_hook_iter).second;
return found_hook;
}
bool
Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
{
StopHookCollection::iterator specified_hook_iter;
specified_hook_iter = m_stop_hooks.find (user_id);
if (specified_hook_iter == m_stop_hooks.end())
return false;
(*specified_hook_iter).second->SetIsActive (active_state);
return true;
}
void
Target::SetAllStopHooksActiveState (bool active_state)
{
StopHookCollection::iterator pos, end = m_stop_hooks.end();
for (pos = m_stop_hooks.begin(); pos != end; pos++)
{
(*pos).second->SetIsActive (active_state);
}
}
void
Target::RunStopHooks ()
{
if (m_suppress_stop_hooks)
return;
if (!m_process_sp)
return;
if (m_stop_hooks.empty())
return;
StopHookCollection::iterator pos, end = m_stop_hooks.end();
// If there aren't any active stop hooks, don't bother either:
bool any_active_hooks = false;
for (pos = m_stop_hooks.begin(); pos != end; pos++)
{
if ((*pos).second->IsActive())
{
any_active_hooks = true;
break;
}
}
if (!any_active_hooks)
return;
CommandReturnObject result;
std::vector<ExecutionContext> exc_ctx_with_reasons;
std::vector<SymbolContext> sym_ctx_with_reasons;
ThreadList &cur_threadlist = m_process_sp->GetThreadList();
size_t num_threads = cur_threadlist.GetSize();
for (size_t i = 0; i < num_threads; i++)
{
lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
if (cur_thread_sp->ThreadStoppedForAReason())
{
lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
}
}
// If no threads stopped for a reason, don't run the stop-hooks.
size_t num_exe_ctx = exc_ctx_with_reasons.size();
if (num_exe_ctx == 0)
return;
result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
bool keep_going = true;
bool hooks_ran = false;
bool print_hook_header;
bool print_thread_header;
if (num_exe_ctx == 1)
print_thread_header = false;
else
print_thread_header = true;
if (m_stop_hooks.size() == 1)
print_hook_header = false;
else
print_hook_header = true;
for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
{
// result.Clear();
StopHookSP cur_hook_sp = (*pos).second;
if (!cur_hook_sp->IsActive())
continue;
bool any_thread_matched = false;
for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
{
if ((cur_hook_sp->GetSpecifier () == NULL
|| cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
&& (cur_hook_sp->GetThreadSpecifier() == NULL
|| cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr())))
{
if (!hooks_ran)
{
hooks_ran = true;
}
if (print_hook_header && !any_thread_matched)
{
result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
any_thread_matched = true;
}
if (print_thread_header)
result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
bool stop_on_continue = true;
bool stop_on_error = true;
bool echo_commands = false;
bool print_results = true;
GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
&exc_ctx_with_reasons[i],
stop_on_continue,
stop_on_error,
echo_commands,
print_results,
result);
// If the command started the target going again, we should bag out of
// running the stop hooks.
if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
(result.GetStatus() == eReturnStatusSuccessContinuingResult))
{
result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
keep_going = false;
}
}
}
}
result.GetImmediateOutputStream()->Flush();
result.GetImmediateErrorStream()->Flush();
}
bool
Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
{
bool changed = false;
if (module)
{
ObjectFile *object_file = module->GetObjectFile();
if (object_file)
{
SectionList *section_list = object_file->GetSectionList ();
if (section_list)
{
// All sections listed in the dyld image info structure will all
// either be fixed up already, or they will all be off by a single
// slide amount that is determined by finding the first segment
// that is at file offset zero which also has bytes (a file size
// that is greater than zero) in the object file.
// Determine the slide amount (if any)
const size_t num_sections = section_list->GetSize();
size_t sect_idx = 0;
for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
{
// Iterate through the object file sections to find the
// first section that starts of file offset zero and that
// has bytes in the file...
Section *section = section_list->GetSectionAtIndex (sect_idx).get();
if (section)
{
if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
changed = true;
}
}
}
}
}
return changed;
}
//--------------------------------------------------------------
// class Target::StopHook
//--------------------------------------------------------------
Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
UserID (uid),
m_target_sp (target_sp),
m_commands (),
m_specifier_sp (),
m_thread_spec_ap(NULL),
m_active (true)
{
}
Target::StopHook::StopHook (const StopHook &rhs) :
UserID (rhs.GetID()),
m_target_sp (rhs.m_target_sp),
m_commands (rhs.m_commands),
m_specifier_sp (rhs.m_specifier_sp),
m_thread_spec_ap (NULL),
m_active (rhs.m_active)
{
if (rhs.m_thread_spec_ap.get() != NULL)
m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
}
Target::StopHook::~StopHook ()
{
}
void
Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
{
m_thread_spec_ap.reset (specifier);
}
void
Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
{
int indent_level = s->GetIndentLevel();
s->SetIndentLevel(indent_level + 2);
s->Printf ("Hook: %d\n", GetID());
if (m_active)
s->Indent ("State: enabled\n");
else
s->Indent ("State: disabled\n");
if (m_specifier_sp)
{
s->Indent();
s->PutCString ("Specifier:\n");
s->SetIndentLevel (indent_level + 4);
m_specifier_sp->GetDescription (s, level);
s->SetIndentLevel (indent_level + 2);
}
if (m_thread_spec_ap.get() != NULL)
{
StreamString tmp;
s->Indent("Thread:\n");
m_thread_spec_ap->GetDescription (&tmp, level);
s->SetIndentLevel (indent_level + 4);
s->Indent (tmp.GetData());
s->PutCString ("\n");
s->SetIndentLevel (indent_level + 2);
}
s->Indent ("Commands: \n");
s->SetIndentLevel (indent_level + 4);
uint32_t num_commands = m_commands.GetSize();
for (uint32_t i = 0; i < num_commands; i++)
{
s->Indent(m_commands.GetStringAtIndex(i));
s->PutCString ("\n");
}
s->SetIndentLevel (indent_level);
}
//--------------------------------------------------------------
// class Target::SettingsController
//--------------------------------------------------------------
Target::SettingsController::SettingsController () :
UserSettingsController ("target", Debugger::GetSettingsController()),
m_default_architecture ()
{
m_default_settings.reset (new TargetInstanceSettings (*this, false,
InstanceSettings::GetDefaultName().AsCString()));
}
Target::SettingsController::~SettingsController ()
{
}
lldb::InstanceSettingsSP
Target::SettingsController::CreateInstanceSettings (const char *instance_name)
{
TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
false,
instance_name);
lldb::InstanceSettingsSP new_settings_sp (new_settings);
return new_settings_sp;
}
#define TSC_DEFAULT_ARCH "default-arch"
#define TSC_EXPR_PREFIX "expr-prefix"
#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
#define TSC_SKIP_PROLOGUE "skip-prologue"
#define TSC_SOURCE_MAP "source-map"
#define TSC_MAX_CHILDREN "max-children-count"
#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
static const ConstString &
GetSettingNameForDefaultArch ()
{
static ConstString g_const_string (TSC_DEFAULT_ARCH);
return g_const_string;
}
static const ConstString &
GetSettingNameForExpressionPrefix ()
{
static ConstString g_const_string (TSC_EXPR_PREFIX);
return g_const_string;
}
static const ConstString &
GetSettingNameForPreferDynamicValue ()
{
static ConstString g_const_string (TSC_PREFER_DYNAMIC);
return g_const_string;
}
static const ConstString &
GetSettingNameForSourcePathMap ()
{
static ConstString g_const_string (TSC_SOURCE_MAP);
return g_const_string;
}
static const ConstString &
GetSettingNameForSkipPrologue ()
{
static ConstString g_const_string (TSC_SKIP_PROLOGUE);
return g_const_string;
}
static const ConstString &
GetSettingNameForMaxChildren ()
{
static ConstString g_const_string (TSC_MAX_CHILDREN);
return g_const_string;
}
static const ConstString &
GetSettingNameForMaxStringSummaryLength ()
{
static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
return g_const_string;
}
bool
Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
const char *index_value,
const char *value,
const SettingEntry &entry,
const VarSetOperationType op,
Error&err)
{
if (var_name == GetSettingNameForDefaultArch())
{
m_default_architecture.SetTriple (value, NULL);
if (!m_default_architecture.IsValid())
err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
}
return true;
}
bool
Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
StringList &value,
Error &err)
{
if (var_name == GetSettingNameForDefaultArch())
{
// If the arch is invalid (the default), don't show a string for it
if (m_default_architecture.IsValid())
value.AppendString (m_default_architecture.GetArchitectureName());
return true;
}
else
err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
return false;
}
//--------------------------------------------------------------
// class TargetInstanceSettings
//--------------------------------------------------------------
TargetInstanceSettings::TargetInstanceSettings
(
UserSettingsController &owner,
bool live_instance,
const char *name
) :
InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
m_expr_prefix_file (),
m_expr_prefix_contents_sp (),
m_prefer_dynamic_value (2),
m_skip_prologue (true, true),
m_source_map (NULL, NULL),
m_max_children_display(256),
m_max_strlen_length(1024)
{
// CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
// until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
// For this reason it has to be called here, rather than in the initializer or in the parent constructor.
// This is true for CreateInstanceName() too.
if (GetInstanceName () == InstanceSettings::InvalidName())
{
ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
m_owner.RegisterInstanceSettings (this);
}
if (live_instance)
{
const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
CopyInstanceSettings (pending_settings,false);
}
}
TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
m_expr_prefix_file (rhs.m_expr_prefix_file),
m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
m_skip_prologue (rhs.m_skip_prologue),
m_source_map (rhs.m_source_map),
m_max_children_display(rhs.m_max_children_display),
m_max_strlen_length(rhs.m_max_strlen_length)
{
if (m_instance_name != InstanceSettings::GetDefaultName())
{
const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
CopyInstanceSettings (pending_settings,false);
}
}
TargetInstanceSettings::~TargetInstanceSettings ()
{
}
TargetInstanceSettings&
TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
{
if (this != &rhs)
{
}
return *this;
}
void
TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
const char *index_value,
const char *value,
const ConstString &instance_name,
const SettingEntry &entry,
VarSetOperationType op,
Error &err,
bool pending)
{
if (var_name == GetSettingNameForExpressionPrefix ())
{
err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
if (err.Success())
{
switch (op)
{
default:
break;
case eVarSetOperationAssign:
case eVarSetOperationAppend:
{
if (!m_expr_prefix_file.GetCurrentValue().Exists())
{
err.SetErrorToGenericError ();
err.SetErrorStringWithFormat ("%s does not exist.\n", value);
return;
}
m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
{
err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
m_expr_prefix_contents_sp.reset();
}
}
break;
case eVarSetOperationClear:
m_expr_prefix_contents_sp.reset();
}
}
}
else if (var_name == GetSettingNameForPreferDynamicValue())
{
int new_value;
UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
if (err.Success())
m_prefer_dynamic_value = new_value;
}
else if (var_name == GetSettingNameForSkipPrologue())
{
err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
}
else if (var_name == GetSettingNameForMaxChildren())
{
bool ok;
uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
if (ok)
m_max_children_display = new_value;
}
else if (var_name == GetSettingNameForMaxStringSummaryLength())
{
bool ok;
uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
if (ok)
m_max_strlen_length = new_value;
}
else if (var_name == GetSettingNameForSourcePathMap ())
{
switch (op)
{
case eVarSetOperationReplace:
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
case eVarSetOperationRemove:
default:
break;
case eVarSetOperationAssign:
m_source_map.Clear(true);
// Fall through to append....
case eVarSetOperationAppend:
{
Args args(value);
const uint32_t argc = args.GetArgumentCount();
if (argc & 1 || argc == 0)
{
err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
}
else
{
char resolved_new_path[PATH_MAX];
FileSpec file_spec;
const char *old_path;
for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
{
const char *new_path = args.GetArgumentAtIndex(idx+1);
assert (new_path); // We have an even number of paths, this shouldn't happen!
file_spec.SetFile(new_path, true);
if (file_spec.Exists())
{
if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
{
err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
return;
}
}
else
{
err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
return;
}
m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
}
}
}
break;
case eVarSetOperationClear:
m_source_map.Clear(true);
break;
}
}
}
void
TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
{
TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
if (!new_settings_ptr)
return;
m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
m_skip_prologue = new_settings_ptr->m_skip_prologue;
m_max_children_display = new_settings_ptr->m_max_children_display;
m_max_strlen_length = new_settings_ptr->m_max_strlen_length;
}
bool
TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString &var_name,
StringList &value,
Error *err)
{
if (var_name == GetSettingNameForExpressionPrefix ())
{
char path[PATH_MAX];
const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
if (path_len > 0)
value.AppendString (path, path_len);
}
else if (var_name == GetSettingNameForPreferDynamicValue())
{
value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
}
else if (var_name == GetSettingNameForSkipPrologue())
{
if (m_skip_prologue)
value.AppendString ("true");
else
value.AppendString ("false");
}
else if (var_name == GetSettingNameForSourcePathMap ())
{
}
else if (var_name == GetSettingNameForMaxChildren())
{
StreamString count_str;
count_str.Printf ("%d", m_max_children_display);
value.AppendString (count_str.GetData());
}
else if (var_name == GetSettingNameForMaxStringSummaryLength())
{
StreamString count_str;
count_str.Printf ("%d", m_max_strlen_length);
value.AppendString (count_str.GetData());
}
else
{
if (err)
err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
return false;
}
return true;
}
const ConstString
TargetInstanceSettings::CreateInstanceName ()
{
StreamString sstr;
static int instance_count = 1;
sstr.Printf ("target_%d", instance_count);
++instance_count;
const ConstString ret_val (sstr.GetData());
return ret_val;
}
//--------------------------------------------------
// Target::SettingsController Variable Tables
//--------------------------------------------------
OptionEnumValueElement
TargetInstanceSettings::g_dynamic_value_types[] =
{
{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
{ 0, NULL, NULL }
};
SettingEntry
Target::SettingsController::global_settings_table[] =
{
// var-name var-type default enum init'd hidden help-text
// ================= ================== =========== ==== ====== ====== =========================================================================
{ TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
{ NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
};
SettingEntry
Target::SettingsController::instance_settings_table[] =
{
// var-name var-type default enum init'd hidden help-text
// ================= ================== =============== ======================= ====== ====== =========================================================================
{ TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
{ TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
{ TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
{ TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
{ TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
{ TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
{ NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
};
|