Implemented TOOLBAR_MouseLeave to handle WM_MOUSELEAVE messages.
[wine/multimedia.git] / debugger / types.c
blob5233d5e9259c12f050aae174d62b47003547e5dc
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 "debugger.h"
24 #define NR_TYPE_HASH 521
26 int DEBUG_nchar;
27 static int DEBUG_maxchar = 1024;
29 struct en_values
31 struct en_values* next;
32 char * name;
33 int value;
36 struct member
38 struct member * next;
39 char * name;
40 struct datatype * type;
41 int offset;
42 int size;
45 struct datatype
47 enum debug_type type;
48 struct datatype * next;
49 char * name;
50 union
52 struct
54 char basic_type;
55 char * output_format;
56 char basic_size;
57 unsigned b_signed:1;
58 } basic;
59 struct
61 unsigned short bitoff;
62 unsigned short nbits;
63 struct datatype * basetype;
64 } bitfield;
66 struct
68 struct datatype * pointsto;
69 } pointer;
70 struct
72 struct datatype * rettype;
73 } funct;
74 struct
76 int start;
77 int end;
78 struct datatype * basictype;
79 } array;
80 struct
82 int size;
83 struct member * members;
84 } structure;
85 struct
87 struct en_values * members;
88 } enumeration;
89 } un;
92 #define BASIC_INT 1
93 #define BASIC_CHAR 2
94 #define BASIC_LONG 3
95 #define BASIC_UINT 4
96 #define BASIC_LUI 5
97 #define BASIC_LONGLONG 6
98 #define BASIC_ULONGLONGI 7
99 #define BASIC_SHORT 8
100 #define BASIC_SHORTUI 9
101 #define BASIC_SCHAR 10
102 #define BASIC_UCHAR 11
103 #define BASIC_FLT 12
104 #define BASIC_LONG_DOUBLE 13
105 #define BASIC_DOUBLE 14
106 #define BASIC_CMPLX_INT 15
107 #define BASIC_CMPLX_FLT 16
108 #define BASIC_CMPLX_DBL 17
109 #define BASIC_CMPLX_LONG_DBL 18
110 #define BASIC_VOID 19
112 struct datatype * DEBUG_TypeInt = NULL;
113 struct datatype * DEBUG_TypeIntConst = NULL;
114 struct datatype * DEBUG_TypeUSInt = NULL;
115 struct datatype * DEBUG_TypeString = NULL;
118 * All of the types that have been defined so far.
120 static struct datatype * type_hash_table[NR_TYPE_HASH + 1];
121 static struct datatype * pointer_types = NULL;
123 static unsigned int type_hash( const char * name )
125 unsigned int hash = 0;
126 unsigned int tmp;
127 const char * p;
129 p = name;
131 while (*p)
133 hash = (hash << 4) + *p++;
135 if( (tmp = (hash & 0xf0000000)) )
137 hash ^= tmp >> 24;
139 hash &= ~tmp;
141 return hash % NR_TYPE_HASH;
145 static struct datatype *
146 DEBUG_InitBasic(int type, char * name, int size, int b_signed,
147 char * output_format)
149 int hash;
151 struct datatype * dt;
152 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
154 if( dt != NULL )
156 if( name != NULL )
158 hash = type_hash(name);
160 else
162 hash = NR_TYPE_HASH;
165 dt->type = DT_BASIC;
166 dt->name = name;
167 dt->next = type_hash_table[hash];
168 type_hash_table[hash] = dt;
169 dt->un.basic.basic_type = type;
170 dt->un.basic.basic_size = size;
171 dt->un.basic.b_signed = b_signed;
172 dt->un.basic.output_format = output_format;
175 return dt;
178 static
179 struct datatype *
180 DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename)
182 struct datatype * dt = NULL;
184 if( typename != NULL )
186 for( dt = type_hash_table[hash]; dt; dt = dt->next )
188 if( xtype != dt->type || dt->name == NULL
189 || dt->name[0] != typename[0])
191 continue;
194 if( strcmp(dt->name, typename) == 0 )
196 return dt;
201 return dt;
204 struct datatype *
205 DEBUG_NewDataType(enum debug_type xtype, const char * typename)
207 struct datatype * dt = NULL;
208 int hash;
211 * The last bucket is special, and is used to hold typeless names.
213 if( typename == NULL )
215 hash = NR_TYPE_HASH;
217 else
219 hash = type_hash(typename);
222 dt = DEBUG_LookupDataType(xtype, hash, typename);
224 if( dt == NULL )
226 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
228 if( dt != NULL )
230 memset(dt, 0, sizeof(*dt));
232 dt->type = xtype;
233 if( typename != NULL )
235 dt->name = DBG_strdup(typename);
237 else
239 dt->name = NULL;
241 if( xtype == DT_POINTER )
243 dt->next = pointer_types;
244 pointer_types = dt;
246 else
248 dt->next = type_hash_table[hash];
249 type_hash_table[hash] = dt;
254 return dt;
257 struct datatype *
258 DEBUG_FindOrMakePointerType(struct datatype * reftype)
260 struct datatype * dt = NULL;
262 if( reftype != NULL )
264 for( dt = pointer_types; dt; dt = dt->next )
266 if( dt->type != DT_POINTER )
268 continue;
271 if( dt->un.pointer.pointsto == reftype )
273 return dt;
278 if( dt == NULL )
280 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
282 if( dt != NULL )
284 dt->type = DT_POINTER;
285 dt->un.pointer.pointsto = reftype;
286 dt->next = pointer_types;
287 pointer_types = dt;
291 return dt;
294 void
295 DEBUG_InitTypes(void)
297 static int beenhere = 0;
298 struct datatype * chartype;
300 if( beenhere++ != 0 )
302 return;
306 * Special version of int used with constants of various kinds.
308 DEBUG_TypeIntConst = DEBUG_InitBasic(BASIC_INT,NULL,4,1,"%d");
311 * Initialize a few builtin types.
314 DEBUG_TypeInt = DEBUG_InitBasic(BASIC_INT,"int",4,1,"%d");
315 chartype = DEBUG_InitBasic(BASIC_CHAR,"char",1,1,"'%c'");
316 DEBUG_InitBasic(BASIC_LONG,"long int",4,1,"%d");
317 DEBUG_TypeUSInt = DEBUG_InitBasic(BASIC_UINT,"unsigned int",4,0,"%d");
318 DEBUG_InitBasic(BASIC_LUI,"long unsigned int",4,0,"%d");
319 DEBUG_InitBasic(BASIC_LONGLONG,"long long int",8,1,"%ld");
320 DEBUG_InitBasic(BASIC_ULONGLONGI,"long long unsigned int",8,0,"%ld");
321 DEBUG_InitBasic(BASIC_SHORT,"short int",2,1,"%d");
322 DEBUG_InitBasic(BASIC_SHORTUI,"short unsigned int",2,0,"%d");
323 DEBUG_InitBasic(BASIC_SCHAR,"signed char",1,1,"'%c'");
324 DEBUG_InitBasic(BASIC_UCHAR,"unsigned char",1,0,"'%c'");
325 DEBUG_InitBasic(BASIC_FLT,"float",4,0,"%f");
326 DEBUG_InitBasic(BASIC_LONG_DOUBLE,"double",8,0,"%lf");
327 DEBUG_InitBasic(BASIC_DOUBLE,"long double",12,0,NULL);
328 DEBUG_InitBasic(BASIC_CMPLX_INT,"complex int",8,1,NULL);
329 DEBUG_InitBasic(BASIC_CMPLX_FLT,"complex float",8,0,NULL);
330 DEBUG_InitBasic(BASIC_CMPLX_DBL,"complex double",16,0,NULL);
331 DEBUG_InitBasic(BASIC_CMPLX_LONG_DBL,"complex long double",24,0,NULL);
332 DEBUG_InitBasic(BASIC_VOID,"void",0,0,NULL);
334 DEBUG_TypeString = DEBUG_NewDataType(DT_POINTER, NULL);
335 DEBUG_SetPointerType(DEBUG_TypeString, chartype);
338 * Now initialize the builtins for codeview.
340 DEBUG_InitCVDataTypes();
344 long long int
345 DEBUG_GetExprValue(const DBG_VALUE *_value, char ** format)
347 unsigned int rtn;
348 struct datatype * type2 = NULL;
349 struct en_values * e;
350 char * def_format = "0x%x";
351 DBG_VALUE value = *_value;
353 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
355 rtn = 0;
356 /* FIXME? I don't quite get this...
357 * if this is wrong, value.addr shall be linearized
359 value.addr.seg = 0;
360 assert(value.type != NULL);
362 switch(value.type->type)
364 case DT_BASIC:
366 rtn = 0;
367 /* FIXME: following code implies i386 byte ordering */
368 if (_value->cookie == DV_TARGET) {
369 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn,
370 value.type->un.basic.basic_size))
371 return 0;
372 } else {
373 memcpy(&rtn, (void*)value.addr.off, value.type->un.basic.basic_size);
376 if( (value.type->un.basic.b_signed)
377 && ((value.type->un.basic.basic_size & 3) != 0)
378 && ((rtn >> (value.type->un.basic.basic_size * 8 - 1)) != 0) )
380 rtn = rtn | ((-1) << (value.type->un.basic.basic_size * 8));
382 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)) )
394 def_format = "%d";
396 break;
397 case DT_POINTER:
398 if (_value->cookie == DV_TARGET) {
399 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(void*)))
400 return 0;
401 } else {
402 rtn = *(unsigned int*)(value.addr.off);
405 type2 = value.type->un.pointer.pointsto;
407 if (!type2)
409 def_format = "Internal symbol error: unable to access memory location 0x%08x";
410 rtn = 0;
411 break;
414 if( type2->type == DT_BASIC && type2->un.basic.basic_size == 1 )
416 if ( _value->cookie == DV_TARGET ) {
417 char ch;
418 def_format = "\"%S\"";
419 if (!DEBUG_READ_MEM_VERBOSE((void*)rtn, &ch, 1))
420 return 0;
421 } else {
422 def_format = "\"%s\"";
425 else
427 def_format = "0x%8.8x";
429 break;
430 case DT_ARRAY:
431 case DT_STRUCT:
432 assert(_value->cookie == DV_TARGET);
433 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(rtn)))
434 return 0;
435 def_format = "0x%8.8x";
436 break;
437 case DT_ENUM:
438 assert(_value->cookie == DV_TARGET);
439 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn, sizeof(rtn)))
440 return 0;
441 for(e = value.type->un.enumeration.members; e; e = e->next )
443 if( e->value == rtn )
445 break;
448 if( e != NULL )
450 rtn = (int) e->name;
451 def_format = "%s";
453 else
455 def_format = "%d";
457 break;
458 default:
459 rtn = 0;
460 break;
464 if( format != NULL )
466 *format = def_format;
468 return rtn;
471 unsigned int
472 DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype)
474 DBG_ADDR addr = value->addr;
475 unsigned int val;
477 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
479 *newtype = NULL;
482 * Make sure that this really makes sense.
484 if( value->type->type != DT_POINTER )
485 return 0;
487 if (value->cookie == DV_TARGET) {
488 if (!DEBUG_READ_MEM((void*)value->addr.off, &val, sizeof(val)))
489 return 0;
490 } else {
491 val = *(unsigned int*)value->addr.off;
494 *newtype = value->type->un.pointer.pointsto;
495 addr.off = val;
496 return DEBUG_ToLinear(&addr); /* FIXME: is this right (or "better") ? */
499 unsigned int
500 DEBUG_FindStructElement(DBG_VALUE* value, const char * ele_name, int * tmpbuf)
502 struct member * m;
503 unsigned int mask;
505 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
508 * Make sure that this really makes sense.
510 if( value->type->type != DT_STRUCT )
512 value->type = NULL;
513 return FALSE;
516 for(m = value->type->un.structure.members; m; m = m->next)
518 if( strcmp(m->name, ele_name) == 0 )
520 value->type = m->type;
521 if( (m->offset & 7) != 0 || (m->size & 7) != 0)
524 * Bitfield operation. We have to extract the field and store
525 * it in a temporary buffer so that we get it all right.
527 *tmpbuf = ((*(int* ) (value->addr.off + (m->offset >> 3))) >> (m->offset & 7));
528 value->addr.off = (int) tmpbuf;
530 mask = 0xffffffff << (m->size);
531 *tmpbuf &= ~mask;
533 * OK, now we have the correct part of the number.
534 * Check to see whether the basic type is signed or not, and if so,
535 * we need to sign extend the number.
537 if( m->type->type == DT_BASIC && m->type->un.basic.b_signed != 0
538 && (*tmpbuf & (1 << (m->size - 1))) != 0 )
540 *tmpbuf |= mask;
543 else
545 value->addr.off += (m->offset >> 3);
547 return TRUE;
551 value->type = NULL;
552 return FALSE;
556 DEBUG_SetStructSize(struct datatype * dt, int size)
558 assert(dt->type == DT_STRUCT);
560 if( dt->un.structure.members != NULL )
562 return FALSE;
565 dt->un.structure.size = size;
566 dt->un.structure.members = NULL;
568 return TRUE;
572 DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2)
575 assert( dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM)));
577 if( dt->type == DT_STRUCT )
579 dt->un.structure.members = dt2->un.structure.members;
581 else
583 dt->un.enumeration.members = dt2->un.enumeration.members;
586 return TRUE;
590 DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type,
591 int offset, int size)
593 struct member * m;
594 struct member * last;
595 struct en_values * e;
597 if( dt->type == DT_STRUCT )
599 for(last = dt->un.structure.members; last; last = last->next)
601 if( (last->name[0] == name[0])
602 && (strcmp(last->name, name) == 0) )
604 return TRUE;
606 if( last->next == NULL )
608 break;
611 m = (struct member *) DBG_alloc(sizeof(struct member));
612 if( m == FALSE )
614 return FALSE;
617 m->name = DBG_strdup(name);
618 m->type = type;
619 m->offset = offset;
620 m->size = size;
621 if( last == NULL )
623 m->next = dt->un.structure.members;
624 dt->un.structure.members = m;
626 else
628 last->next = m;
629 m->next = NULL;
632 * If the base type is bitfield, then adjust the offsets here so that we
633 * are able to look things up without lots of falter-all.
635 if( type && type->type == DT_BITFIELD )
637 m->offset += m->type->un.bitfield.bitoff;
638 m->size = m->type->un.bitfield.nbits;
639 m->type = m->type->un.bitfield.basetype;
642 else if( dt->type == DT_ENUM )
644 e = (struct en_values *) DBG_alloc(sizeof(struct en_values));
645 if( e == FALSE )
647 return FALSE;
650 e->name = DBG_strdup(name);
651 e->value = offset;
652 e->next = dt->un.enumeration.members;
653 dt->un.enumeration.members = e;
655 else
657 assert(FALSE);
659 return TRUE;
662 struct datatype *
663 DEBUG_GetPointerType(struct datatype * dt)
665 if( dt->type == DT_POINTER )
667 return dt->un.pointer.pointsto;
670 return NULL;
674 DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2)
676 switch(dt->type)
678 case DT_POINTER:
679 dt->un.pointer.pointsto = dt2;
680 break;
681 case DT_FUNC:
682 dt->un.funct.rettype = dt2;
683 break;
684 default:
685 assert(FALSE);
688 return TRUE;
692 DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2)
694 assert(dt->type == DT_ARRAY);
695 dt->un.array.start = min;
696 dt->un.array.end = max;
697 dt->un.array.basictype = dt2;
699 return TRUE;
703 DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits,
704 struct datatype * dt2)
706 assert(dt->type == DT_BITFIELD);
707 dt->un.bitfield.bitoff = offset;
708 dt->un.bitfield.nbits = nbits;
709 dt->un.bitfield.basetype = dt2;
711 return TRUE;
714 int DEBUG_GetObjectSize(struct datatype * dt)
716 if( dt == NULL )
718 return 0;
721 switch(dt->type)
723 case DT_BASIC:
724 return dt->un.basic.basic_size;
725 case DT_POINTER:
726 return sizeof(int *);
727 case DT_STRUCT:
728 return dt->un.structure.size;
729 case DT_ENUM:
730 return sizeof(int);
731 case DT_ARRAY:
732 return (dt->un.array.end - dt->un.array.start)
733 * DEBUG_GetObjectSize(dt->un.array.basictype);
734 case DT_BITFIELD:
736 * Bitfields have to be handled seperately later on
737 * when we insert the element into the structure.
739 return 0;
740 case DT_TYPEDEF:
741 case DT_FUNC:
742 case DT_CONST:
743 assert(FALSE);
745 return 0;
748 unsigned int
749 DEBUG_ArrayIndex(const DBG_VALUE * value, DBG_VALUE * result, int index)
751 int size;
753 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
756 * Make sure that this really makes sense.
758 if( value->type->type == DT_POINTER )
761 * Get the base type, so we know how much to index by.
763 size = DEBUG_GetObjectSize(value->type->un.pointer.pointsto);
764 result->type = value->type->un.pointer.pointsto;
765 result->addr.off = (*(unsigned int*) (value->addr.off)) + size * index;
767 else if (value->type->type == DT_ARRAY)
769 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
770 result->type = value->type->un.array.basictype;
771 result->addr.off = value->addr.off + size * (index - value->type->un.array.start);
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 fputc(*pnt++, stderr);
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 default:
902 assert(FALSE);
903 break;
906 leave:
908 if( level == 0 )
910 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\n");
912 return;
916 DEBUG_DumpTypes(void)
918 struct datatype * dt = NULL;
919 struct member * m;
920 int hash;
921 int nm;
922 char * name;
923 char * member_name;
925 for(hash = 0; hash < NR_TYPE_HASH + 1; hash++)
927 for( dt = type_hash_table[hash]; dt; dt = dt->next )
929 name = "none";
930 if( dt->name != NULL )
932 name = dt->name;
934 switch(dt->type)
936 case DT_BASIC:
937 DEBUG_Printf(DBG_CHN_MESG, "0x%p - BASIC(%s)\n",
938 dt, name);
939 break;
940 case DT_POINTER:
941 DEBUG_Printf(DBG_CHN_MESG, "0x%p - POINTER(%s)(%p)\n",
942 dt, name, dt->un.pointer.pointsto);
943 break;
944 case DT_STRUCT:
945 member_name = "none";
946 nm = 0;
947 if( dt->un.structure.members != NULL
948 && dt->un.structure.members->name != NULL )
950 member_name = dt->un.structure.members->name;
951 for( m = dt->un.structure.members; m; m = m->next)
953 nm++;
956 DEBUG_Printf(DBG_CHN_MESG, "0x%p - STRUCT(%s) %d %d %s\n", dt, name,
957 dt->un.structure.size, nm, member_name);
958 break;
959 case DT_ARRAY:
960 DEBUG_Printf(DBG_CHN_MESG, "0x%p - ARRAY(%s)(%p)\n",
961 dt, name, dt->un.array.basictype);
962 break;
963 case DT_ENUM:
964 DEBUG_Printf(DBG_CHN_MESG, "0x%p - ENUM(%s)\n", dt, name);
965 break;
966 case DT_BITFIELD:
967 DEBUG_Printf(DBG_CHN_MESG, "0x%p - BITFIELD(%s)\n", dt, name);
968 break;
969 case DT_FUNC:
970 DEBUG_Printf(DBG_CHN_MESG, "0x%p - FUNC(%s)(%p)\n",
971 dt, name, dt->un.funct.rettype);
972 break;
973 case DT_CONST:
974 case DT_TYPEDEF:
975 DEBUG_Printf(DBG_CHN_MESG, "What???\n");
976 break;
980 return TRUE;
984 enum debug_type DEBUG_GetType(struct datatype * dt)
986 return dt->type;
989 struct datatype *
990 DEBUG_TypeCast(enum debug_type type, const char * name)
992 int hash;
993 struct datatype * rtn;
996 * The last bucket is special, and is used to hold typeless names.
998 if( name == NULL )
1000 hash = NR_TYPE_HASH;
1002 else
1004 hash = type_hash(name);
1007 rtn = DEBUG_LookupDataType(type, hash, name);
1009 return rtn;
1014 DEBUG_PrintTypeCast(const struct datatype * dt)
1016 const char* name = "none";
1018 if( dt->name != NULL )
1020 name = dt->name;
1023 switch(dt->type)
1025 case DT_BASIC:
1026 DEBUG_Printf(DBG_CHN_MESG, "%s", name);
1027 break;
1028 case DT_POINTER:
1029 DEBUG_PrintTypeCast(dt->un.pointer.pointsto);
1030 DEBUG_Printf(DBG_CHN_MESG, "*");
1031 break;
1032 case DT_STRUCT:
1033 DEBUG_Printf(DBG_CHN_MESG, "struct %s", name);
1034 break;
1035 case DT_ARRAY:
1036 DEBUG_Printf(DBG_CHN_MESG, "%s[]", name);
1037 break;
1038 case DT_ENUM:
1039 DEBUG_Printf(DBG_CHN_MESG, "enum %s", name);
1040 break;
1041 case DT_BITFIELD:
1042 DEBUG_Printf(DBG_CHN_MESG, "unsigned %s", name);
1043 break;
1044 case DT_FUNC:
1045 DEBUG_PrintTypeCast(dt->un.funct.rettype);
1046 DEBUG_Printf(DBG_CHN_MESG, "(*%s)()", name);
1047 break;
1048 case DT_CONST:
1049 case DT_TYPEDEF:
1050 DEBUG_Printf(DBG_CHN_MESG, "What???\n");
1051 break;
1054 return TRUE;
1057 int DEBUG_PrintType( const DBG_VALUE *value )
1059 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
1061 if (!value->type)
1063 DEBUG_Printf(DBG_CHN_MESG, "Unknown type\n");
1064 return FALSE;
1066 if (!DEBUG_PrintTypeCast(value->type))
1067 return FALSE;
1068 DEBUG_Printf(DBG_CHN_MESG, "\n");
1069 return TRUE;