Link ttydrv and x11drv objects into their respective dll.
[wine/multimedia.git] / debugger / types.c
blob64f12905fbf71af1c1cf993ecec69a7b3a4b8603
1 /*
2 * File types.c - datatype handling stuff for internal debugger.
4 * Copyright (C) 1997, Eric Youngdale.
6 * This really doesn't do much at the moment, but it forms the framework
7 * upon which full support for datatype handling will eventually be hung.
8 */
10 #include "config.h"
11 #include <stdio.h>
12 #include <stdlib.h>
14 #include <fcntl.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <limits.h>
18 #include <string.h>
19 #include <unistd.h>
21 #include "pe_image.h"
22 #include "peexe.h"
23 #include "debugger.h"
25 #define NR_TYPE_HASH 521
27 int DEBUG_nchar;
28 static int DEBUG_maxchar = 1024;
30 struct en_values
32 struct en_values* next;
33 char * name;
34 int value;
37 struct member
39 struct member * next;
40 char * name;
41 struct datatype * type;
42 int offset;
43 int size;
46 struct datatype
48 enum debug_type type;
49 struct datatype * next;
50 char * name;
51 union
53 struct
55 char basic_type;
56 char * output_format;
57 char basic_size;
58 unsigned b_signed:1;
59 } basic;
60 struct
62 unsigned short bitoff;
63 unsigned short nbits;
64 struct datatype * basetype;
65 } bitfield;
67 struct
69 struct datatype * pointsto;
70 } pointer;
71 struct
73 struct datatype * rettype;
74 } funct;
75 struct
77 int start;
78 int end;
79 struct datatype * basictype;
80 } array;
81 struct
83 int size;
84 struct member * members;
85 } structure;
86 struct
88 struct en_values * members;
89 } enumeration;
90 } un;
93 #define BASIC_INT 1
94 #define BASIC_CHAR 2
95 #define BASIC_LONG 3
96 #define BASIC_UINT 4
97 #define BASIC_LUI 5
98 #define BASIC_LONGLONG 6
99 #define BASIC_ULONGLONGI 7
100 #define BASIC_SHORT 8
101 #define BASIC_SHORTUI 9
102 #define BASIC_SCHAR 10
103 #define BASIC_UCHAR 11
104 #define BASIC_FLT 12
105 #define BASIC_LONG_DOUBLE 13
106 #define BASIC_DOUBLE 14
107 #define BASIC_CMPLX_INT 15
108 #define BASIC_CMPLX_FLT 16
109 #define BASIC_CMPLX_DBL 17
110 #define BASIC_CMPLX_LONG_DBL 18
111 #define BASIC_VOID 19
113 struct datatype * DEBUG_TypeInt = NULL;
114 struct datatype * DEBUG_TypeIntConst = NULL;
115 struct datatype * DEBUG_TypeUSInt = NULL;
116 struct datatype * DEBUG_TypeString = NULL;
119 * All of the types that have been defined so far.
121 static struct datatype * type_hash_table[NR_TYPE_HASH + 1];
122 static struct datatype * pointer_types = NULL;
124 static unsigned int type_hash( const char * name )
126 unsigned int hash = 0;
127 unsigned int tmp;
128 const char * p;
130 p = name;
132 while (*p)
134 hash = (hash << 4) + *p++;
136 if( (tmp = (hash & 0xf0000000)) )
138 hash ^= tmp >> 24;
140 hash &= ~tmp;
142 return hash % NR_TYPE_HASH;
146 static struct datatype *
147 DEBUG_InitBasic(int type, char * name, int size, int b_signed,
148 char * output_format)
150 int hash;
152 struct datatype * dt;
153 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
155 if( dt != NULL )
157 if( name != NULL )
159 hash = type_hash(name);
161 else
163 hash = NR_TYPE_HASH;
166 dt->type = DT_BASIC;
167 dt->name = name;
168 dt->next = type_hash_table[hash];
169 type_hash_table[hash] = dt;
170 dt->un.basic.basic_type = type;
171 dt->un.basic.basic_size = size;
172 dt->un.basic.b_signed = b_signed;
173 dt->un.basic.output_format = output_format;
176 return dt;
179 static
180 struct datatype *
181 DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename)
183 struct datatype * dt = NULL;
185 if( typename != NULL )
187 for( dt = type_hash_table[hash]; dt; dt = dt->next )
189 if( xtype != dt->type || dt->name == NULL
190 || dt->name[0] != typename[0])
192 continue;
195 if( strcmp(dt->name, typename) == 0 )
197 return dt;
202 return dt;
205 struct datatype *
206 DEBUG_NewDataType(enum debug_type xtype, const char * typename)
208 struct datatype * dt = NULL;
209 int hash;
212 * The last bucket is special, and is used to hold typeless names.
214 if( typename == NULL )
216 hash = NR_TYPE_HASH;
218 else
220 hash = type_hash(typename);
223 dt = DEBUG_LookupDataType(xtype, hash, typename);
225 if( dt == NULL )
227 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
229 if( dt != NULL )
231 memset(dt, 0, sizeof(*dt));
233 dt->type = xtype;
234 if( typename != NULL )
236 dt->name = DBG_strdup(typename);
238 else
240 dt->name = NULL;
242 if( xtype == DT_POINTER )
244 dt->next = pointer_types;
245 pointer_types = dt;
247 else
249 dt->next = type_hash_table[hash];
250 type_hash_table[hash] = dt;
255 return dt;
258 struct datatype *
259 DEBUG_FindOrMakePointerType(struct datatype * reftype)
261 struct datatype * dt = NULL;
263 if( reftype != NULL )
265 for( dt = pointer_types; dt; dt = dt->next )
267 if( dt->type != DT_POINTER )
269 continue;
272 if( dt->un.pointer.pointsto == reftype )
274 return dt;
279 if( dt == NULL )
281 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
283 if( dt != NULL )
285 dt->type = DT_POINTER;
286 dt->un.pointer.pointsto = reftype;
287 dt->next = pointer_types;
288 pointer_types = dt;
292 return dt;
295 void
296 DEBUG_InitTypes(void)
298 static int beenhere = 0;
299 struct datatype * chartype;
301 if( beenhere++ != 0 )
303 return;
307 * Special version of int used with constants of various kinds.
309 DEBUG_TypeIntConst = DEBUG_InitBasic(BASIC_INT,NULL,4,1,"%d");
312 * Initialize a few builtin types.
315 DEBUG_TypeInt = DEBUG_InitBasic(BASIC_INT,"int",4,1,"%d");
316 chartype = DEBUG_InitBasic(BASIC_CHAR,"char",1,1,"'%c'");
317 DEBUG_InitBasic(BASIC_LONG,"long int",4,1,"%d");
318 DEBUG_TypeUSInt = DEBUG_InitBasic(BASIC_UINT,"unsigned int",4,0,"%d");
319 DEBUG_InitBasic(BASIC_LUI,"long unsigned int",4,0,"%d");
320 DEBUG_InitBasic(BASIC_LONGLONG,"long long int",8,1,"%ld");
321 DEBUG_InitBasic(BASIC_ULONGLONGI,"long long unsigned int",8,0,"%ld");
322 DEBUG_InitBasic(BASIC_SHORT,"short int",2,1,"%d");
323 DEBUG_InitBasic(BASIC_SHORTUI,"short unsigned int",2,0,"%d");
324 DEBUG_InitBasic(BASIC_SCHAR,"signed char",1,1,"'%c'");
325 DEBUG_InitBasic(BASIC_UCHAR,"unsigned char",1,0,"'%c'");
326 DEBUG_InitBasic(BASIC_FLT,"float",4,0,"%f");
327 DEBUG_InitBasic(BASIC_LONG_DOUBLE,"double",8,0,"%lf");
328 DEBUG_InitBasic(BASIC_DOUBLE,"long double",12,0,NULL);
329 DEBUG_InitBasic(BASIC_CMPLX_INT,"complex int",8,1,NULL);
330 DEBUG_InitBasic(BASIC_CMPLX_FLT,"complex float",8,0,NULL);
331 DEBUG_InitBasic(BASIC_CMPLX_DBL,"complex double",16,0,NULL);
332 DEBUG_InitBasic(BASIC_CMPLX_LONG_DBL,"complex long double",24,0,NULL);
333 DEBUG_InitBasic(BASIC_VOID,"void",0,0,NULL);
335 DEBUG_TypeString = DEBUG_NewDataType(DT_POINTER, NULL);
336 DEBUG_SetPointerType(DEBUG_TypeString, chartype);
339 * Now initialize the builtins for codeview.
341 DEBUG_InitCVDataTypes();
345 long long int
346 DEBUG_GetExprValue(const DBG_VALUE *_value, char ** format)
348 unsigned int rtn;
349 struct datatype * type2 = NULL;
350 struct en_values * e;
351 char * def_format = "0x%x";
352 DBG_VALUE value = *_value;
354 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
356 rtn = 0;
357 /* FIXME? I don't quite get this...
358 * if this is wrong, value.addr shall be linearized
360 value.addr.seg = 0;
361 assert(value.type != NULL);
363 switch(value.type->type)
365 case DT_BASIC:
367 rtn = 0;
368 /* FIXME: following code implies i386 byte ordering */
369 if (_value->cookie == DV_TARGET) {
370 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn,
371 value.type->un.basic.basic_size))
372 return 0;
373 } else {
374 memcpy(&rtn, (void*)value.addr.off, value.type->un.basic.basic_size);
377 if( (value.type->un.basic.b_signed)
378 && ((value.type->un.basic.basic_size & 3) != 0)
379 && ((rtn >> (value.type->un.basic.basic_size * 8 - 1)) != 0) )
381 rtn = rtn | ((-1) << (value.type->un.basic.basic_size * 8));
383 if( value.type->un.basic.output_format != NULL )
385 def_format = value.type->un.basic.output_format;
389 * Check for single character prints that are out of range.
391 if( value.type->un.basic.basic_size == 1
392 && strcmp(def_format, "'%c'") == 0
393 && ((rtn < 0x20) || (rtn > 0x80)) )
395 def_format = "%d";
397 break;
398 case DT_POINTER:
399 if (_value->cookie == DV_TARGET) {
400 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(void*)))
401 return 0;
402 } else {
403 rtn = *(unsigned int*)(value.addr.off);
406 type2 = value.type->un.pointer.pointsto;
408 if (!type2)
410 def_format = "Internal symbol error: unable to access memory location 0x%08x";
411 rtn = 0;
412 break;
415 if( type2->type == DT_BASIC && type2->un.basic.basic_size == 1 )
417 if ( _value->cookie == DV_TARGET ) {
418 char ch;
419 def_format = "\"%S\"";
420 if (!DEBUG_READ_MEM_VERBOSE((void*)rtn, &ch, 1))
421 return 0;
422 } else {
423 def_format = "\"%s\"";
426 else
428 def_format = "0x%8.8x";
430 break;
431 case DT_ARRAY:
432 case DT_STRUCT:
433 assert(_value->cookie == DV_TARGET);
434 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(rtn)))
435 return 0;
436 def_format = "0x%8.8x";
437 break;
438 case DT_ENUM:
439 assert(_value->cookie == DV_TARGET);
440 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(rtn)))
441 return 0;
442 for(e = value.type->un.enumeration.members; e; e = e->next )
444 if( e->value == rtn )
446 break;
449 if( e != NULL )
451 rtn = (int) e->name;
452 def_format = "%s";
454 else
456 def_format = "%d";
458 break;
459 default:
460 rtn = 0;
461 break;
465 if( format != NULL )
467 *format = def_format;
469 return rtn;
472 unsigned int
473 DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype)
475 DBG_ADDR addr = value->addr;
476 unsigned int val;
478 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
480 *newtype = NULL;
483 * Make sure that this really makes sense.
485 if( value->type->type != DT_POINTER )
486 return 0;
488 if (value->cookie == DV_TARGET) {
489 if (!DEBUG_READ_MEM((void*)value->addr.off, &val, sizeof(val)))
490 return 0;
491 } else {
492 val = *(unsigned int*)value->addr.off;
495 *newtype = value->type->un.pointer.pointsto;
496 addr.off = val;
497 return DEBUG_ToLinear(&addr); /* FIXME: is this right (or "better") ? */
500 unsigned int
501 DEBUG_FindStructElement(DBG_VALUE* value, const char * ele_name, int * tmpbuf)
503 struct member * m;
504 unsigned int mask;
506 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
509 * Make sure that this really makes sense.
511 if( value->type->type != DT_STRUCT )
513 value->type = NULL;
514 return FALSE;
517 for(m = value->type->un.structure.members; m; m = m->next)
519 if( strcmp(m->name, ele_name) == 0 )
521 value->type = m->type;
522 if( (m->offset & 7) != 0 || (m->size & 7) != 0)
525 * Bitfield operation. We have to extract the field and store
526 * it in a temporary buffer so that we get it all right.
528 *tmpbuf = ((*(int* ) (value->addr.off + (m->offset >> 3))) >> (m->offset & 7));
529 value->addr.off = (int) tmpbuf;
531 mask = 0xffffffff << (m->size);
532 *tmpbuf &= ~mask;
534 * OK, now we have the correct part of the number.
535 * Check to see whether the basic type is signed or not, and if so,
536 * we need to sign extend the number.
538 if( m->type->type == DT_BASIC && m->type->un.basic.b_signed != 0
539 && (*tmpbuf & (1 << (m->size - 1))) != 0 )
541 *tmpbuf |= mask;
544 else
546 value->addr.off += (m->offset >> 3);
548 return TRUE;
552 value->type = NULL;
553 return FALSE;
557 DEBUG_SetStructSize(struct datatype * dt, int size)
559 assert(dt->type == DT_STRUCT);
561 if( dt->un.structure.members != NULL )
563 return FALSE;
566 dt->un.structure.size = size;
567 dt->un.structure.members = NULL;
569 return TRUE;
573 DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2)
576 assert( dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM)));
578 if( dt->type == DT_STRUCT )
580 dt->un.structure.members = dt2->un.structure.members;
582 else
584 dt->un.enumeration.members = dt2->un.enumeration.members;
587 return TRUE;
591 DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type,
592 int offset, int size)
594 struct member * m;
595 struct member * last;
596 struct en_values * e;
598 if( dt->type == DT_STRUCT )
600 for(last = dt->un.structure.members; last; last = last->next)
602 if( (last->name[0] == name[0])
603 && (strcmp(last->name, name) == 0) )
605 return TRUE;
607 if( last->next == NULL )
609 break;
612 m = (struct member *) DBG_alloc(sizeof(struct member));
613 if( m == FALSE )
615 return FALSE;
618 m->name = DBG_strdup(name);
619 m->type = type;
620 m->offset = offset;
621 m->size = size;
622 if( last == NULL )
624 m->next = dt->un.structure.members;
625 dt->un.structure.members = m;
627 else
629 last->next = m;
630 m->next = NULL;
633 * If the base type is bitfield, then adjust the offsets here so that we
634 * are able to look things up without lots of falter-all.
636 if( type->type == DT_BITFIELD )
638 m->offset += m->type->un.bitfield.bitoff;
639 m->size = m->type->un.bitfield.nbits;
640 m->type = m->type->un.bitfield.basetype;
643 else if( dt->type == DT_ENUM )
645 e = (struct en_values *) DBG_alloc(sizeof(struct en_values));
646 if( e == FALSE )
648 return FALSE;
651 e->name = DBG_strdup(name);
652 e->value = offset;
653 e->next = dt->un.enumeration.members;
654 dt->un.enumeration.members = e;
656 else
658 assert(FALSE);
660 return TRUE;
663 struct datatype *
664 DEBUG_GetPointerType(struct datatype * dt)
666 if( dt->type == DT_POINTER )
668 return dt->un.pointer.pointsto;
671 return NULL;
675 DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2)
677 switch(dt->type)
679 case DT_POINTER:
680 dt->un.pointer.pointsto = dt2;
681 break;
682 case DT_FUNC:
683 dt->un.funct.rettype = dt2;
684 break;
685 default:
686 assert(FALSE);
689 return TRUE;
693 DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2)
695 assert(dt->type == DT_ARRAY);
696 dt->un.array.start = min;
697 dt->un.array.end = max;
698 dt->un.array.basictype = dt2;
700 return TRUE;
704 DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits,
705 struct datatype * dt2)
707 assert(dt->type == DT_BITFIELD);
708 dt->un.bitfield.bitoff = offset;
709 dt->un.bitfield.nbits = nbits;
710 dt->un.bitfield.basetype = dt2;
712 return TRUE;
715 int DEBUG_GetObjectSize(struct datatype * dt)
717 if( dt == NULL )
719 return 0;
722 switch(dt->type)
724 case DT_BASIC:
725 return dt->un.basic.basic_size;
726 case DT_POINTER:
727 return sizeof(int *);
728 case DT_STRUCT:
729 return dt->un.structure.size;
730 case DT_ENUM:
731 return sizeof(int);
732 case DT_ARRAY:
733 return (dt->un.array.end - dt->un.array.start)
734 * DEBUG_GetObjectSize(dt->un.array.basictype);
735 case DT_BITFIELD:
737 * Bitfields have to be handled seperately later on
738 * when we insert the element into the structure.
740 return 0;
741 case DT_TYPEDEF:
742 case DT_FUNC:
743 case DT_CONST:
744 assert(FALSE);
746 return 0;
749 unsigned int
750 DEBUG_ArrayIndex(const DBG_VALUE * value, DBG_VALUE * result, int index)
752 int size;
754 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
757 * Make sure that this really makes sense.
759 if( value->type->type == DT_POINTER )
762 * Get the base type, so we know how much to index by.
764 size = DEBUG_GetObjectSize(value->type->un.pointer.pointsto);
765 result->type = value->type->un.pointer.pointsto;
766 result->addr.off = (*(unsigned int*) (value->addr.off)) + size * index;
768 else if (value->type->type == DT_ARRAY)
770 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
771 result->type = value->type->un.array.basictype;
772 result->addr.off = value->addr.off + size * (index - value->type->un.array.start);
775 return TRUE;
778 /***********************************************************************
779 * DEBUG_Print
781 * Implementation of the 'print' command.
783 void
784 DEBUG_Print( const DBG_VALUE *value, int count, char format, int level )
786 DBG_VALUE val1;
787 int i;
788 struct member * m;
789 char * pnt;
790 int size;
791 int xval;
793 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
795 if (count != 1)
797 fprintf( stderr, "Count other than 1 is meaningless in 'print' command\n" );
798 return;
801 if( value->type == NULL )
803 /* No type, just print the addr value */
804 if (value->addr.seg && (value->addr.seg != 0xffffffff))
805 DEBUG_nchar += fprintf( stderr, "0x%04lx: ", value->addr.seg );
806 DEBUG_nchar += fprintf( stderr, "0x%08lx", value->addr.off );
807 goto leave;
810 if( level == 0 )
812 DEBUG_nchar = 0;
815 if( DEBUG_nchar > DEBUG_maxchar )
817 fprintf(stderr, "...");
818 goto leave;
821 if( format == 'i' || format == 's' || format == 'w' || format == 'b' )
823 fprintf( stderr, "Format specifier '%c' is meaningless in 'print' command\n", format );
824 format = '\0';
827 switch(value->type->type)
829 case DT_BASIC:
830 case DT_ENUM:
831 case DT_CONST:
832 case DT_POINTER:
833 DEBUG_PrintBasic(value, 1, format);
834 break;
835 case DT_STRUCT:
836 DEBUG_nchar += fprintf(stderr, "{");
837 for(m = value->type->un.structure.members; m; m = m->next)
839 val1 = *value;
840 DEBUG_FindStructElement(&val1, m->name, &xval);
841 DEBUG_nchar += fprintf(stderr, "%s=", m->name);
842 DEBUG_Print(&val1, 1, format, level + 1);
843 if( m->next != NULL )
845 DEBUG_nchar += fprintf(stderr, ", ");
847 if( DEBUG_nchar > DEBUG_maxchar )
849 fprintf(stderr, "...}");
850 goto leave;
853 DEBUG_nchar += fprintf(stderr, "}");
854 break;
855 case DT_ARRAY:
857 * Loop over all of the entries, printing stuff as we go.
859 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
860 if( size == 1 )
863 * Special handling for character arrays.
865 pnt = (char *) value->addr.off;
866 DEBUG_nchar += fprintf(stderr, "\"");
867 for( i=value->type->un.array.start; i < value->type->un.array.end; i++ )
869 fputc(*pnt++, stderr);
870 DEBUG_nchar++;
871 if( DEBUG_nchar > DEBUG_maxchar )
873 fprintf(stderr, "...\"");
874 goto leave;
877 DEBUG_nchar += fprintf(stderr, "\"");
878 break;
880 val1 = *value;
881 val1.type = value->type->un.array.basictype;
882 DEBUG_nchar += fprintf(stderr, "{");
883 for( i=value->type->un.array.start; i <= value->type->un.array.end; i++ )
885 DEBUG_Print(&val1, 1, format, level + 1);
886 val1.addr.off += size;
887 if( i == value->type->un.array.end )
889 DEBUG_nchar += fprintf(stderr, "}");
891 else
893 DEBUG_nchar += fprintf(stderr, ", ");
895 if( DEBUG_nchar > DEBUG_maxchar )
897 fprintf(stderr, "...}");
898 goto leave;
901 break;
902 default:
903 assert(FALSE);
904 break;
907 leave:
909 if( level == 0 )
911 DEBUG_nchar += fprintf(stderr, "\n");
913 return;
917 DEBUG_DumpTypes(void)
919 struct datatype * dt = NULL;
920 struct member * m;
921 int hash;
922 int nm;
923 char * name;
924 char * member_name;
926 for(hash = 0; hash < NR_TYPE_HASH + 1; hash++)
928 for( dt = type_hash_table[hash]; dt; dt = dt->next )
930 name = "none";
931 if( dt->name != NULL )
933 name = dt->name;
935 switch(dt->type)
937 case DT_BASIC:
938 fprintf(stderr, "0x%p - BASIC(%s)\n",
939 dt, name);
940 break;
941 case DT_POINTER:
942 fprintf(stderr, "0x%p - POINTER(%s)(%p)\n",
943 dt, name, dt->un.pointer.pointsto);
944 break;
945 case DT_STRUCT:
946 member_name = "none";
947 nm = 0;
948 if( dt->un.structure.members != NULL
949 && dt->un.structure.members->name != NULL )
951 member_name = dt->un.structure.members->name;
952 for( m = dt->un.structure.members; m; m = m->next)
954 nm++;
957 fprintf(stderr, "0x%p - STRUCT(%s) %d %d %s\n", dt, name,
958 dt->un.structure.size, nm, member_name);
959 break;
960 case DT_ARRAY:
961 fprintf(stderr, "0x%p - ARRAY(%s)(%p)\n",
962 dt, name, dt->un.array.basictype);
963 break;
964 case DT_ENUM:
965 fprintf(stderr, "0x%p - ENUM(%s)\n",
966 dt, name);
967 break;
968 case DT_BITFIELD:
969 fprintf(stderr, "0x%p - BITFIELD(%s)\n", dt, name);
970 break;
971 case DT_FUNC:
972 fprintf(stderr, "0x%p - FUNC(%s)(%p)\n",
973 dt, name, dt->un.funct.rettype);
974 break;
975 case DT_CONST:
976 case DT_TYPEDEF:
977 fprintf(stderr, "What???\n");
978 break;
982 return TRUE;
986 enum debug_type DEBUG_GetType(struct datatype * dt)
988 return dt->type;
991 struct datatype *
992 DEBUG_TypeCast(enum debug_type type, const char * name)
994 int hash;
995 struct datatype * rtn;
998 * The last bucket is special, and is used to hold typeless names.
1000 if( name == NULL )
1002 hash = NR_TYPE_HASH;
1004 else
1006 hash = type_hash(name);
1009 rtn = DEBUG_LookupDataType(type, hash, name);
1011 return rtn;
1016 DEBUG_PrintTypeCast(const struct datatype * dt)
1018 const char* name = "none";
1020 if( dt->name != NULL )
1022 name = dt->name;
1025 switch(dt->type)
1027 case DT_BASIC:
1028 fprintf(stderr, "%s", name);
1029 break;
1030 case DT_POINTER:
1031 DEBUG_PrintTypeCast(dt->un.pointer.pointsto);
1032 fprintf(stderr, "*");
1033 break;
1034 case DT_STRUCT:
1035 fprintf(stderr, "struct %s", name);
1036 break;
1037 case DT_ARRAY:
1038 fprintf(stderr, "%s[]", name);
1039 break;
1040 case DT_ENUM:
1041 fprintf(stderr, "enum %s", name);
1042 break;
1043 case DT_BITFIELD:
1044 fprintf(stderr, "unsigned %s", name);
1045 break;
1046 case DT_FUNC:
1047 DEBUG_PrintTypeCast(dt->un.funct.rettype);
1048 fprintf(stderr, "(*%s)()", name);
1049 break;
1050 case DT_CONST:
1051 case DT_TYPEDEF:
1052 fprintf(stderr, "What???\n");
1053 break;
1056 return TRUE;
1059 int DEBUG_PrintType( const DBG_VALUE *value )
1061 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
1063 if (!value->type)
1065 fprintf(stderr, "Unknown type\n");
1066 return FALSE;
1068 if (!DEBUG_PrintTypeCast(value->type))
1069 return FALSE;
1070 fprintf(stderr, "\n");
1071 return TRUE;