summaryrefslogtreecommitdiff
path: root/coregrind/m_debuginfo/UNUSED_STABS.txt
blob: 38790261517d13734d2c3a299980800a73b92ceb (plain)
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

/*--------------------------------------------------------------------*/
/*--- Extract type info from debug info.                symtypes.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2000-2005 Julian Seward
      jseward@acm.org

   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.

   The GNU General Public License is contained in the file COPYING.
*/

#include "pub_core_basics.h"
#include "pub_core_debuginfo.h"
#include "pub_core_debuglog.h"    // For VG_(debugLog_vprintf)
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_machine.h"
#include "pub_core_mallocfree.h"

#include "priv_symtypes.h"

typedef enum {
   TyUnknown,			/* unknown type */
   TyUnresolved,		/* unresolved type */
   TyError,			/* error type */

   TyVoid,			/* void */

   TyInt,			/* integer */
   TyBool,			/* boolean */
   TyChar,			/* character */
   TyFloat,			/* float */

   TyRange,			/* type subrange */

   TyEnum,			/* enum */

   TyPointer,			/* pointer */
   TyArray,			/* array */
   TyStruct,			/* structure/class */
   TyUnion,			/* union */

   TyTypedef			/* typedef */
} TyKind;

static const Char *ppkind(TyKind k)
{
   switch(k) {
#define S(x)	case x:		return #x
      S(TyUnknown);
      S(TyUnresolved);
      S(TyError);
      S(TyVoid);
      S(TyInt);
      S(TyBool);
      S(TyChar);
      S(TyRange);
      S(TyFloat);
      S(TyEnum);
      S(TyPointer);
      S(TyArray);
      S(TyStruct);
      S(TyUnion);
      S(TyTypedef);
#undef S
   default:
      return "Ty???";
   }
}

/* struct/union field */
typedef struct _StField {
   UInt		offset;		/* offset into structure (0 for union) (in bits) */
   UInt		size;		/* size (in bits) */
   SymType	*type;		/* type of element */
   Char	*name;			/* name of element */
} StField;

/* enum tag */
typedef struct _EnTag {
   const Char   *name;		/* name */
   UInt		val;		/* value */
} EnTag;

struct _SymType {
   TyKind	kind;			/* type descriminator */
   UInt		size;			/* sizeof(type) */
   Char		*name;			/* useful name */

   union {
      /* TyInt,TyBool,TyChar */
      struct {
	 Bool		issigned;	/* signed or not */
      } t_scalar;

      /* TyFloat */
      struct {
	 Bool		isdouble;	/* is double prec */
      } t_float;

      /* TyRange */
      struct {
	 Int		min;
	 Int		max;
	 SymType	*type;
      } t_range;

      /* TyPointer */
      struct {
	 SymType	*type;		/* *type */
      } t_pointer;

      /* TyArray */
      struct {
	 SymType	*idxtype;
	 SymType	*type;
      } t_array;

      /* TyEnum */
      struct {
	 UInt		ntag;		/* number of tags */
	 EnTag		*tags;		/* tags */
      } t_enum;

      /* TyStruct, TyUnion */
      struct {
	 UInt		nfield;		/* number of fields */
	 UInt		nfieldalloc;	/* number of fields allocated */
	 StField	*fields;	/* fields */
      } t_struct;

      /* TyTypedef */
      struct {
	 SymType	*type;		/* type */
      } t_typedef;

      /* TyUnresolved - reference to unresolved type */
      struct {
	 /* some kind of symtab reference */
	 SymResolver	*resolver;	/* symtab reader's resolver */
	 void		*data;		/* data for resolver */
      } t_unresolved;
   } u;
};


Bool ML_(st_isstruct)(SymType *ty)
{
   return ty->kind == TyStruct;
}

Bool ML_(st_isunion)(SymType *ty)
{
   return ty->kind == TyUnion;
}

Bool ML_(st_isenum)(SymType *ty)
{
   return ty->kind == TyEnum;
}

static inline SymType *alloc(SymType *st)
{
   if (st == NULL) {
      st = VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(*st));
      st->kind = TyUnknown;
      st->name = NULL;
   }

   return st;
}

static void resolve(SymType *st)
{
   if (st->kind != TyUnresolved)
      return;

   (*st->u.t_unresolved.resolver)(st, st->u.t_unresolved.data);

   if (st->kind == TyUnresolved)
      st->kind = TyError;
}

SymType *ML_(st_mkunresolved)(SymType *st, SymResolver *resolver, void *data)
{
   st = alloc(st);
   
   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);

   st->kind = TyUnresolved;
   st->size = 0;
   st->u.t_unresolved.resolver = resolver;
   st->u.t_unresolved.data = data;

   return st;
}

void ML_(st_unresolved_setdata)(SymType *st, SymResolver *resolver, void *data)
{
   if (st->kind != TyUnresolved)
      return;

   st->u.t_unresolved.resolver = resolver;
   st->u.t_unresolved.data = data;
}

Bool ML_(st_isresolved)(SymType *st)
{
   return st->kind != TyUnresolved;
}

