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
|
/* debug.c -- Handle generic debugging information.
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* This file implements a generic debugging format. We may eventually
have readers which convert different formats into this generic
format, and writers which write it out. The initial impetus for
this was writing a convertor from stabs to HP IEEE-695 debugging
format. */
#include <stdio.h>
#include <assert.h>
#include "bfd.h"
#include "bucomm.h"
#include "libiberty.h"
#include "debug.h"
/* Global information we keep for debugging. A pointer to this
structure is the debugging handle passed to all the routines. */
struct debug_handle
{
/* A linked list of compilation units. */
struct debug_unit *units;
/* The current compilation unit. */
struct debug_unit *current_unit;
/* The current source file. */
struct debug_file *current_file;
/* The current function. */
struct debug_function *current_function;
/* The current block. */
struct debug_block *current_block;
/* The current line number information for the current unit. */
struct debug_lineno *current_lineno;
/* Mark. This is used by debug_write. */
unsigned int mark;
/* Another mark used by debug_write. */
unsigned int class_mark;
};
/* Information we keep for a single compilation unit. */
struct debug_unit
{
/* The next compilation unit. */
struct debug_unit *next;
/* A list of files included in this compilation unit. The first
file is always the main one, and that is where the main file name
is stored. */
struct debug_file *files;
/* Line number information for this compilation unit. This is not
stored by function, because assembler code may have line number
information without function information. */
struct debug_lineno *linenos;
};
/* Information kept for a single source file. */
struct debug_file
{
/* The next source file in this compilation unit. */
struct debug_file *next;
/* The name of the source file. */
const char *filename;
/* Global functions, variables, types, etc. */
struct debug_namespace *globals;
};
/* A type. */
struct debug_type
{
/* Kind of type. */
enum debug_type_kind kind;
/* Size of type (0 if not known). */
unsigned int size;
/* Type which is a pointer to this type. */
debug_type pointer;
/* Tagged union with additional information about the type. */
union
{
/* DEBUG_KIND_INDIRECT. */
struct debug_indirect_type *kindirect;
/* DEBUG_KIND_INT. */
/* Whether the integer is unsigned. */
boolean kint;
/* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
DEBUG_KIND_UNION_CLASS. */
struct debug_class_type *kclass;
/* DEBUG_KIND_ENUM. */
struct debug_enum_type *kenum;
/* DEBUG_KIND_POINTER. */
struct debug_type *kpointer;
/* DEBUG_KIND_FUNCTION. */
struct debug_function_type *kfunction;
/* DEBUG_KIND_REFERENCE. */
struct debug_type *kreference;
/* DEBUG_KIND_RANGE. */
struct debug_range_type *krange;
/* DEBUG_KIND_ARRAY. */
struct debug_array_type *karray;
/* DEBUG_KIND_SET. */
struct debug_set_type *kset;
/* DEBUG_KIND_OFFSET. */
struct debug_offset_type *koffset;
/* DEBUG_KIND_METHOD. */
struct debug_method_type *kmethod;
/* DEBUG_KIND_CONST. */
struct debug_type *kconst;
/* DEBUG_KIND_VOLATILE. */
struct debug_type *kvolatile;
/* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
struct debug_named_type *knamed;
} u;
};
/* Information kept for an indirect type. */
struct debug_indirect_type
{
/* Slot where the final type will appear. */
debug_type *slot;
/* Tag. */
const char *tag;
};
/* Information kept for a struct, union, or class. */
struct debug_class_type
{
/* NULL terminated array of fields. */
debug_field *fields;
/* A mark field used to avoid recursively printing out structs. */
unsigned int mark;
/* The remaining fields are only used for DEBUG_KIND_CLASS and
DEBUG_KIND_UNION_CLASS. */
/* NULL terminated array of base classes. */
debug_baseclass *baseclasses;
/* NULL terminated array of methods. */
debug_method *methods;
/* The type of the class providing the virtual function table for
this class. This may point to the type itself. */
debug_type vptrbase;
};
/* Information kept for an enum. */
struct debug_enum_type
{
/* NULL terminated array of names. */
const char **names;
/* Array of corresponding values. */
bfd_signed_vma *values;
};
/* Information kept for a function. FIXME: We should be able to
record the parameter types. */
struct debug_function_type
{
/* Return type. */
debug_type return_type;
};
/* Information kept for a range. */
struct debug_range_type
{
/* Range base type. */
debug_type type;
/* Lower bound. */
bfd_signed_vma lower;
/* Upper bound. */
bfd_signed_vma upper;
};
/* Information kept for an array. */
struct debug_array_type
{
/* Element type. */
debug_type element_type;
/* Range type. */
debug_type range_type;
/* Lower bound. */
bfd_signed_vma lower;
/* Upper bound. */
bfd_signed_vma upper;
/* Whether this array is really a string. */
boolean stringp;
};
/* Information kept for a set. */
struct debug_set_type
{
/* Base type. */
debug_type type;
/* Whether this set is really a bitstring. */
boolean bitstringp;
};
/* Information kept for an offset type (a based pointer). */
struct debug_offset_type
{
/* The type the pointer is an offset from. */
debug_type base_type;
/* The type the pointer points to. */
debug_type target_type;
};
/* Information kept for a method type. */
struct debug_method_type
{
/* The return type. */
debug_type return_type;
/* The object type which this method is for. */
debug_type domain_type;
/* A NULL terminated array of argument types. */
debug_type *arg_types;
};
/* Information kept for a named type. */
struct debug_named_type
{
/* Name. */
struct debug_name *name;
/* Real type. */
debug_type type;
};
/* A field in a struct or union. */
struct debug_field
{
/* Name of the field. */
const char *name;
/* Type of the field. */
struct debug_type *type;
/* Visibility of the field. */
enum debug_visibility visibility;
/* Whether this is a static member. */
boolean static_member;
union
{
/* If static_member is false. */
struct
{
/* Bit position of the field in the struct. */
unsigned int bitpos;
/* Size of the field in bits. */
unsigned int bitsize;
} f;
/* If static_member is true. */
struct
{
const char *physname;
} s;
} u;
};
/* A base class for an object. */
struct debug_baseclass
{
/* Type of the base class. */
struct debug_type *type;
/* Bit position of the base class in the object. */
unsigned int bitpos;
/* Whether the base class is virtual. */
boolean virtual;
/* Visibility of the base class. */
enum debug_visibility visibility;
};
/* A method of an object. */
struct debug_method
{
/* The name of the method. */
const char *name;
/* A NULL terminated array of different types of variants. */
struct debug_method_variant **variants;
};
/* The variants of a method function of an object. These indicate
which method to run. */
struct debug_method_variant
{
/* The argument types of the function. */
const char *argtypes;
/* The type of the function. */
struct debug_type *type;
/* The visibility of the function. */
enum debug_visibility visibility;
/* Whether the function is const. */
boolean constp;
/* Whether the function is volatile. */
boolean volatilep;
/* The offset to the function in the virtual function table. */
bfd_vma voffset;
/* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
#define VOFFSET_STATIC_METHOD (1)
/* Context of a virtual method function. */
struct debug_type *context;
};
/* A variable. This is the information we keep for a variable object.
This has no name; a name is associated with a variable in a
debug_name structure. */
struct debug_variable
{
/* Kind of variable. */
enum debug_var_kind kind;
/* Type. */
debug_type type;
/* Value. The interpretation of the value depends upon kind. */
bfd_vma val;
};
/* A function. This has no name; a name is associated with a function
in a debug_name structure. */
struct debug_function
{
/* Return type. */
debug_type return_type;
/* Parameter information. */
struct debug_parameter *parameters;
/* Block information. The first structure on the list is the main
block of the function, and describes function local variables. */
struct debug_block *blocks;
};
/* A function parameter. */
struct debug_parameter
{
/* Next parameter. */
struct debug_parameter *next;
/* Name. */
const char *name;
/* Type. */
debug_type type;
/* Kind. */
enum debug_parm_kind kind;
/* Value (meaning depends upon kind). */
bfd_vma val;
};
/* A typed constant. */
struct debug_typed_constant
{
/* Type. */
debug_type type;
/* Value. FIXME: We may eventually need to support non-integral
values. */
bfd_vma val;
};
/* Information about a block within a function. */
struct debug_block
{
/* Next block with the same parent. */
struct debug_block *next;
/* Parent block. */
struct debug_block *parent;
/* List of child blocks. */
struct debug_block *children;
/* Start address of the block. */
bfd_vma start;
/* End address of the block. */
bfd_vma end;
/* Local variables. */
struct debug_namespace *locals;
};
/* Line number information we keep for a compilation unit. FIXME:
This structure is easy to create, but can be very space
inefficient. */
struct debug_lineno
{
/* More line number information for this block. */
struct debug_lineno *next;
/* Source file. */
struct debug_file *file;
/* Line numbers, terminated by a -1 or the end of the array. */
#define DEBUG_LINENO_COUNT 10
unsigned long linenos[DEBUG_LINENO_COUNT];
/* Addresses for the line numbers. */
bfd_vma addrs[DEBUG_LINENO_COUNT];
};
/* A namespace. This is a mapping from names to objects. FIXME: This
should be implemented as a hash table. */
struct debug_namespace
{
/* List of items in this namespace. */
struct debug_name *list;
/* Pointer to where the next item in this namespace should go. */
struct debug_name **tail;
};
/* Kinds of objects that appear in a namespace. */
enum debug_object_kind
{
/* A type. */
DEBUG_OBJECT_TYPE,
/* A tagged type (really a different sort of namespace). */
DEBUG_OBJECT_TAG,
/* A variable. */
DEBUG_OBJECT_VARIABLE,
/* A function. */
DEBUG_OBJECT_FUNCTION,
/* An integer constant. */
DEBUG_OBJECT_INT_CONSTANT,
/* A floating point constant. */
DEBUG_OBJECT_FLOAT_CONSTANT,
/* A typed constant. */
DEBUG_OBJECT_TYPED_CONSTANT
};
/* Linkage of an object that appears in a namespace. */
enum debug_object_linkage
{
/* Local variable. */
DEBUG_LINKAGE_AUTOMATIC,
/* Static--either file static or function static, depending upon the
namespace is. */
DEBUG_LINKAGE_STATIC,
/* Global. */
DEBUG_LINKAGE_GLOBAL,
/* No linkage. */
DEBUG_LINKAGE_NONE
};
/* A name in a namespace. */
struct debug_name
{
/* Next name in this namespace. */
struct debug_name *next;
/* Name. */
const char *name;
/* Mark. This is used by debug_write. */
unsigned int mark;
/* Kind of object. */
enum debug_object_kind kind;
/* Linkage of object. */
enum debug_object_linkage linkage;
/* Tagged union with additional information about the object. */
union
{
/* DEBUG_OBJECT_TYPE. */
struct debug_type *type;
/* DEBUG_OBJECT_TAG. */
struct debug_type *tag;
/* DEBUG_OBJECT_VARIABLE. */
struct debug_variable *variable;
/* DEBUG_OBJECT_FUNCTION. */
struct debug_function *function;
/* DEBUG_OBJECT_INT_CONSTANT. */
bfd_vma int_constant;
/* DEBUG_OBJECT_FLOAT_CONSTANT. */
double float_constant;
/* DEBUG_OBJECT_TYPED_CONSTANT. */
struct debug_typed_constant *typed_constant;
} u;
};
static void debug_error PARAMS ((const char *));
static struct debug_name *debug_add_to_namespace
PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
enum debug_object_kind, enum debug_object_linkage));
static struct debug_name *debug_add_to_current_namespace
PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
enum debug_object_linkage));
static struct debug_type *debug_make_type
PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
static boolean debug_write_name
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_name *));
static boolean debug_write_type
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_type *, struct debug_name *));
static boolean debug_write_class_type
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_type *, const char *));
static boolean debug_write_function
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
const char *, enum debug_object_linkage, struct debug_function *));
static boolean debug_write_block
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_block *));
/* Issue an error message. */
static void
debug_error (message)
const char *message;
{
fprintf (stderr, "%s\n", message);
}
/* Add an object to a namespace. */
static struct debug_name *
debug_add_to_namespace (info, nsp, name, kind, linkage)
struct debug_handle *info;
struct debug_namespace **nsp;
const char *name;
enum debug_object_kind kind;
enum debug_object_linkage linkage;
{
struct debug_name *n;
struct debug_namespace *ns;
n = (struct debug_name *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->name = name;
n->kind = kind;
n->linkage = linkage;
ns = *nsp;
if (ns == NULL)
{
ns = (struct debug_namespace *) xmalloc (sizeof *ns);
memset (ns, 0, sizeof *ns);
ns->tail = &ns->list;
*nsp = ns;
}
*ns->tail = n;
ns->tail = &n->next;
return n;
}
/* Add an object to the current namespace. */
static struct debug_name *
debug_add_to_current_namespace (info, name, kind, linkage)
struct debug_handle *info;
const char *name;
enum debug_object_kind kind;
enum debug_object_linkage linkage;
{
struct debug_namespace **nsp;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
debug_error ("debug_add_to_current_namespace: no current file");
return NULL;
}
if (info->current_block != NULL)
nsp = &info->current_block->locals;
else
nsp = &info->current_file->globals;
return debug_add_to_namespace (info, nsp, name, kind, linkage);
}
/* Return a handle for debugging information. */
PTR
debug_init ()
{
struct debug_handle *ret;
ret = (struct debug_handle *) xmalloc (sizeof *ret);
memset (ret, 0, sizeof *ret);
return (PTR) ret;
}
/* Set the source filename. This implicitly starts a new compilation
unit. */
boolean
debug_set_filename (handle, name)
PTR handle;
const char *name;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_file *nfile;
struct debug_unit *nunit;
if (name == NULL)
name = "";
nfile = (struct debug_file *) xmalloc (sizeof *nfile);
memset (nfile, 0, sizeof *nfile);
nfile->filename = name;
nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
memset (nunit, 0, sizeof *nunit);
nunit->files = nfile;
info->current_file = nfile;
if (info->current_unit != NULL)
info->current_unit->next = nunit;
else
{
assert (info->units == NULL);
info->units = nunit;
}
info->current_unit = nunit;
info->current_function = NULL;
info->current_block = NULL;
info->current_lineno = NULL;
return true;
}
/* Append a string to the source filename. */
boolean
debug_append_filename (handle, string)
PTR handle;
const char *string;
{
struct debug_handle *info = (struct debug_handle *) handle;
char *n;
if (string == NULL)
string = "";
if (info->current_unit == NULL)
{
debug_error ("debug_append_filename: no current file");
return false;
}
n = (char *) xmalloc (strlen (info->current_unit->files->filename)
+ strlen (string)
+ 1);
sprintf (n, "%s%s", info->current_unit->files->filename, string);
info->current_unit->files->filename = n;
return true;
}
/* Change source files to the given file name. This is used for
include files in a single compilation unit. */
boolean
debug_start_source (handle, name)
PTR handle;
const char *name;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_file *f, **pf;
if (name == NULL)
name = "";
if (info->current_unit == NULL)
{
debug_error ("debug_start_source: no debug_set_filename call");
return false;
}
for (f = info->current_unit->files; f != NULL; f = f->next)
{
if (f->filename[0] == name[0]
&& f->filename[1] == name[1]
&& strcmp (f->filename, name) == 0)
{
info->current_file = f;
return true;
}
}
f = (struct debug_file *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->filename = name;
for (pf = &info->current_file->next;
*pf != NULL;
pf = &(*pf)->next)
;
*pf = f;
info->current_file = f;
return true;
}
/* Record a function definition. This implicitly starts a function
block. The debug_type argument is the type of the return value.
The boolean indicates whether the function is globally visible.
The bfd_vma is the address of the start of the function. Currently
the parameter types are specified by calls to
debug_record_parameter. FIXME: There is no way to specify nested
functions. FIXME: I don't think there is any way to record where a
function ends. */
boolean
debug_record_function (handle, name, return_type, global, addr)
PTR handle;
const char *name;
debug_type return_type;
boolean global;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_function *f;
struct debug_block *b;
struct debug_name *n;
if (name == NULL)
name = "";
if (return_type == NULL)
return false;
if (info->current_unit == NULL)
{
debug_error ("debug_record_function: no debug_set_filename call");
return false;
}
f = (struct debug_function *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->return_type = return_type;
b = (struct debug_block *) xmalloc (sizeof *b);
memset (b, 0, sizeof *b);
b->start = addr;
b->end = (bfd_vma) -1;
f->blocks = b;
info->current_function = f;
info->current_block = b;
/* FIXME: If we could handle nested functions, this would be the
place: we would want to use a different namespace. */
n = debug_add_to_namespace (info,
&info->current_file->globals,
name,
DEBUG_OBJECT_FUNCTION,
(global
? DEBUG_LINKAGE_GLOBAL
: DEBUG_LINKAGE_STATIC));
if (n == NULL)
return false;
n->u.function = f;
return true;
}
/* Record a parameter for the current function. */
boolean
debug_record_parameter (handle, name, type, kind, val)
PTR handle;
const char *name;
debug_type type;
enum debug_parm_kind kind;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_parameter *p, **pp;
if (name == NULL || type == NULL)
return false;
if (info->current_unit == NULL
|| info->current_function == NULL)
{
debug_error ("debug_record_parameter: no current function");
return false;
}
p = (struct debug_parameter *) xmalloc (sizeof *p);
memset (p, 0, sizeof *p);
p->name = name;
p->type = type;
p->kind = kind;
p->val = val;
for (pp = &info->current_function->parameters;
*pp != NULL;
pp = &(*pp)->next)
;
*pp = p;
return true;
}
/* End a function. FIXME: This should handle function nesting. */
boolean
debug_end_function (handle, addr)
PTR handle;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
if (info->current_unit == NULL
|| info->current_block == NULL
|| info->current_function == NULL)
{
debug_error ("debug_end_function: no current function");
return false;
}
if (info->current_block->parent != NULL)
{
debug_error ("debug_end_function: some blocks were not closed");
return false;
}
info->current_block->end = addr;
info->current_function = NULL;
info->current_block = NULL;
return true;
}
/* Start a block in a function. All local information will be
recorded in this block, until the matching call to debug_end_block.
debug_start_block and debug_end_block may be nested. The bfd_vma
argument is the address at which this block starts. */
boolean
debug_start_block (handle, addr)
PTR handle;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_block *b, **pb;
/* We must always have a current block: debug_record_function sets
one up. */
if (info->current_unit == NULL
|| info->current_block == NULL)
{
debug_error ("debug_start_block: no current block");
return false;
}
b = (struct debug_block *) xmalloc (sizeof *b);
memset (b, 0, sizeof *b);
b->parent = info->current_block;
b->start = addr;
b->end = (bfd_vma) -1;
/* This new block is a child of the current block. */
for (pb = &info->current_block->children;
*pb != NULL;
pb = &(*pb)->next)
;
*pb = b;
info->current_block = b;
return true;
}
/* Finish a block in a function. This matches the call to
debug_start_block. The argument is the address at which this block
ends. */
boolean
debug_end_block (handle, addr)
PTR handle;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_block *parent;
if (info->current_unit == NULL
|| info->current_block == NULL)
{
debug_error ("debug_end_block: no current block");
return false;
}
parent = info->current_block->parent;
if (parent == NULL)
{
debug_error ("debug_end_block: attempt to close top level block");
return false;
}
info->current_block->end = addr;
info->current_block = parent;
return true;
}
/* Associate a line number in the current source file and function
with a given address. */
boolean
debug_record_line (handle, lineno, addr)
PTR handle;
unsigned long lineno;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_lineno *l;
unsigned int i;
if (info->current_unit == NULL)
{
debug_error ("debug_record_line: no current unit");
return false;
}
l = info->current_lineno;
if (l != NULL && l->file == info->current_file)
{
for (i = 0; i < DEBUG_LINENO_COUNT; i++)
{
if (l->linenos[i] == (unsigned long) -1)
{
l->linenos[i] = lineno;
l->addrs[i] = addr;
return true;
}
}
}
/* If we get here, then either 1) there is no current_lineno
structure, which means this is the first line number in this
compilation unit, 2) the current_lineno structure is for a
different file, or 3) the current_lineno structure is full.
Regardless, we want to allocate a new debug_lineno structure, put
it in the right place, and make it the new current_lineno
structure. */
l = (struct debug_lineno *) xmalloc (sizeof *l);
memset (l, 0, sizeof *l);
l->file = info->current_file;
l->linenos[0] = lineno;
l->addrs[0] = addr;
for (i = 1; i < DEBUG_LINENO_COUNT; i++)
l->linenos[i] = (unsigned long) -1;
if (info->current_lineno != NULL)
info->current_lineno->next = l;
else
info->current_unit->linenos = l;
info->current_lineno = l;
return true;
}
/* Start a named common block. This is a block of variables that may
move in memory. */
boolean
debug_start_common_block (handle, name)
PTR handle;
const char *name;
{
/* FIXME */
debug_error ("debug_start_common_block: not implemented");
return false;
}
/* End a named common block. */
boolean
debug_end_common_block (handle, name)
PTR handle;
const char *name;
{
/* FIXME */
debug_error ("debug_end_common_block: not implemented");
return false;
}
/* Record a named integer constant. */
boolean
debug_record_int_const (handle, name, val)
PTR handle;
const char *name;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_name *n;
if (name == NULL)
return false;
n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
DEBUG_LINKAGE_NONE);
if (n == NULL)
return false;
n->u.int_constant = val;
return true;
}
/* Record a named floating point constant. */
boolean
debug_record_float_const (handle, name, val)
PTR handle;
const char *name;
double val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_name *n;
if (name == NULL)
return false;
n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
DEBUG_LINKAGE_NONE);
if (n == NULL)
return false;
n->u.float_constant = val;
return true;
}
/* Record a typed constant with an integral value. */
boolean
debug_record_typed_const (handle, name, type, val)
PTR handle;
const char *name;
debug_type type;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_name *n;
struct debug_typed_constant *tc;
if (name == NULL || type == NULL)
return false;
n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
DEBUG_LINKAGE_NONE);
if (n == NULL)
return false;
tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
memset (tc, 0, sizeof *tc);
tc->type = type;
tc->val = val;
n->u.typed_constant = tc;
return true;
}
/* Record a label. */
boolean
debug_record_label (handle, name, type, addr)
PTR handle;
const char *name;
debug_type type;
bfd_vma addr;
{
/* FIXME. */
debug_error ("debug_record_label not implemented");
return false;
}
/* Record a variable. */
boolean
debug_record_variable (handle, name, type, kind, val)
PTR handle;
const char *name;
debug_type type;
enum debug_var_kind kind;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_namespace **nsp;
enum debug_object_linkage linkage;
struct debug_name *n;
struct debug_variable *v;
if (name == NULL || type == NULL)
return false;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
debug_error ("debug_record_variable: no current file");
return false;
}
if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
{
nsp = &info->current_file->globals;
if (kind == DEBUG_GLOBAL)
linkage = DEBUG_LINKAGE_GLOBAL;
else
linkage = DEBUG_LINKAGE_STATIC;
}
else
{
if (info->current_block == NULL)
{
debug_error ("debug_record_variable: no current block");
return false;
}
nsp = &info->current_block->locals;
linkage = DEBUG_LINKAGE_AUTOMATIC;
}
n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
if (n == NULL)
return false;
v = (struct debug_variable *) xmalloc (sizeof *v);
memset (v, 0, sizeof *v);
v->kind = kind;
v->type = type;
v->val = val;
n->u.variable = v;
return true;
}
/* Make a type with a given kind and size. */
/*ARGSUSED*/
static struct debug_type *
debug_make_type (info, kind, size)
struct debug_handle *info;
enum debug_type_kind kind;
unsigned int size;
{
struct debug_type *t;
t = (struct debug_type *) xmalloc (sizeof *t);
memset (t, 0, sizeof *t);
t->kind = kind;
t->size = size;
return t;
}
/* Make an indirect type which may be used as a placeholder for a type
which is referenced before it is defined. */
debug_type
debug_make_indirect_type (handle, slot, tag)
PTR handle;
debug_type *slot;
const char *tag;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_indirect_type *i;
t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
i = (struct debug_indirect_type *) xmalloc (sizeof *i);
memset (i, 0, sizeof *i);
i->slot = slot;
i->tag = tag;
t->u.kindirect = i;
return t;
}
/* Make a void type. There is only one of these. */
debug_type
debug_make_void_type (handle)
PTR handle;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_VOID, 0);
}
/* Make an integer type of a given size. The boolean argument is true
if the integer is unsigned. */
debug_type
debug_make_int_type (handle, size, unsignedp)
PTR handle;
unsigned int size;
boolean unsignedp;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
t = debug_make_type (info, DEBUG_KIND_INT, size);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kint = unsignedp;
return t;
}
/* Make a floating point type of a given size. FIXME: On some
platforms, like an Alpha, you probably need to be able to specify
the format. */
debug_type
debug_make_float_type (handle, size)
PTR handle;
unsigned int size;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_FLOAT, size);
}
/* Make a boolean type of a given size. */
debug_type
debug_make_bool_type (handle, size)
PTR handle;
unsigned int size;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_BOOL, size);
}
/* Make a complex type of a given size. */
debug_type
debug_make_complex_type (handle, size)
PTR handle;
unsigned int size;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
}
/* Make a structure type. The second argument is true for a struct,
false for a union. The third argument is the size of the struct.
The fourth argument is a NULL terminated array of fields. */
debug_type
debug_make_struct_type (handle, structp, size, fields)
PTR handle;
boolean structp;
bfd_vma size;
debug_field *fields;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_class_type *c;
t = debug_make_type (info,
structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
size);
if (t == NULL)
return DEBUG_TYPE_NULL;
c = (struct debug_class_type *) xmalloc (sizeof *c);
memset (c, 0, sizeof *c);
c->fields = fields;
t->u.kclass = c;
return t;
}
/* Make an object type. The first three arguments after the handle
are the same as for debug_make_struct_type. The next arguments are
a NULL terminated array of base classes, a NULL terminated array of
methods, the type of the object holding the virtual function table
if it is not this object, and a boolean which is true if this
object has its own virtual function table. */
debug_type
debug_make_object_type (handle, structp, size, fields, baseclasses,
methods, vptrbase, ownvptr)
PTR handle;
boolean structp;
bfd_vma size;
debug_field *fields;
debug_baseclass *baseclasses;
debug_method *methods;
debug_type vptrbase;
boolean ownvptr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_class_type *c;
t = debug_make_type (info,
structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
size);
if (t == NULL)
return DEBUG_TYPE_NULL;
c = (struct debug_class_type *) xmalloc (sizeof *c);
memset (c, 0, sizeof *c);
c->fields = fields;
c->baseclasses = baseclasses;
c->methods = methods;
if (ownvptr)
c->vptrbase = t;
else
c->vptrbase = vptrbase;
t->u.kclass = c;
return t;
}
/* Make an enumeration type. The arguments are a null terminated
array of strings, and an array of corresponding values. */
debug_type
debug_make_enum_type (handle, names, values)
PTR handle;
const char **names;
bfd_signed_vma *values;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_enum_type *e;
t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
e = (struct debug_enum_type *) xmalloc (sizeof *e);
memset (e, 0, sizeof *e);
e->names = names;
e->values = values;
t->u.kenum = e;
return t;
}
/* Make a pointer to a given type. */
debug_type
debug_make_pointer_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
if (type->pointer != DEBUG_TYPE_NULL)
return type->pointer;
t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kpointer = type;
type->pointer = t;
return t;
}
/* Make a function returning a given type. FIXME: We should be able
to record the parameter types. */
debug_type
debug_make_function_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_function_type *f;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
f = (struct debug_function_type *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->return_type = type;
t->u.kfunction = f;
return t;
}
/* Make a reference to a given type. */
debug_type
debug_make_reference_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kreference = type;
return t;
}
/* Make a range of a given type from a lower to an upper bound. */
debug_type
debug_make_range_type (handle, type, lower, upper)
PTR handle;
debug_type type;
bfd_signed_vma lower;
bfd_signed_vma upper;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_range_type *r;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
r = (struct debug_range_type *) xmalloc (sizeof *r);
memset (r, 0, sizeof *r);
r->type = type;
r->lower = lower;
r->upper = upper;
t->u.krange = r;
return t;
}
/* Make an array type. The second argument is the type of an element
of the array. The third argument is the type of a range of the
array. The fourth and fifth argument are the lower and upper
bounds, respectively. The sixth argument is true if this array is
actually a string, as in C. */
debug_type
debug_make_array_type (handle, element_type, range_type, lower, upper,
stringp)
PTR handle;
debug_type element_type;
debug_type range_type;
bfd_signed_vma lower;
bfd_signed_vma upper;
boolean stringp;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_array_type *a;
if (element_type == NULL || range_type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
a = (struct debug_array_type *) xmalloc (sizeof *a);
memset (a, 0, sizeof *a);
a->element_type = element_type;
a->range_type = range_type;
a->lower = lower;
a->upper = upper;
a->stringp = stringp;
t->u.karray = a;
return t;
}
/* Make a set of a given type. For example, a Pascal set type. The
boolean argument is true if this set is actually a bitstring, as in
CHILL. */
debug_type
debug_make_set_type (handle, type, bitstringp)
PTR handle;
debug_type type;
boolean bitstringp;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_set_type *s;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_SET, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
s = (struct debug_set_type *) xmalloc (sizeof *s);
memset (s, 0, sizeof *s);
s->type = type;
s->bitstringp = bitstringp;
t->u.kset = s;
return t;
}
/* Make a type for a pointer which is relative to an object. The
second argument is the type of the object to which the pointer is
relative. The third argument is the type that the pointer points
to. */
debug_type
debug_make_offset_type (handle, base_type, target_type)
PTR handle;
debug_type base_type;
debug_type target_type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_offset_type *o;
if (base_type == NULL || target_type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
o = (struct debug_offset_type *) xmalloc (sizeof *o);
memset (o, 0, sizeof *o);
o->base_type = base_type;
o->target_type = target_type;
t->u.koffset = o;
return t;
}
/* Make a type for a method function. The second argument is the
return type, the third argument is the domain, and the fourth
argument is a NULL terminated array of argument types. */
debug_type
debug_make_method_type (handle, return_type, domain_type, arg_types)
PTR handle;
debug_type return_type;
debug_type domain_type;
debug_type *arg_types;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_method_type *m;
if (return_type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
m = (struct debug_method_type *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->return_type = return_type;
m->domain_type = domain_type;
m->arg_types = arg_types;
t->u.kmethod = m;
return t;
}
/* Make a const qualified version of a given type. */
debug_type
debug_make_const_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_CONST, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kconst = type;
return t;
}
/* Make a volatile qualified version of a given type. */
debug_type
debug_make_volatile_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kvolatile = type;
return t;
}
/* Make an undefined tagged type. For example, a struct which has
been mentioned, but not defined. */
debug_type
debug_make_undefined_tagged_type (handle, name, kind)
PTR handle;
const char *name;
enum debug_type_kind kind;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (name == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, kind, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
return debug_tag_type (handle, name, t);
}
/* Make a base class for an object. The second argument is the base
class type. The third argument is the bit position of this base
class in the object (always 0 unless doing multiple inheritance).
The fourth argument is whether this is a virtual class. The fifth
argument is the visibility of the base class. */
/*ARGSUSED*/
debug_baseclass
debug_make_baseclass (handle, type, bitpos, virtual, visibility)
PTR handle;
debug_type type;
bfd_vma bitpos;
boolean virtual;
enum debug_visibility visibility;
{
struct debug_baseclass *b;
b = (struct debug_baseclass *) xmalloc (sizeof *b);
memset (b, 0, sizeof *b);
b->type = type;
b->bitpos = bitpos;
b->virtual = virtual;
b->visibility = visibility;
return b;
}
/* Make a field for a struct. The second argument is the name. The
third argument is the type of the field. The fourth argument is
the bit position of the field. The fifth argument is the size of
the field (it may be zero). The sixth argument is the visibility
of the field. */
/*ARGSUSED*/
debug_field
debug_make_field (handle, name, type, bitpos, bitsize, visibility)
PTR handle;
const char *name;
debug_type type;
bfd_vma bitpos;
bfd_vma bitsize;
enum debug_visibility visibility;
{
struct debug_field *f;
f = (struct debug_field *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->name = name;
f->type = type;
f->static_member = false;
f->u.f.bitpos = bitpos;
f->u.f.bitsize = bitsize;
f->visibility = visibility;
return f;
}
/* Make a static member of an object. The second argument is the
name. The third argument is the type of the member. The fourth
argument is the physical name of the member (i.e., the name as a
global variable). The fifth argument is the visibility of the
member. */
/*ARGSUSED*/
debug_field
debug_make_static_member (handle, name, type, physname, visibility)
PTR handle;
const char *name;
debug_type type;
const char *physname;
enum debug_visibility visibility;
{
struct debug_field *f;
f = (struct debug_field *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->name = name;
f->type = type;
f->static_member = true;
f->u.s.physname = physname;
f->visibility = visibility;
return f;
}
/* Make a method. The second argument is the name, and the third
argument is a NULL terminated array of method variants. */
/*ARGSUSED*/
debug_method
debug_make_method (handle, name, variants)
PTR handle;
const char *name;
debug_method_variant *variants;
{
struct debug_method *m;
m = (struct debug_method *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->name = name;
m->variants = variants;
return m;
}
/* Make a method argument. The second argument is the real name of
the function. The third argument is the type of the function. The
fourth argument is the visibility. The fifth argument is whether
this is a const function. The sixth argument is whether this is a
volatile function. The seventh argument is the offset in the
virtual function table, if any. The eighth argument is the virtual
function context. FIXME: Are the const and volatile arguments
necessary? Could we just use debug_make_const_type? */
/*ARGSUSED*/
debug_method_variant
debug_make_method_variant (handle, argtypes, type, visibility, constp,
volatilep, voffset, context)
PTR handle;
const char *argtypes;
debug_type type;
enum debug_visibility visibility;
boolean constp;
boolean volatilep;
bfd_vma voffset;
debug_type context;
{
struct debug_method_variant *m;
m = (struct debug_method_variant *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->argtypes = argtypes;
m->type = type;
m->visibility = visibility;
m->constp = constp;
m->volatilep = volatilep;
m->voffset = voffset;
m->context = context;
return m;
}
/* Make a static method argument. The arguments are the same as for
debug_make_method_variant, except that the last two are omitted
since a static method can not also be virtual. */
debug_method_variant
debug_make_static_method_variant (handle, argtypes, type, visibility,
constp, volatilep)
PTR handle;
const char *argtypes;
debug_type type;
enum debug_visibility visibility;
boolean constp;
boolean volatilep;
{
struct debug_method_variant *m;
m = (struct debug_method_variant *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->argtypes = argtypes;
m->type = type;
m->visibility = visibility;
m->constp = constp;
m->volatilep = volatilep;
m->voffset = VOFFSET_STATIC_METHOD;
return m;
}
/* Name a type. */
debug_type
debug_name_type (handle, name, type)
PTR handle;
const char *name;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_named_type *n;
struct debug_name *nm;
if (name == NULL || type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
n = (struct debug_named_type *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->type = type;
t->u.knamed = n;
/* We also need to add the name to the current namespace. */
nm = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPE,
DEBUG_LINKAGE_NONE);
if (nm == NULL)
return false;
nm->u.type = t;
n->name = nm;
return t;
}
/* Tag a type. */
debug_type
debug_tag_type (handle, name, type)
PTR handle;
const char *name;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_named_type *n;
struct debug_name *nm;
if (name == NULL || type == NULL)
return DEBUG_TYPE_NULL;
if (info->current_file == NULL)
{
debug_error ("debug_tag_type: no current file");
return DEBUG_TYPE_NULL;
}
if (type->kind == DEBUG_KIND_TAGGED)
{
if (strcmp (type->u.knamed->name->name, name) == 0)
return type;
debug_error ("debug_tag_type: extra tag attempted");
return DEBUG_TYPE_NULL;
}
t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
n = (struct debug_named_type *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->type = type;
t->u.knamed = n;
/* We keep a global namespace of tags for each compilation unit. I
don't know if that is the right thing to do. */
nm = debug_add_to_namespace (info, &info->current_file->globals, name,
DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
if (nm == NULL)
return false;
nm->u.tag = t;
n->name = nm;
return t;
}
/* Record the size of a given type. */
/*ARGSUSED*/
boolean
debug_record_type_size (handle, type, size)
PTR handle;
debug_type type;
unsigned int size;
{
if (type->size != 0 && type->size != size)
fprintf (stderr, "Warning: changing type size from %d to %d\n",
type->size, size);
type->size = size;
return true;
}
/* Find a tagged type. */
debug_type
debug_find_tagged_type (handle, name, kind)
PTR handle;
const char *name;
enum debug_type_kind kind;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_unit *u;
/* We search the globals of all the compilation units. I don't know
if this is correct or not. It would be easy to change. */
for (u = info->units; u != NULL; u = u->next)
{
struct debug_file *f;
for (f = u->files; f != NULL; f = f->next)
{
struct debug_name *n;
if (f->globals != NULL)
{
for (n = f->globals->list; n != NULL; n = n->next)
{
if (n->kind == DEBUG_OBJECT_TAG
&& (kind == DEBUG_KIND_VOID
|| n->u.tag->kind == kind)
&& n->name[0] == name[0]
&& strcmp (n->name, name) == 0)
return n->u.tag;
}
}
}
}
return DEBUG_TYPE_NULL;
}
/* Get the name of a type. */
/*ARGSUSED*/
const char *
debug_get_type_name (handle, type)
PTR handle;
debug_type type;
{
if (type->kind == DEBUG_KIND_INDIRECT)
{
if (*type->u.kindirect->slot != NULL)
return debug_get_type_name (handle, *type->u.kindirect->slot);
return type->u.kindirect->tag;
}
if (type->kind == DEBUG_KIND_NAMED
|| type->kind == DEBUG_KIND_TAGGED)
return type->u.knamed->name->name;
return NULL;
}
/* Write out the debugging information. This is given a handle to
debugging information, and a set of function pointers to call. */
boolean
debug_write (handle, fns, fhandle)
PTR handle;
const struct debug_write_fns *fns;
PTR fhandle;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_unit *u;
/* We use a mark to tell whether we have already written out a
particular name. We use an integer, so that we don't have to
clear the mark fields if we happen to write out the same
information more than once. */
++info->mark;
for (u = info->units; u != NULL; u = u->next)
{
struct debug_file *f;
boolean first_file;
struct debug_lineno *l;
if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
return false;
first_file = true;
for (f = u->files; f != NULL; f = f->next)
{
struct debug_name *n;
if (first_file)
first_file = false;
else
{
if (! (*fns->start_source) (fhandle, f->filename))
return false;
}
if (f->globals != NULL)
{
for (n = f->globals->list; n != NULL; n = n->next)
{
if (! debug_write_name (info, fns, fhandle, n))
return false;
}
}
}
for (l = u->linenos; l != NULL; l = l->next)
{
unsigned int i;
for (i = 0; i < DEBUG_LINENO_COUNT; i++)
{
if (l->linenos[i] == (unsigned long) -1)
break;
if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
l->addrs[i]))
return false;
}
}
}
return true;
}
/* Write out an element in a namespace. */
static boolean
debug_write_name (info, fns, fhandle, n)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_name *n;
{
/* The class_mark field is used to prevent recursively outputting a
struct or class. */
++info->class_mark;
switch (n->kind)
{
case DEBUG_OBJECT_TYPE:
if (! debug_write_type (info, fns, fhandle, n->u.type, n)
|| ! (*fns->typdef) (fhandle, n->name))
return false;
return true;
case DEBUG_OBJECT_TAG:
if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
return false;
return (*fns->tag) (fhandle, n->name);
case DEBUG_OBJECT_VARIABLE:
if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
(struct debug_name *) NULL))
return false;
return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
n->u.variable->val);
case DEBUG_OBJECT_FUNCTION:
return debug_write_function (info, fns, fhandle, n->name,
n->linkage, n->u.function);
case DEBUG_OBJECT_INT_CONSTANT:
return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
case DEBUG_OBJECT_FLOAT_CONSTANT:
return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
case DEBUG_OBJECT_TYPED_CONSTANT:
if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
(struct debug_name *) NULL))
return false;
return (*fns->typed_constant) (fhandle, n->name,
n->u.typed_constant->val);
default:
abort ();
return false;
}
/*NOTREACHED*/
}
/* Write out a type. If the type is DEBUG_KIND_NAMED or
DEBUG_KIND_TAGGED, then the name argument is the name for which we
are about to call typedef or tag. If the type is anything else,
then the name argument is a tag from a DEBUG_KIND_TAGGED type which
points to this one. */
static boolean
debug_write_type (info, fns, fhandle, type, name)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_type *type;
struct debug_name *name;
{
unsigned int i;
const char *tag;
/* If we have a name for this type, just output it. We only output
typedef names after they have been defined. We output type tags
whenever we are not actually defining them. */
if ((type->kind == DEBUG_KIND_NAMED
|| type->kind == DEBUG_KIND_TAGGED)
&& (type->u.knamed->name->mark == info->mark
|| (type->kind == DEBUG_KIND_TAGGED
&& type->u.knamed->name != name)))
{
if (type->kind == DEBUG_KIND_NAMED)
return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
else
return (*fns->tag_type) (fhandle, type->u.knamed->name->name,
type->u.knamed->type->kind);
}
/* Mark the name after we have already looked for a known name, so
that we don't just define a type in terms of itself. We need to
mark the name here so that a struct containing a pointer to
itself will work. */
if (name != NULL)
name->mark = info->mark;
tag = NULL;
if (name != NULL
&& type->kind != DEBUG_KIND_NAMED
&& type->kind != DEBUG_KIND_TAGGED)
{
assert (name->kind == DEBUG_OBJECT_TAG);
tag = name->name;
}
switch (type->kind)
{
case DEBUG_KIND_INDIRECT:
if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
return (*fns->empty_type) (fhandle);
return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
(struct debug_name *) NULL);
case DEBUG_KIND_VOID:
return (*fns->void_type) (fhandle);
case DEBUG_KIND_INT:
return (*fns->int_type) (fhandle, type->size, type->u.kint);
case DEBUG_KIND_FLOAT:
return (*fns->float_type) (fhandle, type->size);
case DEBUG_KIND_COMPLEX:
return (*fns->complex_type) (fhandle, type->size);
case DEBUG_KIND_BOOL:
return (*fns->bool_type) (fhandle, type->size);
case DEBUG_KIND_STRUCT:
case DEBUG_KIND_UNION:
if (info->class_mark == type->u.kclass->mark)
{
/* We are currently outputting this struct. I don't know if
this can happen, but it can happen for a class. */
return (*fns->tag_type) (fhandle, "?defining?", type->kind);
}
type->u.kclass->mark = info->class_mark;
if (! (*fns->start_struct_type) (fhandle, tag,
type->kind == DEBUG_KIND_STRUCT,
type->size))
return false;
if (type->u.kclass->fields != NULL)
{
for (i = 0; type->u.kclass->fields[i] != NULL; i++)
{
struct debug_field *f;
f = type->u.kclass->fields[i];
if (! debug_write_type (info, fns, fhandle, f->type,
(struct debug_name *) NULL)
|| ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
f->u.f.bitsize, f->visibility))
return false;
}
}
return (*fns->end_struct_type) (fhandle);
case DEBUG_KIND_CLASS:
case DEBUG_KIND_UNION_CLASS:
return debug_write_class_type (info, fns, fhandle, type, tag);
case DEBUG_KIND_ENUM:
return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
type->u.kenum->values);
case DEBUG_KIND_POINTER:
if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
(struct debug_name *) NULL))
return false;
return (*fns->pointer_type) (fhandle);
case DEBUG_KIND_FUNCTION:
if (! debug_write_type (info, fns, fhandle,
type->u.kfunction->return_type,
(struct debug_name *) NULL))
return false;
return (*fns->function_type) (fhandle);
case DEBUG_KIND_REFERENCE:
if (! debug_write_type (info, fns, fhandle, type->u.kreference,
(struct debug_name *) NULL))
return false;
return (*fns->reference_type) (fhandle);
case DEBUG_KIND_RANGE:
if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
(struct debug_name *) NULL))
return false;
return (*fns->range_type) (fhandle, type->u.krange->lower,
type->u.krange->upper);
case DEBUG_KIND_ARRAY:
if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
(struct debug_name *) NULL)
|| ! debug_write_type (info, fns, fhandle,
type->u.karray->range_type,
(struct debug_name *) NULL))
return false;
return (*fns->array_type) (fhandle, type->u.karray->lower,
type->u.karray->upper,
type->u.karray->stringp);
case DEBUG_KIND_SET:
if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
(struct debug_name *) NULL))
return false;
return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
case DEBUG_KIND_OFFSET:
if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
(struct debug_name *) NULL)
|| ! debug_write_type (info, fns, fhandle,
type->u.koffset->target_type,
(struct debug_name *) NULL))
return false;
return (*fns->offset_type) (fhandle);
case DEBUG_KIND_METHOD:
if (! debug_write_type (info, fns, fhandle,
type->u.kmethod->return_type,
(struct debug_name *) NULL))
return false;
if (type->u.kmethod->arg_types == NULL)
i = -1;
else
{
for (i = 0; type->u.kmethod->arg_types[i] != NULL; i++)
{
if (! debug_write_type (info, fns, fhandle,
type->u.kmethod->arg_types[i],
(struct debug_name *) NULL))
return false;
}
}
if (type->u.kmethod->domain_type != NULL)
{
if (! debug_write_type (info, fns, fhandle,
type->u.kmethod->domain_type,
(struct debug_name *) NULL))
return false;
}
return (*fns->method_type) (fhandle,
type->u.kmethod->domain_type != NULL,
i);
case DEBUG_KIND_CONST:
if (! debug_write_type (info, fns, fhandle, type->u.kconst,
(struct debug_name *) NULL))
return false;
return (*fns->const_type) (fhandle);
case DEBUG_KIND_VOLATILE:
if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
(struct debug_name *) NULL))
return false;
return (*fns->volatile_type) (fhandle);
case DEBUG_KIND_NAMED:
return debug_write_type (info, fns, fhandle, type->u.knamed->type,
(struct debug_name *) NULL);
case DEBUG_KIND_TAGGED:
return debug_write_type (info, fns, fhandle, type->u.knamed->type,
type->u.knamed->name);
default:
abort ();
return false;
}
}
/* Write out a class type. */
static boolean
debug_write_class_type (info, fns, fhandle, type, tag)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_type *type;
const char *tag;
{
unsigned int i;
if (info->class_mark == type->u.kclass->mark)
{
/* We are currently outputting this class. This can happen when
there are methods for an anonymous class. */
return (*fns->tag_type) (fhandle, "?defining?", type->kind);
}
type->u.kclass->mark = info->class_mark;
if (type->u.kclass->vptrbase != NULL
&& type->u.kclass->vptrbase != type)
{
if (! debug_write_type (info, fns, fhandle, type->u.kclass->vptrbase,
(struct debug_name *) NULL))
return false;
}
if (! (*fns->start_class_type) (fhandle, tag,
type->kind == DEBUG_KIND_CLASS,
type->size,
type->u.kclass->vptrbase != NULL,
type->u.kclass->vptrbase == type))
return false;
if (type->u.kclass->fields != NULL)
{
for (i = 0; type->u.kclass->fields[i] != NULL; i++)
{
struct debug_field *f;
f = type->u.kclass->fields[i];
if (! debug_write_type (info, fns, fhandle, f->type,
(struct debug_name *) NULL))
return false;
if (f->static_member)
{
if (! (*fns->class_static_member) (fhandle, f->name,
f->u.s.physname,
f->visibility))
return false;
}
else
{
if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
f->u.f.bitsize, f->visibility))
return false;
}
}
}
if (type->u.kclass->baseclasses != NULL)
{
for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
{
struct debug_baseclass *b;
b = type->u.kclass->baseclasses[i];
if (! debug_write_type (info, fns, fhandle, b->type,
(struct debug_name *) NULL))
return false;
if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
b->visibility))
return false;
}
}
if (type->u.kclass->methods != NULL)
{
for (i = 0; type->u.kclass->methods[i] != NULL; i++)
{
struct debug_method *m;
unsigned int j;
m = type->u.kclass->methods[i];
if (! (*fns->class_start_method) (fhandle, m->name))
return false;
for (j = 0; m->variants[j] != NULL; j++)
{
struct debug_method_variant *v;
v = m->variants[j];
if (v->context != NULL)
{
if (! debug_write_type (info, fns, fhandle, v->context,
(struct debug_name *) NULL))
return false;
}
if (! debug_write_type (info, fns, fhandle, v->type,
(struct debug_name *) NULL))
return false;
if (v->voffset != VOFFSET_STATIC_METHOD)
{
if (! (*fns->class_method_variant) (fhandle, v->argtypes,
v->visibility,
v->constp, v->volatilep,
v->voffset,
v->context != NULL))
return false;
}
else
{
if (! (*fns->class_static_method_variant) (fhandle,
v->argtypes,
v->visibility,
v->constp,
v->volatilep))
return false;
}
}
if (! (*fns->class_end_method) (fhandle))
return false;
}
}
return (*fns->end_class_type) (fhandle);
}
/* Write out information for a function. */
static boolean
debug_write_function (info, fns, fhandle, name, linkage, function)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
const char *name;
enum debug_object_linkage linkage;
struct debug_function *function;
{
struct debug_parameter *p;
struct debug_block *b;
if (! debug_write_type (info, fns, fhandle, function->return_type,
(struct debug_name *) NULL))
return false;
if (! (*fns->start_function) (fhandle, name,
linkage == DEBUG_LINKAGE_GLOBAL))
return false;
for (p = function->parameters; p != NULL; p = p->next)
{
if (! debug_write_type (info, fns, fhandle, p->type,
(struct debug_name *) NULL)
|| ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
return false;
}
for (b = function->blocks; b != NULL; b = b->next)
{
if (! debug_write_block (info, fns, fhandle, b))
return false;
}
return (*fns->end_function) (fhandle);
}
/* Write out information for a block. */
static boolean
debug_write_block (info, fns, fhandle, block)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_block *block;
{
struct debug_name *n;
struct debug_block *b;
if (! (*fns->start_block) (fhandle, block->start))
return false;
if (block->locals != NULL)
{
for (n = block->locals->list; n != NULL; n = n->next)
{
if (! debug_write_name (info, fns, fhandle, n))
return false;
}
}
for (b = block->children; b != NULL; b = b->next)
{
if (! debug_write_block (info, fns, fhandle, b))
return false;
}
return (*fns->end_block) (fhandle, block->end);
}
|