dbghelp: Expose no children in SymGetTypeInfo() for some SymTags.
[wine.git] / dlls / dbghelp / type.c
blob709a4bc851b9822155c9de65ba6c53a7dd42e8c3
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 <stdlib.h>
28 #include <stdarg.h>
29 #include <assert.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winnls.h"
34 #include "wine/debug.h"
35 #include "dbghelp_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
38 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt);
40 static const char* symt_get_tag_str(DWORD tag)
42 switch (tag)
44 case SymTagNull: return "SymTagNull";
45 case SymTagExe: return "SymTagExe";
46 case SymTagCompiland: return "SymTagCompiland";
47 case SymTagCompilandDetails: return "SymTagCompilandDetails";
48 case SymTagCompilandEnv: return "SymTagCompilandEnv";
49 case SymTagFunction: return "SymTagFunction";
50 case SymTagBlock: return "SymTagBlock";
51 case SymTagData: return "SymTagData";
52 case SymTagAnnotation: return "SymTagAnnotation";
53 case SymTagLabel: return "SymTagLabel";
54 case SymTagPublicSymbol: return "SymTagPublicSymbol";
55 case SymTagUDT: return "SymTagUDT";
56 case SymTagEnum: return "SymTagEnum";
57 case SymTagFunctionType: return "SymTagFunctionType";
58 case SymTagPointerType: return "SymTagPointerType";
59 case SymTagArrayType: return "SymTagArrayType";
60 case SymTagBaseType: return "SymTagBaseType";
61 case SymTagTypedef: return "SymTagTypedef,";
62 case SymTagBaseClass: return "SymTagBaseClass";
63 case SymTagFriend: return "SymTagFriend";
64 case SymTagFunctionArgType: return "SymTagFunctionArgType,";
65 case SymTagFuncDebugStart: return "SymTagFuncDebugStart";
66 case SymTagFuncDebugEnd: return "SymTagFuncDebugEnd";
67 case SymTagUsingNamespace: return "SymTagUsingNamespace";
68 case SymTagVTableShape: return "SymTagVTableShape";
69 case SymTagVTable: return "SymTagVTable";
70 case SymTagCustom: return "SymTagCustom";
71 case SymTagThunk: return "SymTagThunk";
72 case SymTagCustomType: return "SymTagCustomType";
73 case SymTagManagedType: return "SymTagManagedType";
74 case SymTagDimension: return "SymTagDimension";
75 case SymTagCallSite: return "SymTagCallSite";
76 case SymTagInlineSite: return "SymTagInlineSite";
77 case SymTagBaseInterface: return "SymTagBaseInterface";
78 case SymTagVectorType: return "SymTagVectorType";
79 case SymTagMatrixType: return "SymTagMatrixType";
80 case SymTagHLSLType: return "SymTagHLSLType";
81 case SymTagCaller: return "SymTagCaller";
82 case SymTagCallee: return "SymTagCallee";
83 case SymTagExport: return "SymTagExport";
84 case SymTagHeapAllocationSite: return "SymTagHeapAllocationSite";
85 case SymTagCoffGroup: return "SymTagCoffGroup";
86 case SymTagInlinee: return "SymTagInlinee";
87 default: return "---";
91 const char* symt_get_name(const struct symt* sym)
93 switch (sym->tag)
95 /* lexical tree */
96 case SymTagData: return ((const struct symt_data*)sym)->hash_elt.name;
97 case SymTagFunction: return ((const struct symt_function*)sym)->hash_elt.name;
98 case SymTagPublicSymbol: return ((const struct symt_public*)sym)->hash_elt.name;
99 case SymTagBaseType: return ((const struct symt_basic*)sym)->hash_elt.name;
100 case SymTagLabel: return ((const struct symt_hierarchy_point*)sym)->hash_elt.name;
101 case SymTagThunk: return ((const struct symt_thunk*)sym)->hash_elt.name;
102 /* hierarchy tree */
103 case SymTagEnum: return ((const struct symt_enum*)sym)->hash_elt.name;
104 case SymTagTypedef: return ((const struct symt_typedef*)sym)->hash_elt.name;
105 case SymTagUDT: return ((const struct symt_udt*)sym)->hash_elt.name;
106 case SymTagCompiland: return source_get(((const struct symt_compiland*)sym)->container->module,
107 ((const struct symt_compiland*)sym)->source);
108 default:
109 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym->tag));
110 /* fall through */
111 case SymTagArrayType:
112 case SymTagPointerType:
113 case SymTagFunctionType:
114 return NULL;
118 WCHAR* symt_get_nameW(const struct symt* sym)
120 const char* name = symt_get_name(sym);
121 WCHAR* nameW;
122 DWORD sz;
124 if (!name) return NULL;
125 sz = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
126 if ((nameW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
127 MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, sz);
128 return nameW;
131 BOOL symt_get_address(const struct symt* type, ULONG64* addr)
133 switch (type->tag)
135 case SymTagData:
136 switch (((const struct symt_data*)type)->kind)
138 case DataIsGlobal:
139 case DataIsFileStatic:
140 *addr = ((const struct symt_data*)type)->u.var.offset;
141 break;
142 default: return FALSE;
144 break;
145 case SymTagBlock:
146 *addr = ((const struct symt_block*)type)->address;
147 break;
148 case SymTagFunction:
149 *addr = ((const struct symt_function*)type)->address;
150 break;
151 case SymTagPublicSymbol:
152 *addr = ((const struct symt_public*)type)->address;
153 break;
154 case SymTagFuncDebugStart:
155 case SymTagFuncDebugEnd:
156 case SymTagLabel:
157 if (!((const struct symt_hierarchy_point*)type)->parent ||
158 !symt_get_address(((const struct symt_hierarchy_point*)type)->parent, addr))
159 return FALSE;
160 *addr += ((const struct symt_hierarchy_point*)type)->loc.offset;
161 break;
162 case SymTagThunk:
163 *addr = ((const struct symt_thunk*)type)->address;
164 break;
165 default:
166 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type->tag));
167 /* fall through */
168 case SymTagExe:
169 case SymTagCompiland:
170 return FALSE;
172 return TRUE;
175 static struct symt* symt_find_type_by_name(const struct module* module,
176 enum SymTagEnum sym_tag,
177 const char* typename)
179 void* ptr;
180 struct symt_ht* type;
181 struct hash_table_iter hti;
183 assert(typename);
184 assert(module);
186 hash_table_iter_init(&module->ht_types, &hti, typename);
187 while ((ptr = hash_table_iter_up(&hti)))
189 type = CONTAINING_RECORD(ptr, struct symt_ht, hash_elt);
191 if ((sym_tag == SymTagNull || type->symt.tag == sym_tag) &&
192 type->hash_elt.name && !strcmp(type->hash_elt.name, typename))
193 return &type->symt;
195 SetLastError(ERROR_INVALID_NAME); /* FIXME ?? */
196 return NULL;
199 static void symt_add_type(struct module* module, struct symt* symt)
201 struct symt** p;
202 p = vector_add(&module->vtypes, &module->pool);
203 assert(p);
204 *p = symt;
207 struct symt_basic* symt_new_basic(struct module* module, enum BasicType bt,
208 const char* typename, unsigned size)
210 struct symt_basic* sym;
212 if (typename)
214 sym = (struct symt_basic*)symt_find_type_by_name(module, SymTagBaseType,
215 typename);
216 if (sym && sym->bt == bt && sym->size == size)
217 return sym;
219 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
221 sym->symt.tag = SymTagBaseType;
222 if (typename)
224 sym->hash_elt.name = pool_strdup(&module->pool, typename);
225 hash_table_add(&module->ht_types, &sym->hash_elt);
226 } else sym->hash_elt.name = NULL;
227 sym->bt = bt;
228 sym->size = size;
229 symt_add_type(module, &sym->symt);
231 return sym;
234 struct symt_udt* symt_new_udt(struct module* module, const char* typename,
235 unsigned size, enum UdtKind kind)
237 struct symt_udt* sym;
239 TRACE_(dbghelp_symt)("Adding udt %s:%s\n",
240 debugstr_w(module->modulename), typename);
241 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
243 sym->symt.tag = SymTagUDT;
244 sym->kind = kind;
245 sym->size = size;
246 if (typename)
248 sym->hash_elt.name = pool_strdup(&module->pool, typename);
249 hash_table_add(&module->ht_types, &sym->hash_elt);
250 } else sym->hash_elt.name = NULL;
251 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
252 symt_add_type(module, &sym->symt);
254 return sym;
257 BOOL symt_set_udt_size(struct module* module, struct symt_udt* udt, unsigned size)
259 assert(udt->symt.tag == SymTagUDT);
260 if (vector_length(&udt->vchildren) != 0)
262 if (udt->size != size)
263 FIXME_(dbghelp_symt)("Changing size for %s from %u to %u\n",
264 udt->hash_elt.name, udt->size, size);
265 return TRUE;
267 udt->size = size;
268 return TRUE;
271 /******************************************************************
272 * symt_add_udt_element
274 * add an element to a udt (struct, class, union)
275 * the size & offset parameters are expressed in bits (not bytes) so that
276 * we can mix in the single call bytes aligned elements (regular fields) and
277 * the others (bit fields)
279 BOOL symt_add_udt_element(struct module* module, struct symt_udt* udt_type,
280 const char* name, struct symt* elt_type,
281 unsigned offset, unsigned bit_offset, unsigned bit_size)
283 struct symt_data* m;
284 struct symt** p;
286 assert(udt_type->symt.tag == SymTagUDT);
288 TRACE_(dbghelp_symt)("Adding %s to UDT %s\n", name, udt_type->hash_elt.name);
289 if (name)
291 unsigned int i;
292 for (i=0; i<vector_length(&udt_type->vchildren); i++)
294 m = *(struct symt_data**)vector_at(&udt_type->vchildren, i);
295 assert(m);
296 assert(m->symt.tag == SymTagData);
297 if (strcmp(m->hash_elt.name, name) == 0)
298 return TRUE;
302 if ((m = pool_alloc(&module->pool, sizeof(*m))) == NULL) return FALSE;
303 memset(m, 0, sizeof(*m));
304 m->symt.tag = SymTagData;
305 m->hash_elt.name = name ? pool_strdup(&module->pool, name) : "";
306 m->hash_elt.next = NULL;
308 m->kind = DataIsMember;
309 m->container = &udt_type->symt;
310 m->type = elt_type;
311 m->u.member.offset = offset;
312 m->u.member.bit_offset = bit_offset;
313 m->u.member.bit_length = bit_size;
314 p = vector_add(&udt_type->vchildren, &module->pool);
315 *p = &m->symt;
317 return TRUE;
320 struct symt_enum* symt_new_enum(struct module* module, const char* typename,
321 struct symt* basetype)
323 struct symt_enum* sym;
325 TRACE_(dbghelp_symt)("Adding enum %s:%s\n",
326 debugstr_w(module->modulename), typename);
327 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
329 sym->symt.tag = SymTagEnum;
330 if (typename)
332 sym->hash_elt.name = pool_strdup(&module->pool, typename);
333 hash_table_add(&module->ht_types, &sym->hash_elt);
334 } else sym->hash_elt.name = NULL;
335 sym->base_type = basetype;
336 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
337 symt_add_type(module, &sym->symt);
339 return sym;
342 BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type,
343 const char* name, int value)
345 struct symt_data* e;
346 struct symt** p;
348 assert(enum_type->symt.tag == SymTagEnum);
349 e = pool_alloc(&module->pool, sizeof(*e));
350 if (e == NULL) return FALSE;
352 e->symt.tag = SymTagData;
353 e->hash_elt.name = pool_strdup(&module->pool, name);
354 e->hash_elt.next = NULL;
355 e->kind = DataIsConstant;
356 e->container = &enum_type->symt;
357 e->type = enum_type->base_type;
358 e->u.value.n1.n2.vt = VT_I4;
359 e->u.value.n1.n2.n3.lVal = value;
361 p = vector_add(&enum_type->vchildren, &module->pool);
362 if (!p) return FALSE; /* FIXME we leak e */
363 *p = &e->symt;
365 return TRUE;
368 struct symt_array* symt_new_array(struct module* module, int min, DWORD cnt,
369 struct symt* base, struct symt* index)
371 struct symt_array* sym;
373 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
375 sym->symt.tag = SymTagArrayType;
376 sym->start = min;
377 sym->count = cnt;
378 sym->base_type = base;
379 sym->index_type = index;
380 symt_add_type(module, &sym->symt);
382 return sym;
385 struct symt_function_signature* symt_new_function_signature(struct module* module,
386 struct symt* ret_type,
387 enum CV_call_e call_conv)
389 struct symt_function_signature* sym;
391 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
393 sym->symt.tag = SymTagFunctionType;
394 sym->rettype = ret_type;
395 vector_init(&sym->vchildren, sizeof(struct symt*), 4);
396 sym->call_conv = call_conv;
397 symt_add_type(module, &sym->symt);
399 return sym;
402 BOOL symt_add_function_signature_parameter(struct module* module,
403 struct symt_function_signature* sig_type,
404 struct symt* param)
406 struct symt** p;
407 struct symt_function_arg_type* arg;
409 assert(sig_type->symt.tag == SymTagFunctionType);
410 arg = pool_alloc(&module->pool, sizeof(*arg));
411 if (!arg) return FALSE;
412 arg->symt.tag = SymTagFunctionArgType;
413 arg->arg_type = param;
414 p = vector_add(&sig_type->vchildren, &module->pool);
415 if (!p) return FALSE; /* FIXME we leak arg */
416 *p = &arg->symt;
418 return TRUE;
421 struct symt_pointer* symt_new_pointer(struct module* module, struct symt* ref_type, ULONG_PTR size)
423 struct symt_pointer* sym;
425 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
427 sym->symt.tag = SymTagPointerType;
428 sym->pointsto = ref_type;
429 sym->size = size;
430 symt_add_type(module, &sym->symt);
432 return sym;
435 struct symt_typedef* symt_new_typedef(struct module* module, struct symt* ref,
436 const char* name)
438 struct symt_typedef* sym;
440 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
442 sym->symt.tag = SymTagTypedef;
443 sym->type = ref;
444 sym->hash_elt.name = pool_strdup(&module->pool, name);
445 hash_table_add(&module->ht_types, &sym->hash_elt);
446 symt_add_type(module, &sym->symt);
448 return sym;
451 /******************************************************************
452 * SymEnumTypes (DBGHELP.@)
455 BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
456 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
457 PVOID UserContext)
459 struct module_pair pair;
460 char buffer[sizeof(SYMBOL_INFO) + 256];
461 SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
462 struct symt* type;
463 DWORD64 size;
464 unsigned int i;
466 TRACE("(%p %s %p %p)\n",
467 hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
468 UserContext);
470 if (!(pair.pcs = process_find_by_handle(hProcess))) return FALSE;
471 pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
472 if (!module_get_debug(&pair)) return FALSE;
474 sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
475 sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
477 for (i=0; i<vector_length(&pair.effective->vtypes); i++)
479 type = *(struct symt**)vector_at(&pair.effective->vtypes, i);
480 sym_info->TypeIndex = symt_ptr2index(pair.effective, type);
481 sym_info->Index = 0; /* FIXME */
482 symt_get_info(pair.effective, type, TI_GET_LENGTH, &size);
483 sym_info->Size = size;
484 sym_info->ModBase = pair.requested->module.BaseOfImage;
485 sym_info->Flags = 0; /* FIXME */
486 sym_info->Value = 0; /* FIXME */
487 sym_info->Address = 0; /* FIXME */
488 sym_info->Register = 0; /* FIXME */
489 sym_info->Scope = 0; /* FIXME */
490 sym_info->Tag = type->tag;
491 symbol_setname(sym_info, symt_get_name(type));
492 if (!EnumSymbolsCallback(sym_info, sym_info->Size, UserContext)) break;
494 return TRUE;
497 struct enum_types_AtoW
499 char buffer[sizeof(SYMBOL_INFOW) + 256 * sizeof(WCHAR)];
500 void* user;
501 PSYM_ENUMERATESYMBOLS_CALLBACKW callback;
504 static BOOL CALLBACK enum_types_AtoW(PSYMBOL_INFO si, ULONG size, PVOID _et)
506 struct enum_types_AtoW* et = _et;
507 SYMBOL_INFOW* siW = (SYMBOL_INFOW*)et->buffer;
509 copy_symbolW(siW, si);
510 return et->callback(siW, size, et->user);
513 /******************************************************************
514 * SymEnumTypesW (DBGHELP.@)
517 BOOL WINAPI SymEnumTypesW(HANDLE hProcess, ULONG64 BaseOfDll,
518 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
519 PVOID UserContext)
521 struct enum_types_AtoW et;
523 et.callback = EnumSymbolsCallback;
524 et.user = UserContext;
526 return SymEnumTypes(hProcess, BaseOfDll, enum_types_AtoW, &et);
529 /******************************************************************
530 * symt_get_info
532 * Retrieves information about a symt (either symbol or type)
534 BOOL symt_get_info(struct module* module, const struct symt* type,
535 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo)
537 unsigned len;
539 if (!type) return FALSE;
541 /* helper to typecast pInfo to its expected type (_t) */
542 #define X(_t) (*((_t*)pInfo))
544 switch (req)
546 case TI_FINDCHILDREN:
548 const struct vector* v;
549 struct symt** pt;
550 unsigned i;
551 TI_FINDCHILDREN_PARAMS* tifp = pInfo;
553 switch (type->tag)
555 case SymTagExe: v = &((const struct symt_module*)type)->vchildren; break;
556 case SymTagCompiland: v = &((const struct symt_compiland*)type)->vchildren; break;
557 case SymTagUDT: v = &((const struct symt_udt*)type)->vchildren; break;
558 case SymTagEnum: v = &((const struct symt_enum*)type)->vchildren; break;
559 case SymTagFunctionType: v = &((const struct symt_function_signature*)type)->vchildren; break;
560 case SymTagFunction: v = &((const struct symt_function*)type)->vchildren; break;
561 case SymTagBlock: v = &((const struct symt_block*)type)->vchildren; break;
562 case SymTagPointerType:
563 case SymTagArrayType:
564 case SymTagFunctionArgType:
565 case SymTagThunk:
566 case SymTagLabel:
567 case SymTagFuncDebugStart:
568 case SymTagFuncDebugEnd:
569 case SymTagTypedef:
570 case SymTagBaseType:
571 /* for those, CHILDRENCOUNT returns 0 */
572 return tifp->Count == 0;
573 default:
574 FIXME("Unsupported sym-tag %s for find-children\n",
575 symt_get_tag_str(type->tag));
576 return FALSE;
578 for (i = 0; i < tifp->Count; i++)
580 if (!(pt = vector_at(v, tifp->Start + i))) return FALSE;
581 tifp->ChildId[i] = symt_ptr2index(module, *pt);
584 break;
586 case TI_GET_ADDRESS:
587 return symt_get_address(type, (ULONG64*)pInfo);
589 case TI_GET_BASETYPE:
590 switch (type->tag)
592 case SymTagBaseType:
593 X(DWORD) = ((const struct symt_basic*)type)->bt;
594 break;
595 case SymTagEnum:
596 X(DWORD) = btInt;
597 break;
598 default:
599 return FALSE;
601 break;
603 case TI_GET_BITPOSITION:
604 if (type->tag == SymTagData &&
605 ((const struct symt_data*)type)->kind == DataIsMember &&
606 ((const struct symt_data*)type)->u.member.bit_length != 0)
607 X(DWORD) = ((const struct symt_data*)type)->u.member.bit_offset;
608 else return FALSE;
609 break;
611 case TI_GET_CHILDRENCOUNT:
612 switch (type->tag)
614 case SymTagExe:
615 X(DWORD) = vector_length(&((const struct symt_module*)type)->vchildren);
616 break;
617 case SymTagCompiland:
618 X(DWORD) = vector_length(&((const struct symt_compiland*)type)->vchildren);
619 break;
620 case SymTagUDT:
621 X(DWORD) = vector_length(&((const struct symt_udt*)type)->vchildren);
622 break;
623 case SymTagEnum:
624 X(DWORD) = vector_length(&((const struct symt_enum*)type)->vchildren);
625 break;
626 case SymTagFunctionType:
627 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
628 break;
629 case SymTagFunction:
630 X(DWORD) = vector_length(&((const struct symt_function*)type)->vchildren);
631 break;
632 case SymTagBlock:
633 X(DWORD) = vector_length(&((const struct symt_block*)type)->vchildren);
634 break;
635 /* some SymTag:s return 0 */
636 case SymTagPointerType:
637 case SymTagArrayType:
638 case SymTagFunctionArgType:
639 case SymTagThunk:
640 case SymTagFuncDebugStart:
641 case SymTagFuncDebugEnd:
642 case SymTagLabel:
643 case SymTagTypedef:
644 case SymTagBaseType:
645 X(DWORD) = 0;
646 break;
647 default:
648 FIXME("Unsupported sym-tag %s for get-children-count\n",
649 symt_get_tag_str(type->tag));
650 /* fall through */
651 /* some others return error */
652 case SymTagData:
653 case SymTagPublicSymbol:
654 return FALSE;
656 break;
658 case TI_GET_COUNT:
659 switch (type->tag)
661 case SymTagArrayType:
662 X(DWORD) = ((const struct symt_array*)type)->count;
663 break;
664 case SymTagFunctionType:
665 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
666 * should be included in this value (and not in GET_CHILDREN_COUNT)
668 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
669 break;
670 default: return FALSE;
672 break;
674 case TI_GET_DATAKIND:
675 if (type->tag != SymTagData) return FALSE;
676 X(DWORD) = ((const struct symt_data*)type)->kind;
677 break;
679 case TI_GET_LENGTH:
680 switch (type->tag)
682 case SymTagBaseType:
683 X(DWORD64) = ((const struct symt_basic*)type)->size;
684 break;
685 case SymTagFunction:
686 X(DWORD64) = ((const struct symt_function*)type)->size;
687 break;
688 case SymTagBlock:
689 X(DWORD64) = ((const struct symt_block*)type)->size;
690 break;
691 case SymTagPointerType:
692 X(DWORD64) = ((const struct symt_pointer*)type)->size;
693 break;
694 case SymTagUDT:
695 X(DWORD64) = ((const struct symt_udt*)type)->size;
696 break;
697 case SymTagEnum:
698 if (!symt_get_info(module, ((const struct symt_enum*)type)->base_type, TI_GET_LENGTH, pInfo))
699 return FALSE;
700 break;
701 case SymTagData:
702 if (((const struct symt_data*)type)->kind != DataIsMember ||
703 !((const struct symt_data*)type)->u.member.bit_length)
704 return FALSE;
705 X(DWORD64) = ((const struct symt_data*)type)->u.member.bit_length;
706 break;
707 case SymTagArrayType:
708 if (!symt_get_info(module, ((const struct symt_array*)type)->base_type,
709 TI_GET_LENGTH, pInfo))
710 return FALSE;
711 X(DWORD64) *= ((const struct symt_array*)type)->count;
712 break;
713 case SymTagPublicSymbol:
714 X(DWORD64) = ((const struct symt_public*)type)->size;
715 break;
716 case SymTagTypedef:
717 return symt_get_info(module, ((const struct symt_typedef*)type)->type, TI_GET_LENGTH, pInfo);
718 case SymTagThunk:
719 X(DWORD64) = ((const struct symt_thunk*)type)->size;
720 break;
721 case SymTagLabel:
722 X(DWORD64) = 0;
723 break;
724 default:
725 FIXME("Unsupported sym-tag %s for get-length\n",
726 symt_get_tag_str(type->tag));
727 /* fall through */
728 case SymTagExe:
729 case SymTagCompiland:
730 case SymTagFunctionType:
731 return FALSE;
733 break;
735 case TI_GET_LEXICALPARENT:
736 switch (type->tag)
738 case SymTagCompiland:
739 X(DWORD) = symt_ptr2index(module, &((const struct symt_compiland*)type)->container->symt);
740 break;
741 case SymTagBlock:
742 X(DWORD) = symt_ptr2index(module, ((const struct symt_block*)type)->container);
743 break;
744 case SymTagData:
745 X(DWORD) = symt_ptr2index(module, ((const struct symt_data*)type)->container);
746 break;
747 case SymTagFunction:
748 X(DWORD) = symt_ptr2index(module, ((const struct symt_function*)type)->container);
749 break;
750 case SymTagThunk:
751 X(DWORD) = symt_ptr2index(module, ((const struct symt_thunk*)type)->container);
752 break;
753 case SymTagUDT:
754 case SymTagEnum:
755 case SymTagFunctionArgType:
756 X(DWORD) = symt_ptr2index(module, &module->top->symt);
757 break;
758 default:
759 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
760 symt_get_tag_str(type->tag));
761 /* fall through */
762 case SymTagExe:
763 return FALSE;
765 break;
767 case TI_GET_NESTED:
768 switch (type->tag)
770 case SymTagUDT:
771 case SymTagEnum:
772 X(DWORD) = 0;
773 break;
774 default:
775 return FALSE;
777 break;
779 case TI_GET_OFFSET:
780 switch (type->tag)
782 case SymTagData:
783 switch (((const struct symt_data*)type)->kind)
785 case DataIsParam:
786 case DataIsLocal:
787 X(ULONG) = ((const struct symt_data*)type)->u.var.offset;
788 break;
789 case DataIsMember:
790 X(ULONG) = ((const struct symt_data*)type)->u.member.offset;
791 break;
792 default:
793 FIXME("Unknown kind (%u) for get-offset\n",
794 ((const struct symt_data*)type)->kind);
795 return FALSE;
797 break;
798 default:
799 FIXME("Unsupported sym-tag %s for get-offset\n",
800 symt_get_tag_str(type->tag));
801 return FALSE;
803 break;
805 case TI_GET_SYMNAME:
806 if (type->tag == SymTagExe)
808 DWORD len = (lstrlenW(module->modulename) + 1) * sizeof(WCHAR);
809 WCHAR* wname = HeapAlloc(GetProcessHeap(), 0, len);
810 if (!wname) return FALSE;
811 memcpy(wname, module->modulename, len);
812 X(WCHAR*) = wname;
814 else
816 const char* name = symt_get_name(type);
817 if (!name) return FALSE;
818 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
819 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
820 if (!X(WCHAR*)) return FALSE;
821 MultiByteToWideChar(CP_ACP, 0, name, -1, X(WCHAR*), len);
823 break;
825 case TI_GET_SYMTAG:
826 X(DWORD) = type->tag;
827 break;
829 case TI_GET_TYPE:
830 case TI_GET_TYPEID:
831 switch (type->tag)
833 /* hierarchical => hierarchical */
834 case SymTagArrayType:
835 X(DWORD) = symt_ptr2index(module, ((const struct symt_array*)type)->base_type);
836 break;
837 case SymTagPointerType:
838 X(DWORD) = symt_ptr2index(module, ((const struct symt_pointer*)type)->pointsto);
839 break;
840 case SymTagFunctionType:
841 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_signature*)type)->rettype);
842 break;
843 case SymTagTypedef:
844 X(DWORD) = symt_ptr2index(module, ((const struct symt_typedef*)type)->type);
845 break;
846 /* lexical => hierarchical */
847 case SymTagData:
848 X(DWORD) = symt_ptr2index(module, ((const struct symt_data*)type)->type);
849 break;
850 case SymTagFunction:
851 X(DWORD) = symt_ptr2index(module, ((const struct symt_function*)type)->type);
852 break;
853 case SymTagEnum:
854 X(DWORD) = symt_ptr2index(module, ((const struct symt_enum*)type)->base_type);
855 break;
856 case SymTagFunctionArgType:
857 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_arg_type*)type)->arg_type);
858 break;
859 default:
860 FIXME("Unsupported sym-tag %s for get-type\n",
861 symt_get_tag_str(type->tag));
862 /* fall through */
863 case SymTagPublicSymbol:
864 case SymTagThunk:
865 case SymTagLabel:
866 return FALSE;
868 break;
870 case TI_GET_UDTKIND:
871 if (type->tag != SymTagUDT) return FALSE;
872 X(DWORD) = ((const struct symt_udt*)type)->kind;
873 break;
875 case TI_GET_VALUE:
876 if (type->tag != SymTagData) return FALSE;
877 switch (((const struct symt_data*)type)->kind)
879 case DataIsConstant: X(VARIANT) = ((const struct symt_data*)type)->u.value; break;
880 case DataIsLocal:
881 case DataIsParam:
883 struct location loc = ((const struct symt_data*)type)->u.var;
884 unsigned i;
885 struct module_format* modfmt;
887 if (loc.kind < loc_user) return FALSE;
888 for (i = 0; i < DFI_LAST; i++)
890 modfmt = module->format_info[i];
891 if (modfmt && modfmt->loc_compute)
893 modfmt->loc_compute(module->process, modfmt,
894 (const struct symt_function*)((const struct symt_data*)type)->container, &loc);
895 break;
898 if (loc.kind != loc_absolute) return FALSE;
899 X(VARIANT).n1.n2.vt = VT_UI4; /* FIXME */
900 X(VARIANT).n1.n2.n3.uiVal = loc.offset;
902 break;
903 default: return FALSE;
905 break;
907 case TI_GET_CALLING_CONVENTION:
908 if (type->tag != SymTagFunctionType) return FALSE;
909 if (((const struct symt_function_signature*)type)->call_conv == -1)
911 FIXME("No support for calling convention for this signature\n");
912 X(DWORD) = CV_CALL_FAR_C; /* FIXME */
914 else X(DWORD) = ((const struct symt_function_signature*)type)->call_conv;
915 break;
916 case TI_GET_ARRAYINDEXTYPEID:
917 if (type->tag != SymTagArrayType) return FALSE;
918 X(DWORD) = symt_ptr2index(module, ((const struct symt_array*)type)->index_type);
919 break;
921 case TI_GET_CLASSPARENTID:
922 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
923 * belong to a parent class
925 return FALSE;
927 #undef X
929 case TI_GET_ADDRESSOFFSET:
930 case TI_GET_SYMINDEX:
931 case TI_GET_THISADJUST:
932 case TI_GET_VIRTUALBASECLASS:
933 case TI_GET_VIRTUALBASEPOINTEROFFSET:
934 case TI_GET_VIRTUALTABLESHAPEID:
935 case TI_IS_EQUIV_TO:
936 FIXME("Unsupported GetInfo request (%u)\n", req);
937 return FALSE;
938 default:
939 FIXME("Unknown GetInfo request (%u)\n", req);
940 return FALSE;
943 return TRUE;
946 /******************************************************************
947 * SymGetTypeInfo (DBGHELP.@)
950 BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
951 ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType,
952 PVOID pInfo)
954 struct module_pair pair;
956 pair.pcs = process_find_by_handle(hProcess);
957 if (!pair.pcs) return FALSE;
959 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
960 if (!module_get_debug(&pair))
962 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
963 return FALSE;
966 return symt_get_info(pair.effective, symt_index2ptr(pair.effective, TypeId), GetType, pInfo);
969 /******************************************************************
970 * SymGetTypeFromName (DBGHELP.@)
973 BOOL WINAPI SymGetTypeFromName(HANDLE hProcess, ULONG64 BaseOfDll,
974 PCSTR Name, PSYMBOL_INFO Symbol)
976 struct module_pair pair;
977 struct symt* type;
978 DWORD64 size;
980 pair.pcs = process_find_by_handle(hProcess);
981 if (!pair.pcs) return FALSE;
982 pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
983 if (!module_get_debug(&pair)) return FALSE;
984 type = symt_find_type_by_name(pair.effective, SymTagNull, Name);
985 if (!type) return FALSE;
986 Symbol->Index = Symbol->TypeIndex = symt_ptr2index(pair.effective, type);
987 symbol_setname(Symbol, symt_get_name(type));
988 symt_get_info(pair.effective, type, TI_GET_LENGTH, &size);
989 Symbol->Size = size;
990 Symbol->ModBase = pair.requested->module.BaseOfImage;
991 Symbol->Tag = type->tag;
993 return TRUE;