void ML_(st_setname)(SymType *st, Char *name)
{
   if (st->name != NULL)
      st->name = name;
}

SymType *ML_(st_mkvoid)(SymType *st)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);
   
   st->kind = TyVoid;
   st->size = 1;		/* for address calculations */
   st->name = "void";
   return st;
}

SymType *ML_(st_mkint)(SymType *st, UInt size, Bool isSigned)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);
   
   st->kind = TyInt;
   st->size = size;
   st->u.t_scalar.issigned = isSigned;

   return st;
}

SymType *ML_(st_mkfloat)(SymType *st, UInt size)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);
   
   st->kind = TyFloat;
   st->size = size;
   st->u.t_scalar.issigned = True;

   return st;
}

SymType *ML_(st_mkbool)(SymType *st, UInt size)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);
   
   st->kind = TyBool;
   st->size = size;

   return st;
}


SymType *ML_(st_mkpointer)(SymType *st, SymType *ptr)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);

   st->kind = TyPointer;
   st->size = sizeof(void *);
   st->u.t_pointer.type = ptr;

   return st;
}

SymType *ML_(st_mkrange)(SymType *st, SymType *ty, Int min, Int max)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);

   st->kind = TyRange;
   st->size = 0;		/* ? */
   st->u.t_range.type = ty;
   st->u.t_range.min = min;
   st->u.t_range.max = max;

   return st;
}

SymType *ML_(st_mkstruct)(SymType *st, UInt size, UInt nfields)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown || st->kind == TyStruct);

   vg_assert(st->kind != TyStruct || st->u.t_struct.nfield == 0);

   st->kind = TyStruct;
   st->size = size;
   st->u.t_struct.nfield = 0;
   st->u.t_struct.nfieldalloc = nfields;
   if (nfields != 0)
      st->u.t_struct.fields = VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(StField) * nfields);
   else
      st->u.t_struct.fields = NULL;
   
   return st;
}

SymType *ML_(st_mkunion)(SymType *st, UInt size, UInt nfields)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown || st->kind == TyUnion);

   vg_assert(st->kind != TyUnion || st->u.t_struct.nfield == 0);

   st->kind = TyUnion;
   st->size = size;
   st->u.t_struct.nfield = 0;
   st->u.t_struct.nfieldalloc = nfields;
   if (nfields != 0)
      st->u.t_struct.fields = VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(StField) * nfields);
   else
      st->u.t_struct.fields = NULL;

   return st;
}

void ML_(st_addfield)(SymType *st, Char *name, SymType *type, UInt off, UInt size)
{
   StField *f;

   vg_assert(st->kind == TyStruct || st->kind == TyUnion);

   if (st->u.t_struct.nfieldalloc == st->u.t_struct.nfield) {
      StField *n = VG_(arena_malloc)(VG_AR_SYMTAB, 
				     sizeof(StField) * (st->u.t_struct.nfieldalloc + 2));
      VG_(memcpy)(n, st->u.t_struct.fields, sizeof(*n) * st->u.t_struct.nfield);
      if (st->u.t_struct.fields != NULL)
	 VG_(arena_free)(VG_AR_SYMTAB, st->u.t_struct.fields);
      st->u.t_struct.nfieldalloc++;
      st->u.t_struct.fields = n;
   }

   f = &st->u.t_struct.fields[st->u.t_struct.nfield++];
   f->name = name;
   f->type = type;
   f->offset = off;
   f->size = size;
}


SymType *ML_(st_mkenum)(SymType *st, UInt ntags)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown || st->kind == TyEnum);

   st->kind = TyEnum;
   st->u.t_enum.ntag = 0;
   st->u.t_enum.tags = NULL;
   
   return st;
}

SymType *ML_(st_mkarray)(SymType *st, SymType *idxtype, SymType *type)
{
   st = alloc(st);

   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown);

   st->kind = TyArray;
   st->u.t_array.type = type;
   st->u.t_array.idxtype = idxtype;
   
   return st;
}

SymType *ML_(st_mktypedef)(SymType *st, Char *name, SymType *type)
{
   st = alloc(st);

   vg_assert(st != type);
   vg_assert(st->kind == TyUnresolved || st->kind == TyUnknown ||
	     st->kind == TyStruct || st->kind == TyUnion ||
	     st->kind == TyTypedef);
   
   st->kind = TyTypedef;
   st->name = name;
   st->u.t_typedef.type = type;

   return st;
}


SymType *ML_(st_basetype)(SymType *type, Bool do_resolve)
{
   while (type->kind == TyTypedef || (do_resolve && type->kind == TyUnresolved)) {
      if (do_resolve)
	 resolve(type);

      if (type->kind == TyTypedef)
	 type = type->u.t_typedef.type;
   }

   return type;
}

UInt ML_(st_sizeof)(SymType *ty)
{
   return ty->size;
}

#ifndef TEST
/*
  Hash of visited addresses, so we don't get stuck in loops.  It isn't
  simply enough to keep track of addresses, since we need to interpret
  the memory according to the type.  If a given location has multiple
  pointers with different types (for example, void * and struct foo *),
  then we need to look at it under each type.
*/
struct visited {
   Addr		a;
   SymType	*ty;
   struct visited *next;
};

