Added more conversion routines (rate conversion is implemented).
[wine.git] / debugger / types.c
blobacc023e53a4a5a57a531daa2e90be37e5c9a5c77
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 <stdlib.h>
13 #include <fcntl.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <limits.h>
17 #include <string.h>
18 #include <unistd.h>
20 #include "debugger.h"
22 #define NR_TYPE_HASH 521
24 int DEBUG_nchar;
25 static int DEBUG_maxchar = 1024;
27 struct en_values
29 struct en_values* next;
30 char * name;
31 int value;
34 struct member
36 struct member * next;
37 char * name;
38 struct datatype * type;
39 int offset;
40 int size;
43 struct datatype
45 enum debug_type type;
46 struct datatype * next;
47 char * name;
48 union
50 struct
52 char basic_type;
53 char * output_format;
54 char basic_size;
55 unsigned b_signed:1;
56 } basic;
57 struct
59 unsigned short bitoff;
60 unsigned short nbits;
61 struct datatype * basetype;
62 } bitfield;
64 struct
66 struct datatype * pointsto;
67 } pointer;
68 struct
70 struct datatype * rettype;
71 } funct;
72 struct
74 int start;
75 int end;
76 struct datatype * basictype;
77 } array;
78 struct
80 int size;
81 struct member * members;
82 } structure;
83 struct
85 struct en_values * members;
86 } enumeration;
87 } un;
90 #define BASIC_INT 1
91 #define BASIC_CHAR 2
92 #define BASIC_LONG 3
93 #define BASIC_UINT 4
94 #define BASIC_LUI 5
95 #define BASIC_LONGLONG 6
96 #define BASIC_ULONGLONGI 7
97 #define BASIC_SHORT 8
98 #define BASIC_SHORTUI 9
99 #define BASIC_SCHAR 10
100 #define BASIC_UCHAR 11
101 #define BASIC_FLT 12
102 #define BASIC_LONG_DOUBLE 13
103 #define BASIC_DOUBLE 14
104 #define BASIC_CMPLX_INT 15
105 #define BASIC_CMPLX_FLT 16
106 #define BASIC_CMPLX_DBL 17
107 #define BASIC_CMPLX_LONG_DBL 18
108 #define BASIC_VOID 19
110 struct datatype * DEBUG_TypeInt = NULL;
111 struct datatype * DEBUG_TypeIntConst = NULL;
112 struct datatype * DEBUG_TypeUSInt = NULL;
113 struct datatype * DEBUG_TypeString = NULL;
114 struct datatype * DEBUG_TypeShortUInt = NULL;
116 * All of the types that have been defined so far.
118 static struct datatype * type_hash_table[NR_TYPE_HASH + 1];
119 static struct datatype * pointer_types = NULL;
121 static unsigned int type_hash( const char * name )
123 unsigned int hash = 0;
124 unsigned int tmp;
125 const char * p;
127 p = name;
129 while (*p)
131 hash = (hash << 4) + *p++;
133 if( (tmp = (hash & 0xf0000000)) )
135 hash ^= tmp >> 24;
137 hash &= ~tmp;
139 return hash % NR_TYPE_HASH;
143 static struct datatype *
144 DEBUG_InitBasic(int type, char * name, int size, int b_signed,
145 char * output_format)
147 int hash;
149 struct datatype * dt;
150 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
152 if( dt != NULL )
154 if( name != NULL )
156 hash = type_hash(name);
158 else
160 hash = NR_TYPE_HASH;
163 dt->type = DT_BASIC;
164 dt->name = name;
165 dt->next = type_hash_table[hash];
166 type_hash_table[hash] = dt;
167 dt->un.basic.basic_type = type;
168 dt->un.basic.basic_size = size;
169 dt->un.basic.b_signed = b_signed;
170 dt->un.basic.output_format = output_format;
173 return dt;
176 static
177 struct datatype *
178 DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename)
180 struct datatype * dt = NULL;
182 if( typename != NULL )
184 for( dt = type_hash_table[hash]; dt; dt = dt->next )
186 if( xtype != dt->type || dt->name == NULL
187 || dt->name[0] != typename[0])
189 continue;
192 if( strcmp(dt->name, typename) == 0 )
194 return dt;
199 return dt;
202 struct datatype *
203 DEBUG_NewDataType(enum debug_type xtype, const char * typename)
205 struct datatype * dt = NULL;
206 int hash;
209 * The last bucket is special, and is used to hold typeless names.
211 if( typename == NULL )
213 hash = NR_TYPE_HASH;
215 else
217 hash = type_hash(typename);
220 dt = DEBUG_LookupDataType(xtype, hash, typename);
222 if( dt == NULL )
224 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
226 if( dt != NULL )
228 memset(dt, 0, sizeof(*dt));
230 dt->type = xtype;
231 if( typename != NULL )
233 dt->name = DBG_strdup(typename);
235 else
237 dt->name = NULL;
239 if( xtype == DT_POINTER )
241 dt->next = pointer_types;
242 pointer_types = dt;
244 else
246 dt->next = type_hash_table[hash];
247 type_hash_table[hash] = dt;
252 return dt;
255 struct datatype *
256 DEBUG_FindOrMakePointerType(struct datatype * reftype)
258 struct datatype * dt = NULL;
260 if( reftype != NULL )
262 for( dt = pointer_types; dt; dt = dt->next )
264 if( dt->type != DT_POINTER )
266 continue;
269 if( dt->un.pointer.pointsto == reftype )
271 return dt;
276 if( dt == NULL )
278 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
280 if( dt != NULL )
282 dt->type = DT_POINTER;
283 dt->un.pointer.pointsto = reftype;
284 dt->next = pointer_types;
285 pointer_types = dt;
289 return dt;
292 void
293 DEBUG_InitTypes(void)
295 static int beenhere = 0;
296 struct datatype * chartype;
298 if( beenhere++ != 0 )
300 return;
304 * Special version of int used with constants of various kinds.
306 DEBUG_TypeIntConst = DEBUG_InitBasic(BASIC_INT,NULL,4,1,"%d");
309 * Initialize a few builtin types.
312 DEBUG_TypeInt = DEBUG_InitBasic(BASIC_INT,"int",4,1,"%d");
313 chartype = DEBUG_InitBasic(BASIC_CHAR,"char",1,1,"'%c'");
314 DEBUG_InitBasic(BASIC_LONG,"long int",4,1,"%d");
315 DEBUG_TypeUSInt = DEBUG_InitBasic(BASIC_UINT,"unsigned int",4,0,"%d");
316 DEBUG_InitBasic(BASIC_LUI,"long unsigned int",4,0,"%d");
317 DEBUG_InitBasic(BASIC_LONGLONG,"long long int",8,1,"%ld");
318 DEBUG_InitBasic(BASIC_ULONGLONGI,"long long unsigned int",8,0,"%ld");
319 DEBUG_InitBasic(BASIC_SHORT,"short int",2,1,"%d");
320 DEBUG_TypeShortUInt = DEBUG_InitBasic(BASIC_SHORTUI,"short unsigned int",2,0,"%d");
321 DEBUG_InitBasic(BASIC_SCHAR,"signed char",1,1,"'%c'");
322 DEBUG_InitBasic(BASIC_UCHAR,"unsigned char",1,0,"'%c'");
323 DEBUG_InitBasic(BASIC_FLT,"float",4,0,"%f");
324 DEBUG_InitBasic(BASIC_LONG_DOUBLE,"double",8,0,"%lf");
325 DEBUG_InitBasic(BASIC_DOUBLE,"long double",12,0,NULL);
326 DEBUG_InitBasic(BASIC_CMPLX_INT,"complex int",8,1,NULL);
327 DEBUG_InitBasic(BASIC_CMPLX_FLT,"complex float",8,0,NULL);
328 DEBUG_InitBasic(BASIC_CMPLX_DBL,"complex double",16,0,NULL);
329 DEBUG_InitBasic(BASIC_CMPLX_LONG_DBL,"complex long double",24,0,NULL);
330 DEBUG_InitBasic(BASIC_VOID,"void",0,0,NULL);
332 DEBUG_TypeString = DEBUG_NewDataType(DT_POINTER, NULL);
333 DEBUG_SetPointerType(DEBUG_TypeString, chartype);
336 * Now initialize the builtins for codeview.
338 DEBUG_InitCVDataTypes();
342 long long int
343 DEBUG_GetExprValue(const DBG_VALUE* _value, char** format)
345 long long int rtn;
346 unsigned int rtn2;
347 struct datatype * type2 = NULL;
348 struct en_values * e;
349 char * def_format = "0x%x";
350 DBG_VALUE value = *_value;
352 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
354 rtn = 0; rtn2 = 0;
355 /* FIXME? I don't quite get this...
356 * if this is wrong, value.addr shall be linearized
358 value.addr.seg = 0;
359 assert(value.type != NULL);
361 switch (value.type->type) {
362 case DT_BASIC:
364 if (value.type->un.basic.basic_size > sizeof(rtn)) {
365 DEBUG_Printf(DBG_CHN_ERR, "Size too large (%d)\n",
366 value.type->un.basic.basic_size);
367 return 0;
369 /* FIXME: following code implies i386 byte ordering */
370 if (_value->cookie == DV_TARGET) {
371 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn,
372 value.type->un.basic.basic_size))
373 return 0;
374 } else {
375 memcpy(&rtn, (void*)value.addr.off, value.type->un.basic.basic_size);
378 if ( (value.type->un.basic.b_signed)
379 && ((value.type->un.basic.basic_size & 3) != 0)
380 && ((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) {
384 def_format = value.type->un.basic.output_format;
388 * Check for single character prints that are out of range.
390 if ( value.type->un.basic.basic_size == 1
391 && strcmp(def_format, "'%c'") == 0
392 && ((rtn < 0x20) || (rtn > 0x80))) {
393 def_format = "%d";
395 break;
396 case DT_POINTER:
397 if (_value->cookie == DV_TARGET) {
398 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(void*)))
399 return 0;
400 } else {
401 rtn2 = *(unsigned int*)(value.addr.off);
404 type2 = value.type->un.pointer.pointsto;
406 if (!type2) {
407 def_format = "Internal symbol error: unable to access memory location 0x%08x";
408 rtn = 0;
409 break;
412 if (type2->type == DT_BASIC && type2->un.basic.basic_size == 1) {
413 if (_value->cookie == DV_TARGET) {
414 char ch;
415 def_format = "\"%S\"";
416 /* FIXME: assuming little endian */
417 if (!DEBUG_READ_MEM_VERBOSE((void*)rtn2, &ch, 1))
418 return 0;
419 } else {
420 def_format = "\"%s\"";
422 } else {
423 def_format = "0x%8.8x";
425 rtn = rtn2;
426 break;
427 case DT_ARRAY:
428 case DT_STRUCT:
429 assert(_value->cookie == DV_TARGET);
430 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(rtn2)))
431 return 0;
432 rtn = rtn2;
433 def_format = "0x%8.8x";
434 break;
435 case DT_ENUM:
436 assert(_value->cookie == DV_TARGET);
437 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(rtn2)))
438 return 0;
439 rtn = rtn2;
440 def_format = "%d";
441 for (e = value.type->un.enumeration.members; e; e = e->next) {
442 if (e->value == rtn) {
443 rtn = (int)e->name;
444 def_format = "%s";
445 break;
448 break;
449 default:
450 rtn = 0;
451 break;
455 if (format != NULL) {
456 *format = def_format;
458 return rtn;
461 unsigned int
462 DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype)
464 DBG_ADDR addr = value->addr;
465 unsigned int val;
467 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
469 *newtype = NULL;
472 * Make sure that this really makes sense.
474 if( value->type->type != DT_POINTER )
475 return 0;
477 if (value->cookie == DV_TARGET) {
478 if (!DEBUG_READ_MEM((void*)value->addr.off, &val, sizeof(val)))
479 return 0;
480 } else {
481 val = *(unsigned int*)value->addr.off;
484 *newtype = value->type->un.pointer.pointsto;
485 addr.off = val;
486 return DEBUG_ToLinear(&addr); /* FIXME: is this right (or "better") ? */
489 unsigned int
490 DEBUG_FindStructElement(DBG_VALUE* value, const char * ele_name, int * tmpbuf)
492 struct member * m;
493 unsigned int mask;
495 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
498 * Make sure that this really makes sense.
500 if( value->type->type != DT_STRUCT )
502 value->type = NULL;
503 return FALSE;
506 for(m = value->type->un.structure.members; m; m = m->next)
508 if( strcmp(m->name, ele_name) == 0 )
510 value->type = m->type;
511 if( (m->offset & 7) != 0 || (m->size & 7) != 0)
514 * Bitfield operation. We have to extract the field and store
515 * it in a temporary buffer so that we get it all right.
517 *tmpbuf = ((*(int* ) (value->addr.off + (m->offset >> 3))) >> (m->offset & 7));
518 value->addr.off = (int) tmpbuf;
520 mask = 0xffffffff << (m->size);
521 *tmpbuf &= ~mask;
523 * OK, now we have the correct part of the number.
524 * Check to see whether the basic type is signed or not, and if so,
525 * we need to sign extend the number.
527 if( m->type->type == DT_BASIC && m->type->un.basic.b_signed != 0
528 && (*tmpbuf & (1 << (m->size - 1))) != 0 )
530 *tmpbuf |= mask;
533 else
535 value->addr.off += (m->offset >> 3);
537 return TRUE;
541 value->type = NULL;
542 return FALSE;
546 DEBUG_SetStructSize(struct datatype * dt, int size)
548 assert(dt->type == DT_STRUCT);
550 if( dt->un.structure.members != NULL )
552 return FALSE;
555 dt->un.structure.size = size;
556 dt->un.structure.members = NULL;
558 return TRUE;
562 DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2)
565 assert( dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM)));
567 if( dt->type == DT_STRUCT )
569 dt->un.structure.members = dt2->un.structure.members;
571 else
573 dt->un.enumeration.members = dt2->un.enumeration.members;
576 return TRUE;
580 DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type,
581 int offset, int size)
583 struct member * m;
584 struct member * last;
585 struct en_values * e;
587 if( dt->type == DT_STRUCT )
589 for(last = dt->un.structure.members; last; last = last->next)
591 if( (last->name[0] == name[0])
592 && (strcmp(last->name, name) == 0) )
594 return TRUE;
596 if( last->next == NULL )
598 break;
601 m = (struct member *) DBG_alloc(sizeof(struct member));
602 if( m == FALSE )
604 return FALSE;
607 m->name = DBG_strdup(name);
608 m->type = type;
609 m->offset = offset;
610 m->size = size;
611 if( last == NULL )
613 m->next = dt->un.structure.members;
614 dt->un.structure.members = m;
616 else
618 last->next = m;
619 m->next = NULL;
622 * If the base type is bitfield, then adjust the offsets here so that we
623 * are able to look things up without lots of falter-all.
625 if( type && type->type == DT_BITFIELD )
627 m->offset += m->type->un.bitfield.bitoff;
628 m->size = m->type->un.bitfield.nbits;
629 m->type = m->type->un.bitfield.basetype;
632 else if( dt->type == DT_ENUM )
634 e = (struct en_values *) DBG_alloc(sizeof(struct en_values));
635 if( e == FALSE )
637 return FALSE;
640 e->name = DBG_strdup(name);
641 e->value = offset;
642 e->next = dt->un.enumeration.members;
643 dt->un.enumeration.members = e;
645 else
647 assert(FALSE);
649 return TRUE;
652 struct datatype *
653 DEBUG_GetPointerType(struct datatype * dt)
655 if( dt->type == DT_POINTER )
657 return dt->un.pointer.pointsto;
660 return NULL;
664 DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2)
666 switch(dt->type)
668 case DT_POINTER:
669 dt->un.pointer.pointsto = dt2;
670 break;
671 case DT_FUNC:
672 dt->un.funct.rettype = dt2;
673 break;
674 default:
675 assert(FALSE);
678 return TRUE;
682 DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2)
684 assert(dt->type == DT_ARRAY);
685 dt->un.array.start = min;
686 dt->un.array.end = max;
687 dt->un.array.basictype = dt2;
689 return TRUE;
693 DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits,
694 struct datatype * dt2)
696 assert(dt->type == DT_BITFIELD);
697 dt->un.bitfield.bitoff = offset;
698 dt->un.bitfield.nbits = nbits;
699 dt->un.bitfield.basetype = dt2;
701 return TRUE;
704 int DEBUG_GetObjectSize(struct datatype * dt)
706 if( dt == NULL )
708 return 0;
711 switch(dt->type)
713 case DT_BASIC:
714 return dt->un.basic.basic_size;
715 case DT_POINTER:
716 return sizeof(int *);
717 case DT_STRUCT:
718 return dt->un.structure.size;
719 case DT_ENUM:
720 return sizeof(int);
721 case DT_ARRAY:
722 return (dt->un.array.end - dt->un.array.start)
723 * DEBUG_GetObjectSize(dt->un.array.basictype);
724 case DT_BITFIELD:
726 * Bitfields have to be handled seperately later on
727 * when we insert the element into the structure.
729 return 0;
730 case DT_TYPEDEF:
731 case DT_FUNC:
732 case DT_CONST:
733 assert(FALSE);
735 return 0;
738 unsigned int
739 DEBUG_ArrayIndex(const DBG_VALUE * value, DBG_VALUE * result, int index)
741 int size;
743 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
746 * Make sure that this really makes sense.
748 if( value->type->type == DT_POINTER )
751 * Get the base type, so we know how much to index by.
753 size = DEBUG_GetObjectSize(value->type->un.pointer.pointsto);
754 result->type = value->type->un.pointer.pointsto;
755 result->addr.off = (DWORD)DEBUG_ReadMemory(value) + size*index;
757 /* Contents of array must be on same target */
758 result->cookie = value->cookie;
760 else if (value->type->type == DT_ARRAY)
762 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
763 result->type = value->type->un.array.basictype;
764 result->addr.off = value->addr.off + size * (index - value->type->un.array.start);
766 /* Contents of array must be on same target */
767 result->cookie = value->cookie;
769 else
771 assert(FALSE);
774 return TRUE;
777 /***********************************************************************
778 * DEBUG_Print
780 * Implementation of the 'print' command.
782 void
783 DEBUG_Print( const DBG_VALUE *value, int count, char format, int level )
785 DBG_VALUE val1;
786 int i;
787 struct member * m;
788 char * pnt;
789 int size;
790 int xval;
792 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
794 if (count != 1)
796 DEBUG_Printf( DBG_CHN_MESG, "Count other than 1 is meaningless in 'print' command\n" );
797 return;
800 if( value->type == NULL )
802 /* No type, just print the addr value */
803 if (value->addr.seg && (value->addr.seg != 0xffffffff))
804 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%04lx: ", value->addr.seg );
805 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", value->addr.off );
806 goto leave;
809 if( level == 0 )
811 DEBUG_nchar = 0;
814 if( DEBUG_nchar > DEBUG_maxchar )
816 DEBUG_Printf(DBG_CHN_MESG, "...");
817 goto leave;
820 if( format == 'i' || format == 's' || format == 'w' || format == 'b' )
822 DEBUG_Printf( DBG_CHN_MESG, "Format specifier '%c' is meaningless in 'print' command\n", format );
823 format = '\0';
826 switch(value->type->type)
828 case DT_BASIC:
829 case DT_ENUM:
830 case DT_CONST:
831 case DT_POINTER:
832 DEBUG_PrintBasic(value, 1, format);
833 break;
834 case DT_STRUCT:
835 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "{");
836 for(m = value->type->un.structure.members; m; m = m->next)
838 val1 = *value;
839 DEBUG_FindStructElement(&val1, m->name, &xval);
840 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%s=", m->name);
841 DEBUG_Print(&val1, 1, format, level + 1);
842 if( m->next != NULL )
844 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, ", ");
846 if( DEBUG_nchar > DEBUG_maxchar )
848 DEBUG_Printf(DBG_CHN_MESG, "...}");
849 goto leave;
852 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "}");
853 break;
854 case DT_ARRAY:
856 * Loop over all of the entries, printing stuff as we go.
858 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
859 if( size == 1 )
862 * Special handling for character arrays.
864 pnt = (char *) value->addr.off;
865 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
866 for( i=value->type->un.array.start; i < value->type->un.array.end; i++ )
868 DEBUG_Output(DBG_CHN_MESG, pnt++, 1);
869 DEBUG_nchar++;
870 if( DEBUG_nchar > DEBUG_maxchar )
872 DEBUG_Printf(DBG_CHN_MESG, "...\"");
873 goto leave;
876 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
877 break;
879 val1 = *value;
880 val1.type = value->type->un.array.basictype;
881 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "{");
882 for( i=value->type->un.array.start; i <= value->type->un.array.end; i++ )
884 DEBUG_Print(&val1, 1, format, level + 1);
885 val1.addr.off += size;
886 if( i == value->type->un.array.end )
888 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "}");
890 else
892 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, ", ");
894 if( DEBUG_nchar > DEBUG_maxchar )
896 DEBUG_Printf(DBG_CHN_MESG, "...}");
897 goto leave;
900 break;
901 case DT_FUNC:
902 DEBUG_Printf(DBG_CHN_MESG, "Function at ???\n");
903 break;
904 default:
905 DEBUG_Printf(DBG_CHN_MESG, "Unknown type (%d)\n", value->type->type);
906 assert(FALSE);
907 break;
910 leave:
912 if( level == 0 )
914 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\n");
916 return;
920 DEBUG_DumpTypes(void)
922 struct datatype * dt = NULL;
923 struct member * m;
924 int hash;
925 int nm;
926 char * name;
927 char * member_name;
929 for(hash = 0; hash < NR_TYPE_HASH + 1; hash++)
931 for( dt = type_hash_table[hash]; dt; dt = dt->next )
933 name = "none";
934 if( dt->name != NULL )
936 name = dt->name;
938 switch(dt->type)
940 case DT_BASIC:
941 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BASIC(%s)\n",
942 (unsigned long)dt, name);
943 break;
944 case DT_POINTER:
945 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - POINTER(%s)(%08lx)\n",
946 (unsigned long)dt, name, (unsigned long)dt->un.pointer.pointsto);
947 break;
948 case DT_STRUCT:
949 member_name = "none";
950 nm = 0;
951 if( dt->un.structure.members != NULL
952 && dt->un.structure.members->name != NULL )
954 member_name = dt->un.structure.members->name;
955 for( m = dt->un.structure.members; m; m = m->next)
957 nm++;
960 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - STRUCT(%s) %d %d %s\n",
961 (unsigned long)dt, name, dt->un.structure.size, nm, member_name);
962 break;
963 case DT_ARRAY:
964 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ARRAY(%s)(%08lx)\n",
965 (unsigned long)dt, name, (unsigned long)dt->un.array.basictype);
966 break;
967 case DT_ENUM:
968 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ENUM(%s)\n",
969 (unsigned long)dt, name);
970 break;
971 case DT_BITFIELD:
972 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BITFIELD(%s)\n",
973 (unsigned long)dt, name);
974 break;
975 case DT_FUNC:
976 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - FUNC(%s)(%08lx)\n",
977 (unsigned long)dt, name, (unsigned long)dt->un.funct.rettype);
978 break;
979 case DT_CONST:
980 case DT_TYPEDEF:
981 DEBUG_Printf(DBG_CHN_MESG, "What???\n");
982 break;
986 return TRUE;
990 enum debug_type DEBUG_GetType(struct datatype * dt)
992 return dt->type;
995 struct datatype *
996 DEBUG_TypeCast(enum debug_type type, const char * name)
998 int hash;
999 struct datatype * rtn;
1002 * The last bucket is special, and is used to hold typeless names.
1004 if( name == NULL )
1006 hash = NR_TYPE_HASH;
1008 else
1010 hash = type_hash(name);
1013 rtn = DEBUG_LookupDataType(type, hash, name);
1015 return rtn;
1020 DEBUG_PrintTypeCast(const struct datatype * dt)
1022 const char* name = "none";
1024 if( dt->name != NULL )
1026 name = dt->name;
1029 switch(dt->type)
1031 case DT_BASIC:
1032 DEBUG_Printf(DBG_CHN_MESG, "%s", name);
1033 break;
1034 case DT_POINTER:
1035 DEBUG_PrintTypeCast(dt->un.pointer.pointsto);
1036 DEBUG_Printf(DBG_CHN_MESG, "*");
1037 break;
1038 case DT_STRUCT:
1039 DEBUG_Printf(DBG_CHN_MESG, "struct %s", name);
1040 break;
1041 case DT_ARRAY:
1042 DEBUG_Printf(DBG_CHN_MESG, "%s[]", name);
1043 break;
1044 case DT_ENUM:
1045 DEBUG_Printf(DBG_CHN_MESG, "enum %s", name);
1046 break;
1047 case DT_BITFIELD:
1048 DEBUG_Printf(DBG_CHN_MESG, "unsigned %s", name);
1049 break;
1050 case DT_FUNC:
1051 DEBUG_PrintTypeCast(dt->un.funct.rettype);
1052 DEBUG_Printf(DBG_CHN_MESG, "(*%s)()", name);
1053 break;
1054 case DT_CONST:
1055 case DT_TYPEDEF:
1056 DEBUG_Printf(DBG_CHN_MESG, "What???\n");
1057 break;
1060 return TRUE;
1063 int DEBUG_PrintType( const DBG_VALUE *value )
1065 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
1067 if (!value->type)
1069 DEBUG_Printf(DBG_CHN_MESG, "Unknown type\n");
1070 return FALSE;
1072 if (!DEBUG_PrintTypeCast(value->type))
1073 return FALSE;
1074 DEBUG_Printf(DBG_CHN_MESG, "\n");
1075 return TRUE;