Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * File types.c - datatype handling stuff for internal debugger. |
| 3 | * |
| 4 | * Copyright (C) 1997, Eric Youngdale. |
| 5 | * |
| 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 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | |
| 13 | #include <assert.h> |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 14 | #include <fcntl.h> |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 15 | #include <sys/types.h> |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 16 | #include <sys/stat.h> |
| 17 | #include <limits.h> |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 18 | #include <string.h> |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 19 | #include <unistd.h> |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 20 | |
| 21 | #include "win.h" |
| 22 | #include "pe_image.h" |
| 23 | #include "peexe.h" |
| 24 | #include "debugger.h" |
| 25 | #include "peexe.h" |
| 26 | #include "xmalloc.h" |
| 27 | |
| 28 | #define NR_TYPE_HASH 521 |
| 29 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 30 | int DEBUG_nchar; |
| 31 | static int DEBUG_maxchar = 1024; |
| 32 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 33 | struct en_values |
| 34 | { |
| 35 | struct en_values* next; |
| 36 | char * name; |
| 37 | int value; |
| 38 | }; |
| 39 | |
| 40 | struct member |
| 41 | { |
| 42 | struct member * next; |
| 43 | char * name; |
| 44 | struct datatype * type; |
| 45 | int offset; |
| 46 | int size; |
| 47 | }; |
| 48 | |
| 49 | struct datatype |
| 50 | { |
| 51 | enum debug_type type; |
| 52 | struct datatype * next; |
| 53 | char * name; |
| 54 | union |
| 55 | { |
| 56 | struct |
| 57 | { |
| 58 | char basic_type; |
| 59 | char * output_format; |
| 60 | char basic_size; |
| 61 | unsigned b_signed:1; |
| 62 | } basic; |
| 63 | struct |
| 64 | { |
| 65 | unsigned short bitoff; |
| 66 | unsigned short nbits; |
| 67 | struct datatype * basetype; |
| 68 | } bitfield; |
| 69 | |
| 70 | struct |
| 71 | { |
| 72 | struct datatype * pointsto; |
| 73 | } pointer; |
| 74 | struct |
| 75 | { |
| 76 | struct datatype * rettype; |
| 77 | } funct; |
| 78 | struct |
| 79 | { |
| 80 | int start; |
| 81 | int end; |
| 82 | struct datatype * basictype; |
| 83 | } array; |
| 84 | struct |
| 85 | { |
| 86 | int size; |
| 87 | struct member * members; |
| 88 | } structure; |
| 89 | struct |
| 90 | { |
| 91 | struct en_values * members; |
| 92 | } enumeration; |
| 93 | } un; |
| 94 | }; |
| 95 | |
| 96 | #define BASIC_INT 1 |
| 97 | #define BASIC_CHAR 2 |
| 98 | #define BASIC_LONG 3 |
| 99 | #define BASIC_UINT 4 |
| 100 | #define BASIC_LUI 5 |
| 101 | #define BASIC_LONGLONG 6 |
| 102 | #define BASIC_ULONGLONGI 7 |
| 103 | #define BASIC_SHORT 8 |
| 104 | #define BASIC_SHORTUI 9 |
| 105 | #define BASIC_SCHAR 10 |
| 106 | #define BASIC_UCHAR 11 |
| 107 | #define BASIC_FLT 12 |
| 108 | #define BASIC_LONG_DOUBLE 13 |
| 109 | #define BASIC_DOUBLE 14 |
| 110 | #define BASIC_CMPLX_INT 15 |
| 111 | #define BASIC_CMPLX_FLT 16 |
| 112 | #define BASIC_CMPLX_DBL 17 |
| 113 | #define BASIC_CMPLX_LONG_DBL 18 |
| 114 | #define BASIC_VOID 19 |
| 115 | |
| 116 | struct datatype * DEBUG_TypeInt = NULL; |
| 117 | struct datatype * DEBUG_TypeIntConst = NULL; |
| 118 | struct datatype * DEBUG_TypeUSInt = NULL; |
| 119 | struct datatype * DEBUG_TypeString = NULL; |
| 120 | |
| 121 | /* |
| 122 | * All of the types that have been defined so far. |
| 123 | */ |
| 124 | static struct datatype * type_hash_table[NR_TYPE_HASH + 1]; |
| 125 | static struct datatype * pointer_types = NULL; |
| 126 | |
| 127 | static unsigned int type_hash( const char * name ) |
| 128 | { |
| 129 | unsigned int hash = 0; |
| 130 | unsigned int tmp; |
| 131 | const char * p; |
| 132 | |
| 133 | p = name; |
| 134 | |
| 135 | while (*p) |
| 136 | { |
| 137 | hash = (hash << 4) + *p++; |
| 138 | |
| 139 | if( (tmp = (hash & 0xf0000000)) ) |
| 140 | { |
| 141 | hash ^= tmp >> 24; |
| 142 | } |
| 143 | hash &= ~tmp; |
| 144 | } |
| 145 | return hash % NR_TYPE_HASH; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | static struct datatype * |
| 150 | DEBUG_InitBasic(int type, char * name, int size, int b_signed, |
| 151 | char * output_format) |
| 152 | { |
| 153 | int hash; |
| 154 | |
| 155 | struct datatype * dt; |
| 156 | dt = (struct datatype *) xmalloc(sizeof(struct datatype)); |
| 157 | |
| 158 | if( dt != NULL ) |
| 159 | { |
| 160 | if( name != NULL ) |
| 161 | { |
| 162 | hash = type_hash(name); |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | hash = NR_TYPE_HASH; |
| 167 | } |
| 168 | |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 169 | dt->type = DT_BASIC; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 170 | dt->name = name; |
| 171 | dt->next = type_hash_table[hash]; |
| 172 | type_hash_table[hash] = dt; |
| 173 | dt->un.basic.basic_type = type; |
| 174 | dt->un.basic.basic_size = size; |
| 175 | dt->un.basic.b_signed = b_signed; |
| 176 | dt->un.basic.output_format = output_format; |
| 177 | } |
| 178 | |
| 179 | return dt; |
| 180 | } |
| 181 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 182 | static |
| 183 | struct datatype * |
| 184 | DEBUG_LookupDataType(enum debug_type xtype, int hash, const char * typename) |
| 185 | { |
| 186 | struct datatype * dt = NULL; |
| 187 | |
| 188 | if( typename != NULL ) |
| 189 | { |
| 190 | for( dt = type_hash_table[hash]; dt; dt = dt->next ) |
| 191 | { |
| 192 | if( xtype != dt->type || dt->name == NULL |
| 193 | || dt->name[0] != typename[0]) |
| 194 | { |
| 195 | continue; |
| 196 | } |
| 197 | |
| 198 | if( strcmp(dt->name, typename) == 0 ) |
| 199 | { |
| 200 | return dt; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return dt; |
| 206 | } |
| 207 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 208 | struct datatype * |
| 209 | DEBUG_NewDataType(enum debug_type xtype, const char * typename) |
| 210 | { |
| 211 | struct datatype * dt = NULL; |
| 212 | int hash; |
| 213 | |
| 214 | /* |
| 215 | * The last bucket is special, and is used to hold typeless names. |
| 216 | */ |
| 217 | if( typename == NULL ) |
| 218 | { |
| 219 | hash = NR_TYPE_HASH; |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | hash = type_hash(typename); |
| 224 | } |
| 225 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 226 | dt = DEBUG_LookupDataType(xtype, hash, typename); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 227 | |
| 228 | if( dt == NULL ) |
| 229 | { |
| 230 | dt = (struct datatype *) xmalloc(sizeof(struct datatype)); |
| 231 | |
| 232 | if( dt != NULL ) |
| 233 | { |
| 234 | memset(dt, 0, sizeof(*dt)); |
| 235 | |
| 236 | dt->type = xtype; |
| 237 | if( typename != NULL ) |
| 238 | { |
| 239 | dt->name = xstrdup(typename); |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | dt->name = NULL; |
| 244 | } |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 245 | if( xtype == DT_POINTER ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 246 | { |
| 247 | dt->next = pointer_types; |
| 248 | pointer_types = dt; |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | dt->next = type_hash_table[hash]; |
| 253 | type_hash_table[hash] = dt; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return dt; |
| 259 | } |
| 260 | |
| 261 | struct datatype * |
| 262 | DEBUG_FindOrMakePointerType(struct datatype * reftype) |
| 263 | { |
| 264 | struct datatype * dt = NULL; |
| 265 | |
| 266 | if( reftype != NULL ) |
| 267 | { |
| 268 | for( dt = pointer_types; dt; dt = dt->next ) |
| 269 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 270 | if( dt->type != DT_POINTER ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 271 | { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | if( dt->un.pointer.pointsto == reftype ) |
| 276 | { |
| 277 | return dt; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if( dt == NULL ) |
| 283 | { |
| 284 | dt = (struct datatype *) xmalloc(sizeof(struct datatype)); |
| 285 | |
| 286 | if( dt != NULL ) |
| 287 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 288 | dt->type = DT_POINTER; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 289 | dt->un.pointer.pointsto = reftype; |
| 290 | dt->next = pointer_types; |
| 291 | pointer_types = dt; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return dt; |
| 296 | } |
| 297 | |
| 298 | void |
| 299 | DEBUG_InitTypes() |
| 300 | { |
| 301 | static int beenhere = 0; |
| 302 | struct datatype * chartype; |
| 303 | |
| 304 | if( beenhere++ != 0 ) |
| 305 | { |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Special version of int used with constants of various kinds. |
| 311 | */ |
| 312 | DEBUG_TypeIntConst = DEBUG_InitBasic(BASIC_INT,NULL,4,1,"%d"); |
| 313 | |
| 314 | /* |
| 315 | * Initialize a few builtin types. |
| 316 | */ |
| 317 | |
| 318 | |
| 319 | DEBUG_TypeInt = DEBUG_InitBasic(BASIC_INT,"int",4,1,"%d"); |
| 320 | chartype = DEBUG_InitBasic(BASIC_CHAR,"char",1,1,"'%c'"); |
| 321 | DEBUG_InitBasic(BASIC_LONG,"long int",4,1,"%d"); |
| 322 | DEBUG_TypeUSInt = DEBUG_InitBasic(BASIC_UINT,"unsigned int",4,0,"%d"); |
| 323 | DEBUG_InitBasic(BASIC_LUI,"long unsigned int",4,0,"%d"); |
| 324 | DEBUG_InitBasic(BASIC_LONGLONG,"long long int",8,1,"%ld"); |
| 325 | DEBUG_InitBasic(BASIC_ULONGLONGI,"long long unsigned int",8,0,"%ld"); |
| 326 | DEBUG_InitBasic(BASIC_SHORT,"short int",2,1,"%d"); |
| 327 | DEBUG_InitBasic(BASIC_SHORTUI,"short unsigned int",2,0,"%d"); |
| 328 | DEBUG_InitBasic(BASIC_SCHAR,"signed char",1,1,"'%c'"); |
| 329 | DEBUG_InitBasic(BASIC_UCHAR,"unsigned char",1,0,"'%c'"); |
| 330 | DEBUG_InitBasic(BASIC_FLT,"float",4,0,"%f"); |
| 331 | DEBUG_InitBasic(BASIC_LONG_DOUBLE,"double",8,0,"%lf"); |
| 332 | DEBUG_InitBasic(BASIC_DOUBLE,"long double",12,0,NULL); |
| 333 | DEBUG_InitBasic(BASIC_CMPLX_INT,"complex int",8,1,NULL); |
| 334 | DEBUG_InitBasic(BASIC_CMPLX_FLT,"complex float",8,0,NULL); |
| 335 | DEBUG_InitBasic(BASIC_CMPLX_DBL,"complex double",16,0,NULL); |
| 336 | DEBUG_InitBasic(BASIC_CMPLX_LONG_DBL,"complex long double",24,0,NULL); |
| 337 | DEBUG_InitBasic(BASIC_VOID,"void",0,0,NULL); |
| 338 | |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 339 | DEBUG_TypeString = DEBUG_NewDataType(DT_POINTER, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 340 | DEBUG_SetPointerType(DEBUG_TypeString, chartype); |
| 341 | |
| 342 | /* |
| 343 | * Now initialize the builtins for codeview. |
| 344 | */ |
| 345 | DEBUG_InitCVDataTypes(); |
| 346 | |
| 347 | } |
| 348 | |
| 349 | long long int |
| 350 | DEBUG_GetExprValue(DBG_ADDR * addr, char ** format) |
| 351 | { |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 352 | DBG_ADDR address = *addr; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 353 | unsigned int rtn; |
| 354 | struct datatype * type2 = NULL; |
| 355 | struct en_values * e; |
| 356 | char * def_format = "0x%x"; |
| 357 | |
| 358 | rtn = 0; |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 359 | address.seg = 0; /* FIXME? I don't quite get this... */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 360 | assert(addr->type != NULL); |
| 361 | |
| 362 | switch(addr->type->type) |
| 363 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 364 | case DT_BASIC: |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 365 | if (!DBG_CHECK_READ_PTR( &address, addr->type->un.basic.basic_size)) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 366 | { |
| 367 | return 0; |
| 368 | } |
| 369 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 370 | memcpy(&rtn, (char *) addr->off, addr->type->un.basic.basic_size); |
| 371 | if( (addr->type->un.basic.b_signed) |
| 372 | && ((addr->type->un.basic.basic_size & 3) != 0) |
| 373 | && ((rtn >> (addr->type->un.basic.basic_size * 8 - 1)) != 0) ) |
| 374 | { |
| 375 | rtn = rtn | ((-1) << (addr->type->un.basic.basic_size * 8)); |
| 376 | } |
| 377 | if( addr->type->un.basic.output_format != NULL ) |
| 378 | { |
| 379 | def_format = addr->type->un.basic.output_format; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Check for single character prints that are out of range. |
| 384 | */ |
| 385 | if( addr->type->un.basic.basic_size == 1 |
| 386 | && strcmp(def_format, "'%c'") == 0 |
| 387 | && ((rtn < 0x20) || (rtn > 0x80)) ) |
| 388 | { |
| 389 | def_format = "%d"; |
| 390 | } |
| 391 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 392 | case DT_POINTER: |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 393 | if (!DBG_CHECK_READ_PTR( &address, 1 )) return 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 394 | rtn = (unsigned int) *((unsigned char **)addr->off); |
| 395 | type2 = addr->type->un.pointer.pointsto; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 396 | if( type2->type == DT_BASIC && type2->un.basic.basic_size == 1 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 397 | { |
| 398 | def_format = "\"%s\""; |
| 399 | break; |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | def_format = "0x%8.8x"; |
| 404 | } |
| 405 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 406 | case DT_ARRAY: |
| 407 | case DT_STRUCT: |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 408 | if (!DBG_CHECK_READ_PTR( &address, 1 )) return 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 409 | rtn = (unsigned int) *((unsigned char **)addr->off); |
| 410 | def_format = "0x%8.8x"; |
| 411 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 412 | case DT_ENUM: |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 413 | if (!DBG_CHECK_READ_PTR( &address, 1 )) return 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 414 | rtn = (unsigned int) *((unsigned char **)addr->off); |
| 415 | for(e = addr->type->un.enumeration.members; e; e = e->next ) |
| 416 | { |
| 417 | if( e->value == rtn ) |
| 418 | { |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | if( e != NULL ) |
| 423 | { |
| 424 | rtn = (int) e->name; |
| 425 | def_format = "%s"; |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | def_format = "%d"; |
| 430 | } |
| 431 | break; |
| 432 | default: |
| 433 | rtn = 0; |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | |
| 438 | if( format != NULL ) |
| 439 | { |
| 440 | *format = def_format; |
| 441 | } |
| 442 | return rtn; |
| 443 | } |
| 444 | |
| 445 | unsigned int |
| 446 | DEBUG_TypeDerefPointer(DBG_ADDR * addr, struct datatype ** newtype) |
| 447 | { |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 448 | DBG_ADDR address = *addr; |
| 449 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 450 | /* |
| 451 | * Make sure that this really makes sense. |
| 452 | */ |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 453 | if( addr->type->type != DT_POINTER ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 454 | { |
| 455 | *newtype = NULL; |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | *newtype = addr->type->un.pointer.pointsto; |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 460 | address.off = *(unsigned int*) (addr->off); |
| 461 | return (unsigned int)DBG_ADDR_TO_LIN(&address); /* FIXME: is this right (or "better") ? */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | unsigned int |
| 465 | DEBUG_FindStructElement(DBG_ADDR * addr, const char * ele_name, int * tmpbuf) |
| 466 | { |
| 467 | struct member * m; |
| 468 | unsigned int mask; |
| 469 | |
| 470 | /* |
| 471 | * Make sure that this really makes sense. |
| 472 | */ |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 473 | if( addr->type->type != DT_STRUCT ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 474 | { |
| 475 | addr->type = NULL; |
| 476 | return FALSE; |
| 477 | } |
| 478 | |
| 479 | for(m = addr->type->un.structure.members; m; m = m->next) |
| 480 | { |
| 481 | if( strcmp(m->name, ele_name) == 0 ) |
| 482 | { |
| 483 | addr->type = m->type; |
| 484 | if( (m->offset & 7) != 0 || (m->size & 7) != 0) |
| 485 | { |
| 486 | /* |
| 487 | * Bitfield operation. We have to extract the field and store |
| 488 | * it in a temporary buffer so that we get it all right. |
| 489 | */ |
| 490 | *tmpbuf = ((*(int* ) (addr->off + (m->offset >> 3))) >> (m->offset & 7)); |
| 491 | addr->off = (int) tmpbuf; |
| 492 | |
| 493 | mask = 0xffffffff << (m->size); |
| 494 | *tmpbuf &= ~mask; |
| 495 | /* |
| 496 | * OK, now we have the correct part of the number. |
| 497 | * Check to see whether the basic type is signed or not, and if so, |
| 498 | * we need to sign extend the number. |
| 499 | */ |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 500 | if( m->type->type == DT_BASIC && m->type->un.basic.b_signed != 0 |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 501 | && (*tmpbuf & (1 << (m->size - 1))) != 0 ) |
| 502 | { |
| 503 | *tmpbuf |= mask; |
| 504 | } |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | addr->off += (m->offset >> 3); |
| 509 | } |
| 510 | return TRUE; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | addr->type = NULL; |
| 515 | return FALSE; |
| 516 | } |
| 517 | |
| 518 | int |
| 519 | DEBUG_SetStructSize(struct datatype * dt, int size) |
| 520 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 521 | assert(dt->type == DT_STRUCT); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 522 | |
| 523 | if( dt->un.structure.members != NULL ) |
| 524 | { |
| 525 | return FALSE; |
| 526 | } |
| 527 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 528 | dt->un.structure.size = size; |
| 529 | dt->un.structure.members = NULL; |
| 530 | |
| 531 | return TRUE; |
| 532 | } |
| 533 | |
| 534 | int |
| 535 | DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2) |
| 536 | { |
| 537 | |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 538 | assert( dt->type == dt2->type && ((dt->type == DT_STRUCT) || (dt->type == DT_ENUM))); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 539 | |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 540 | if( dt->type == DT_STRUCT ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 541 | { |
| 542 | dt->un.structure.members = dt2->un.structure.members; |
| 543 | } |
| 544 | else |
| 545 | { |
| 546 | dt->un.enumeration.members = dt2->un.enumeration.members; |
| 547 | } |
| 548 | |
| 549 | return TRUE; |
| 550 | } |
| 551 | |
| 552 | int |
| 553 | DEBUG_AddStructElement(struct datatype * dt, char * name, struct datatype * type, |
| 554 | int offset, int size) |
| 555 | { |
| 556 | struct member * m; |
| 557 | struct member * last; |
| 558 | struct en_values * e; |
| 559 | |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 560 | if( dt->type == DT_STRUCT ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 561 | { |
| 562 | for(last = dt->un.structure.members; last; last = last->next) |
| 563 | { |
| 564 | if( (last->name[0] == name[0]) |
| 565 | && (strcmp(last->name, name) == 0) ) |
| 566 | { |
| 567 | return TRUE; |
| 568 | } |
| 569 | if( last->next == NULL ) |
| 570 | { |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | m = (struct member *) xmalloc(sizeof(struct member)); |
| 575 | if( m == FALSE ) |
| 576 | { |
| 577 | return FALSE; |
| 578 | } |
| 579 | |
| 580 | m->name = xstrdup(name); |
| 581 | m->type = type; |
| 582 | m->offset = offset; |
| 583 | m->size = size; |
| 584 | if( last == NULL ) |
| 585 | { |
| 586 | m->next = dt->un.structure.members; |
| 587 | dt->un.structure.members = m; |
| 588 | } |
| 589 | else |
| 590 | { |
| 591 | last->next = m; |
| 592 | m->next = NULL; |
| 593 | } |
| 594 | /* |
| 595 | * If the base type is bitfield, then adjust the offsets here so that we |
| 596 | * are able to look things up without lots of falter-all. |
| 597 | */ |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 598 | if( type->type == DT_BITFIELD ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 599 | { |
| 600 | m->offset += m->type->un.bitfield.bitoff; |
| 601 | m->size = m->type->un.bitfield.nbits; |
| 602 | m->type = m->type->un.bitfield.basetype; |
| 603 | } |
| 604 | } |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 605 | else if( dt->type == DT_ENUM ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 606 | { |
| 607 | e = (struct en_values *) xmalloc(sizeof(struct en_values)); |
| 608 | if( e == FALSE ) |
| 609 | { |
| 610 | return FALSE; |
| 611 | } |
| 612 | |
| 613 | e->name = xstrdup(name); |
| 614 | e->value = offset; |
| 615 | e->next = dt->un.enumeration.members; |
| 616 | dt->un.enumeration.members = e; |
| 617 | } |
| 618 | else |
| 619 | { |
| 620 | assert(FALSE); |
| 621 | } |
| 622 | return TRUE; |
| 623 | } |
| 624 | |
| 625 | struct datatype * |
| 626 | DEBUG_GetPointerType(struct datatype * dt) |
| 627 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 628 | if( dt->type == DT_POINTER ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 629 | { |
| 630 | return dt->un.pointer.pointsto; |
| 631 | } |
| 632 | |
| 633 | return NULL; |
| 634 | } |
| 635 | |
| 636 | int |
| 637 | DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2) |
| 638 | { |
| 639 | switch(dt->type) |
| 640 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 641 | case DT_POINTER: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 642 | dt->un.pointer.pointsto = dt2; |
| 643 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 644 | case DT_FUNC: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 645 | dt->un.funct.rettype = dt2; |
| 646 | break; |
| 647 | default: |
| 648 | assert(FALSE); |
| 649 | } |
| 650 | |
| 651 | return TRUE; |
| 652 | } |
| 653 | |
| 654 | int |
| 655 | DEBUG_SetArrayParams(struct datatype * dt, int min, int max, struct datatype * dt2) |
| 656 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 657 | assert(dt->type == DT_ARRAY); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 658 | dt->un.array.start = min; |
| 659 | dt->un.array.end = max; |
| 660 | dt->un.array.basictype = dt2; |
| 661 | |
| 662 | return TRUE; |
| 663 | } |
| 664 | |
| 665 | int |
| 666 | DEBUG_SetBitfieldParams(struct datatype * dt, int offset, int nbits, |
| 667 | struct datatype * dt2) |
| 668 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 669 | assert(dt->type == DT_BITFIELD); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 670 | dt->un.bitfield.bitoff = offset; |
| 671 | dt->un.bitfield.nbits = nbits; |
| 672 | dt->un.bitfield.basetype = dt2; |
| 673 | |
| 674 | return TRUE; |
| 675 | } |
| 676 | |
| 677 | int DEBUG_GetObjectSize(struct datatype * dt) |
| 678 | { |
| 679 | if( dt == NULL ) |
| 680 | { |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | switch(dt->type) |
| 685 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 686 | case DT_BASIC: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 687 | return dt->un.basic.basic_size; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 688 | case DT_POINTER: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 689 | return sizeof(int *); |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 690 | case DT_STRUCT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 691 | return dt->un.structure.size; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 692 | case DT_ENUM: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 693 | return sizeof(int); |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 694 | case DT_ARRAY: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 695 | return (dt->un.array.end - dt->un.array.start) |
| 696 | * DEBUG_GetObjectSize(dt->un.array.basictype); |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 697 | case DT_BITFIELD: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 698 | /* |
| 699 | * Bitfields have to be handled seperately later on |
| 700 | * when we insert the element into the structure. |
| 701 | */ |
| 702 | return 0; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 703 | case DT_TYPEDEF: |
| 704 | case DT_FUNC: |
| 705 | case DT_CONST: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 706 | assert(FALSE); |
| 707 | } |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | unsigned int |
| 712 | DEBUG_ArrayIndex(DBG_ADDR * addr, DBG_ADDR * result, int index) |
| 713 | { |
| 714 | int size; |
| 715 | |
| 716 | /* |
| 717 | * Make sure that this really makes sense. |
| 718 | */ |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 719 | if( addr->type->type == DT_POINTER ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 720 | { |
| 721 | /* |
| 722 | * Get the base type, so we know how much to index by. |
| 723 | */ |
| 724 | size = DEBUG_GetObjectSize(addr->type->un.pointer.pointsto); |
| 725 | result->type = addr->type->un.pointer.pointsto; |
| 726 | result->off = (*(unsigned int*) (addr->off)) + size * index; |
| 727 | } |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 728 | else if (addr->type->type == DT_ARRAY) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 729 | { |
| 730 | size = DEBUG_GetObjectSize(addr->type->un.array.basictype); |
| 731 | result->type = addr->type->un.array.basictype; |
| 732 | result->off = addr->off + size * (index - addr->type->un.array.start); |
| 733 | } |
| 734 | |
| 735 | return TRUE; |
| 736 | } |
| 737 | |
| 738 | /*********************************************************************** |
| 739 | * DEBUG_Print |
| 740 | * |
| 741 | * Implementation of the 'print' command. |
| 742 | */ |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 743 | void |
| 744 | DEBUG_Print( const DBG_ADDR *addr, int count, char format, int level ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 745 | { |
| 746 | DBG_ADDR addr1; |
| 747 | int i; |
| 748 | struct member * m; |
| 749 | char * pnt; |
| 750 | int size; |
| 751 | long long int value; |
| 752 | |
| 753 | if (count != 1) |
| 754 | { |
| 755 | fprintf( stderr, "Count other than 1 is meaningless in 'print' command\n" ); |
| 756 | return; |
| 757 | } |
| 758 | |
| 759 | if( addr->type == NULL ) |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 760 | { |
| 761 | /* No type, just print the addr value */ |
| 762 | if (addr->seg && (addr->seg != 0xffffffff)) |
| 763 | DEBUG_nchar += fprintf( stderr, "0x%04lx: ", addr->seg ); |
| 764 | DEBUG_nchar += fprintf( stderr, "0x%08lx", addr->off ); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 765 | goto leave; |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 766 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 767 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 768 | if( level == 0 ) |
| 769 | { |
| 770 | DEBUG_nchar = 0; |
| 771 | } |
| 772 | |
| 773 | if( DEBUG_nchar > DEBUG_maxchar ) |
| 774 | { |
| 775 | fprintf(stderr, "..."); |
| 776 | goto leave; |
| 777 | } |
| 778 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 779 | if( format == 'i' || format == 's' || format == 'w' || format == 'b' ) |
| 780 | { |
| 781 | fprintf( stderr, "Format specifier '%c' is meaningless in 'print' command\n", format ); |
| 782 | format = '\0'; |
| 783 | } |
| 784 | |
| 785 | switch(addr->type->type) |
| 786 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 787 | case DT_BASIC: |
| 788 | case DT_ENUM: |
| 789 | case DT_CONST: |
| 790 | case DT_POINTER: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 791 | DEBUG_PrintBasic(addr, 1, format); |
| 792 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 793 | case DT_STRUCT: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 794 | DEBUG_nchar += fprintf(stderr, "{"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 795 | for(m = addr->type->un.structure.members; m; m = m->next) |
| 796 | { |
| 797 | addr1 = *addr; |
| 798 | DEBUG_FindStructElement(&addr1, m->name, |
| 799 | (int *) &value); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 800 | DEBUG_nchar += fprintf(stderr, "%s=", m->name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 801 | DEBUG_Print(&addr1, 1, format, level + 1); |
| 802 | if( m->next != NULL ) |
| 803 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 804 | DEBUG_nchar += fprintf(stderr, ", "); |
| 805 | } |
| 806 | if( DEBUG_nchar > DEBUG_maxchar ) |
| 807 | { |
| 808 | fprintf(stderr, "...}"); |
| 809 | goto leave; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 812 | DEBUG_nchar += fprintf(stderr, "}"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 813 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 814 | case DT_ARRAY: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 815 | /* |
| 816 | * Loop over all of the entries, printing stuff as we go. |
| 817 | */ |
| 818 | size = DEBUG_GetObjectSize(addr->type->un.array.basictype); |
| 819 | if( size == 1 ) |
| 820 | { |
| 821 | /* |
| 822 | * Special handling for character arrays. |
| 823 | */ |
| 824 | pnt = (char *) addr->off; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 825 | DEBUG_nchar += fprintf(stderr, "\""); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 826 | for( i=addr->type->un.array.start; i < addr->type->un.array.end; i++ ) |
| 827 | { |
| 828 | fputc(*pnt++, stderr); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 829 | DEBUG_nchar++; |
| 830 | if( DEBUG_nchar > DEBUG_maxchar ) |
| 831 | { |
| 832 | fprintf(stderr, "...\""); |
| 833 | goto leave; |
| 834 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 835 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 836 | DEBUG_nchar += fprintf(stderr, "\""); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 837 | break; |
| 838 | } |
| 839 | addr1 = *addr; |
| 840 | addr1.type = addr->type->un.array.basictype; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 841 | DEBUG_nchar += fprintf(stderr, "{"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 842 | for( i=addr->type->un.array.start; i <= addr->type->un.array.end; i++ ) |
| 843 | { |
| 844 | DEBUG_Print(&addr1, 1, format, level + 1); |
| 845 | addr1.off += size; |
| 846 | if( i == addr->type->un.array.end ) |
| 847 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 848 | DEBUG_nchar += fprintf(stderr, "}"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 849 | } |
| 850 | else |
| 851 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 852 | DEBUG_nchar += fprintf(stderr, ", "); |
| 853 | } |
| 854 | if( DEBUG_nchar > DEBUG_maxchar ) |
| 855 | { |
| 856 | fprintf(stderr, "...}"); |
| 857 | goto leave; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | break; |
| 861 | default: |
| 862 | assert(FALSE); |
| 863 | break; |
| 864 | } |
| 865 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 866 | leave: |
| 867 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 868 | if( level == 0 ) |
| 869 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 870 | DEBUG_nchar += fprintf(stderr, "\n"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 871 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 872 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 873 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 874 | |
| 875 | int |
| 876 | DEBUG_DumpTypes() |
| 877 | { |
| 878 | struct datatype * dt = NULL; |
| 879 | struct member * m; |
| 880 | int hash; |
| 881 | int nm; |
| 882 | char * name; |
| 883 | char * member_name; |
| 884 | |
| 885 | for(hash = 0; hash < NR_TYPE_HASH + 1; hash++) |
| 886 | { |
| 887 | for( dt = type_hash_table[hash]; dt; dt = dt->next ) |
| 888 | { |
| 889 | name = "none"; |
| 890 | if( dt->name != NULL ) |
| 891 | { |
| 892 | name = dt->name; |
| 893 | } |
| 894 | switch(dt->type) |
| 895 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 896 | case DT_BASIC: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 897 | fprintf(stderr, "0x%p - BASIC(%s)\n", |
| 898 | dt, name); |
| 899 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 900 | case DT_POINTER: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 901 | fprintf(stderr, "0x%p - POINTER(%s)(%p)\n", |
| 902 | dt, name, dt->un.pointer.pointsto); |
| 903 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 904 | case DT_STRUCT: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 905 | member_name = "none"; |
| 906 | nm = 0; |
| 907 | if( dt->un.structure.members != NULL |
| 908 | && dt->un.structure.members->name != NULL ) |
| 909 | { |
| 910 | member_name = dt->un.structure.members->name; |
| 911 | for( m = dt->un.structure.members; m; m = m->next) |
| 912 | { |
| 913 | nm++; |
| 914 | } |
| 915 | } |
| 916 | fprintf(stderr, "0x%p - STRUCT(%s) %d %d %s\n", dt, name, |
| 917 | dt->un.structure.size, nm, member_name); |
| 918 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 919 | case DT_ARRAY: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 920 | fprintf(stderr, "0x%p - ARRAY(%s)(%p)\n", |
| 921 | dt, name, dt->un.array.basictype); |
| 922 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 923 | case DT_ENUM: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 924 | fprintf(stderr, "0x%p - ENUM(%s)\n", |
| 925 | dt, name); |
| 926 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 927 | case DT_BITFIELD: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 928 | fprintf(stderr, "0x%p - BITFIELD(%s)\n", dt, name); |
| 929 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 930 | case DT_FUNC: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 931 | fprintf(stderr, "0x%p - FUNC(%s)(%p)\n", |
| 932 | dt, name, dt->un.funct.rettype); |
| 933 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 934 | case DT_CONST: |
| 935 | case DT_TYPEDEF: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 936 | fprintf(stderr, "What???\n"); |
| 937 | break; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | return TRUE; |
| 942 | } |
| 943 | |
| 944 | |
| 945 | enum debug_type DEBUG_GetType(struct datatype * dt) |
| 946 | { |
| 947 | return dt->type; |
| 948 | } |
| 949 | |
| 950 | struct datatype * |
| 951 | DEBUG_TypeCast(enum debug_type type, const char * name) |
| 952 | { |
| 953 | int hash; |
| 954 | struct datatype * rtn; |
| 955 | |
| 956 | /* |
| 957 | * The last bucket is special, and is used to hold typeless names. |
| 958 | */ |
| 959 | if( name == NULL ) |
| 960 | { |
| 961 | hash = NR_TYPE_HASH; |
| 962 | } |
| 963 | else |
| 964 | { |
| 965 | hash = type_hash(name); |
| 966 | } |
| 967 | |
| 968 | rtn = DEBUG_LookupDataType(type, hash, name); |
| 969 | |
| 970 | return rtn; |
| 971 | |
| 972 | } |
| 973 | |
| 974 | int |
| 975 | DEBUG_PrintTypeCast(struct datatype * dt) |
| 976 | { |
| 977 | char * name; |
| 978 | |
| 979 | name = "none"; |
| 980 | if( dt->name != NULL ) |
| 981 | { |
| 982 | name = dt->name; |
| 983 | } |
| 984 | |
| 985 | switch(dt->type) |
| 986 | { |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 987 | case DT_BASIC: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 988 | fprintf(stderr, "%s", name); |
| 989 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 990 | case DT_POINTER: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 991 | DEBUG_PrintTypeCast(dt->un.pointer.pointsto); |
| 992 | fprintf(stderr, "*"); |
| 993 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 994 | case DT_STRUCT: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 995 | fprintf(stderr, "struct %s", name); |
| 996 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 997 | case DT_ARRAY: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 998 | fprintf(stderr, "%s[]", name); |
| 999 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 1000 | case DT_ENUM: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1001 | fprintf(stderr, "enum %s", name); |
| 1002 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 1003 | case DT_BITFIELD: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1004 | fprintf(stderr, "unsigned %s", name); |
| 1005 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 1006 | case DT_FUNC: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1007 | DEBUG_PrintTypeCast(dt->un.funct.rettype); |
| 1008 | fprintf(stderr, "(*%s)()", name); |
| 1009 | break; |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 1010 | case DT_CONST: |
| 1011 | case DT_TYPEDEF: |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1012 | fprintf(stderr, "What???\n"); |
| 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | return TRUE; |
| 1017 | } |
| 1018 | |
| 1019 | |