widl: Don't force removal of progids since "CLSID" is also a progid.
[wine.git] / dlls / dbghelp / type.c
blobe933e19c9b20969b19e405ad9cf6b8e8dfb9ce90
1 /*
2 * File types.c - management of types (hierarchical tree)
4 * Copyright (C) 1997, Eric Youngdale.
5 * 2004, Eric Pouech.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * Note: This really doesn't do much at the moment, but it forms the framework
22 * upon which full support for datatype handling will eventually be built.
25 #define NONAMELESSUNION
27 #include "config.h"
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <assert.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winnls.h"
35 #include "wine/debug.h"
36 #include "dbghelp_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
39 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt);
41 static const char* symt_get_tag_str(DWORD tag)
43 switch (tag)
45 case SymTagNull: return "SymTagNull";
46 case SymTagExe: return "SymTagExe";
47 case SymTagCompiland: return "SymTagCompiland";
48 case SymTagCompilandDetails: return "SymTagCompilandDetails";
49 case SymTagCompilandEnv: return "SymTagCompilandEnv";
50 case SymTagFunction: return "SymTagFunction";
51 case SymTagBlock: return "SymTagBlock";
52 case SymTagData: return "SymTagData";
53 case SymTagAnnotation: return "SymTagAnnotation";
54 case SymTagLabel: return "SymTagLabel";
55 case SymTagPublicSymbol: return "SymTagPublicSymbol";
56 case SymTagUDT: return "SymTagUDT";
57 case SymTagEnum: return "SymTagEnum";
58 case SymTagFunctionType: return "SymTagFunctionType";
59 case SymTagPointerType: return "SymTagPointerType";
60 case SymTagArrayType: return "SymTagArrayType";
61 case SymTagBaseType: return "SymTagBaseType";
62 case SymTagTypedef: return "SymTagTypedef,";
63 case SymTagBaseClass: return "SymTagBaseClass";
64 case SymTagFriend: return "SymTagFriend";
65 case SymTagFunctionArgType: return "SymTagFunctionArgType,";
66 case SymTagFuncDebugStart: return "SymTagFuncDebugStart,";
67 case SymTagFuncDebugEnd: return "SymTagFuncDebugEnd";
68 case SymTagUsingNamespace: return "SymTagUsingNamespace,";
69 case SymTagVTableShape: return "SymTagVTableShape";
70 case SymTagVTable: return "SymTagVTable";
71 case SymTagCustom: return "SymTagCustom";
72 case SymTagThunk: return "SymTagThunk";
73 case SymTagCustomType: return "SymTagCustomType";
74 case SymTagManagedType: return "SymTagManagedType";
75 case SymTagDimension: return "SymTagDimension";
76 default: return "---";
80 const char* symt_get_name(const struct symt* sym)
82 switch (sym->tag)
84 /* lexical tree */
85 case SymTagData: return ((const struct symt_data*)sym)->hash_elt.name;
86 case SymTagFunction: return ((const struct symt_function*)sym)->hash_elt.name;
87 case SymTagPublicSymbol: return ((const struct symt_public*)sym)->hash_elt.name;
88 case SymTagBaseType: return ((const struct symt_basic*)sym)->hash_elt.name;
89 case SymTagLabel: return ((const struct symt_hierarchy_point*)sym)->hash_elt.name;
90 case SymTagThunk: return ((const struct symt_thunk*)sym)->hash_elt.name;
91 /* hierarchy tree */
92 case SymTagEnum: return ((const struct symt_enum*)sym)->name;
93 case SymTagTypedef: return ((const struct symt_typedef*)sym)->hash_elt.name;
94 case SymTagUDT: return ((const struct symt_udt*)sym)->hash_elt.name;
95 default:
96 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym->tag));
97 /* fall through */
98 case SymTagArrayType:
99 case SymTagPointerType:
100 case SymTagFunctionType:
101 return NULL;
105 static struct symt* symt_find_type_by_name(const struct module* module,
106 enum SymTagEnum sym_tag,
107 const char* typename)
109 void* ptr;
110 struct symt_ht* type;
111 struct hash_table_iter hti;
113 assert(typename);
114 assert(module);
116 hash_table_iter_init(&module->ht_types, &hti, typename);
117 while ((ptr = hash_table_iter_up(&hti)))
119 type = GET_ENTRY(ptr, struct symt_ht, hash_elt);
121 if ((sym_tag == SymTagNull || type->symt.tag == sym_tag) &&
122 type->hash_elt.name && !strcmp(type->hash_elt.name, typename))
123 return &type->symt;
125 SetLastError(ERROR_INVALID_NAME); /* FIXME ?? */
126 return NULL;
129 static void symt_add_type(struct module* module, struct symt* symt)
131 struct symt** p;
132 p = vector_add(&module->vtypes, &module->pool);
133 assert(p);
134 *p = symt;
137 struct symt_basic* symt_new_basic(struct module* module, enum BasicType bt,
138 const char* typename, unsigned size)
140 struct symt_basic* sym;
142 if (typename)
144 sym = (struct symt_basic*)symt_find_type_by_name(module, SymTagBaseType,
145 typename);
146 if (sym && sym->bt == bt && sym->size == size)
147 return sym;
149 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
151 sym->symt.tag = SymTagBaseType;
152 if (typename)
154 sym->hash_elt.name = pool_strdup(&module->pool, typename);
155 hash_table_add(&module->ht_types, &sym->hash_elt);
156 } else sym->hash_elt.name = NULL;
157 sym->bt = bt;
158 sym->size = size;
159 symt_add_type(module, &sym->symt);
161 return sym;
164 struct symt_udt* symt_new_udt(struct module* module, const char* typename,
165 unsigned size, enum UdtKind kind)
167 struct symt_udt* sym;
169 TRACE_(dbghelp_symt)("Adding udt %s:%s\n",
170 debugstr_w(module->module.ModuleName), typename);
171 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
173 sym->symt.tag = SymTagUDT;
174 sym->kind = kind;
175 sym->size = size;
176 if (typename)
178 sym->hash_elt.name = pool_strdup(&module->pool, typename);
179 hash_table_add(&module->ht_types, &sym->hash_elt);
180 } else sym->hash_elt.name = NULL;
181 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
182 symt_add_type(module, &sym->symt);
184 return sym;
187 BOOL symt_set_udt_size(struct module* module, struct symt_udt* udt, unsigned size)
189 assert(udt->symt.tag == SymTagUDT);
190 if (vector_length(&udt->vchildren) != 0)
192 if (udt->size != size)
193 FIXME_(dbghelp_symt)("Changing size for %s from %u to %u\n",
194 udt->hash_elt.name, udt->size, size);
195 return TRUE;
197 udt->size = size;
198 return TRUE;
201 /******************************************************************
202 * symt_add_udt_element
204 * add an element to a udt (struct, class, union)
205 * the size & offset parameters are expressed in bits (not bytes) so that
206 * we can mix in the single call bytes aligned elements (regular fields) and
207 * the others (bit fields)
209 BOOL symt_add_udt_element(struct module* module, struct symt_udt* udt_type,
210 const char* name, struct symt* elt_type,
211 unsigned offset, unsigned size)
213 struct symt_data* m;
214 struct symt** p;
216 assert(udt_type->symt.tag == SymTagUDT);
218 TRACE_(dbghelp_symt)("Adding %s to UDT %s\n", name, udt_type->hash_elt.name);
219 if (name)
221 unsigned int i;
222 for (i=0; i<vector_length(&udt_type->vchildren); i++)
224 m = *(struct symt_data**)vector_at(&udt_type->vchildren, i);
225 assert(m);
226 assert(m->symt.tag == SymTagData);
227 if (strcmp(m->hash_elt.name, name) == 0)
228 return TRUE;
232 if ((m = pool_alloc(&module->pool, sizeof(*m))) == NULL) return FALSE;
233 memset(m, 0, sizeof(*m));
234 m->symt.tag = SymTagData;
235 m->hash_elt.name = name ? pool_strdup(&module->pool, name) : "";
236 m->hash_elt.next = NULL;
238 m->kind = DataIsMember;
239 m->container = &udt_type->symt;
240 m->type = elt_type;
241 m->u.member.offset = offset;
242 m->u.member.length = ((offset & 7) || (size & 7)) ? size : 0;
243 p = vector_add(&udt_type->vchildren, &module->pool);
244 *p = &m->symt;
246 return TRUE;
249 struct symt_enum* symt_new_enum(struct module* module, const char* typename,
250 struct symt* basetype)
252 struct symt_enum* sym;
254 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
256 sym->symt.tag = SymTagEnum;
257 sym->name = (typename) ? pool_strdup(&module->pool, typename) : NULL;
258 sym->base_type = basetype;
259 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
261 return sym;
264 BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type,
265 const char* name, int value)
267 struct symt_data* e;
268 struct symt** p;
270 assert(enum_type->symt.tag == SymTagEnum);
271 e = pool_alloc(&module->pool, sizeof(*e));
272 if (e == NULL) return FALSE;
274 e->symt.tag = SymTagData;
275 e->hash_elt.name = pool_strdup(&module->pool, name);
276 e->hash_elt.next = NULL;
277 e->kind = DataIsConstant;
278 e->container = &enum_type->symt;
279 e->type = enum_type->base_type;
280 e->u.value.n1.n2.vt = VT_I4;
281 e->u.value.n1.n2.n3.lVal = value;
283 p = vector_add(&enum_type->vchildren, &module->pool);
284 if (!p) return FALSE; /* FIXME we leak e */
285 *p = &e->symt;
287 return TRUE;
290 struct symt_array* symt_new_array(struct module* module, int min, int max,
291 struct symt* base, struct symt* index)
293 struct symt_array* sym;
295 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
297 sym->symt.tag = SymTagArrayType;
298 sym->start = min;
299 sym->end = max;
300 sym->base_type = base;
301 sym->index_type = index;
302 symt_add_type(module, &sym->symt);
304 return sym;
307 static inline DWORD symt_array_count(struct module* module, const struct symt_array* array)
309 if (array->end < 0)
311 DWORD64 elem_size;
312 /* One could want to also set the array->end field in array, but we won't do it
313 * as long as all the get_type() helpers use const objects
315 if (symt_get_info(module, array->base_type, TI_GET_LENGTH, &elem_size) && elem_size)
316 return -array->end / (DWORD)elem_size;
317 return 0;
319 return array->end - array->start + 1;
322 struct symt_function_signature* symt_new_function_signature(struct module* module,
323 struct symt* ret_type,
324 enum CV_call_e call_conv)
326 struct symt_function_signature* sym;
328 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
330 sym->symt.tag = SymTagFunctionType;
331 sym->rettype = ret_type;
332 vector_init(&sym->vchildren, sizeof(struct symt*), 4);
333 sym->call_conv = call_conv;
334 symt_add_type(module, &sym->symt);
336 return sym;
339 BOOL symt_add_function_signature_parameter(struct module* module,
340 struct symt_function_signature* sig_type,
341 struct symt* param)
343 struct symt** p;
344 struct symt_function_arg_type* arg;
346 assert(sig_type->symt.tag == SymTagFunctionType);
347 arg = pool_alloc(&module->pool, sizeof(*arg));
348 if (!arg) return FALSE;
349 arg->symt.tag = SymTagFunctionArgType;
350 arg->arg_type = param;
351 arg->container = &sig_type->symt;
352 p = vector_add(&sig_type->vchildren, &module->pool);
353 if (!p) return FALSE; /* FIXME we leak arg */
354 *p = &arg->symt;
356 return TRUE;
359 struct symt_pointer* symt_new_pointer(struct module* module, struct symt* ref_type)
361 struct symt_pointer* sym;
363 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
365 sym->symt.tag = SymTagPointerType;
366 sym->pointsto = ref_type;
367 symt_add_type(module, &sym->symt);
369 return sym;
372 struct symt_typedef* symt_new_typedef(struct module* module, struct symt* ref,
373 const char* name)
375 struct symt_typedef* sym;
377 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
379 sym->symt.tag = SymTagTypedef;
380 sym->type = ref;
381 sym->hash_elt.name = pool_strdup(&module->pool, name);
382 hash_table_add(&module->ht_types, &sym->hash_elt);
383 symt_add_type(module, &sym->symt);
385 return sym;
388 /******************************************************************
389 * SymEnumTypes (DBGHELP.@)
392 BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
393 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
394 PVOID UserContext)
396 struct module_pair pair;
397 char buffer[sizeof(SYMBOL_INFO) + 256];
398 SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
399 const char* tmp;
400 struct symt* type;
401 DWORD64 size;
402 unsigned int i;
404 TRACE("(%p %s %p %p)\n",
405 hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
406 UserContext);
408 if (!(pair.pcs = process_find_by_handle(hProcess))) return FALSE;
409 pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
410 if (!module_get_debug(&pair)) return FALSE;
412 sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
413 sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
415 for (i=0; i<vector_length(&pair.effective->vtypes); i++)
417 type = *(struct symt**)vector_at(&pair.effective->vtypes, i);
418 sym_info->TypeIndex = symt_ptr2index(pair.effective, type);
419 sym_info->info = 0; /* FIXME */
420 symt_get_info(pair.effective, type, TI_GET_LENGTH, &size);
421 sym_info->Size = size;
422 sym_info->ModBase = pair.requested->module.BaseOfImage;
423 sym_info->Flags = 0; /* FIXME */
424 sym_info->Value = 0; /* FIXME */
425 sym_info->Address = 0; /* FIXME */
426 sym_info->Register = 0; /* FIXME */
427 sym_info->Scope = 0; /* FIXME */
428 sym_info->Tag = type->tag;
429 tmp = symt_get_name(type);
430 if (tmp)
432 sym_info->NameLen = min(strlen(tmp),sym_info->MaxNameLen-1);
433 memcpy(sym_info->Name, tmp, sym_info->NameLen);
434 sym_info->Name[sym_info->NameLen] = '\0';
436 else
437 sym_info->Name[sym_info->NameLen = 0] = '\0';
438 if (!EnumSymbolsCallback(sym_info, sym_info->Size, UserContext)) break;
440 return TRUE;
443 struct enum_types_AtoW
445 char buffer[sizeof(SYMBOL_INFOW) + 256 * sizeof(WCHAR)];
446 void* user;
447 PSYM_ENUMERATESYMBOLS_CALLBACKW callback;
450 static BOOL CALLBACK enum_types_AtoW(PSYMBOL_INFO si, ULONG addr, PVOID _et)
452 struct enum_types_AtoW* et = _et;
453 SYMBOL_INFOW* siW = (SYMBOL_INFOW*)et->buffer;
455 copy_symbolW(siW, si);
456 return et->callback(siW, addr, et->user);
459 /******************************************************************
460 * SymEnumTypesW (DBGHELP.@)
463 BOOL WINAPI SymEnumTypesW(HANDLE hProcess, ULONG64 BaseOfDll,
464 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
465 PVOID UserContext)
467 struct enum_types_AtoW et;
469 et.callback = EnumSymbolsCallback;
470 et.user = UserContext;
472 return SymEnumTypes(hProcess, BaseOfDll, enum_types_AtoW, &et);
475 /******************************************************************
476 * symt_get_info
478 * Retrieves information about a symt (either symbol or type)
480 BOOL symt_get_info(struct module* module, const struct symt* type,
481 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo)
483 unsigned len;
485 if (!type) return FALSE;
487 /* helper to typecast pInfo to its expected type (_t) */
488 #define X(_t) (*((_t*)pInfo))
490 switch (req)
492 case TI_FINDCHILDREN:
494 const struct vector* v;
495 struct symt** pt;
496 unsigned i;
497 TI_FINDCHILDREN_PARAMS* tifp = pInfo;
499 switch (type->tag)
501 case SymTagUDT: v = &((const struct symt_udt*)type)->vchildren; break;
502 case SymTagEnum: v = &((const struct symt_enum*)type)->vchildren; break;
503 case SymTagFunctionType: v = &((const struct symt_function_signature*)type)->vchildren; break;
504 case SymTagFunction: v = &((const struct symt_function*)type)->vchildren; break;
505 default:
506 FIXME("Unsupported sym-tag %s for find-children\n",
507 symt_get_tag_str(type->tag));
508 return FALSE;
510 for (i = 0; i < tifp->Count; i++)
512 if (!(pt = vector_at(v, tifp->Start + i))) return FALSE;
513 tifp->ChildId[i] = symt_ptr2index(module, *pt);
516 break;
518 case TI_GET_ADDRESS:
519 switch (type->tag)
521 case SymTagData:
522 switch (((const struct symt_data*)type)->kind)
524 case DataIsGlobal:
525 case DataIsFileStatic:
526 X(ULONG64) = ((const struct symt_data*)type)->u.var.offset;
527 break;
528 default: return FALSE;
530 break;
531 case SymTagFunction:
532 X(ULONG64) = ((const struct symt_function*)type)->address;
533 break;
534 case SymTagPublicSymbol:
535 X(ULONG64) = ((const struct symt_public*)type)->address;
536 break;
537 case SymTagFuncDebugStart:
538 case SymTagFuncDebugEnd:
539 case SymTagLabel:
540 if (!symt_get_info(module, ((const struct symt_hierarchy_point*)type)->parent,
541 req, pInfo))
542 return FALSE;
543 X(ULONG64) += ((const struct symt_hierarchy_point*)type)->loc.offset;
544 break;
545 case SymTagThunk:
546 X(ULONG64) = ((const struct symt_thunk*)type)->address;
547 break;
548 case SymTagCompiland:
549 X(ULONG64) = ((const struct symt_compiland*)type)->address;
550 break;
551 default:
552 FIXME("Unsupported sym-tag %s for get-address\n",
553 symt_get_tag_str(type->tag));
554 return FALSE;
556 break;
558 case TI_GET_BASETYPE:
559 switch (type->tag)
561 case SymTagBaseType:
562 X(DWORD) = ((const struct symt_basic*)type)->bt;
563 break;
564 case SymTagEnum:
565 X(DWORD) = btInt;
566 break;
567 default:
568 return FALSE;
570 break;
572 case TI_GET_BITPOSITION:
573 if (type->tag == SymTagData &&
574 ((const struct symt_data*)type)->kind == DataIsMember &&
575 ((const struct symt_data*)type)->u.member.length != 0)
576 X(DWORD) = ((const struct symt_data*)type)->u.member.offset & 7;
577 else return FALSE;
578 break;
580 case TI_GET_CHILDRENCOUNT:
581 switch (type->tag)
583 case SymTagUDT:
584 X(DWORD) = vector_length(&((const struct symt_udt*)type)->vchildren);
585 break;
586 case SymTagEnum:
587 X(DWORD) = vector_length(&((const struct symt_enum*)type)->vchildren);
588 break;
589 case SymTagFunctionType:
590 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
591 break;
592 case SymTagFunction:
593 X(DWORD) = vector_length(&((const struct symt_function*)type)->vchildren);
594 break;
595 case SymTagPointerType: /* MS does it that way */
596 case SymTagArrayType: /* MS does it that way */
597 case SymTagThunk: /* MS does it that way */
598 X(DWORD) = 0;
599 break;
600 default:
601 FIXME("Unsupported sym-tag %s for get-children-count\n",
602 symt_get_tag_str(type->tag));
603 /* fall through */
604 case SymTagData:
605 case SymTagPublicSymbol:
606 case SymTagBaseType:
607 return FALSE;
609 break;
611 case TI_GET_COUNT:
612 switch (type->tag)
614 case SymTagArrayType:
615 X(DWORD) = symt_array_count(module, (const struct symt_array*)type);
616 break;
617 case SymTagFunctionType:
618 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
619 * should be included in this value (and not in GET_CHILDREN_COUNT)
621 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
622 break;
623 default: return FALSE;
625 break;
627 case TI_GET_DATAKIND:
628 if (type->tag != SymTagData) return FALSE;
629 X(DWORD) = ((const struct symt_data*)type)->kind;
630 break;
632 case TI_GET_LENGTH:
633 switch (type->tag)
635 case SymTagBaseType:
636 X(DWORD64) = ((const struct symt_basic*)type)->size;
637 break;
638 case SymTagFunction:
639 X(DWORD64) = ((const struct symt_function*)type)->size;
640 break;
641 case SymTagPointerType:
642 X(DWORD64) = sizeof(void*);
643 break;
644 case SymTagUDT:
645 X(DWORD64) = ((const struct symt_udt*)type)->size;
646 break;
647 case SymTagEnum:
648 X(DWORD64) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
649 break;
650 case SymTagData:
651 if (((const struct symt_data*)type)->kind != DataIsMember ||
652 !((const struct symt_data*)type)->u.member.length)
653 return FALSE;
654 X(DWORD64) = ((const struct symt_data*)type)->u.member.length;
655 break;
656 case SymTagArrayType:
657 if (!symt_get_info(module, ((const struct symt_array*)type)->base_type,
658 TI_GET_LENGTH, pInfo))
659 return FALSE;
660 X(DWORD64) *= symt_array_count(module, (const struct symt_array*)type);
661 break;
662 case SymTagPublicSymbol:
663 X(DWORD64) = ((const struct symt_public*)type)->size;
664 break;
665 case SymTagTypedef:
666 return symt_get_info(module, ((const struct symt_typedef*)type)->type, TI_GET_LENGTH, pInfo);
667 case SymTagThunk:
668 X(DWORD64) = ((const struct symt_thunk*)type)->size;
669 break;
670 case SymTagLabel:
671 X(DWORD64) = 0;
672 break;
673 default:
674 FIXME("Unsupported sym-tag %s for get-length\n",
675 symt_get_tag_str(type->tag));
676 /* fall through */
677 case SymTagFunctionType:
678 return 0;
680 break;
682 case TI_GET_LEXICALPARENT:
683 switch (type->tag)
685 case SymTagBlock:
686 X(DWORD) = symt_ptr2index(module, ((const struct symt_block*)type)->container);
687 break;
688 case SymTagData:
689 X(DWORD) = symt_ptr2index(module, ((const struct symt_data*)type)->container);
690 break;
691 case SymTagFunction:
692 X(DWORD) = symt_ptr2index(module, ((const struct symt_function*)type)->container);
693 break;
694 case SymTagThunk:
695 X(DWORD) = symt_ptr2index(module, ((const struct symt_thunk*)type)->container);
696 break;
697 case SymTagFunctionArgType:
698 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_arg_type*)type)->container);
699 break;
700 default:
701 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
702 symt_get_tag_str(type->tag));
703 return FALSE;
705 break;
707 case TI_GET_NESTED:
708 switch (type->tag)
710 case SymTagUDT:
711 case SymTagEnum:
712 X(DWORD) = 0;
713 break;
714 default:
715 return FALSE;
717 break;
719 case TI_GET_OFFSET:
720 switch (type->tag)
722 case SymTagData:
723 switch (((const struct symt_data*)type)->kind)
725 case DataIsParam:
726 case DataIsLocal:
727 X(ULONG) = ((const struct symt_data*)type)->u.var.offset;
728 break;
729 case DataIsMember:
730 X(ULONG) = ((const struct symt_data*)type)->u.member.offset >> 3;
731 break;
732 default:
733 FIXME("Unknown kind (%u) for get-offset\n",
734 ((const struct symt_data*)type)->kind);
735 return FALSE;
737 break;
738 default:
739 FIXME("Unsupported sym-tag %s for get-offset\n",
740 symt_get_tag_str(type->tag));
741 return FALSE;
743 break;
745 case TI_GET_SYMNAME:
747 const char* name = symt_get_name(type);
748 if (!name) return FALSE;
749 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
750 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
751 if (!X(WCHAR*)) return FALSE;
752 MultiByteToWideChar(CP_ACP, 0, name, -1, X(WCHAR*), len);
754 break;
756 case TI_GET_SYMTAG:
757 X(DWORD) = type->tag;
758 break;
760 case TI_GET_TYPE:
761 case TI_GET_TYPEID:
762 switch (type->tag)
764 /* hierarchical => hierarchical */
765 case SymTagArrayType:
766 X(DWORD) = symt_ptr2index(module, ((const struct symt_array*)type)->base_type);
767 break;
768 case SymTagPointerType:
769 X(DWORD) = symt_ptr2index(module, ((const struct symt_pointer*)type)->pointsto);
770 break;
771 case SymTagFunctionType:
772 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_signature*)type)->rettype);
773 break;
774 case SymTagTypedef:
775 X(DWORD) = symt_ptr2index(module, ((const struct symt_typedef*)type)->type);
776 break;
777 /* lexical => hierarchical */
778 case SymTagData:
779 X(DWORD) = symt_ptr2index(module, ((const struct symt_data*)type)->type);
780 break;
781 case SymTagFunction:
782 X(DWORD) = symt_ptr2index(module, ((const struct symt_function*)type)->type);
783 break;
784 case SymTagEnum:
785 X(DWORD) = symt_ptr2index(module, ((const struct symt_enum*)type)->base_type);
786 break;
787 case SymTagFunctionArgType:
788 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_arg_type*)type)->arg_type);
789 break;
790 default:
791 FIXME("Unsupported sym-tag %s for get-type\n",
792 symt_get_tag_str(type->tag));
793 case SymTagPublicSymbol:
794 case SymTagThunk:
795 case SymTagLabel:
796 return FALSE;
798 break;
800 case TI_GET_UDTKIND:
801 if (type->tag != SymTagUDT) return FALSE;
802 X(DWORD) = ((const struct symt_udt*)type)->kind;
803 break;
805 case TI_GET_VALUE:
806 if (type->tag != SymTagData) return FALSE;
807 switch (((const struct symt_data*)type)->kind)
809 case DataIsConstant: X(VARIANT) = ((const struct symt_data*)type)->u.value; break;
810 case DataIsLocal:
811 case DataIsParam:
813 struct location loc = ((const struct symt_data*)type)->u.var;
814 unsigned i;
815 struct module_format* modfmt;
817 if (loc.kind < loc_user) return FALSE;
818 for (i = 0; i < DFI_LAST; i++)
820 modfmt = module->format_info[i];
821 if (modfmt && modfmt->loc_compute)
823 modfmt->loc_compute(module->process, modfmt,
824 (const struct symt_function*)((const struct symt_data*)type)->container, &loc);
825 break;
828 if (loc.kind != loc_absolute) return FALSE;
829 X(VARIANT).n1.n2.vt = VT_UI4; /* FIXME */
830 X(VARIANT).n1.n2.n3.uiVal = loc.offset;
832 break;
833 default: return FALSE;
835 break;
837 case TI_GET_CALLING_CONVENTION:
838 if (type->tag != SymTagFunctionType) return FALSE;
839 if (((const struct symt_function_signature*)type)->call_conv == -1)
841 FIXME("No support for calling convention for this signature\n");
842 X(DWORD) = CV_CALL_FAR_C; /* FIXME */
844 else X(DWORD) = ((const struct symt_function_signature*)type)->call_conv;
845 break;
846 case TI_GET_ARRAYINDEXTYPEID:
847 if (type->tag != SymTagArrayType) return FALSE;
848 X(DWORD) = symt_ptr2index(module, ((const struct symt_array*)type)->index_type);
849 break;
851 case TI_GET_CLASSPARENTID:
852 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
853 * belong to a parent class
855 return FALSE;
857 #undef X
859 case TI_GET_ADDRESSOFFSET:
860 case TI_GET_SYMINDEX:
861 case TI_GET_THISADJUST:
862 case TI_GET_VIRTUALBASECLASS:
863 case TI_GET_VIRTUALBASEPOINTEROFFSET:
864 case TI_GET_VIRTUALTABLESHAPEID:
865 case TI_IS_EQUIV_TO:
866 FIXME("Unsupported GetInfo request (%u)\n", req);
867 return FALSE;
868 default:
869 FIXME("Unknown GetInfo request (%u)\n", req);
870 return FALSE;
873 return TRUE;
876 /******************************************************************
877 * SymGetTypeInfo (DBGHELP.@)
880 BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
881 ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType,
882 PVOID pInfo)
884 struct module_pair pair;
886 pair.pcs = process_find_by_handle(hProcess);
887 if (!pair.pcs) return FALSE;
889 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
890 if (!module_get_debug(&pair))
892 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
893 return FALSE;
896 return symt_get_info(pair.effective, symt_index2ptr(pair.effective, TypeId), GetType, pInfo);
899 /******************************************************************
900 * SymGetTypeFromName (DBGHELP.@)
903 BOOL WINAPI SymGetTypeFromName(HANDLE hProcess, ULONG64 BaseOfDll,
904 PCSTR Name, PSYMBOL_INFO Symbol)
906 struct process* pcs = process_find_by_handle(hProcess);
907 struct module_pair pair;
908 struct symt* type;
910 if (!pcs) return FALSE;
911 pair.requested = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
912 if (!module_get_debug(&pair)) return FALSE;
913 type = symt_find_type_by_name(pair.effective, SymTagNull, Name);
914 if (!type) return FALSE;
915 Symbol->TypeIndex = symt_ptr2index(pair.effective, type);
917 return TRUE;