msxml3: Use standard dlopen() instead of the libwine wrappers.
[wine/zf.git] / programs / winedbg / types.c
blob019554ad1becc201aad38aaaa9c2b3dbaac754f0
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 "debugger.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
32 /******************************************************************
33 * types_get_real_type
35 * Get rid of any potential typedef in the lvalue's type to get
36 * to the 'real' type (the one we can work upon).
38 BOOL types_get_real_type(struct dbg_type* type, DWORD* tag)
40 if (type->id == dbg_itype_none) return FALSE;
43 if (!types_get_info(type, TI_GET_SYMTAG, tag))
44 return FALSE;
45 if (*tag != SymTagTypedef) return TRUE;
46 } while (types_get_info(type, TI_GET_TYPE, &type->id));
47 return FALSE;
50 /******************************************************************
51 * types_extract_as_longlong
53 * Given a lvalue, try to get an integral (or pointer/address) value
54 * out of it
56 LONGLONG types_extract_as_longlong(const struct dbg_lvalue* lvalue,
57 unsigned* psize, BOOL *issigned)
59 LONGLONG rtn = 0;
60 DWORD tag, bt;
61 DWORD64 size;
62 struct dbg_type type = lvalue->type;
63 BOOL s = FALSE;
65 if (!types_get_real_type(&type, &tag))
66 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
68 if (type.id == dbg_itype_segptr)
70 return (LONG_PTR)memory_to_linear_addr(&lvalue->addr);
73 if (psize) *psize = 0;
74 if (issigned) *issigned = FALSE;
75 switch (tag)
77 case SymTagBaseType:
78 if (!types_get_info(&type, TI_GET_LENGTH, &size) ||
79 !types_get_info(&type, TI_GET_BASETYPE, &bt))
81 WINE_ERR("Couldn't get information\n");
82 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
83 return rtn;
85 if (size > sizeof(rtn))
87 WINE_ERR("Size too large (%s)\n", wine_dbgstr_longlong(size));
88 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
89 return rtn;
91 switch (bt)
93 case btChar:
94 case btInt:
95 if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn))
96 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
97 break;
98 case btUInt:
99 if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
100 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
101 break;
102 case btFloat:
103 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
105 if (psize) *psize = (unsigned)size;
106 if (issigned) *issigned = s;
107 break;
108 case SymTagPointerType:
109 if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(void*), s = FALSE, &rtn))
110 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
111 break;
112 case SymTagArrayType:
113 case SymTagUDT:
114 if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
115 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
116 break;
117 case SymTagEnum:
118 /* FIXME: we don't handle enum size */
119 if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
120 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
121 break;
122 case SymTagFunctionType:
123 rtn = (ULONG_PTR)memory_to_linear_addr(&lvalue->addr);
124 break;
125 default:
126 WINE_FIXME("Unsupported tag %u\n", tag);
127 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
130 return rtn;
133 /******************************************************************
134 * types_extract_as_integer
136 * Given a lvalue, try to get an integral (or pointer/address) value
137 * out of it
139 long int types_extract_as_integer(const struct dbg_lvalue* lvalue)
141 return types_extract_as_longlong(lvalue, NULL, NULL);
144 /******************************************************************
145 * types_extract_as_address
149 void types_extract_as_address(const struct dbg_lvalue* lvalue, ADDRESS64* addr)
151 if (lvalue->type.id == dbg_itype_segptr && lvalue->type.module == 0)
153 *addr = lvalue->addr;
155 else
157 addr->Mode = AddrModeFlat;
158 addr->Offset = types_extract_as_longlong(lvalue, NULL, NULL);
162 BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lvalue_from)
164 LONGLONG val;
165 DWORD64 size;
166 BOOL is_signed;
168 if (!types_get_info(&lvalue_to->type, TI_GET_LENGTH, &size)) return FALSE;
169 if (sizeof(val) < size)
171 dbg_printf("Insufficient size\n");
172 return FALSE;
174 /* FIXME: should support floats as well */
175 val = types_extract_as_longlong(lvalue_from, NULL, &is_signed);
176 return dbg_curr_process->be_cpu->store_integer(lvalue_to, size, is_signed, val);
179 /******************************************************************
180 * types_get_udt_element_lvalue
182 * Implement a structure derefencement
184 static BOOL types_get_udt_element_lvalue(struct dbg_lvalue* lvalue,
185 const struct dbg_type* type, long int* tmpbuf)
187 DWORD offset, bitoffset;
188 DWORD bt;
189 DWORD64 length;
191 unsigned mask;
193 types_get_info(type, TI_GET_TYPE, &lvalue->type.id);
194 lvalue->type.module = type->module;
195 if (!types_get_info(type, TI_GET_OFFSET, &offset)) return FALSE;
196 lvalue->addr.Offset += offset;
198 if (types_get_info(type, TI_GET_BITPOSITION, &bitoffset))
200 types_get_info(type, TI_GET_LENGTH, &length);
201 /* FIXME: this test isn't sufficient, depending on start of bitfield
202 * (ie a 32 bit field can spread across 5 bytes)
204 if (length > 8 * sizeof(*tmpbuf)) return FALSE;
205 lvalue->addr.Offset += bitoffset >> 3;
207 * Bitfield operation. We have to extract the field and store
208 * it in a temporary buffer so that we get it all right.
210 if (!memory_read_value(lvalue, sizeof(*tmpbuf), tmpbuf)) return FALSE;
211 mask = 0xffffffff << (DWORD)length;
212 *tmpbuf >>= bitoffset & 7;
213 *tmpbuf &= ~mask;
215 lvalue->cookie = DLV_HOST;
216 lvalue->addr.Offset = (ULONG_PTR)tmpbuf;
219 * OK, now we have the correct part of the number.
220 * Check to see whether the basic type is signed or not, and if so,
221 * we need to sign extend the number.
223 if (types_get_info(&lvalue->type, TI_GET_BASETYPE, &bt) &&
224 bt == btInt && (*tmpbuf & (1 << ((DWORD)length - 1))))
226 *tmpbuf |= mask;
229 else
231 if (!memory_read_value(lvalue, sizeof(*tmpbuf), tmpbuf)) return FALSE;
233 return TRUE;
236 /******************************************************************
237 * types_udt_find_element
240 BOOL types_udt_find_element(struct dbg_lvalue* lvalue, const char* name, long int* tmpbuf)
242 DWORD tag, count;
243 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
244 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
245 WCHAR* ptr;
246 char tmp[256];
247 struct dbg_type type;
249 if (!types_get_real_type(&lvalue->type, &tag) || tag != SymTagUDT)
250 return FALSE;
252 if (types_get_info(&lvalue->type, TI_GET_CHILDRENCOUNT, &count))
254 fcp->Start = 0;
255 while (count)
257 fcp->Count = min(count, 256);
258 if (types_get_info(&lvalue->type, TI_FINDCHILDREN, fcp))
260 unsigned i;
261 type.module = lvalue->type.module;
262 for (i = 0; i < min(fcp->Count, count); i++)
264 ptr = NULL;
265 type.id = fcp->ChildId[i];
266 types_get_info(&type, TI_GET_SYMNAME, &ptr);
267 if (!ptr) continue;
268 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
269 HeapFree(GetProcessHeap(), 0, ptr);
270 if (strcmp(tmp, name)) continue;
272 return types_get_udt_element_lvalue(lvalue, &type, tmpbuf);
275 count -= min(count, 256);
276 fcp->Start += 256;
279 return FALSE;
282 /******************************************************************
283 * types_array_index
285 * Grab an element from an array
287 BOOL types_array_index(const struct dbg_lvalue* lvalue, int index, struct dbg_lvalue* result)
289 struct dbg_type type = lvalue->type;
290 DWORD tag, count;
292 memset(result, 0, sizeof(*result));
293 result->type.id = dbg_itype_none;
294 result->type.module = 0;
296 if (!types_get_real_type(&type, &tag)) return FALSE;
297 switch (tag)
299 case SymTagArrayType:
300 if (!types_get_info(&type, TI_GET_COUNT, &count)) return FALSE;
301 if (index < 0 || index >= count) return FALSE;
302 result->addr = lvalue->addr;
303 break;
304 case SymTagPointerType:
305 if (!memory_read_value(lvalue, dbg_curr_process->be_cpu->pointer_size, &result->addr.Offset))
306 return FALSE;
307 result->addr.Mode = AddrModeFlat;
308 switch (dbg_curr_process->be_cpu->pointer_size)
310 case 4: result->addr.Offset = (DWORD)result->addr.Offset; break;
311 case 8: break;
312 default: assert(0);
314 break;
315 default:
316 assert(FALSE);
319 * Get the base type, so we know how much to index by.
321 if (!types_get_info(&type, TI_GET_TYPE, &result->type.id)) return FALSE;
322 result->type.module = type.module;
323 if (index)
325 DWORD64 length;
326 if (!types_get_info(&result->type, TI_GET_LENGTH, &length)) return FALSE;
327 result->addr.Offset += index * (DWORD)length;
329 /* FIXME: the following statement is not always true (and can lead to buggy behavior).
330 * There is no way to tell where the deref:ed value is...
331 * For example:
332 * x is a pointer to struct s, x being on the stack
333 * => lvalue is in debuggee, result is in debugger
334 * x is a pointer to struct s, x being optimized into a reg
335 * => lvalue is debugger, result is debuggee
336 * x is a pointer to internal variable x
337 * => lvalue is debugger, result is debuggee
338 * So we always force debuggee address space, because dereferencing pointers to
339 * internal variables is very unlikely. A correct fix would be
340 * rather large.
342 result->cookie = DLV_TARGET;
343 return TRUE;
346 struct type_find_t
348 unsigned long result; /* out: the found type */
349 enum SymTagEnum tag; /* in: the tag to look for */
350 union
352 unsigned long typeid; /* when tag is SymTagUDT */
353 const char* name; /* when tag is SymTagPointerType */
354 } u;
357 static BOOL CALLBACK types_cb(PSYMBOL_INFO sym, ULONG size, void* _user)
359 struct type_find_t* user = _user;
360 BOOL ret = TRUE;
361 struct dbg_type type;
362 DWORD type_id;
364 if (sym->Tag == user->tag)
366 switch (user->tag)
368 case SymTagUDT:
369 if (!strcmp(user->u.name, sym->Name))
371 user->result = sym->TypeIndex;
372 ret = FALSE;
374 break;
375 case SymTagPointerType:
376 type.module = sym->ModBase;
377 type.id = sym->TypeIndex;
378 if (types_get_info(&type, TI_GET_TYPE, &type_id) && type_id == user->u.typeid)
380 user->result = sym->TypeIndex;
381 ret = FALSE;
383 break;
384 default: break;
387 return ret;
390 /******************************************************************
391 * types_find_pointer
393 * Should look up in module based at linear whether (typeid*) exists
394 * Otherwise, we could create it locally
396 struct dbg_type types_find_pointer(const struct dbg_type* type)
398 struct type_find_t f;
399 struct dbg_type ret;
401 f.result = dbg_itype_none;
402 f.tag = SymTagPointerType;
403 f.u.typeid = type->id;
404 SymEnumTypes(dbg_curr_process->handle, type->module, types_cb, &f);
405 ret.module = type->module;
406 ret.id = f.result;
407 return ret;
410 /******************************************************************
411 * types_find_type
413 * Should look up in the module based at linear address whether a type
414 * named 'name' and with the correct tag exists
416 struct dbg_type types_find_type(unsigned long linear, const char* name, enum SymTagEnum tag)
419 struct type_find_t f;
420 struct dbg_type ret;
422 f.result = dbg_itype_none;
423 f.tag = tag;
424 f.u.name = name;
425 SymEnumTypes(dbg_curr_process->handle, linear, types_cb, &f);
426 ret.module = linear;
427 ret.id = f.result;
428 return ret;
431 /***********************************************************************
432 * print_value
434 * Implementation of the 'print' command.
436 void print_value(const struct dbg_lvalue* lvalue, char format, int level)
438 struct dbg_type type = lvalue->type;
439 struct dbg_lvalue lvalue_field;
440 int i;
441 DWORD tag;
442 DWORD count;
443 DWORD64 size;
445 if (!types_get_real_type(&type, &tag))
447 WINE_FIXME("---error\n");
448 return;
451 if (type.id == dbg_itype_none)
453 /* No type, just print the addr value */
454 print_bare_address(&lvalue->addr);
455 goto leave;
458 if (format == 'i' || format == 's' || format == 'w' || format == 'b' || format == 'g')
460 dbg_printf("Format specifier '%c' is meaningless in 'print' command\n", format);
461 format = '\0';
464 switch (tag)
466 case SymTagBaseType:
467 case SymTagEnum:
468 case SymTagPointerType:
469 /* FIXME: this in not 100% optimal (as we're going through the typedef handling
470 * stuff again
472 print_basic(lvalue, format);
473 break;
474 case SymTagUDT:
475 if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count))
477 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
478 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
479 WCHAR* ptr;
480 char tmp[256];
481 long int tmpbuf;
482 struct dbg_type sub_type;
484 dbg_printf("{");
485 fcp->Start = 0;
486 while (count)
488 fcp->Count = min(count, 256);
489 if (types_get_info(&type, TI_FINDCHILDREN, fcp))
491 for (i = 0; i < min(fcp->Count, count); i++)
493 ptr = NULL;
494 sub_type.module = type.module;
495 sub_type.id = fcp->ChildId[i];
496 types_get_info(&sub_type, TI_GET_SYMNAME, &ptr);
497 if (!ptr) continue;
498 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
499 dbg_printf("%s=", tmp);
500 HeapFree(GetProcessHeap(), 0, ptr);
501 lvalue_field = *lvalue;
502 if (types_get_udt_element_lvalue(&lvalue_field, &sub_type, &tmpbuf))
504 print_value(&lvalue_field, format, level + 1);
506 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
509 count -= min(count, 256);
510 fcp->Start += 256;
512 dbg_printf("}");
514 break;
515 case SymTagArrayType:
517 * Loop over all of the entries, printing stuff as we go.
519 count = 1; size = 1;
520 types_get_info(&type, TI_GET_COUNT, &count);
521 types_get_info(&type, TI_GET_LENGTH, &size);
523 if (size == count)
525 unsigned len;
526 char buffer[256];
528 * Special handling for character arrays.
530 /* FIXME should check basic type here (should be a char!!!!)... */
531 len = min(count, sizeof(buffer));
532 memory_get_string(dbg_curr_process,
533 memory_to_linear_addr(&lvalue->addr),
534 lvalue->cookie == DLV_TARGET, TRUE, buffer, len);
535 dbg_printf("\"%s%s\"", buffer, (len < count) ? "..." : "");
536 break;
538 lvalue_field = *lvalue;
539 types_get_info(&type, TI_GET_TYPE, &lvalue_field.type.id);
540 dbg_printf("{");
541 for (i = 0; i < count; i++)
543 print_value(&lvalue_field, format, level + 1);
544 lvalue_field.addr.Offset += size / count;
545 dbg_printf((i == count - 1) ? "}" : ", ");
547 break;
548 case SymTagFunctionType:
549 dbg_printf("Function ");
550 print_bare_address(&lvalue->addr);
551 dbg_printf(": ");
552 types_print_type(&type, FALSE);
553 break;
554 case SymTagTypedef:
555 lvalue_field = *lvalue;
556 types_get_info(&lvalue->type, TI_GET_TYPE, &lvalue_field.type.id);
557 print_value(&lvalue_field, format, level);
558 break;
559 default:
560 WINE_FIXME("Unknown tag (%u)\n", tag);
561 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
562 break;
565 leave:
567 if (level == 0) dbg_printf("\n");
570 static BOOL CALLBACK print_types_cb(PSYMBOL_INFO sym, ULONG size, void* ctx)
572 struct dbg_type type;
573 type.module = sym->ModBase;
574 type.id = sym->TypeIndex;
575 dbg_printf("Mod: %08lx ID: %08lx\n", type.module, type.id);
576 types_print_type(&type, TRUE);
577 dbg_printf("\n");
578 return TRUE;
581 static BOOL CALLBACK print_types_mod_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
583 return SymEnumTypes(dbg_curr_process->handle, base, print_types_cb, ctx);
586 BOOL print_types(void)
588 if (!dbg_curr_process)
590 dbg_printf("No known process, cannot print types\n");
591 return FALSE;
593 SymEnumerateModules64(dbg_curr_process->handle, print_types_mod_cb, NULL);
594 return FALSE;
597 BOOL types_print_type(const struct dbg_type* type, BOOL details)
599 WCHAR* ptr;
600 char tmp[256];
601 const char* name;
602 DWORD tag, udt, count;
603 struct dbg_type subtype;
605 if (type->id == dbg_itype_none || !types_get_info(type, TI_GET_SYMTAG, &tag))
607 dbg_printf("--invalid--<%lxh>--", type->id);
608 return FALSE;
611 if (types_get_info(type, TI_GET_SYMNAME, &ptr) && ptr)
613 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
614 name = tmp;
615 HeapFree(GetProcessHeap(), 0, ptr);
617 else name = "--none--";
619 switch (tag)
621 case SymTagBaseType:
622 if (details) dbg_printf("Basic<%s>", name); else dbg_printf("%s", name);
623 break;
624 case SymTagPointerType:
625 types_get_info(type, TI_GET_TYPE, &subtype.id);
626 subtype.module = type->module;
627 types_print_type(&subtype, FALSE);
628 dbg_printf("*");
629 break;
630 case SymTagUDT:
631 types_get_info(type, TI_GET_UDTKIND, &udt);
632 switch (udt)
634 case UdtStruct: dbg_printf("struct %s", name); break;
635 case UdtUnion: dbg_printf("union %s", name); break;
636 case UdtClass: dbg_printf("class %s", name); break;
637 default: WINE_ERR("Unsupported UDT type (%d) for %s\n", udt, name); break;
639 if (details &&
640 types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
642 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
643 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
644 WCHAR* ptr;
645 char tmp[256];
646 int i;
647 struct dbg_type type_elt;
648 dbg_printf(" {");
650 fcp->Start = 0;
651 while (count)
653 fcp->Count = min(count, 256);
654 if (types_get_info(type, TI_FINDCHILDREN, fcp))
656 for (i = 0; i < min(fcp->Count, count); i++)
658 ptr = NULL;
659 type_elt.module = type->module;
660 type_elt.id = fcp->ChildId[i];
661 types_get_info(&type_elt, TI_GET_SYMNAME, &ptr);
662 if (!ptr) continue;
663 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
664 HeapFree(GetProcessHeap(), 0, ptr);
665 dbg_printf("%s", tmp);
666 if (types_get_info(&type_elt, TI_GET_TYPE, &type_elt.id))
668 dbg_printf(":");
669 types_print_type(&type_elt, details);
671 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
674 count -= min(count, 256);
675 fcp->Start += 256;
677 dbg_printf("}");
679 break;
680 case SymTagArrayType:
681 types_get_info(type, TI_GET_TYPE, &subtype.id);
682 subtype.module = type->module;
683 types_print_type(&subtype, details);
684 if (types_get_info(type, TI_GET_COUNT, &count))
685 dbg_printf(" %s[%d]", name, count);
686 else
687 dbg_printf(" %s[]", name);
688 break;
689 case SymTagEnum:
690 dbg_printf("enum %s", name);
691 break;
692 case SymTagFunctionType:
693 types_get_info(type, TI_GET_TYPE, &subtype.id);
694 /* is the returned type the same object as function sig itself ? */
695 if (subtype.id != type->id)
697 subtype.module = type->module;
698 types_print_type(&subtype, FALSE);
700 else
702 subtype.module = 0;
703 dbg_printf("<ret_type=self>");
705 dbg_printf(" (*%s)(", name);
706 if (types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
708 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
709 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
710 int i;
712 fcp->Start = 0;
713 if (!count) dbg_printf("void");
714 else while (count)
716 fcp->Count = min(count, 256);
717 if (types_get_info(type, TI_FINDCHILDREN, fcp))
719 for (i = 0; i < min(fcp->Count, count); i++)
721 subtype.id = fcp->ChildId[i];
722 types_get_info(&subtype, TI_GET_TYPE, &subtype.id);
723 types_print_type(&subtype, FALSE);
724 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
727 count -= min(count, 256);
728 fcp->Start += 256;
731 dbg_printf(")");
732 break;
733 case SymTagTypedef:
734 dbg_printf("%s", name);
735 break;
736 default:
737 WINE_ERR("Unknown type %u for %s\n", tag, name);
738 break;
741 return TRUE;
744 /* helper to typecast pInfo to its expected type (_t) */
745 #define X(_t) (*((_t*)pInfo))
747 BOOL types_get_info(const struct dbg_type* type, IMAGEHLP_SYMBOL_TYPE_INFO ti, void* pInfo)
749 if (type->id == dbg_itype_none) return FALSE;
750 if (type->module != 0)
752 DWORD ret, tag, bt;
753 ret = SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, ti, pInfo);
754 if (!ret &&
755 SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_SYMTAG, &tag) &&
756 tag == SymTagBaseType &&
757 SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_BASETYPE, &bt))
759 static const WCHAR voidW[] = {'v','o','i','d','\0'};
760 static const WCHAR charW[] = {'c','h','a','r','\0'};
761 static const WCHAR wcharW[] = {'W','C','H','A','R','\0'};
762 static const WCHAR intW[] = {'i','n','t','\0'};
763 static const WCHAR uintW[] = {'u','n','s','i','g','n','e','d',' ','i','n','t','\0'};
764 static const WCHAR floatW[] = {'f','l','o','a','t','\0'};
765 static const WCHAR boolW[] = {'b','o','o','l','\0'};
766 static const WCHAR longW[] = {'l','o','n','g',' ','i','n','t','\0'};
767 static const WCHAR ulongW[] = {'u','n','s','i','g','n','e','d',' ','l','o','n','g',' ','i','n','t','\0'};
768 static const WCHAR complexW[] = {'c','o','m','p','l','e','x','\0'};
769 const WCHAR* name = NULL;
771 switch (bt)
773 case btVoid: name = voidW; break;
774 case btChar: name = charW; break;
775 case btWChar: name = wcharW; break;
776 case btInt: name = intW; break;
777 case btUInt: name = uintW; break;
778 case btFloat: name = floatW; break;
779 case btBool: name = boolW; break;
780 case btLong: name = longW; break;
781 case btULong: name = ulongW; break;
782 case btComplex: name = complexW; break;
783 default: WINE_FIXME("Unsupported basic type %u\n", bt); return FALSE;
785 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(WCHAR));
786 if (X(WCHAR*))
788 lstrcpyW(X(WCHAR*), name);
789 ret = TRUE;
792 return ret;
795 assert(type->id >= dbg_itype_first);
797 switch (type->id)
799 case dbg_itype_unsigned_long_int:
800 switch (ti)
802 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
803 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
804 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
805 default: WINE_FIXME("unsupported %u for u-long int\n", ti); return FALSE;
807 break;
808 case dbg_itype_signed_long_int:
809 switch (ti)
811 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
812 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
813 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
814 default: WINE_FIXME("unsupported %u for s-long int\n", ti); return FALSE;
816 break;
817 case dbg_itype_unsigned_int:
818 switch (ti)
820 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
821 case TI_GET_LENGTH: X(DWORD64) = 4; break;
822 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
823 default: WINE_FIXME("unsupported %u for u-int\n", ti); return FALSE;
825 break;
826 case dbg_itype_signed_int:
827 switch (ti)
829 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
830 case TI_GET_LENGTH: X(DWORD64) = 4; break;
831 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
832 default: WINE_FIXME("unsupported %u for s-int\n", ti); return FALSE;
834 break;
835 case dbg_itype_unsigned_short_int:
836 switch (ti)
838 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
839 case TI_GET_LENGTH: X(DWORD64) = 2; break;
840 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
841 default: WINE_FIXME("unsupported %u for u-short int\n", ti); return FALSE;
843 break;
844 case dbg_itype_signed_short_int:
845 switch (ti)
847 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
848 case TI_GET_LENGTH: X(DWORD64) = 2; break;
849 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
850 default: WINE_FIXME("unsupported %u for s-short int\n", ti); return FALSE;
852 break;
853 case dbg_itype_unsigned_char_int:
854 switch (ti)
856 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
857 case TI_GET_LENGTH: X(DWORD64) = 1; break;
858 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
859 default: WINE_FIXME("unsupported %u for u-char int\n", ti); return FALSE;
861 break;
862 case dbg_itype_signed_char_int:
863 switch (ti)
865 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
866 case TI_GET_LENGTH: X(DWORD64) = 1; break;
867 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
868 default: WINE_FIXME("unsupported %u for s-char int\n", ti); return FALSE;
870 break;
871 case dbg_itype_char:
872 switch (ti)
874 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
875 case TI_GET_LENGTH: X(DWORD64) = 1; break;
876 case TI_GET_BASETYPE: X(DWORD) = btChar; break;
877 default: WINE_FIXME("unsupported %u for char int\n", ti); return FALSE;
879 break;
880 case dbg_itype_astring:
881 switch (ti)
883 case TI_GET_SYMTAG: X(DWORD) = SymTagPointerType; break;
884 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
885 case TI_GET_TYPE: X(DWORD) = dbg_itype_char; break;
886 default: WINE_FIXME("unsupported %u for a string\n", ti); return FALSE;
888 break;
889 case dbg_itype_segptr:
890 switch (ti)
892 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
893 case TI_GET_LENGTH: X(DWORD64) = 4; break;
894 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
895 default: WINE_FIXME("unsupported %u for seg-ptr\n", ti); return FALSE;
897 break;
898 case dbg_itype_short_real:
899 switch (ti)
901 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
902 case TI_GET_LENGTH: X(DWORD64) = 4; break;
903 case TI_GET_BASETYPE: X(DWORD) = btFloat; break;
904 default: WINE_FIXME("unsupported %u for short real\n", ti); return FALSE;
906 break;
907 case dbg_itype_real:
908 switch (ti)
910 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
911 case TI_GET_LENGTH: X(DWORD64) = 8; break;
912 case TI_GET_BASETYPE: X(DWORD) = btFloat; break;
913 default: WINE_FIXME("unsupported %u for real\n", ti); return FALSE;
915 break;
916 case dbg_itype_long_real:
917 switch (ti)
919 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
920 case TI_GET_LENGTH: X(DWORD64) = 10; break;
921 case TI_GET_BASETYPE: X(DWORD) = btFloat; break;
922 default: WINE_FIXME("unsupported %u for long real\n", ti); return FALSE;
924 break;
925 case dbg_itype_m128a:
926 switch (ti)
928 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
929 case TI_GET_LENGTH: X(DWORD64) = 16; break;
930 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
931 default: WINE_FIXME("unsupported %u for XMM register\n", ti); return FALSE;
933 break;
934 default: WINE_FIXME("unsupported type id 0x%lx\n", type->id);
937 #undef X
938 return TRUE;