2 * File types.c - management of types (hierarchical tree)
4 * Copyright (C) 1997, Eric Youngdale.
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
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
)
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
)
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 SymTagInlineSite
: return ((const struct symt_inlinesite
*)sym
)->func
.hash_elt
.name
;
99 case SymTagPublicSymbol
: return ((const struct symt_public
*)sym
)->hash_elt
.name
;
100 case SymTagBaseType
: return ((const struct symt_basic
*)sym
)->hash_elt
.name
;
101 case SymTagLabel
: return ((const struct symt_hierarchy_point
*)sym
)->hash_elt
.name
;
102 case SymTagThunk
: return ((const struct symt_thunk
*)sym
)->hash_elt
.name
;
103 case SymTagCustom
: return ((const struct symt_custom
*)sym
)->hash_elt
.name
;
105 case SymTagEnum
: return ((const struct symt_enum
*)sym
)->hash_elt
.name
;
106 case SymTagTypedef
: return ((const struct symt_typedef
*)sym
)->hash_elt
.name
;
107 case SymTagUDT
: return ((const struct symt_udt
*)sym
)->hash_elt
.name
;
108 case SymTagCompiland
: return source_get(((const struct symt_compiland
*)sym
)->container
->module
,
109 ((const struct symt_compiland
*)sym
)->source
);
111 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym
->tag
));
113 case SymTagArrayType
:
114 case SymTagPointerType
:
115 case SymTagFunctionType
:
116 case SymTagFunctionArgType
:
118 case SymTagFuncDebugStart
:
119 case SymTagFuncDebugEnd
:
124 WCHAR
* symt_get_nameW(const struct symt
* sym
)
126 const char* name
= symt_get_name(sym
);
130 if (!name
) return NULL
;
131 sz
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
132 if ((nameW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
133 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sz
);
137 BOOL
symt_get_address(const struct symt
* type
, ULONG64
* addr
)
142 switch (((const struct symt_data
*)type
)->kind
)
145 case DataIsFileStatic
:
146 *addr
= ((const struct symt_data
*)type
)->u
.var
.offset
;
148 default: return FALSE
;
152 *addr
= ((const struct symt_block
*)type
)->address
;
155 *addr
= ((const struct symt_function
*)type
)->address
;
157 case SymTagInlineSite
:
158 *addr
= ((const struct symt_inlinesite
*)type
)->func
.address
;
160 case SymTagPublicSymbol
:
161 *addr
= ((const struct symt_public
*)type
)->address
;
163 case SymTagFuncDebugStart
:
164 case SymTagFuncDebugEnd
:
166 if (!((const struct symt_hierarchy_point
*)type
)->parent
||
167 !symt_get_address(((const struct symt_hierarchy_point
*)type
)->parent
, addr
))
169 *addr
+= ((const struct symt_hierarchy_point
*)type
)->loc
.offset
;
172 *addr
= ((const struct symt_thunk
*)type
)->address
;
175 *addr
= ((const struct symt_custom
*)type
)->address
;
178 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type
->tag
));
181 case SymTagCompiland
:
182 case SymTagFunctionType
:
183 case SymTagFunctionArgType
:
188 case SymTagPointerType
:
189 case SymTagArrayType
:
195 static struct symt
* symt_find_type_by_name(const struct module
* module
,
196 enum SymTagEnum sym_tag
,
197 const char* typename
)
200 struct symt_ht
* type
;
201 struct hash_table_iter hti
;
206 hash_table_iter_init(&module
->ht_types
, &hti
, typename
);
207 while ((ptr
= hash_table_iter_up(&hti
)))
209 type
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
211 if ((sym_tag
== SymTagNull
|| type
->symt
.tag
== sym_tag
) &&
212 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, typename
))
215 SetLastError(ERROR_INVALID_NAME
); /* FIXME ?? */
219 static void symt_add_type(struct module
* module
, struct symt
* symt
)
222 p
= vector_add(&module
->vtypes
, &module
->pool
);
227 struct symt_basic
* symt_new_basic(struct module
* module
, enum BasicType bt
,
228 const char* typename
, unsigned size
)
230 struct symt_basic
* sym
;
234 sym
= (struct symt_basic
*)symt_find_type_by_name(module
, SymTagBaseType
,
236 if (sym
&& sym
->bt
== bt
&& sym
->size
== size
)
239 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
241 sym
->symt
.tag
= SymTagBaseType
;
244 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
245 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
246 } else sym
->hash_elt
.name
= NULL
;
249 symt_add_type(module
, &sym
->symt
);
254 struct symt_udt
* symt_new_udt(struct module
* module
, const char* typename
,
255 unsigned size
, enum UdtKind kind
)
257 struct symt_udt
* sym
;
259 TRACE_(dbghelp_symt
)("Adding udt %s:%s\n",
260 debugstr_w(module
->modulename
), typename
);
261 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
263 sym
->symt
.tag
= SymTagUDT
;
268 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
269 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
270 } else sym
->hash_elt
.name
= NULL
;
271 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
272 symt_add_type(module
, &sym
->symt
);
277 BOOL
symt_set_udt_size(struct module
* module
, struct symt_udt
* udt
, unsigned size
)
279 assert(udt
->symt
.tag
== SymTagUDT
);
280 if (vector_length(&udt
->vchildren
) != 0)
282 if (udt
->size
!= size
)
283 FIXME_(dbghelp_symt
)("Changing size for %s from %u to %u\n",
284 udt
->hash_elt
.name
, udt
->size
, size
);
291 /******************************************************************
292 * symt_add_udt_element
294 * add an element to a udt (struct, class, union)
295 * the size & offset parameters are expressed in bits (not bytes) so that
296 * we can mix in the single call bytes aligned elements (regular fields) and
297 * the others (bit fields)
299 BOOL
symt_add_udt_element(struct module
* module
, struct symt_udt
* udt_type
,
300 const char* name
, struct symt
* elt_type
,
301 unsigned offset
, unsigned bit_offset
, unsigned bit_size
)
306 assert(udt_type
->symt
.tag
== SymTagUDT
);
308 TRACE_(dbghelp_symt
)("Adding %s to UDT %s\n", name
, udt_type
->hash_elt
.name
);
312 for (i
=0; i
<vector_length(&udt_type
->vchildren
); i
++)
314 m
= *(struct symt_data
**)vector_at(&udt_type
->vchildren
, i
);
316 assert(m
->symt
.tag
== SymTagData
);
317 if (strcmp(m
->hash_elt
.name
, name
) == 0)
322 if ((m
= pool_alloc(&module
->pool
, sizeof(*m
))) == NULL
) return FALSE
;
323 memset(m
, 0, sizeof(*m
));
324 m
->symt
.tag
= SymTagData
;
325 m
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : "";
326 m
->hash_elt
.next
= NULL
;
328 m
->kind
= DataIsMember
;
329 m
->container
= &udt_type
->symt
;
331 m
->u
.member
.offset
= offset
;
332 m
->u
.member
.bit_offset
= bit_offset
;
333 m
->u
.member
.bit_length
= bit_size
;
334 p
= vector_add(&udt_type
->vchildren
, &module
->pool
);
340 struct symt_enum
* symt_new_enum(struct module
* module
, const char* typename
,
341 struct symt
* basetype
)
343 struct symt_enum
* sym
;
345 TRACE_(dbghelp_symt
)("Adding enum %s:%s\n",
346 debugstr_w(module
->modulename
), typename
);
347 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
349 sym
->symt
.tag
= SymTagEnum
;
352 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
353 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
354 } else sym
->hash_elt
.name
= NULL
;
355 sym
->base_type
= basetype
;
356 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
357 symt_add_type(module
, &sym
->symt
);
362 BOOL
symt_add_enum_element(struct module
* module
, struct symt_enum
* enum_type
,
363 const char* name
, int value
)
368 assert(enum_type
->symt
.tag
== SymTagEnum
);
369 e
= pool_alloc(&module
->pool
, sizeof(*e
));
370 if (e
== NULL
) return FALSE
;
372 e
->symt
.tag
= SymTagData
;
373 e
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
374 e
->hash_elt
.next
= NULL
;
375 e
->kind
= DataIsConstant
;
376 e
->container
= &enum_type
->symt
;
377 e
->type
= enum_type
->base_type
;
378 V_VT(&e
->u
.value
) = VT_I4
;
379 V_I4(&e
->u
.value
) = value
;
381 p
= vector_add(&enum_type
->vchildren
, &module
->pool
);
382 if (!p
) return FALSE
; /* FIXME we leak e */
388 struct symt_array
* symt_new_array(struct module
* module
, int min
, DWORD cnt
,
389 struct symt
* base
, struct symt
* index
)
391 struct symt_array
* sym
;
393 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
395 sym
->symt
.tag
= SymTagArrayType
;
398 sym
->base_type
= base
;
399 sym
->index_type
= index
;
400 symt_add_type(module
, &sym
->symt
);
405 struct symt_function_signature
* symt_new_function_signature(struct module
* module
,
406 struct symt
* ret_type
,
407 enum CV_call_e call_conv
)
409 struct symt_function_signature
* sym
;
411 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
413 sym
->symt
.tag
= SymTagFunctionType
;
414 sym
->rettype
= ret_type
;
415 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 4);
416 sym
->call_conv
= call_conv
;
417 symt_add_type(module
, &sym
->symt
);
422 BOOL
symt_add_function_signature_parameter(struct module
* module
,
423 struct symt_function_signature
* sig_type
,
427 struct symt_function_arg_type
* arg
;
429 assert(sig_type
->symt
.tag
== SymTagFunctionType
);
430 arg
= pool_alloc(&module
->pool
, sizeof(*arg
));
431 if (!arg
) return FALSE
;
432 arg
->symt
.tag
= SymTagFunctionArgType
;
433 arg
->arg_type
= param
;
434 p
= vector_add(&sig_type
->vchildren
, &module
->pool
);
435 if (!p
) return FALSE
; /* FIXME we leak arg */
441 struct symt_pointer
* symt_new_pointer(struct module
* module
, struct symt
* ref_type
, ULONG_PTR size
)
443 struct symt_pointer
* sym
;
445 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
447 sym
->symt
.tag
= SymTagPointerType
;
448 sym
->pointsto
= ref_type
;
450 symt_add_type(module
, &sym
->symt
);
455 struct symt_typedef
* symt_new_typedef(struct module
* module
, struct symt
* ref
,
458 struct symt_typedef
* sym
;
460 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
462 sym
->symt
.tag
= SymTagTypedef
;
464 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
465 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
466 symt_add_type(module
, &sym
->symt
);
471 /******************************************************************
472 * SymEnumTypes (DBGHELP.@)
475 BOOL WINAPI
SymEnumTypes(HANDLE hProcess
, ULONG64 BaseOfDll
,
476 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
479 struct module_pair pair
;
480 char buffer
[sizeof(SYMBOL_INFO
) + 256];
481 SYMBOL_INFO
* sym_info
= (SYMBOL_INFO
*)buffer
;
486 TRACE("(%p %s %p %p)\n",
487 hProcess
, wine_dbgstr_longlong(BaseOfDll
), EnumSymbolsCallback
,
490 if (!module_init_pair(&pair
, hProcess
, BaseOfDll
)) return FALSE
;
492 sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
493 sym_info
->MaxNameLen
= sizeof(buffer
) - sizeof(SYMBOL_INFO
);
495 for (i
=0; i
<vector_length(&pair
.effective
->vtypes
); i
++)
497 type
= *(struct symt
**)vector_at(&pair
.effective
->vtypes
, i
);
498 sym_info
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
499 sym_info
->Index
= 0; /* FIXME */
500 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
501 sym_info
->Size
= size
;
502 sym_info
->ModBase
= pair
.requested
->module
.BaseOfImage
;
503 sym_info
->Flags
= 0; /* FIXME */
504 sym_info
->Value
= 0; /* FIXME */
505 sym_info
->Address
= 0; /* FIXME */
506 sym_info
->Register
= 0; /* FIXME */
507 sym_info
->Scope
= 0; /* FIXME */
508 sym_info
->Tag
= type
->tag
;
509 symbol_setname(sym_info
, symt_get_name(type
));
510 if (!EnumSymbolsCallback(sym_info
, sym_info
->Size
, UserContext
)) break;
515 struct enum_types_AtoW
517 char buffer
[sizeof(SYMBOL_INFOW
) + 256 * sizeof(WCHAR
)];
519 PSYM_ENUMERATESYMBOLS_CALLBACKW callback
;
522 static BOOL CALLBACK
enum_types_AtoW(PSYMBOL_INFO si
, ULONG size
, PVOID _et
)
524 struct enum_types_AtoW
* et
= _et
;
525 SYMBOL_INFOW
* siW
= (SYMBOL_INFOW
*)et
->buffer
;
527 copy_symbolW(siW
, si
);
528 return et
->callback(siW
, size
, et
->user
);
531 /******************************************************************
532 * SymEnumTypesW (DBGHELP.@)
535 BOOL WINAPI
SymEnumTypesW(HANDLE hProcess
, ULONG64 BaseOfDll
,
536 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
539 struct enum_types_AtoW et
;
541 et
.callback
= EnumSymbolsCallback
;
542 et
.user
= UserContext
;
544 return SymEnumTypes(hProcess
, BaseOfDll
, enum_types_AtoW
, &et
);
547 static void enum_types_of_module(struct module_pair
* pair
, const char* name
, PSYM_ENUMERATESYMBOLS_CALLBACK cb
, PVOID user
)
549 char buffer
[sizeof(SYMBOL_INFO
) + 256];
550 SYMBOL_INFO
* sym_info
= (SYMBOL_INFO
*)buffer
;
556 sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
557 sym_info
->MaxNameLen
= sizeof(buffer
) - sizeof(SYMBOL_INFO
);
559 for (i
= 0; i
< vector_length(&pair
->effective
->vtypes
); i
++)
561 type
= *(struct symt
**)vector_at(&pair
->effective
->vtypes
, i
);
562 tname
= symt_get_name(type
);
563 if (tname
&& SymMatchStringA(tname
, name
, TRUE
))
565 sym_info
->TypeIndex
= symt_ptr2index(pair
->effective
, type
);
566 sym_info
->Index
= 0; /* FIXME */
567 symt_get_info(pair
->effective
, type
, TI_GET_LENGTH
, &size
);
568 sym_info
->Size
= size
;
569 sym_info
->ModBase
= pair
->requested
->module
.BaseOfImage
;
570 sym_info
->Flags
= 0; /* FIXME */
571 sym_info
->Value
= 0; /* FIXME */
572 sym_info
->Address
= 0; /* FIXME */
573 sym_info
->Register
= 0; /* FIXME */
574 sym_info
->Scope
= 0; /* FIXME */
575 sym_info
->Tag
= type
->tag
;
576 symbol_setname(sym_info
, tname
);
577 if (!cb(sym_info
, sym_info
->Size
, user
)) break;
582 static BOOL
walk_modules(struct module_pair
* pair
)
584 /* first walk PE only modules */
585 if (!pair
->requested
|| pair
->requested
->type
== DMT_PE
)
587 while ((pair
->requested
= pair
->requested
? pair
->requested
->next
: pair
->pcs
->lmodules
) != NULL
)
589 if (pair
->requested
->type
== DMT_PE
&& module_get_debug(pair
)) return TRUE
;
592 /* then walk ELF or Mach-O modules, not containing PE modules */
593 while ((pair
->requested
= pair
->requested
? pair
->requested
->next
: pair
->pcs
->lmodules
) != NULL
)
595 if ((pair
->requested
->type
== DMT_ELF
|| pair
->requested
->type
== DMT_MACHO
) &&
596 !module_get_containee(pair
->pcs
, pair
->requested
) &&
597 module_get_debug(pair
))
603 BOOL WINAPI
SymEnumTypesByName(HANDLE proc
, ULONG64 base
, PCSTR name
, PSYM_ENUMERATESYMBOLS_CALLBACK cb
, PVOID user
)
605 struct module_pair pair
;
608 TRACE("(%p %I64x %s %p %p)\n", proc
, base
, wine_dbgstr_a(name
), cb
, user
);
610 if (!name
) return SymEnumTypes(proc
, base
, cb
, user
);
611 bang
= strchr(name
, '!');
616 pair
.pcs
= process_find_by_handle(proc
);
617 if (bang
== name
) return FALSE
;
618 if (!pair
.pcs
) return FALSE
;
619 sz
= MultiByteToWideChar(CP_ACP
, 0, name
, bang
- name
, NULL
, 0) + 1;
620 if ((modW
= malloc(sz
* sizeof(WCHAR
))) == NULL
) return FALSE
;
621 MultiByteToWideChar(CP_ACP
, 0, name
, bang
- name
, modW
, sz
);
622 modW
[sz
- 1] = L
'\0';
623 pair
.requested
= NULL
;
624 while (walk_modules(&pair
))
626 if (SymMatchStringW(pair
.requested
->modulename
, modW
, FALSE
))
627 enum_types_of_module(&pair
, bang
+ 1, cb
, user
);
633 if (!module_init_pair(&pair
, proc
, base
) || !module_get_debug(&pair
)) return FALSE
;
634 enum_types_of_module(&pair
, name
, cb
, user
);
639 BOOL WINAPI
SymEnumTypesByNameW(HANDLE proc
, ULONG64 base
, PCWSTR nameW
, PSYM_ENUMERATESYMBOLS_CALLBACKW cb
, PVOID user
)
641 struct enum_types_AtoW et
;
642 DWORD len
= nameW
? WideCharToMultiByte(CP_ACP
, 0, nameW
, -1, NULL
, 0, NULL
, NULL
) : 0;
646 TRACE("(%p %I64x %s %p %p)\n", proc
, base
, wine_dbgstr_w(nameW
), cb
, user
);
650 if (!(name
= malloc(len
))) return FALSE
;
651 WideCharToMultiByte(CP_ACP
, 0, nameW
, -1, name
, len
, NULL
, NULL
);
658 ret
= SymEnumTypesByName(proc
, base
, name
, enum_types_AtoW
, &et
);
663 /******************************************************************
666 * Retrieves information about a symt (either symbol or type)
668 BOOL
symt_get_info(struct module
* module
, const struct symt
* type
,
669 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
)
673 if (!type
) return FALSE
;
675 /* helper to typecast pInfo to its expected type (_t) */
676 #define X(_t) (*((_t*)pInfo))
680 case TI_FINDCHILDREN
:
682 const struct vector
* v
;
685 TI_FINDCHILDREN_PARAMS
* tifp
= pInfo
;
689 case SymTagExe
: v
= &((const struct symt_module
*)type
)->vchildren
; break;
690 case SymTagCompiland
: v
= &((const struct symt_compiland
*)type
)->vchildren
; break;
691 case SymTagUDT
: v
= &((const struct symt_udt
*)type
)->vchildren
; break;
692 case SymTagEnum
: v
= &((const struct symt_enum
*)type
)->vchildren
; break;
693 case SymTagFunctionType
: v
= &((const struct symt_function_signature
*)type
)->vchildren
; break;
694 case SymTagFunction
: v
= &((const struct symt_function
*)type
)->vchildren
; break;
695 case SymTagInlineSite
: v
= &((const struct symt_inlinesite
*)type
)->func
.vchildren
; break;
696 case SymTagBlock
: v
= &((const struct symt_block
*)type
)->vchildren
; break;
697 case SymTagPointerType
:
698 case SymTagArrayType
:
699 case SymTagFunctionArgType
:
702 case SymTagFuncDebugStart
:
703 case SymTagFuncDebugEnd
:
707 /* for those, CHILDRENCOUNT returns 0 */
708 return tifp
->Count
== 0;
710 FIXME("Unsupported sym-tag %s for find-children\n",
711 symt_get_tag_str(type
->tag
));
714 for (i
= 0; i
< tifp
->Count
; i
++)
716 if (!(pt
= vector_at(v
, tifp
->Start
+ i
))) return FALSE
;
717 tifp
->ChildId
[i
] = symt_ptr2index(module
, *pt
);
723 return symt_get_address(type
, (ULONG64
*)pInfo
);
725 case TI_GET_BASETYPE
:
729 X(DWORD
) = ((const struct symt_basic
*)type
)->bt
;
732 return symt_get_info(module
, ((const struct symt_enum
*)type
)->base_type
, req
, pInfo
);
738 case TI_GET_BITPOSITION
:
739 if (type
->tag
== SymTagData
&&
740 ((const struct symt_data
*)type
)->kind
== DataIsMember
&&
741 ((const struct symt_data
*)type
)->u
.member
.bit_length
!= 0)
742 X(DWORD
) = ((const struct symt_data
*)type
)->u
.member
.bit_offset
;
746 case TI_GET_CHILDRENCOUNT
:
750 X(DWORD
) = vector_length(&((const struct symt_module
*)type
)->vchildren
);
752 case SymTagCompiland
:
753 X(DWORD
) = vector_length(&((const struct symt_compiland
*)type
)->vchildren
);
756 X(DWORD
) = vector_length(&((const struct symt_udt
*)type
)->vchildren
);
759 X(DWORD
) = vector_length(&((const struct symt_enum
*)type
)->vchildren
);
761 case SymTagFunctionType
:
762 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
765 X(DWORD
) = vector_length(&((const struct symt_function
*)type
)->vchildren
);
767 case SymTagInlineSite
:
768 X(DWORD
) = vector_length(&((const struct symt_inlinesite
*)type
)->func
.vchildren
);
771 X(DWORD
) = vector_length(&((const struct symt_block
*)type
)->vchildren
);
773 /* some SymTag:s return 0 */
774 case SymTagPointerType
:
775 case SymTagArrayType
:
776 case SymTagFunctionArgType
:
778 case SymTagFuncDebugStart
:
779 case SymTagFuncDebugEnd
:
787 FIXME("Unsupported sym-tag %s for get-children-count\n",
788 symt_get_tag_str(type
->tag
));
790 /* some others return error */
792 case SymTagPublicSymbol
:
800 case SymTagArrayType
:
801 X(DWORD
) = ((const struct symt_array
*)type
)->count
;
803 case SymTagFunctionType
:
804 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
805 * should be included in this value (and not in GET_CHILDREN_COUNT)
807 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
809 default: return FALSE
;
813 case TI_GET_DATAKIND
:
814 if (type
->tag
!= SymTagData
) return FALSE
;
815 X(DWORD
) = ((const struct symt_data
*)type
)->kind
;
822 X(DWORD64
) = ((const struct symt_basic
*)type
)->size
;
825 X(DWORD64
) = ((const struct symt_function
*)type
)->size
;
828 X(DWORD64
) = ((const struct symt_block
*)type
)->size
;
830 case SymTagPointerType
:
831 X(DWORD64
) = ((const struct symt_pointer
*)type
)->size
;
834 X(DWORD64
) = ((const struct symt_udt
*)type
)->size
;
837 if (!symt_get_info(module
, ((const struct symt_enum
*)type
)->base_type
, TI_GET_LENGTH
, pInfo
))
841 if (((const struct symt_data
*)type
)->kind
!= DataIsMember
||
842 !((const struct symt_data
*)type
)->u
.member
.bit_length
)
844 X(DWORD64
) = ((const struct symt_data
*)type
)->u
.member
.bit_length
;
846 case SymTagArrayType
:
847 if (!symt_get_info(module
, ((const struct symt_array
*)type
)->base_type
,
848 TI_GET_LENGTH
, pInfo
))
850 X(DWORD64
) *= ((const struct symt_array
*)type
)->count
;
852 case SymTagPublicSymbol
:
853 X(DWORD64
) = ((const struct symt_public
*)type
)->size
;
856 return symt_get_info(module
, ((const struct symt_typedef
*)type
)->type
, TI_GET_LENGTH
, pInfo
);
858 X(DWORD64
) = ((const struct symt_thunk
*)type
)->size
;
861 X(DWORD64
) = ((const struct symt_custom
*)type
)->size
;
864 FIXME("Unsupported sym-tag %s for get-length\n",
865 symt_get_tag_str(type
->tag
));
868 case SymTagCompiland
:
869 case SymTagFunctionType
:
870 case SymTagFunctionArgType
:
871 case SymTagInlineSite
: /* native doesn't expose it, perhaps because of non-contiguous range */
873 case SymTagFuncDebugStart
:
874 case SymTagFuncDebugEnd
:
879 case TI_GET_LEXICALPARENT
:
882 case SymTagCompiland
:
883 X(DWORD
) = symt_ptr2index(module
, &((const struct symt_compiland
*)type
)->container
->symt
);
886 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_block
*)type
)->container
);
889 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->container
);
892 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->container
);
894 case SymTagInlineSite
:
895 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_inlinesite
*)type
)->func
.container
);
898 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_thunk
*)type
)->container
);
900 case SymTagFuncDebugStart
:
901 case SymTagFuncDebugEnd
:
903 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_hierarchy_point
*)type
)->parent
);
907 case SymTagFunctionType
:
908 case SymTagFunctionArgType
:
909 case SymTagPointerType
:
910 case SymTagArrayType
:
913 case SymTagBaseClass
:
914 case SymTagPublicSymbol
:
916 X(DWORD
) = symt_ptr2index(module
, &module
->top
->symt
);
919 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
920 symt_get_tag_str(type
->tag
));
943 switch (((const struct symt_data
*)type
)->kind
)
947 X(ULONG
) = ((const struct symt_data
*)type
)->u
.var
.offset
;
950 X(ULONG
) = ((const struct symt_data
*)type
)->u
.member
.offset
;
953 FIXME("Unknown kind (%u) for get-offset\n",
954 ((const struct symt_data
*)type
)->kind
);
959 FIXME("Unsupported sym-tag %s for get-offset\n",
960 symt_get_tag_str(type
->tag
));
963 case SymTagCompiland
:
965 case SymTagFunctionType
:
966 case SymTagFunctionArgType
:
967 case SymTagPointerType
:
968 case SymTagArrayType
:
973 case SymTagFuncDebugStart
:
974 case SymTagFuncDebugEnd
:
976 case SymTagInlineSite
:
983 if (type
->tag
== SymTagExe
)
985 DWORD len
= (lstrlenW(module
->modulename
) + 1) * sizeof(WCHAR
);
986 WCHAR
* wname
= HeapAlloc(GetProcessHeap(), 0, len
);
987 if (!wname
) return FALSE
;
988 memcpy(wname
, module
->modulename
, len
);
993 const char* name
= symt_get_name(type
);
994 if (!name
) return FALSE
;
995 len
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
996 X(WCHAR
*) = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
997 if (!X(WCHAR
*)) return FALSE
;
998 MultiByteToWideChar(CP_ACP
, 0, name
, -1, X(WCHAR
*), len
);
1003 X(DWORD
) = type
->tag
;
1010 /* hierarchical => hierarchical */
1011 case SymTagArrayType
:
1012 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->base_type
);
1014 case SymTagPointerType
:
1015 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_pointer
*)type
)->pointsto
);
1017 case SymTagFunctionType
:
1018 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_signature
*)type
)->rettype
);
1021 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_typedef
*)type
)->type
);
1023 /* lexical => hierarchical */
1025 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->type
);
1027 case SymTagFunction
:
1028 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->type
);
1030 case SymTagInlineSite
:
1031 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_inlinesite
*)type
)->func
.type
);
1034 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_enum
*)type
)->base_type
);
1036 case SymTagFunctionArgType
:
1037 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->arg_type
);
1040 FIXME("Unsupported sym-tag %s for get-type\n",
1041 symt_get_tag_str(type
->tag
));
1043 case SymTagPublicSymbol
:
1046 case SymTagFuncDebugStart
:
1047 case SymTagFuncDebugEnd
:
1050 case SymTagCompiland
:
1052 case SymTagBaseType
:
1058 case TI_GET_UDTKIND
:
1059 if (type
->tag
!= SymTagUDT
) return FALSE
;
1060 X(DWORD
) = ((const struct symt_udt
*)type
)->kind
;
1064 if (type
->tag
!= SymTagData
) return FALSE
;
1065 switch (((const struct symt_data
*)type
)->kind
)
1067 case DataIsConstant
: X(VARIANT
) = ((const struct symt_data
*)type
)->u
.value
; break;
1071 struct location loc
= ((const struct symt_data
*)type
)->u
.var
;
1073 struct module_format
* modfmt
;
1075 if (loc
.kind
< loc_user
) return FALSE
;
1076 for (i
= 0; i
< DFI_LAST
; i
++)
1078 modfmt
= module
->format_info
[i
];
1079 if (modfmt
&& modfmt
->loc_compute
)
1081 modfmt
->loc_compute(module
->process
, modfmt
,
1082 (const struct symt_function
*)((const struct symt_data
*)type
)->container
, &loc
);
1086 if (loc
.kind
!= loc_absolute
) return FALSE
;
1087 V_VT(&X(VARIANT
)) = VT_UI4
; /* FIXME */
1088 V_UI4(&X(VARIANT
)) = loc
.offset
;
1091 default: return FALSE
;
1095 case TI_GET_CALLING_CONVENTION
:
1096 if (type
->tag
!= SymTagFunctionType
) return FALSE
;
1097 if (((const struct symt_function_signature
*)type
)->call_conv
== -1)
1099 FIXME("No support for calling convention for this signature\n");
1100 X(DWORD
) = CV_CALL_FAR_C
; /* FIXME */
1102 else X(DWORD
) = ((const struct symt_function_signature
*)type
)->call_conv
;
1104 case TI_GET_ARRAYINDEXTYPEID
:
1105 if (type
->tag
!= SymTagArrayType
) return FALSE
;
1106 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->index_type
);
1109 case TI_GET_SYMINDEX
:
1110 /* not very useful as it is...
1111 * native sometimes (eg for UDT) return id of another instance
1112 * of the same UDT definition... maybe forward declaration?
1114 X(DWORD
) = symt_ptr2index(module
, type
);
1117 /* FIXME: we don't support properly C++ for now */
1118 case TI_GET_VIRTUALBASECLASS
:
1119 case TI_GET_VIRTUALTABLESHAPEID
:
1120 case TI_GET_VIRTUALBASEPOINTEROFFSET
:
1121 case TI_GET_CLASSPARENTID
:
1122 case TI_GET_THISADJUST
:
1123 case TI_GET_VIRTUALBASEOFFSET
:
1124 case TI_GET_VIRTUALBASEDISPINDEX
:
1125 case TI_GET_IS_REFERENCE
:
1126 case TI_GET_INDIRECTVIRTUALBASECLASS
:
1127 case TI_GET_VIRTUALBASETABLETYPE
:
1128 case TI_GET_OBJECTPOINTERTYPE
:
1135 static DWORD64 once
;
1136 if (!(once
& ((DWORD64
)1 << req
)))
1138 FIXME("Unsupported GetInfo request (%u)\n", req
);
1139 once
|= (DWORD64
)1 << req
;
1148 /******************************************************************
1149 * SymGetTypeInfo (DBGHELP.@)
1152 BOOL WINAPI
SymGetTypeInfo(HANDLE hProcess
, DWORD64 ModBase
,
1153 ULONG TypeId
, IMAGEHLP_SYMBOL_TYPE_INFO GetType
,
1156 struct module_pair pair
;
1158 if (!module_init_pair(&pair
, hProcess
, ModBase
)) return FALSE
;
1159 return symt_get_info(pair
.effective
, symt_index2ptr(pair
.effective
, TypeId
), GetType
, pInfo
);
1162 /******************************************************************
1163 * SymGetTypeFromName (DBGHELP.@)
1166 BOOL WINAPI
SymGetTypeFromName(HANDLE hProcess
, ULONG64 BaseOfDll
,
1167 PCSTR Name
, PSYMBOL_INFO Symbol
)
1169 struct module_pair pair
;
1173 if (!module_init_pair(&pair
, hProcess
, BaseOfDll
)) return FALSE
;
1174 type
= symt_find_type_by_name(pair
.effective
, SymTagNull
, Name
);
1175 if (!type
) return FALSE
;
1176 Symbol
->Index
= Symbol
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
1177 symbol_setname(Symbol
, symt_get_name(type
));
1178 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
1179 Symbol
->Size
= size
;
1180 Symbol
->ModBase
= pair
.requested
->module
.BaseOfImage
;
1181 Symbol
->Tag
= type
->tag
;