#define VISIT_HASHSZ	1021

static struct visited *visit_hash[VISIT_HASHSZ];

static inline Bool test_visited(Addr a, SymType *type)
{
   struct visited *v;
   UInt b = (UInt)a % VISIT_HASHSZ;
   Bool ret = False;

   for(v = visit_hash[b]; v != NULL; v = v->next) {
      if (v->a == a && v->ty == type) {
	 ret = True;
	 break;
      }
   }
   
   return ret;
}

static Bool has_visited(Addr a, SymType *type)
{
   static const Bool debug = False;
   Bool ret;

   ret = test_visited(a, type);

   if (!ret) {
      UInt b = (UInt)a % VISIT_HASHSZ;
      struct visited * v = VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(*v));

      v->a = a;
      v->ty = type;
      v->next = visit_hash[b];
      visit_hash[b] = v;
   }
   
   if (debug)
      VG_(printf)("has_visited(a=%p, ty=%p) -> %d\n", a, type, ret);

   return ret;
}

static void clear_visited(void)
{
   UInt i;
   
   for(i = 0; i < VISIT_HASHSZ; i++) {
      struct visited *v, *n;
      for(v = visit_hash[i]; v != NULL; v = n) {
	 n = v->next;
	 VG_(arena_free)(VG_AR_SYMTAB, v);
      }
      visit_hash[i] = NULL;
   }
}

static 
void bprintf(void (*send)(HChar, void*), void *send_arg, const Char *fmt, ...)
{
   va_list vargs;

   va_start(vargs, fmt);
   VG_(debugLog_vprintf)(send, send_arg, fmt, vargs);
   va_end(vargs);
}

#define SHADOWCHUNK	0	/* no longer have a core allocator */

#if SHADOWCHUNK
static ShadowChunk *findchunk(Addr a)
{
   Bool find(ShadowChunk *sc) {
      return a >= sc->data && a < (sc->data+sc->size);
   }
   return VG_(any_matching_mallocd_ShadowChunks)(find);
}
#endif

static struct vki_sigaction sigbus_saved;
static struct vki_sigaction sigsegv_saved;
static vki_sigset_t  blockmask_saved;
static jmp_buf valid_addr_jmpbuf;

static void valid_addr_handler(int sig)
{
   //VG_(printf)("OUCH! %d\n", sig);
   __builtin_longjmp(valid_addr_jmpbuf, 1);
}

/* catch badness signals because we're going to be
   playing around in untrusted memory */
static void setup_signals(void)
{
   Int res;
   struct vki_sigaction sigbus_new;
   struct vki_sigaction sigsegv_new;
   vki_sigset_t         unblockmask_new;

   /* Temporarily install a new sigsegv and sigbus handler, and make
      sure SIGBUS, SIGSEGV and SIGTERM are unblocked.  (Perhaps the
      first two can never be blocked anyway?)  */

   sigbus_new.ksa_handler = valid_addr_handler;
   sigbus_new.sa_flags = VKI_SA_ONSTACK | VKI_SA_RESTART;
   sigbus_new.sa_restorer = NULL;
   res = VG_(sigemptyset)( &sigbus_new.sa_mask );
   vg_assert(res == 0);

   sigsegv_new.ksa_handler = valid_addr_handler;
   sigsegv_new.sa_flags = VKI_SA_ONSTACK | VKI_SA_RESTART;
   sigsegv_new.sa_restorer = NULL;
   res = VG_(sigemptyset)( &sigsegv_new.sa_mask );
   vg_assert(res == 0+0);

   res =  VG_(sigemptyset)( &unblockmask_new );
   res |= VG_(sigaddset)( &unblockmask_new, VKI_SIGBUS );
   res |= VG_(sigaddset)( &unblockmask_new, VKI_SIGSEGV );
   res |= VG_(sigaddset)( &unblockmask_new, VKI_SIGTERM );
   vg_assert(res == 0+0+0);

   res = VG_(sigaction)( VKI_SIGBUS, &sigbus_new, &sigbus_saved );
   vg_assert(res == 0+0+0+0);

   res = VG_(sigaction)( VKI_SIGSEGV, &sigsegv_new, &sigsegv_saved );
   vg_assert(res == 0+0+0+0+0);

   res = VG_(sigprocmask)( VKI_SIG_UNBLOCK, &unblockmask_new, &blockmask_saved );
   vg_assert(res == 0+0+0+0+0+0);
}

static void restore_signals(void)
{
   Int res;

   /* Restore signal state to whatever it was before. */
   res = VG_(sigaction)( VKI_SIGBUS, &sigbus_saved, NULL );
   vg_assert(res == 0 +0);

   res = VG_(sigaction)( VKI_SIGSEGV, &sigsegv_saved, NULL );
   vg_assert(res == 0 +0 +0);

   res = VG_(sigprocmask)( VKI_SIG_SETMASK, &blockmask_saved, NULL );
   vg_assert(res == 0 +0 +0 +0);
}

/* if false, setup and restore signals for every access */
#define LAZYSIG		1

