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
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
|
//===-- ValueObject.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/lldb-python.h"
#include "lldb/Core/ValueObject.h"
// C Includes
#include <stdlib.h>
// C++ Includes
// Other libraries and framework includes
#include "llvm/Support/raw_ostream.h"
#include "clang/AST/Type.h"
// Project includes
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/ValueObjectCast.h"
#include "lldb/Core/ValueObjectChild.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/Core/ValueObjectDynamicValue.h"
#include "lldb/Core/ValueObjectList.h"
#include "lldb/Core/ValueObjectMemory.h"
#include "lldb/Core/ValueObjectSyntheticFilter.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Host/Endian.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include "lldb/Symbol/ClangASTType.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/Target/ObjCLanguageRuntime.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_utility;
static user_id_t g_value_obj_uid = 0;
//----------------------------------------------------------------------
// ValueObject constructor
//----------------------------------------------------------------------
ValueObject::ValueObject (ValueObject &parent) :
UserID (++g_value_obj_uid), // Unique identifier for every value object
m_parent (&parent),
m_root (NULL),
m_update_point (parent.GetUpdatePoint ()),
m_name (),
m_data (),
m_value (),
m_error (),
m_value_str (),
m_old_value_str (),
m_location_str (),
m_summary_str (),
m_object_desc_str (),
m_manager(parent.GetManager()),
m_children (),
m_synthetic_children (),
m_dynamic_value (NULL),
m_synthetic_value(NULL),
m_deref_valobj(NULL),
m_format (eFormatDefault),
m_last_format (eFormatDefault),
m_last_format_mgr_revision(0),
m_type_summary_sp(),
m_type_format_sp(),
m_synthetic_children_sp(),
m_user_id_of_forced_summary(),
m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
m_value_is_valid (false),
m_value_did_change (false),
m_children_count_valid (false),
m_old_value_valid (false),
m_is_deref_of_parent (false),
m_is_array_item_for_pointer(false),
m_is_bitfield_for_scalar(false),
m_is_child_at_offset(false),
m_is_getting_summary(false),
m_did_calculate_complete_objc_class_type(false)
{
m_manager->ManageObject(this);
}
//----------------------------------------------------------------------
// ValueObject constructor
//----------------------------------------------------------------------
ValueObject::ValueObject (ExecutionContextScope *exe_scope,
AddressType child_ptr_or_ref_addr_type) :
UserID (++g_value_obj_uid), // Unique identifier for every value object
m_parent (NULL),
m_root (NULL),
m_update_point (exe_scope),
m_name (),
m_data (),
m_value (),
m_error (),
m_value_str (),
m_old_value_str (),
m_location_str (),
m_summary_str (),
m_object_desc_str (),
m_manager(),
m_children (),
m_synthetic_children (),
m_dynamic_value (NULL),
m_synthetic_value(NULL),
m_deref_valobj(NULL),
m_format (eFormatDefault),
m_last_format (eFormatDefault),
m_last_format_mgr_revision(0),
m_type_summary_sp(),
m_type_format_sp(),
m_synthetic_children_sp(),
m_user_id_of_forced_summary(),
m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
m_value_is_valid (false),
m_value_did_change (false),
m_children_count_valid (false),
m_old_value_valid (false),
m_is_deref_of_parent (false),
m_is_array_item_for_pointer(false),
m_is_bitfield_for_scalar(false),
m_is_child_at_offset(false),
m_is_getting_summary(false),
m_did_calculate_complete_objc_class_type(false)
{
m_manager = new ValueObjectManager();
m_manager->ManageObject (this);
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
ValueObject::~ValueObject ()
{
}
bool
ValueObject::UpdateValueIfNeeded (bool update_format)
{
bool did_change_formats = false;
if (update_format)
did_change_formats = UpdateFormatsIfNeeded();
// If this is a constant value, then our success is predicated on whether
// we have an error or not
if (GetIsConstant())
{
// if you were asked to update your formatters, but did not get a chance to do it
// clear your own values (this serves the purpose of faking a stop-id for frozen
// objects (which are regarded as constant, but could have changes behind their backs
// because of the frozen-pointer depth limit)
// TODO: decouple summary from value and then remove this code and only force-clear the summary
if (update_format && !did_change_formats)
ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
return m_error.Success();
}
bool first_update = m_update_point.IsFirstEvaluation();
if (m_update_point.NeedsUpdating())
{
m_update_point.SetUpdated();
// Save the old value using swap to avoid a string copy which
// also will clear our m_value_str
if (m_value_str.empty())
{
m_old_value_valid = false;
}
else
{
m_old_value_valid = true;
m_old_value_str.swap (m_value_str);
ClearUserVisibleData(eClearUserVisibleDataItemsValue);
}
ClearUserVisibleData();
if (IsInScope())
{
const bool value_was_valid = GetValueIsValid();
SetValueDidChange (false);
m_error.Clear();
// Call the pure virtual function to update the value
bool success = UpdateValue ();
SetValueIsValid (success);
if (first_update)
SetValueDidChange (false);
else if (!m_value_did_change && success == false)
{
// The value wasn't gotten successfully, so we mark this
// as changed if the value used to be valid and now isn't
SetValueDidChange (value_was_valid);
}
}
else
{
m_error.SetErrorString("out of scope");
}
}
return m_error.Success();
}
bool
ValueObject::UpdateFormatsIfNeeded()
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
if (log)
log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
GetName().GetCString(),
this,
m_last_format_mgr_revision,
DataVisualization::GetCurrentRevision());
bool any_change = false;
if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
{
SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
#ifndef LLDB_DISABLE_PYTHON
SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
#endif
m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
any_change = true;
}
return any_change;
}
void
ValueObject::SetNeedsUpdate ()
{
m_update_point.SetNeedsUpdate();
// We have to clear the value string here so ConstResult children will notice if their values are
// changed by hand (i.e. with SetValueAsCString).
ClearUserVisibleData(eClearUserVisibleDataItemsValue);
}
void
ValueObject::ClearDynamicTypeInformation ()
{
m_did_calculate_complete_objc_class_type = false;
m_last_format_mgr_revision = 0;
m_override_type = ClangASTType();
SetValueFormat(lldb::TypeFormatImplSP());
SetSummaryFormat(lldb::TypeSummaryImplSP());
SetSyntheticChildren(lldb::SyntheticChildrenSP());
}
ClangASTType
ValueObject::MaybeCalculateCompleteType ()
{
ClangASTType clang_type(GetClangTypeImpl());
if (m_did_calculate_complete_objc_class_type)
{
if (m_override_type.IsValid())
return m_override_type;
else
return clang_type;
}
ClangASTType class_type;
bool is_pointer_type = false;
if (clang_type.IsObjCObjectPointerType(&class_type))
{
is_pointer_type = true;
}
else if (clang_type.IsObjCObjectOrInterfaceType())
{
class_type = clang_type;
}
else
{
return clang_type;
}
m_did_calculate_complete_objc_class_type = true;
if (class_type)
{
ConstString class_name (class_type.GetConstTypeName());
if (class_name)
{
ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
if (process_sp)
{
ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
if (objc_language_runtime)
{
TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
if (complete_objc_class_type_sp)
{
ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
if (complete_class.GetCompleteType())
{
if (is_pointer_type)
{
m_override_type = complete_class.GetPointerType();
}
else
{
m_override_type = complete_class;
}
if (m_override_type.IsValid())
return m_override_type;
}
}
}
}
}
}
return clang_type;
}
ClangASTType
ValueObject::GetClangType ()
{
return MaybeCalculateCompleteType();
}
DataExtractor &
ValueObject::GetDataExtractor ()
{
UpdateValueIfNeeded(false);
return m_data;
}
const Error &
ValueObject::GetError()
{
UpdateValueIfNeeded(false);
return m_error;
}
const ConstString &
ValueObject::GetName() const
{
return m_name;
}
const char *
ValueObject::GetLocationAsCString ()
{
return GetLocationAsCStringImpl(m_value,
m_data);
}
const char *
ValueObject::GetLocationAsCStringImpl (const Value& value,
const DataExtractor& data)
{
if (UpdateValueIfNeeded(false))
{
if (m_location_str.empty())
{
StreamString sstr;
Value::ValueType value_type = value.GetValueType();
switch (value_type)
{
case Value::eValueTypeScalar:
case Value::eValueTypeVector:
if (value.GetContextType() == Value::eContextTypeRegisterInfo)
{
RegisterInfo *reg_info = value.GetRegisterInfo();
if (reg_info)
{
if (reg_info->name)
m_location_str = reg_info->name;
else if (reg_info->alt_name)
m_location_str = reg_info->alt_name;
if (m_location_str.empty())
m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
}
}
if (m_location_str.empty())
m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
break;
case Value::eValueTypeLoadAddress:
case Value::eValueTypeFileAddress:
case Value::eValueTypeHostAddress:
{
uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
m_location_str.swap(sstr.GetString());
}
break;
}
}
}
return m_location_str.c_str();
}
Value &
ValueObject::GetValue()
{
return m_value;
}
const Value &
ValueObject::GetValue() const
{
return m_value;
}
bool
ValueObject::ResolveValue (Scalar &scalar)
{
if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
{
ExecutionContext exe_ctx (GetExecutionContextRef());
Value tmp_value(m_value);
scalar = tmp_value.ResolveValue(&exe_ctx);
if (scalar.IsValid())
{
const uint32_t bitfield_bit_size = GetBitfieldBitSize();
if (bitfield_bit_size)
return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
return true;
}
}
return false;
}
bool
ValueObject::GetValueIsValid () const
{
return m_value_is_valid;
}
void
ValueObject::SetValueIsValid (bool b)
{
m_value_is_valid = b;
}
bool
ValueObject::GetValueDidChange ()
{
GetValueAsCString ();
return m_value_did_change;
}
void
ValueObject::SetValueDidChange (bool value_changed)
{
m_value_did_change = value_changed;
}
ValueObjectSP
ValueObject::GetChildAtIndex (size_t idx, bool can_create)
{
ValueObjectSP child_sp;
// We may need to update our value if we are dynamic
if (IsPossibleDynamicType ())
UpdateValueIfNeeded(false);
if (idx < GetNumChildren())
{
// Check if we have already made the child value object?
if (can_create && !m_children.HasChildAtIndex(idx))
{
// No we haven't created the child at this index, so lets have our
// subclass do it and cache the result for quick future access.
m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
}
ValueObject* child = m_children.GetChildAtIndex(idx);
if (child != NULL)
return child->GetSP();
}
return child_sp;
}
ValueObjectSP
ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
size_t* index_of_error)
{
if (idxs.size() == 0)
return GetSP();
ValueObjectSP root(GetSP());
for (size_t idx : idxs)
{
root = root->GetChildAtIndex(idx, true);
if (!root)
{
if (index_of_error)
*index_of_error = idx;
return root;
}
}
return root;
}
ValueObjectSP
ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
size_t* index_of_error)
{
if (idxs.size() == 0)
return GetSP();
ValueObjectSP root(GetSP());
for (std::pair<size_t, bool> idx : idxs)
{
root = root->GetChildAtIndex(idx.first, idx.second);
if (!root)
{
if (index_of_error)
*index_of_error = idx.first;
return root;
}
}
return root;
}
lldb::ValueObjectSP
ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
size_t* index_of_error)
{
if (idxs.size() == 0)
return GetSP();
ValueObjectSP root(GetSP());
for (size_t idx : idxs)
{
root = root->GetChildAtIndex(idx, true);
if (!root)
{
if (index_of_error)
*index_of_error = idx;
return root;
}
}
return root;
}
lldb::ValueObjectSP
ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
size_t* index_of_error)
{
if (idxs.size() == 0)
return GetSP();
ValueObjectSP root(GetSP());
for (std::pair<size_t, bool> idx : idxs)
{
root = root->GetChildAtIndex(idx.first, idx.second);
if (!root)
{
if (index_of_error)
*index_of_error = idx.first;
return root;
}
}
return root;
}
size_t
ValueObject::GetIndexOfChildWithName (const ConstString &name)
{
bool omit_empty_base_classes = true;
return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
}
ValueObjectSP
ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
{
// when getting a child by name, it could be buried inside some base
// classes (which really aren't part of the expression path), so we
// need a vector of indexes that can get us down to the correct child
ValueObjectSP child_sp;
// We may need to update our value if we are dynamic
if (IsPossibleDynamicType ())
UpdateValueIfNeeded(false);
std::vector<uint32_t> child_indexes;
bool omit_empty_base_classes = true;
const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
omit_empty_base_classes,
child_indexes);
if (num_child_indexes > 0)
{
std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
std::vector<uint32_t>::const_iterator end = child_indexes.end ();
child_sp = GetChildAtIndex(*pos, can_create);
for (++pos; pos != end; ++pos)
{
if (child_sp)
{
ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
child_sp = new_child_sp;
}
else
{
child_sp.reset();
}
}
}
return child_sp;
}
size_t
ValueObject::GetNumChildren ()
{
UpdateValueIfNeeded();
if (!m_children_count_valid)
{
SetNumChildren (CalculateNumChildren());
}
return m_children.GetChildrenCount();
}
bool
ValueObject::MightHaveChildren()
{
bool has_children = false;
const uint32_t type_info = GetTypeInfo();
if (type_info)
{
if (type_info & (ClangASTType::eTypeHasChildren |
ClangASTType::eTypeIsPointer |
ClangASTType::eTypeIsReference))
has_children = true;
}
else
{
has_children = GetNumChildren () > 0;
}
return has_children;
}
// Should only be called by ValueObject::GetNumChildren()
void
ValueObject::SetNumChildren (size_t num_children)
{
m_children_count_valid = true;
m_children.SetChildrenCount(num_children);
}
void
ValueObject::SetName (const ConstString &name)
{
m_name = name;
}
ValueObject *
ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
{
ValueObject *valobj = NULL;
bool omit_empty_base_classes = true;
bool ignore_array_bounds = synthetic_array_member;
std::string child_name_str;
uint32_t child_byte_size = 0;
int32_t child_byte_offset = 0;
uint32_t child_bitfield_bit_size = 0;
uint32_t child_bitfield_bit_offset = 0;
bool child_is_base_class = false;
bool child_is_deref_of_parent = false;
const bool transparent_pointers = synthetic_array_member == false;
ClangASTType child_clang_type;
ExecutionContext exe_ctx (GetExecutionContextRef());
child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
GetName().GetCString(),
idx,
transparent_pointers,
omit_empty_base_classes,
ignore_array_bounds,
child_name_str,
child_byte_size,
child_byte_offset,
child_bitfield_bit_size,
child_bitfield_bit_offset,
child_is_base_class,
child_is_deref_of_parent);
if (child_clang_type)
{
if (synthetic_index)
child_byte_offset += child_byte_size * synthetic_index;
ConstString child_name;
if (!child_name_str.empty())
child_name.SetCString (child_name_str.c_str());
valobj = new ValueObjectChild (*this,
child_clang_type,
child_name,
child_byte_size,
child_byte_offset,
child_bitfield_bit_size,
child_bitfield_bit_offset,
child_is_base_class,
child_is_deref_of_parent,
eAddressTypeInvalid);
//if (valobj)
// valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
}
return valobj;
}
bool
ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
std::string& destination)
{
destination.clear();
// ideally we would like to bail out if passing NULL, but if we do so
// we end up not providing the summary for function pointers anymore
if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
return false;
m_is_getting_summary = true;
// this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
// information that we might care to see in a crash log. might be useful in very specific situations though.
/*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
GetTypeName().GetCString(),
GetName().GetCString(),
summary_ptr->GetDescription().c_str());*/
if (UpdateValueIfNeeded (false))
{
if (summary_ptr)
{
if (HasSyntheticValue())
m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
summary_ptr->FormatObject(this, destination);
}
else
{
ClangASTType clang_type = GetClangType();
// Do some default printout for function pointers
if (clang_type)
{
if (clang_type.IsFunctionPointerType ())
{
StreamString sstr;
AddressType func_ptr_address_type = eAddressTypeInvalid;
addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
{
switch (func_ptr_address_type)
{
case eAddressTypeInvalid:
case eAddressTypeFile:
break;
case eAddressTypeLoad:
{
ExecutionContext exe_ctx (GetExecutionContextRef());
Address so_addr;
Target *target = exe_ctx.GetTargetPtr();
if (target && target->GetSectionLoadList().IsEmpty() == false)
{
if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
{
so_addr.Dump (&sstr,
exe_ctx.GetBestExecutionContextScope(),
Address::DumpStyleResolvedDescription,
Address::DumpStyleSectionNameOffset);
}
}
}
break;
case eAddressTypeHost:
break;
}
}
if (sstr.GetSize() > 0)
{
destination.assign (1, '(');
destination.append (sstr.GetData(), sstr.GetSize());
destination.append (1, ')');
}
}
}
}
}
m_is_getting_summary = false;
return !destination.empty();
}
const char *
ValueObject::GetSummaryAsCString ()
{
if (UpdateValueIfNeeded(true) && m_summary_str.empty())
{
GetSummaryAsCString(GetSummaryFormat().get(),
m_summary_str);
}
if (m_summary_str.empty())
return NULL;
return m_summary_str.c_str();
}
bool
ValueObject::IsCStringContainer(bool check_pointer)
{
ClangASTType pointee_or_element_clang_type;
const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
pointee_or_element_clang_type.IsCharType ());
if (!is_char_arr_ptr)
return false;
if (!check_pointer)
return true;
if (type_flags.Test(ClangASTType::eTypeIsArray))
return true;
addr_t cstr_address = LLDB_INVALID_ADDRESS;
AddressType cstr_address_type = eAddressTypeInvalid;
cstr_address = GetAddressOf (true, &cstr_address_type);
return (cstr_address != LLDB_INVALID_ADDRESS);
}
size_t
ValueObject::GetPointeeData (DataExtractor& data,
uint32_t item_idx,
uint32_t item_count)
{
ClangASTType pointee_or_element_clang_type;
const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
if (!(is_pointer_type || is_array_type))
return 0;
if (item_count == 0)
return 0;
const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
const uint64_t bytes = item_count * item_type_size;
const uint64_t offset = item_idx * item_type_size;
if (item_idx == 0 && item_count == 1) // simply a deref
{
if (is_pointer_type)
{
Error error;
ValueObjectSP pointee_sp = Dereference(error);
if (error.Fail() || pointee_sp.get() == NULL)
return 0;
return pointee_sp->GetDataExtractor().Copy(data);
}
else
{
ValueObjectSP child_sp = GetChildAtIndex(0, true);
if (child_sp.get() == NULL)
return 0;
return child_sp->GetDataExtractor().Copy(data);
}
return true;
}
else /* (items > 1) */
{
Error error;
lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
AddressType addr_type;
lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
switch (addr_type)
{
case eAddressTypeFile:
{
ModuleSP module_sp (GetModule());
if (module_sp)
{
addr = addr + offset;
Address so_addr;
module_sp->ResolveFileAddress(addr, so_addr);
ExecutionContext exe_ctx (GetExecutionContextRef());
Target* target = exe_ctx.GetTargetPtr();
if (target)
{
heap_buf_ptr->SetByteSize(bytes);
size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
if (error.Success())
{
data.SetData(data_sp);
return bytes_read;
}
}
}
}
break;
case eAddressTypeLoad:
{
ExecutionContext exe_ctx (GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (process)
{
heap_buf_ptr->SetByteSize(bytes);
size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
if (error.Success())
{
data.SetData(data_sp);
return bytes_read;
}
}
}
break;
case eAddressTypeHost:
{
const uint64_t max_bytes = GetClangType().GetByteSize();
if (max_bytes > offset)
{
size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
data.SetData(data_sp);
return bytes_read;
}
}
break;
case eAddressTypeInvalid:
break;
}
}
return 0;
}
uint64_t
ValueObject::GetData (DataExtractor& data)
{
UpdateValueIfNeeded(false);
ExecutionContext exe_ctx (GetExecutionContextRef());
Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
if (error.Fail())
{
if (m_data.GetByteSize())
{
data = m_data;
return data.GetByteSize();
}
else
{
return 0;
}
}
data.SetAddressByteSize(m_data.GetAddressByteSize());
data.SetByteOrder(m_data.GetByteOrder());
return data.GetByteSize();
}
bool
ValueObject::SetData (DataExtractor &data, Error &error)
{
error.Clear();
// Make sure our value is up to date first so that our location and location
// type is valid.
if (!UpdateValueIfNeeded(false))
{
error.SetErrorString("unable to read value");
return false;
}
uint64_t count = 0;
const Encoding encoding = GetClangType().GetEncoding(count);
const size_t byte_size = GetByteSize();
Value::ValueType value_type = m_value.GetValueType();
switch (value_type)
{
case Value::eValueTypeScalar:
{
Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
if (!set_error.Success())
{
error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
return false;
}
}
break;
case Value::eValueTypeLoadAddress:
{
// If it is a load address, then the scalar value is the storage location
// of the data, and we have to shove this value down to that load location.
ExecutionContext exe_ctx (GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (process)
{
addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
size_t bytes_written = process->WriteMemory(target_addr,
data.GetDataStart(),
byte_size,
error);
if (!error.Success())
return false;
if (bytes_written != byte_size)
{
error.SetErrorString("unable to write value to memory");
return false;
}
}
}
break;
case Value::eValueTypeHostAddress:
{
// If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
m_data.SetData(buffer_sp, 0);
data.CopyByteOrderedData (0,
byte_size,
const_cast<uint8_t *>(m_data.GetDataStart()),
byte_size,
m_data.GetByteOrder());
m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
}
break;
case Value::eValueTypeFileAddress:
case Value::eValueTypeVector:
break;
}
// If we have reached this point, then we have successfully changed the value.
SetNeedsUpdate();
return true;
}
// will compute strlen(str), but without consuming more than
// maxlen bytes out of str (this serves the purpose of reading
// chunks of a string without having to worry about
// missing NULL terminators in the chunk)
// of course, if strlen(str) > maxlen, the function will return
// maxlen_value (which should be != maxlen, because that allows you
// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
static uint32_t
strlen_or_inf (const char* str,
uint32_t maxlen,
uint32_t maxlen_value)
{
uint32_t len = 0;
if (str)
{
while(*str)
{
len++;str++;
if (len >= maxlen)
return maxlen_value;
}
}
return len;
}
size_t
ValueObject::ReadPointedString (Stream& s,
Error& error,
uint32_t max_length,
bool honor_array,
Format item_format)
{
ExecutionContext exe_ctx (GetExecutionContextRef());
Target* target = exe_ctx.GetTargetPtr();
if (!target)
{
s << "<no target to read from>";
error.SetErrorString("no target to read from");
return 0;
}
if (max_length == 0)
max_length = target->GetMaximumSizeOfStringSummary();
size_t bytes_read = 0;
size_t total_bytes_read = 0;
ClangASTType clang_type = GetClangType();
ClangASTType elem_or_pointee_clang_type;
const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
elem_or_pointee_clang_type.IsCharType ())
{
addr_t cstr_address = LLDB_INVALID_ADDRESS;
AddressType cstr_address_type = eAddressTypeInvalid;
size_t cstr_len = 0;
bool capped_data = false;
if (type_flags.Test (ClangASTType::eTypeIsArray))
{
// We have an array
uint64_t array_size = 0;
if (clang_type.IsArrayType(NULL, &array_size, NULL))
{
cstr_len = array_size;
if (cstr_len > max_length)
{
capped_data = true;
cstr_len = max_length;
}
}
cstr_address = GetAddressOf (true, &cstr_address_type);
}
else
{
// We have a pointer
cstr_address = GetPointerValue (&cstr_address_type);
}
if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
{
s << "<invalid address>";
error.SetErrorString("invalid address");
return 0;
}
Address cstr_so_addr (cstr_address);
DataExtractor data;
if (cstr_len > 0 && honor_array)
{
// I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
// but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
GetPointeeData(data, 0, cstr_len);
if ((bytes_read = data.GetByteSize()) > 0)
{
total_bytes_read = bytes_read;
s << '"';
data.Dump (&s,
0, // Start offset in "data"
item_format,
1, // Size of item (1 byte for a char!)
bytes_read, // How many bytes to print?
UINT32_MAX, // num per line
LLDB_INVALID_ADDRESS,// base address
0, // bitfield bit size
0); // bitfield bit offset
if (capped_data)
s << "...";
s << '"';
}
}
else
{
cstr_len = max_length;
const size_t k_max_buf_size = 64;
size_t offset = 0;
int cstr_len_displayed = -1;
bool capped_cstr = false;
// I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
// but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
{
total_bytes_read += bytes_read;
const char *cstr = data.PeekCStr(0);
size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
if (len > k_max_buf_size)
len = k_max_buf_size;
if (cstr && cstr_len_displayed < 0)
s << '"';
if (cstr_len_displayed < 0)
cstr_len_displayed = len;
if (len == 0)
break;
cstr_len_displayed += len;
if (len > bytes_read)
len = bytes_read;
if (len > cstr_len)
len = cstr_len;
data.Dump (&s,
0, // Start offset in "data"
item_format,
1, // Size of item (1 byte for a char!)
len, // How many bytes to print?
UINT32_MAX, // num per line
LLDB_INVALID_ADDRESS,// base address
0, // bitfield bit size
0); // bitfield bit offset
if (len < k_max_buf_size)
break;
if (len >= cstr_len)
{
capped_cstr = true;
break;
}
cstr_len -= len;
offset += len;
}
if (cstr_len_displayed >= 0)
{
s << '"';
if (capped_cstr)
s << "...";
}
}
}
else
{
error.SetErrorString("not a string object");
s << "<not a string object>";
}
return total_bytes_read;
}
const char *
ValueObject::GetObjectDescription ()
{
if (!UpdateValueIfNeeded (true))
return NULL;
if (!m_object_desc_str.empty())
return m_object_desc_str.c_str();
ExecutionContext exe_ctx (GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (process == NULL)
return NULL;
StreamString s;
LanguageType language = GetObjectRuntimeLanguage();
LanguageRuntime *runtime = process->GetLanguageRuntime(language);
if (runtime == NULL)
{
// Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
ClangASTType clang_type = GetClangType();
if (clang_type)
{
bool is_signed;
if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
{
runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
}
}
}
if (runtime && runtime->GetObjectDescription(s, *this))
{
m_object_desc_str.append (s.GetData());
}
if (m_object_desc_str.empty())
return NULL;
else
return m_object_desc_str.c_str();
}
bool
ValueObject::GetValueAsCString (lldb::Format format,
std::string& destination)
{
if (GetClangType().IsAggregateType () == false && UpdateValueIfNeeded(false))
{
const Value::ContextType context_type = m_value.GetContextType();
if (context_type == Value::eContextTypeRegisterInfo)
{
const RegisterInfo *reg_info = m_value.GetRegisterInfo();
if (reg_info)
{
ExecutionContext exe_ctx (GetExecutionContextRef());
StreamString reg_sstr;
m_data.Dump (®_sstr,
0,
format,
reg_info->byte_size,
1,
UINT32_MAX,
LLDB_INVALID_ADDRESS,
0,
0,
exe_ctx.GetBestExecutionContextScope());
destination.swap(reg_sstr.GetString());
}
}
else
{
ClangASTType clang_type = GetClangType ();
if (clang_type)
{
// put custom bytes to display in this DataExtractor to override the default value logic
lldb_private::DataExtractor special_format_data;
if (format == eFormatCString)
{
Flags type_flags(clang_type.GetTypeInfo(NULL));
if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
{
// if we are dumping a pointer as a c-string, get the pointee data as a string
TargetSP target_sp(GetTargetSP());
if (target_sp)
{
size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
Error error;
DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
Address address(GetPointerValue());
if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
special_format_data.SetData(buffer_sp);
}
}
}
StreamString sstr;
ExecutionContext exe_ctx (GetExecutionContextRef());
clang_type.DumpTypeValue (&sstr, // The stream to use for display
format, // Format to display this type with
special_format_data.GetByteSize() ?
special_format_data: m_data, // Data to extract from
0, // Byte offset into "m_data"
GetByteSize(), // Byte size of item in "m_data"
GetBitfieldBitSize(), // Bitfield bit size
GetBitfieldBitOffset(), // Bitfield bit offset
exe_ctx.GetBestExecutionContextScope());
// Don't set the m_error to anything here otherwise
// we won't be able to re-format as anything else. The
// code for ClangASTType::DumpTypeValue() should always
// return something, even if that something contains
// an error messsage. "m_error" is used to detect errors
// when reading the valid object, not for formatting errors.
if (sstr.GetString().empty())
destination.clear();
else
destination.swap(sstr.GetString());
}
}
return !destination.empty();
}
else
return false;
}
const char *
ValueObject::GetValueAsCString ()
{
if (UpdateValueIfNeeded(true))
{
lldb::Format my_format = GetFormat();
if (my_format == lldb::eFormatDefault)
{
if (m_type_format_sp)
my_format = m_type_format_sp->GetFormat();
else
{
if (m_is_bitfield_for_scalar)
my_format = eFormatUnsigned;
else
{
if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
{
const RegisterInfo *reg_info = m_value.GetRegisterInfo();
if (reg_info)
my_format = reg_info->format;
}
else
{
my_format = GetClangType().GetFormat();
}
}
}
}
if (my_format != m_last_format || m_value_str.empty())
{
m_last_format = my_format;
if (GetValueAsCString(my_format, m_value_str))
{
if (!m_value_did_change && m_old_value_valid)
{
// The value was gotten successfully, so we consider the
// value as changed if the value string differs
SetValueDidChange (m_old_value_str != m_value_str);
}
}
}
}
if (m_value_str.empty())
return NULL;
return m_value_str.c_str();
}
// if > 8bytes, 0 is returned. this method should mostly be used
// to read address values out of pointers
uint64_t
ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
{
// If our byte size is zero this is an aggregate type that has children
if (!GetClangType().IsAggregateType())
{
Scalar scalar;
if (ResolveValue (scalar))
{
if (success)
*success = true;
return scalar.ULongLong(fail_value);
}
// fallthrough, otherwise...
}
if (success)
*success = false;
return fail_value;
}
// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
// this call up to date by returning true for your new special cases. We will eventually move
// to checking this call result before trying to display special cases
bool
ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Format custom_format)
{
Flags flags(GetTypeInfo());
if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
&& val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
{
if (IsCStringContainer(true) &&
(custom_format == eFormatCString ||
custom_format == eFormatCharArray ||
custom_format == eFormatChar ||
custom_format == eFormatVectorOfChar))
return true;
if (flags.Test(ClangASTType::eTypeIsArray))
{
if ((custom_format == eFormatBytes) ||
(custom_format == eFormatBytesWithASCII))
return true;
if ((custom_format == eFormatVectorOfChar) ||
(custom_format == eFormatVectorOfFloat32) ||
(custom_format == eFormatVectorOfFloat64) ||
(custom_format == eFormatVectorOfSInt16) ||
(custom_format == eFormatVectorOfSInt32) ||
(custom_format == eFormatVectorOfSInt64) ||
(custom_format == eFormatVectorOfSInt8) ||
(custom_format == eFormatVectorOfUInt128) ||
(custom_format == eFormatVectorOfUInt16) ||
(custom_format == eFormatVectorOfUInt32) ||
(custom_format == eFormatVectorOfUInt64) ||
(custom_format == eFormatVectorOfUInt8))
return true;
}
}
return false;
}
bool
ValueObject::DumpPrintableRepresentation(Stream& s,
ValueObjectRepresentationStyle val_obj_display,
Format custom_format,
PrintableRepresentationSpecialCases special)
{
Flags flags(GetTypeInfo());
bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
if (allow_special)
{
if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
&& val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
{
// when being asked to get a printable display an array or pointer type directly,
// try to "do the right thing"
if (IsCStringContainer(true) &&
(custom_format == eFormatCString ||
custom_format == eFormatCharArray ||
custom_format == eFormatChar ||
custom_format == eFormatVectorOfChar)) // print char[] & char* directly
{
Error error;
ReadPointedString(s,
error,
0,
(custom_format == eFormatVectorOfChar) ||
(custom_format == eFormatCharArray));
return !error.Fail();
}
if (custom_format == eFormatEnum)
return false;
// this only works for arrays, because I have no way to know when
// the pointed memory ends, and no special \0 end of data marker
if (flags.Test(ClangASTType::eTypeIsArray))
{
if ((custom_format == eFormatBytes) ||
(custom_format == eFormatBytesWithASCII))
{
const size_t count = GetNumChildren();
s << '[';
for (size_t low = 0; low < count; low++)
{
if (low)
s << ',';
ValueObjectSP child = GetChildAtIndex(low,true);
if (!child.get())
{
s << "<invalid child>";
continue;
}
child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
}
s << ']';
return true;
}
if ((custom_format == eFormatVectorOfChar) ||
(custom_format == eFormatVectorOfFloat32) ||
(custom_format == eFormatVectorOfFloat64) ||
(custom_format == eFormatVectorOfSInt16) ||
(custom_format == eFormatVectorOfSInt32) ||
(custom_format == eFormatVectorOfSInt64) ||
(custom_format == eFormatVectorOfSInt8) ||
(custom_format == eFormatVectorOfUInt128) ||
(custom_format == eFormatVectorOfUInt16) ||
(custom_format == eFormatVectorOfUInt32) ||
(custom_format == eFormatVectorOfUInt64) ||
(custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
{
const size_t count = GetNumChildren();
Format format = FormatManager::GetSingleItemFormat(custom_format);
s << '[';
for (size_t low = 0; low < count; low++)
{
if (low)
s << ',';
ValueObjectSP child = GetChildAtIndex(low,true);
if (!child.get())
{
s << "<invalid child>";
continue;
}
child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
}
s << ']';
return true;
}
}
if ((custom_format == eFormatBoolean) ||
(custom_format == eFormatBinary) ||
(custom_format == eFormatChar) ||
(custom_format == eFormatCharPrintable) ||
(custom_format == eFormatComplexFloat) ||
(custom_format == eFormatDecimal) ||
(custom_format == eFormatHex) ||
(custom_format == eFormatHexUppercase) ||
(custom_format == eFormatFloat) ||
(custom_format == eFormatOctal) ||
(custom_format == eFormatOSType) ||
(custom_format == eFormatUnicode16) ||
(custom_format == eFormatUnicode32) ||
(custom_format == eFormatUnsigned) ||
(custom_format == eFormatPointer) ||
(custom_format == eFormatComplexInteger) ||
(custom_format == eFormatComplex) ||
(custom_format == eFormatDefault)) // use the [] operator
return false;
}
}
if (only_special)
return false;
bool var_success = false;
{
const char *cstr = NULL;
// this is a local stream that we are using to ensure that the data pointed to by cstr survives
// long enough for us to copy it to its destination - it is necessary to have this temporary storage
// area for cases where our desired output is not backed by some other longer-term storage
StreamString strm;
if (custom_format != eFormatInvalid)
SetFormat(custom_format);
switch(val_obj_display)
{
case eValueObjectRepresentationStyleValue:
cstr = GetValueAsCString();
break;
case eValueObjectRepresentationStyleSummary:
cstr = GetSummaryAsCString();
break;
case eValueObjectRepresentationStyleLanguageSpecific:
cstr = GetObjectDescription();
break;
case eValueObjectRepresentationStyleLocation:
cstr = GetLocationAsCString();
break;
case eValueObjectRepresentationStyleChildrenCount:
strm.Printf("%zu", GetNumChildren());
cstr = strm.GetString().c_str();
break;
case eValueObjectRepresentationStyleType:
cstr = GetTypeName().AsCString();
break;
case eValueObjectRepresentationStyleName:
cstr = GetName().AsCString();
break;
case eValueObjectRepresentationStyleExpressionPath:
GetExpressionPath(strm, false);
cstr = strm.GetString().c_str();
break;
}
if (!cstr)
{
if (val_obj_display == eValueObjectRepresentationStyleValue)
cstr = GetSummaryAsCString();
else if (val_obj_display == eValueObjectRepresentationStyleSummary)
{
if (GetClangType().IsAggregateType())
{
strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
cstr = strm.GetString().c_str();
}
else
cstr = GetValueAsCString();
}
}
if (cstr)
s.PutCString(cstr);
else
{
if (m_error.Fail())
s.Printf("<%s>", m_error.AsCString());
else if (val_obj_display == eValueObjectRepresentationStyleSummary)
s.PutCString("<no summary available>");
else if (val_obj_display == eValueObjectRepresentationStyleValue)
s.PutCString("<no value available>");
else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
else
s.PutCString("<no printable representation>");
}
// we should only return false here if we could not do *anything*
// even if we have an error message as output, that's a success
// from our callers' perspective, so return true
var_success = true;
if (custom_format != eFormatInvalid)
SetFormat(eFormatDefault);
}
return var_success;
}
addr_t
ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
{
if (!UpdateValueIfNeeded(false))
return LLDB_INVALID_ADDRESS;
switch (m_value.GetValueType())
{
case Value::eValueTypeScalar:
case Value::eValueTypeVector:
if (scalar_is_load_address)
{
if(address_type)
*address_type = eAddressTypeLoad;
return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
}
break;
case Value::eValueTypeLoadAddress:
case Value::eValueTypeFileAddress:
case Value::eValueTypeHostAddress:
{
if(address_type)
*address_type = m_value.GetValueAddressType ();
return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
}
break;
}
if (address_type)
*address_type = eAddressTypeInvalid;
return LLDB_INVALID_ADDRESS;
}
addr_t
ValueObject::GetPointerValue (AddressType *address_type)
{
addr_t address = LLDB_INVALID_ADDRESS;
if(address_type)
*address_type = eAddressTypeInvalid;
if (!UpdateValueIfNeeded(false))
return address;
switch (m_value.GetValueType())
{
case Value::eValueTypeScalar:
case Value::eValueTypeVector:
address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
break;
case Value::eValueTypeHostAddress:
case Value::eValueTypeLoadAddress:
case Value::eValueTypeFileAddress:
{
lldb::offset_t data_offset = 0;
address = m_data.GetPointer(&data_offset);
}
break;
}
if (address_type)
*address_type = GetAddressTypeOfChildren();
return address;
}
bool
ValueObject::SetValueFromCString (const char *value_str, Error& error)
{
error.Clear();
// Make sure our value is up to date first so that our location and location
// type is valid.
if (!UpdateValueIfNeeded(false))
{
error.SetErrorString("unable to read value");
return false;
}
uint64_t count = 0;
const Encoding encoding = GetClangType().GetEncoding (count);
const size_t byte_size = GetByteSize();
Value::ValueType value_type = m_value.GetValueType();
if (value_type == Value::eValueTypeScalar)
{
// If the value is already a scalar, then let the scalar change itself:
m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
}
else if (byte_size <= Scalar::GetMaxByteSize())
{
// If the value fits in a scalar, then make a new scalar and again let the
// scalar code do the conversion, then figure out where to put the new value.
Scalar new_scalar;
error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
if (error.Success())
{
switch (value_type)
{
case Value::eValueTypeLoadAddress:
{
// If it is a load address, then the scalar value is the storage location
// of the data, and we have to shove this value down to that load location.
ExecutionContext exe_ctx (GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (process)
{
addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
size_t bytes_written = process->WriteScalarToMemory (target_addr,
new_scalar,
byte_size,
error);
if (!error.Success())
return false;
if (bytes_written != byte_size)
{
error.SetErrorString("unable to write value to memory");
return false;
}
}
}
break;
case Value::eValueTypeHostAddress:
{
// If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
DataExtractor new_data;
new_data.SetByteOrder (m_data.GetByteOrder());
DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
m_data.SetData(buffer_sp, 0);
bool success = new_scalar.GetData(new_data);
if (success)
{
new_data.CopyByteOrderedData (0,
byte_size,
const_cast<uint8_t *>(m_data.GetDataStart()),
byte_size,
m_data.GetByteOrder());
}
m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
}
break;
case Value::eValueTypeFileAddress:
case Value::eValueTypeScalar:
case Value::eValueTypeVector:
break;
}
}
else
{
return false;
}
}
else
{
// We don't support setting things bigger than a scalar at present.
error.SetErrorString("unable to write aggregate data type");
return false;
}
// If we have reached this point, then we have successfully changed the value.
SetNeedsUpdate();
return true;
}
bool
ValueObject::GetDeclaration (Declaration &decl)
{
decl.Clear();
return false;
}
ConstString
ValueObject::GetTypeName()
{
return GetClangType().GetConstTypeName();
}
ConstString
ValueObject::GetQualifiedTypeName()
{
return GetClangType().GetConstQualifiedTypeName();
}
LanguageType
ValueObject::GetObjectRuntimeLanguage ()
{
return GetClangType().GetMinimumLanguage ();
}
void
ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
{
m_synthetic_children[key] = valobj;
}
ValueObjectSP
ValueObject::GetSyntheticChild (const ConstString &key) const
{
ValueObjectSP synthetic_child_sp;
std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
if (pos != m_synthetic_children.end())
synthetic_child_sp = pos->second->GetSP();
return synthetic_child_sp;
}
uint32_t
ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
{
return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
}
bool
ValueObject::IsPointerType ()
{
return GetClangType().IsPointerType();
}
bool
ValueObject::IsArrayType ()
{
return GetClangType().IsArrayType (NULL, NULL, NULL);
}
bool
ValueObject::IsScalarType ()
{
return GetClangType().IsScalarType ();
}
bool
ValueObject::IsIntegerType (bool &is_signed)
{
return GetClangType().IsIntegerType (is_signed);
}
bool
ValueObject::IsPointerOrReferenceType ()
{
return GetClangType().IsPointerOrReferenceType ();
}
bool
ValueObject::IsPossibleDynamicType ()
{
ExecutionContext exe_ctx (GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (process)
return process->IsPossibleDynamicValue(*this);
else
return GetClangType().IsPossibleDynamicType (NULL, true, true);
}
bool
ValueObject::IsObjCNil ()
{
const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
if (!isObjCpointer)
return false;
bool canReadValue = true;
bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
return canReadValue && isZero;
}
ValueObjectSP
ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
{
const uint32_t type_info = GetTypeInfo ();
if (type_info & ClangASTType::eTypeIsArray)
return GetSyntheticArrayMemberFromArray(index, can_create);
if (type_info & ClangASTType::eTypeIsPointer)
return GetSyntheticArrayMemberFromPointer(index, can_create);
return ValueObjectSP();
}
ValueObjectSP
ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
{
ValueObjectSP synthetic_child_sp;
if (IsPointerType ())
{
char index_str[64];
snprintf(index_str, sizeof(index_str), "[%zu]", index);
ConstString index_const_str(index_str);
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
synthetic_child_sp = GetSyntheticChild (index_const_str);
if (!synthetic_child_sp)
{
ValueObject *synthetic_child;
// We haven't made a synthetic array member for INDEX yet, so
// lets make one and cache it for any future reference.
synthetic_child = CreateChildAtIndex(0, true, index);
// Cache the value if we got one back...
if (synthetic_child)
{
AddSyntheticChild(index_const_str, synthetic_child);
synthetic_child_sp = synthetic_child->GetSP();
synthetic_child_sp->SetName(ConstString(index_str));
synthetic_child_sp->m_is_array_item_for_pointer = true;
}
}
}
return synthetic_child_sp;
}
// This allows you to create an array member using and index
// that doesn't not fall in the normal bounds of the array.
// Many times structure can be defined as:
// struct Collection
// {
// uint32_t item_count;
// Item item_array[0];
// };
// The size of the "item_array" is 1, but many times in practice
// there are more items in "item_array".
ValueObjectSP
ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
{
ValueObjectSP synthetic_child_sp;
if (IsArrayType ())
{
char index_str[64];
snprintf(index_str, sizeof(index_str), "[%zu]", index);
ConstString index_const_str(index_str);
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
synthetic_child_sp = GetSyntheticChild (index_const_str);
if (!synthetic_child_sp)
{
ValueObject *synthetic_child;
// We haven't made a synthetic array member for INDEX yet, so
// lets make one and cache it for any future reference.
synthetic_child = CreateChildAtIndex(0, true, index);
// Cache the value if we got one back...
if (synthetic_child)
{
AddSyntheticChild(index_const_str, synthetic_child);
synthetic_child_sp = synthetic_child->GetSP();
synthetic_child_sp->SetName(ConstString(index_str));
synthetic_child_sp->m_is_array_item_for_pointer = true;
}
}
}
return synthetic_child_sp;
}
ValueObjectSP
ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
{
ValueObjectSP synthetic_child_sp;
if (IsScalarType ())
{
char index_str[64];
snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
ConstString index_const_str(index_str);
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
synthetic_child_sp = GetSyntheticChild (index_const_str);
if (!synthetic_child_sp)
{
// We haven't made a synthetic array member for INDEX yet, so
// lets make one and cache it for any future reference.
ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
GetClangType(),
index_const_str,
GetByteSize(),
0,
to-from+1,
from,
false,
false,
eAddressTypeInvalid);
// Cache the value if we got one back...
if (synthetic_child)
{
AddSyntheticChild(index_const_str, synthetic_child);
synthetic_child_sp = synthetic_child->GetSP();
synthetic_child_sp->SetName(ConstString(index_str));
synthetic_child_sp->m_is_bitfield_for_scalar = true;
}
}
}
return synthetic_child_sp;
}
ValueObjectSP
ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
{
ValueObjectSP synthetic_child_sp;
char name_str[64];
snprintf(name_str, sizeof(name_str), "@%i", offset);
ConstString name_const_str(name_str);
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
synthetic_child_sp = GetSyntheticChild (name_const_str);
if (synthetic_child_sp.get())
return synthetic_child_sp;
if (!can_create)
return ValueObjectSP();
ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
type,
name_const_str,
type.GetByteSize(),
offset,
0,
0,
false,
false,
eAddressTypeInvalid);
if (synthetic_child)
{
AddSyntheticChild(name_const_str, synthetic_child);
synthetic_child_sp = synthetic_child->GetSP();
synthetic_child_sp->SetName(name_const_str);
synthetic_child_sp->m_is_child_at_offset = true;
}
return synthetic_child_sp;
}
// your expression path needs to have a leading . or ->
// (unless it somehow "looks like" an array, in which case it has
// a leading [ symbol). while the [ is meaningful and should be shown
// to the user, . and -> are just parser design, but by no means
// added information for the user.. strip them off
static const char*
SkipLeadingExpressionPathSeparators(const char* expression)
{
if (!expression || !expression[0])
return expression;
if (expression[0] == '.')
return expression+1;
if (expression[0] == '-' && expression[1] == '>')
return expression+2;
return expression;
}
ValueObjectSP
ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
{
ValueObjectSP synthetic_child_sp;
ConstString name_const_string(expression);
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
synthetic_child_sp = GetSyntheticChild (name_const_string);
if (!synthetic_child_sp)
{
// We haven't made a synthetic array member for expression yet, so
// lets make one and cache it for any future reference.
synthetic_child_sp = GetValueForExpressionPath(expression,
NULL, NULL, NULL,
GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
// Cache the value if we got one back...
if (synthetic_child_sp.get())
{
// FIXME: this causes a "real" child to end up with its name changed to the contents of expression
AddSyntheticChild(name_const_string, synthetic_child_sp.get());
synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
}
}
return synthetic_child_sp;
}
void
ValueObject::CalculateSyntheticValue (bool use_synthetic)
{
if (use_synthetic == false)
return;
TargetSP target_sp(GetTargetSP());
if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
{
m_synthetic_value = NULL;
return;
}
lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
if (!UpdateFormatsIfNeeded() && m_synthetic_value)
return;
if (m_synthetic_children_sp.get() == NULL)
return;
if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
return;
m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
}
void
ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
{
if (use_dynamic == eNoDynamicValues)
return;
if (!m_dynamic_value && !IsDynamic())
{
ExecutionContext exe_ctx (GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (process && process->IsPossibleDynamicValue(*this))
{
ClearDynamicTypeInformation ();
m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
}
}
}
ValueObjectSP
ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
{
if (use_dynamic == eNoDynamicValues)
return ValueObjectSP();
if (!IsDynamic() && m_dynamic_value == NULL)
{
CalculateDynamicValue(use_dynamic);
}
if (m_dynamic_value)
return m_dynamic_value->GetSP();
else
return ValueObjectSP();
}
ValueObjectSP
ValueObject::GetStaticValue()
{
return GetSP();
}
lldb::ValueObjectSP
ValueObject::GetNonSyntheticValue ()
{
return GetSP();
}
ValueObjectSP
ValueObject::GetSyntheticValue (bool use_synthetic)
{
if (use_synthetic == false)
return ValueObjectSP();
CalculateSyntheticValue(use_synthetic);
if (m_synthetic_value)
return m_synthetic_value->GetSP();
else
return ValueObjectSP();
}
bool
ValueObject::HasSyntheticValue()
{
UpdateFormatsIfNeeded();
if (m_synthetic_children_sp.get() == NULL)
return false;
CalculateSyntheticValue(true);
if (m_synthetic_value)
return true;
else
return false;
}
bool
ValueObject::GetBaseClassPath (Stream &s)
{
if (IsBaseClass())
{
bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
ClangASTType clang_type = GetClangType();
std::string cxx_class_name;
bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
if (this_had_base_class)
{
if (parent_had_base_class)
s.PutCString("::");
s.PutCString(cxx_class_name.c_str());
}
return parent_had_base_class || this_had_base_class;
}
return false;
}
ValueObject *
ValueObject::GetNonBaseClassParent()
{
if (GetParent())
{
if (GetParent()->IsBaseClass())
return GetParent()->GetNonBaseClassParent();
else
return GetParent();
}
return NULL;
}
void
ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
{
const bool is_deref_of_parent = IsDereferenceOfParent ();
if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
{
// this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
// fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
// the eHonorPointers mode is meant to produce strings in this latter format
s.PutCString("*(");
}
ValueObject* parent = GetParent();
if (parent)
parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
// if we are a deref_of_parent just because we are synthetic array
// members made up to allow ptr[%d] syntax to work in variable
// printing, then add our name ([%d]) to the expression path
if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
s.PutCString(m_name.AsCString());
if (!IsBaseClass())
{
if (!is_deref_of_parent)
{
ValueObject *non_base_class_parent = GetNonBaseClassParent();
if (non_base_class_parent)
{
ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
if (non_base_class_parent_clang_type)
{
if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
{
s.PutCString("->");
}
else
{
const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
{
s.PutCString("->");
}
else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
!(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
{
s.PutChar('.');
}
}
}
}
const char *name = GetName().GetCString();
if (name)
{
if (qualify_cxx_base_classes)
{
if (GetBaseClassPath (s))
s.PutCString("::");
}
s.PutCString(name);
}
}
}
if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
{
s.PutChar(')');
}
}
ValueObjectSP
ValueObject::GetValueForExpressionPath(const char* expression,
const char** first_unparsed,
ExpressionPathScanEndReason* reason_to_stop,
ExpressionPathEndResultType* final_value_type,
const GetValueForExpressionPathOptions& options,
ExpressionPathAftermath* final_task_on_target)
{
const char* dummy_first_unparsed;
ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
first_unparsed ? first_unparsed : &dummy_first_unparsed,
reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
final_value_type ? final_value_type : &dummy_final_value_type,
options,
final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
return ret_val;
if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
{
if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
{
Error error;
ValueObjectSP final_value = ret_val->Dereference(error);
if (error.Fail() || !final_value.get())
{
if (reason_to_stop)
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
if (final_value_type)
*final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
if (final_task_on_target)
*final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
return final_value;
}
}
if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
{
Error error;
ValueObjectSP final_value = ret_val->AddressOf(error);
if (error.Fail() || !final_value.get())
{
if (reason_to_stop)
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
if (final_value_type)
*final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
if (final_task_on_target)
*final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
return final_value;
}
}
}
return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
}
int
ValueObject::GetValuesForExpressionPath(const char* expression,
ValueObjectListSP& list,
const char** first_unparsed,
ExpressionPathScanEndReason* reason_to_stop,
ExpressionPathEndResultType* final_value_type,
const GetValueForExpressionPathOptions& options,
ExpressionPathAftermath* final_task_on_target)
{
const char* dummy_first_unparsed;
ExpressionPathScanEndReason dummy_reason_to_stop;
ExpressionPathEndResultType dummy_final_value_type;
ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
first_unparsed ? first_unparsed : &dummy_first_unparsed,
reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
final_value_type ? final_value_type : &dummy_final_value_type,
options,
final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
if (!ret_val.get()) // if there are errors, I add nothing to the list
return 0;
if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
{
// I need not expand a range, just post-process the final value and return
if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
{
list->Append(ret_val);
return 1;
}
if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
{
if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
{
Error error;
ValueObjectSP final_value = ret_val->Dereference(error);
if (error.Fail() || !final_value.get())
{
if (reason_to_stop)
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
if (final_value_type)
*final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
*final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
list->Append(final_value);
return 1;
}
}
if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
{
Error error;
ValueObjectSP final_value = ret_val->AddressOf(error);
if (error.Fail() || !final_value.get())
{
if (reason_to_stop)
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
if (final_value_type)
*final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
*final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
list->Append(final_value);
return 1;
}
}
}
}
else
{
return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
first_unparsed ? first_unparsed : &dummy_first_unparsed,
ret_val,
list,
reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
final_value_type ? final_value_type : &dummy_final_value_type,
options,
final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
}
// in any non-covered case, just do the obviously right thing
list->Append(ret_val);
return 1;
}
ValueObjectSP
ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
const char** first_unparsed,
ExpressionPathScanEndReason* reason_to_stop,
ExpressionPathEndResultType* final_result,
const GetValueForExpressionPathOptions& options,
ExpressionPathAftermath* what_next)
{
ValueObjectSP root = GetSP();
if (!root.get())
return ValueObjectSP();
*first_unparsed = expression_cstr;
while (true)
{
const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
ClangASTType root_clang_type = root->GetClangType();
ClangASTType pointee_clang_type;
Flags pointee_clang_type_info;
Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
if (pointee_clang_type)
pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
if (!expression_cstr || *expression_cstr == '\0')
{
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
return root;
}
switch (*expression_cstr)
{
case '-':
{
if (options.m_check_dot_vs_arrow_syntax &&
root_clang_type_info.Test(ClangASTType::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
options.m_no_fragile_ivar)
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
if (expression_cstr[1] != '>')
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
expression_cstr++; // skip the -
}
case '.': // or fallthrough from ->
{
if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
expression_cstr++; // skip .
const char *next_separator = strpbrk(expression_cstr+1,"-.[");
ConstString child_name;
if (!next_separator) // if no other separator just expand this last layer
{
child_name.SetCString (expression_cstr);
ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
if (child_valobj_sp.get()) // we know we are done, so just return
{
*first_unparsed = "";
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
return child_valobj_sp;
}
else if (options.m_no_synthetic_children == false) // let's try with synthetic children
{
if (root->IsSynthetic())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
child_valobj_sp = root->GetSyntheticValue();
if (child_valobj_sp.get())
child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
}
// if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
// so we hit the "else" branch, and return an error
if(child_valobj_sp.get()) // if it worked, just return
{
*first_unparsed = "";
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
return child_valobj_sp;
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
else // other layers do expand
{
child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
if (child_valobj_sp.get()) // store the new root and move on
{
root = child_valobj_sp;
*first_unparsed = next_separator;
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
continue;
}
else if (options.m_no_synthetic_children == false) // let's try with synthetic children
{
if (root->IsSynthetic())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
child_valobj_sp = root->GetSyntheticValue(true);
if (child_valobj_sp)
child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
}
// if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
// so we hit the "else" branch, and return an error
if(child_valobj_sp.get()) // if it worked, move on
{
root = child_valobj_sp;
*first_unparsed = next_separator;
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
continue;
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
break;
}
case '[':
{
if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && !root_clang_type_info.Test(ClangASTType::eTypeIsVector)) // if this is not a T[] nor a T*
{
if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
{
if (options.m_no_synthetic_children) // ...only chance left is synthetic
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
{
if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
{
*first_unparsed = expression_cstr+2;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
*final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
return root;
}
}
const char *separator_position = ::strchr(expression_cstr+1,'-');
const char *close_bracket_position = ::strchr(expression_cstr+1,']');
if (!close_bracket_position) // if there is no ], this is a syntax error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
{
char *end = NULL;
unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
if (!end || end != close_bracket_position) // if something weird is in our way return an error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
{
if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
{
*first_unparsed = expression_cstr+2;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
*final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
return root;
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
// from here on we do have a valid index
if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
{
ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
if (!child_valobj_sp)
child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
if (!child_valobj_sp)
if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
if (child_valobj_sp)
{
root = child_valobj_sp;
*first_unparsed = end+1; // skip ]
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
continue;
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
{
if (*what_next == ValueObject::eExpressionPathAftermathDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
{
Error error;
root = root->Dereference(error);
if (error.Fail() || !root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
*what_next = eExpressionPathAftermathNothing;
continue;
}
}
else
{
if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
&& pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
&& root->HasSyntheticValue()
&& options.m_no_synthetic_children == false)
{
root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
}
else
root = root->GetSyntheticArrayMemberFromPointer(index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
*first_unparsed = end+1; // skip ]
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
continue;
}
}
}
else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
{
root = root->GetSyntheticBitFieldChild(index, index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
{
*first_unparsed = end+1; // skip ]
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
*final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
return root;
}
}
else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
{
root = root->GetChildAtIndex(index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
*first_unparsed = end+1; // skip ]
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
continue;
}
}
else if (options.m_no_synthetic_children == false)
{
if (root->HasSyntheticValue())
root = root->GetSyntheticValue();
else if (!root->IsSynthetic())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
// if we are here, then root itself is a synthetic VO.. should be good to go
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
root = root->GetChildAtIndex(index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
*first_unparsed = end+1; // skip ]
*final_result = ValueObject::eExpressionPathEndResultTypePlain;
continue;
}
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
}
else // we have a low and a high index
{
char *end = NULL;
unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
if (!end || end != separator_position) // if something weird is in our way return an error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
if (!end || end != close_bracket_position) // if something weird is in our way return an error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
if (index_lower > index_higher) // swap indices if required
{
unsigned long temp = index_lower;
index_lower = index_higher;
index_higher = temp;
}
if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
{
root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
*first_unparsed = end+1; // skip ]
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
*final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
return root;
}
}
else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
*what_next == ValueObject::eExpressionPathAftermathDereference &&
pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
{
Error error;
root = root->Dereference(error);
if (error.Fail() || !root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
}
else
{
*what_next = ValueObject::eExpressionPathAftermathNothing;
continue;
}
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
*final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
return root;
}
}
break;
}
default: // some non-separator is in the way
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return ValueObjectSP();
break;
}
}
}
}
int
ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
const char** first_unparsed,
ValueObjectSP root,
ValueObjectListSP& list,
ExpressionPathScanEndReason* reason_to_stop,
ExpressionPathEndResultType* final_result,
const GetValueForExpressionPathOptions& options,
ExpressionPathAftermath* what_next)
{
if (!root.get())
return 0;
*first_unparsed = expression_cstr;
while (true)
{
const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
ClangASTType root_clang_type = root->GetClangType();
ClangASTType pointee_clang_type;
Flags pointee_clang_type_info;
Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
if (pointee_clang_type)
pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
if (!expression_cstr || *expression_cstr == '\0')
{
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
list->Append(root);
return 1;
}
switch (*expression_cstr)
{
case '[':
{
if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if this is not a T[] nor a T*
{
if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
}
if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
{
if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else // expand this into list
{
const size_t max_index = root->GetNumChildren() - 1;
for (size_t index = 0; index < max_index; index++)
{
ValueObjectSP child =
root->GetChildAtIndex(index, true);
list->Append(child);
}
*first_unparsed = expression_cstr+2;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return max_index; // tell me number of items I added to the VOList
}
}
const char *separator_position = ::strchr(expression_cstr+1,'-');
const char *close_bracket_position = ::strchr(expression_cstr+1,']');
if (!close_bracket_position) // if there is no ], this is a syntax error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
{
char *end = NULL;
unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
if (!end || end != close_bracket_position) // if something weird is in our way return an error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
{
if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
{
const size_t max_index = root->GetNumChildren() - 1;
for (size_t index = 0; index < max_index; index++)
{
ValueObjectSP child =
root->GetChildAtIndex(index, true);
list->Append(child);
}
*first_unparsed = expression_cstr+2;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return max_index; // tell me number of items I added to the VOList
}
else
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
}
// from here on we do have a valid index
if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
{
root = root->GetChildAtIndex(index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
list->Append(root);
*first_unparsed = end+1; // skip ]
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return 1;
}
}
else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
{
if (*what_next == ValueObject::eExpressionPathAftermathDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
{
Error error;
root = root->Dereference(error);
if (error.Fail() || !root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
*what_next = eExpressionPathAftermathNothing;
continue;
}
}
else
{
root = root->GetSyntheticArrayMemberFromPointer(index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
list->Append(root);
*first_unparsed = end+1; // skip ]
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return 1;
}
}
}
else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
{
root = root->GetSyntheticBitFieldChild(index, index, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
{
list->Append(root);
*first_unparsed = end+1; // skip ]
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return 1;
}
}
}
else // we have a low and a high index
{
char *end = NULL;
unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
if (!end || end != separator_position) // if something weird is in our way return an error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
if (!end || end != close_bracket_position) // if something weird is in our way return an error
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
if (index_lower > index_higher) // swap indices if required
{
unsigned long temp = index_lower;
index_lower = index_higher;
index_higher = temp;
}
if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
{
root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
if (!root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
list->Append(root);
*first_unparsed = end+1; // skip ]
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return 1;
}
}
else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
*what_next == ValueObject::eExpressionPathAftermathDereference &&
pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
{
Error error;
root = root->Dereference(error);
if (error.Fail() || !root.get())
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
}
else
{
*what_next = ValueObject::eExpressionPathAftermathNothing;
continue;
}
}
else
{
for (unsigned long index = index_lower;
index <= index_higher; index++)
{
ValueObjectSP child =
root->GetChildAtIndex(index, true);
list->Append(child);
}
*first_unparsed = end+1;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
*final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
return index_higher-index_lower+1; // tell me number of items I added to the VOList
}
}
break;
}
default: // some non-[ separator, or something entirely wrong, is in the way
{
*first_unparsed = expression_cstr;
*reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return 0;
break;
}
}
}
}
static void
DumpValueObject_Impl (Stream &s,
ValueObject *valobj,
const ValueObject::DumpValueObjectOptions& options,
uint32_t ptr_depth,
uint32_t curr_depth)
{
if (valobj)
{
bool update_success = valobj->UpdateValueIfNeeded (true);
const char *root_valobj_name =
options.m_root_valobj_name.empty() ?
valobj->GetName().AsCString() :
options.m_root_valobj_name.c_str();
if (update_success && options.m_use_dynamic != eNoDynamicValues)
{
ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
if (dynamic_value)
valobj = dynamic_value;
}
ClangASTType clang_type = valobj->GetClangType();
const Flags type_flags (clang_type.GetTypeInfo ());
const char *err_cstr = NULL;
const bool has_children = type_flags.Test (ClangASTType::eTypeHasChildren);
const bool has_value = type_flags.Test (ClangASTType::eTypeHasValue);
const bool print_valobj = options.m_flat_output == false || has_value;
if (print_valobj)
{
if (options.m_show_location)
{
s.Printf("%s: ", valobj->GetLocationAsCString());
}
s.Indent();
bool show_type = true;
// if we are at the root-level and been asked to hide the root's type, then hide it
if (curr_depth == 0 && options.m_hide_root_type)
show_type = false;
else
// otherwise decide according to the usual rules (asked to show types - always at the root level)
show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
if (show_type)
{
// Some ValueObjects don't have types (like registers sets). Only print
// the type if there is one to print
ConstString qualified_type_name(valobj->GetQualifiedTypeName());
if (qualified_type_name)
s.Printf("(%s) ", qualified_type_name.GetCString());
}
if (options.m_flat_output)
{
// If we are showing types, also qualify the C++ base classes
const bool qualify_cxx_base_classes = options.m_show_types;
if (!options.m_hide_name)
{
valobj->GetExpressionPath(s, qualify_cxx_base_classes);
s.PutCString(" =");
}
}
else if (!options.m_hide_name)
{
const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
s.Printf ("%s =", name_cstr);
}
if (!options.m_scope_already_checked && !valobj->IsInScope())
{
err_cstr = "out of scope";
}
}
std::string summary_str;
std::string value_str;
const char *val_cstr = NULL;
const char *sum_cstr = NULL;
TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
if (options.m_omit_summary_depth > 0)
entry = NULL;
bool is_nil = valobj->IsObjCNil();
if (err_cstr == NULL)
{
if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
{
valobj->GetValueAsCString(options.m_format,
value_str);
}
else
{
val_cstr = valobj->GetValueAsCString();
if (val_cstr)
value_str = val_cstr;
}
err_cstr = valobj->GetError().AsCString();
}
if (err_cstr)
{
s.Printf (" <%s>\n", err_cstr);
}
else
{
const bool is_ref = type_flags.Test (ClangASTType::eTypeIsReference);
if (print_valobj)
{
if (is_nil)
sum_cstr = "nil";
else if (options.m_omit_summary_depth == 0)
{
if (options.m_summary_sp)
{
valobj->GetSummaryAsCString(entry, summary_str);
sum_cstr = summary_str.c_str();
}
else
sum_cstr = valobj->GetSummaryAsCString();
}
// Make sure we have a value and make sure the summary didn't
// specify that the value should not be printed - and do not print
// the value if this thing is nil
// (but show the value if the user passes a format explicitly)
if (!is_nil && !value_str.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || sum_cstr == NULL) && !options.m_hide_value)
s.Printf(" %s", value_str.c_str());
if (sum_cstr)
s.Printf(" %s", sum_cstr);
// let's avoid the overly verbose no description error for a nil thing
if (options.m_use_objc && !is_nil)
{
if (!options.m_hide_value || !options.m_hide_name)
s.Printf(" ");
const char *object_desc = valobj->GetObjectDescription();
if (object_desc)
s.Printf("%s\n", object_desc);
else
s.Printf ("[no Objective-C description available]\n");
return;
}
}
if (curr_depth < options.m_max_depth)
{
// We will show children for all concrete types. We won't show
// pointer contents unless a pointer depth has been specified.
// We won't reference contents unless the reference is the
// root object (depth of zero).
bool print_children = true;
// Use a new temporary pointer depth in case we override the
// current pointer depth below...
uint32_t curr_ptr_depth = ptr_depth;
const bool is_ptr = type_flags.Test (ClangASTType::eTypeIsPointer);
if (is_ptr || is_ref)
{
// We have a pointer or reference whose value is an address.
// Make sure that address is not NULL
AddressType ptr_address_type;
if (valobj->GetPointerValue (&ptr_address_type) == 0)
print_children = false;
else if (is_ref && curr_depth == 0)
{
// If this is the root object (depth is zero) that we are showing
// and it is a reference, and no pointer depth has been supplied
// print out what it references. Don't do this at deeper depths
// otherwise we can end up with infinite recursion...
curr_ptr_depth = 1;
}
if (curr_ptr_depth == 0)
print_children = false;
}
if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
{
ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
ValueObject* synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
size_t num_children = synth_valobj->GetNumChildren();
bool print_dotdotdot = false;
if (num_children)
{
if (options.m_flat_output)
{
if (print_valobj)
s.EOL();
}
else
{
if (print_valobj)
s.PutCString(is_ref ? ": {\n" : " {\n");
s.IndentMore();
}
const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
if (num_children > max_num_children && !options.m_ignore_cap)
{
num_children = max_num_children;
print_dotdotdot = true;
}
ValueObject::DumpValueObjectOptions child_options(options);
child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
.SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
for (size_t idx=0; idx<num_children; ++idx)
{
ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
if (child_sp.get())
{
DumpValueObject_Impl (s,
child_sp.get(),
child_options,
(is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
curr_depth + 1);
}
}
if (!options.m_flat_output)
{
if (print_dotdotdot)
{
ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
Target *target = exe_ctx.GetTargetPtr();
if (target)
target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
s.Indent("...\n");
}
s.IndentLess();
s.Indent("}\n");
}
}
else if (has_children)
{
// Aggregate, no children...
if (print_valobj)
s.PutCString(" {}\n");
}
else
{
if (print_valobj)
s.EOL();
}
}
else
{
s.EOL();
}
}
else
{
if (has_children && print_valobj)
{
s.PutCString("{...}\n");
}
}
}
}
}
void
ValueObject::LogValueObject (Log *log,
ValueObject *valobj)
{
if (log && valobj)
return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
}
void
ValueObject::LogValueObject (Log *log,
ValueObject *valobj,
const DumpValueObjectOptions& options)
{
if (log && valobj)
{
StreamString s;
ValueObject::DumpValueObject (s, valobj, options);
if (s.GetSize())
log->PutCString(s.GetData());
}
}
void
ValueObject::DumpValueObject (Stream &s,
ValueObject *valobj)
{
if (!valobj)
return;
DumpValueObject_Impl(s,
valobj,
DumpValueObjectOptions::DefaultOptions(),
0,
0);
}
void
ValueObject::DumpValueObject (Stream &s,
ValueObject *valobj,
const DumpValueObjectOptions& options)
{
DumpValueObject_Impl(s,
valobj,
options,
options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
0 // current object depth is 0 since we are just starting
);
}
ValueObjectSP
ValueObject::CreateConstantValue (const ConstString &name)
{
ValueObjectSP valobj_sp;
if (UpdateValueIfNeeded(false) && m_error.Success())
{
ExecutionContext exe_ctx (GetExecutionContextRef());
DataExtractor data;
data.SetByteOrder (m_data.GetByteOrder());
data.SetAddressByteSize(m_data.GetAddressByteSize());
if (IsBitfield())
{
Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
}
else
m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
GetClangType(),
name,
data,
GetAddressOf());
}
if (!valobj_sp)
{
valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
}
return valobj_sp;
}
ValueObjectSP
ValueObject::Dereference (Error &error)
{
if (m_deref_valobj)
return m_deref_valobj->GetSP();
const bool is_pointer_type = IsPointerType();
if (is_pointer_type)
{
bool omit_empty_base_classes = true;
bool ignore_array_bounds = false;
std::string child_name_str;
uint32_t child_byte_size = 0;
int32_t child_byte_offset = 0;
uint32_t child_bitfield_bit_size = 0;
uint32_t child_bitfield_bit_offset = 0;
bool child_is_base_class = false;
bool child_is_deref_of_parent = false;
const bool transparent_pointers = false;
ClangASTType clang_type = GetClangType();
ClangASTType child_clang_type;
ExecutionContext exe_ctx (GetExecutionContextRef());
child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
GetName().GetCString(),
0,
transparent_pointers,
omit_empty_base_classes,
ignore_array_bounds,
child_name_str,
child_byte_size,
child_byte_offset,
child_bitfield_bit_size,
child_bitfield_bit_offset,
child_is_base_class,
child_is_deref_of_parent);
if (child_clang_type && child_byte_size)
{
ConstString child_name;
if (!child_name_str.empty())
child_name.SetCString (child_name_str.c_str());
m_deref_valobj = new ValueObjectChild (*this,
child_clang_type,
child_name,
child_byte_size,
child_byte_offset,
child_bitfield_bit_size,
child_bitfield_bit_offset,
child_is_base_class,
child_is_deref_of_parent,
eAddressTypeInvalid);
}
}
if (m_deref_valobj)
{
error.Clear();
return m_deref_valobj->GetSP();
}
else
{
StreamString strm;
GetExpressionPath(strm, true);
if (is_pointer_type)
error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
else
error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
return ValueObjectSP();
}
}
ValueObjectSP
ValueObject::AddressOf (Error &error)
{
if (m_addr_of_valobj_sp)
return m_addr_of_valobj_sp;
AddressType address_type = eAddressTypeInvalid;
const bool scalar_is_load_address = false;
addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
error.Clear();
if (addr != LLDB_INVALID_ADDRESS)
{
switch (address_type)
{
case eAddressTypeInvalid:
{
StreamString expr_path_strm;
GetExpressionPath(expr_path_strm, true);
error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
}
break;
case eAddressTypeFile:
case eAddressTypeLoad:
case eAddressTypeHost:
{
ClangASTType clang_type = GetClangType();
if (clang_type)
{
std::string name (1, '&');
name.append (m_name.AsCString(""));
ExecutionContext exe_ctx (GetExecutionContextRef());
m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
clang_type.GetPointerType(),
ConstString (name.c_str()),
addr,
eAddressTypeInvalid,
m_data.GetAddressByteSize());
}
}
break;
}
}
else
{
StreamString expr_path_strm;
GetExpressionPath(expr_path_strm, true);
error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
}
return m_addr_of_valobj_sp;
}
ValueObjectSP
ValueObject::Cast (const ClangASTType &clang_ast_type)
{
return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
}
ValueObjectSP
ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
{
ValueObjectSP valobj_sp;
AddressType address_type;
addr_t ptr_value = GetPointerValue (&address_type);
if (ptr_value != LLDB_INVALID_ADDRESS)
{
Address ptr_addr (ptr_value);
ExecutionContext exe_ctx (GetExecutionContextRef());
valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
name,
ptr_addr,
clang_ast_type);
}
return valobj_sp;
}
ValueObjectSP
ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
{
ValueObjectSP valobj_sp;
AddressType address_type;
addr_t ptr_value = GetPointerValue (&address_type);
if (ptr_value != LLDB_INVALID_ADDRESS)
{
Address ptr_addr (ptr_value);
ExecutionContext exe_ctx (GetExecutionContextRef());
valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
name,
ptr_addr,
type_sp);
}
return valobj_sp;
}
ValueObject::EvaluationPoint::EvaluationPoint () :
m_mod_id(),
m_exe_ctx_ref(),
m_needs_update (true),
m_first_update (true)
{
}
ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
m_mod_id(),
m_exe_ctx_ref(),
m_needs_update (true),
m_first_update (true)
{
ExecutionContext exe_ctx(exe_scope);
TargetSP target_sp (exe_ctx.GetTargetSP());
if (target_sp)
{
m_exe_ctx_ref.SetTargetSP (target_sp);
ProcessSP process_sp (exe_ctx.GetProcessSP());
if (!process_sp)
process_sp = target_sp->GetProcessSP();
if (process_sp)
{
m_mod_id = process_sp->GetModID();
m_exe_ctx_ref.SetProcessSP (process_sp);
ThreadSP thread_sp (exe_ctx.GetThreadSP());
if (!thread_sp)
{
if (use_selected)
thread_sp = process_sp->GetThreadList().GetSelectedThread();
}
if (thread_sp)
{
m_exe_ctx_ref.SetThreadSP(thread_sp);
StackFrameSP frame_sp (exe_ctx.GetFrameSP());
if (!frame_sp)
{
if (use_selected)
frame_sp = thread_sp->GetSelectedFrame();
}
if (frame_sp)
m_exe_ctx_ref.SetFrameSP(frame_sp);
}
}
}
}
ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
m_mod_id(),
m_exe_ctx_ref(rhs.m_exe_ctx_ref),
m_needs_update (true),
m_first_update (true)
{
}
ValueObject::EvaluationPoint::~EvaluationPoint ()
{
}
// This function checks the EvaluationPoint against the current process state. If the current
// state matches the evaluation point, or the evaluation point is already invalid, then we return
// false, meaning "no change". If the current state is different, we update our state, and return
// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
// future calls to NeedsUpdate will return true.
// exe_scope will be set to the current execution context scope.
bool
ValueObject::EvaluationPoint::SyncWithProcessState()
{
// Start with the target, if it is NULL, then we're obviously not going to get any further:
ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
if (exe_ctx.GetTargetPtr() == NULL)
return false;
// If we don't have a process nothing can change.
Process *process = exe_ctx.GetProcessPtr();
if (process == NULL)
return false;
// If our stop id is the current stop ID, nothing has changed:
ProcessModID current_mod_id = process->GetModID();
// If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
// In either case, we aren't going to be able to sync with the process state.
if (current_mod_id.GetStopID() == 0)
return false;
bool changed = false;
const bool was_valid = m_mod_id.IsValid();
if (was_valid)
{
if (m_mod_id == current_mod_id)
{
// Everything is already up to date in this object, no need to
// update the execution context scope.
changed = false;
}
else
{
m_mod_id = current_mod_id;
m_needs_update = true;
changed = true;
}
}
// Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
// That way we'll be sure to return a valid exe_scope.
// If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
if (m_exe_ctx_ref.HasThreadRef())
{
ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
if (thread_sp)
{
if (m_exe_ctx_ref.HasFrameRef())
{
StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
if (!frame_sp)
{
// We used to have a frame, but now it is gone
SetInvalid();
changed = was_valid;
}
}
}
else
{
// We used to have a thread, but now it is gone
SetInvalid();
changed = was_valid;
}
}
return changed;
}
void
ValueObject::EvaluationPoint::SetUpdated ()
{
ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
if (process_sp)
m_mod_id = process_sp->GetModID();
m_first_update = false;
m_needs_update = false;
}
void
ValueObject::ClearUserVisibleData(uint32_t clear_mask)
{
if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
m_value_str.clear();
if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
m_location_str.clear();
if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
{
m_summary_str.clear();
}
if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
m_object_desc_str.clear();
if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
{
if (m_synthetic_value)
m_synthetic_value = NULL;
}
}
SymbolContextScope *
ValueObject::GetSymbolContextScope()
{
if (m_parent)
{
if (!m_parent->IsPointerOrReferenceType())
return m_parent->GetSymbolContextScope();
}
return NULL;
}
lldb::ValueObjectSP
ValueObject::CreateValueObjectFromExpression (const char* name,
const char* expression,
const ExecutionContext& exe_ctx)
{
lldb::ValueObjectSP retval_sp;
lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
if (!target_sp)
return retval_sp;
if (!expression || !*expression)
return retval_sp;
target_sp->EvaluateExpression (expression,
exe_ctx.GetFrameSP().get(),
retval_sp);
if (retval_sp && name && *name)
retval_sp->SetName(ConstString(name));
return retval_sp;
}
lldb::ValueObjectSP
ValueObject::CreateValueObjectFromAddress (const char* name,
uint64_t address,
const ExecutionContext& exe_ctx,
ClangASTType type)
{
if (type)
{
ClangASTType pointer_type(type.GetPointerType());
if (pointer_type)
{
lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
pointer_type,
ConstString(name),
buffer,
lldb::endian::InlHostByteOrder(),
exe_ctx.GetAddressByteSize()));
if (ptr_result_valobj_sp)
{
ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
Error err;
ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
if (ptr_result_valobj_sp && name && *name)
ptr_result_valobj_sp->SetName(ConstString(name));
}
return ptr_result_valobj_sp;
}
}
return lldb::ValueObjectSP();
}
lldb::ValueObjectSP
ValueObject::CreateValueObjectFromData (const char* name,
DataExtractor& data,
const ExecutionContext& exe_ctx,
ClangASTType type)
{
lldb::ValueObjectSP new_value_sp;
new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
type,
ConstString(name),
data,
LLDB_INVALID_ADDRESS);
new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
if (new_value_sp && name && *name)
new_value_sp->SetName(ConstString(name));
return new_value_sp;
}
ModuleSP
ValueObject::GetModule ()
{
ValueObject* root(GetRoot());
if (root != this)
return root->GetModule();
return lldb::ModuleSP();
}
ValueObject*
ValueObject::GetRoot ()
{
if (m_root)
return m_root;
ValueObject* parent = m_parent;
if (!parent)
return (m_root = this);
while (parent->m_parent)
{
if (parent->m_root)
return (m_root = parent->m_root);
parent = parent->m_parent;
}
return (m_root = parent);
}
AddressType
ValueObject::GetAddressTypeOfChildren()
{
if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
{
ValueObject* root(GetRoot());
if (root != this)
return root->GetAddressTypeOfChildren();
}
return m_address_type_of_ptr_or_ref_children;
}
lldb::DynamicValueType
ValueObject::GetDynamicValueType ()
{
ValueObject* with_dv_info = this;
while (with_dv_info)
{
if (with_dv_info->HasDynamicValueTypeInfo())
return with_dv_info->GetDynamicValueTypeImpl();
with_dv_info = with_dv_info->m_parent;
}
return lldb::eNoDynamicValues;
}
lldb::Format
ValueObject::GetFormat () const
{
const ValueObject* with_fmt_info = this;
while (with_fmt_info)
{
if (with_fmt_info->m_format != lldb::eFormatDefault)
return with_fmt_info->m_format;
with_fmt_info = with_fmt_info->m_parent;
}
return m_format;
}
|