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
32 #ifndef DBGHELP_STATIC_LIB
36 #include "wine/debug.h"
38 #include "dbghelp_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
41 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt
);
43 static const char* symt_get_tag_str(DWORD tag
)
47 case SymTagNull
: return "SymTagNull";
48 case SymTagExe
: return "SymTagExe";
49 case SymTagCompiland
: return "SymTagCompiland";
50 case SymTagCompilandDetails
: return "SymTagCompilandDetails";
51 case SymTagCompilandEnv
: return "SymTagCompilandEnv";
52 case SymTagFunction
: return "SymTagFunction";
53 case SymTagBlock
: return "SymTagBlock";
54 case SymTagData
: return "SymTagData";
55 case SymTagAnnotation
: return "SymTagAnnotation";
56 case SymTagLabel
: return "SymTagLabel";
57 case SymTagPublicSymbol
: return "SymTagPublicSymbol";
58 case SymTagUDT
: return "SymTagUDT";
59 case SymTagEnum
: return "SymTagEnum";
60 case SymTagFunctionType
: return "SymTagFunctionType";
61 case SymTagPointerType
: return "SymTagPointerType";
62 case SymTagArrayType
: return "SymTagArrayType";
63 case SymTagBaseType
: return "SymTagBaseType";
64 case SymTagTypedef
: return "SymTagTypedef,";
65 case SymTagBaseClass
: return "SymTagBaseClass";
66 case SymTagFriend
: return "SymTagFriend";
67 case SymTagFunctionArgType
: return "SymTagFunctionArgType,";
68 case SymTagFuncDebugStart
: return "SymTagFuncDebugStart,";
69 case SymTagFuncDebugEnd
: return "SymTagFuncDebugEnd";
70 case SymTagUsingNamespace
: return "SymTagUsingNamespace,";
71 case SymTagVTableShape
: return "SymTagVTableShape";
72 case SymTagVTable
: return "SymTagVTable";
73 case SymTagCustom
: return "SymTagCustom";
74 case SymTagThunk
: return "SymTagThunk";
75 case SymTagCustomType
: return "SymTagCustomType";
76 case SymTagManagedType
: return "SymTagManagedType";
77 case SymTagDimension
: return "SymTagDimension";
78 default: return "---";
82 const char* symt_get_name(const struct symt
* sym
)
87 case SymTagData
: return ((const struct symt_data
*)sym
)->hash_elt
.name
;
88 case SymTagFunction
: return ((const struct symt_function
*)sym
)->hash_elt
.name
;
89 case SymTagPublicSymbol
: return ((const struct symt_public
*)sym
)->hash_elt
.name
;
90 case SymTagBaseType
: return ((const struct symt_basic
*)sym
)->hash_elt
.name
;
91 case SymTagLabel
: return ((const struct symt_hierarchy_point
*)sym
)->hash_elt
.name
;
92 case SymTagThunk
: return ((const struct symt_thunk
*)sym
)->hash_elt
.name
;
94 case SymTagEnum
: return ((const struct symt_enum
*)sym
)->name
;
95 case SymTagTypedef
: return ((const struct symt_typedef
*)sym
)->hash_elt
.name
;
96 case SymTagUDT
: return ((const struct symt_udt
*)sym
)->hash_elt
.name
;
98 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym
->tag
));
100 case SymTagArrayType
:
101 case SymTagPointerType
:
102 case SymTagFunctionType
:
107 WCHAR
* symt_get_nameW(const struct symt
* sym
)
109 const char* name
= symt_get_name(sym
);
113 if (!name
) return NULL
;
114 sz
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
115 if ((nameW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
116 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sz
);
120 BOOL
symt_get_address(const struct symt
* type
, ULONG64
* addr
)
125 switch (((const struct symt_data
*)type
)->kind
)
128 case DataIsFileStatic
:
129 *addr
= ((const struct symt_data
*)type
)->u
.var
.offset
;
131 default: return FALSE
;
135 *addr
= ((const struct symt_function
*)type
)->address
;
137 case SymTagPublicSymbol
:
138 *addr
= ((const struct symt_public
*)type
)->address
;
140 case SymTagFuncDebugStart
:
141 case SymTagFuncDebugEnd
:
143 if (!((const struct symt_hierarchy_point
*)type
)->parent
||
144 !symt_get_address(((const struct symt_hierarchy_point
*)type
)->parent
, addr
))
146 *addr
+= ((const struct symt_hierarchy_point
*)type
)->loc
.offset
;
149 *addr
= ((const struct symt_thunk
*)type
)->address
;
151 case SymTagCompiland
:
152 *addr
= ((const struct symt_compiland
*)type
)->address
;
155 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type
->tag
));
161 static struct symt
* symt_find_type_by_name(const struct module
* module
,
162 enum SymTagEnum sym_tag
,
163 const char* typename
)
166 struct symt_ht
* type
;
167 struct hash_table_iter hti
;
172 hash_table_iter_init(&module
->ht_types
, &hti
, typename
);
173 while ((ptr
= hash_table_iter_up(&hti
)))
175 type
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
177 if ((sym_tag
== SymTagNull
|| type
->symt
.tag
== sym_tag
) &&
178 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, typename
))
181 SetLastError(ERROR_INVALID_NAME
); /* FIXME ?? */
185 static void symt_add_type(struct module
* module
, struct symt
* symt
)
188 p
= vector_add(&module
->vtypes
, &module
->pool
);
193 struct symt_basic
* symt_new_basic(struct module
* module
, enum BasicType bt
,
194 const char* typename
, unsigned size
)
196 struct symt_basic
* sym
;
200 sym
= (struct symt_basic
*)symt_find_type_by_name(module
, SymTagBaseType
,
202 if (sym
&& sym
->bt
== bt
&& sym
->size
== size
)
205 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
207 sym
->symt
.tag
= SymTagBaseType
;
210 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
211 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
212 } else sym
->hash_elt
.name
= NULL
;
215 symt_add_type(module
, &sym
->symt
);
220 struct symt_udt
* symt_new_udt(struct module
* module
, const char* typename
,
221 unsigned size
, enum UdtKind kind
)
223 struct symt_udt
* sym
;
225 TRACE_(dbghelp_symt
)("Adding udt %s:%s\n",
226 debugstr_w(module
->module
.ModuleName
), typename
);
227 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
229 sym
->symt
.tag
= SymTagUDT
;
234 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
235 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
236 } else sym
->hash_elt
.name
= NULL
;
237 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
238 symt_add_type(module
, &sym
->symt
);
243 BOOL
symt_set_udt_size(struct module
* module
, struct symt_udt
* udt
, unsigned size
)
245 assert(udt
->symt
.tag
== SymTagUDT
);
246 if (vector_length(&udt
->vchildren
) != 0)
248 if (udt
->size
!= size
)
249 FIXME_(dbghelp_symt
)("Changing size for %s from %u to %u\n",
250 udt
->hash_elt
.name
, udt
->size
, size
);
257 /******************************************************************
258 * symt_add_udt_element
260 * add an element to a udt (struct, class, union)
261 * the size & offset parameters are expressed in bits (not bytes) so that
262 * we can mix in the single call bytes aligned elements (regular fields) and
263 * the others (bit fields)
265 BOOL
symt_add_udt_element(struct module
* module
, struct symt_udt
* udt_type
,
266 const char* name
, struct symt
* elt_type
,
267 unsigned offset
, unsigned size
)
272 assert(udt_type
->symt
.tag
== SymTagUDT
);
274 TRACE_(dbghelp_symt
)("Adding %s to UDT %s\n", name
, udt_type
->hash_elt
.name
);
278 for (i
=0; i
<vector_length(&udt_type
->vchildren
); i
++)
280 m
= *(struct symt_data
**)vector_at(&udt_type
->vchildren
, i
);
282 assert(m
->symt
.tag
== SymTagData
);
283 if (strcmp(m
->hash_elt
.name
, name
) == 0)
288 if ((m
= pool_alloc(&module
->pool
, sizeof(*m
))) == NULL
) return FALSE
;
289 memset(m
, 0, sizeof(*m
));
290 m
->symt
.tag
= SymTagData
;
291 m
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : "";
292 m
->hash_elt
.next
= NULL
;
294 m
->kind
= DataIsMember
;
295 m
->container
= &udt_type
->symt
;
297 m
->u
.member
.offset
= offset
;
298 m
->u
.member
.length
= ((offset
& 7) || (size
& 7)) ? size
: 0;
299 p
= vector_add(&udt_type
->vchildren
, &module
->pool
);
305 struct symt_enum
* symt_new_enum(struct module
* module
, const char* typename
,
306 struct symt
* basetype
)
308 struct symt_enum
* sym
;
310 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
312 sym
->symt
.tag
= SymTagEnum
;
313 sym
->name
= (typename
) ? pool_strdup(&module
->pool
, typename
) : NULL
;
314 sym
->base_type
= basetype
;
315 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
320 BOOL
symt_add_enum_element(struct module
* module
, struct symt_enum
* enum_type
,
321 const char* name
, int value
)
326 assert(enum_type
->symt
.tag
== SymTagEnum
);
327 e
= pool_alloc(&module
->pool
, sizeof(*e
));
328 if (e
== NULL
) return FALSE
;
330 e
->symt
.tag
= SymTagData
;
331 e
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
332 e
->hash_elt
.next
= NULL
;
333 e
->kind
= DataIsConstant
;
334 e
->container
= &enum_type
->symt
;
335 e
->type
= enum_type
->base_type
;
336 e
->u
.value
.n1
.n2
.vt
= VT_I4
;
337 e
->u
.value
.n1
.n2
.n3
.lVal
= value
;
339 p
= vector_add(&enum_type
->vchildren
, &module
->pool
);
340 if (!p
) return FALSE
; /* FIXME we leak e */
346 struct symt_array
* symt_new_array(struct module
* module
, int min
, int max
,
347 struct symt
* base
, struct symt
* index
)
349 struct symt_array
* sym
;
351 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
353 sym
->symt
.tag
= SymTagArrayType
;
356 sym
->base_type
= base
;
357 sym
->index_type
= index
;
358 symt_add_type(module
, &sym
->symt
);
363 static inline DWORD
symt_array_count(struct module
* module
, const struct symt_array
* array
)
368 /* One could want to also set the array->end field in array, but we won't do it
369 * as long as all the get_type() helpers use const objects
371 if (symt_get_info(module
, array
->base_type
, TI_GET_LENGTH
, &elem_size
) && elem_size
)
372 return -array
->end
/ (DWORD
)elem_size
;
375 return array
->end
- array
->start
+ 1;
378 struct symt_function_signature
* symt_new_function_signature(struct module
* module
,
379 struct symt
* ret_type
,
380 enum CV_call_e call_conv
)
382 struct symt_function_signature
* sym
;
384 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
386 sym
->symt
.tag
= SymTagFunctionType
;
387 sym
->rettype
= ret_type
;
388 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 4);
389 sym
->call_conv
= call_conv
;
390 symt_add_type(module
, &sym
->symt
);
395 BOOL
symt_add_function_signature_parameter(struct module
* module
,
396 struct symt_function_signature
* sig_type
,
400 struct symt_function_arg_type
* arg
;
402 assert(sig_type
->symt
.tag
== SymTagFunctionType
);
403 arg
= pool_alloc(&module
->pool
, sizeof(*arg
));
404 if (!arg
) return FALSE
;
405 arg
->symt
.tag
= SymTagFunctionArgType
;
406 arg
->arg_type
= param
;
407 arg
->container
= &sig_type
->symt
;
408 p
= vector_add(&sig_type
->vchildren
, &module
->pool
);
409 if (!p
) return FALSE
; /* FIXME we leak arg */
415 struct symt_pointer
* symt_new_pointer(struct module
* module
, struct symt
* ref_type
, unsigned long size
)
417 struct symt_pointer
* sym
;
419 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
421 sym
->symt
.tag
= SymTagPointerType
;
422 sym
->pointsto
= ref_type
;
424 symt_add_type(module
, &sym
->symt
);
429 struct symt_typedef
* symt_new_typedef(struct module
* module
, struct symt
* ref
,
432 struct symt_typedef
* sym
;
434 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
436 sym
->symt
.tag
= SymTagTypedef
;
438 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
439 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
440 symt_add_type(module
, &sym
->symt
);
445 /******************************************************************
446 * SymEnumTypes (DBGHELP.@)
449 BOOL WINAPI
SymEnumTypes(HANDLE hProcess
, ULONG64 BaseOfDll
,
450 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
453 struct module_pair pair
;
454 char buffer
[sizeof(SYMBOL_INFO
) + 256];
455 SYMBOL_INFO
* sym_info
= (SYMBOL_INFO
*)buffer
;
461 TRACE("(%p %s %p %p)\n",
462 hProcess
, wine_dbgstr_longlong(BaseOfDll
), EnumSymbolsCallback
,
465 if (!(pair
.pcs
= process_find_by_handle(hProcess
))) return FALSE
;
466 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
467 if (!module_get_debug(&pair
)) return FALSE
;
469 sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
470 sym_info
->MaxNameLen
= sizeof(buffer
) - sizeof(SYMBOL_INFO
);
472 for (i
=0; i
<vector_length(&pair
.effective
->vtypes
); i
++)
474 type
= *(struct symt
**)vector_at(&pair
.effective
->vtypes
, i
);
475 sym_info
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
476 sym_info
->Index
= 0; /* FIXME */
477 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
478 sym_info
->Size
= size
;
479 sym_info
->ModBase
= pair
.requested
->module
.BaseOfImage
;
480 sym_info
->Flags
= 0; /* FIXME */
481 sym_info
->Value
= 0; /* FIXME */
482 sym_info
->Address
= 0; /* FIXME */
483 sym_info
->Register
= 0; /* FIXME */
484 sym_info
->Scope
= 0; /* FIXME */
485 sym_info
->Tag
= type
->tag
;
486 tmp
= symt_get_name(type
);
489 sym_info
->NameLen
= min(strlen(tmp
),sym_info
->MaxNameLen
-1);
490 memcpy(sym_info
->Name
, tmp
, sym_info
->NameLen
);
491 sym_info
->Name
[sym_info
->NameLen
] = '\0';
494 sym_info
->Name
[sym_info
->NameLen
= 0] = '\0';
495 if (!EnumSymbolsCallback(sym_info
, sym_info
->Size
, UserContext
)) break;
500 struct enum_types_AtoW
502 char buffer
[sizeof(SYMBOL_INFOW
) + 256 * sizeof(WCHAR
)];
504 PSYM_ENUMERATESYMBOLS_CALLBACKW callback
;
507 static BOOL CALLBACK
enum_types_AtoW(PSYMBOL_INFO si
, ULONG addr
, PVOID _et
)
509 struct enum_types_AtoW
* et
= _et
;
510 SYMBOL_INFOW
* siW
= (SYMBOL_INFOW
*)et
->buffer
;
512 copy_symbolW(siW
, si
);
513 return et
->callback(siW
, addr
, et
->user
);
516 /******************************************************************
517 * SymEnumTypesW (DBGHELP.@)
520 BOOL WINAPI
SymEnumTypesW(HANDLE hProcess
, ULONG64 BaseOfDll
,
521 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
524 struct enum_types_AtoW et
;
526 et
.callback
= EnumSymbolsCallback
;
527 et
.user
= UserContext
;
529 return SymEnumTypes(hProcess
, BaseOfDll
, enum_types_AtoW
, &et
);
532 /******************************************************************
535 * Retrieves information about a symt (either symbol or type)
537 BOOL
symt_get_info(struct module
* module
, const struct symt
* type
,
538 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
)
542 if (!type
) return FALSE
;
544 /* helper to typecast pInfo to its expected type (_t) */
545 #define X(_t) (*((_t*)pInfo))
549 case TI_FINDCHILDREN
:
551 const struct vector
* v
;
554 TI_FINDCHILDREN_PARAMS
* tifp
= pInfo
;
558 case SymTagUDT
: v
= &((const struct symt_udt
*)type
)->vchildren
; break;
559 case SymTagEnum
: v
= &((const struct symt_enum
*)type
)->vchildren
; break;
560 case SymTagFunctionType
: v
= &((const struct symt_function_signature
*)type
)->vchildren
; break;
561 case SymTagFunction
: v
= &((const struct symt_function
*)type
)->vchildren
; break;
563 FIXME("Unsupported sym-tag %s for find-children\n",
564 symt_get_tag_str(type
->tag
));
567 for (i
= 0; i
< tifp
->Count
; i
++)
569 if (!(pt
= vector_at(v
, tifp
->Start
+ i
))) return FALSE
;
570 tifp
->ChildId
[i
] = symt_ptr2index(module
, *pt
);
576 return symt_get_address(type
, (ULONG64
*)pInfo
);
578 case TI_GET_BASETYPE
:
582 X(DWORD
) = ((const struct symt_basic
*)type
)->bt
;
592 case TI_GET_BITPOSITION
:
593 if (type
->tag
== SymTagData
&&
594 ((const struct symt_data
*)type
)->kind
== DataIsMember
&&
595 ((const struct symt_data
*)type
)->u
.member
.length
!= 0)
596 X(DWORD
) = ((const struct symt_data
*)type
)->u
.member
.offset
& 7;
600 case TI_GET_CHILDRENCOUNT
:
604 X(DWORD
) = vector_length(&((const struct symt_udt
*)type
)->vchildren
);
607 X(DWORD
) = vector_length(&((const struct symt_enum
*)type
)->vchildren
);
609 case SymTagFunctionType
:
610 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
613 X(DWORD
) = vector_length(&((const struct symt_function
*)type
)->vchildren
);
615 case SymTagPointerType
: /* MS does it that way */
616 case SymTagArrayType
: /* MS does it that way */
617 case SymTagThunk
: /* MS does it that way */
621 FIXME("Unsupported sym-tag %s for get-children-count\n",
622 symt_get_tag_str(type
->tag
));
625 case SymTagPublicSymbol
:
634 case SymTagArrayType
:
635 X(DWORD
) = symt_array_count(module
, (const struct symt_array
*)type
);
637 case SymTagFunctionType
:
638 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
639 * should be included in this value (and not in GET_CHILDREN_COUNT)
641 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
643 default: return FALSE
;
647 case TI_GET_DATAKIND
:
648 if (type
->tag
!= SymTagData
) return FALSE
;
649 X(DWORD
) = ((const struct symt_data
*)type
)->kind
;
656 X(DWORD64
) = ((const struct symt_basic
*)type
)->size
;
659 X(DWORD64
) = ((const struct symt_function
*)type
)->size
;
661 case SymTagPointerType
:
662 X(DWORD64
) = ((const struct symt_pointer
*)type
)->size
;
665 X(DWORD64
) = ((const struct symt_udt
*)type
)->size
;
668 X(DWORD64
) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
671 if (((const struct symt_data
*)type
)->kind
!= DataIsMember
||
672 !((const struct symt_data
*)type
)->u
.member
.length
)
674 X(DWORD64
) = ((const struct symt_data
*)type
)->u
.member
.length
;
676 case SymTagArrayType
:
677 if (!symt_get_info(module
, ((const struct symt_array
*)type
)->base_type
,
678 TI_GET_LENGTH
, pInfo
))
680 X(DWORD64
) *= symt_array_count(module
, (const struct symt_array
*)type
);
682 case SymTagPublicSymbol
:
683 X(DWORD64
) = ((const struct symt_public
*)type
)->size
;
686 return symt_get_info(module
, ((const struct symt_typedef
*)type
)->type
, TI_GET_LENGTH
, pInfo
);
688 X(DWORD64
) = ((const struct symt_thunk
*)type
)->size
;
694 FIXME("Unsupported sym-tag %s for get-length\n",
695 symt_get_tag_str(type
->tag
));
697 case SymTagFunctionType
:
702 case TI_GET_LEXICALPARENT
:
706 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_block
*)type
)->container
);
709 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->container
);
712 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->container
);
715 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_thunk
*)type
)->container
);
717 case SymTagFunctionArgType
:
718 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->container
);
721 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
722 symt_get_tag_str(type
->tag
));
743 switch (((const struct symt_data
*)type
)->kind
)
747 X(ULONG
) = ((const struct symt_data
*)type
)->u
.var
.offset
;
750 X(ULONG
) = ((const struct symt_data
*)type
)->u
.member
.offset
>> 3;
753 FIXME("Unknown kind (%u) for get-offset\n",
754 ((const struct symt_data
*)type
)->kind
);
759 FIXME("Unsupported sym-tag %s for get-offset\n",
760 symt_get_tag_str(type
->tag
));
767 const char* name
= symt_get_name(type
);
768 if (!name
) return FALSE
;
769 len
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
770 X(WCHAR
*) = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
771 if (!X(WCHAR
*)) return FALSE
;
772 MultiByteToWideChar(CP_ACP
, 0, name
, -1, X(WCHAR
*), len
);
777 X(DWORD
) = type
->tag
;
784 /* hierarchical => hierarchical */
785 case SymTagArrayType
:
786 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->base_type
);
788 case SymTagPointerType
:
789 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_pointer
*)type
)->pointsto
);
791 case SymTagFunctionType
:
792 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_signature
*)type
)->rettype
);
795 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_typedef
*)type
)->type
);
797 /* lexical => hierarchical */
799 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->type
);
802 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->type
);
805 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_enum
*)type
)->base_type
);
807 case SymTagFunctionArgType
:
808 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->arg_type
);
811 FIXME("Unsupported sym-tag %s for get-type\n",
812 symt_get_tag_str(type
->tag
));
814 case SymTagPublicSymbol
:
822 if (type
->tag
!= SymTagUDT
) return FALSE
;
823 X(DWORD
) = ((const struct symt_udt
*)type
)->kind
;
827 if (type
->tag
!= SymTagData
) return FALSE
;
828 switch (((const struct symt_data
*)type
)->kind
)
830 case DataIsConstant
: X(VARIANT
) = ((const struct symt_data
*)type
)->u
.value
; break;
834 struct location loc
= ((const struct symt_data
*)type
)->u
.var
;
836 struct module_format
* modfmt
;
838 if (loc
.kind
< loc_user
) return FALSE
;
839 for (i
= 0; i
< DFI_LAST
; i
++)
841 modfmt
= module
->format_info
[i
];
842 if (modfmt
&& modfmt
->loc_compute
)
844 modfmt
->loc_compute(module
->process
, modfmt
,
845 (const struct symt_function
*)((const struct symt_data
*)type
)->container
, &loc
);
849 if (loc
.kind
!= loc_absolute
) return FALSE
;
850 X(VARIANT
).n1
.n2
.vt
= VT_UI4
; /* FIXME */
851 X(VARIANT
).n1
.n2
.n3
.uiVal
= loc
.offset
;
854 default: return FALSE
;
858 case TI_GET_CALLING_CONVENTION
:
859 if (type
->tag
!= SymTagFunctionType
) return FALSE
;
860 if (((const struct symt_function_signature
*)type
)->call_conv
== -1)
862 FIXME("No support for calling convention for this signature\n");
863 X(DWORD
) = CV_CALL_FAR_C
; /* FIXME */
865 else X(DWORD
) = ((const struct symt_function_signature
*)type
)->call_conv
;
867 case TI_GET_ARRAYINDEXTYPEID
:
868 if (type
->tag
!= SymTagArrayType
) return FALSE
;
869 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->index_type
);
872 case TI_GET_CLASSPARENTID
:
873 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
874 * belong to a parent class
880 case TI_GET_ADDRESSOFFSET
:
881 case TI_GET_SYMINDEX
:
882 case TI_GET_THISADJUST
:
883 case TI_GET_VIRTUALBASECLASS
:
884 case TI_GET_VIRTUALBASEPOINTEROFFSET
:
885 case TI_GET_VIRTUALTABLESHAPEID
:
887 FIXME("Unsupported GetInfo request (%u)\n", req
);
890 FIXME("Unknown GetInfo request (%u)\n", req
);
897 /******************************************************************
898 * SymGetTypeInfo (DBGHELP.@)
901 BOOL WINAPI
SymGetTypeInfo(HANDLE hProcess
, DWORD64 ModBase
,
902 ULONG TypeId
, IMAGEHLP_SYMBOL_TYPE_INFO GetType
,
905 struct module_pair pair
;
907 pair
.pcs
= process_find_by_handle(hProcess
);
908 if (!pair
.pcs
) return FALSE
;
910 pair
.requested
= module_find_by_addr(pair
.pcs
, ModBase
, DMT_UNKNOWN
);
911 if (!module_get_debug(&pair
))
913 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase
));
917 return symt_get_info(pair
.effective
, symt_index2ptr(pair
.effective
, TypeId
), GetType
, pInfo
);
920 /******************************************************************
921 * SymGetTypeFromName (DBGHELP.@)
924 BOOL WINAPI
SymGetTypeFromName(HANDLE hProcess
, ULONG64 BaseOfDll
,
925 PCSTR Name
, PSYMBOL_INFO Symbol
)
927 struct process
* pcs
= process_find_by_handle(hProcess
);
928 struct module_pair pair
;
931 if (!pcs
) return FALSE
;
932 pair
.requested
= module_find_by_addr(pcs
, BaseOfDll
, DMT_UNKNOWN
);
933 if (!module_get_debug(&pair
)) return FALSE
;
934 type
= symt_find_type_by_name(pair
.effective
, SymTagNull
, Name
);
935 if (!type
) return FALSE
;
936 Symbol
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);