static Bool is_valid_addr(Addr a)
{
   static SymType faulted = { TyError };
   static const Bool debug = False;
   volatile Bool ret = False;

   if ((a > VKI_PAGE_SIZE) && !test_visited(a, &faulted)) {
      if (!LAZYSIG)
	 setup_signals();
   
      if (__builtin_setjmp(valid_addr_jmpbuf) == 0) {
	 volatile UInt *volatile ptr = (volatile UInt *)a;

	 *ptr;

	 ret = True;
      } else {
	 /* cache bad addresses in visited table */
	 has_visited(a, &faulted);
	 ret = False;
      }

      if (!LAZYSIG)
	 restore_signals();
   }

   if (debug)
      VG_(printf)("is_valid_addr(%p) -> %d\n", a, ret);

   return ret;
}

static Int free_varlist(Variable *list)
{
   Variable *next;
   Int count = 0;

   for(; list != NULL; list = next) {
      next = list->next;
      count++;
      if (list->name)
	 VG_(arena_free)(VG_AR_SYMTAB, list->name);
      VG_(arena_free)(VG_AR_SYMTAB, list);
   }
   return count;
}

/* Composite: struct, union, array
   Non-composite: everything else
 */
static inline Bool is_composite(SymType *ty)
{
   switch(ty->kind) {
   case TyUnion:
   case TyStruct:
   case TyArray:
      return True;

   default:
      return False;
   }
}

/* There's something at the end of the rainbow */
static inline Bool is_followable(SymType *ty)
{
   return ty->kind == TyPointer || is_composite(ty);
}

/* Result buffer */
static Char *describe_addr_buf;
static UInt describe_addr_bufidx;
static UInt describe_addr_bufsz;

/* Add a character to the result buffer */
static void describe_addr_addbuf(HChar c,void *p) {
   if ((describe_addr_bufidx+1) >= describe_addr_bufsz) {
      Char *n;
    
      if (describe_addr_bufsz == 0)
         describe_addr_bufsz = 8;
      else
         describe_addr_bufsz *= 2;
    
      /* use tool malloc so that the tool can free it */
      n = VG_(malloc)(describe_addr_bufsz);
      if (describe_addr_buf != NULL && describe_addr_bufidx != 0)
         VG_(memcpy)(n, describe_addr_buf, describe_addr_bufidx);
      if (describe_addr_buf != NULL)
         VG_(free)(describe_addr_buf);
      describe_addr_buf = n;
   }
   describe_addr_buf[describe_addr_bufidx++] = c;
   describe_addr_buf[describe_addr_bufidx] = '\0';
}

#define MAX_PLY		7	/* max depth we go */
#define MAX_ELEMENTS	5000	/* max number of array elements we scan */
#define MAX_VARS	10000	/* max number of variables total traversed */

static const Bool memaccount = False; /* match creates to frees */
static const Bool debug = False;

/* Add a new variable to the list */
static Bool newvar(Char *name, SymType *ty, Addr valuep, UInt size,
                   Variable *var, Int *numvars, Int *created,
                   Variable **newlist, Variable **newlistend) {
   Variable *v;

   /* have we been here before? */
   if (has_visited(valuep, ty))
      return False;
	    
   /* are we too deep? */
   if (var->distance > MAX_PLY)
      return False;

   /* have we done too much? */
   if ((*numvars)-- == 0)
      return False;

   if (memaccount)
      (*created)++;
	    
   v = VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(*v));

   if (name)
      v->name = VG_(arena_strdup)(VG_AR_SYMTAB, name);
   else
      v->name = NULL;
   v->type = ML_(st_basetype)(ty, False);
   v->valuep = valuep;
   v->size = size == -1 ? ty->size : size;
   v->container = var;
   v->distance = var->distance + 1;
   v->next = NULL;

   if (*newlist == NULL)
      *newlist = *newlistend = v;
   else {
      (*newlistend)->next = v;
      *newlistend = v;
   }
	    
   if (debug)
      VG_(printf)("    --> %d: name=%s type=%p(%s %s) container=%p &val=%p\n", 
                  v->distance, v->name, v->type, ppkind(v->type->kind), 
                  v->type->name ? (char *)v->type->name : "",
                  v->container, v->valuep);
   return True;
}

static void genstring(Variable *v, Variable *inner, Int *len, Char **ep,
                      Char **sp) {
   Variable *c = v->container;

   if (c != NULL)
      genstring(c, v, len, ep, sp);

   if (v->name != NULL) {
      *len = VG_(strlen)(v->name);
      VG_(memcpy)(*ep, v->name, *len);
      (*ep) += *len;
   }

   switch(v->type->kind) {
   case TyPointer:
      /* pointer-to-structure/union handled specially */
      if (inner == NULL ||
          !(inner->type->kind == TyStruct || inner->type->kind == TyUnion)) {
         *--(*sp) = '*';
         *--(*sp) = '(';
	 *(*ep)++ = ')';
      }
      break;

   case TyStruct:
   case TyUnion:
      if (c && c->type->kind == TyPointer) {
         *(*ep)++ = '-';
         *(*ep)++ = '>';
      } else
         *(*ep)++ = '.';
      break;

   default:
      break;
   }
}

