jscript: We don't need throw_eval_error() so remove it.
[wine/multimedia.git] / dlls / dbghelp / type.c
blob947eb49095eb7148df0dab8797df62c6160d58c3
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 struct symt_function_signature* symt_new_function_signature(struct module* module,
308 struct symt* ret_type,
309 enum CV_call_e call_conv)
311 struct symt_function_signature* sym;
313 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
315 sym->symt.tag = SymTagFunctionType;
316 sym->rettype = ret_type;
317 vector_init(&sym->vchildren, sizeof(struct symt*), 4);
318 sym->call_conv = call_conv;
319 symt_add_type(module, &sym->symt);
321 return sym;
324 BOOL symt_add_function_signature_parameter(struct module* module,
325 struct symt_function_signature* sig_type,
326 struct symt* param)
328 struct symt** p;
329 struct symt_function_arg_type* arg;
331 assert(sig_type->symt.tag == SymTagFunctionType);
332 arg = pool_alloc(&module->pool, sizeof(*arg));
333 if (!arg) return FALSE;
334 arg->symt.tag = SymTagFunctionArgType;
335 arg->arg_type = param;
336 arg->container = &sig_type->symt;
337 p = vector_add(&sig_type->vchildren, &module->pool);
338 if (!p) return FALSE; /* FIXME we leak arg */
339 *p = &arg->symt;
341 return TRUE;
344 struct symt_pointer* symt_new_pointer(struct module* module, struct symt* ref_type)
346 struct symt_pointer* sym;
348 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
350 sym->symt.tag = SymTagPointerType;
351 sym->pointsto = ref_type;
352 symt_add_type(module, &sym->symt);
354 return sym;
357 struct symt_typedef* symt_new_typedef(struct module* module, struct symt* ref,
358 const char* name)
360 struct symt_typedef* sym;
362 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
364 sym->symt.tag = SymTagTypedef;
365 sym->type = ref;
366 sym->hash_elt.name = pool_strdup(&module->pool, name);
367 hash_table_add(&module->ht_types, &sym->hash_elt);
368 symt_add_type(module, &sym->symt);
370 return sym;
373 /******************************************************************
374 * SymEnumTypes (DBGHELP.@)
377 BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
378 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
379 PVOID UserContext)
381 struct module_pair pair;
382 char buffer[sizeof(SYMBOL_INFO) + 256];
383 SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
384 const char* tmp;
385 struct symt* type;
386 DWORD64 size;
387 unsigned int i;
389 TRACE("(%p %s %p %p)\n",
390 hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
391 UserContext);
393 if (!(pair.pcs = process_find_by_handle(hProcess))) return FALSE;
394 pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
395 if (!module_get_debug(&pair)) return FALSE;
397 sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
398 sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
400 for (i=0; i<vector_length(&pair.effective->vtypes); i++)
402 type = *(struct symt**)vector_at(&pair.effective->vtypes, i);
403 sym_info->TypeIndex = (DWORD)type;
404 sym_info->info = 0; /* FIXME */
405 symt_get_info(type, TI_GET_LENGTH, &size);
406 sym_info->Size = size;
407 sym_info->ModBase = pair.requested->module.BaseOfImage;
408 sym_info->Flags = 0; /* FIXME */
409 sym_info->Value = 0; /* FIXME */
410 sym_info->Address = 0; /* FIXME */
411 sym_info->Register = 0; /* FIXME */
412 sym_info->Scope = 0; /* FIXME */
413 sym_info->Tag = type->tag;
414 tmp = symt_get_name(type);
415 if (tmp)
417 sym_info->NameLen = min(strlen(tmp),sym_info->MaxNameLen-1);
418 memcpy(sym_info->Name, tmp, sym_info->NameLen);
419 sym_info->Name[sym_info->NameLen] = '\0';
421 else
422 sym_info->Name[sym_info->NameLen = 0] = '\0';
423 if (!EnumSymbolsCallback(sym_info, sym_info->Size, UserContext)) break;
425 return TRUE;
428 struct enum_types_AtoW
430 char buffer[sizeof(SYMBOL_INFOW) + 256 * sizeof(WCHAR)];
431 void* user;
432 PSYM_ENUMERATESYMBOLS_CALLBACKW callback;
435 static BOOL CALLBACK enum_types_AtoW(PSYMBOL_INFO si, ULONG addr, PVOID _et)
437 struct enum_types_AtoW* et = _et;
438 SYMBOL_INFOW* siW = (SYMBOL_INFOW*)et->buffer;
440 copy_symbolW(siW, si);
441 return et->callback(siW, addr, et->user);
444 /******************************************************************
445 * SymEnumTypesW (DBGHELP.@)
448 BOOL WINAPI SymEnumTypesW(HANDLE hProcess, ULONG64 BaseOfDll,
449 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
450 PVOID UserContext)
452 struct enum_types_AtoW et;
454 et.callback = EnumSymbolsCallback;
455 et.user = UserContext;
457 return SymEnumTypes(hProcess, BaseOfDll, enum_types_AtoW, &et);
460 /******************************************************************
461 * symt_get_info
463 * Retrieves information about a symt (either symbol or type)
465 BOOL symt_get_info(const struct symt* type, IMAGEHLP_SYMBOL_TYPE_INFO req,
466 void* pInfo)
468 unsigned len;
470 if (!type) return FALSE;
472 /* helper to typecast pInfo to its expected type (_t) */
473 #define X(_t) (*((_t*)pInfo))
475 switch (req)
477 case TI_FINDCHILDREN:
479 const struct vector* v;
480 struct symt** pt;
481 unsigned i;
482 TI_FINDCHILDREN_PARAMS* tifp = pInfo;
484 switch (type->tag)
486 case SymTagUDT: v = &((const struct symt_udt*)type)->vchildren; break;
487 case SymTagEnum: v = &((const struct symt_enum*)type)->vchildren; break;
488 case SymTagFunctionType: v = &((const struct symt_function_signature*)type)->vchildren; break;
489 case SymTagFunction: v = &((const struct symt_function*)type)->vchildren; break;
490 default:
491 FIXME("Unsupported sym-tag %s for find-children\n",
492 symt_get_tag_str(type->tag));
493 return FALSE;
495 for (i = 0; i < tifp->Count; i++)
497 if (!(pt = vector_at(v, tifp->Start + i))) return FALSE;
498 tifp->ChildId[i] = (DWORD)*pt;
501 break;
503 case TI_GET_ADDRESS:
504 switch (type->tag)
506 case SymTagData:
507 switch (((const struct symt_data*)type)->kind)
509 case DataIsGlobal:
510 case DataIsFileStatic:
511 X(ULONG64) = ((const struct symt_data*)type)->u.var.offset;
512 break;
513 default: return FALSE;
515 break;
516 case SymTagFunction:
517 X(ULONG64) = ((const struct symt_function*)type)->address;
518 break;
519 case SymTagPublicSymbol:
520 X(ULONG64) = ((const struct symt_public*)type)->address;
521 break;
522 case SymTagFuncDebugStart:
523 case SymTagFuncDebugEnd:
524 case SymTagLabel:
525 if (!symt_get_info(((const struct symt_hierarchy_point*)type)->parent,
526 req, pInfo))
527 return FALSE;
528 X(ULONG64) += ((const struct symt_hierarchy_point*)type)->loc.offset;
529 break;
530 case SymTagThunk:
531 X(ULONG64) = ((const struct symt_thunk*)type)->address;
532 break;
533 case SymTagCompiland:
534 X(ULONG64) = ((const struct symt_compiland*)type)->address;
535 break;
536 default:
537 FIXME("Unsupported sym-tag %s for get-address\n",
538 symt_get_tag_str(type->tag));
539 return FALSE;
541 break;
543 case TI_GET_BASETYPE:
544 switch (type->tag)
546 case SymTagBaseType:
547 X(DWORD) = ((const struct symt_basic*)type)->bt;
548 break;
549 case SymTagEnum:
550 X(DWORD) = btInt;
551 break;
552 default:
553 return FALSE;
555 break;
557 case TI_GET_BITPOSITION:
558 if (type->tag == SymTagData &&
559 ((const struct symt_data*)type)->kind == DataIsMember &&
560 ((const struct symt_data*)type)->u.member.length != 0)
561 X(DWORD) = ((const struct symt_data*)type)->u.member.offset & 7;
562 else return FALSE;
563 break;
565 case TI_GET_CHILDRENCOUNT:
566 switch (type->tag)
568 case SymTagUDT:
569 X(DWORD) = vector_length(&((const struct symt_udt*)type)->vchildren);
570 break;
571 case SymTagEnum:
572 X(DWORD) = vector_length(&((const struct symt_enum*)type)->vchildren);
573 break;
574 case SymTagFunctionType:
575 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
576 break;
577 case SymTagFunction:
578 X(DWORD) = vector_length(&((const struct symt_function*)type)->vchildren);
579 break;
580 case SymTagPointerType: /* MS does it that way */
581 case SymTagArrayType: /* MS does it that way */
582 case SymTagThunk: /* MS does it that way */
583 X(DWORD) = 0;
584 break;
585 default:
586 FIXME("Unsupported sym-tag %s for get-children-count\n",
587 symt_get_tag_str(type->tag));
588 /* fall through */
589 case SymTagData:
590 case SymTagPublicSymbol:
591 case SymTagBaseType:
592 return FALSE;
594 break;
596 case TI_GET_COUNT:
597 switch (type->tag)
599 case SymTagArrayType:
600 X(DWORD) = ((const struct symt_array*)type)->end -
601 ((const struct symt_array*)type)->start + 1;
602 break;
603 case SymTagFunctionType:
604 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
605 * should be included in this value (and not in GET_CHILDREN_COUNT)
607 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
608 break;
609 default: return FALSE;
611 break;
613 case TI_GET_DATAKIND:
614 if (type->tag != SymTagData) return FALSE;
615 X(DWORD) = ((const struct symt_data*)type)->kind;
616 break;
618 case TI_GET_LENGTH:
619 switch (type->tag)
621 case SymTagBaseType:
622 X(DWORD64) = ((const struct symt_basic*)type)->size;
623 break;
624 case SymTagFunction:
625 X(DWORD64) = ((const struct symt_function*)type)->size;
626 break;
627 case SymTagPointerType:
628 X(DWORD64) = sizeof(void*);
629 break;
630 case SymTagUDT:
631 X(DWORD64) = ((const struct symt_udt*)type)->size;
632 break;
633 case SymTagEnum:
634 X(DWORD64) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
635 break;
636 case SymTagData:
637 if (((const struct symt_data*)type)->kind != DataIsMember ||
638 !((const struct symt_data*)type)->u.member.length)
639 return FALSE;
640 X(DWORD64) = ((const struct symt_data*)type)->u.member.length;
641 break;
642 case SymTagArrayType:
643 if (!symt_get_info(((const struct symt_array*)type)->base_type,
644 TI_GET_LENGTH, pInfo))
645 return FALSE;
646 X(DWORD64) *= ((const struct symt_array*)type)->end -
647 ((const struct symt_array*)type)->start + 1;
648 break;
649 case SymTagPublicSymbol:
650 X(DWORD64) = ((const struct symt_public*)type)->size;
651 break;
652 case SymTagTypedef:
653 return symt_get_info(((const struct symt_typedef*)type)->type, TI_GET_LENGTH, pInfo);
654 case SymTagThunk:
655 X(DWORD64) = ((const struct symt_thunk*)type)->size;
656 break;
657 case SymTagLabel:
658 X(DWORD64) = 0;
659 break;
660 default:
661 FIXME("Unsupported sym-tag %s for get-length\n",
662 symt_get_tag_str(type->tag));
663 /* fall through */
664 case SymTagFunctionType:
665 return 0;
667 break;
669 case TI_GET_LEXICALPARENT:
670 switch (type->tag)
672 case SymTagBlock:
673 X(DWORD) = (DWORD)((const struct symt_block*)type)->container;
674 break;
675 case SymTagData:
676 X(DWORD) = (DWORD)((const struct symt_data*)type)->container;
677 break;
678 case SymTagFunction:
679 X(DWORD) = (DWORD)((const struct symt_function*)type)->container;
680 break;
681 case SymTagThunk:
682 X(DWORD) = (DWORD)((const struct symt_thunk*)type)->container;
683 break;
684 case SymTagFunctionArgType:
685 X(DWORD) = (DWORD)((const struct symt_function_arg_type*)type)->container;
686 break;
687 default:
688 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
689 symt_get_tag_str(type->tag));
690 return FALSE;
692 break;
694 case TI_GET_NESTED:
695 switch (type->tag)
697 case SymTagUDT:
698 case SymTagEnum:
699 X(DWORD) = 0;
700 break;
701 default:
702 return FALSE;
704 break;
706 case TI_GET_OFFSET:
707 switch (type->tag)
709 case SymTagData:
710 switch (((const struct symt_data*)type)->kind)
712 case DataIsParam:
713 case DataIsLocal:
714 X(ULONG) = ((const struct symt_data*)type)->u.var.offset;
715 break;
716 case DataIsMember:
717 X(ULONG) = ((const struct symt_data*)type)->u.member.offset >> 3;
718 break;
719 default:
720 FIXME("Unknown kind (%u) for get-offset\n",
721 ((const struct symt_data*)type)->kind);
722 return FALSE;
724 break;
725 default:
726 FIXME("Unsupported sym-tag %s for get-offset\n",
727 symt_get_tag_str(type->tag));
728 return FALSE;
730 break;
732 case TI_GET_SYMNAME:
734 const char* name = symt_get_name(type);
735 if (!name) return FALSE;
736 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
737 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
738 if (!X(WCHAR*)) return FALSE;
739 MultiByteToWideChar(CP_ACP, 0, name, -1, X(WCHAR*), len);
741 break;
743 case TI_GET_SYMTAG:
744 X(DWORD) = type->tag;
745 break;
747 case TI_GET_TYPE:
748 case TI_GET_TYPEID:
749 switch (type->tag)
751 /* hierarchical => hierarchical */
752 case SymTagArrayType:
753 X(DWORD) = (DWORD)((const struct symt_array*)type)->base_type;
754 break;
755 case SymTagPointerType:
756 X(DWORD) = (DWORD)((const struct symt_pointer*)type)->pointsto;
757 break;
758 case SymTagFunctionType:
759 X(DWORD) = (DWORD)((const struct symt_function_signature*)type)->rettype;
760 break;
761 case SymTagTypedef:
762 X(DWORD) = (DWORD)((const struct symt_typedef*)type)->type;
763 break;
764 /* lexical => hierarchical */
765 case SymTagData:
766 X(DWORD) = (DWORD)((const struct symt_data*)type)->type;
767 break;
768 case SymTagFunction:
769 X(DWORD) = (DWORD)((const struct symt_function*)type)->type;
770 break;
771 case SymTagEnum:
772 X(DWORD) = (DWORD)((const struct symt_enum*)type)->base_type;
773 break;
774 case SymTagFunctionArgType:
775 X(DWORD) = (DWORD)((const struct symt_function_arg_type*)type)->arg_type;
776 break;
777 default:
778 FIXME("Unsupported sym-tag %s for get-type\n",
779 symt_get_tag_str(type->tag));
780 case SymTagPublicSymbol:
781 case SymTagThunk:
782 case SymTagLabel:
783 return FALSE;
785 break;
787 case TI_GET_UDTKIND:
788 if (type->tag != SymTagUDT) return FALSE;
789 X(DWORD) = ((const struct symt_udt*)type)->kind;
790 break;
792 case TI_GET_VALUE:
793 if (type->tag != SymTagData || ((const struct symt_data*)type)->kind != DataIsConstant)
794 return FALSE;
795 X(VARIANT) = ((const struct symt_data*)type)->u.value;
796 break;
798 case TI_GET_CALLING_CONVENTION:
799 if (type->tag != SymTagFunctionType) return FALSE;
800 if (((const struct symt_function_signature*)type)->call_conv == -1)
802 FIXME("No support for calling convention for this signature\n");
803 X(DWORD) = CV_CALL_FAR_C; /* FIXME */
805 else X(DWORD) = ((const struct symt_function_signature*)type)->call_conv;
806 break;
807 case TI_GET_ARRAYINDEXTYPEID:
808 if (type->tag != SymTagArrayType) return FALSE;
809 X(DWORD) = (DWORD)((const struct symt_array*)type)->index_type;
810 break;
812 case TI_GET_CLASSPARENTID:
813 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
814 * belong to a parent class
816 return FALSE;
818 #undef X
820 case TI_GET_ADDRESSOFFSET:
821 case TI_GET_SYMINDEX:
822 case TI_GET_THISADJUST:
823 case TI_GET_VIRTUALBASECLASS:
824 case TI_GET_VIRTUALBASEPOINTEROFFSET:
825 case TI_GET_VIRTUALTABLESHAPEID:
826 case TI_IS_EQUIV_TO:
827 FIXME("Unsupported GetInfo request (%u)\n", req);
828 return FALSE;
829 default:
830 FIXME("Unknown GetInfo request (%u)\n", req);
831 return FALSE;
834 return TRUE;
837 /******************************************************************
838 * SymGetTypeInfo (DBGHELP.@)
841 BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
842 ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType,
843 PVOID pInfo)
845 struct module_pair pair;
847 pair.pcs = process_find_by_handle(hProcess);
848 if (!pair.pcs) return FALSE;
850 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
851 if (!module_get_debug(&pair))
853 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
854 return FALSE;
857 return symt_get_info((struct symt*)TypeId, GetType, pInfo);
860 /******************************************************************
861 * SymGetTypeFromName (DBGHELP.@)
864 BOOL WINAPI SymGetTypeFromName(HANDLE hProcess, ULONG64 BaseOfDll,
865 PCSTR Name, PSYMBOL_INFO Symbol)
867 struct process* pcs = process_find_by_handle(hProcess);
868 struct module* module;
869 struct symt* type;
871 if (!pcs) return FALSE;
872 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
873 if (!module) return FALSE;
874 type = symt_find_type_by_name(module, SymTagNull, Name);
875 if (!type) return FALSE;
876 Symbol->TypeIndex = (DWORD)type;
878 return TRUE;