mshtml: Implement nsIStandardURL interface in nsWineURI object.
[wine/multimedia.git] / dlls / dbghelp / type.c
blob3fccb47f1418a59cede82cdafc7629fd56be77ec
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 BOOL symt_get_address(const struct symt* type, ULONG64* addr)
107 switch (type->tag)
109 case SymTagData:
110 switch (((const struct symt_data*)type)->kind)
112 case DataIsGlobal:
113 case DataIsFileStatic:
114 *addr = ((const struct symt_data*)type)->u.var.offset;
115 break;
116 default: return FALSE;
118 break;
119 case SymTagFunction:
120 *addr = ((const struct symt_function*)type)->address;
121 break;
122 case SymTagPublicSymbol:
123 *addr = ((const struct symt_public*)type)->address;
124 break;
125 case SymTagFuncDebugStart:
126 case SymTagFuncDebugEnd:
127 case SymTagLabel:
128 if (!((const struct symt_hierarchy_point*)type)->parent ||
129 !symt_get_address(((const struct symt_hierarchy_point*)type)->parent, addr))
130 return FALSE;
131 *addr += ((const struct symt_hierarchy_point*)type)->loc.offset;
132 break;
133 case SymTagThunk:
134 *addr = ((const struct symt_thunk*)type)->address;
135 break;
136 case SymTagCompiland:
137 *addr = ((const struct symt_compiland*)type)->address;
138 break;
139 default:
140 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type->tag));
141 return FALSE;
143 return TRUE;
146 static struct symt* symt_find_type_by_name(const struct module* module,
147 enum SymTagEnum sym_tag,
148 const char* typename)
150 void* ptr;
151 struct symt_ht* type;
152 struct hash_table_iter hti;
154 assert(typename);
155 assert(module);
157 hash_table_iter_init(&module->ht_types, &hti, typename);
158 while ((ptr = hash_table_iter_up(&hti)))
160 type = GET_ENTRY(ptr, struct symt_ht, hash_elt);
162 if ((sym_tag == SymTagNull || type->symt.tag == sym_tag) &&
163 type->hash_elt.name && !strcmp(type->hash_elt.name, typename))
164 return &type->symt;
166 SetLastError(ERROR_INVALID_NAME); /* FIXME ?? */
167 return NULL;
170 static void symt_add_type(struct module* module, struct symt* symt)
172 struct symt** p;
173 p = vector_add(&module->vtypes, &module->pool);
174 assert(p);
175 *p = symt;
178 struct symt_basic* symt_new_basic(struct module* module, enum BasicType bt,
179 const char* typename, unsigned size)
181 struct symt_basic* sym;
183 if (typename)
185 sym = (struct symt_basic*)symt_find_type_by_name(module, SymTagBaseType,
186 typename);
187 if (sym && sym->bt == bt && sym->size == size)
188 return sym;
190 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
192 sym->symt.tag = SymTagBaseType;
193 if (typename)
195 sym->hash_elt.name = pool_strdup(&module->pool, typename);
196 hash_table_add(&module->ht_types, &sym->hash_elt);
197 } else sym->hash_elt.name = NULL;
198 sym->bt = bt;
199 sym->size = size;
200 symt_add_type(module, &sym->symt);
202 return sym;
205 struct symt_udt* symt_new_udt(struct module* module, const char* typename,
206 unsigned size, enum UdtKind kind)
208 struct symt_udt* sym;
210 TRACE_(dbghelp_symt)("Adding udt %s:%s\n",
211 debugstr_w(module->module.ModuleName), typename);
212 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
214 sym->symt.tag = SymTagUDT;
215 sym->kind = kind;
216 sym->size = size;
217 if (typename)
219 sym->hash_elt.name = pool_strdup(&module->pool, typename);
220 hash_table_add(&module->ht_types, &sym->hash_elt);
221 } else sym->hash_elt.name = NULL;
222 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
223 symt_add_type(module, &sym->symt);
225 return sym;
228 BOOL symt_set_udt_size(struct module* module, struct symt_udt* udt, unsigned size)
230 assert(udt->symt.tag == SymTagUDT);
231 if (vector_length(&udt->vchildren) != 0)
233 if (udt->size != size)
234 FIXME_(dbghelp_symt)("Changing size for %s from %u to %u\n",
235 udt->hash_elt.name, udt->size, size);
236 return TRUE;
238 udt->size = size;
239 return TRUE;
242 /******************************************************************
243 * symt_add_udt_element
245 * add an element to a udt (struct, class, union)
246 * the size & offset parameters are expressed in bits (not bytes) so that
247 * we can mix in the single call bytes aligned elements (regular fields) and
248 * the others (bit fields)
250 BOOL symt_add_udt_element(struct module* module, struct symt_udt* udt_type,
251 const char* name, struct symt* elt_type,
252 unsigned offset, unsigned size)
254 struct symt_data* m;
255 struct symt** p;
257 assert(udt_type->symt.tag == SymTagUDT);
259 TRACE_(dbghelp_symt)("Adding %s to UDT %s\n", name, udt_type->hash_elt.name);
260 if (name)
262 unsigned int i;
263 for (i=0; i<vector_length(&udt_type->vchildren); i++)
265 m = *(struct symt_data**)vector_at(&udt_type->vchildren, i);
266 assert(m);
267 assert(m->symt.tag == SymTagData);
268 if (strcmp(m->hash_elt.name, name) == 0)
269 return TRUE;
273 if ((m = pool_alloc(&module->pool, sizeof(*m))) == NULL) return FALSE;
274 memset(m, 0, sizeof(*m));
275 m->symt.tag = SymTagData;
276 m->hash_elt.name = name ? pool_strdup(&module->pool, name) : "";
277 m->hash_elt.next = NULL;
279 m->kind = DataIsMember;
280 m->container = &udt_type->symt;
281 m->type = elt_type;
282 m->u.member.offset = offset;
283 m->u.member.length = ((offset & 7) || (size & 7)) ? size : 0;
284 p = vector_add(&udt_type->vchildren, &module->pool);
285 *p = &m->symt;
287 return TRUE;
290 struct symt_enum* symt_new_enum(struct module* module, const char* typename,
291 struct symt* basetype)
293 struct symt_enum* sym;
295 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
297 sym->symt.tag = SymTagEnum;
298 sym->name = (typename) ? pool_strdup(&module->pool, typename) : NULL;
299 sym->base_type = basetype;
300 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
302 return sym;
305 BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type,
306 const char* name, int value)
308 struct symt_data* e;
309 struct symt** p;
311 assert(enum_type->symt.tag == SymTagEnum);
312 e = pool_alloc(&module->pool, sizeof(*e));
313 if (e == NULL) return FALSE;
315 e->symt.tag = SymTagData;
316 e->hash_elt.name = pool_strdup(&module->pool, name);
317 e->hash_elt.next = NULL;
318 e->kind = DataIsConstant;
319 e->container = &enum_type->symt;
320 e->type = enum_type->base_type;
321 e->u.value.n1.n2.vt = VT_I4;
322 e->u.value.n1.n2.n3.lVal = value;
324 p = vector_add(&enum_type->vchildren, &module->pool);
325 if (!p) return FALSE; /* FIXME we leak e */
326 *p = &e->symt;
328 return TRUE;
331 struct symt_array* symt_new_array(struct module* module, int min, int max,
332 struct symt* base, struct symt* index)
334 struct symt_array* sym;
336 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
338 sym->symt.tag = SymTagArrayType;
339 sym->start = min;
340 sym->end = max;
341 sym->base_type = base;
342 sym->index_type = index;
343 symt_add_type(module, &sym->symt);
345 return sym;
348 static inline DWORD symt_array_count(struct module* module, const struct symt_array* array)
350 if (array->end < 0)
352 DWORD64 elem_size;
353 /* One could want to also set the array->end field in array, but we won't do it
354 * as long as all the get_type() helpers use const objects
356 if (symt_get_info(module, array->base_type, TI_GET_LENGTH, &elem_size) && elem_size)
357 return -array->end / (DWORD)elem_size;
358 return 0;
360 return array->end - array->start + 1;
363 struct symt_function_signature* symt_new_function_signature(struct module* module,
364 struct symt* ret_type,
365 enum CV_call_e call_conv)
367 struct symt_function_signature* sym;
369 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
371 sym->symt.tag = SymTagFunctionType;
372 sym->rettype = ret_type;
373 vector_init(&sym->vchildren, sizeof(struct symt*), 4);
374 sym->call_conv = call_conv;
375 symt_add_type(module, &sym->symt);
377 return sym;
380 BOOL symt_add_function_signature_parameter(struct module* module,
381 struct symt_function_signature* sig_type,
382 struct symt* param)
384 struct symt** p;
385 struct symt_function_arg_type* arg;
387 assert(sig_type->symt.tag == SymTagFunctionType);
388 arg = pool_alloc(&module->pool, sizeof(*arg));
389 if (!arg) return FALSE;
390 arg->symt.tag = SymTagFunctionArgType;
391 arg->arg_type = param;
392 arg->container = &sig_type->symt;
393 p = vector_add(&sig_type->vchildren, &module->pool);
394 if (!p) return FALSE; /* FIXME we leak arg */
395 *p = &arg->symt;
397 return TRUE;
400 struct symt_pointer* symt_new_pointer(struct module* module, struct symt* ref_type, unsigned long size)
402 struct symt_pointer* sym;
404 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
406 sym->symt.tag = SymTagPointerType;
407 sym->pointsto = ref_type;
408 sym->size = size;
409 symt_add_type(module, &sym->symt);
411 return sym;
414 struct symt_typedef* symt_new_typedef(struct module* module, struct symt* ref,
415 const char* name)
417 struct symt_typedef* sym;
419 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
421 sym->symt.tag = SymTagTypedef;
422 sym->type = ref;
423 sym->hash_elt.name = pool_strdup(&module->pool, name);
424 hash_table_add(&module->ht_types, &sym->hash_elt);
425 symt_add_type(module, &sym->symt);
427 return sym;
430 /******************************************************************
431 * SymEnumTypes (DBGHELP.@)
434 BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
435 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
436 PVOID UserContext)
438 struct module_pair pair;
439 char buffer[sizeof(SYMBOL_INFO) + 256];
440 SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
441 const char* tmp;
442 struct symt* type;
443 DWORD64 size;
444 unsigned int i;
446 TRACE("(%p %s %p %p)\n",
447 hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
448 UserContext);
450 if (!(pair.pcs = process_find_by_handle(hProcess))) return FALSE;
451 pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
452 if (!module_get_debug(&pair)) return FALSE;
454 sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
455 sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
457 for (i=0; i<vector_length(&pair.effective->vtypes); i++)
459 type = *(struct symt**)vector_at(&pair.effective->vtypes, i);
460 sym_info->TypeIndex = symt_ptr2index(pair.effective, type);
461 sym_info->info = 0; /* FIXME */
462 symt_get_info(pair.effective, type, TI_GET_LENGTH, &size);
463 sym_info->Size = size;
464 sym_info->ModBase = pair.requested->module.BaseOfImage;
465 sym_info->Flags = 0; /* FIXME */
466 sym_info->Value = 0; /* FIXME */
467 sym_info->Address = 0; /* FIXME */
468 sym_info->Register = 0; /* FIXME */
469 sym_info->Scope = 0; /* FIXME */
470 sym_info->Tag = type->tag;
471 tmp = symt_get_name(type);
472 if (tmp)
474 sym_info->NameLen = min(strlen(tmp),sym_info->MaxNameLen-1);
475 memcpy(sym_info->Name, tmp, sym_info->NameLen);
476 sym_info->Name[sym_info->NameLen] = '\0';
478 else
479 sym_info->Name[sym_info->NameLen = 0] = '\0';
480 if (!EnumSymbolsCallback(sym_info, sym_info->Size, UserContext)) break;
482 return TRUE;
485 struct enum_types_AtoW
487 char buffer[sizeof(SYMBOL_INFOW) + 256 * sizeof(WCHAR)];
488 void* user;
489 PSYM_ENUMERATESYMBOLS_CALLBACKW callback;
492 static BOOL CALLBACK enum_types_AtoW(PSYMBOL_INFO si, ULONG addr, PVOID _et)
494 struct enum_types_AtoW* et = _et;
495 SYMBOL_INFOW* siW = (SYMBOL_INFOW*)et->buffer;
497 copy_symbolW(siW, si);
498 return et->callback(siW, addr, et->user);
501 /******************************************************************
502 * SymEnumTypesW (DBGHELP.@)
505 BOOL WINAPI SymEnumTypesW(HANDLE hProcess, ULONG64 BaseOfDll,
506 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
507 PVOID UserContext)
509 struct enum_types_AtoW et;
511 et.callback = EnumSymbolsCallback;
512 et.user = UserContext;
514 return SymEnumTypes(hProcess, BaseOfDll, enum_types_AtoW, &et);
517 /******************************************************************
518 * symt_get_info
520 * Retrieves information about a symt (either symbol or type)
522 BOOL symt_get_info(struct module* module, const struct symt* type,
523 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo)
525 unsigned len;
527 if (!type) return FALSE;
529 /* helper to typecast pInfo to its expected type (_t) */
530 #define X(_t) (*((_t*)pInfo))
532 switch (req)
534 case TI_FINDCHILDREN:
536 const struct vector* v;
537 struct symt** pt;
538 unsigned i;
539 TI_FINDCHILDREN_PARAMS* tifp = pInfo;
541 switch (type->tag)
543 case SymTagUDT: v = &((const struct symt_udt*)type)->vchildren; break;
544 case SymTagEnum: v = &((const struct symt_enum*)type)->vchildren; break;
545 case SymTagFunctionType: v = &((const struct symt_function_signature*)type)->vchildren; break;
546 case SymTagFunction: v = &((const struct symt_function*)type)->vchildren; break;
547 default:
548 FIXME("Unsupported sym-tag %s for find-children\n",
549 symt_get_tag_str(type->tag));
550 return FALSE;
552 for (i = 0; i < tifp->Count; i++)
554 if (!(pt = vector_at(v, tifp->Start + i))) return FALSE;
555 tifp->ChildId[i] = symt_ptr2index(module, *pt);
558 break;
560 case TI_GET_ADDRESS:
561 return symt_get_address(type, (ULONG64*)pInfo);
563 case TI_GET_BASETYPE:
564 switch (type->tag)
566 case SymTagBaseType:
567 X(DWORD) = ((const struct symt_basic*)type)->bt;
568 break;
569 case SymTagEnum:
570 X(DWORD) = btInt;
571 break;
572 default:
573 return FALSE;
575 break;
577 case TI_GET_BITPOSITION:
578 if (type->tag == SymTagData &&
579 ((const struct symt_data*)type)->kind == DataIsMember &&
580 ((const struct symt_data*)type)->u.member.length != 0)
581 X(DWORD) = ((const struct symt_data*)type)->u.member.offset & 7;
582 else return FALSE;
583 break;
585 case TI_GET_CHILDRENCOUNT:
586 switch (type->tag)
588 case SymTagUDT:
589 X(DWORD) = vector_length(&((const struct symt_udt*)type)->vchildren);
590 break;
591 case SymTagEnum:
592 X(DWORD) = vector_length(&((const struct symt_enum*)type)->vchildren);
593 break;
594 case SymTagFunctionType:
595 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
596 break;
597 case SymTagFunction:
598 X(DWORD) = vector_length(&((const struct symt_function*)type)->vchildren);
599 break;
600 case SymTagPointerType: /* MS does it that way */
601 case SymTagArrayType: /* MS does it that way */
602 case SymTagThunk: /* MS does it that way */
603 X(DWORD) = 0;
604 break;
605 default:
606 FIXME("Unsupported sym-tag %s for get-children-count\n",
607 symt_get_tag_str(type->tag));
608 /* fall through */
609 case SymTagData:
610 case SymTagPublicSymbol:
611 case SymTagBaseType:
612 return FALSE;
614 break;
616 case TI_GET_COUNT:
617 switch (type->tag)
619 case SymTagArrayType:
620 X(DWORD) = symt_array_count(module, (const struct symt_array*)type);
621 break;
622 case SymTagFunctionType:
623 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
624 * should be included in this value (and not in GET_CHILDREN_COUNT)
626 X(DWORD) = vector_length(&((const struct symt_function_signature*)type)->vchildren);
627 break;
628 default: return FALSE;
630 break;
632 case TI_GET_DATAKIND:
633 if (type->tag != SymTagData) return FALSE;
634 X(DWORD) = ((const struct symt_data*)type)->kind;
635 break;
637 case TI_GET_LENGTH:
638 switch (type->tag)
640 case SymTagBaseType:
641 X(DWORD64) = ((const struct symt_basic*)type)->size;
642 break;
643 case SymTagFunction:
644 X(DWORD64) = ((const struct symt_function*)type)->size;
645 break;
646 case SymTagPointerType:
647 X(DWORD64) = ((const struct symt_pointer*)type)->size;
648 break;
649 case SymTagUDT:
650 X(DWORD64) = ((const struct symt_udt*)type)->size;
651 break;
652 case SymTagEnum:
653 X(DWORD64) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
654 break;
655 case SymTagData:
656 if (((const struct symt_data*)type)->kind != DataIsMember ||
657 !((const struct symt_data*)type)->u.member.length)
658 return FALSE;
659 X(DWORD64) = ((const struct symt_data*)type)->u.member.length;
660 break;
661 case SymTagArrayType:
662 if (!symt_get_info(module, ((const struct symt_array*)type)->base_type,
663 TI_GET_LENGTH, pInfo))
664 return FALSE;
665 X(DWORD64) *= symt_array_count(module, (const struct symt_array*)type);
666 break;
667 case SymTagPublicSymbol:
668 X(DWORD64) = ((const struct symt_public*)type)->size;
669 break;
670 case SymTagTypedef:
671 return symt_get_info(module, ((const struct symt_typedef*)type)->type, TI_GET_LENGTH, pInfo);
672 case SymTagThunk:
673 X(DWORD64) = ((const struct symt_thunk*)type)->size;
674 break;
675 case SymTagLabel:
676 X(DWORD64) = 0;
677 break;
678 default:
679 FIXME("Unsupported sym-tag %s for get-length\n",
680 symt_get_tag_str(type->tag));
681 /* fall through */
682 case SymTagFunctionType:
683 return 0;
685 break;
687 case TI_GET_LEXICALPARENT:
688 switch (type->tag)
690 case SymTagBlock:
691 X(DWORD) = symt_ptr2index(module, ((const struct symt_block*)type)->container);
692 break;
693 case SymTagData:
694 X(DWORD) = symt_ptr2index(module, ((const struct symt_data*)type)->container);
695 break;
696 case SymTagFunction:
697 X(DWORD) = symt_ptr2index(module, ((const struct symt_function*)type)->container);
698 break;
699 case SymTagThunk:
700 X(DWORD) = symt_ptr2index(module, ((const struct symt_thunk*)type)->container);
701 break;
702 case SymTagFunctionArgType:
703 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_arg_type*)type)->container);
704 break;
705 default:
706 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
707 symt_get_tag_str(type->tag));
708 return FALSE;
710 break;
712 case TI_GET_NESTED:
713 switch (type->tag)
715 case SymTagUDT:
716 case SymTagEnum:
717 X(DWORD) = 0;
718 break;
719 default:
720 return FALSE;
722 break;
724 case TI_GET_OFFSET:
725 switch (type->tag)
727 case SymTagData:
728 switch (((const struct symt_data*)type)->kind)
730 case DataIsParam:
731 case DataIsLocal:
732 X(ULONG) = ((const struct symt_data*)type)->u.var.offset;
733 break;
734 case DataIsMember:
735 X(ULONG) = ((const struct symt_data*)type)->u.member.offset >> 3;
736 break;
737 default:
738 FIXME("Unknown kind (%u) for get-offset\n",
739 ((const struct symt_data*)type)->kind);
740 return FALSE;
742 break;
743 default:
744 FIXME("Unsupported sym-tag %s for get-offset\n",
745 symt_get_tag_str(type->tag));
746 return FALSE;
748 break;
750 case TI_GET_SYMNAME:
752 const char* name = symt_get_name(type);
753 if (!name) return FALSE;
754 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
755 X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
756 if (!X(WCHAR*)) return FALSE;
757 MultiByteToWideChar(CP_ACP, 0, name, -1, X(WCHAR*), len);
759 break;
761 case TI_GET_SYMTAG:
762 X(DWORD) = type->tag;
763 break;
765 case TI_GET_TYPE:
766 case TI_GET_TYPEID:
767 switch (type->tag)
769 /* hierarchical => hierarchical */
770 case SymTagArrayType:
771 X(DWORD) = symt_ptr2index(module, ((const struct symt_array*)type)->base_type);
772 break;
773 case SymTagPointerType:
774 X(DWORD) = symt_ptr2index(module, ((const struct symt_pointer*)type)->pointsto);
775 break;
776 case SymTagFunctionType:
777 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_signature*)type)->rettype);
778 break;
779 case SymTagTypedef:
780 X(DWORD) = symt_ptr2index(module, ((const struct symt_typedef*)type)->type);
781 break;
782 /* lexical => hierarchical */
783 case SymTagData:
784 X(DWORD) = symt_ptr2index(module, ((const struct symt_data*)type)->type);
785 break;
786 case SymTagFunction:
787 X(DWORD) = symt_ptr2index(module, ((const struct symt_function*)type)->type);
788 break;
789 case SymTagEnum:
790 X(DWORD) = symt_ptr2index(module, ((const struct symt_enum*)type)->base_type);
791 break;
792 case SymTagFunctionArgType:
793 X(DWORD) = symt_ptr2index(module, ((const struct symt_function_arg_type*)type)->arg_type);
794 break;
795 default:
796 FIXME("Unsupported sym-tag %s for get-type\n",
797 symt_get_tag_str(type->tag));
798 /* fall through */
799 case SymTagPublicSymbol:
800 case SymTagThunk:
801 case SymTagLabel:
802 return FALSE;
804 break;
806 case TI_GET_UDTKIND:
807 if (type->tag != SymTagUDT) return FALSE;
808 X(DWORD) = ((const struct symt_udt*)type)->kind;
809 break;
811 case TI_GET_VALUE:
812 if (type->tag != SymTagData) return FALSE;
813 switch (((const struct symt_data*)type)->kind)
815 case DataIsConstant: X(VARIANT) = ((const struct symt_data*)type)->u.value; break;
816 case DataIsLocal:
817 case DataIsParam:
819 struct location loc = ((const struct symt_data*)type)->u.var;
820 unsigned i;
821 struct module_format* modfmt;
823 if (loc.kind < loc_user) return FALSE;
824 for (i = 0; i < DFI_LAST; i++)
826 modfmt = module->format_info[i];
827 if (modfmt && modfmt->loc_compute)
829 modfmt->loc_compute(module->process, modfmt,
830 (const struct symt_function*)((const struct symt_data*)type)->container, &loc);
831 break;
834 if (loc.kind != loc_absolute) return FALSE;
835 X(VARIANT).n1.n2.vt = VT_UI4; /* FIXME */
836 X(VARIANT).n1.n2.n3.uiVal = loc.offset;
838 break;
839 default: return FALSE;
841 break;
843 case TI_GET_CALLING_CONVENTION:
844 if (type->tag != SymTagFunctionType) return FALSE;
845 if (((const struct symt_function_signature*)type)->call_conv == -1)
847 FIXME("No support for calling convention for this signature\n");
848 X(DWORD) = CV_CALL_FAR_C; /* FIXME */
850 else X(DWORD) = ((const struct symt_function_signature*)type)->call_conv;
851 break;
852 case TI_GET_ARRAYINDEXTYPEID:
853 if (type->tag != SymTagArrayType) return FALSE;
854 X(DWORD) = symt_ptr2index(module, ((const struct symt_array*)type)->index_type);
855 break;
857 case TI_GET_CLASSPARENTID:
858 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
859 * belong to a parent class
861 return FALSE;
863 #undef X
865 case TI_GET_ADDRESSOFFSET:
866 case TI_GET_SYMINDEX:
867 case TI_GET_THISADJUST:
868 case TI_GET_VIRTUALBASECLASS:
869 case TI_GET_VIRTUALBASEPOINTEROFFSET:
870 case TI_GET_VIRTUALTABLESHAPEID:
871 case TI_IS_EQUIV_TO:
872 FIXME("Unsupported GetInfo request (%u)\n", req);
873 return FALSE;
874 default:
875 FIXME("Unknown GetInfo request (%u)\n", req);
876 return FALSE;
879 return TRUE;
882 /******************************************************************
883 * SymGetTypeInfo (DBGHELP.@)
886 BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase,
887 ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType,
888 PVOID pInfo)
890 struct module_pair pair;
892 pair.pcs = process_find_by_handle(hProcess);
893 if (!pair.pcs) return FALSE;
895 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
896 if (!module_get_debug(&pair))
898 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase));
899 return FALSE;
902 return symt_get_info(pair.effective, symt_index2ptr(pair.effective, TypeId), GetType, pInfo);
905 /******************************************************************
906 * SymGetTypeFromName (DBGHELP.@)
909 BOOL WINAPI SymGetTypeFromName(HANDLE hProcess, ULONG64 BaseOfDll,
910 PCSTR Name, PSYMBOL_INFO Symbol)
912 struct process* pcs = process_find_by_handle(hProcess);
913 struct module_pair pair;
914 struct symt* type;
916 if (!pcs) return FALSE;
917 pair.requested = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
918 if (!module_get_debug(&pair)) return FALSE;
919 type = symt_find_type_by_name(pair.effective, SymTagNull, Name);
920 if (!type) return FALSE;
921 Symbol->TypeIndex = symt_ptr2index(pair.effective, type);
923 return TRUE;