Char *VG_(describe_addr)(ThreadId tid, Addr addr)
{
   Addr eip;			/* thread's EIP */
   Variable *list;		/* worklist */
   Variable *keeplist;		/* container variables */
   Variable *found;		/* the chain we found */
   Int created=0, freed=0;
   Int numvars = MAX_VARS;

   describe_addr_buf = NULL;
   describe_addr_bufidx = 0;
   describe_addr_bufsz = 0;

   clear_visited();

   found = NULL;
   keeplist = NULL;

   eip = VG_(get_IP)(tid);
   list = ML_(get_scope_variables)(tid);

   if (memaccount) {
      Variable *v;

      for(v = list; v != NULL; v = v->next)
	 created++;
   }

   if (debug) {
      Char file[100];
      Int line;
      if (!VG_(get_filename_linenum)(eip, file, sizeof(file), 
                                          NULL, 0, NULL, &line))
	 file[0] = 0;
      VG_(printf)("describing address %p for tid=%d @ %s:%d\n", addr, tid, file, line);
   }

   if (LAZYSIG)
      setup_signals();

   /* breadth-first traversal of all memory visible to the program at
      the current point */
   while(list != NULL && found == NULL) {
      Variable **prev = &list;
      Variable *var, *next;
      Variable *newlist = NULL, *newlistend = NULL;

      if (debug)
	 VG_(printf)("----------------------------------------\n");

      for(var = list; var != NULL; var = next) {
	 SymType *type = var->type;
	 Bool keep = False;

	 next = var->next;

	 if (debug)
	    VG_(printf)("  %d: name=%s type=%p(%s %s) container=%p &val=%p\n", 
			var->distance, var->name, 
			var->type, ppkind(var->type->kind), 
			var->type->name ? (char *)var->type->name : "",
			var->container, var->valuep);
   
	 if (0 && has_visited(var->valuep, var->type)) {
	    /* advance prev; we're keeping this one on the doomed list */
	    prev = &var->next;
	    continue;
	 }

	 if (!is_composite(var->type) && 
	     addr >= var->valuep && addr < (var->valuep + var->size)) {
	    /* at hit - remove it from the list, add it to the
	       keeplist and set found */
	    found = var;
	    *prev = var->next;
	    var->next = keeplist;
	    keeplist = var;
	    break;
	 }

	 type = ML_(st_basetype)(type, True);
	 
	 switch(type->kind) {
	 case TyUnion:
	 case TyStruct: {
	    Int i;

	    if (debug)
	       VG_(printf)("    %d fields\n", type->u.t_struct.nfield);
	    for(i = 0; i < type->u.t_struct.nfield; i++) {
	       StField *f = &type->u.t_struct.fields[i];
	       if(newvar(f->name, f->type, var->valuep + (f->offset / 8),
                         (f->size + 7) / 8, var, &numvars, &created, &newlist,
                         &newlistend))
                  keep = True;
	    }
	    break;
	 }

	 case TyArray: {
	    Int i; 
	    Int offset;		/* offset of index for non-0-based arrays */
	    Int min, max;	/* range of indicies we care about (0 based) */
	    SymType *ty = type->u.t_array.type;
	    vg_assert(type->u.t_array.idxtype->kind == TyRange);

	    offset = type->u.t_array.idxtype->u.t_range.min;
	    min = 0;
	    max = type->u.t_array.idxtype->u.t_range.max - offset;

	    if ((max-min+1) == 0) {
#if SHADOWCHUNK
	       /* zero-sized array - look at allocated memory */
	       ShadowChunk *sc = findchunk(var->valuep);

	       if (sc != NULL) {
		  max = ((sc->data + sc->size - var->valuep) / ty->size) + min;
		  if (debug)
		     VG_(printf)("    zero sized array: using min=%d max=%d\n",
				 min, max);
	       }
#endif
	    }

	    /* If this array's elements can't take us anywhere useful,
	       just look to see if an element itself is being pointed
	       to; otherwise just skip the whole thing */
	    if (!is_followable(ty)) {
	       UInt sz = ty->size * (max+1);

	       if (debug)
		  VG_(printf)("    non-followable array (sz=%d): checking addr %p in range %p-%p\n",
			      sz, addr, var->valuep, (var->valuep + sz));
	       if (ty->size > 0 && addr >= var->valuep && addr <= (var->valuep + sz))
		  min = max = (addr - var->valuep) / ty->size;
	       else
		  break;
	    }

	    /* truncate array if it's too big */
	    if (max-min+1 > MAX_ELEMENTS)
	       max = min+MAX_ELEMENTS;
	    
	    if (debug)
	       VG_(printf)("    array index %d - %d\n", min, max);
	    for(i = min; i <= max; i++) {
	       Char b[10];
	       VG_(sprintf)(b, "[%d]", i+offset);
	       if(newvar(b, ty, var->valuep + (i * ty->size), -1, var,
                         &numvars, &created, &newlist, &newlistend))
                  keep = True;
	    }

	    break;
	 }

	 case TyPointer:
	    /* follow */
	    /* XXX work out a way of telling whether a pointer is
	       actually a decayed array, and treat it accordingly */
	    if (is_valid_addr(var->valuep))
	       if(newvar(NULL, type->u.t_pointer.type, *(Addr *)var->valuep,
                         -1, var, &numvars, &created, &newlist, &newlistend))
                  keep = True;
	    break;

	 case TyUnresolved:
	    VG_(printf)("var %s is unresolved (type=%p)\n", var->name, type);
	    break;

	 default:
	    /* Simple non-composite, non-pointer type */
	    break;
	 }
	 
	 if (keep) {
	    /* ironically, keep means remove it from the list */
	    *prev = next;
	    
	    /* being kept - add it if not already there */
	    if (keeplist != var) {
	       var->next = keeplist;
	       keeplist = var;
	    }
	 } else {
	    /* advance prev; we're keeping it on the doomed list */
	    prev = &var->next;
	 }
      }

      /* kill old list */
      freed += free_varlist(list);
      list = NULL;

      if (found) {
	 /* kill new list too */
	 freed += free_varlist(newlist);
	 newlist = newlistend = NULL;
      } else {
	 /* new list becomes old list */
	 list = newlist;
      }
   }

   if (LAZYSIG)
      restore_signals();

   if (found != NULL) {
      Int len = 0;
      Char file[100];
      Int line;

      /* Try to generate an idiomatic C-like expression from what
	 we've found. */

      {
	 Variable *v;
	 for(v = found; v != NULL; v = v->container) {
	    if (debug)
	       VG_(printf)("v=%p (%s) %s\n",
			   v, v->name ? v->name : (Char *)"",
			   ppkind(v->type->kind));
	    
	    len += (v->name ? VG_(strlen)(v->name) : 0) + 5;
	 }
      }

      /* now that we know how long the expression will be
	 (approximately) build it up */
      {
	 Char expr[len*2];
	 Char *sp = &expr[len];	/* pointer at start of string */
	 Char *ep = sp;		/* pointer at end of string */
	 Bool ptr = True;

	 /* If the result is already a pointer, just use that as the
            value, otherwise generate &(...) around the expression. */
         if (found->container && found->container->type->kind == TyPointer) {
            vg_assert(found->name == NULL);

	    found->name = found->container->name;
	    found->container->name = NULL;
	    found->container = found->container->container;
	 } else {
            bprintf(describe_addr_addbuf, 0, "&(");
	    ptr = False;
	 }

	 genstring(found, NULL, &len, &ep, &sp);

	 if (!ptr)
	    *ep++ = ')';

	 *ep++ = '\0';

	 bprintf(describe_addr_addbuf, 0, sp);

	 if (addr != found->valuep)
	    bprintf(describe_addr_addbuf, 0, "+%d", addr - found->valuep);

	 if (VG_(get_filename_linenum)(eip, file, sizeof(file), 
                                            NULL, 0, NULL, &line))
	    bprintf(describe_addr_addbuf, 0, " at %s:%d", file, line, addr);
      }
   }

   freed += free_varlist(keeplist);

   if (memaccount)
      VG_(printf)("created %d, freed %d\n", created, freed);

   clear_visited();

   if (debug)
      VG_(printf)("returning buf=%s\n", describe_addr_buf);

   return describe_addr_buf;
}
#endif /* TEST */

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*--- Header for symbol table stuff.                 priv_symtab.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2000-2005 Julian Seward
      jseward@acm.org

   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.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __PRIV_SYMTAB_H
