makedep: Store the include paths without the -I prefix.
[wine.git] / programs / winedbg / types.c
blob8e8e9c4aef820042d7ec88f5fb77f6eb961b6187
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);
84 if (size > sizeof(rtn))
86 WINE_ERR("Size too large (%s)\n", wine_dbgstr_longlong(size));
87 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
89 switch (bt)
91 case btChar:
92 case btInt:
93 if (!be_cpu->fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn))
94 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
95 break;
96 case btUInt:
97 if (!be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
98 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
99 break;
100 case btFloat:
101 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
103 if (psize) *psize = (unsigned)size;
104 if (issigned) *issigned = s;
105 break;
106 case SymTagPointerType:
107 if (!be_cpu->fetch_integer(lvalue, sizeof(void*), s = FALSE, &rtn))
108 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
109 break;
110 case SymTagArrayType:
111 case SymTagUDT:
112 if (!be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
113 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
114 break;
115 case SymTagEnum:
116 /* FIXME: we don't handle enum size */
117 if (!be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
118 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
119 break;
120 case SymTagFunctionType:
121 rtn = (ULONG_PTR)memory_to_linear_addr(&lvalue->addr);
122 break;
123 default:
124 WINE_FIXME("Unsupported tag %u\n", tag);
125 RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
128 return rtn;
131 /******************************************************************
132 * types_extract_as_integer
134 * Given a lvalue, try to get an integral (or pointer/address) value
135 * out of it
137 long int types_extract_as_integer(const struct dbg_lvalue* lvalue)
139 return types_extract_as_longlong(lvalue, NULL, NULL);
142 /******************************************************************
143 * types_extract_as_address
147 void types_extract_as_address(const struct dbg_lvalue* lvalue, ADDRESS64* addr)
149 if (lvalue->type.id == dbg_itype_segptr && lvalue->type.module == 0)
151 *addr = lvalue->addr;
153 else
155 addr->Mode = AddrModeFlat;
156 addr->Offset = types_extract_as_longlong(lvalue, NULL, NULL);
160 BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lvalue_from)
162 LONGLONG val;
163 DWORD64 size;
164 BOOL is_signed;
166 if (!types_get_info(&lvalue_to->type, TI_GET_LENGTH, &size)) return FALSE;
167 if (sizeof(val) < size)
169 dbg_printf("Unsufficient size\n");
170 return FALSE;
172 /* FIXME: should support floats as well */
173 val = types_extract_as_longlong(lvalue_from, NULL, &is_signed);
174 return be_cpu->store_integer(lvalue_to, size, is_signed, val);
177 /******************************************************************
178 * types_get_udt_element_lvalue
180 * Implement a structure derefencement
182 static BOOL types_get_udt_element_lvalue(struct dbg_lvalue* lvalue,
183 const struct dbg_type* type, long int* tmpbuf)
185 DWORD offset, bitoffset;
186 DWORD bt;
187 DWORD64 length;
189 unsigned mask;
191 types_get_info(type, TI_GET_TYPE, &lvalue->type.id);
192 lvalue->type.module = type->module;
193 if (!types_get_info(type, TI_GET_OFFSET, &offset)) return FALSE;
194 lvalue->addr.Offset += offset;
196 if (types_get_info(type, TI_GET_BITPOSITION, &bitoffset))
198 types_get_info(type, TI_GET_LENGTH, &length);
199 /* FIXME: this test isn't sufficient, depending on start of bitfield
200 * (ie a 32 bit field can spread across 5 bytes)
202 if (length > 8 * sizeof(*tmpbuf)) return FALSE;
203 lvalue->addr.Offset += bitoffset >> 3;
205 * Bitfield operation. We have to extract the field and store
206 * it in a temporary buffer so that we get it all right.
208 if (!memory_read_value(lvalue, sizeof(*tmpbuf), tmpbuf)) return FALSE;
209 mask = 0xffffffff << (DWORD)length;
210 *tmpbuf >>= bitoffset & 7;
211 *tmpbuf &= ~mask;
213 lvalue->cookie = DLV_HOST;
214 lvalue->addr.Offset = (ULONG_PTR)tmpbuf;
217 * OK, now we have the correct part of the number.
218 * Check to see whether the basic type is signed or not, and if so,
219 * we need to sign extend the number.
221 if (types_get_info(&lvalue->type, TI_GET_BASETYPE, &bt) &&
222 bt == btInt && (*tmpbuf & (1 << ((DWORD)length - 1))))
224 *tmpbuf |= mask;
227 else
229 if (!memory_read_value(lvalue, sizeof(*tmpbuf), tmpbuf)) return FALSE;
231 return TRUE;
234 /******************************************************************
235 * types_udt_find_element
238 BOOL types_udt_find_element(struct dbg_lvalue* lvalue, const char* name, long int* tmpbuf)
240 DWORD tag, count;
241 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
242 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
243 WCHAR* ptr;
244 char tmp[256];
245 struct dbg_type type;
247 if (!types_get_real_type(&lvalue->type, &tag) || tag != SymTagUDT)
248 return FALSE;
250 if (types_get_info(&lvalue->type, TI_GET_CHILDRENCOUNT, &count))
252 fcp->Start = 0;
253 while (count)
255 fcp->Count = min(count, 256);
256 if (types_get_info(&lvalue->type, TI_FINDCHILDREN, fcp))
258 unsigned i;
259 type.module = lvalue->type.module;
260 for (i = 0; i < min(fcp->Count, count); i++)
262 ptr = NULL;
263 type.id = fcp->ChildId[i];
264 types_get_info(&type, TI_GET_SYMNAME, &ptr);
265 if (!ptr) continue;
266 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
267 HeapFree(GetProcessHeap(), 0, ptr);
268 if (strcmp(tmp, name)) continue;
270 return types_get_udt_element_lvalue(lvalue, &type, tmpbuf);
273 count -= min(count, 256);
274 fcp->Start += 256;
277 return FALSE;
280 /******************************************************************
281 * types_array_index
283 * Grab an element from an array
285 BOOL types_array_index(const struct dbg_lvalue* lvalue, int index, struct dbg_lvalue* result)
287 struct dbg_type type = lvalue->type;
288 DWORD tag, count;
290 memset(result, 0, sizeof(*result));
291 result->type.id = dbg_itype_none;
292 result->type.module = 0;
294 if (!types_get_real_type(&type, &tag)) return FALSE;
295 switch (tag)
297 case SymTagArrayType:
298 if (!types_get_info(&type, TI_GET_COUNT, &count)) return FALSE;
299 if (index < 0 || index >= count) return FALSE;
300 result->addr = lvalue->addr;
301 break;
302 case SymTagPointerType:
303 if (!memory_read_value(lvalue, be_cpu->pointer_size, &result->addr.Offset)) return FALSE;
304 result->addr.Mode = AddrModeFlat;
305 switch (be_cpu->pointer_size)
307 case 4: result->addr.Offset = (DWORD)result->addr.Offset; break;
308 case 8: break;
309 default: assert(0);
311 break;
312 default:
313 assert(FALSE);
316 * Get the base type, so we know how much to index by.
318 if (!types_get_info(&type, TI_GET_TYPE, &result->type.id)) return FALSE;
319 result->type.module = type.module;
320 if (index)
322 DWORD64 length;
323 if (!types_get_info(&result->type, TI_GET_LENGTH, &length)) return FALSE;
324 result->addr.Offset += index * (DWORD)length;
326 /* FIXME: the following statement is not always true (and can lead to buggy behavior).
327 * There is no way to tell were the deref:ed value is...
328 * For example:
329 * x is a pointer to struct s, x being on the stack
330 * => lvalue is in debuggee, result is in debugger
331 * x is a pointer to struct s, x being optimized into a reg
332 * => lvalue is debugger, result is debuggee
333 * x is a pointer to internal variable x
334 * => lvalue is debugger, result is debuggee
335 * So we always force debuggee address space, because dereferencing pointers to
336 * internal variables is very unlikely. A correct fix would be
337 * rather large.
339 result->cookie = DLV_TARGET;
340 return TRUE;
343 struct type_find_t
345 unsigned long result; /* out: the found type */
346 enum SymTagEnum tag; /* in: the tag to look for */
347 union
349 unsigned long typeid; /* when tag is SymTagUDT */
350 const char* name; /* when tag is SymTagPointerType */
351 } u;
354 static BOOL CALLBACK types_cb(PSYMBOL_INFO sym, ULONG size, void* _user)
356 struct type_find_t* user = _user;
357 BOOL ret = TRUE;
358 struct dbg_type type;
359 DWORD type_id;
361 if (sym->Tag == user->tag)
363 switch (user->tag)
365 case SymTagUDT:
366 if (!strcmp(user->u.name, sym->Name))
368 user->result = sym->TypeIndex;
369 ret = FALSE;
371 break;
372 case SymTagPointerType:
373 type.module = sym->ModBase;
374 type.id = sym->TypeIndex;
375 if (types_get_info(&type, TI_GET_TYPE, &type_id) && type_id == user->u.typeid)
377 user->result = sym->TypeIndex;
378 ret = FALSE;
380 break;
381 default: break;
384 return ret;
387 /******************************************************************
388 * types_find_pointer
390 * Should look up in module based at linear whether (typeid*) exists
391 * Otherwise, we could create it locally
393 struct dbg_type types_find_pointer(const struct dbg_type* type)
395 struct type_find_t f;
396 struct dbg_type ret;
398 f.result = dbg_itype_none;
399 f.tag = SymTagPointerType;
400 f.u.typeid = type->id;
401 SymEnumTypes(dbg_curr_process->handle, type->module, types_cb, &f);
402 ret.module = type->module;
403 ret.id = f.result;
404 return ret;
407 /******************************************************************
408 * types_find_type
410 * Should look up in the module based at linear address whether a type
411 * named 'name' and with the correct tag exists
413 struct dbg_type types_find_type(unsigned long linear, const char* name, enum SymTagEnum tag)
416 struct type_find_t f;
417 struct dbg_type ret;
419 f.result = dbg_itype_none;
420 f.tag = tag;
421 f.u.name = name;
422 SymEnumTypes(dbg_curr_process->handle, linear, types_cb, &f);
423 ret.module = linear;
424 ret.id = f.result;
425 return ret;
428 /***********************************************************************
429 * print_value
431 * Implementation of the 'print' command.
433 void print_value(const struct dbg_lvalue* lvalue, char format, int level)
435 struct dbg_type type = lvalue->type;
436 struct dbg_lvalue lvalue_field;
437 int i;
438 DWORD tag;
439 DWORD count;
440 DWORD64 size;
442 if (!types_get_real_type(&type, &tag))
444 WINE_FIXME("---error\n");
445 return;
448 if (type.id == dbg_itype_none)
450 /* No type, just print the addr value */
451 print_bare_address(&lvalue->addr);
452 goto leave;
455 if (format == 'i' || format == 's' || format == 'w' || format == 'b' || format == 'g')
457 dbg_printf("Format specifier '%c' is meaningless in 'print' command\n", format);
458 format = '\0';
461 switch (tag)
463 case SymTagBaseType:
464 case SymTagEnum:
465 case SymTagPointerType:
466 /* FIXME: this in not 100% optimal (as we're going through the typedef handling
467 * stuff again
469 print_basic(lvalue, format);
470 break;
471 case SymTagUDT:
472 if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count))
474 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
475 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
476 WCHAR* ptr;
477 char tmp[256];
478 long int tmpbuf;
479 struct dbg_type sub_type;
481 dbg_printf("{");
482 fcp->Start = 0;
483 while (count)
485 fcp->Count = min(count, 256);
486 if (types_get_info(&type, TI_FINDCHILDREN, fcp))
488 for (i = 0; i < min(fcp->Count, count); i++)
490 ptr = NULL;
491 sub_type.module = type.module;
492 sub_type.id = fcp->ChildId[i];
493 types_get_info(&sub_type, TI_GET_SYMNAME, &ptr);
494 if (!ptr) continue;
495 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
496 dbg_printf("%s=", tmp);
497 HeapFree(GetProcessHeap(), 0, ptr);
498 lvalue_field = *lvalue;
499 if (types_get_udt_element_lvalue(&lvalue_field, &sub_type, &tmpbuf))
501 print_value(&lvalue_field, format, level + 1);
503 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
506 count -= min(count, 256);
507 fcp->Start += 256;
509 dbg_printf("}");
511 break;
512 case SymTagArrayType:
514 * Loop over all of the entries, printing stuff as we go.
516 count = 1; size = 1;
517 types_get_info(&type, TI_GET_COUNT, &count);
518 types_get_info(&type, TI_GET_LENGTH, &size);
520 if (size == count)
522 unsigned len;
523 char buffer[256];
525 * Special handling for character arrays.
527 /* FIXME should check basic type here (should be a char!!!!)... */
528 len = min(count, sizeof(buffer));
529 memory_get_string(dbg_curr_process,
530 memory_to_linear_addr(&lvalue->addr),
531 lvalue->cookie == DLV_TARGET, TRUE, buffer, len);
532 dbg_printf("\"%s%s\"", buffer, (len < count) ? "..." : "");
533 break;
535 lvalue_field = *lvalue;
536 types_get_info(&type, TI_GET_TYPE, &lvalue_field.type.id);
537 dbg_printf("{");
538 for (i = 0; i < count; i++)
540 print_value(&lvalue_field, format, level + 1);
541 lvalue_field.addr.Offset += size / count;
542 dbg_printf((i == count - 1) ? "}" : ", ");
544 break;
545 case SymTagFunctionType:
546 dbg_printf("Function ");
547 print_bare_address(&lvalue->addr);
548 dbg_printf(": ");
549 types_print_type(&type, FALSE);
550 break;
551 case SymTagTypedef:
552 lvalue_field = *lvalue;
553 types_get_info(&lvalue->type, TI_GET_TYPE, &lvalue_field.type.id);
554 print_value(&lvalue_field, format, level);
555 break;
556 default:
557 WINE_FIXME("Unknown tag (%u)\n", tag);
558 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
559 break;
562 leave:
564 if (level == 0) dbg_printf("\n");
567 static BOOL CALLBACK print_types_cb(PSYMBOL_INFO sym, ULONG size, void* ctx)
569 struct dbg_type type;
570 type.module = sym->ModBase;
571 type.id = sym->TypeIndex;
572 dbg_printf("Mod: %08lx ID: %08lx\n", type.module, type.id);
573 types_print_type(&type, TRUE);
574 dbg_printf("\n");
575 return TRUE;
578 static BOOL CALLBACK print_types_mod_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
580 return SymEnumTypes(dbg_curr_process->handle, base, print_types_cb, ctx);
583 BOOL print_types(void)
585 if (!dbg_curr_process)
587 dbg_printf("No known process, cannot print types\n");
588 return FALSE;
590 SymEnumerateModules64(dbg_curr_process->handle, print_types_mod_cb, NULL);
591 return FALSE;
594 BOOL types_print_type(const struct dbg_type* type, BOOL details)
596 WCHAR* ptr;
597 char tmp[256];
598 const char* name;
599 DWORD tag, udt, count;
600 struct dbg_type subtype;
602 if (type->id == dbg_itype_none || !types_get_info(type, TI_GET_SYMTAG, &tag))
604 dbg_printf("--invalid--<%lxh>--", type->id);
605 return FALSE;
608 if (types_get_info(type, TI_GET_SYMNAME, &ptr) && ptr)
610 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
611 name = tmp;
612 HeapFree(GetProcessHeap(), 0, ptr);
614 else name = "--none--";
616 switch (tag)
618 case SymTagBaseType:
619 if (details) dbg_printf("Basic<%s>", name); else dbg_printf("%s", name);
620 break;
621 case SymTagPointerType:
622 types_get_info(type, TI_GET_TYPE, &subtype.id);
623 subtype.module = type->module;
624 types_print_type(&subtype, FALSE);
625 dbg_printf("*");
626 break;
627 case SymTagUDT:
628 types_get_info(type, TI_GET_UDTKIND, &udt);
629 switch (udt)
631 case UdtStruct: dbg_printf("struct %s", name); break;
632 case UdtUnion: dbg_printf("union %s", name); break;
633 case UdtClass: dbg_printf("class %s", name); break;
634 default: WINE_ERR("Unsupported UDT type (%d) for %s\n", udt, name); break;
636 if (details &&
637 types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
639 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
640 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
641 WCHAR* ptr;
642 char tmp[256];
643 int i;
644 struct dbg_type type_elt;
645 dbg_printf(" {");
647 fcp->Start = 0;
648 while (count)
650 fcp->Count = min(count, 256);
651 if (types_get_info(type, TI_FINDCHILDREN, fcp))
653 for (i = 0; i < min(fcp->Count, count); i++)
655 ptr = NULL;
656 type_elt.module = type->module;
657 type_elt.id = fcp->ChildId[i];
658 types_get_info(&type_elt, TI_GET_SYMNAME, &ptr);
659 if (!ptr) continue;
660 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
661 HeapFree(GetProcessHeap(), 0, ptr);
662 dbg_printf("%s", tmp);
663 if (types_get_info(&type_elt, TI_GET_TYPE, &type_elt.id))
665 dbg_printf(":");
666 types_print_type(&type_elt, details);
668 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
671 count -= min(count, 256);
672 fcp->Start += 256;
674 dbg_printf("}");
676 break;
677 case SymTagArrayType:
678 types_get_info(type, TI_GET_TYPE, &subtype.id);
679 subtype.module = type->module;
680 types_print_type(&subtype, details);
681 if (types_get_info(type, TI_GET_COUNT, &count))
682 dbg_printf(" %s[%d]", name, count);
683 else
684 dbg_printf(" %s[]", name);
685 break;
686 case SymTagEnum:
687 dbg_printf("enum %s", name);
688 break;
689 case SymTagFunctionType:
690 types_get_info(type, TI_GET_TYPE, &subtype.id);
691 /* is the returned type the same object as function sig itself ? */
692 if (subtype.id != type->id)
694 subtype.module = type->module;
695 types_print_type(&subtype, FALSE);
697 else
699 subtype.module = 0;
700 dbg_printf("<ret_type=self>");
702 dbg_printf(" (*%s)(", name);
703 if (types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
705 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
706 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
707 int i;
709 fcp->Start = 0;
710 if (!count) dbg_printf("void");
711 else while (count)
713 fcp->Count = min(count, 256);
714 if (types_get_info(type, TI_FINDCHILDREN, fcp))
716 for (i = 0; i < min(fcp->Count, count); i++)
718 subtype.id = fcp->ChildId[i];
719 types_get_info(&subtype, TI_GET_TYPE, &subtype.id);
720 types_print_type(&subtype, FALSE);
721 if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
724 count -= min(count, 256);
725 fcp->Start += 256;
728 dbg_printf(")");
729 break;
730 case SymTagTypedef:
731 dbg_printf("%s", name);
732 break;
733 default:
734 WINE_ERR("Unknown type %u for %s\n", tag, name);
735 break;
738 return TRUE;
741 /* helper to typecast pInfo to its expected type (_t) */
742 #define X(_t) (*((_t*)pInfo))
744 BOOL types_get_info(const struct dbg_type* type, IMAGEHLP_SYMBOL_TYPE_INFO ti, void* pInfo)
746 if (type->id == dbg_itype_none) return FALSE;
747 if (type->module != 0)
749 DWORD ret, tag, bt;
750 ret = SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, ti, pInfo);
751 if (!ret &&
752 SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_SYMTAG, &tag) &&
753 tag == SymTagBaseType &&
754 SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_BASETYPE, &bt))
756 static const WCHAR voidW[] = {'v','o','i','d','\0'};
757 static const WCHAR charW[] = {'c','h','a','r','\0'};
758 static const WCHAR wcharW[] = {'W','C','H','A','R','\0'};
759 static const WCHAR intW[] = {'i','n','t','\0'};
760 static const WCHAR uintW[] = {'u','n','s','i','g','n','e','d',' ','i','n','t','\0'};
761 static const WCHAR floatW[] = {'f','l','o','a','t','\0'};
762 static const WCHAR boolW[] = {'b','o','o','l','\0'};
763 static const WCHAR longW[] = {'l','o','n','g',' ','i','n','t','\0'};
764 static const WCHAR ulongW[] = {'u','n','s','i','g','n','e','d',' ','l','o','n','g',' ','i','n','t','\0'};
765 static const WCHAR complexW[] = {'c','o','m','p','l','e','x','\0'};
766 const WCHAR* name = NULL;
768 switch (bt)
770 case btVoid: name = voidW; break;
771 case btChar: name = charW; break;
772 case btWChar: name = wcharW; break;
773 case btInt: name = intW; break;
774 case btUInt: name = uintW; break;
775 case btFloat: name = floatW; break;
776 case btBool: name = boolW; break;
777 case btLong: name = longW; break;
778 case btULong: name = ulongW; break;
779 case btComplex: name = complexW; break;
780 default: WINE_FIXME("Unsupported basic type %u\n", bt); return FALSE;
782 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(WCHAR));
783 if (X(WCHAR*))
785 lstrcpyW(X(WCHAR*), name);
786 ret = TRUE;
789 return ret;
792 assert(type->id >= dbg_itype_first);
794 switch (type->id)
796 case dbg_itype_unsigned_long_int:
797 switch (ti)
799 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
800 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
801 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
802 default: WINE_FIXME("unsupported %u for u-long int\n", ti); return FALSE;
804 break;
805 case dbg_itype_signed_long_int:
806 switch (ti)
808 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
809 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
810 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
811 default: WINE_FIXME("unsupported %u for s-long int\n", ti); return FALSE;
813 break;
814 case dbg_itype_unsigned_int:
815 switch (ti)
817 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
818 case TI_GET_LENGTH: X(DWORD64) = 4; break;
819 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
820 default: WINE_FIXME("unsupported %u for u-int\n", ti); return FALSE;
822 break;
823 case dbg_itype_signed_int:
824 switch (ti)
826 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
827 case TI_GET_LENGTH: X(DWORD64) = 4; break;
828 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
829 default: WINE_FIXME("unsupported %u for s-int\n", ti); return FALSE;
831 break;
832 case dbg_itype_unsigned_short_int:
833 switch (ti)
835 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
836 case TI_GET_LENGTH: X(DWORD64) = 2; break;
837 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
838 default: WINE_FIXME("unsupported %u for u-short int\n", ti); return FALSE;
840 break;
841 case dbg_itype_signed_short_int:
842 switch (ti)
844 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
845 case TI_GET_LENGTH: X(DWORD64) = 2; break;
846 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
847 default: WINE_FIXME("unsupported %u for s-short int\n", ti); return FALSE;
849 break;
850 case dbg_itype_unsigned_char_int:
851 switch (ti)
853 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
854 case TI_GET_LENGTH: X(DWORD64) = 1; break;
855 case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
856 default: WINE_FIXME("unsupported %u for u-char int\n", ti); return FALSE;
858 break;
859 case dbg_itype_signed_char_int:
860 switch (ti)
862 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
863 case TI_GET_LENGTH: X(DWORD64) = 1; break;
864 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
865 default: WINE_FIXME("unsupported %u for s-char int\n", ti); return FALSE;
867 break;
868 case dbg_itype_char:
869 switch (ti)
871 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
872 case TI_GET_LENGTH: X(DWORD64) = 1; break;
873 case TI_GET_BASETYPE: X(DWORD) = btChar; break;
874 default: WINE_FIXME("unsupported %u for char int\n", ti); return FALSE;
876 break;
877 case dbg_itype_astring:
878 switch (ti)
880 case TI_GET_SYMTAG: X(DWORD) = SymTagPointerType; break;
881 case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
882 case TI_GET_TYPE: X(DWORD) = dbg_itype_char; break;
883 default: WINE_FIXME("unsupported %u for a string\n", ti); return FALSE;
885 break;
886 case dbg_itype_segptr:
887 switch (ti)
889 case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
890 case TI_GET_LENGTH: X(DWORD64) = 4; break;
891 case TI_GET_BASETYPE: X(DWORD) = btInt; break;
892 default: WINE_FIXME("unsupported %u for seg-ptr\n", ti); return FALSE;
894 break;
895 default: WINE_FIXME("unsupported type id 0x%lx\n", type->id);
898 #undef X
899 return TRUE;