Moved a number of 16-bit functions to file16.c.
[wine.git] / programs / winedbg / types.c
blob9fa7a37045046f0e57da45c7adfa41bc6c22fc8a
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 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
36 #include "debugger.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
41 #define NR_TYPE_HASH 521
43 int DEBUG_nchar;
44 static const int DEBUG_maxchar = 1024;
46 struct en_values
48 struct en_values* next;
49 char * name;
50 int value;
53 struct member
55 struct member * next;
56 char * name;
57 struct datatype * type;
58 int offset;
59 int size;
62 struct datatype
64 enum debug_type type;
65 struct datatype * next;
66 const char * name;
67 union
69 struct
71 char basic_type;
72 const char * output_format;
73 char basic_size;
74 unsigned b_signed:1;
75 } basic;
76 struct
78 unsigned short bitoff;
79 unsigned short nbits;
80 struct datatype * basetype;
81 } bitfield;
83 struct
85 struct datatype * pointsto;
86 } pointer;
87 struct
89 struct datatype * rettype;
90 } funct;
91 struct
93 int start;
94 int end;
95 struct datatype * basictype;
96 } array;
97 struct
99 int size;
100 struct member * members;
101 } structure;
102 struct
104 struct en_values * members;
105 } enumeration;
106 } un;
110 * All of the types that have been defined so far.
112 static struct datatype * type_hash_table[NR_TYPE_HASH + 1];
113 static struct datatype * pointer_types = NULL;
114 static struct datatype * basic_types[DT_BASIC_LAST];
116 static unsigned int type_hash( const char * name )
118 unsigned int hash = 0;
119 unsigned int tmp;
120 const char * p;
122 p = name;
124 while (*p)
126 hash = (hash << 4) + *p++;
128 if( (tmp = (hash & 0xf0000000)) )
130 hash ^= tmp >> 24;
132 hash &= ~tmp;
134 return hash % NR_TYPE_HASH;
138 static struct datatype *
139 DEBUG_InitBasic(int type, const char * name, int size, int b_signed,
140 const char * output_format)
142 int hash;
144 struct datatype * dt;
145 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
147 if( dt != NULL )
149 if( name != NULL )
151 hash = type_hash(name);
153 else
155 hash = NR_TYPE_HASH;
158 dt->type = DT_BASIC;
159 dt->name = name;
160 dt->next = type_hash_table[hash];
161 type_hash_table[hash] = dt;
162 dt->un.basic.basic_type = type;
163 dt->un.basic.basic_size = size;
164 dt->un.basic.b_signed = b_signed;
165 dt->un.basic.output_format = output_format;
166 basic_types[type] = dt;
169 return dt;
172 static
173 struct datatype *
174 DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename)
176 struct datatype * dt = NULL;
178 if( typename != NULL )
180 for( dt = type_hash_table[hash]; dt; dt = dt->next )
182 if( xtype != dt->type || dt->name == NULL
183 || dt->name[0] != typename[0])
185 continue;
188 if( strcmp(dt->name, typename) == 0 )
190 return dt;
195 return dt;
198 struct datatype *
199 DEBUG_GetBasicType(enum debug_type_basic basic)
201 if (basic == 0 || basic >= DT_BASIC_LAST)
203 return NULL;
205 return basic_types[basic];
208 struct datatype *
209 DEBUG_NewDataType(enum debug_type xtype, const char * typename)
211 struct datatype * dt = NULL;
212 int hash;
215 * The last bucket is special, and is used to hold typeless names.
217 if( typename == NULL )
219 hash = NR_TYPE_HASH;
221 else
223 hash = type_hash(typename);
226 dt = DEBUG_LookupDataType(xtype, hash, typename);
228 if( dt == NULL )
230 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
232 if( dt != NULL )
234 memset(dt, 0, sizeof(*dt));
236 dt->type = xtype;
237 if( typename != NULL )
239 dt->name = DBG_strdup(typename);
241 else
243 dt->name = NULL;
245 if( xtype == DT_POINTER )
247 dt->next = pointer_types;
248 pointer_types = dt;
250 else
252 dt->next = type_hash_table[hash];
253 type_hash_table[hash] = dt;
258 return dt;
261 struct datatype *
262 DEBUG_FindOrMakePointerType(struct datatype * reftype)
264 struct datatype * dt = NULL;
266 if( reftype != NULL )
268 for( dt = pointer_types; dt; dt = dt->next )
270 if( dt->type != DT_POINTER )
272 continue;
275 if( dt->un.pointer.pointsto == reftype )
277 return dt;
282 if( dt == NULL )
284 dt = (struct datatype *) DBG_alloc(sizeof(struct datatype));
286 if( dt != NULL )
288 dt->type = DT_POINTER;
289 dt->un.pointer.pointsto = reftype;
290 dt->next = pointer_types;
291 pointer_types = dt;
295 return dt;
298 void
299 DEBUG_InitTypes(void)
301 static int beenhere = 0;
303 if( beenhere++ != 0 )
305 return;
309 * Initialize a few builtin types.
312 DEBUG_InitBasic(DT_BASIC_INT,"int",4,1,"%d");
313 DEBUG_InitBasic(DT_BASIC_CHAR,"char",1,1,"'%c'");
314 DEBUG_InitBasic(DT_BASIC_LONGINT,"long int",4,1,"%d");
315 DEBUG_InitBasic(DT_BASIC_UINT,"unsigned int",4,0,"%d");
316 DEBUG_InitBasic(DT_BASIC_ULONGINT,"long unsigned int",4,0,"%d");
317 DEBUG_InitBasic(DT_BASIC_LONGLONGINT,"long long int",8,1,"%ld");
318 DEBUG_InitBasic(DT_BASIC_ULONGLONGINT,"long long unsigned int",8,0,"%ld");
319 DEBUG_InitBasic(DT_BASIC_SHORTINT,"short int",2,1,"%d");
320 DEBUG_InitBasic(DT_BASIC_USHORTINT,"short unsigned int",2,0,"%d");
321 DEBUG_InitBasic(DT_BASIC_SCHAR,"signed char",1,1,"'%c'");
322 DEBUG_InitBasic(DT_BASIC_UCHAR,"unsigned char",1,0,"'%c'");
323 DEBUG_InitBasic(DT_BASIC_FLOAT,"float",4,0,"%f");
324 DEBUG_InitBasic(DT_BASIC_DOUBLE,"long double",12,0,NULL);
325 DEBUG_InitBasic(DT_BASIC_LONGDOUBLE,"double",8,0,"%lf");
326 DEBUG_InitBasic(DT_BASIC_CMPLX_INT,"complex int",8,1,NULL);
327 DEBUG_InitBasic(DT_BASIC_CMPLX_FLOAT,"complex float",8,0,NULL);
328 DEBUG_InitBasic(DT_BASIC_CMPLX_DOUBLE,"complex double",16,0,NULL);
329 DEBUG_InitBasic(DT_BASIC_CMPLX_LONGDOUBLE,"complex long double",24,0,NULL);
330 DEBUG_InitBasic(DT_BASIC_VOID,"void",0,0,NULL);
331 DEBUG_InitBasic(DT_BASIC_BOOL1,NULL,1,0,"%B");
332 DEBUG_InitBasic(DT_BASIC_BOOL2,NULL,2,0,"%B");
333 DEBUG_InitBasic(DT_BASIC_BOOL4,NULL,4,0,"%B");
335 basic_types[DT_BASIC_STRING] = DEBUG_NewDataType(DT_POINTER, NULL);
336 DEBUG_SetPointerType(basic_types[DT_BASIC_STRING], basic_types[DT_BASIC_CHAR]);
339 * Special version of int used with constants of various kinds.
341 DEBUG_InitBasic(DT_BASIC_CONST_INT,NULL,4,1,"%d");
344 * Now initialize the builtins for codeview.
346 DEBUG_InitCVDataTypes();
348 DEBUG_InitBasic(DT_BASIC_CONTEXT,NULL,4,0,"%R");
351 long long int
352 DEBUG_GetExprValue(const DBG_VALUE* _value, const char** format)
354 long long int rtn;
355 unsigned int rtn2;
356 struct datatype * type2 = NULL;
357 struct en_values * e;
358 const char * def_format = "0x%x";
359 DBG_VALUE value = *_value;
361 assert(_value->cookie == DV_TARGET || _value->cookie == DV_HOST);
363 rtn = 0; rtn2 = 0;
364 /* FIXME? I don't quite get this...
365 * if this is wrong, value.addr shall be linearized
367 value.addr.seg = 0;
368 assert(value.type != NULL);
370 switch (value.type->type) {
371 case DT_BASIC:
373 if (value.type->un.basic.basic_size > sizeof(rtn)) {
374 WINE_ERR("Size too large (%d)\n", value.type->un.basic.basic_size);
375 return 0;
377 /* FIXME: following code implies i386 byte ordering */
378 if (_value->cookie == DV_TARGET) {
379 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn,
380 value.type->un.basic.basic_size))
381 return 0;
382 } else {
383 memcpy(&rtn, (void*)value.addr.off, value.type->un.basic.basic_size);
386 if ( (value.type->un.basic.b_signed)
387 && ((value.type->un.basic.basic_size & 3) != 0)
388 && ((rtn >> (value.type->un.basic.basic_size * 8 - 1)) != 0)) {
389 rtn = rtn | ((-1) << (value.type->un.basic.basic_size * 8));
391 /* float type has to be promoted as a double */
392 if (value.type->un.basic.basic_type == DT_BASIC_FLOAT) {
393 float f;
394 double d;
395 memcpy(&f, &rtn, sizeof(f));
396 d = (double)f;
397 memcpy(&rtn, &d, sizeof(rtn));
399 if (value.type->un.basic.output_format != NULL) {
400 def_format = value.type->un.basic.output_format;
404 * Check for single character prints that are out of range.
406 if ( value.type->un.basic.basic_size == 1
407 && strcmp(def_format, "'%c'") == 0
408 && ((rtn < 0x20) || (rtn > 0x80))) {
409 def_format = "%d";
411 break;
412 case DT_POINTER:
413 if (_value->cookie == DV_TARGET) {
414 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(void*)))
415 return 0;
416 } else {
417 rtn2 = *(unsigned int*)(value.addr.off);
420 type2 = value.type->un.pointer.pointsto;
422 if (!type2) {
423 def_format = "Internal symbol error: unable to access memory location 0x%08x";
424 rtn = 0;
425 break;
428 if (type2->type == DT_BASIC && type2->un.basic.basic_size == 1) {
429 if (_value->cookie == DV_TARGET) {
430 char ch;
431 def_format = "\"%S\"";
432 /* FIXME: assuming little endian */
433 if (!DEBUG_READ_MEM_VERBOSE((void*)rtn2, &ch, 1))
434 return 0;
435 } else {
436 def_format = "\"%s\"";
438 } else {
439 def_format = "0x%8.8x";
441 rtn = rtn2;
442 break;
443 case DT_ARRAY:
444 case DT_STRUCT:
445 assert(_value->cookie == DV_TARGET);
446 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(rtn2)))
447 return 0;
448 rtn = rtn2;
449 def_format = "0x%8.8x";
450 break;
451 case DT_ENUM:
452 assert(_value->cookie == DV_TARGET);
453 if (!DEBUG_READ_MEM_VERBOSE((void*)value.addr.off, &rtn2, sizeof(rtn2)))
454 return 0;
455 rtn = rtn2;
456 def_format = "%d";
457 for (e = value.type->un.enumeration.members; e; e = e->next) {
458 if (e->value == rtn) {
459 rtn = (int)e->name;
460 def_format = "%s";
461 break;
464 break;
465 default:
466 rtn = 0;
467 break;
471 if (format != NULL) {
472 *format = def_format;
474 return rtn;
477 unsigned int
478 DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype)
480 DBG_ADDR addr = value->addr;
481 unsigned int val;
483 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
485 *newtype = NULL;
488 * Make sure that this really makes sense.
490 if( value->type->type != DT_POINTER )
491 return 0;
493 if (value->cookie == DV_TARGET) {
494 if (!DEBUG_READ_MEM((void*)value->addr.off, &val, sizeof(val)))
495 return 0;
496 } else {
497 val = *(unsigned int*)value->addr.off;
500 *newtype = value->type->un.pointer.pointsto;
501 addr.off = val;
502 return DEBUG_ToLinear(&addr); /* FIXME: is this right (or "better") ? */
505 unsigned int
506 DEBUG_FindStructElement(DBG_VALUE* value, const char * ele_name, int * tmpbuf)
508 struct member * m;
509 unsigned int mask;
511 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
514 * Make sure that this really makes sense.
516 if( value->type->type != DT_STRUCT )
518 value->type = NULL;
519 return FALSE;
522 for(m = value->type->un.structure.members; m; m = m->next)
524 if( strcmp(m->name, ele_name) == 0 )
526 value->type = m->type;
527 if( (m->offset & 7) != 0 || (m->size & 7) != 0)
530 * Bitfield operation. We have to extract the field and store
531 * it in a temporary buffer so that we get it all right.
533 *tmpbuf = ((*(int* ) (value->addr.off + (m->offset >> 3))) >> (m->offset & 7));
534 value->addr.off = (int) tmpbuf;
536 mask = 0xffffffff << (m->size);
537 *tmpbuf &= ~mask;
539 * OK, now we have the correct part of the number.
540 * Check to see whether the basic type is signed or not, and if so,
541 * we need to sign extend the number.
543 if( m->type->type == DT_BASIC && m->type->un.basic.b_signed != 0
544 && (*tmpbuf & (1 << (m->size - 1))) != 0 )
546 *tmpbuf |= mask;
549 else
551 value->addr.off += (m->offset >> 3);
553 return TRUE;
557 value->type = NULL;
558 return FALSE;
562 DEBUG_SetStructSize(struct datatype * dt, int size)
564 assert(dt->type == DT_STRUCT);
566 if( dt->un.structure.members != NULL )
568 return FALSE;
571 dt->un.structure.size = size;
572 dt->un.structure.members = NULL;
574 return TRUE;
578 DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2)
580 if (!(dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM)))) {
581 DEBUG_Printf("Error: Copyfield list mismatch (%d<>%d): ", dt->type, dt2->type);
582 DEBUG_PrintTypeCast(dt);
583 DEBUG_Printf(" ");
584 DEBUG_PrintTypeCast(dt2);
585 DEBUG_Printf("\n");
586 return FALSE;
589 if( dt->type == DT_STRUCT )
591 dt->un.structure.members = dt2->un.structure.members;
593 else
595 dt->un.enumeration.members = dt2->un.enumeration.members;
598 return TRUE;
602 DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type,
603 int offset, int size)
605 struct member * m;
606 struct member * last;
607 struct en_values * e;
609 if( dt->type == DT_STRUCT )
611 for(last = dt->un.structure.members; last; last = last->next)
613 if( (last->name[0] == name[0])
614 && (strcmp(last->name, name) == 0) )
616 return TRUE;
618 if( last->next == NULL )
620 break;
623 m = (struct member *) DBG_alloc(sizeof(struct member));
624 if( m == NULL )
626 return FALSE;
629 m->name = DBG_strdup(name);
630 m->type = type;
631 m->offset = offset;
632 m->size = size;
633 if( last == NULL )
635 m->next = dt->un.structure.members;
636 dt->un.structure.members = m;
638 else
640 last->next = m;
641 m->next = NULL;
644 * If the base type is bitfield, then adjust the offsets here so that we
645 * are able to look things up without lots of falter-all.
647 if( type && type->type == DT_BITFIELD )
649 m->offset += m->type->un.bitfield.bitoff;
650 m->size = m->type->un.bitfield.nbits;
651 m->type = m->type->un.bitfield.basetype;
654 else if( dt->type == DT_ENUM )
656 e = (struct en_values *) DBG_alloc(sizeof(struct en_values));
657 if( e == FALSE )
659 return FALSE;
662 e->name = DBG_strdup(name);
663 e->value = offset;
664 e->next = dt->un.enumeration.members;
665 dt->un.enumeration.members = e;
667 else
669 assert(FALSE);
671 return TRUE;
674 struct datatype *
675 DEBUG_GetPointerType(struct datatype * dt)
677 if( dt->type == DT_POINTER )
679 return dt->un.pointer.pointsto;
682 return NULL;
686 DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2)
688 switch(dt->type)
690 case DT_POINTER:
691 dt->un.pointer.pointsto = dt2;
692 break;
693 case DT_FUNC:
694 dt->un.funct.rettype = dt2;
695 break;
696 default:
697 assert(FALSE);
700 return TRUE;
704 DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2)
706 assert(dt->type == DT_ARRAY);
707 dt->un.array.start = min;
708 dt->un.array.end = max;
709 dt->un.array.basictype = dt2;
711 return TRUE;
715 DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits,
716 struct datatype * dt2)
718 assert(dt->type == DT_BITFIELD);
719 dt->un.bitfield.bitoff = offset;
720 dt->un.bitfield.nbits = nbits;
721 dt->un.bitfield.basetype = dt2;
723 return TRUE;
726 int DEBUG_GetObjectSize(struct datatype * dt)
728 if( dt == NULL )
730 return 0;
733 switch(dt->type)
735 case DT_BASIC:
736 return dt->un.basic.basic_size;
737 case DT_POINTER:
738 return sizeof(int *);
739 case DT_STRUCT:
740 return dt->un.structure.size;
741 case DT_ENUM:
742 return sizeof(int);
743 case DT_ARRAY:
744 return (dt->un.array.end - dt->un.array.start)
745 * DEBUG_GetObjectSize(dt->un.array.basictype);
746 case DT_BITFIELD:
748 * Bitfields have to be handled separately later on
749 * when we insert the element into the structure.
751 return 0;
752 case DT_FUNC:
753 assert(FALSE);
754 default:
755 WINE_ERR("Unknown type???\n");
756 break;
758 return 0;
761 unsigned int
762 DEBUG_ArrayIndex(const DBG_VALUE * value, DBG_VALUE * result, int index)
764 int size;
766 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
769 * Make sure that this really makes sense.
771 if( value->type->type == DT_POINTER )
774 * Get the base type, so we know how much to index by.
776 size = DEBUG_GetObjectSize(value->type->un.pointer.pointsto);
777 result->type = value->type->un.pointer.pointsto;
778 result->addr.off = (DWORD)DEBUG_ReadMemory(value) + size*index;
780 /* Contents of array must be on same target */
781 result->cookie = value->cookie;
783 else if (value->type->type == DT_ARRAY)
785 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
786 result->type = value->type->un.array.basictype;
787 result->addr.off = value->addr.off + size * (index - value->type->un.array.start);
789 /* Contents of array must be on same target */
790 result->cookie = value->cookie;
792 else
794 assert(FALSE);
797 return TRUE;
800 /***********************************************************************
801 * DEBUG_Print
803 * Implementation of the 'print' command.
805 void
806 DEBUG_Print( const DBG_VALUE *value, int count, char format, int level )
808 DBG_VALUE val1;
809 int i;
810 struct member * m;
811 char * pnt;
812 int size;
813 int xval;
815 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
817 if (count != 1)
819 DEBUG_Printf("Count other than 1 is meaningless in 'print' command\n");
820 return;
823 if( value->type == NULL )
825 /* No type, just print the addr value */
826 if (value->addr.seg && (value->addr.seg != 0xffffffff))
827 DEBUG_nchar += DEBUG_Printf("0x%04lx: ", value->addr.seg);
828 DEBUG_nchar += DEBUG_Printf("0x%08lx", value->addr.off);
829 goto leave;
832 if( level == 0 )
834 DEBUG_nchar = 0;
837 if( DEBUG_nchar > DEBUG_maxchar )
839 DEBUG_Printf("...");
840 goto leave;
843 if( format == 'i' || format == 's' || format == 'w' || format == 'b' || format == 'g')
845 DEBUG_Printf("Format specifier '%c' is meaningless in 'print' command\n", format);
846 format = '\0';
849 switch(value->type->type)
851 case DT_BASIC:
852 case DT_ENUM:
853 case DT_POINTER:
854 DEBUG_PrintBasic(value, 1, format);
855 break;
856 case DT_STRUCT:
857 DEBUG_nchar += DEBUG_Printf("{");
858 for(m = value->type->un.structure.members; m; m = m->next)
860 val1 = *value;
861 DEBUG_FindStructElement(&val1, m->name, &xval);
862 DEBUG_nchar += DEBUG_Printf("%s=", m->name);
863 DEBUG_Print(&val1, 1, format, level + 1);
864 if( m->next != NULL )
866 DEBUG_nchar += DEBUG_Printf(", ");
868 if( DEBUG_nchar > DEBUG_maxchar )
870 DEBUG_Printf("...}");
871 goto leave;
874 DEBUG_nchar += DEBUG_Printf("}");
875 break;
876 case DT_ARRAY:
878 * Loop over all of the entries, printing stuff as we go.
880 size = DEBUG_GetObjectSize(value->type->un.array.basictype);
881 if( size == 1 )
883 int len, clen;
886 * Special handling for character arrays.
888 pnt = (char *) value->addr.off;
889 len = value->type->un.array.end - value->type->un.array.start + 1;
890 clen = (DEBUG_nchar + len < DEBUG_maxchar)
891 ? len : (DEBUG_maxchar - DEBUG_nchar);
893 DEBUG_nchar += DEBUG_Printf("\"");
894 switch (value->cookie)
896 case DV_TARGET:
897 DEBUG_nchar += DEBUG_PrintStringA(&value->addr, clen);
898 break;
899 case DV_HOST:
900 DEBUG_OutputA(pnt, clen);
901 break;
902 default: assert(0);
904 DEBUG_nchar += DEBUG_Printf((len > clen) ? "...\"" : "\"");
905 break;
907 val1 = *value;
908 val1.type = value->type->un.array.basictype;
909 DEBUG_nchar += DEBUG_Printf("{");
910 for( i=value->type->un.array.start; i <= value->type->un.array.end; i++ )
912 DEBUG_Print(&val1, 1, format, level + 1);
913 val1.addr.off += size;
914 if( i == value->type->un.array.end )
916 DEBUG_nchar += DEBUG_Printf("}");
918 else
920 DEBUG_nchar += DEBUG_Printf(", ");
922 if( DEBUG_nchar > DEBUG_maxchar )
924 DEBUG_Printf("...}");
925 goto leave;
928 break;
929 case DT_FUNC:
930 DEBUG_Printf("Function at ???\n");
931 break;
932 default:
933 DEBUG_Printf("Unknown type (%d)\n", value->type->type);
934 assert(FALSE);
935 break;
938 leave:
940 if( level == 0 )
942 DEBUG_nchar += DEBUG_Printf("\n");
946 static void DEBUG_DumpAType(struct datatype* dt, BOOL deep)
948 const char* name = (dt->name) ? dt->name : "--none--";
950 switch (dt->type)
952 case DT_BASIC:
953 DEBUG_Printf("BASIC(%s)", name);
954 break;
955 case DT_POINTER:
956 DEBUG_Printf("POINTER(%s)<", name);
957 DEBUG_DumpAType(dt->un.pointer.pointsto, FALSE);
958 DEBUG_Printf(">");
959 break;
960 case DT_STRUCT:
961 DEBUG_Printf("STRUCT(%s) %d {",
962 name, dt->un.structure.size);
963 if (dt->un.structure.members != NULL)
965 struct member * m;
966 for (m = dt->un.structure.members; m; m = m->next)
968 DEBUG_Printf(" %s(%d", m->name, m->offset / 8);
969 if (m->offset % 8 != 0)
970 DEBUG_Printf(".%d", m->offset / 8);
971 DEBUG_Printf("/%d", m->size / 8);
972 if (m->size % 8 != 0)
973 DEBUG_Printf(".%d", m->size % 8);
974 DEBUG_Printf(")");
977 DEBUG_Printf(" }");
978 break;
979 case DT_ARRAY:
980 DEBUG_Printf("ARRAY(%s)[", name);
981 DEBUG_DumpAType(dt->un.array.basictype, FALSE);
982 DEBUG_Printf("]");
983 break;
984 case DT_ENUM:
985 DEBUG_Printf("ENUM(%s)", name);
986 break;
987 case DT_BITFIELD:
988 DEBUG_Printf("BITFIELD(%s)", name);
989 break;
990 case DT_FUNC:
991 DEBUG_Printf("FUNC(%s)(", name);
992 DEBUG_DumpAType(dt->un.funct.rettype, FALSE);
993 DEBUG_Printf(")");
994 break;
995 default:
996 WINE_ERR("Unknown type???");
997 break;
999 if (deep) DEBUG_Printf("\n");
1002 int DEBUG_DumpTypes(void)
1004 struct datatype * dt = NULL;
1005 int hash;
1007 for (hash = 0; hash < NR_TYPE_HASH + 1; hash++)
1009 for (dt = type_hash_table[hash]; dt; dt = dt->next)
1011 DEBUG_DumpAType(dt, TRUE);
1014 return TRUE;
1017 enum debug_type DEBUG_GetType(struct datatype * dt)
1019 return dt->type;
1022 const char* DEBUG_GetName(struct datatype * dt)
1024 return dt->name;
1027 struct datatype *
1028 DEBUG_TypeCast(enum debug_type type, const char * name)
1030 int hash;
1033 * The last bucket is special, and is used to hold typeless names.
1035 if( name == NULL )
1037 hash = NR_TYPE_HASH;
1039 else
1041 hash = type_hash(name);
1044 return DEBUG_LookupDataType(type, hash, name);
1048 DEBUG_PrintTypeCast(const struct datatype * dt)
1050 const char* name = "none";
1052 if(dt == NULL)
1054 DEBUG_Printf("--invalid--");
1055 return FALSE;
1058 if( dt->name != NULL )
1060 name = dt->name;
1063 switch(dt->type)
1065 case DT_BASIC:
1066 DEBUG_Printf("%s", name);
1067 break;
1068 case DT_POINTER:
1069 DEBUG_PrintTypeCast(dt->un.pointer.pointsto);
1070 DEBUG_Printf("*");
1071 break;
1072 case DT_STRUCT:
1073 DEBUG_Printf("struct %s", name);
1074 break;
1075 case DT_ARRAY:
1076 DEBUG_Printf("%s[]", name);
1077 break;
1078 case DT_ENUM:
1079 DEBUG_Printf("enum %s", name);
1080 break;
1081 case DT_BITFIELD:
1082 DEBUG_Printf("unsigned %s", name);
1083 break;
1084 case DT_FUNC:
1085 DEBUG_PrintTypeCast(dt->un.funct.rettype);
1086 DEBUG_Printf("(*%s)()", name);
1087 break;
1088 default:
1089 WINE_ERR("Unknown type???\n");
1090 break;
1093 return TRUE;
1096 int DEBUG_PrintType( const DBG_VALUE *value )
1098 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
1100 if (!value->type)
1102 DEBUG_Printf("Unknown type\n");
1103 return FALSE;
1105 if (!DEBUG_PrintTypeCast(value->type))
1106 return FALSE;
1107 DEBUG_Printf("\n");
1108 return TRUE;