#define __PRIV_SYMTAB_H

/* A structure to hold an ELF symbol (very crudely). */
typedef 
   struct { 
      Addr addr;   /* lowest address of entity */
      UInt size;   /* size in bytes */
      Char *name;  /* name */
      Addr tocptr; /* ppc64-linux only: value that R2 should have */
   }
   RiSym;

/* Line count at which overflow happens, due to line numbers being stored as
 * shorts in `struct nlist' in a.out.h. */
#define LINENO_OVERFLOW (1 << (sizeof(short) * 8))

#define LINENO_BITS     20
#define LOC_SIZE_BITS  (32 - LINENO_BITS)
#define MAX_LINENO     ((1 << LINENO_BITS) - 1)

/* Unlikely to have any lines with instruction ranges > 4096 bytes */
#define MAX_LOC_SIZE   ((1 << LOC_SIZE_BITS) - 1)

/* Number used to detect line number overflows;  if one line is 60000-odd
 * smaller than the previous, is was probably an overflow.  
 */
#define OVERFLOW_DIFFERENCE     (LINENO_OVERFLOW - 5000)

/* A structure to hold addr-to-source info for a single line.  There can be a
 * lot of these, hence the dense packing. */
typedef
   struct {
      /* Word 1 */
      Addr   addr;                  /* lowest address for this line */
      /* Word 2 */
      UShort size:LOC_SIZE_BITS;    /* byte size; we catch overflows of this */
      UInt   lineno:LINENO_BITS;    /* source line number, or zero */
      /* Word 3 */
      Char*  filename;              /* source filename */
      /* Word 4 */
      Char*  dirname;               /* source directory name */
   }
   RiLoc;


