ntoskrnl.exe: Add ObRegisterCallbacks stub.
[wine.git] / programs / winedbg / types.c
blob3268d7e4dbf201c696cd69af776ddcb30db0745e
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 (!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 (!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 (!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 (!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 (!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("Unsufficient 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 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, be_cpu->pointer_size, &result->addr.Offset)) return FALSE;
306 result->addr.Mode = AddrModeFlat;
307 switch (be_cpu->pointer_size)
309 case 4: result->addr.Offset = (DWORD)result->addr.Offset; break;
310 case 8: break;
311 default: assert(0);
313 break;
314 default:
315 assert(FALSE);
318 * Get the base type, so we know how much to index by.
320 if (!types_get_info(&type, TI_GET_TYPE, &result->type.id)) return FALSE;
321 result->type.module = type.module;
322 if (index)
324 DWORD64 length;
325 if (!types_get_info(&result->type, TI_GET_LENGTH, &length)) return FALSE;
326 result->addr.Offset += index * (DWORD)length;
328 /* FIXME: the following statement is not always true (and can lead to buggy behavior).
329 * There is no way to tell where the deref:ed value is...
330 * For example:
331 * x is a pointer to struct s, x being on the stack
332 * => lvalue is in debuggee, result is in debugger
333 * x is a pointer to struct s, x being optimized into a reg
334 * => lvalue is debugger, result is debuggee
335 * x is a pointer to internal variable x
336 * => lvalue is debugger, result is debuggee
337 * So we always force debuggee address space, because dereferencing pointers to
338 * internal variables is very unlikely. A correct fix would be
339 * rather large.
341 result->cookie = DLV_TARGET;
342 return TRUE;
345 struct type_find_t
347 unsigned long result; /* out: the found type */
348 enum SymTagEnum tag; /* in: the tag to look for */
349 union
351 unsigned long typeid; /* when tag is SymTagUDT */
352 const char* name; /* when tag is SymTagPointerType */
353 } u;
356 static BOOL CALLBACK types_cb(PSYMBOL_INFO sym, ULONG size, void* _user)
358 struct type_find_t* user = _user;
359 BOOL ret = TRUE;
360 struct dbg_type type;
361 DWORD type_id;
363 if (sym->Tag == user->tag)
365 switch (user->tag)
367 case SymTagUDT:
368 if (!strcmp(user->u.name, sym->Name))
370 user->result = sym->TypeIndex;
371 ret = FALSE;
373 break;
374 case SymTagPointerType:
375 type.module = sym->ModBase;
376 type.id = sym->TypeIndex;
377 if (types_get_info(&type, TI_GET_TYPE, &type_id) && type_id == user->u.typeid)
379 user->result = sym->TypeIndex;
380 ret = FALSE;
382 break;
383 default: break;
386 return ret;
389 /******************************************************************
390 * types_find_pointer
392 * Should look up in module based at linear whether (typeid*) exists
393 * Otherwise, we could create it locally
395 struct dbg_type types_find_pointer(const struct dbg_type* type)
397 struct type_find_t f;
398 struct dbg_type ret;
400 f.result = dbg_itype_none;
401 f.tag = SymTagPointerType;
402 f.u.typeid = type->id;
403 SymEnumTypes(dbg_curr_process->handle, type->module, types_cb, &f);
404 ret.module = type->module;
405 ret.id = f.result;
406 return ret;
409 /******************************************************************
410 * types_find_type
412 * Should look up in the module based at linear address whether a type
413 * named 'name' and with the correct tag exists
415 struct dbg_type types_find_type(unsigned long linear, const char* name, enum SymTagEnum tag)
418 struct type_find_t f;
419 struct dbg_type ret;
421 f.result = dbg_itype_none;
422 f.tag = tag;
423 f.u.name = name;
424 SymEnumTypes(dbg_curr_process->handle, linear, types_cb, &f);
425 ret.module = linear;
426 ret.id = f.result;
427 return ret;
430 /***********************************************************************
431 * print_value
433 * Implementation of the 'print' command.
435 void print_value(const struct dbg_lvalue* lvalue, char format, int level)
437 struct dbg_type type = lvalue->type;
438 struct dbg_lvalue lvalue_field;
439 int i;
440 DWORD tag;
441 DWORD count;
442 DWORD64 size;
444 if (!types_get_real_type(&type, &tag))
446 WINE_FIXME("---error\n");
447 return;
450 if (type.id == dbg_itype_none)
452 /* No type, just print the addr value */
453 print_bare_address(&lvalue->addr);
454 goto leave;
457 if (format == 'i' || format == 's' || format == 'w' || format == 'b' || format == 'g')
459 dbg_printf("Format specifier '%c' is meaningless in 'print' command\n", format);
460 format = '\0';
463 switch (tag)
465 case SymTagBaseType:
466 case SymTagEnum:
467 case SymTagPointerType:
468 /* FIXME: this in not 100% optimal (as we're going through the typedef handling
469 * stuff again
471 print_basic(lvalue, format);
472 break;
473 case SymTagUDT:
474 if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count))
476 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
477 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
478 WCHAR* ptr;
479 char tmp[256];
480 long int tmpbuf;
481 struct dbg_type sub_type;
483 dbg_printf("{");
484 fcp->Start = 0;
485 while (count)
487 fcp->Count = min(count, 256);
488 if (types_get_info(&type, TI_FINDCHILDREN, fcp))
490 for (i = 0; i < min(fcp->Count, count); i++)
492 ptr = NULL;
493 sub_type.module = type.module;
494 sub_type.id = fcp->ChildId[i];
495 types_get_info(&sub_type, TI_GET_SYMNAME, &ptr);
496 if (!ptr) continue;
497 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
498 dbg_printf("%s=", tmp);
499 HeapFree(GetProcessHeap(), 0, ptr);
500 lvalue_field = *lvalue;
501 if (types_get_udt_element_lvalue(&lvalue_field, &sub_type, &tmpbuf))
503 print_value(&lvalue_field, format, level + 1);
505 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
508 count -= min(count, 256);
509 fcp->Start += 256;
511 dbg_printf("}");
513 break;
514 case SymTagArrayType:
516 * Loop over all of the entries, printing stuff as we go.
518 count = 1; size = 1;
519 types_get_info(&type, TI_GET_COUNT, &count);
520 types_get_info(&type, TI_GET_LENGTH, &size);
522 if (size == count)
524 unsigned len;
525 char buffer[256];
527 * Special handling for character arrays.
529 /* FIXME should check basic type here (should be a char!!!!)... */
530 len = min(count, sizeof(buffer));
531 memory_get_string(dbg_curr_process,
532 memory_to_linear_addr(&lvalue->addr),
533 lvalue->cookie == DLV_TARGET, TRUE, buffer, len);
534 dbg_printf("\"%s%s\"", buffer, (len < count) ? "..." : "");
535 break;
537 lvalue_field = *lvalue;
538 types_get_info(&type, TI_GET_TYPE, &lvalue_field.type.id);
539 dbg_printf("{");
540 for (i = 0; i < count; i++)
542 print_value(&lvalue_field, format, level + 1);
543 lvalue_field.addr.Offset += size / count;
544 dbg_printf((i == count - 1) ? "}" : ", ");
546 break;
547 case SymTagFunctionType:
548 dbg_printf("Function ");
549 print_bare_address(&lvalue->addr);
550 dbg_printf(": ");
551 types_print_type(&type, FALSE);
552 break;
553 case SymTagTypedef:
554 lvalue_field = *lvalue;
555 types_get_info(&lvalue->type, TI_GET_TYPE, &lvalue_field.type.id);
556 print_value(&lvalue_field, format, level);
557 break;
558 default:
559 WINE_FIXME("Unknown tag (%u)\n", tag);
560 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
561 break;
564 leave:
566 if (level == 0) dbg_printf("\n");
569 static BOOL CALLBACK print_types_cb(PSYMBOL_INFO sym, ULONG size, void* ctx)
571 struct dbg_type type;
572 type.module = sym->ModBase;
573 type.id = sym->TypeIndex;
574 dbg_printf("Mod: %08lx ID: %08lx\n", type.module, type.id);
575 types_print_type(&type, TRUE);
576 dbg_printf("\n");
577 return TRUE;
580 static BOOL CALLBACK print_types_mod_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
582 return SymEnumTypes(dbg_curr_process->handle, base, print_types_cb, ctx);
585 BOOL print_types(void)
587 if (!dbg_curr_process)
589 dbg_printf("No known process, cannot print types\n");
590 return FALSE;
592 SymEnumerateModules64(dbg_curr_process->handle, print_types_mod_cb, NULL);
593 return FALSE;
596 BOOL types_print_type(const struct dbg_type* type, BOOL details)
598 WCHAR* ptr;
599 char tmp[256];
600 const char* name;
601 DWORD tag, udt, count;
602 struct dbg_type subtype;
604 if (type->id == dbg_itype_none || !types_get_info(type, TI_GET_SYMTAG, &tag))
606 dbg_printf("--invalid--<%lxh>--", type->id);
607 return FALSE;
610 if (types_get_info(type, TI_GET_SYMNAME, &ptr) && ptr)
612 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
613 name = tmp;
614 HeapFree(GetProcessHeap(), 0, ptr);
616 else name = "--none--";
618 switch (tag)
620 case SymTagBaseType:
621 if (details) dbg_printf("Basic<%s>", name); else dbg_printf("%s", name);
622 break;
623 case SymTagPointerType:
624 types_get_info(type, TI_GET_TYPE, &subtype.id);
625 subtype.module = type->module;
626 types_print_type(&subtype, FALSE);
627 dbg_printf("*");
628 break;
629 case SymTagUDT:
630 types_get_info(type, TI_GET_UDTKIND, &udt);
631 switch (udt)
633 case UdtStruct: dbg_printf("struct %s", name); break;
634 case UdtUnion: dbg_printf("union %s", name); break;
635 case UdtClass: dbg_printf("class %s", name); break;
636 default: WINE_ERR("Unsupported UDT type (%d) for %s\n", udt, name); break;
638 if (details &&
639 types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
641 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
642 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
643 WCHAR* ptr;
644 char tmp[256];
645 int i;
646 struct dbg_type type_elt;
647 dbg_printf(" {");
649 fcp->Start = 0;
650 while (count)
652 fcp->Count = min(count, 256);
653 if (types_get_info(type, TI_FINDCHILDREN, fcp))
655 for (i = 0; i < min(fcp->Count, count); i++)
657 ptr = NULL;
658 type_elt.module = type->module;
659 type_elt.id = fcp->ChildId[i];
660 types_get_info(&type_elt, TI_GET_SYMNAME, &ptr);
661 if (!ptr) continue;
662 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
663 HeapFree(GetProcessHeap(), 0, ptr);
664 dbg_printf("%s", tmp);
665 if (types_get_info(&type_elt, TI_GET_TYPE, &type_elt.id))
667 dbg_printf(":");
668 types_print_type(&type_elt, details);
670 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
673 count -= min(count, 256);
674 fcp->Start += 256;
676 dbg_printf("}");
678 break;
679 case SymTagArrayType:
680 types_get_info(type, TI_GET_TYPE, &subtype.id);
681 subtype.module = type->module;
682 types_print_type(&subtype, details);
683 if (types_get_info(type, TI_GET_COUNT, &count))
684 dbg_printf(" %s[%d]", name, count);
685 else
686 dbg_printf(" %s[]", name);
687 break;
688 case SymTagEnum:
689 dbg_printf("enum %s", name);
690 break;
691 case SymTagFunctionType:
692 types_get_info(type, TI_GET_TYPE, &subtype.id);
693 /* is the returned type the same object as function sig itself ? */
694 if (subtype.id != type->id)
696 subtype.module = type->module;
697 types_print_type(&subtype, FALSE);
699 else
701 subtype.module = 0;
702 dbg_printf("<ret_type=self>");
704 dbg_printf(" (*%s)(", name);
705 if (types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
707 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
708 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
709 int i;
711 fcp->Start = 0;
712 if (!count) dbg_printf("void");
713 else while (count)
715 fcp->Count = min(count, 256);
716 if (types_get_info(type, TI_FINDCHILDREN, fcp))
718 for (i = 0; i < min(fcp->Count, count); i++)
720 subtype.id = fcp->ChildId[i];
721 types_get_info(&subtype, TI_GET_TYPE, &subtype.id);
722 types_print_type(&subtype, FALSE);
723 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
726 count -= min(count, 256);
727 fcp->Start += 256;
730 dbg_printf(")");
731 break;
732 case SymTagTypedef:
733 dbg_printf("%s", name);
734 break;
735 default:
736 WINE_ERR("Unknown type %u for %s\n", tag, name);
737 break;
740 return TRUE;
743 /* helper to typecast pInfo to its expected type (_t) */
744 #define X(_t) (*((_t*)pInfo))
746 BOOL types_get_info(const struct dbg_type* type, IMAGEHLP_SYMBOL_TYPE_INFO ti, void* pInfo)
748 if (type->id == dbg_itype_none) return FALSE;
749 if (type->module != 0)
751 DWORD ret, tag, bt;
752 ret = SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, ti, pInfo);
753 if (!ret &&
754 SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_SYMTAG, &tag) &&
755 tag == SymTagBaseType &&
756 SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_BASETYPE, &bt))
758 static const WCHAR voidW[] = {'v','o','i','d','\0'};
759 static const WCHAR charW[] = {'c','h','a','r','\0'};
760 static const WCHAR wcharW[] = {'W','C','H','A','R','\0'};
761 static const WCHAR intW[] = {'i','n','t','\0'};
762 static const WCHAR uintW[] = {'u','n','s','i','g','n','e','d',' ','i','n','t','\0'};
763 static const WCHAR floatW[] = {'f','l','o','a','t','\0'};
764 static const WCHAR boolW[] = {'b','o','o','l','\0'};
765 static const WCHAR longW[] = {'l','o','n','g',' ','i','n','t','\0'};
766 static const WCHAR ulongW[] = {'u','n','s','i','g','n','e','d',' ','l','o','n','g',' ','i','n','t','\0'};
767 static const WCHAR complexW[] = {'c','o','m','p','l','e','x','\0'};
768 const WCHAR* name = NULL;
770 switch (bt)
772 case btVoid: name = voidW; break;
773 case btChar: name = charW; break;
774 case btWChar: name = wcharW; break;
775 case btInt: name = intW; break;
776 case btUInt: name = uintW; break;
777 case btFloat: name = floatW; break;
778 case btBool: name = boolW; break;
779 case btLong: name = longW; break;
780 case btULong: name = ulongW; break;
781 case btComplex: name = complexW; break;
782 default: WINE_FIXME("Unsupported basic type %u\n", bt); return FALSE;
784 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(WCHAR));
785 if (X(WCHAR*))
787 lstrcpyW(X(WCHAR*), name);
788 ret = TRUE;
791 return ret;
794 assert(type->id >= dbg_itype_first);
796 switch (type->id)
798 case dbg_itype_unsigned_long_int:
799 switch (ti)
801 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
802 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
803 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
804 default: WINE_FIXME("unsupported %u for u-long int\n", ti); return FALSE;
806 break;
807 case dbg_itype_signed_long_int:
808 switch (ti)
810 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
811 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
812 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
813 default: WINE_FIXME("unsupported %u for s-long int\n", ti); return FALSE;
815 break;
816 case dbg_itype_unsigned_int:
817 switch (ti)
819 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
820 case TI_GET_LENGTH: X(DWORD64) = 4; break;
821 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
822 default: WINE_FIXME("unsupported %u for u-int\n", ti); return FALSE;
824 break;
825 case dbg_itype_signed_int:
826 switch (ti)
828 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
829 case TI_GET_LENGTH: X(DWORD64) = 4; break;
830 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
831 default: WINE_FIXME("unsupported %u for s-int\n", ti); return FALSE;
833 break;
834 case dbg_itype_unsigned_short_int:
835 switch (ti)
837 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
838 case TI_GET_LENGTH: X(DWORD64) = 2; break;
839 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
840 default: WINE_FIXME("unsupported %u for u-short int\n", ti); return FALSE;
842 break;
843 case dbg_itype_signed_short_int:
844 switch (ti)
846 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
847 case TI_GET_LENGTH: X(DWORD64) = 2; break;
848 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
849 default: WINE_FIXME("unsupported %u for s-short int\n", ti); return FALSE;
851 break;
852 case dbg_itype_unsigned_char_int:
853 switch (ti)
855 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
856 case TI_GET_LENGTH: X(DWORD64) = 1; break;
857 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
858 default: WINE_FIXME("unsupported %u for u-char int\n", ti); return FALSE;
860 break;
861 case dbg_itype_signed_char_int:
862 switch (ti)
864 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
865 case TI_GET_LENGTH: X(DWORD64) = 1; break;
866 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
867 default: WINE_FIXME("unsupported %u for s-char int\n", ti); return FALSE;
869 break;
870 case dbg_itype_char:
871 switch (ti)
873 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
874 case TI_GET_LENGTH: X(DWORD64) = 1; break;
875 case TI_GET_BASETYPE: X(DWORD) = btChar; break;
876 default: WINE_FIXME("unsupported %u for char int\n", ti); return FALSE;
878 break;
879 case dbg_itype_astring:
880 switch (ti)
882 case TI_GET_SYMTAG: X(DWORD) = SymTagPointerType; break;
883 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
884 case TI_GET_TYPE: X(DWORD) = dbg_itype_char; break;
885 default: WINE_FIXME("unsupported %u for a string\n", ti); return FALSE;
887 break;
888 case dbg_itype_segptr:
889 switch (ti)
891 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
892 case TI_GET_LENGTH: X(DWORD64) = 4; break;
893 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
894 default: WINE_FIXME("unsupported %u for seg-ptr\n", ti); return FALSE;
896 break;
897 case dbg_itype_short_real:
898 switch (ti)
900 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
901 case TI_GET_LENGTH: X(DWORD64) = 4; break;
902 case TI_GET_BASETYPE: X(DWORD) = btFloat; break;
903 default: WINE_FIXME("unsupported %u for short real\n", ti); return FALSE;
905 break;
906 case dbg_itype_real:
907 switch (ti)
909 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
910 case TI_GET_LENGTH: X(DWORD64) = 8; break;
911 case TI_GET_BASETYPE: X(DWORD) = btFloat; break;
912 default: WINE_FIXME("unsupported %u for real\n", ti); return FALSE;
914 break;
915 case dbg_itype_long_real:
916 switch (ti)
918 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
919 case TI_GET_LENGTH: X(DWORD64) = 10; break;
920 case TI_GET_BASETYPE: X(DWORD) = btFloat; break;
921 default: WINE_FIXME("unsupported %u for long real\n", ti); return FALSE;
923 break;
924 case dbg_itype_m128a:
925 switch (ti)
927 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
928 case TI_GET_LENGTH: X(DWORD64) = 16; break;
929 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
930 default: WINE_FIXME("unsupported %u for XMM register\n", ti); return FALSE;
932 break;
933 default: WINE_FIXME("unsupported type id 0x%lx\n", type->id);
936 #undef X
937 return TRUE;