Started implementation of the functions GetDefaultCommConfigA/W.
[wine.git] / debugger / types.c
blob76b9ae410fdf439662d7002123bda978dd7b715d
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 "pe_image.h"
21 #include "debugger.h"
23 #define NR_TYPE_HASH 521
25 int DEBUG_nchar;
26 static int DEBUG_maxchar = 1024;
28 struct en_values
30 struct en_values* next;
31 char * name;
32 int value;
35 struct member
37 struct member * next;
38 char * name;
39 struct datatype * type;
40 int offset;
41 int size;
44 struct datatype
46 enum debug_type type;
47 struct datatype * next;
48 char * name;
49 union
51 struct
53 char basic_type;
54 char * output_format;
55 char basic_size;
56 unsigned b_signed:1;
57 } basic;
58 struct
60 unsigned short bitoff;
61 unsigned short nbits;
62 struct datatype * basetype;
63 } bitfield;
65 struct
67 struct datatype * pointsto;
68 } pointer;
69 struct
71 struct datatype * rettype;
72 } funct;
73 struct
75 int start;
76 int end;
77 struct datatype * basictype;
78 } array;
79 struct
81 int size;
82 struct member * members;
83 } structure;
84 struct
86 struct en_values * members;
87 } enumeration;
88 } un;
91 #define BASIC_INT 1
92 #define BASIC_CHAR 2
93 #define BASIC_LONG 3
94 #define BASIC_UINT 4
95 #define BASIC_LUI 5
96 #define BASIC_LONGLONG 6
97 #define BASIC_ULONGLONGI 7
98 #define BASIC_SHORT 8
99 #define BASIC_SHORTUI 9
100 #define BASIC_SCHAR 10
101 #define BASIC_UCHAR 11
102 #define BASIC_FLT 12
103 #define BASIC_LONG_DOUBLE 13
104 #define BASIC_DOUBLE 14
105 #define BASIC_CMPLX_INT 15
106 #define BASIC_CMPLX_FLT 16
107 #define BASIC_CMPLX_DBL 17
108 #define BASIC_CMPLX_LONG_DBL 18
109 #define BASIC_VOID 19
111 struct datatype * DEBUG_TypeInt = NULL;
112 struct datatype * DEBUG_TypeIntConst = NULL;
113 struct datatype * DEBUG_TypeUSInt = NULL;
114 struct datatype * DEBUG_TypeString = NULL;
115 struct datatype * DEBUG_TypeShortUInt = NULL;
117 * All of the types that have been defined so far.
119 static struct datatype * type_hash_table[NR_TYPE_HASH + 1];
120 static struct datatype * pointer_types = NULL;
122 static unsigned int type_hash( const char * name )
124 unsigned int hash = 0;
125 unsigned int tmp;
126 const char * p;
128 p = name;
130 while (*p)
132 hash = (hash << 4) + *p++;
134 if( (tmp = (hash & 0xf0000000)) )
136 hash ^= tmp >> 24;
138 hash &= ~tmp;
140 return hash % NR_TYPE_HASH;
144 static struct datatype *
145 DEBUG_InitBasic(int type, char * name, int size, int b_signed,
146 char * output_format)
148 int hash;
150 struct datatype * dt;
151 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
153 if( dt != NULL )
155 if( name != NULL )
157 hash = type_hash(name);
159 else
161 hash = NR_TYPE_HASH;
164 dt->type = DT_BASIC;
165 dt->name = name;
166 dt->next = type_hash_table[hash];
167 type_hash_table[hash] = dt;
168 dt->un.basic.basic_type = type;
169 dt->un.basic.basic_size = size;
170 dt->un.basic.b_signed = b_signed;
171 dt->un.basic.output_format = output_format;
174 return dt;
177 static
178 struct datatype *
179 DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename)
181 struct datatype * dt = NULL;
183 if( typename != NULL )
185 for( dt = type_hash_table[hash]; dt; dt = dt->next )
187 if( xtype != dt->type || dt->name == NULL
188 || dt->name[0] != typename[0])
190 continue;
193 if( strcmp(dt->name, typename) == 0 )
195 return dt;
200 return dt;
203 struct datatype *
204 DEBUG_NewDataType(enum debug_type xtype, const char * typename)
206 struct datatype * dt = NULL;
207 int hash;
210 * The last bucket is special, and is used to hold typeless names.
212 if( typename == NULL )
214 hash = NR_TYPE_HASH;
216 else
218 hash = type_hash(typename);
221 dt = DEBUG_LookupDataType(xtype, hash, typename);
223 if( dt == NULL )
225 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
227 if( dt != NULL )
229 memset(dt, 0, sizeof(*dt));
231 dt->type = xtype;
232 if( typename != NULL )
234 dt->name = DBG_strdup(typename);
236 else
238 dt->name = NULL;
240 if( xtype == DT_POINTER )
242 dt->next = pointer_types;
243 pointer_types = dt;
245 else
247 dt->next = type_hash_table[hash];
248 type_hash_table[hash] = dt;
253 return dt;
256 struct datatype *
257 DEBUG_FindOrMakePointerType(struct datatype * reftype)
259 struct datatype * dt = NULL;
261 if( reftype != NULL )
263 for( dt = pointer_types; dt; dt = dt->next )
265 if( dt->type != DT_POINTER )
267 continue;
270 if( dt->un.pointer.pointsto == reftype )
272 return dt;
277 if( dt == NULL )
279 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
281 if( dt != NULL )
283 dt->type = DT_POINTER;
284 dt->un.pointer.pointsto = reftype;
285 dt->next = pointer_types;
286 pointer_types = dt;
290 return dt;
293 void
294 DEBUG_InitTypes(void)
296 static int beenhere = 0;
297 struct datatype * chartype;
299 if( beenhere++ != 0 )
301 return;
305 * Special version of int used with constants of various kinds.
307 DEBUG_TypeIntConst = DEBUG_InitBasic(BASIC_INT,NULL,4,1,"%d");
310 * Initialize a few builtin types.
313 DEBUG_TypeInt = DEBUG_InitBasic(BASIC_INT,"int",4,1,"%d");
314 chartype = DEBUG_InitBasic(BASIC_CHAR,"char",1,1,"'%c'");
315 DEBUG_InitBasic(BASIC_LONG,"long int",4,1,"%d");
316 DEBUG_TypeUSInt = DEBUG_InitBasic(BASIC_UINT,"unsigned int",4,0,"%d");
317 DEBUG_InitBasic(BASIC_LUI,"long unsigned int",4,0,"%d");
318 DEBUG_InitBasic(BASIC_LONGLONG,"long long int",8,1,"%ld");
319 DEBUG_InitBasic(BASIC_ULONGLONGI,"long long unsigned int",8,0,"%ld");
320 DEBUG_InitBasic(BASIC_SHORT,"short int",2,1,"%d");
321 DEBUG_TypeShortUInt = DEBUG_InitBasic(BASIC_SHORTUI,"short unsigned int",2,0,"%d");
322 DEBUG_InitBasic(BASIC_SCHAR,"signed char",1,1,"'%c'");
323 DEBUG_InitBasic(BASIC_UCHAR,"unsigned char",1,0,"'%c'");
324 DEBUG_InitBasic(BASIC_FLT,"float",4,0,"%f");
325 DEBUG_InitBasic(BASIC_LONG_DOUBLE,"double",8,0,"%lf");
326 DEBUG_InitBasic(BASIC_DOUBLE,"long double",12,0,NULL);
327 DEBUG_InitBasic(BASIC_CMPLX_INT,"complex int",8,1,NULL);
328 DEBUG_InitBasic(BASIC_CMPLX_FLT,"complex float",8,0,NULL);
329 DEBUG_InitBasic(BASIC_CMPLX_DBL,"complex double",16,0,NULL);
330 DEBUG_InitBasic(BASIC_CMPLX_LONG_DBL,"complex long double",24,0,NULL);
331 DEBUG_InitBasic(BASIC_VOID,"void",0,0,NULL);
333 DEBUG_TypeString = DEBUG_NewDataType(DT_POINTER, NULL);
334 DEBUG_SetPointerType(DEBUG_TypeString, chartype);
337 * Now initialize the builtins for codeview.
339 DEBUG_InitCVDataTypes();
343 long long int
344 DEBUG_GetExprValue(const DBG_VALUE *_value, char ** format)
346 unsigned int rtn;
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;
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)
363 case DT_BASIC:
365 rtn = 0;
366 /* FIXME: following code implies i386 byte ordering */
367 if (_value->cookie == DV_TARGET) {
368 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn,
369 value.type->un.basic.basic_size))
370 return 0;
371 } else {
372 memcpy(&rtn, (void*)value.addr.off, value.type->un.basic.basic_size);
375 if( (value.type->un.basic.b_signed)
376 && ((value.type->un.basic.basic_size & 3) != 0)
377 && ((rtn >> (value.type->un.basic.basic_size * 8 - 1)) != 0) )
379 rtn = rtn | ((-1) << (value.type->un.basic.basic_size * 8));
381 if( value.type->un.basic.output_format != NULL )
383 def_format = value.type->un.basic.output_format;
387 * Check for single character prints that are out of range.
389 if( value.type->un.basic.basic_size == 1
390 && strcmp(def_format, "'%c'") == 0
391 && ((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, &rtn, sizeof(void*)))
399 return 0;
400 } else {
401 rtn = *(unsigned int*)(value.addr.off);
404 type2 = value.type->un.pointer.pointsto;
406 if (!type2)
408 def_format = "Internal symbol error: unable to access memory location 0x%08x";
409 rtn = 0;
410 break;
413 if( type2->type == DT_BASIC && type2->un.basic.basic_size == 1 )
415 if ( _value->cookie == DV_TARGET ) {
416 char ch;
417 def_format = "\"%S\"";
418 if (!DEBUG_READ_MEM_VERBOSE((void*)rtn, &ch, 1))
419 return 0;
420 } else {
421 def_format = "\"%s\"";
424 else
426 def_format = "0x%8.8x";
428 break;
429 case DT_ARRAY:
430 case DT_STRUCT:
431 assert(_value->cookie == DV_TARGET);
432 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(rtn)))
433 return 0;
434 def_format = "0x%8.8x";
435 break;
436 case DT_ENUM:
437 assert(_value->cookie == DV_TARGET);
438 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(rtn)))
439 return 0;
440 for(e = value.type->un.enumeration.members; e; e = e->next )
442 if( e->value == rtn )
444 break;
447 if( e != NULL )
449 rtn = (int) e->name;
450 def_format = "%s";
452 else
454 def_format = "%d";
456 break;
457 default:
458 rtn = 0;
459 break;
463 if( format != NULL )
465 *format = def_format;
467 return rtn;
470 unsigned int
471 DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype)
473 DBG_ADDR addr = value->addr;
474 unsigned int val;
476 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
478 *newtype = NULL;
481 * Make sure that this really makes sense.
483 if( value->type->type != DT_POINTER )
484 return 0;
486 if (value->cookie == DV_TARGET) {
487 if (!DEBUG_READ_MEM((void*)value->addr.off, &val, sizeof(val)))
488 return 0;
489 } else {
490 val = *(unsigned int*)value->addr.off;
493 *newtype = value->type->un.pointer.pointsto;
494 addr.off = val;
495 return DEBUG_ToLinear(&addr); /* FIXME: is this right (or "better") ? */
498 unsigned int
499 DEBUG_FindStructElement(DBG_VALUE* value, const char * ele_name, int * tmpbuf)
501 struct member * m;
502 unsigned int mask;
504 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
507 * Make sure that this really makes sense.
509 if( value->type->type != DT_STRUCT )
511 value->type = NULL;
512 return FALSE;
515 for(m = value->type->un.structure.members; m; m = m->next)
517 if( strcmp(m->name, ele_name) == 0 )
519 value->type = m->type;
520 if( (m->offset & 7) != 0 || (m->size & 7) != 0)
523 * Bitfield operation. We have to extract the field and store
524 * it in a temporary buffer so that we get it all right.
526 *tmpbuf = ((*(int* ) (value->addr.off + (m->offset >> 3))) >> (m->offset & 7));
527 value->addr.off = (int) tmpbuf;
529 mask = 0xffffffff << (m->size);
530 *tmpbuf &= ~mask;
532 * OK, now we have the correct part of the number.
533 * Check to see whether the basic type is signed or not, and if so,
534 * we need to sign extend the number.
536 if( m->type->type == DT_BASIC && m->type->un.basic.b_signed != 0
537 && (*tmpbuf & (1 << (m->size - 1))) != 0 )
539 *tmpbuf |= mask;
542 else
544 value->addr.off += (m->offset >> 3);
546 return TRUE;
550 value->type = NULL;
551 return FALSE;
555 DEBUG_SetStructSize(struct datatype * dt, int size)
557 assert(dt->type == DT_STRUCT);
559 if( dt->un.structure.members != NULL )
561 return FALSE;
564 dt->un.structure.size = size;
565 dt->un.structure.members = NULL;
567 return TRUE;
571 DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2)
574 assert( dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM)));
576 if( dt->type == DT_STRUCT )
578 dt->un.structure.members = dt2->un.structure.members;
580 else
582 dt->un.enumeration.members = dt2->un.enumeration.members;
585 return TRUE;
589 DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type,
590 int offset, int size)
592 struct member * m;
593 struct member * last;
594 struct en_values * e;
596 if( dt->type == DT_STRUCT )
598 for(last = dt->un.structure.members; last; last = last->next)
600 if( (last->name[0] == name[0])
601 && (strcmp(last->name, name) == 0) )
603 return TRUE;
605 if( last->next == NULL )
607 break;
610 m = (struct member *) DBG_alloc(sizeof(struct member));
611 if( m == FALSE )
613 return FALSE;
616 m->name = DBG_strdup(name);
617 m->type = type;
618 m->offset = offset;
619 m->size = size;
620 if( last == NULL )
622 m->next = dt->un.structure.members;
623 dt->un.structure.members = m;
625 else
627 last->next = m;
628 m->next = NULL;
631 * If the base type is bitfield, then adjust the offsets here so that we
632 * are able to look things up without lots of falter-all.
634 if( type && type->type == DT_BITFIELD )
636 m->offset += m->type->un.bitfield.bitoff;
637 m->size = m->type->un.bitfield.nbits;
638 m->type = m->type->un.bitfield.basetype;
641 else if( dt->type == DT_ENUM )
643 e = (struct en_values *) DBG_alloc(sizeof(struct en_values));
644 if( e == FALSE )
646 return FALSE;
649 e->name = DBG_strdup(name);
650 e->value = offset;
651 e->next = dt->un.enumeration.members;
652 dt->un.enumeration.members = e;
654 else
656 assert(FALSE);
658 return TRUE;
661 struct datatype *
662 DEBUG_GetPointerType(struct datatype * dt)
664 if( dt->type == DT_POINTER )
666 return dt->un.pointer.pointsto;
669 return NULL;
673 DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2)
675 switch(dt->type)
677 case DT_POINTER:
678 dt->un.pointer.pointsto = dt2;
679 break;
680 case DT_FUNC:
681 dt->un.funct.rettype = dt2;
682 break;
683 default:
684 assert(FALSE);
687 return TRUE;
691 DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2)
693 assert(dt->type == DT_ARRAY);
694 dt->un.array.start = min;
695 dt->un.array.end = max;
696 dt->un.array.basictype = dt2;
698 return TRUE;
702 DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits,
703 struct datatype * dt2)
705 assert(dt->type == DT_BITFIELD);
706 dt->un.bitfield.bitoff = offset;
707 dt->un.bitfield.nbits = nbits;
708 dt->un.bitfield.basetype = dt2;
710 return TRUE;
713 int DEBUG_GetObjectSize(struct datatype * dt)
715 if( dt == NULL )
717 return 0;
720 switch(dt->type)
722 case DT_BASIC:
723 return dt->un.basic.basic_size;
724 case DT_POINTER:
725 return sizeof(int *);
726 case DT_STRUCT:
727 return dt->un.structure.size;
728 case DT_ENUM:
729 return sizeof(int);
730 case DT_ARRAY:
731 return (dt->un.array.end - dt->un.array.start)
732 * DEBUG_GetObjectSize(dt->un.array.basictype);
733 case DT_BITFIELD:
735 * Bitfields have to be handled seperately later on
736 * when we insert the element into the structure.
738 return 0;
739 case DT_TYPEDEF:
740 case DT_FUNC:
741 case DT_CONST:
742 assert(FALSE);
744 return 0;
747 unsigned int
748 DEBUG_ArrayIndex(const DBG_VALUE * value, DBG_VALUE * result, int index)
750 int size;
752 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
755 * Make sure that this really makes sense.
757 if( value->type->type == DT_POINTER )
760 * Get the base type, so we know how much to index by.
762 size = DEBUG_GetObjectSize(value->type->un.pointer.pointsto);
763 result->type = value->type->un.pointer.pointsto;
764 result->addr.off = (DWORD)DEBUG_ReadMemory(value) + size*index;
766 /* Contents of array must be on same target */
767 result->cookie = value->cookie;
769 else if (value->type->type == DT_ARRAY)
771 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
772 result->type = value->type->un.array.basictype;
773 result->addr.off = value->addr.off + size * (index - value->type->un.array.start);
775 /* Contents of array must be on same target */
776 result->cookie = value->cookie;
778 else
780 assert(FALSE);
783 return TRUE;
786 /***********************************************************************
787 * DEBUG_Print
789 * Implementation of the 'print' command.
791 void
792 DEBUG_Print( const DBG_VALUE *value, int count, char format, int level )
794 DBG_VALUE val1;
795 int i;
796 struct member * m;
797 char * pnt;
798 int size;
799 int xval;
801 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
803 if (count != 1)
805 DEBUG_Printf( DBG_CHN_MESG, "Count other than 1 is meaningless in 'print' command\n" );
806 return;
809 if( value->type == NULL )
811 /* No type, just print the addr value */
812 if (value->addr.seg && (value->addr.seg != 0xffffffff))
813 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%04lx: ", value->addr.seg );
814 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", value->addr.off );
815 goto leave;
818 if( level == 0 )
820 DEBUG_nchar = 0;
823 if( DEBUG_nchar > DEBUG_maxchar )
825 DEBUG_Printf(DBG_CHN_MESG, "...");
826 goto leave;
829 if( format == 'i' || format == 's' || format == 'w' || format == 'b' )
831 DEBUG_Printf( DBG_CHN_MESG, "Format specifier '%c' is meaningless in 'print' command\n", format );
832 format = '\0';
835 switch(value->type->type)
837 case DT_BASIC:
838 case DT_ENUM:
839 case DT_CONST:
840 case DT_POINTER:
841 DEBUG_PrintBasic(value, 1, format);
842 break;
843 case DT_STRUCT:
844 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "{");
845 for(m = value->type->un.structure.members; m; m = m->next)
847 val1 = *value;
848 DEBUG_FindStructElement(&val1, m->name, &xval);
849 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%s=", m->name);
850 DEBUG_Print(&val1, 1, format, level + 1);
851 if( m->next != NULL )
853 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, ", ");
855 if( DEBUG_nchar > DEBUG_maxchar )
857 DEBUG_Printf(DBG_CHN_MESG, "...}");
858 goto leave;
861 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "}");
862 break;
863 case DT_ARRAY:
865 * Loop over all of the entries, printing stuff as we go.
867 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
868 if( size == 1 )
871 * Special handling for character arrays.
873 pnt = (char *) value->addr.off;
874 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
875 for( i=value->type->un.array.start; i < value->type->un.array.end; i++ )
877 DEBUG_Output(DBG_CHN_MESG, pnt++, 1);
878 DEBUG_nchar++;
879 if( DEBUG_nchar > DEBUG_maxchar )
881 DEBUG_Printf(DBG_CHN_MESG, "...\"");
882 goto leave;
885 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
886 break;
888 val1 = *value;
889 val1.type = value->type->un.array.basictype;
890 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "{");
891 for( i=value->type->un.array.start; i <= value->type->un.array.end; i++ )
893 DEBUG_Print(&val1, 1, format, level + 1);
894 val1.addr.off += size;
895 if( i == value->type->un.array.end )
897 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "}");
899 else
901 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, ", ");
903 if( DEBUG_nchar > DEBUG_maxchar )
905 DEBUG_Printf(DBG_CHN_MESG, "...}");
906 goto leave;
909 break;
910 case DT_FUNC:
911 DEBUG_Printf(DBG_CHN_MESG, "Function at ???\n");
912 break;
913 default:
914 DEBUG_Printf(DBG_CHN_MESG, "Unknown type (%d)\n", value->type->type);
915 assert(FALSE);
916 break;
919 leave:
921 if( level == 0 )
923 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\n");
925 return;
929 DEBUG_DumpTypes(void)
931 struct datatype * dt = NULL;
932 struct member * m;
933 int hash;
934 int nm;
935 char * name;
936 char * member_name;
938 for(hash = 0; hash < NR_TYPE_HASH + 1; hash++)
940 for( dt = type_hash_table[hash]; dt; dt = dt->next )
942 name = "none";
943 if( dt->name != NULL )
945 name = dt->name;
947 switch(dt->type)
949 case DT_BASIC:
950 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BASIC(%s)\n",
951 (unsigned long)dt, name);
952 break;
953 case DT_POINTER:
954 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - POINTER(%s)(%08lx)\n",
955 (unsigned long)dt, name, (unsigned long)dt->un.pointer.pointsto);
956 break;
957 case DT_STRUCT:
958 member_name = "none";
959 nm = 0;
960 if( dt->un.structure.members != NULL
961 && dt->un.structure.members->name != NULL )
963 member_name = dt->un.structure.members->name;
964 for( m = dt->un.structure.members; m; m = m->next)
966 nm++;
969 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - STRUCT(%s) %d %d %s\n",
970 (unsigned long)dt, name, dt->un.structure.size, nm, member_name);
971 break;
972 case DT_ARRAY:
973 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ARRAY(%s)(%08lx)\n",
974 (unsigned long)dt, name, (unsigned long)dt->un.array.basictype);
975 break;
976 case DT_ENUM:
977 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ENUM(%s)\n",
978 (unsigned long)dt, name);
979 break;
980 case DT_BITFIELD:
981 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BITFIELD(%s)\n",
982 (unsigned long)dt, name);
983 break;
984 case DT_FUNC:
985 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - FUNC(%s)(%08lx)\n",
986 (unsigned long)dt, name, (unsigned long)dt->un.funct.rettype);
987 break;
988 case DT_CONST:
989 case DT_TYPEDEF:
990 DEBUG_Printf(DBG_CHN_MESG, "What???\n");
991 break;
995 return TRUE;
999 enum debug_type DEBUG_GetType(struct datatype * dt)
1001 return dt->type;
1004 struct datatype *
1005 DEBUG_TypeCast(enum debug_type type, const char * name)
1007 int hash;
1008 struct datatype * rtn;
1011 * The last bucket is special, and is used to hold typeless names.
1013 if( name == NULL )
1015 hash = NR_TYPE_HASH;
1017 else
1019 hash = type_hash(name);
1022 rtn = DEBUG_LookupDataType(type, hash, name);
1024 return rtn;
1029 DEBUG_PrintTypeCast(const struct datatype * dt)
1031 const char* name = "none";
1033 if( dt->name != NULL )
1035 name = dt->name;
1038 switch(dt->type)
1040 case DT_BASIC:
1041 DEBUG_Printf(DBG_CHN_MESG, "%s", name);
1042 break;
1043 case DT_POINTER:
1044 DEBUG_PrintTypeCast(dt->un.pointer.pointsto);
1045 DEBUG_Printf(DBG_CHN_MESG, "*");
1046 break;
1047 case DT_STRUCT:
1048 DEBUG_Printf(DBG_CHN_MESG, "struct %s", name);
1049 break;
1050 case DT_ARRAY:
1051 DEBUG_Printf(DBG_CHN_MESG, "%s[]", name);
1052 break;
1053 case DT_ENUM:
1054 DEBUG_Printf(DBG_CHN_MESG, "enum %s", name);
1055 break;
1056 case DT_BITFIELD:
1057 DEBUG_Printf(DBG_CHN_MESG, "unsigned %s", name);
1058 break;
1059 case DT_FUNC:
1060 DEBUG_PrintTypeCast(dt->un.funct.rettype);
1061 DEBUG_Printf(DBG_CHN_MESG, "(*%s)()", name);
1062 break;
1063 case DT_CONST:
1064 case DT_TYPEDEF:
1065 DEBUG_Printf(DBG_CHN_MESG, "What???\n");
1066 break;
1069 return TRUE;
1072 int DEBUG_PrintType( const DBG_VALUE *value )
1074 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
1076 if (!value->type)
1078 DEBUG_Printf(DBG_CHN_MESG, "Unknown type\n");
1079 return FALSE;
1081 if (!DEBUG_PrintTypeCast(value->type))
1082 return FALSE;
1083 DEBUG_Printf(DBG_CHN_MESG, "\n");
1084 return TRUE;