/* A structure to hold a set of variables in a particular scope */
typedef struct _Scope Scope;	/* a set of symbols in one scope */
typedef struct _Sym Sym;	/* a single symbol */
typedef struct _ScopeRange ScopeRange; /* a range of code addreses a scope covers */

typedef enum {
      SyESPrel,			/* on the stack (relative to ESP) */
      SyEBPrel,			/* on the stack (relative to EBP) */
      SyReg,			/* in a register */
      SyType,			/* a type definition */
      SyStatic,			/* a static variable */
      SyGlobal,			/* a global variable (XXX any different to static
				   in an outer scope?) */
} SyKind;

struct _Sym {
   SymType	*type;		/* type */
   Char		*name;		/* name */
   SyKind	kind;		/* kind of symbol */

   /* a value, depending on kind */
   union {
      OffT	offset;		/* offset on stack (-ve -> ebp; +ve -> esp) */
      Int	regno;		/* register number */
      Addr	addr;		/* static or global address */
   } u;
};

struct _Scope {
   Scope	*outer;		/* outer (containing) scope */
   UInt		nsyms;		/* number of symbols in this scope */
   UInt		depth;		/* depth of scope */
   Sym	        *syms;		/* the symbols */
};

/* A structure to map a scope to a range of code addresses; scopes may
   be broken into multiple ranges (before and after a nested scope) */
struct _ScopeRange {
   Addr		addr;			/* start address of this scope */
   Int		size;			/* length of scope */
   Scope       *scope;			/* symbols in scope */
};

#define STRCHUNKSIZE	(64*1024)


/* A structure to summarise CFI summary info for the code address
   range [base .. base+len-1].  In short, if you know (sp,fp,ip) at
   some point and ip is in the range [base .. base+len-1], it tells
   you how to calculate (sp,fp) for the caller of the current
   frame and also ra, the return address of the current frame.

   First off, calculate CFA, the Canonical Frame Address, thusly:

     cfa = if cfa_sprel then sp+cfa_off else fp+cfa_off

   Once that is done, the previous frame's sp/fp values and this
   frame's ra value can be calculated like this:

      old_sp/fp/ra
         = case sp/fp/ra_how of
              CFIR_UNKNOWN   -> we don't know, sorry
              CFIR_SAME      -> same as it was before (sp/fp only)
              CFIR_CFAREL    -> cfa + sp/fp/ra_off
              CFIR_MEMCFAREL -> *( cfa + sp/fp/ra_off )
*/

#define CFIR_UNKNOWN   ((UChar)0)
#define CFIR_SAME      ((UChar)1)
#define CFIR_CFAREL    ((UChar)2)
#define CFIR_MEMCFAREL ((UChar)3)

typedef
   struct {
      Addr  base;
      UInt  len;
      Bool  cfa_sprel;
      UChar ra_how; /* a CFIR_ value */
      UChar sp_how; /* a CFIR_ value */
      UChar fp_how; /* a CFIR_ value */
      Int   cfa_off;
      Int   ra_off;
      Int   sp_off;
      Int   fp_off;
   }
   CfiSI;

extern void ML_(ppCfiSI)   ( CfiSI* );


/* A structure which contains information pertaining to one mapped
   text segment.  This type is exported only abstractly - in
   pub_tool_debuginfo.h. */
struct _SegInfo {
   struct _SegInfo* next;	/* list of SegInfos */

   Int	  ref;

   /* Description of the mapped segment. */
   Addr   start;
   UInt   size;
   Char*  filename; /* in mallocville */
   OffT   foffset;
   Char*  soname;

   /* An expandable array of symbols. */
   RiSym* symtab;
   UInt   symtab_used;
   UInt   symtab_size;
   /* An expandable array of locations. */
   RiLoc* loctab;
   UInt   loctab_used;
   UInt   loctab_size;
   /* An expandable array of scope ranges. */
   ScopeRange *scopetab;
   UInt        scopetab_used;
   UInt        scopetab_size;
   /* An expandable array of CFI summary info records.  Also includes
      summary address bounds, showing the min and max address covered
      by any of the records, as an aid to fast searching. */
   CfiSI* cfisi;
   UInt   cfisi_used;
   UInt   cfisi_size;
   Addr   cfisi_minaddr;
   Addr   cfisi_maxaddr;

   /* Expandable arrays of characters -- the string table.
      Pointers into this are stable (the arrays are not reallocated)
    */
   struct strchunk {
      UInt   strtab_used;
      struct strchunk *next;
      Char   strtab[STRCHUNKSIZE];
   }      *strchunks;

   /* offset    is what we need to add to symbol table entries
      to get the real location of that symbol in memory.
   */
   OffT   offset;

   /* Bounds of data, BSS, PLT, GOT and OPD (for ppc64-linux) so that
      tools can see what section an address is in.  In the running image! */
   Addr	  plt_start_vma;
   UInt   plt_size;
   Addr   got_start_vma;
   UInt   got_size;
   Addr   opd_start_vma;
   UInt   opd_size;
   Addr   data_start_vma;
   UInt   data_size;
   Addr   bss_start_vma;
   UInt   bss_size;

