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
|
/* Support routines for decoding "stabs" debugging information format.
Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
Free Software Foundation, Inc.
This file is part of GDB.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Support routines for reading and decoding debugging information in
the "stabs" format. This format is used with many systems that use
the a.out object file format, as well as some systems that use
COFF or ELF where the stabs data is placed in a special section.
Avoid placing any object file format specific code in this file. */
#include "defs.h"
#include "bfd.h"
#include "obstack.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "symfile.h"
#include "objfiles.h"
#include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
#include "buildsym.h"
#include "complaints.h"
#include "demangle.h"
#include <ctype.h>
/* Ask stabsread.h to define the vars it normally declares `extern'. */
#define EXTERN /**/
#include "stabsread.h" /* Our own declarations */
#undef EXTERN
/* The routines that read and process a complete stabs for a C struct or
C++ class pass lists of data member fields and lists of member function
fields in an instance of a field_info structure, as defined below.
This is part of some reorganization of low level C++ support and is
expected to eventually go away... (FIXME) */
struct field_info
{
struct nextfield
{
struct nextfield *next;
/* This is the raw visibility from the stab. It is not checked
for being one of the visibilities we recognize, so code which
examines this field better be able to deal. */
int visibility;
struct field field;
} *list;
struct next_fnfieldlist
{
struct next_fnfieldlist *next;
struct fn_fieldlist fn_fieldlist;
} *fnlist;
};
static struct type *
dbx_alloc_type PARAMS ((int [2], struct objfile *));
static long read_huge_number PARAMS ((char **, int, int *));
static struct type *error_type PARAMS ((char **));
static int
read_type_number PARAMS ((char **, int *));
static struct type *
read_range_type PARAMS ((char **, int [2], struct objfile *));
static struct type *
os9k_read_type PARAMS ((char **, struct objfile *));
static struct type *
os9k_read_enum_type PARAMS ((char **, struct type *, struct objfile *));
static int
read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
struct objfile *));
static int
attach_fields_to_type PARAMS ((struct field_info *, struct type *,
struct objfile *));
static struct type *
os9k_read_array_type PARAMS ((char **, struct type *, struct objfile *));
extern struct complaint error_type_complaint;
extern struct complaint stabs_general_complaint;
extern struct complaint range_type_base_complaint;
extern struct complaint reg_value_complaint;
/* Define this as 1 if a pcc declaration of a char or short argument
gives the correct address. Otherwise assume pcc gives the
address of the corresponding int, which is not the same on a
big-endian machine. */
#ifndef BELIEVE_PCC_PROMOTION
#define BELIEVE_PCC_PROMOTION 0
#endif
/* Make a list of forward references which haven't been defined. */
static struct type **undef_types;
static int undef_types_allocated;
static int undef_types_length;
/* Check for and handle cretinous stabs symbol name continuation! */
#define STABS_CONTINUE(pp) \
do { \
if (**(pp) == '\\') *(pp) = next_symbol_text (); \
} while (0)
static struct type **init_type_vector[] = {
0,
&builtin_type_int,
&builtin_type_char,
&builtin_type_long,
&builtin_type_short,
&builtin_type_unsigned_char,
&builtin_type_unsigned_short,
&builtin_type_unsigned_long,
&builtin_type_unsigned_int,
&builtin_type_float,
&builtin_type_double,
&builtin_type_void,
&builtin_type_long_double
};
static void
os9k_init_type_vector(tv)
struct type **tv;
{
int i;
for (i=0; i<sizeof(init_type_vector)/sizeof(struct type **); i++)
tv[i] = (init_type_vector[i] == 0 ? 0 : *(init_type_vector[i]));
}
/* Look up a dbx type-number pair. Return the address of the slot
where the type for that number-pair is stored.
The number-pair is in TYPENUMS.
This can be used for finding the type associated with that pair
or for associating a new type with the pair. */
static struct type **
dbx_lookup_type (typenums)
int typenums[2];
{
register int filenum = typenums[0];
register int index = typenums[1];
unsigned old_len;
register int real_filenum;
register struct header_file *f;
int f_orig_length;
if (filenum == -1) /* -1,-1 is for temporary types. */
return 0;
if (filenum < 0 || filenum >= n_this_object_header_files)
{
static struct complaint msg = {"\
Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
0, 0};
complain (&msg, filenum, index, symnum);
goto error_return;
}
if (filenum == 0)
{
/* Type is defined outside of header files.
Find it in this object file's type vector. */
if (index >= type_vector_length)
{
old_len = type_vector_length;
if (old_len == 0)
{
type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
type_vector = (struct type **)
malloc (type_vector_length * sizeof (struct type *));
}
while (index >= type_vector_length)
{
type_vector_length *= 2;
}
type_vector = (struct type **)
xrealloc ((char *) type_vector,
(type_vector_length * sizeof (struct type *)));
memset (&type_vector[old_len], 0,
(type_vector_length - old_len) * sizeof (struct type *));
os9k_init_type_vector(type_vector);
}
return (&type_vector[index]);
}
else
{
real_filenum = this_object_header_files[filenum];
if (real_filenum >= n_header_files)
{
struct type *temp_type;
struct type **temp_type_p;
warning ("GDB internal error: bad real_filenum");
error_return:
temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
*temp_type_p = temp_type;
return temp_type_p;
}
f = &header_files[real_filenum];
f_orig_length = f->length;
if (index >= f_orig_length)
{
while (index >= f->length)
{
f->length *= 2;
}
f->vector = (struct type **)
xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
memset (&f->vector[f_orig_length], 0,
(f->length - f_orig_length) * sizeof (struct type *));
}
return (&f->vector[index]);
}
}
/* Make sure there is a type allocated for type numbers TYPENUMS
and return the type object.
This can create an empty (zeroed) type object.
TYPENUMS may be (-1, -1) to return a new type object that is not
put into the type vector, and so may not be referred to by number. */
static struct type *
dbx_alloc_type (typenums, objfile)
int typenums[2];
struct objfile *objfile;
{
register struct type **type_addr;
if (typenums[0] == -1)
{
return (alloc_type (objfile));
}
type_addr = dbx_lookup_type (typenums);
/* If we are referring to a type not known at all yet,
allocate an empty type for it.
We will fill it in later if we find out how. */
if (*type_addr == 0)
{
*type_addr = alloc_type (objfile);
}
return (*type_addr);
}
/* Read a number by which a type is referred to in dbx data,
or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
Just a single number N is equivalent to (0,N).
Return the two numbers by storing them in the vector TYPENUMS.
TYPENUMS will then be used as an argument to dbx_lookup_type.
Returns 0 for success, -1 for error. */
static int
read_type_number (pp, typenums)
register char **pp;
register int *typenums;
{
int nbits;
if (**pp == '(')
{
(*pp)++;
typenums[0] = read_huge_number (pp, ',', &nbits);
if (nbits != 0) return -1;
typenums[1] = read_huge_number (pp, ')', &nbits);
if (nbits != 0) return -1;
}
else
{
typenums[0] = 0;
typenums[1] = read_huge_number (pp, 0, &nbits);
if (nbits != 0) return -1;
}
return 0;
}
/* Skip rest of this symbol and return an error type.
General notes on error recovery: error_type always skips to the
end of the symbol (modulo cretinous dbx symbol name continuation).
Thus code like this:
if (*(*pp)++ != ';')
return error_type (pp);
is wrong because if *pp starts out pointing at '\0' (typically as the
result of an earlier error), it will be incremented to point to the
start of the next symbol, which might produce strange results, at least
if you run off the end of the string table. Instead use
if (**pp != ';')
return error_type (pp);
++*pp;
or
if (**pp != ';')
foo = error_type (pp);
else
++*pp;
And in case it isn't obvious, the point of all this hair is so the compiler
can define new types and new syntaxes, and old versions of the
debugger will be able to read the new symbol tables. */
static struct type *
error_type (pp)
char **pp;
{
complain (&error_type_complaint);
while (1)
{
/* Skip to end of symbol. */
while (**pp != '\0')
{
(*pp)++;
}
/* Check for and handle cretinous dbx symbol name continuation! */
if ((*pp)[-1] == '\\')
{
*pp = next_symbol_text ();
}
else
{
break;
}
}
return (builtin_type_error);
}
/* This page contains subroutines of read_type. */
#define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
#define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
#define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
#define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
static void
read_one_struct_field (fip, pp, p, type, objfile)
struct field_info *fip;
char **pp;
char *p;
struct type *type;
struct objfile *objfile;
{
fip -> list -> field.name =
obsavestring (*pp, p - *pp, &objfile -> type_obstack);
*pp = p + 1;
fip -> list -> visibility = VISIBILITY_PUBLIC;
fip -> list -> field.type = os9k_read_type (pp, objfile);
if (**pp == ':')
{
p = ++(*pp);
#if 0
/* Possible future hook for nested types. */
if (**pp == '!')
{
fip -> list -> field.bitpos = (long)-2; /* nested type */
p = ++(*pp);
}
else
#endif
{
/* Static class member. */
fip -> list -> field.bitpos = (long) -1;
}
while (*p != ';')
{
p++;
}
fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
*pp = p + 1;
return;
}
else if (**pp != ',')
{
/* Bad structure-type format. */
complain (&stabs_general_complaint, "bad structure-type format");
return;
}
(*pp)++; /* Skip the comma. */
{
int nbits;
fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits);
if (nbits != 0)
{
complain (&stabs_general_complaint, "bad structure-type format");
return;
}
fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits);
if (nbits != 0)
{
complain (&stabs_general_complaint, "bad structure-type format");
return;
}
}
if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
{
/* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
it is a field which has been optimized out. The correct stab for
this case is to use VISIBILITY_IGNORE, but that is a recent
invention. (2) It is a 0-size array. For example
union { int num; char str[0]; } foo. Printing "<no value>" for
str in "p foo" is OK, since foo.str (and thus foo.str[3])
will continue to work, and a 0-size array as a whole doesn't
have any contents to print.
I suspect this probably could also happen with gcc -gstabs (not
-gstabs+) for static fields, and perhaps other C++ extensions.
Hopefully few people use -gstabs with gdb, since it is intended
for dbx compatibility. */
/* Ignore this field. */
fip -> list-> visibility = VISIBILITY_IGNORE;
}
else
{
/* Detect an unpacked field and mark it as such.
dbx gives a bit size for all fields.
Note that forward refs cannot be packed,
and treat enums as if they had the width of ints. */
if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
&& TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
{
fip -> list -> field.bitsize = 0;
}
if ((fip -> list -> field.bitsize
== TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type)
|| (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
&& (fip -> list -> field.bitsize
== TARGET_INT_BIT)
)
)
&&
fip -> list -> field.bitpos % 8 == 0)
{
fip -> list -> field.bitsize = 0;
}
}
}
/* Read struct or class data fields. They have the form:
NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
At the end, we see a semicolon instead of a field.
In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
a static field.
The optional VISIBILITY is one of:
'/0' (VISIBILITY_PRIVATE)
'/1' (VISIBILITY_PROTECTED)
'/2' (VISIBILITY_PUBLIC)
'/9' (VISIBILITY_IGNORE)
or nothing, for C style fields with public visibility.
Returns 1 for success, 0 for failure. */
static int
read_struct_fields (fip, pp, type, objfile)
struct field_info *fip;
char **pp;
struct type *type;
struct objfile *objfile;
{
register char *p;
struct nextfield *new;
/* We better set p right now, in case there are no fields at all... */
p = *pp;
/* Read each data member type until we find the terminating ';' at the end of
the data member list, or break for some other reason such as finding the
start of the member function list. */
while (**pp != ';' && **pp != '\0')
{
STABS_CONTINUE (pp);
/* Get space to record the next field's data. */
new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
make_cleanup (free, new);
memset (new, 0, sizeof (struct nextfield));
new -> next = fip -> list;
fip -> list = new;
/* Get the field name. */
p = *pp;
/* Look for the ':' that separates the field name from the field
values. Data members are delimited by a single ':', while member
functions are delimited by a pair of ':'s. When we hit the member
functions (if any), terminate scan loop and return. */
while (*p != ':' && *p != '\0')
{
p++;
}
if (*p == '\0')
return 0;
/* Check to see if we have hit the member functions yet. */
if (p[1] == ':')
{
break;
}
read_one_struct_field (fip, pp, p, type, objfile);
}
if (p[0] == ':' && p[1] == ':')
{
/* chill the list of fields: the last entry (at the head) is a
partially constructed entry which we now scrub. */
fip -> list = fip -> list -> next;
}
return 1;
}
/* Create the vector of fields, and record how big it is.
We need this info to record proper virtual function table information
for this class's virtual functions. */
static int
attach_fields_to_type (fip, type, objfile)
struct field_info *fip;
register struct type *type;
struct objfile *objfile;
{
register int nfields = 0;
register int non_public_fields = 0;
register struct nextfield *scan;
/* Count up the number of fields that we have, as well as taking note of
whether or not there are any non-public fields, which requires us to
allocate and build the private_field_bits and protected_field_bits
bitfields. */
for (scan = fip -> list; scan != NULL; scan = scan -> next)
{
nfields++;
if (scan -> visibility != VISIBILITY_PUBLIC)
{
non_public_fields++;
}
}
/* Now we know how many fields there are, and whether or not there are any
non-public fields. Record the field count, allocate space for the
array of fields, and create blank visibility bitfields if necessary. */
TYPE_NFIELDS (type) = nfields;
TYPE_FIELDS (type) = (struct field *)
TYPE_ALLOC (type, sizeof (struct field) * nfields);
memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
/* Copy the saved-up fields into the field vector. Start from the head
of the list, adding to the tail of the field array, so that they end
up in the same order in the array in which they were added to the list. */
while (nfields-- > 0)
{
TYPE_FIELD (type, nfields) = fip -> list -> field;
fip -> list = fip -> list -> next;
}
return 1;
}
/* Read the description of a structure (or union type) and return an object
describing the type.
PP points to a character pointer that points to the next unconsumed token
in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
*PP will point to "4a:1,0,32;;".
TYPE points to an incomplete type that needs to be filled in.
OBJFILE points to the current objfile from which the stabs information is
being read. (Note that it is redundant in that TYPE also contains a pointer
to this same objfile, so it might be a good idea to eliminate it. FIXME).
*/
static struct type *
read_struct_type (pp, type, objfile)
char **pp;
struct type *type;
struct objfile *objfile;
{
struct cleanup *back_to;
struct field_info fi;
fi.list = NULL;
fi.fnlist = NULL;
back_to = make_cleanup (null_cleanup, 0);
INIT_CPLUS_SPECIFIC (type);
TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
/* First comes the total size in bytes. */
{
int nbits;
TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
if (nbits != 0)
return error_type (pp);
}
/* Now read the baseclasses, if any, read the regular C struct or C++
class member fields, attach the fields to the type, read the C++
member functions, attach them to the type, and then read any tilde
field (baseclass specifier for the class holding the main vtable). */
if (!read_struct_fields (&fi, pp, type, objfile)
|| !attach_fields_to_type (&fi, type, objfile)
)
{
do_cleanups (back_to);
return (error_type (pp));
}
do_cleanups (back_to);
return (type);
}
static long
read_huge_number (pp, end, bits)
char **pp;
int end;
int *bits;
{
char *p = *pp;
int sign = 1;
long n = 0;
int radix = 10;
char overflow = 0;
int nbits = 0;
int c;
long upper_limit;
if (*p == '-')
{
sign = -1;
p++;
}
/* Leading zero means octal. GCC uses this to output values larger
than an int (because that would be hard in decimal). */
if (*p == '0')
{
radix = 8;
p++;
}
upper_limit = LONG_MAX / radix;
while ((c = *p++) >= '0' && c < ('0' + radix))
{
if (n <= upper_limit)
{
n *= radix;
n += c - '0'; /* FIXME this overflows anyway */
}
else
overflow = 1;
/* This depends on large values being output in octal, which is
what GCC does. */
if (radix == 8)
{
if (nbits == 0)
{
if (c == '0')
/* Ignore leading zeroes. */
;
else if (c == '1')
nbits = 1;
else if (c == '2' || c == '3')
nbits = 2;
else
nbits = 3;
}
else
nbits += 3;
}
}
if (end)
{
if (c && c != end)
{
if (bits != NULL)
*bits = -1;
return 0;
}
}
else
--p;
*pp = p;
if (overflow)
{
if (nbits == 0)
{
/* Large decimal constants are an error (because it is hard to
count how many bits are in them). */
if (bits != NULL)
*bits = -1;
return 0;
}
/* -0x7f is the same as 0x80. So deal with it by adding one to
the number of bits. */
if (sign == -1)
++nbits;
if (bits)
*bits = nbits;
}
else
{
if (bits)
*bits = 0;
return n * sign;
}
/* It's *BITS which has the interesting information. */
return 0;
}
static struct type *
read_range_type (pp, typenums, objfile)
char **pp;
int typenums[2];
struct objfile *objfile;
{
int rangenums[2];
long n2, n3;
int n2bits, n3bits;
int self_subrange;
struct type *result_type;
struct type *index_type;
/* First comes a type we are a subrange of.
In C it is usually 0, 1 or the type being defined. */
/* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
not just a type number. */
if (read_type_number (pp, rangenums) != 0)
return error_type (pp);
self_subrange = (rangenums[0] == typenums[0] &&
rangenums[1] == typenums[1]);
/* A semicolon should now follow; skip it. */
if (**pp == ';')
(*pp)++;
/* The remaining two operands are usually lower and upper bounds
of the range. But in some special cases they mean something else. */
n2 = read_huge_number (pp, ';', &n2bits);
n3 = read_huge_number (pp, ';', &n3bits);
if (n2bits == -1 || n3bits == -1)
return error_type (pp);
/* If limits are huge, must be large integral type. */
if (n2bits != 0 || n3bits != 0)
{
char got_signed = 0;
char got_unsigned = 0;
/* Number of bits in the type. */
int nbits = 0;
/* Range from 0 to <large number> is an unsigned large integral type. */
if ((n2bits == 0 && n2 == 0) && n3bits != 0)
{
got_unsigned = 1;
nbits = n3bits;
}
/* Range from <large number> to <large number>-1 is a large signed
integral type. Take care of the case where <large number> doesn't
fit in a long but <large number>-1 does. */
else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
|| (n2bits != 0 && n3bits == 0
&& (n2bits == sizeof (long) * HOST_CHAR_BIT)
&& n3 == LONG_MAX))
{
got_signed = 1;
nbits = n2bits;
}
if (got_signed || got_unsigned)
{
return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
objfile);
}
else
return error_type (pp);
}
/* A type defined as a subrange of itself, with bounds both 0, is void. */
if (self_subrange && n2 == 0 && n3 == 0)
return init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
/* If n3 is zero and n2 is not, we want a floating type,
and n2 is the width in bytes.
Fortran programs appear to use this for complex types also,
and they give no way to distinguish between double and single-complex!
GDB does not have complex types.
Just return the complex as a float of that size. It won't work right
for the complex values, but at least it makes the file loadable. */
if (n3 == 0 && n2 > 0)
{
return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
}
/* If the upper bound is -1, it must really be an unsigned int. */
else if (n2 == 0 && n3 == -1)
{
/* It is unsigned int or unsigned long. */
/* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
compatibility hack. */
return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
TYPE_FLAG_UNSIGNED, NULL, objfile);
}
/* Special case: char is defined (Who knows why) as a subrange of
itself with range 0-127. */
else if (self_subrange && n2 == 0 && n3 == 127)
return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
/* We used to do this only for subrange of self or subrange of int. */
else if (n2 == 0)
{
if (n3 < 0)
/* n3 actually gives the size. */
return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
NULL, objfile);
if (n3 == 0xff)
return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
if (n3 == 0xffff)
return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
/* -1 is used for the upper bound of (4 byte) "unsigned int" and
"unsigned long", and we already checked for that,
so don't need to test for it here. */
}
/* I think this is for Convex "long long". Since I don't know whether
Convex sets self_subrange, I also accept that particular size regardless
of self_subrange. */
else if (n3 == 0 && n2 < 0
&& (self_subrange
|| n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
else if (n2 == -n3 -1)
{
if (n3 == 0x7f)
return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
if (n3 == 0x7fff)
return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
if (n3 == 0x7fffffff)
return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
}
/* We have a real range type on our hands. Allocate space and
return a real pointer. */
/* At this point I don't have the faintest idea how to deal with
a self_subrange type; I'm going to assume that this is used
as an idiom, and that all of them are special cases. So . . . */
if (self_subrange)
return error_type (pp);
index_type = *dbx_lookup_type (rangenums);
if (index_type == NULL)
{
/* Does this actually ever happen? Is that why we are worrying
about dealing with it rather than just calling error_type? */
static struct type *range_type_index;
complain (&range_type_base_complaint, rangenums[1]);
if (range_type_index == NULL)
range_type_index =
init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
0, "range type index type", NULL);
index_type = range_type_index;
}
result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
return (result_type);
}
#if !defined (REG_STRUCT_HAS_ADDR)
#define REG_STRUCT_HAS_ADDR(gcc_p) 0
#endif
static char *type_synonym_name = NULL;
struct symbol *
os9k_define_symbol (valu, string, desc, type, objfile)
CORE_ADDR valu;
char *string;
int desc;
int type;
struct objfile *objfile;
{
register struct symbol *sym;
char *p = (char *) strchr (string, ':');
int deftype;
int synonym = 0;
register int i;
/* We would like to eliminate nameless symbols, but keep their types.
E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
to type 2, but, should not create a symbol to address that type. Since
the symbol will be nameless, there is no way any user can refer to it. */
int nameless;
/* Ignore syms with empty names. */
if (string[0] == 0)
return 0;
/* Ignore old-style symbols from cc -go */
if (p == 0)
return 0;
while (p[1] == ':')
{
p += 2;
p = strchr(p, ':');
}
/* If a nameless stab entry, all we need is the type, not the symbol.
e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
sym = (struct symbol *)
obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
memset (sym, 0, sizeof (struct symbol));
if (processing_gcc_compilation)
{
/* GCC 2.x puts the line number in desc. SunOS apparently puts in the
number of bytes occupied by a type or object, which we ignore. */
SYMBOL_LINE(sym) = desc;
}
else
{
SYMBOL_LINE(sym) = 0; /* unknown */
}
{
SYMBOL_LANGUAGE (sym) = current_subfile -> language;
SYMBOL_NAME (sym) = (char *)
obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
/* Open-coded memcpy--saves function call time. */
/* FIXME: Does it really? Try replacing with simple strcpy and
try it on an executable with a large symbol table. */
/* FIXME: considering that gcc can open code memcpy anyway, I
doubt it. xoxorich. */
{
register char *p1 = string;
register char *p2 = SYMBOL_NAME (sym);
while (p1 != p)
{
*p2++ = *p1++;
}
*p2++ = '\0';
}
/* If this symbol is from a C++ compilation, then attempt to cache the
demangled form for future reference. This is a typical time versus
space tradeoff, that was decided in favor of time because it sped up
C++ symbol lookups by a factor of about 20. */
SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
}
p++;
/* Determine the type of name being defined. */
#if 0
/* Getting GDB to correctly skip the symbol on an undefined symbol
descriptor and not ever dump core is a very dodgy proposition if
we do things this way. I say the acorn RISC machine can just
fix their compiler. */
/* The Acorn RISC machine's compiler can put out locals that don't
start with "234=" or "(3,4)=", so assume anything other than the
deftypes we know how to handle is a local. */
if (!strchr ("cfFGpPrStTvVXCR", *p))
#else
if (isdigit (*p) || *p == '(' || *p == '-')
#endif
deftype = 'l';
else
deftype = *p++;
switch (deftype)
{
case 'c':
/* c is a special case, not followed by a type-number.
SYMBOL:c=iVALUE for an integer constant symbol.
SYMBOL:c=rVALUE for a floating constant symbol.
SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
e.g. "b:c=e6,0" for "const b = blob1"
(where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
if (*p != '=')
{
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_TYPE (sym) = error_type (&p);
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &file_symbols);
return sym;
}
++p;
switch (*p++)
{
case 'r':
{
double d = atof (p);
char *dbl_valu;
/* FIXME-if-picky-about-floating-accuracy: Should be using
target arithmetic to get the value. real.c in GCC
probably has the necessary code. */
/* FIXME: lookup_fundamental_type is a hack. We should be
creating a type especially for the type of float constants.
Problem is, what type should it be?
Also, what should the name of this type be? Should we
be using 'S' constants (see stabs.texinfo) instead? */
SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
FT_DBL_PREC_FLOAT);
dbl_valu = (char *)
obstack_alloc (&objfile -> symbol_obstack,
TYPE_LENGTH (SYMBOL_TYPE (sym)));
store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
SYMBOL_VALUE_BYTES (sym) = dbl_valu;
SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
}
break;
case 'i':
{
/* Defining integer constants this way is kind of silly,
since 'e' constants allows the compiler to give not
only the value, but the type as well. C has at least
int, long, unsigned int, and long long as constant
types; other languages probably should have at least
unsigned as well as signed constants. */
/* We just need one int constant type for all objfiles.
It doesn't depend on languages or anything (arguably its
name should be a language-specific name for a type of
that size, but I'm inclined to say that if the compiler
wants a nice name for the type, it can use 'e'). */
static struct type *int_const_type;
/* Yes, this is as long as a *host* int. That is because we
use atoi. */
if (int_const_type == NULL)
int_const_type =
init_type (TYPE_CODE_INT,
sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
"integer constant",
(struct objfile *)NULL);
SYMBOL_TYPE (sym) = int_const_type;
SYMBOL_VALUE (sym) = atoi (p);
SYMBOL_CLASS (sym) = LOC_CONST;
}
break;
case 'e':
/* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
can be represented as integral.
e.g. "b:c=e6,0" for "const b = blob1"
(where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
{
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
if (*p != ',')
{
SYMBOL_TYPE (sym) = error_type (&p);
break;
}
++p;
/* If the value is too big to fit in an int (perhaps because
it is unsigned), or something like that, we silently get
a bogus value. The type and everything else about it is
correct. Ideally, we should be using whatever we have
available for parsing unsigned and long long values,
however. */
SYMBOL_VALUE (sym) = atoi (p);
}
break;
default:
{
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_TYPE (sym) = error_type (&p);
}
}
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &file_symbols);
return sym;
case 'C':
/* The name of a caught exception. */
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_LABEL;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
SYMBOL_VALUE_ADDRESS (sym) = valu;
add_symbol_to_list (sym, &local_symbols);
break;
case 'f':
/* A static function definition. */
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_BLOCK;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &file_symbols);
/* fall into process_function_types. */
process_function_types:
/* Function result types are described as the result type in stabs.
We need to convert this to the function-returning-type-X type
in GDB. E.g. "int" is converted to "function returning int". */
if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
{
#if 0
/* This code doesn't work -- it needs to realloc and can't. */
/* Attempt to set up to record a function prototype... */
struct type *new = alloc_type (objfile);
/* Generate a template for the type of this function. The
types of the arguments will be added as we read the symbol
table. */
*new = *lookup_function_type (SYMBOL_TYPE(sym));
SYMBOL_TYPE(sym) = new;
TYPE_OBJFILE (new) = objfile;
in_function_type = new;
#else
SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
#endif
}
/* fall into process_prototype_types */
process_prototype_types:
/* Sun acc puts declared types of arguments here. We don't care
about their actual types (FIXME -- we should remember the whole
function prototype), but the list may define some new types
that we have to remember, so we must scan it now. */
while (*p == ';') {
p++;
os9k_read_type (&p, objfile);
}
break;
case 'F':
/* A global function definition. */
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_BLOCK;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &global_symbols);
goto process_function_types;
case 'V':
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_VALUE_ADDRESS (sym) = valu;
/*
i = hashname (SYMBOL_NAME (sym));
SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
global_sym_chain[i] = sym;
*/
SYMBOL_CLASS (sym) = LOC_STATIC;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &global_symbols);
break;
/* This case is faked by a conditional above,
when there is no code letter in the dbx data.
Dbx data never actually contains 'l'. */
case 'l':
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_LOCAL;
SYMBOL_VALUE (sym) = valu;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &local_symbols);
break;
case 'p':
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
/* Normally this is a parameter, a LOC_ARG. On the i960, it
can also be a LOC_LOCAL_ARG depending on symbol type. */
#ifndef DBX_PARM_SYMBOL_CLASS
#define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
#endif
SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
SYMBOL_VALUE (sym) = valu;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
#if 0
/* This doesn't work yet. */
add_param_to_type (&in_function_type, sym);
#endif
add_symbol_to_list (sym, &local_symbols);
break;
case 'P':
/* acc seems to use P to delare the prototypes of functions that
are referenced by this file. gdb is not prepared to deal
with this extra information. FIXME, it ought to. */
if (type == N_FUN)
{
os9k_read_type (&p, objfile);
goto process_prototype_types;
}
/*FALLTHROUGH*/
case 'R':
#if 0
/* Parameter which is in a register. */
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_REGPARM;
SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
if (SYMBOL_VALUE (sym) >= NUM_REGS)
{
complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym));
SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
}
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &local_symbols);
break;
#endif 0
case 'r':
/* Register variable (either global or local). */
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_REGISTER;
SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
if (SYMBOL_VALUE (sym) >= NUM_REGS)
{
complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym));
SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
}
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
if (within_function)
{
/* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
name to represent an argument passed in a register.
GCC uses 'P' for the same case. So if we find such a symbol pair
we combine it into one 'P' symbol.
But we only do this in the REG_STRUCT_HAS_ADDR case, so that
we can still get information about what is going on with the
stack (VAX for computing args_printed, using stack slots instead
of saved registers in backtraces, etc.).
Note that this code illegally combines
main(argc) struct foo argc; { register struct foo argc; }
but this case is considered pathological and causes a warning
from a decent compiler. */
if (local_symbols
&& local_symbols->nsyms > 0
&& REG_STRUCT_HAS_ADDR (processing_gcc_compilation)
&& (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
|| TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))
{
struct symbol *prev_sym;
prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
if (SYMBOL_CLASS (prev_sym) == LOC_ARG
&& STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
{
SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
/* Use the type from the LOC_REGISTER; that is the type
that is actually in that register. */
SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
sym = prev_sym;
break;
}
}
add_symbol_to_list (sym, &local_symbols);
}
else
add_symbol_to_list (sym, &file_symbols);
break;
case 't':
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
/* For a nameless type, we don't want a create a symbol, thus we
did not use `sym'. Return without further processing. */
if (nameless) return NULL;
SYMBOL_CLASS (sym) = LOC_TYPEDEF;
SYMBOL_VALUE (sym) = valu;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
{
if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
|| TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
{
/* If we are giving a name to a type such as "pointer to
foo" or "function returning foo", we better not set
the TYPE_NAME. If the program contains "typedef char
*caddr_t;", we don't want all variables of type char
* to print as caddr_t. This is not just a
consequence of GDB's type management; PCC and GCC (at
least through version 2.4) both output variables of
either type char * or caddr_t with the type number
defined in the 't' symbol for caddr_t. If a future
compiler cleans this up it GDB is not ready for it
yet, but if it becomes ready we somehow need to
disable this check (without breaking the PCC/GCC2.4
case).
Sigh.
Fortunately, this check seems not to be necessary
for anything except pointers or functions. */
}
else
TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
}
add_symbol_to_list (sym, &file_symbols);
break;
case 'T':
/* Struct, union, or enum tag. For GNU C++, this can be be followed
by 't' which means we are typedef'ing it as well. */
synonym = *p == 't';
if (synonym)
{
p++;
type_synonym_name = obsavestring (SYMBOL_NAME (sym),
strlen (SYMBOL_NAME (sym)),
&objfile -> symbol_obstack);
}
/* The semantics of C++ state that "struct foo { ... }" also defines
a typedef for "foo". Unfortunately, cfront never makes the typedef
when translating C++ into C. We make the typedef here so that
"ptype foo" works as expected for cfront translated code. */
else if (current_subfile->language == language_cplus)
{
synonym = 1;
type_synonym_name = obsavestring (SYMBOL_NAME (sym),
strlen (SYMBOL_NAME (sym)),
&objfile -> symbol_obstack);
}
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
/* For a nameless type, we don't want a create a symbol, thus we
did not use `sym'. Return without further processing. */
if (nameless) return NULL;
SYMBOL_CLASS (sym) = LOC_TYPEDEF;
SYMBOL_VALUE (sym) = valu;
SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
TYPE_TAG_NAME (SYMBOL_TYPE (sym))
= obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
add_symbol_to_list (sym, &file_symbols);
if (synonym)
{
/* Clone the sym and then modify it. */
register struct symbol *typedef_sym = (struct symbol *)
obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
*typedef_sym = *sym;
SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
SYMBOL_VALUE (typedef_sym) = valu;
SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
TYPE_NAME (SYMBOL_TYPE (sym))
= obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
add_symbol_to_list (typedef_sym, &file_symbols);
}
break;
case 'v':
/* Static symbol at top level of file */
SYMBOL_TYPE (sym) = os9k_read_type (&p, objfile);
SYMBOL_CLASS (sym) = LOC_STATIC;
SYMBOL_VALUE_ADDRESS (sym) = valu;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &file_symbols);
break;
default:
SYMBOL_TYPE (sym) = error_type (&p);
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_VALUE (sym) = 0;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
add_symbol_to_list (sym, &file_symbols);
break;
}
/* When passing structures to a function, some systems sometimes pass
the address in a register, not the structure itself.
If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
to LOC_REGPARM_ADDR for structures and unions. */
if (SYMBOL_CLASS (sym) == LOC_REGPARM
&& REG_STRUCT_HAS_ADDR (processing_gcc_compilation)
&& ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
|| (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)))
SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
return sym;
}
/* Read type information or a type definition; return the type. Even
though this routine accepts either type information or a type
definition, the distinction is relevant--some parts of stabsread.c
assume that type information starts with a digit, '-', or '(' in
deciding whether to call read_type. */
static struct type *
os9k_read_type (pp, objfile)
register char **pp;
struct objfile *objfile;
{
register struct type *type = 0;
struct type *type1;
int typenums[2];
int xtypenums[2];
char type_descriptor;
/* Size in bits of type if specified by a type attribute, or -1 if
there is no size attribute. */
int type_size = -1;
/* Used to distinguish string and bitstring from char-array and set. */
int is_string = 0;
/* Read type number if present. The type number may be omitted.
for instance in a two-dimensional array declared with type
"ar1;1;10;ar1;1;10;4". */
if ((**pp >= '0' && **pp <= '9')
|| **pp == '('
|| **pp == '-')
{
if (read_type_number (pp, typenums) != 0)
return error_type (pp);
/* Type is not being defined here. Either it already exists,
or this is a forward reference to it. dbx_alloc_type handles
both cases. */
if (**pp != '=')
return dbx_alloc_type (typenums, objfile);
/* Type is being defined here. */
/* Skip the '='. */
++(*pp);
while (**pp == '@')
{
char *p = *pp + 1;
/* It might be a type attribute or a member type. */
if (isdigit (*p) || *p == '(' || *p == '-')
/* Member type. */
break;
else
{
/* Type attributes. */
char *attr = p;
/* Skip to the semicolon. */
while (*p != ';' && *p != '\0')
++p;
*pp = p;
if (*p == '\0')
return error_type (pp);
else
/* Skip the semicolon. */
++*pp;
switch (*attr)
{
case 's':
type_size = atoi (attr + 1);
if (type_size <= 0)
type_size = -1;
break;
case 'S':
is_string = 1;
break;
default:
/* Ignore unrecognized type attributes, so future compilers
can invent new ones. */
break;
}
}
}
/* Skip the type descriptor, we get it below with (*pp)[-1]. */
++(*pp);
}
else
{
/* 'typenums=' not present, type is anonymous. Read and return
the definition, but don't put it in the type vector. */
typenums[0] = typenums[1] = -1;
(*pp)++;
}
type_descriptor = (*pp)[-1];
switch (type_descriptor)
{
case 'x':
{
enum type_code code;
/* Used to index through file_symbols. */
struct pending *ppt;
int i;
/* Name including "struct", etc. */
char *type_name;
{
char *from, *to, *p, *q1, *q2;
/* Set the type code according to the following letter. */
switch ((*pp)[0])
{
case 's':
code = TYPE_CODE_STRUCT;
break;
case 'u':
code = TYPE_CODE_UNION;
break;
case 'e':
code = TYPE_CODE_ENUM;
break;
default:
{
/* Complain and keep going, so compilers can invent new
cross-reference types. */
static struct complaint msg =
{"Unrecognized cross-reference type `%c'", 0, 0};
complain (&msg, (*pp)[0]);
code = TYPE_CODE_STRUCT;
break;
}
}
q1 = strchr(*pp, '<');
p = strchr(*pp, ':');
if (p == NULL)
return error_type (pp);
while (q1 && p > q1 && p[1] == ':')
{
q2 = strchr(q1, '>');
if (!q2 || q2 < p)
break;
p += 2;
p = strchr(p, ':');
if (p == NULL)
return error_type (pp);
}
to = type_name =
(char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1);
/* Copy the name. */
from = *pp + 1;
while (from < p)
*to++ = *from++;
*to = '\0';
/* Set the pointer ahead of the name which we just read, and
the colon. */
*pp = from + 1;
}
/* Now check to see whether the type has already been
declared. This was written for arrays of cross-referenced
types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
sure it is not necessary anymore. But it might be a good
idea, to save a little memory. */
for (ppt = file_symbols; ppt; ppt = ppt->next)
for (i = 0; i < ppt->nsyms; i++)
{
struct symbol *sym = ppt->symbol[i];
if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
&& SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
&& (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
&& STREQ (SYMBOL_NAME (sym), type_name))
{
obstack_free (&objfile -> type_obstack, type_name);
type = SYMBOL_TYPE (sym);
return type;
}
}
/* Didn't find the type to which this refers, so we must
be dealing with a forward reference. Allocate a type
structure for it, and keep track of it so we can
fill in the rest of the fields when we get the full
type. */
type = dbx_alloc_type (typenums, objfile);
TYPE_CODE (type) = code;
TYPE_TAG_NAME (type) = type_name;
TYPE_NAME(type) = NULL;
INIT_CPLUS_SPECIFIC(type);
TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
add_undefined_type (type);
return type;
}
case '-': /* RS/6000 built-in type */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '(':
{
char *pp_saved;
(*pp)--;
pp_saved = *pp;
/* Peek ahead at the number to detect void. */
if (read_type_number (pp, xtypenums) != 0)
return error_type (pp);
if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
/* It's being defined as itself. That means it is "void". */
type = init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
else
{
struct type *xtype;
/* Go back to the number and have read_type get it. This means
that we can deal with something like t(1,2)=(3,4)=... which
the Lucid compiler uses. */
*pp = pp_saved;
xtype = os9k_read_type (pp, objfile);
/* The type is being defined to another type. So we copy the type.
This loses if we copy a C++ class and so we lose track of how
the names are mangled (but g++ doesn't output stabs like this
now anyway). */
type = alloc_type (objfile);
memcpy (type, xtype, sizeof (struct type));
/* The idea behind clearing the names is that the only purpose
for defining a type to another type is so that the name of
one can be different. So we probably don't need to worry much
about the case where the compiler doesn't give a name to the
new type. */
TYPE_NAME (type) = NULL;
TYPE_TAG_NAME (type) = NULL;
}
if (typenums[0] != -1)
*dbx_lookup_type (typenums) = type;
break;
}
/* In the following types, we must be sure to overwrite any existing
type that the typenums refer to, rather than allocating a new one
and making the typenums point to the new one. This is because there
may already be pointers to the existing type (if it had been
forward-referenced), and we must change it to a pointer, function,
reference, or whatever, *in-place*. */
case '*':
type1 = os9k_read_type (pp, objfile);
type = make_pointer_type (type1, dbx_lookup_type (typenums));
break;
case '&': /* Reference to another type */
type1 = os9k_read_type (pp, objfile);
type = make_reference_type (type1, dbx_lookup_type (typenums));
break;
case 'f': /* Function returning another type */
if (**pp == '(') {
while (**pp != ')') ++*pp; /* skip os9000 function prototype */
++*pp;
}
type1 = os9k_read_type (pp, objfile);
type = make_function_type (type1, dbx_lookup_type (typenums));
break;
case 'c': /* Const qualifier on some type (Sun) */
type = os9k_read_type (pp, objfile);
/* FIXME! For now, we ignore const and volatile qualifiers. */
break;
case 'b': /* Const volatile */
case 'i': /* Volatile qual on some type (Sun) */
type = os9k_read_type (pp, objfile);
/* FIXME! For now, we ignore const and volatile qualifiers. */
break;
/* FIXME -- we should be doing smash_to_XXX types here. */
case '@': /* Member (class & variable) type */
{
struct type *domain = os9k_read_type (pp, objfile);
struct type *memtype;
if (**pp != ',')
/* Invalid member type data format. */
return error_type (pp);
++*pp;
memtype = os9k_read_type (pp, objfile);
type = dbx_alloc_type (typenums, objfile);
smash_to_member_type (type, domain, memtype);
}
break;
case 'r': /* Range type */
type = read_range_type (pp, typenums, objfile);
if (typenums[0] != -1)
*dbx_lookup_type (typenums) = type;
break;
case 'e': /* Enumeration type */
type = dbx_alloc_type (typenums, objfile);
type = os9k_read_enum_type (pp, type, objfile);
if (typenums[0] != -1)
*dbx_lookup_type (typenums) = type;
break;
case 's': /* Struct type */
case 'u': /* Union type */
type = dbx_alloc_type (typenums, objfile);
if (!TYPE_NAME (type))
{
TYPE_NAME (type) = type_synonym_name;
}
type_synonym_name = NULL;
switch (type_descriptor)
{
case 's':
TYPE_CODE (type) = TYPE_CODE_STRUCT;
break;
case 'u':
TYPE_CODE (type) = TYPE_CODE_UNION;
break;
}
type = read_struct_type (pp, type, objfile);
break;
case 'a': /* Array type */
if (**pp == 'r')
++*pp;
type = dbx_alloc_type (typenums, objfile);
type = os9k_read_array_type (pp, type, objfile);
if (is_string)
TYPE_CODE (type) = TYPE_CODE_STRING;
break;
case 'S':
type1 = os9k_read_type (pp, objfile);
type = create_set_type ((struct type*) NULL, type1);
if (is_string)
TYPE_CODE (type) = TYPE_CODE_BITSTRING;
if (typenums[0] != -1)
*dbx_lookup_type (typenums) = type;
break;
default:
--*pp; /* Go back to the symbol in error */
/* Particularly important if it was \0! */
return error_type (pp);
}
if (type == 0)
{
warning ("GDB internal error, type is NULL in stabsread.c\n");
return error_type (pp);
}
/* Size specified in a type attribute overrides any other size. */
if (type_size != -1)
TYPE_LENGTH (type) = type_size / TARGET_CHAR_BIT;
return type;
}
/* Read a definition of an array type,
and create and return a suitable type object.
Also creates a range type which represents the bounds of that
array. */
static struct type *
os9k_read_array_type (pp, type, objfile)
register char **pp;
register struct type *type;
struct objfile *objfile;
{
struct type *index_type, *element_type, *range_type;
int lower, upper;
int adjustable = 0;
int nbits;
/* Format of an array type:
"arlower,upper;<array_contents_type>". Put code in
to handle this.
Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
for these, produce a type like float[][]. */
index_type = builtin_type_int;
if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
{
(*pp)++;
adjustable = 1;
}
lower = read_huge_number (pp, ',', &nbits);
if (nbits != 0)
return error_type (pp);
if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
{
(*pp)++;
adjustable = 1;
}
upper = read_huge_number (pp, ';', &nbits);
if (nbits != 0)
return error_type (pp);
element_type = os9k_read_type (pp, objfile);
if (adjustable)
{
lower = 0;
upper = -1;
}
range_type =
create_range_type ((struct type *) NULL, index_type, lower, upper);
type = create_array_type (type, element_type, range_type);
/* If we have an array whose element type is not yet known, but whose
bounds *are* known, record it to be adjusted at the end of the file. */
/* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think
the two have the same effect except that the latter is cleaner and the
former would be wrong for types which really are zero-length (if we
have any). */
if (TYPE_LENGTH (element_type) == 0 && !adjustable)
{
TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
add_undefined_type (type);
}
return type;
}
/* Read a definition of an enumeration type,
and create and return a suitable type object.
Also defines the symbols that represent the values of the type. */
static struct type *
os9k_read_enum_type (pp, type, objfile)
register char **pp;
register struct type *type;
struct objfile *objfile;
{
register char *p;
char *name;
register long n;
register struct symbol *sym;
int nsyms = 0;
struct pending **symlist;
struct pending *osyms, *syms;
int o_nsyms;
int size;
int nbits;
#if 0
/* FIXME! The stabs produced by Sun CC merrily define things that ought
to be file-scope, between N_FN entries, using N_LSYM. What's a mother
to do? For now, force all enum values to file scope. */
if (within_function)
symlist = &local_symbols;
else
#endif
symlist = &file_symbols;
osyms = *symlist;
o_nsyms = osyms ? osyms->nsyms : 0;
/* Read the value-names and their values.
The input syntax is NAME:VALUE,NAME:VALUE, and so on.
A semicolon or comma instead of a NAME means the end. */
size = read_huge_number(pp, 0, &nbits);
if (nbits != 0)
return error_type (pp);
while (**pp && **pp != ';' && **pp != ',')
{
STABS_CONTINUE (pp);
p = *pp;
while (*p != ':') p++;
name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
*pp = p + 1;
n = read_huge_number (pp, ',', &nbits);
if (nbits != 0)
return error_type (pp);
sym = (struct symbol *)
obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
memset (sym, 0, sizeof (struct symbol));
SYMBOL_NAME (sym) = name;
SYMBOL_LANGUAGE (sym) = current_subfile -> language;
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
SYMBOL_VALUE (sym) = n;
add_symbol_to_list (sym, symlist);
nsyms++;
}
if (**pp == ';')
(*pp)++; /* Skip the semicolon. */
/* Now fill in the fields of the type-structure. */
TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
TYPE_CODE (type) = TYPE_CODE_ENUM;
TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
TYPE_NFIELDS (type) = nsyms;
TYPE_FIELDS (type) = (struct field *)
TYPE_ALLOC (type, sizeof (struct field) * nsyms);
memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
/* Find the symbols for the values and put them into the type.
The symbols can be found in the symlist that we put them on
to cause them to be defined. osyms contains the old value
of that symlist; everything up to there was defined by us. */
/* Note that we preserve the order of the enum constants, so
that in something like "enum {FOO, LAST_THING=FOO}" we print
FOO, not LAST_THING. */
for (syms = *symlist, n = 0; syms; syms = syms->next)
{
int j = 0;
if (syms == osyms)
j = o_nsyms;
for (; j < syms->nsyms; j++,n++)
{
struct symbol *xsym = syms->symbol[j];
SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
TYPE_FIELD_VALUE (type, n) = 0;
TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
TYPE_FIELD_BITSIZE (type, n) = 0;
}
if (syms == osyms)
break;
}
return type;
}
|