Unregister 16-bit dlls on module unload.
[wine/multimedia.git] / debugger / types.c
blob16d3ca5dcfd563d1ed843c5a801df4cbc5b3304f
1 /*
2 * File types.c - datatype handling stuff for internal debugger.
4 * Copyright (C) 1997, Eric Youngdale.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Note: This really doesn't do much at the moment, but it forms the framework
21 * upon which full support for datatype handling will eventually be built.
24 #include "config.h"
25 #include <stdlib.h>
27 #include <fcntl.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <limits.h>
31 #include <string.h>
32 #include <unistd.h>
34 #include "debugger.h"
36 #define NR_TYPE_HASH 521
38 int DEBUG_nchar;
39 static int DEBUG_maxchar = 1024;
41 struct en_values
43 struct en_values* next;
44 char * name;
45 int value;
48 struct member
50 struct member * next;
51 char * name;
52 struct datatype * type;
53 int offset;
54 int size;
57 struct datatype
59 enum debug_type type;
60 struct datatype * next;
61 char * name;
62 union
64 struct
66 char basic_type;
67 char * output_format;
68 char basic_size;
69 unsigned b_signed:1;
70 } basic;
71 struct
73 unsigned short bitoff;
74 unsigned short nbits;
75 struct datatype * basetype;
76 } bitfield;
78 struct
80 struct datatype * pointsto;
81 } pointer;
82 struct
84 struct datatype * rettype;
85 } funct;
86 struct
88 int start;
89 int end;
90 struct datatype * basictype;
91 } array;
92 struct
94 int size;
95 struct member * members;
96 } structure;
97 struct
99 struct en_values * members;
100 } enumeration;
101 } un;
105 * All of the types that have been defined so far.
107 static struct datatype * type_hash_table[NR_TYPE_HASH + 1];
108 static struct datatype * pointer_types = NULL;
109 static struct datatype * basic_types[DT_BASIC_LAST];
111 static unsigned int type_hash( const char * name )
113 unsigned int hash = 0;
114 unsigned int tmp;
115 const char * p;
117 p = name;
119 while (*p)
121 hash = (hash << 4) + *p++;
123 if( (tmp = (hash & 0xf0000000)) )
125 hash ^= tmp >> 24;
127 hash &= ~tmp;
129 return hash % NR_TYPE_HASH;
133 static struct datatype *
134 DEBUG_InitBasic(int type, char * name, int size, int b_signed,
135 char * output_format)
137 int hash;
139 struct datatype * dt;
140 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
142 if( dt != NULL )
144 if( name != NULL )
146 hash = type_hash(name);
148 else
150 hash = NR_TYPE_HASH;
153 dt->type = DT_BASIC;
154 dt->name = name;
155 dt->next = type_hash_table[hash];
156 type_hash_table[hash] = dt;
157 dt->un.basic.basic_type = type;
158 dt->un.basic.basic_size = size;
159 dt->un.basic.b_signed = b_signed;
160 dt->un.basic.output_format = output_format;
161 basic_types[type] = dt;
164 return dt;
167 static
168 struct datatype *
169 DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename)
171 struct datatype * dt = NULL;
173 if( typename != NULL )
175 for( dt = type_hash_table[hash]; dt; dt = dt->next )
177 if( xtype != dt->type || dt->name == NULL
178 || dt->name[0] != typename[0])
180 continue;
183 if( strcmp(dt->name, typename) == 0 )
185 return dt;
190 return dt;
193 struct datatype *
194 DEBUG_GetBasicType(enum debug_type_basic basic)
196 if (basic == 0 || basic >= DT_BASIC_LAST)
198 return NULL;
200 return basic_types[basic];
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;
298 if( beenhere++ != 0 )
300 return;
304 * Initialize a few builtin types.
307 DEBUG_InitBasic(DT_BASIC_INT,"int",4,1,"%d");
308 DEBUG_InitBasic(DT_BASIC_CHAR,"char",1,1,"'%c'");
309 DEBUG_InitBasic(DT_BASIC_LONGINT,"long int",4,1,"%d");
310 DEBUG_InitBasic(DT_BASIC_UINT,"unsigned int",4,0,"%d");
311 DEBUG_InitBasic(DT_BASIC_ULONGINT,"long unsigned int",4,0,"%d");
312 DEBUG_InitBasic(DT_BASIC_LONGLONGINT,"long long int",8,1,"%ld");
313 DEBUG_InitBasic(DT_BASIC_ULONGLONGINT,"long long unsigned int",8,0,"%ld");
314 DEBUG_InitBasic(DT_BASIC_SHORTINT,"short int",2,1,"%d");
315 DEBUG_InitBasic(DT_BASIC_USHORTINT,"short unsigned int",2,0,"%d");
316 DEBUG_InitBasic(DT_BASIC_SCHAR,"signed char",1,1,"'%c'");
317 DEBUG_InitBasic(DT_BASIC_UCHAR,"unsigned char",1,0,"'%c'");
318 DEBUG_InitBasic(DT_BASIC_FLOAT,"float",4,0,"%f");
319 DEBUG_InitBasic(DT_BASIC_DOUBLE,"long double",12,0,NULL);
320 DEBUG_InitBasic(DT_BASIC_LONGDOUBLE,"double",8,0,"%lf");
321 DEBUG_InitBasic(DT_BASIC_CMPLX_INT,"complex int",8,1,NULL);
322 DEBUG_InitBasic(DT_BASIC_CMPLX_FLOAT,"complex float",8,0,NULL);
323 DEBUG_InitBasic(DT_BASIC_CMPLX_DOUBLE,"complex double",16,0,NULL);
324 DEBUG_InitBasic(DT_BASIC_CMPLX_LONGDOUBLE,"complex long double",24,0,NULL);
325 DEBUG_InitBasic(DT_BASIC_VOID,"void",0,0,NULL);
326 DEBUG_InitBasic(DT_BASIC_BOOL1,NULL,1,0,"%B");
327 DEBUG_InitBasic(DT_BASIC_BOOL2,NULL,2,0,"%B");
328 DEBUG_InitBasic(DT_BASIC_BOOL4,NULL,4,0,"%B");
330 basic_types[DT_BASIC_STRING] = DEBUG_NewDataType(DT_POINTER, NULL);
331 DEBUG_SetPointerType(basic_types[DT_BASIC_STRING], basic_types[DT_BASIC_CHAR]);
334 * Special version of int used with constants of various kinds.
336 DEBUG_InitBasic(DT_BASIC_CONST_INT,NULL,4,1,"%d");
339 * Now initialize the builtins for codeview.
341 DEBUG_InitCVDataTypes();
345 long long int
346 DEBUG_GetExprValue(const DBG_VALUE* _value, char** format)
348 long long int rtn;
349 unsigned int rtn2;
350 struct datatype * type2 = NULL;
351 struct en_values * e;
352 char * def_format = "0x%x";
353 DBG_VALUE value = *_value;
355 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
357 rtn = 0; rtn2 = 0;
358 /* FIXME? I don't quite get this...
359 * if this is wrong, value.addr shall be linearized
361 value.addr.seg = 0;
362 assert(value.type != NULL);
364 switch (value.type->type) {
365 case DT_BASIC:
367 if (value.type->un.basic.basic_size > sizeof(rtn)) {
368 DEBUG_Printf(DBG_CHN_ERR, "Size too large (%d)\n",
369 value.type->un.basic.basic_size);
370 return 0;
372 /* FIXME: following code implies i386 byte ordering */
373 if (_value->cookie == DV_TARGET) {
374 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn,
375 value.type->un.basic.basic_size))
376 return 0;
377 } else {
378 memcpy(&rtn, (void*)value.addr.off, value.type->un.basic.basic_size);
381 if ( (value.type->un.basic.b_signed)
382 && ((value.type->un.basic.basic_size & 3) != 0)
383 && ((rtn >> (value.type->un.basic.basic_size * 8 - 1)) != 0)) {
384 rtn = rtn | ((-1) << (value.type->un.basic.basic_size * 8));
386 /* float type has to be promoted as a double */
387 if (value.type->un.basic.basic_type == DT_BASIC_FLOAT) {
388 float f;
389 double d;
390 memcpy(&f, &rtn, sizeof(f));
391 d = (double)f;
392 memcpy(&rtn, &d, sizeof(rtn));
394 if (value.type->un.basic.output_format != NULL) {
395 def_format = value.type->un.basic.output_format;
399 * Check for single character prints that are out of range.
401 if ( value.type->un.basic.basic_size == 1
402 && strcmp(def_format, "'%c'") == 0
403 && ((rtn < 0x20) || (rtn > 0x80))) {
404 def_format = "%d";
406 break;
407 case DT_POINTER:
408 if (_value->cookie == DV_TARGET) {
409 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(void*)))
410 return 0;
411 } else {
412 rtn2 = *(unsigned int*)(value.addr.off);
415 type2 = value.type->un.pointer.pointsto;
417 if (!type2) {
418 def_format = "Internal symbol error: unable to access memory location 0x%08x";
419 rtn = 0;
420 break;
423 if (type2->type == DT_BASIC && type2->un.basic.basic_size == 1) {
424 if (_value->cookie == DV_TARGET) {
425 char ch;
426 def_format = "\"%S\"";
427 /* FIXME: assuming little endian */
428 if (!DEBUG_READ_MEM_VERBOSE((void*)rtn2, &ch, 1))
429 return 0;
430 } else {
431 def_format = "\"%s\"";
433 } else {
434 def_format = "0x%8.8x";
436 rtn = rtn2;
437 break;
438 case DT_ARRAY:
439 case DT_STRUCT:
440 assert(_value->cookie == DV_TARGET);
441 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(rtn2)))
442 return 0;
443 rtn = rtn2;
444 def_format = "0x%8.8x";
445 break;
446 case DT_ENUM:
447 assert(_value->cookie == DV_TARGET);
448 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(rtn2)))
449 return 0;
450 rtn = rtn2;
451 def_format = "%d";
452 for (e = value.type->un.enumeration.members; e; e = e->next) {
453 if (e->value == rtn) {
454 rtn = (int)e->name;
455 def_format = "%s";
456 break;
459 break;
460 default:
461 rtn = 0;
462 break;
466 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)
575 if (!(dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM)))) {
576 DEBUG_Printf(DBG_CHN_MESG, "Error: Copyfield list mismatch (%d<>%d): ", dt->type, dt2->type);
577 DEBUG_PrintTypeCast(dt);
578 DEBUG_Printf(DBG_CHN_MESG, " ");
579 DEBUG_PrintTypeCast(dt2);
580 DEBUG_Printf(DBG_CHN_MESG, "\n");
581 return FALSE;
584 if( dt->type == DT_STRUCT )
586 dt->un.structure.members = dt2->un.structure.members;
588 else
590 dt->un.enumeration.members = dt2->un.enumeration.members;
593 return TRUE;
597 DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type,
598 int offset, int size)
600 struct member * m;
601 struct member * last;
602 struct en_values * e;
604 if( dt->type == DT_STRUCT )
606 for(last = dt->un.structure.members; last; last = last->next)
608 if( (last->name[0] == name[0])
609 && (strcmp(last->name, name) == 0) )
611 return TRUE;
613 if( last->next == NULL )
615 break;
618 m = (struct member *) DBG_alloc(sizeof(struct member));
619 if( m == FALSE )
621 return FALSE;
624 m->name = DBG_strdup(name);
625 m->type = type;
626 m->offset = offset;
627 m->size = size;
628 if( last == NULL )
630 m->next = dt->un.structure.members;
631 dt->un.structure.members = m;
633 else
635 last->next = m;
636 m->next = NULL;
639 * If the base type is bitfield, then adjust the offsets here so that we
640 * are able to look things up without lots of falter-all.
642 if( type && type->type == DT_BITFIELD )
644 m->offset += m->type->un.bitfield.bitoff;
645 m->size = m->type->un.bitfield.nbits;
646 m->type = m->type->un.bitfield.basetype;
649 else if( dt->type == DT_ENUM )
651 e = (struct en_values *) DBG_alloc(sizeof(struct en_values));
652 if( e == FALSE )
654 return FALSE;
657 e->name = DBG_strdup(name);
658 e->value = offset;
659 e->next = dt->un.enumeration.members;
660 dt->un.enumeration.members = e;
662 else
664 assert(FALSE);
666 return TRUE;
669 struct datatype *
670 DEBUG_GetPointerType(struct datatype * dt)
672 if( dt->type == DT_POINTER )
674 return dt->un.pointer.pointsto;
677 return NULL;
681 DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2)
683 switch(dt->type)
685 case DT_POINTER:
686 dt->un.pointer.pointsto = dt2;
687 break;
688 case DT_FUNC:
689 dt->un.funct.rettype = dt2;
690 break;
691 default:
692 assert(FALSE);
695 return TRUE;
699 DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2)
701 assert(dt->type == DT_ARRAY);
702 dt->un.array.start = min;
703 dt->un.array.end = max;
704 dt->un.array.basictype = dt2;
706 return TRUE;
710 DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits,
711 struct datatype * dt2)
713 assert(dt->type == DT_BITFIELD);
714 dt->un.bitfield.bitoff = offset;
715 dt->un.bitfield.nbits = nbits;
716 dt->un.bitfield.basetype = dt2;
718 return TRUE;
721 int DEBUG_GetObjectSize(struct datatype * dt)
723 if( dt == NULL )
725 return 0;
728 switch(dt->type)
730 case DT_BASIC:
731 return dt->un.basic.basic_size;
732 case DT_POINTER:
733 return sizeof(int *);
734 case DT_STRUCT:
735 return dt->un.structure.size;
736 case DT_ENUM:
737 return sizeof(int);
738 case DT_ARRAY:
739 return (dt->un.array.end - dt->un.array.start)
740 * DEBUG_GetObjectSize(dt->un.array.basictype);
741 case DT_BITFIELD:
743 * Bitfields have to be handled separately later on
744 * when we insert the element into the structure.
746 return 0;
747 case DT_FUNC:
748 assert(FALSE);
749 default:
750 DEBUG_Printf(DBG_CHN_ERR, "Unknown type???\n");
751 break;
753 return 0;
756 unsigned int
757 DEBUG_ArrayIndex(const DBG_VALUE * value, DBG_VALUE * result, int index)
759 int size;
761 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
764 * Make sure that this really makes sense.
766 if( value->type->type == DT_POINTER )
769 * Get the base type, so we know how much to index by.
771 size = DEBUG_GetObjectSize(value->type->un.pointer.pointsto);
772 result->type = value->type->un.pointer.pointsto;
773 result->addr.off = (DWORD)DEBUG_ReadMemory(value) + size*index;
775 /* Contents of array must be on same target */
776 result->cookie = value->cookie;
778 else if (value->type->type == DT_ARRAY)
780 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
781 result->type = value->type->un.array.basictype;
782 result->addr.off = value->addr.off + size * (index - value->type->un.array.start);
784 /* Contents of array must be on same target */
785 result->cookie = value->cookie;
787 else
789 assert(FALSE);
792 return TRUE;
795 /***********************************************************************
796 * DEBUG_Print
798 * Implementation of the 'print' command.
800 void
801 DEBUG_Print( const DBG_VALUE *value, int count, char format, int level )
803 DBG_VALUE val1;
804 int i;
805 struct member * m;
806 char * pnt;
807 int size;
808 int xval;
810 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
812 if (count != 1)
814 DEBUG_Printf( DBG_CHN_MESG, "Count other than 1 is meaningless in 'print' command\n" );
815 return;
818 if( value->type == NULL )
820 /* No type, just print the addr value */
821 if (value->addr.seg && (value->addr.seg != 0xffffffff))
822 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%04lx: ", value->addr.seg );
823 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", value->addr.off );
824 goto leave;
827 if( level == 0 )
829 DEBUG_nchar = 0;
832 if( DEBUG_nchar > DEBUG_maxchar )
834 DEBUG_Printf(DBG_CHN_MESG, "...");
835 goto leave;
838 if( format == 'i' || format == 's' || format == 'w' || format == 'b' || format == 'g')
840 DEBUG_Printf( DBG_CHN_MESG, "Format specifier '%c' is meaningless in 'print' command\n", format );
841 format = '\0';
844 switch(value->type->type)
846 case DT_BASIC:
847 case DT_ENUM:
848 case DT_POINTER:
849 DEBUG_PrintBasic(value, 1, format);
850 break;
851 case DT_STRUCT:
852 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "{");
853 for(m = value->type->un.structure.members; m; m = m->next)
855 val1 = *value;
856 DEBUG_FindStructElement(&val1, m->name, &xval);
857 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%s=", m->name);
858 DEBUG_Print(&val1, 1, format, level + 1);
859 if( m->next != NULL )
861 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, ", ");
863 if( DEBUG_nchar > DEBUG_maxchar )
865 DEBUG_Printf(DBG_CHN_MESG, "...}");
866 goto leave;
869 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "}");
870 break;
871 case DT_ARRAY:
873 * Loop over all of the entries, printing stuff as we go.
875 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
876 if( size == 1 )
878 int len, clen;
881 * Special handling for character arrays.
883 pnt = (char *) value->addr.off;
884 len = value->type->un.array.end - value->type->un.array.start + 1;
885 clen = (DEBUG_nchar + len < DEBUG_maxchar)
886 ? len : (DEBUG_maxchar - DEBUG_nchar);
888 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
889 switch (value->cookie)
891 case DV_TARGET:
892 clen = DEBUG_PrintStringA(DBG_CHN_MESG, &value->addr, clen);
893 break;
894 case DV_HOST:
895 DEBUG_OutputA(DBG_CHN_MESG, pnt, clen);
896 break;
897 default: assert(0);
899 DEBUG_nchar += clen;
900 if (clen != len)
902 DEBUG_Printf(DBG_CHN_MESG, "...\"");
903 goto leave;
905 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
906 break;
908 val1 = *value;
909 val1.type = value->type->un.array.basictype;
910 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "{");
911 for( i=value->type->un.array.start; i <= value->type->un.array.end; i++ )
913 DEBUG_Print(&val1, 1, format, level + 1);
914 val1.addr.off += size;
915 if( i == value->type->un.array.end )
917 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "}");
919 else
921 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, ", ");
923 if( DEBUG_nchar > DEBUG_maxchar )
925 DEBUG_Printf(DBG_CHN_MESG, "...}");
926 goto leave;
929 break;
930 case DT_FUNC:
931 DEBUG_Printf(DBG_CHN_MESG, "Function at ???\n");
932 break;
933 default:
934 DEBUG_Printf(DBG_CHN_MESG, "Unknown type (%d)\n", value->type->type);
935 assert(FALSE);
936 break;
939 leave:
941 if( level == 0 )
943 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\n");
945 return;
949 DEBUG_DumpTypes(void)
951 struct datatype * dt = NULL;
952 struct member * m;
953 int hash;
954 int nm;
955 char * name;
956 char * member_name;
958 for(hash = 0; hash < NR_TYPE_HASH + 1; hash++)
960 for( dt = type_hash_table[hash]; dt; dt = dt->next )
962 name = "none";
963 if( dt->name != NULL )
965 name = dt->name;
967 switch(dt->type)
969 case DT_BASIC:
970 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BASIC(%s)\n",
971 (unsigned long)dt, name);
972 break;
973 case DT_POINTER:
974 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - POINTER(%s)(%08lx)\n",
975 (unsigned long)dt, name, (unsigned long)dt->un.pointer.pointsto);
976 break;
977 case DT_STRUCT:
978 member_name = "none";
979 nm = 0;
980 if( dt->un.structure.members != NULL
981 && dt->un.structure.members->name != NULL )
983 member_name = dt->un.structure.members->name;
984 for( m = dt->un.structure.members; m; m = m->next)
986 nm++;
989 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - STRUCT(%s) %d %d %s\n",
990 (unsigned long)dt, name, dt->un.structure.size, nm, member_name);
991 break;
992 case DT_ARRAY:
993 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ARRAY(%s)(%08lx)\n",
994 (unsigned long)dt, name, (unsigned long)dt->un.array.basictype);
995 break;
996 case DT_ENUM:
997 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ENUM(%s)\n",
998 (unsigned long)dt, name);
999 break;
1000 case DT_BITFIELD:
1001 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BITFIELD(%s)\n",
1002 (unsigned long)dt, name);
1003 break;
1004 case DT_FUNC:
1005 DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - FUNC(%s)(%08lx)\n",
1006 (unsigned long)dt, name, (unsigned long)dt->un.funct.rettype);
1007 break;
1008 default:
1009 DEBUG_Printf(DBG_CHN_ERR, "Unknown type???\n");
1010 break;
1014 return TRUE;
1018 enum debug_type DEBUG_GetType(struct datatype * dt)
1020 return dt->type;
1023 struct datatype *
1024 DEBUG_TypeCast(enum debug_type type, const char * name)
1026 int hash;
1029 * The last bucket is special, and is used to hold typeless names.
1031 if( name == NULL )
1033 hash = NR_TYPE_HASH;
1035 else
1037 hash = type_hash(name);
1040 return DEBUG_LookupDataType(type, hash, name);
1044 DEBUG_PrintTypeCast(const struct datatype * dt)
1046 const char* name = "none";
1048 if(dt == NULL)
1050 DEBUG_Printf(DBG_CHN_MESG, "--invalid--");
1051 return FALSE;
1054 if( dt->name != NULL )
1056 name = dt->name;
1059 switch(dt->type)
1061 case DT_BASIC:
1062 DEBUG_Printf(DBG_CHN_MESG, "%s", name);
1063 break;
1064 case DT_POINTER:
1065 DEBUG_PrintTypeCast(dt->un.pointer.pointsto);
1066 DEBUG_Printf(DBG_CHN_MESG, "*");
1067 break;
1068 case DT_STRUCT:
1069 DEBUG_Printf(DBG_CHN_MESG, "struct %s", name);
1070 break;
1071 case DT_ARRAY:
1072 DEBUG_Printf(DBG_CHN_MESG, "%s[]", name);
1073 break;
1074 case DT_ENUM:
1075 DEBUG_Printf(DBG_CHN_MESG, "enum %s", name);
1076 break;
1077 case DT_BITFIELD:
1078 DEBUG_Printf(DBG_CHN_MESG, "unsigned %s", name);
1079 break;
1080 case DT_FUNC:
1081 DEBUG_PrintTypeCast(dt->un.funct.rettype);
1082 DEBUG_Printf(DBG_CHN_MESG, "(*%s)()", name);
1083 break;
1084 default:
1085 DEBUG_Printf(DBG_CHN_ERR, "Unknown type???\n");
1086 break;
1089 return TRUE;
1092 int DEBUG_PrintType( const DBG_VALUE *value )
1094 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
1096 if (!value->type)
1098 DEBUG_Printf(DBG_CHN_MESG, "Unknown type\n");
1099 return FALSE;
1101 if (!DEBUG_PrintTypeCast(value->type))
1102 return FALSE;
1103 DEBUG_Printf(DBG_CHN_MESG, "\n");
1104 return TRUE;