   /* data used by stabs parser */
   struct _StabTypeTab	*stab_typetab;
};

extern
Char *ML_(addStr) ( SegInfo* si, Char* str, Int len );

extern
void ML_(addScopeInfo) ( SegInfo* si, Addr this, Addr next, Scope *scope);

extern
void ML_(addLineInfo) ( SegInfo* si, 
                        Char* filename, 
                        Char* dirname,  /* NULL is allowable */
                        Addr this, Addr next, Int lineno, Int entry);

extern
void ML_(addCfiSI) ( SegInfo* si, CfiSI* cfisi );

/* Non-fatal -- use vg_panic if terminal. */
extern
void ML_(symerr) ( Char* msg );

/* --------------------
   Stabs reader
   -------------------- */
extern
void ML_(read_debuginfo_stabs) ( SegInfo* si,
				 UChar* stabC,   Int stab_sz, 
				 UChar* stabstr, Int stabstr_sz );

/* --------------------
   DWARF2 reader
   -------------------- */
extern
void ML_(read_debuginfo_dwarf2) 
        ( SegInfo* si,
          UChar* debuginfo,   Int debug_info_sz,  /* .debug_info */
          UChar* debugabbrev,                     /* .debug_abbrev */
          UChar* debugline,   Int debug_line_sz,  /* .debug_line */
          UChar* debugstr );

/* --------------------
   DWARF1 reader
   -------------------- */
extern
void ML_(read_debuginfo_dwarf1) ( SegInfo* si, 
                                  UChar* dwarf1d, Int dwarf1d_sz, 
                                  UChar* dwarf1l, Int dwarf1l_sz );

/* --------------------
   CFI reader
   -------------------- */
extern
void ML_(read_callframe_info_dwarf2) 
    ( /*OUT*/SegInfo* si, UChar* ehframe, Int ehframe_sz, Addr ehframe_addr );


#endif   // __PRIV_SYMTAB_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*--- Intra-Valgrind interfaces for symtypes.c.    priv_symtypes.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2000-2005 Julian Seward
      jseward@acm.org

   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.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __PRIV_SYMTYPES_H
#define __PRIV_SYMTYPES_H

/* Lets try to make these opaque */
typedef struct _SymType SymType;

/* ------------------------------------------------------------
   Constructors for various SymType nodes
   ------------------------------------------------------------ */

/* Find the basetype for a given type: that is, if type is a typedef,
   return the typedef'd type.  If resolve is true, it will resolve
   unresolved symbols.  If type is not a typedef, then this is just
   returns type.
*/
SymType *ML_(st_basetype)(SymType *type, Bool resolve);

void ML_(st_setname)(SymType *ty, Char *name);

typedef void (SymResolver)(SymType *, void *);

/* Create an unresolved type */
SymType *ML_(st_mkunresolved)(SymType *, SymResolver *resolve, void *data);

/* update an unresolved type's data */
void ML_(st_unresolved_setdata)(SymType *, SymResolver *resolve, void *data);

Bool ML_(st_isresolved)(SymType *);
UInt ML_(st_sizeof)(SymType *);

/* Unknown type (unparsable) */
SymType *ML_(st_mkunknown)(SymType *);

SymType *ML_(st_mkvoid)(SymType *);

SymType *ML_(st_mkint)(SymType *, UInt size, Bool isSigned);
SymType *ML_(st_mkbool)(SymType *, UInt size);
SymType *ML_(st_mkchar)(SymType *, Bool isSigned);
SymType *ML_(st_mkfloat)(SymType *, UInt size);
SymType *ML_(st_mkdouble)(SymType *, UInt size);

SymType *ML_(st_mkpointer)(SymType *, SymType *);
SymType *ML_(st_mkrange)(SymType *, SymType *, Int min, Int max);

SymType *ML_(st_mkstruct)(SymType *, UInt size, UInt nfields);
SymType *ML_(st_mkunion)(SymType *, UInt size, UInt nfields);
void ML_(st_addfield)(SymType *, Char *name, SymType *, UInt off, UInt size);

SymType *ML_(st_mkenum)(SymType *, UInt ntags);
SymType *ML_(st_addtag)(SymType *, Char *name, Int val);

SymType *ML_(st_mkarray)(SymType *, SymType *idxtype, SymType *artype);

SymType *ML_(st_mktypedef)(SymType *, Char *name, SymType *type);

Bool ML_(st_isstruct)(SymType *);
Bool ML_(st_isunion)(SymType *);
Bool ML_(st_isenum)(SymType *);

/* ------------------------------------------------------------
   Interface with symtab.c
   ------------------------------------------------------------ */

/* Typed value */
typedef struct _Variable Variable;

struct _Variable {
   Char		*name;		/* name */
   SymType	*type;		/* type of value */
   Addr		valuep;		/* pointer to value */
   UInt		size;		/* size of value */
   UInt		distance;	/* "distance" from site of interest */
   Variable	*next;
   Variable	*container;
};

Variable *ML_(get_scope_variables)(ThreadId tid);

#endif // __PRIV_SYMTYPES_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/