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 SymTagPublicSymbol
: return ((const struct symt_public
*)sym
)->hash_elt
.name
;
99 case SymTagBaseType
: return ((const struct symt_basic
*)sym
)->hash_elt
.name
;
100 case SymTagLabel
: return ((const struct symt_hierarchy_point
*)sym
)->hash_elt
.name
;
101 case SymTagThunk
: return ((const struct symt_thunk
*)sym
)->hash_elt
.name
;
103 case SymTagEnum
: return ((const struct symt_enum
*)sym
)->hash_elt
.name
;
104 case SymTagTypedef
: return ((const struct symt_typedef
*)sym
)->hash_elt
.name
;
105 case SymTagUDT
: return ((const struct symt_udt
*)sym
)->hash_elt
.name
;
106 case SymTagCompiland
: return source_get(((const struct symt_compiland
*)sym
)->container
->module
,
107 ((const struct symt_compiland
*)sym
)->source
);
109 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym
->tag
));
111 case SymTagArrayType
:
112 case SymTagPointerType
:
113 case SymTagFunctionType
:
118 WCHAR
* symt_get_nameW(const struct symt
* sym
)
120 const char* name
= symt_get_name(sym
);
124 if (!name
) return NULL
;
125 sz
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
126 if ((nameW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
127 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sz
);
131 BOOL
symt_get_address(const struct symt
* type
, ULONG64
* addr
)
136 switch (((const struct symt_data
*)type
)->kind
)
139 case DataIsFileStatic
:
140 *addr
= ((const struct symt_data
*)type
)->u
.var
.offset
;
142 default: return FALSE
;
146 *addr
= ((const struct symt_block
*)type
)->address
;
149 *addr
= ((const struct symt_function
*)type
)->address
;
151 case SymTagPublicSymbol
:
152 *addr
= ((const struct symt_public
*)type
)->address
;
154 case SymTagFuncDebugStart
:
155 case SymTagFuncDebugEnd
:
157 if (!((const struct symt_hierarchy_point
*)type
)->parent
||
158 !symt_get_address(((const struct symt_hierarchy_point
*)type
)->parent
, addr
))
160 *addr
+= ((const struct symt_hierarchy_point
*)type
)->loc
.offset
;
163 *addr
= ((const struct symt_thunk
*)type
)->address
;
166 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type
->tag
));
169 case SymTagCompiland
:
175 static struct symt
* symt_find_type_by_name(const struct module
* module
,
176 enum SymTagEnum sym_tag
,
177 const char* typename
)
180 struct symt_ht
* type
;
181 struct hash_table_iter hti
;
186 hash_table_iter_init(&module
->ht_types
, &hti
, typename
);
187 while ((ptr
= hash_table_iter_up(&hti
)))
189 type
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
191 if ((sym_tag
== SymTagNull
|| type
->symt
.tag
== sym_tag
) &&
192 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, typename
))
195 SetLastError(ERROR_INVALID_NAME
); /* FIXME ?? */
199 static void symt_add_type(struct module
* module
, struct symt
* symt
)
202 p
= vector_add(&module
->vtypes
, &module
->pool
);
207 struct symt_basic
* symt_new_basic(struct module
* module
, enum BasicType bt
,
208 const char* typename
, unsigned size
)
210 struct symt_basic
* sym
;
214 sym
= (struct symt_basic
*)symt_find_type_by_name(module
, SymTagBaseType
,
216 if (sym
&& sym
->bt
== bt
&& sym
->size
== size
)
219 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
221 sym
->symt
.tag
= SymTagBaseType
;
224 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
225 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
226 } else sym
->hash_elt
.name
= NULL
;
229 symt_add_type(module
, &sym
->symt
);
234 struct symt_udt
* symt_new_udt(struct module
* module
, const char* typename
,
235 unsigned size
, enum UdtKind kind
)
237 struct symt_udt
* sym
;
239 TRACE_(dbghelp_symt
)("Adding udt %s:%s\n",
240 debugstr_w(module
->modulename
), typename
);
241 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
243 sym
->symt
.tag
= SymTagUDT
;
248 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
249 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
250 } else sym
->hash_elt
.name
= NULL
;
251 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
252 symt_add_type(module
, &sym
->symt
);
257 BOOL
symt_set_udt_size(struct module
* module
, struct symt_udt
* udt
, unsigned size
)
259 assert(udt
->symt
.tag
== SymTagUDT
);
260 if (vector_length(&udt
->vchildren
) != 0)
262 if (udt
->size
!= size
)
263 FIXME_(dbghelp_symt
)("Changing size for %s from %u to %u\n",
264 udt
->hash_elt
.name
, udt
->size
, size
);
271 /******************************************************************
272 * symt_add_udt_element
274 * add an element to a udt (struct, class, union)
275 * the size & offset parameters are expressed in bits (not bytes) so that
276 * we can mix in the single call bytes aligned elements (regular fields) and
277 * the others (bit fields)
279 BOOL
symt_add_udt_element(struct module
* module
, struct symt_udt
* udt_type
,
280 const char* name
, struct symt
* elt_type
,
281 unsigned offset
, unsigned bit_offset
, unsigned bit_size
)
286 assert(udt_type
->symt
.tag
== SymTagUDT
);
288 TRACE_(dbghelp_symt
)("Adding %s to UDT %s\n", name
, udt_type
->hash_elt
.name
);
292 for (i
=0; i
<vector_length(&udt_type
->vchildren
); i
++)
294 m
= *(struct symt_data
**)vector_at(&udt_type
->vchildren
, i
);
296 assert(m
->symt
.tag
== SymTagData
);
297 if (strcmp(m
->hash_elt
.name
, name
) == 0)
302 if ((m
= pool_alloc(&module
->pool
, sizeof(*m
))) == NULL
) return FALSE
;
303 memset(m
, 0, sizeof(*m
));
304 m
->symt
.tag
= SymTagData
;
305 m
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : "";
306 m
->hash_elt
.next
= NULL
;
308 m
->kind
= DataIsMember
;
309 m
->container
= &udt_type
->symt
;
311 m
->u
.member
.offset
= offset
;
312 m
->u
.member
.bit_offset
= bit_offset
;
313 m
->u
.member
.bit_length
= bit_size
;
314 p
= vector_add(&udt_type
->vchildren
, &module
->pool
);
320 struct symt_enum
* symt_new_enum(struct module
* module
, const char* typename
,
321 struct symt
* basetype
)
323 struct symt_enum
* sym
;
325 TRACE_(dbghelp_symt
)("Adding enum %s:%s\n",
326 debugstr_w(module
->modulename
), typename
);
327 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
329 sym
->symt
.tag
= SymTagEnum
;
332 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
333 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
334 } else sym
->hash_elt
.name
= NULL
;
335 sym
->base_type
= basetype
;
336 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
337 symt_add_type(module
, &sym
->symt
);
342 BOOL
symt_add_enum_element(struct module
* module
, struct symt_enum
* enum_type
,
343 const char* name
, int value
)
348 assert(enum_type
->symt
.tag
== SymTagEnum
);
349 e
= pool_alloc(&module
->pool
, sizeof(*e
));
350 if (e
== NULL
) return FALSE
;
352 e
->symt
.tag
= SymTagData
;
353 e
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
354 e
->hash_elt
.next
= NULL
;
355 e
->kind
= DataIsConstant
;
356 e
->container
= &enum_type
->symt
;
357 e
->type
= enum_type
->base_type
;
358 e
->u
.value
.n1
.n2
.vt
= VT_I4
;
359 e
->u
.value
.n1
.n2
.n3
.lVal
= value
;
361 p
= vector_add(&enum_type
->vchildren
, &module
->pool
);
362 if (!p
) return FALSE
; /* FIXME we leak e */
368 struct symt_array
* symt_new_array(struct module
* module
, int min
, DWORD cnt
,
369 struct symt
* base
, struct symt
* index
)
371 struct symt_array
* sym
;
373 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
375 sym
->symt
.tag
= SymTagArrayType
;
378 sym
->base_type
= base
;
379 sym
->index_type
= index
;
380 symt_add_type(module
, &sym
->symt
);
385 struct symt_function_signature
* symt_new_function_signature(struct module
* module
,
386 struct symt
* ret_type
,
387 enum CV_call_e call_conv
)
389 struct symt_function_signature
* sym
;
391 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
393 sym
->symt
.tag
= SymTagFunctionType
;
394 sym
->rettype
= ret_type
;
395 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 4);
396 sym
->call_conv
= call_conv
;
397 symt_add_type(module
, &sym
->symt
);
402 BOOL
symt_add_function_signature_parameter(struct module
* module
,
403 struct symt_function_signature
* sig_type
,
407 struct symt_function_arg_type
* arg
;
409 assert(sig_type
->symt
.tag
== SymTagFunctionType
);
410 arg
= pool_alloc(&module
->pool
, sizeof(*arg
));
411 if (!arg
) return FALSE
;
412 arg
->symt
.tag
= SymTagFunctionArgType
;
413 arg
->arg_type
= param
;
414 p
= vector_add(&sig_type
->vchildren
, &module
->pool
);
415 if (!p
) return FALSE
; /* FIXME we leak arg */
421 struct symt_pointer
* symt_new_pointer(struct module
* module
, struct symt
* ref_type
, ULONG_PTR size
)
423 struct symt_pointer
* sym
;
425 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
427 sym
->symt
.tag
= SymTagPointerType
;
428 sym
->pointsto
= ref_type
;
430 symt_add_type(module
, &sym
->symt
);
435 struct symt_typedef
* symt_new_typedef(struct module
* module
, struct symt
* ref
,
438 struct symt_typedef
* sym
;
440 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
442 sym
->symt
.tag
= SymTagTypedef
;
444 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
445 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
446 symt_add_type(module
, &sym
->symt
);
451 /******************************************************************
452 * SymEnumTypes (DBGHELP.@)
455 BOOL WINAPI
SymEnumTypes(HANDLE hProcess
, ULONG64 BaseOfDll
,
456 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
459 struct module_pair pair
;
460 char buffer
[sizeof(SYMBOL_INFO
) + 256];
461 SYMBOL_INFO
* sym_info
= (SYMBOL_INFO
*)buffer
;
466 TRACE("(%p %s %p %p)\n",
467 hProcess
, wine_dbgstr_longlong(BaseOfDll
), EnumSymbolsCallback
,
470 if (!(pair
.pcs
= process_find_by_handle(hProcess
))) return FALSE
;
471 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
472 if (!module_get_debug(&pair
)) return FALSE
;
474 sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
475 sym_info
->MaxNameLen
= sizeof(buffer
) - sizeof(SYMBOL_INFO
);
477 for (i
=0; i
<vector_length(&pair
.effective
->vtypes
); i
++)
479 type
= *(struct symt
**)vector_at(&pair
.effective
->vtypes
, i
);
480 sym_info
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
481 sym_info
->Index
= 0; /* FIXME */
482 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
483 sym_info
->Size
= size
;
484 sym_info
->ModBase
= pair
.requested
->module
.BaseOfImage
;
485 sym_info
->Flags
= 0; /* FIXME */
486 sym_info
->Value
= 0; /* FIXME */
487 sym_info
->Address
= 0; /* FIXME */
488 sym_info
->Register
= 0; /* FIXME */
489 sym_info
->Scope
= 0; /* FIXME */
490 sym_info
->Tag
= type
->tag
;
491 symbol_setname(sym_info
, symt_get_name(type
));
492 if (!EnumSymbolsCallback(sym_info
, sym_info
->Size
, UserContext
)) break;
497 struct enum_types_AtoW
499 char buffer
[sizeof(SYMBOL_INFOW
) + 256 * sizeof(WCHAR
)];
501 PSYM_ENUMERATESYMBOLS_CALLBACKW callback
;
504 static BOOL CALLBACK
enum_types_AtoW(PSYMBOL_INFO si
, ULONG size
, PVOID _et
)
506 struct enum_types_AtoW
* et
= _et
;
507 SYMBOL_INFOW
* siW
= (SYMBOL_INFOW
*)et
->buffer
;
509 copy_symbolW(siW
, si
);
510 return et
->callback(siW
, size
, et
->user
);
513 /******************************************************************
514 * SymEnumTypesW (DBGHELP.@)
517 BOOL WINAPI
SymEnumTypesW(HANDLE hProcess
, ULONG64 BaseOfDll
,
518 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
521 struct enum_types_AtoW et
;
523 et
.callback
= EnumSymbolsCallback
;
524 et
.user
= UserContext
;
526 return SymEnumTypes(hProcess
, BaseOfDll
, enum_types_AtoW
, &et
);
529 /******************************************************************
532 * Retrieves information about a symt (either symbol or type)
534 BOOL
symt_get_info(struct module
* module
, const struct symt
* type
,
535 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
)
539 if (!type
) return FALSE
;
541 /* helper to typecast pInfo to its expected type (_t) */
542 #define X(_t) (*((_t*)pInfo))
546 case TI_FINDCHILDREN
:
548 const struct vector
* v
;
551 TI_FINDCHILDREN_PARAMS
* tifp
= pInfo
;
555 case SymTagExe
: v
= &((const struct symt_module
*)type
)->vchildren
; break;
556 case SymTagCompiland
: v
= &((const struct symt_compiland
*)type
)->vchildren
; break;
557 case SymTagUDT
: v
= &((const struct symt_udt
*)type
)->vchildren
; break;
558 case SymTagEnum
: v
= &((const struct symt_enum
*)type
)->vchildren
; break;
559 case SymTagFunctionType
: v
= &((const struct symt_function_signature
*)type
)->vchildren
; break;
560 case SymTagFunction
: v
= &((const struct symt_function
*)type
)->vchildren
; break;
561 case SymTagBlock
: v
= &((const struct symt_block
*)type
)->vchildren
; break;
562 case SymTagPointerType
:
563 case SymTagArrayType
:
564 case SymTagFunctionArgType
:
567 case SymTagFuncDebugStart
:
568 case SymTagFuncDebugEnd
:
571 /* for those, CHILDRENCOUNT returns 0 */
572 return tifp
->Count
== 0;
574 FIXME("Unsupported sym-tag %s for find-children\n",
575 symt_get_tag_str(type
->tag
));
578 for (i
= 0; i
< tifp
->Count
; i
++)
580 if (!(pt
= vector_at(v
, tifp
->Start
+ i
))) return FALSE
;
581 tifp
->ChildId
[i
] = symt_ptr2index(module
, *pt
);
587 return symt_get_address(type
, (ULONG64
*)pInfo
);
589 case TI_GET_BASETYPE
:
593 X(DWORD
) = ((const struct symt_basic
*)type
)->bt
;
603 case TI_GET_BITPOSITION
:
604 if (type
->tag
== SymTagData
&&
605 ((const struct symt_data
*)type
)->kind
== DataIsMember
&&
606 ((const struct symt_data
*)type
)->u
.member
.bit_length
!= 0)
607 X(DWORD
) = ((const struct symt_data
*)type
)->u
.member
.bit_offset
;
611 case TI_GET_CHILDRENCOUNT
:
615 X(DWORD
) = vector_length(&((const struct symt_module
*)type
)->vchildren
);
617 case SymTagCompiland
:
618 X(DWORD
) = vector_length(&((const struct symt_compiland
*)type
)->vchildren
);
621 X(DWORD
) = vector_length(&((const struct symt_udt
*)type
)->vchildren
);
624 X(DWORD
) = vector_length(&((const struct symt_enum
*)type
)->vchildren
);
626 case SymTagFunctionType
:
627 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
630 X(DWORD
) = vector_length(&((const struct symt_function
*)type
)->vchildren
);
633 X(DWORD
) = vector_length(&((const struct symt_block
*)type
)->vchildren
);
635 /* some SymTag:s return 0 */
636 case SymTagPointerType
:
637 case SymTagArrayType
:
638 case SymTagFunctionArgType
:
640 case SymTagFuncDebugStart
:
641 case SymTagFuncDebugEnd
:
648 FIXME("Unsupported sym-tag %s for get-children-count\n",
649 symt_get_tag_str(type
->tag
));
651 /* some others return error */
653 case SymTagPublicSymbol
:
661 case SymTagArrayType
:
662 X(DWORD
) = ((const struct symt_array
*)type
)->count
;
664 case SymTagFunctionType
:
665 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
666 * should be included in this value (and not in GET_CHILDREN_COUNT)
668 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
670 default: return FALSE
;
674 case TI_GET_DATAKIND
:
675 if (type
->tag
!= SymTagData
) return FALSE
;
676 X(DWORD
) = ((const struct symt_data
*)type
)->kind
;
683 X(DWORD64
) = ((const struct symt_basic
*)type
)->size
;
686 X(DWORD64
) = ((const struct symt_function
*)type
)->size
;
689 X(DWORD64
) = ((const struct symt_block
*)type
)->size
;
691 case SymTagPointerType
:
692 X(DWORD64
) = ((const struct symt_pointer
*)type
)->size
;
695 X(DWORD64
) = ((const struct symt_udt
*)type
)->size
;
698 if (!symt_get_info(module
, ((const struct symt_enum
*)type
)->base_type
, TI_GET_LENGTH
, pInfo
))
702 if (((const struct symt_data
*)type
)->kind
!= DataIsMember
||
703 !((const struct symt_data
*)type
)->u
.member
.bit_length
)
705 X(DWORD64
) = ((const struct symt_data
*)type
)->u
.member
.bit_length
;
707 case SymTagArrayType
:
708 if (!symt_get_info(module
, ((const struct symt_array
*)type
)->base_type
,
709 TI_GET_LENGTH
, pInfo
))
711 X(DWORD64
) *= ((const struct symt_array
*)type
)->count
;
713 case SymTagPublicSymbol
:
714 X(DWORD64
) = ((const struct symt_public
*)type
)->size
;
717 return symt_get_info(module
, ((const struct symt_typedef
*)type
)->type
, TI_GET_LENGTH
, pInfo
);
719 X(DWORD64
) = ((const struct symt_thunk
*)type
)->size
;
725 FIXME("Unsupported sym-tag %s for get-length\n",
726 symt_get_tag_str(type
->tag
));
729 case SymTagCompiland
:
730 case SymTagFunctionType
:
735 case TI_GET_LEXICALPARENT
:
738 case SymTagCompiland
:
739 X(DWORD
) = symt_ptr2index(module
, &((const struct symt_compiland
*)type
)->container
->symt
);
742 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_block
*)type
)->container
);
745 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->container
);
748 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->container
);
751 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_thunk
*)type
)->container
);
755 case SymTagFunctionArgType
:
756 X(DWORD
) = symt_ptr2index(module
, &module
->top
->symt
);
759 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
760 symt_get_tag_str(type
->tag
));
783 switch (((const struct symt_data
*)type
)->kind
)
787 X(ULONG
) = ((const struct symt_data
*)type
)->u
.var
.offset
;
790 X(ULONG
) = ((const struct symt_data
*)type
)->u
.member
.offset
;
793 FIXME("Unknown kind (%u) for get-offset\n",
794 ((const struct symt_data
*)type
)->kind
);
799 FIXME("Unsupported sym-tag %s for get-offset\n",
800 symt_get_tag_str(type
->tag
));
806 if (type
->tag
== SymTagExe
)
808 DWORD len
= (lstrlenW(module
->modulename
) + 1) * sizeof(WCHAR
);
809 WCHAR
* wname
= HeapAlloc(GetProcessHeap(), 0, len
);
810 if (!wname
) return FALSE
;
811 memcpy(wname
, module
->modulename
, len
);
816 const char* name
= symt_get_name(type
);
817 if (!name
) return FALSE
;
818 len
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
819 X(WCHAR
*) = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
820 if (!X(WCHAR
*)) return FALSE
;
821 MultiByteToWideChar(CP_ACP
, 0, name
, -1, X(WCHAR
*), len
);
826 X(DWORD
) = type
->tag
;
833 /* hierarchical => hierarchical */
834 case SymTagArrayType
:
835 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->base_type
);
837 case SymTagPointerType
:
838 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_pointer
*)type
)->pointsto
);
840 case SymTagFunctionType
:
841 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_signature
*)type
)->rettype
);
844 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_typedef
*)type
)->type
);
846 /* lexical => hierarchical */
848 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->type
);
851 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->type
);
854 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_enum
*)type
)->base_type
);
856 case SymTagFunctionArgType
:
857 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->arg_type
);
860 FIXME("Unsupported sym-tag %s for get-type\n",
861 symt_get_tag_str(type
->tag
));
863 case SymTagPublicSymbol
:
871 if (type
->tag
!= SymTagUDT
) return FALSE
;
872 X(DWORD
) = ((const struct symt_udt
*)type
)->kind
;
876 if (type
->tag
!= SymTagData
) return FALSE
;
877 switch (((const struct symt_data
*)type
)->kind
)
879 case DataIsConstant
: X(VARIANT
) = ((const struct symt_data
*)type
)->u
.value
; break;
883 struct location loc
= ((const struct symt_data
*)type
)->u
.var
;
885 struct module_format
* modfmt
;
887 if (loc
.kind
< loc_user
) return FALSE
;
888 for (i
= 0; i
< DFI_LAST
; i
++)
890 modfmt
= module
->format_info
[i
];
891 if (modfmt
&& modfmt
->loc_compute
)
893 modfmt
->loc_compute(module
->process
, modfmt
,
894 (const struct symt_function
*)((const struct symt_data
*)type
)->container
, &loc
);
898 if (loc
.kind
!= loc_absolute
) return FALSE
;
899 X(VARIANT
).n1
.n2
.vt
= VT_UI4
; /* FIXME */
900 X(VARIANT
).n1
.n2
.n3
.uiVal
= loc
.offset
;
903 default: return FALSE
;
907 case TI_GET_CALLING_CONVENTION
:
908 if (type
->tag
!= SymTagFunctionType
) return FALSE
;
909 if (((const struct symt_function_signature
*)type
)->call_conv
== -1)
911 FIXME("No support for calling convention for this signature\n");
912 X(DWORD
) = CV_CALL_FAR_C
; /* FIXME */
914 else X(DWORD
) = ((const struct symt_function_signature
*)type
)->call_conv
;
916 case TI_GET_ARRAYINDEXTYPEID
:
917 if (type
->tag
!= SymTagArrayType
) return FALSE
;
918 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->index_type
);
921 case TI_GET_CLASSPARENTID
:
922 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
923 * belong to a parent class
929 case TI_GET_ADDRESSOFFSET
:
930 case TI_GET_SYMINDEX
:
931 case TI_GET_THISADJUST
:
932 case TI_GET_VIRTUALBASECLASS
:
933 case TI_GET_VIRTUALBASEPOINTEROFFSET
:
934 case TI_GET_VIRTUALTABLESHAPEID
:
936 FIXME("Unsupported GetInfo request (%u)\n", req
);
939 FIXME("Unknown GetInfo request (%u)\n", req
);
946 /******************************************************************
947 * SymGetTypeInfo (DBGHELP.@)
950 BOOL WINAPI
SymGetTypeInfo(HANDLE hProcess
, DWORD64 ModBase
,
951 ULONG TypeId
, IMAGEHLP_SYMBOL_TYPE_INFO GetType
,
954 struct module_pair pair
;
956 pair
.pcs
= process_find_by_handle(hProcess
);
957 if (!pair
.pcs
) return FALSE
;
959 pair
.requested
= module_find_by_addr(pair
.pcs
, ModBase
, DMT_UNKNOWN
);
960 if (!module_get_debug(&pair
))
962 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase
));
966 return symt_get_info(pair
.effective
, symt_index2ptr(pair
.effective
, TypeId
), GetType
, pInfo
);
969 /******************************************************************
970 * SymGetTypeFromName (DBGHELP.@)
973 BOOL WINAPI
SymGetTypeFromName(HANDLE hProcess
, ULONG64 BaseOfDll
,
974 PCSTR Name
, PSYMBOL_INFO Symbol
)
976 struct module_pair pair
;
980 pair
.pcs
= process_find_by_handle(hProcess
);
981 if (!pair
.pcs
) return FALSE
;
982 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
983 if (!module_get_debug(&pair
)) return FALSE
;
984 type
= symt_find_type_by_name(pair
.effective
, SymTagNull
, Name
);
985 if (!type
) return FALSE
;
986 Symbol
->Index
= Symbol
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
987 symbol_setname(Symbol
, symt_get_name(type
));
988 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
990 Symbol
->ModBase
= pair
.requested
->module
.BaseOfImage
;
991 Symbol
->Tag
= type
->tag
;