wined3d: Use IWineD3DDeviceImpl_ClearSurface in IWineD3DDeviceImpl_Clear.
[wine/multimedia.git] / dlls / dbghelp / type.c
bloba8c6778ed90dae6ba44092dae11e0a36c5d9aa7a
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.
24 #include "config.h"
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <assert.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
32 #include "wine/debug.h"
33 #include "dbghelp_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
36 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt);
38 static const char* symt_get_tag_str(DWORD tag)
40 switch (tag)
42 case SymTagNull: return "SymTagNull";
43 case SymTagExe: return "SymTagExe";
44 case SymTagCompiland: return "SymTagCompiland";
45 case SymTagCompilandDetails: return "SymTagCompilandDetails";
46 case SymTagCompilandEnv: return "SymTagCompilandEnv";
47 case SymTagFunction: return "SymTagFunction";
48 case SymTagBlock: return "SymTagBlock";
49 case SymTagData: return "SymTagData";
50 case SymTagAnnotation: return "SymTagAnnotation";
51 case SymTagLabel: return "SymTagLabel";
52 case SymTagPublicSymbol: return "SymTagPublicSymbol";
53 case SymTagUDT: return "SymTagUDT";
54 case SymTagEnum: return "SymTagEnum";
55 case SymTagFunctionType: return "SymTagFunctionType";
56 case SymTagPointerType: return "SymTagPointerType";
57 case SymTagArrayType: return "SymTagArrayType";
58 case SymTagBaseType: return "SymTagBaseType";
59 case SymTagTypedef: return "SymTagTypedef,";
60 case SymTagBaseClass: return "SymTagBaseClass";
61 case SymTagFriend: return "SymTagFriend";
62 case SymTagFunctionArgType: return "SymTagFunctionArgType,";
63 case SymTagFuncDebugStart: return "SymTagFuncDebugStart,";
64 case SymTagFuncDebugEnd: return "SymTagFuncDebugEnd";
65 case SymTagUsingNamespace: return "SymTagUsingNamespace,";
66 case SymTagVTableShape: return "SymTagVTableShape";
67 case SymTagVTable: return "SymTagVTable";
68 case SymTagCustom: return "SymTagCustom";
69 case SymTagThunk: return "SymTagThunk";
70 case SymTagCustomType: return "SymTagCustomType";
71 case SymTagManagedType: return "SymTagManagedType";
72 case SymTagDimension: return "SymTagDimension";
73 default: return "---";
77 const char* symt_get_name(const struct symt* sym)
79 switch (sym->tag)
81 /* lexical tree */
82 case SymTagData: return ((const struct symt_data*)sym)->hash_elt.name;
83 case SymTagFunction: return ((const struct symt_function*)sym)->hash_elt.name;
84 case SymTagPublicSymbol: return ((const struct symt_public*)sym)->hash_elt.name;
85 case SymTagBaseType: return ((const struct symt_basic*)sym)->hash_elt.name;
86 case SymTagLabel: return ((const struct symt_function_point*)sym)->name;
87 case SymTagThunk: return ((const struct symt_thunk*)sym)->hash_elt.name;
88 /* hierarchy tree */
89 case SymTagEnum: return ((const struct symt_enum*)sym)->name;
90 case SymTagTypedef: return ((const struct symt_typedef*)sym)->hash_elt.name;
91 case SymTagUDT: return ((const struct symt_udt*)sym)->hash_elt.name;
92 default:
93 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym->tag));
94 /* fall through */
95 case SymTagArrayType:
96 case SymTagPointerType:
97 case SymTagFunctionType:
98 return NULL;
102 static struct symt* symt_find_type_by_name(const struct module* module,
103 enum SymTagEnum sym_tag,
104 const char* typename)
106 void* ptr;
107 struct symt_ht* type;
108 struct hash_table_iter hti;
110 assert(typename);
111 assert(module);
113 hash_table_iter_init(&module->ht_types, &hti, typename);
114 while ((ptr = hash_table_iter_up(&hti)))
116 type = GET_ENTRY(ptr, struct symt_ht, hash_elt);
118 if ((sym_tag == SymTagNull || type->symt.tag == sym_tag) &&
119 type->hash_elt.name && !strcmp(type->hash_elt.name, typename))
120 return &type->symt;
122 SetLastError(ERROR_INVALID_NAME); /* FIXME ?? */
123 return NULL;
126 static void symt_add_type(struct module* module, struct symt* symt)
128 struct symt** p;
129 p = vector_add(&module->vtypes, &module->pool);
130 assert(p);
131 *p = symt;
134 struct symt_basic* symt_new_basic(struct module* module, enum BasicType bt,
135 const char* typename, unsigned size)
137 struct symt_basic* sym;
139 if (typename)
141 sym = (struct symt_basic*)symt_find_type_by_name(module, SymTagBaseType,
142 typename);
143 if (sym && sym->bt == bt && sym->size == size)
144 return sym;
146 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
148 sym->symt.tag = SymTagBaseType;
149 if (typename)
151 sym->hash_elt.name = pool_strdup(&module->pool, typename);
152 hash_table_add(&module->ht_types, &sym->hash_elt);
153 } else sym->hash_elt.name = NULL;
154 sym->bt = bt;
155 sym->size = size;
156 symt_add_type(module, &sym->symt);
158 return sym;
161 struct symt_udt* symt_new_udt(struct module* module, const char* typename,
162 unsigned size, enum UdtKind kind)
164 struct symt_udt* sym;
166 TRACE_(dbghelp_symt)("Adding udt %s:%s\n",
167 debugstr_w(module->module.ModuleName), typename);
168 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
170 sym->symt.tag = SymTagUDT;
171 sym->kind = kind;
172 sym->size = size;
173 if (typename)
175 sym->hash_elt.name = pool_strdup(&module->pool, typename);
176 hash_table_add(&module->ht_types, &sym->hash_elt);
177 } else sym->hash_elt.name = NULL;
178 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
179 symt_add_type(module, &sym->symt);
181 return sym;
184 BOOL symt_set_udt_size(struct module* module, struct symt_udt* udt, unsigned size)
186 assert(udt->symt.tag == SymTagUDT);
187 if (vector_length(&udt->vchildren) != 0)
189 if (udt->size != size)
190 FIXME_(dbghelp_symt)("Changing size for %s from %u to %u\n",
191 udt->hash_elt.name, udt->size, size);
192 return TRUE;
194 udt->size = size;
195 return TRUE;
198 /******************************************************************
199 * symt_add_udt_element
201 * add an element to a udt (struct, class, union)
202 * the size & offset parameters are expressed in bits (not bytes) so that
203 * we can mix in the single call bytes aligned elements (regular fields) and
204 * the others (bit fields)
206 BOOL symt_add_udt_element(struct module* module, struct symt_udt* udt_type,
207 const char* name, struct symt* elt_type,
208 unsigned offset, unsigned size)
210 struct symt_data* m;
211 struct symt** p;
213 assert(udt_type->symt.tag == SymTagUDT);
215 TRACE_(dbghelp_symt)("Adding %s to UDT %s\n", name, udt_type->hash_elt.name);
216 if (name)
218 int i;
219 for (i=0; i<vector_length(&udt_type->vchildren); i++)
221 m = *(struct symt_data**)vector_at(&udt_type->vchildren, i);
222 assert(m);
223 assert(m->symt.tag == SymTagData);
224 if (strcmp(m->hash_elt.name, name) == 0)
225 return TRUE;
229 if ((m = pool_alloc(&module->pool, sizeof(*m))) == NULL) return FALSE;
230 memset(m, 0, sizeof(*m));
231 m->symt.tag = SymTagData;
232 m->hash_elt.name = name ? pool_strdup(&module->pool, name) : "";
233 m->hash_elt.next = NULL;
235 m->kind = DataIsMember;
236 m->container = &udt_type->symt;
237 m->type = elt_type;
238 m->u.member.offset = offset;
239 m->u.member.length = ((offset & 7) || (size & 7)) ? size : 0;
240 p = vector_add(&udt_type->vchildren, &module->pool);
241 *p = &m->symt;
243 return TRUE;
246 struct symt_enum* symt_new_enum(struct module* module, const char* typename)
248 struct symt_enum* sym;
250 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
252 sym->symt.tag = SymTagEnum;
253 sym->name = (typename) ? pool_strdup(&module->pool, typename) : NULL;
254 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
256 return sym;
259 BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type,
260 const char* name, int value)
262 struct symt_data* e;
263 struct symt** p;
265 assert(enum_type->symt.tag == SymTagEnum);
266 e = pool_alloc(&module->pool, sizeof(*e));
267 if (e == NULL) return FALSE;
269 e->symt.tag = SymTagData;
270 e->hash_elt.name = pool_strdup(&module->pool, name);
271 e->hash_elt.next = NULL;
272 e->kind = DataIsConstant;
273 e->container = &enum_type->symt;
274 /* CV defines the underlying type for the enumeration */
275 e->type = &symt_new_basic(module, btInt, "int", 4)->symt;
276 e->u.value.n1.n2.vt = VT_I4;
277 e->u.value.n1.n2.n3.lVal = value;
279 p = vector_add(&enum_type->vchildren, &module->pool);
280 if (!p) return FALSE; /* FIXME we leak e */
281 *p = &e->symt;
283 return TRUE;
286 struct symt_array* symt_new_array(struct module* module, int min, int max,
287 struct symt* base, struct symt* index)
289 struct symt_array* sym;
291 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
293 sym->symt.tag = SymTagArrayType;
294 sym->start = min;
295 sym->end = max;
296 sym->base_type = base;
297 sym->index_type = index;
298 symt_add_type(module, &sym->symt);
300 return sym;
303 struct symt_function_signature* symt_new_function_signature(struct module* module,
304 struct symt* ret_type,
305 enum CV_call_e call_conv)
307 struct symt_function_signature* sym;
309 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
311 sym->symt.tag = SymTagFunctionType;
312 sym->rettype = ret_type;
313 vector_init(&sym->vchildren, sizeof(struct symt*), 4);
314 sym->call_conv = call_conv;
315 symt_add_type(module, &sym->symt);
317 return sym;
320 BOOL symt_add_function_signature_parameter(struct module* module,
321 struct symt_function_signature* sig_type,
322 struct symt* param)
324 struct symt** p;
325 struct symt_function_arg_type* arg;
327 assert(sig_type->symt.tag == SymTagFunctionType);
328 arg = pool_alloc(&module->pool, sizeof(*arg));
329 if (!arg) return FALSE;
330 arg->symt.tag = SymTagFunctionArgType;
331 arg->arg_type = param;
332 arg->container = &sig_type->symt;
333 p = vector_add(&sig_type->vchildren, &module->pool);
334 if (!p) return FALSE; /* FIXME we leak arg */
335 *p = &arg->symt;
337 return TRUE;
340 struct symt_pointer* symt_new_pointer(struct module* module, struct symt* ref_type)
342 struct symt_pointer* sym;
344 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
346 sym->symt.tag = SymTagPointerType;
347 sym->pointsto = ref_type;
348 symt_add_type(module, &sym->symt);
350 return sym;
353 struct symt_typedef* symt_new_typedef(struct module* module, struct symt* ref,
354 const char* name)
356 struct symt_typedef* sym;
358 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
360 sym->symt.tag = SymTagTypedef;
361 sym->type = ref;
362 sym->hash_elt.name = pool_strdup(&module->pool, name);
363 hash_table_add(&module->ht_types, &sym->hash_elt);
364 symt_add_type(module, &sym->symt);
366 return sym;
369 /******************************************************************
370 * SymEnumTypes (DBGHELP.@)
373 BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
374 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
375 PVOID UserContext)
377 struct module_pair pair;
378 char buffer[sizeof(SYMBOL_INFO) + 256];
379 SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
380 const char* tmp;
381 struct symt* type;
382 DWORD64 size;
383 int i;
385 TRACE("(%p %s %p %p)\n",
386 hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
387 UserContext);
389 if (!(pair.pcs = process_find_by_handle(hProcess))) return FALSE;
390 pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
391 if (!module_get_debug(&pair)) return FALSE;
393 sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
394 sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
396 for (i=0; i<vector_length(&pair.effective->vtypes); i++)
398 type = *(struct symt**)vector_at(&pair.effective->vtypes, i);
399 sym_info->TypeIndex = (DWORD)type;
400 sym_info->info = 0; /* FIXME */
401 symt_get_info(type, TI_GET_LENGTH, &size);
402 sym_info->Size = size;
403 sym_info->ModBase = pair.requested->module.BaseOfImage;
404 sym_info->Flags = 0; /* FIXME */
405 sym_info->Value = 0; /* FIXME */
406 sym_info->Address = 0; /* FIXME */
407 sym_info->Register = 0; /* FIXME */
408 sym_info->Scope = 0; /* FIXME */
409 sym_info->Tag = type->tag;
410 tmp = symt_get_name(type);
411 if (tmp)
413 sym_info->NameLen = min(strlen(tmp),sym_info->MaxNameLen-1);
414 memcpy(sym_info->Name, tmp, sym_info->NameLen);
415 sym_info->Name[sym_info->NameLen] = '\0';
417 else
418 sym_info->Name[sym_info->NameLen = 0] = '\0';
419 if (!EnumSymbolsCallback(sym_info, sym_info->Size, UserContext)) break;
421 return TRUE;
424 struct enum_types_AtoW
426 char buffer[sizeof(SYMBOL_INFOW) + 256 * sizeof(WCHAR)];
427 void* user;
428 PSYM_ENUMERATESYMBOLS_CALLBACKW callback;
431 BOOL CALLBACK enum_types_AtoW(PSYMBOL_INFO si, ULONG addr, PVOID _et)
433 struct enum_types_AtoW* et = _et;
434 SYMBOL_INFOW* siW = (SYMBOL_INFOW*)et->buffer;
436 copy_symbolW(siW, si);
437 return et->callback(siW, addr, et->user);
440 /******************************************************************
441 * SymEnumTypesW (DBGHELP.@)
444 BOOL WINAPI SymEnumTypesW(HANDLE hProcess, ULONG64 BaseOfDll,
445 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
446 PVOID UserContext)
448 struct enum_types_AtoW et;
450 et.callback = EnumSymbolsCallback;
451 et.user = UserContext;
453 return SymEnumTypes(hProcess, BaseOfDll, enum_types_AtoW, &et);
456 /******************************************************************
457 * symt_get_info
459 * Retrieves information about a symt (either symbol or type)
461 BOOL symt_get_info(const struct symt* type, IMAGEHLP_SYMBOL_TYPE_INFO req,
462 void* pInfo)
464 unsigned len;
466 if (!type) return FALSE;
468 /* helper to typecast pInfo to its expected type (_t) */
469 #define X(_t) (*((_t*)pInfo))
471 switch (req)
473 case TI_FINDCHILDREN:
475 const struct vector* v;
476 struct symt** pt;
477 unsigned i;
478 TI_FINDCHILDREN_PARAMS* tifp = pInfo;
480 switch (type->tag)
482 case SymTagUDT: v = &((const struct symt_udt*)type)->vchildren; break;
483 case SymTagEnum: v = &((const struct symt_enum*)type)->vchildren; break;
484 case SymTagFunctionType: v = &((const struct symt_function_signature*)type)->vchildren; break;
485 case SymTagFunction: v = &((const struct symt_function*)type)->vchildren; break;
486 default:
487 FIXME("Unsupported sym-tag %s for find-children\n",
488 symt_get_tag_str(type->tag));
489 return FALSE;
491 for (i = 0; i < tifp->Count; i++)
493 if (!(pt = vector_at(v, tifp->Start + i))) return FALSE;
494 tifp->ChildId[i] = (DWORD)*pt;
497 break;
499 case TI_GET_ADDRESS:
500 switch (type->tag)
502 case SymTagData:
503 switch (((const struct symt_data*)type)->kind)
505 case DataIsGlobal:
506 case DataIsFileStatic:
507 X(ULONG64) = ((const struct symt_data*)type)->u.var.offset;
508 break;
509 default: return FALSE;
511 break;
512 case SymTagFunction:
513 X(ULONG64) = ((const struct symt_function*)type)->address;
514 break;
515 case SymTagPublicSymbol:
516 X(ULONG64) = ((const struct symt_public*)type)->address;
517 break;
518 case SymTagFuncDebugStart:
519 case SymTagFuncDebugEnd:
520 case SymTagLabel:
521 X(ULONG64) = ((const struct symt_function_point*)type)->parent->address +
522 ((const struct symt_function_point*)type)->loc.offset;
523 break;
524 case SymTagThunk:
525 X(ULONG64) = ((const struct symt_thunk*)type)->address;
526 break;
527 case SymTagCompiland:
528 X(ULONG64) = ((const struct symt_compiland*)type)->address;
529 break;
530 default:
531 FIXME("Unsupported sym-tag %s for get-address\n",
532 symt_get_tag_str(type->tag));
533 return FALSE;
535 break;
537 case TI_GET_BASETYPE:
538 switch (type->tag)
540 case SymTagBaseType:
541 X(DWORD) = ((const struct symt_basic*)type)->bt;
542 break;
543 case SymTagEnum:
544 X(DWORD) = btInt;
545 break;
546 default:
547 return FALSE;
549 break;
551 case TI_GET_BITPOSITION:
552 if (type->tag == SymTagData &&
553 ((const struct symt_data*)type)->kind == DataIsMember &&
554 ((const struct symt_data*)type)->u.member.length != 0)
555 X(DWORD) = ((const struct symt_data*)type)->u.member.offset & 7;
556 else return FALSE;
557 break;
559 case TI_GET_CHILDRENCOUNT:
560 switch (type->tag)
562 case SymTagUDT:
563 X(DWORD) = vector_length(&((const struct symt_udt*)type)->vchildren);
564 break;
565 case SymTagEnum:
566 X(DWORD) = vector_length(&((const struct symt_enum*)type)->vchildren);
567 break;
568 case SymTagFunctionType:
569 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
570 break;
571 case SymTagFunction:
572 X(DWORD) = vector_length(&((const struct symt_function*)type)->vchildren);
573 break;
574 case SymTagPointerType: /* MS does it that way */
575 case SymTagArrayType: /* MS does it that way */
576 case SymTagThunk: /* MS does it that way */
577 X(DWORD) = 0;
578 break;
579 default:
580 FIXME("Unsupported sym-tag %s for get-children-count\n",
581 symt_get_tag_str(type->tag));
582 /* fall through */
583 case SymTagData:
584 case SymTagPublicSymbol:
585 case SymTagBaseType:
586 return FALSE;
588 break;
590 case TI_GET_COUNT:
591 switch (type->tag)
593 case SymTagArrayType:
594 X(DWORD) = ((const struct symt_array*)type)->end -
595 ((const struct symt_array*)type)->start + 1;
596 break;
597 case SymTagFunctionType:
598 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
599 * should be included in this value (and not in GET_CHILDREN_COUNT)
601 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
602 break;
603 default: return FALSE;
605 break;
607 case TI_GET_DATAKIND:
608 if (type->tag != SymTagData) return FALSE;
609 X(DWORD) = ((const struct symt_data*)type)->kind;
610 break;
612 case TI_GET_LENGTH:
613 switch (type->tag)
615 case SymTagBaseType:
616 X(DWORD64) = ((const struct symt_basic*)type)->size;
617 break;
618 case SymTagFunction:
619 X(DWORD64) = ((const struct symt_function*)type)->size;
620 break;
621 case SymTagPointerType:
622 X(DWORD64) = sizeof(void*);
623 break;
624 case SymTagUDT:
625 X(DWORD64) = ((const struct symt_udt*)type)->size;
626 break;
627 case SymTagEnum:
628 X(DWORD64) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
629 break;
630 case SymTagData:
631 if (((const struct symt_data*)type)->kind != DataIsMember ||
632 !((const struct symt_data*)type)->u.member.length)
633 return FALSE;
634 X(DWORD64) = ((const struct symt_data*)type)->u.member.length;
635 break;
636 case SymTagArrayType:
637 if (!symt_get_info(((const struct symt_array*)type)->base_type,
638 TI_GET_LENGTH, pInfo))
639 return FALSE;
640 X(DWORD64) *= ((const struct symt_array*)type)->end -
641 ((const struct symt_array*)type)->start + 1;
642 break;
643 case SymTagPublicSymbol:
644 X(DWORD64) = ((const struct symt_public*)type)->size;
645 break;
646 case SymTagTypedef:
647 return symt_get_info(((const struct symt_typedef*)type)->type, TI_GET_LENGTH, pInfo);
648 case SymTagThunk:
649 X(DWORD64) = ((const struct symt_thunk*)type)->size;
650 break;
651 default:
652 FIXME("Unsupported sym-tag %s for get-length\n",
653 symt_get_tag_str(type->tag));
654 /* fall through */
655 case SymTagFunctionType:
656 return 0;
658 break;
660 case TI_GET_LEXICALPARENT:
661 switch (type->tag)
663 case SymTagBlock:
664 X(DWORD) = (DWORD)((const struct symt_block*)type)->container;
665 break;
666 case SymTagData:
667 X(DWORD) = (DWORD)((const struct symt_data*)type)->container;
668 break;
669 case SymTagFunction:
670 X(DWORD) = (DWORD)((const struct symt_function*)type)->container;
671 break;
672 case SymTagThunk:
673 X(DWORD) = (DWORD)((const struct symt_thunk*)type)->container;
674 break;
675 case SymTagFunctionArgType:
676 X(DWORD) = (DWORD)((const struct symt_function_arg_type*)type)->container;
677 break;
678 default:
679 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
680 symt_get_tag_str(type->tag));
681 return FALSE;
683 break;
685 case TI_GET_NESTED:
686 switch (type->tag)
688 case SymTagUDT:
689 case SymTagEnum:
690 X(DWORD) = 0;
691 break;
692 default:
693 return FALSE;
695 break;
697 case TI_GET_OFFSET:
698 switch (type->tag)
700 case SymTagData:
701 switch (((const struct symt_data*)type)->kind)
703 case DataIsParam:
704 case DataIsLocal:
705 X(ULONG) = ((const struct symt_data*)type)->u.var.offset;
706 break;
707 case DataIsMember:
708 X(ULONG) = ((const struct symt_data*)type)->u.member.offset >> 3;
709 break;
710 default:
711 FIXME("Unknown kind (%u) for get-offset\n",
712 ((const struct symt_data*)type)->kind);
713 return FALSE;
715 break;
716 default:
717 FIXME("Unsupported sym-tag %s for get-offset\n",
718 symt_get_tag_str(type->tag));
719 return FALSE;
721 break;
723 case TI_GET_SYMNAME:
725 const char* name = symt_get_name(type);
726 if (!name) return FALSE;
727 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
728 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
729 if (!X(WCHAR*)) return FALSE;
730 MultiByteToWideChar(CP_ACP, 0, name, -1, X(WCHAR*), len);
732 break;
734 case TI_GET_SYMTAG:
735 X(DWORD) = type->tag;
736 break;
738 case TI_GET_TYPE:
739 case TI_GET_TYPEID:
740 switch (type->tag)
742 /* hierarchical => hierarchical */
743 case SymTagArrayType:
744 X(DWORD) = (DWORD)((const struct symt_array*)type)->base_type;
745 break;
746 case SymTagPointerType:
747 X(DWORD) = (DWORD)((const struct symt_pointer*)type)->pointsto;
748 break;
749 case SymTagFunctionType:
750 X(DWORD) = (DWORD)((const struct symt_function_signature*)type)->rettype;
751 break;
752 case SymTagTypedef:
753 X(DWORD) = (DWORD)((const struct symt_typedef*)type)->type;
754 break;
755 /* lexical => hierarchical */
756 case SymTagData:
757 X(DWORD) = (DWORD)((const struct symt_data*)type)->type;
758 break;
759 case SymTagFunction:
760 X(DWORD) = (DWORD)((const struct symt_function*)type)->type;
761 break;
762 /* FIXME: should also work for enums */
763 case SymTagFunctionArgType:
764 X(DWORD) = (DWORD)((const struct symt_function_arg_type*)type)->arg_type;
765 break;
766 default:
767 FIXME("Unsupported sym-tag %s for get-type\n",
768 symt_get_tag_str(type->tag));
769 case SymTagPublicSymbol:
770 case SymTagThunk:
771 return FALSE;
773 break;
775 case TI_GET_UDTKIND:
776 if (type->tag != SymTagUDT) return FALSE;
777 X(DWORD) = ((const struct symt_udt*)type)->kind;
778 break;
780 case TI_GET_VALUE:
781 if (type->tag != SymTagData || ((const struct symt_data*)type)->kind != DataIsConstant)
782 return FALSE;
783 X(VARIANT) = ((const struct symt_data*)type)->u.value;
784 break;
786 case TI_GET_CALLING_CONVENTION:
787 if (type->tag != SymTagFunctionType) return FALSE;
788 if (((const struct symt_function_signature*)type)->call_conv == -1)
790 FIXME("No support for calling convention for this signature\n");
791 X(DWORD) = CV_CALL_FAR_C; /* FIXME */
793 else X(DWORD) = ((const struct symt_function_signature*)type)->call_conv;
794 break;
795 case TI_GET_ARRAYINDEXTYPEID:
796 if (type->tag != SymTagArrayType) return FALSE;
797 X(DWORD) = (DWORD)((const struct symt_array*)type)->index_type;
798 break;
800 #undef X
802 case TI_GET_ADDRESSOFFSET:
803 case TI_GET_CLASSPARENTID:
804 case TI_GET_SYMINDEX:
805 case TI_GET_THISADJUST:
806 case TI_GET_VIRTUALBASECLASS:
807 case TI_GET_VIRTUALBASEPOINTEROFFSET:
808 case TI_GET_VIRTUALTABLESHAPEID:
809 case TI_IS_EQUIV_TO:
810 FIXME("Unsupported GetInfo request (%u)\n", req);
811 return FALSE;
812 default:
813 FIXME("Unknown GetInfo request (%u)\n", req);
814 return FALSE;
817 return TRUE;
820 /******************************************************************
821 * SymGetTypeInfo (DBGHELP.@)
824 BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
825 ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType,
826 PVOID pInfo)
828 struct module_pair pair;
830 pair.pcs = process_find_by_handle(hProcess);
831 if (!pair.pcs) return FALSE;
833 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
834 if (!module_get_debug(&pair))
836 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
837 return FALSE;
840 return symt_get_info((struct symt*)TypeId, GetType, pInfo);
843 /******************************************************************
844 * SymGetTypeFromName (DBGHELP.@)
847 BOOL WINAPI SymGetTypeFromName(HANDLE hProcess, ULONG64 BaseOfDll,
848 PCSTR Name, PSYMBOL_INFO Symbol)
850 struct process* pcs = process_find_by_handle(hProcess);
851 struct module* module;
852 struct symt* type;
854 if (!pcs) return FALSE;
855 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
856 if (!module) return FALSE;
857 type = symt_find_type_by_name(module, SymTagNull, Name);
858 if (!type) return FALSE;
859 Symbol->TypeIndex = (DWORD)type;
861 return TRUE;