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"
39 #include "dbghelp_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
42 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt
);
44 static const char* symt_get_tag_str(DWORD tag
)
48 case SymTagNull
: return "SymTagNull";
49 case SymTagExe
: return "SymTagExe";
50 case SymTagCompiland
: return "SymTagCompiland";
51 case SymTagCompilandDetails
: return "SymTagCompilandDetails";
52 case SymTagCompilandEnv
: return "SymTagCompilandEnv";
53 case SymTagFunction
: return "SymTagFunction";
54 case SymTagBlock
: return "SymTagBlock";
55 case SymTagData
: return "SymTagData";
56 case SymTagAnnotation
: return "SymTagAnnotation";
57 case SymTagLabel
: return "SymTagLabel";
58 case SymTagPublicSymbol
: return "SymTagPublicSymbol";
59 case SymTagUDT
: return "SymTagUDT";
60 case SymTagEnum
: return "SymTagEnum";
61 case SymTagFunctionType
: return "SymTagFunctionType";
62 case SymTagPointerType
: return "SymTagPointerType";
63 case SymTagArrayType
: return "SymTagArrayType";
64 case SymTagBaseType
: return "SymTagBaseType";
65 case SymTagTypedef
: return "SymTagTypedef,";
66 case SymTagBaseClass
: return "SymTagBaseClass";
67 case SymTagFriend
: return "SymTagFriend";
68 case SymTagFunctionArgType
: return "SymTagFunctionArgType,";
69 case SymTagFuncDebugStart
: return "SymTagFuncDebugStart,";
70 case SymTagFuncDebugEnd
: return "SymTagFuncDebugEnd";
71 case SymTagUsingNamespace
: return "SymTagUsingNamespace,";
72 case SymTagVTableShape
: return "SymTagVTableShape";
73 case SymTagVTable
: return "SymTagVTable";
74 case SymTagCustom
: return "SymTagCustom";
75 case SymTagThunk
: return "SymTagThunk";
76 case SymTagCustomType
: return "SymTagCustomType";
77 case SymTagManagedType
: return "SymTagManagedType";
78 case SymTagDimension
: return "SymTagDimension";
79 default: return "---";
83 const char* symt_get_name(const struct symt
* sym
)
88 case SymTagData
: return ((const struct symt_data
*)sym
)->hash_elt
.name
;
89 case SymTagFunction
: return ((const struct symt_function
*)sym
)->hash_elt
.name
;
90 case SymTagPublicSymbol
: return ((const struct symt_public
*)sym
)->hash_elt
.name
;
91 case SymTagBaseType
: return ((const struct symt_basic
*)sym
)->hash_elt
.name
;
92 case SymTagLabel
: return ((const struct symt_hierarchy_point
*)sym
)->hash_elt
.name
;
93 case SymTagThunk
: return ((const struct symt_thunk
*)sym
)->hash_elt
.name
;
95 case SymTagEnum
: return ((const struct symt_enum
*)sym
)->name
;
96 case SymTagTypedef
: return ((const struct symt_typedef
*)sym
)->hash_elt
.name
;
97 case SymTagUDT
: return ((const struct symt_udt
*)sym
)->hash_elt
.name
;
99 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym
->tag
));
101 case SymTagArrayType
:
102 case SymTagPointerType
:
103 case SymTagFunctionType
:
108 WCHAR
* symt_get_nameW(const struct symt
* sym
)
110 const char* name
= symt_get_name(sym
);
114 if (!name
) return NULL
;
115 sz
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
116 if ((nameW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
117 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sz
);
121 BOOL
symt_get_address(const struct symt
* type
, ULONG64
* addr
)
126 switch (((const struct symt_data
*)type
)->kind
)
129 case DataIsFileStatic
:
130 *addr
= ((const struct symt_data
*)type
)->u
.var
.offset
;
132 default: return FALSE
;
136 *addr
= ((const struct symt_function
*)type
)->address
;
138 case SymTagPublicSymbol
:
139 *addr
= ((const struct symt_public
*)type
)->address
;
141 case SymTagFuncDebugStart
:
142 case SymTagFuncDebugEnd
:
144 if (!((const struct symt_hierarchy_point
*)type
)->parent
||
145 !symt_get_address(((const struct symt_hierarchy_point
*)type
)->parent
, addr
))
147 *addr
+= ((const struct symt_hierarchy_point
*)type
)->loc
.offset
;
150 *addr
= ((const struct symt_thunk
*)type
)->address
;
152 case SymTagCompiland
:
153 *addr
= ((const struct symt_compiland
*)type
)->address
;
156 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type
->tag
));
162 static struct symt
* symt_find_type_by_name(const struct module
* module
,
163 enum SymTagEnum sym_tag
,
164 const char* typename
)
167 struct symt_ht
* type
;
168 struct hash_table_iter hti
;
173 hash_table_iter_init(&module
->ht_types
, &hti
, typename
);
174 while ((ptr
= hash_table_iter_up(&hti
)))
176 type
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
178 if ((sym_tag
== SymTagNull
|| type
->symt
.tag
== sym_tag
) &&
179 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, typename
))
182 SetLastError(ERROR_INVALID_NAME
); /* FIXME ?? */
186 static void symt_add_type(struct module
* module
, struct symt
* symt
)
189 p
= vector_add(&module
->vtypes
, &module
->pool
);
194 struct symt_basic
* symt_new_basic(struct module
* module
, enum BasicType bt
,
195 const char* typename
, unsigned size
)
197 struct symt_basic
* sym
;
201 sym
= (struct symt_basic
*)symt_find_type_by_name(module
, SymTagBaseType
,
203 if (sym
&& sym
->bt
== bt
&& sym
->size
== size
)
206 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
208 sym
->symt
.tag
= SymTagBaseType
;
211 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
212 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
213 } else sym
->hash_elt
.name
= NULL
;
216 symt_add_type(module
, &sym
->symt
);
221 struct symt_udt
* symt_new_udt(struct module
* module
, const char* typename
,
222 unsigned size
, enum UdtKind kind
)
224 struct symt_udt
* sym
;
226 TRACE_(dbghelp_symt
)("Adding udt %s:%s\n",
227 debugstr_w(module
->module
.ModuleName
), typename
);
228 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
230 sym
->symt
.tag
= SymTagUDT
;
235 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
236 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
237 } else sym
->hash_elt
.name
= NULL
;
238 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
239 symt_add_type(module
, &sym
->symt
);
244 BOOL
symt_set_udt_size(struct module
* module
, struct symt_udt
* udt
, unsigned size
)
246 assert(udt
->symt
.tag
== SymTagUDT
);
247 if (vector_length(&udt
->vchildren
) != 0)
249 if (udt
->size
!= size
)
250 FIXME_(dbghelp_symt
)("Changing size for %s from %u to %u\n",
251 udt
->hash_elt
.name
, udt
->size
, size
);
258 /******************************************************************
259 * symt_add_udt_element
261 * add an element to a udt (struct, class, union)
262 * the size & offset parameters are expressed in bits (not bytes) so that
263 * we can mix in the single call bytes aligned elements (regular fields) and
264 * the others (bit fields)
266 BOOL
symt_add_udt_element(struct module
* module
, struct symt_udt
* udt_type
,
267 const char* name
, struct symt
* elt_type
,
268 unsigned offset
, unsigned size
)
273 assert(udt_type
->symt
.tag
== SymTagUDT
);
275 TRACE_(dbghelp_symt
)("Adding %s to UDT %s\n", name
, udt_type
->hash_elt
.name
);
279 for (i
=0; i
<vector_length(&udt_type
->vchildren
); i
++)
281 m
= *(struct symt_data
**)vector_at(&udt_type
->vchildren
, i
);
283 assert(m
->symt
.tag
== SymTagData
);
284 if (strcmp(m
->hash_elt
.name
, name
) == 0)
289 if ((m
= pool_alloc(&module
->pool
, sizeof(*m
))) == NULL
) return FALSE
;
290 memset(m
, 0, sizeof(*m
));
291 m
->symt
.tag
= SymTagData
;
292 m
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : "";
293 m
->hash_elt
.next
= NULL
;
295 m
->kind
= DataIsMember
;
296 m
->container
= &udt_type
->symt
;
298 m
->u
.member
.offset
= offset
;
299 m
->u
.member
.length
= ((offset
& 7) || (size
& 7)) ? size
: 0;
300 p
= vector_add(&udt_type
->vchildren
, &module
->pool
);
306 struct symt_enum
* symt_new_enum(struct module
* module
, const char* typename
,
307 struct symt
* basetype
)
309 struct symt_enum
* sym
;
311 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
313 sym
->symt
.tag
= SymTagEnum
;
314 sym
->name
= (typename
) ? pool_strdup(&module
->pool
, typename
) : NULL
;
315 sym
->base_type
= basetype
;
316 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
321 BOOL
symt_add_enum_element(struct module
* module
, struct symt_enum
* enum_type
,
322 const char* name
, int value
)
327 assert(enum_type
->symt
.tag
== SymTagEnum
);
328 e
= pool_alloc(&module
->pool
, sizeof(*e
));
329 if (e
== NULL
) return FALSE
;
331 e
->symt
.tag
= SymTagData
;
332 e
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
333 e
->hash_elt
.next
= NULL
;
334 e
->kind
= DataIsConstant
;
335 e
->container
= &enum_type
->symt
;
336 e
->type
= enum_type
->base_type
;
337 e
->u
.value
.n1
.n2
.vt
= VT_I4
;
338 e
->u
.value
.n1
.n2
.n3
.lVal
= value
;
340 p
= vector_add(&enum_type
->vchildren
, &module
->pool
);
341 if (!p
) return FALSE
; /* FIXME we leak e */
347 struct symt_array
* symt_new_array(struct module
* module
, int min
, int max
,
348 struct symt
* base
, struct symt
* index
)
350 struct symt_array
* sym
;
352 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
354 sym
->symt
.tag
= SymTagArrayType
;
357 sym
->base_type
= base
;
358 sym
->index_type
= index
;
359 symt_add_type(module
, &sym
->symt
);
364 static inline DWORD
symt_array_count(struct module
* module
, const struct symt_array
* array
)
369 /* One could want to also set the array->end field in array, but we won't do it
370 * as long as all the get_type() helpers use const objects
372 if (symt_get_info(module
, array
->base_type
, TI_GET_LENGTH
, &elem_size
) && elem_size
)
373 return -array
->end
/ (DWORD
)elem_size
;
376 return array
->end
- array
->start
+ 1;
379 struct symt_function_signature
* symt_new_function_signature(struct module
* module
,
380 struct symt
* ret_type
,
381 enum CV_call_e call_conv
)
383 struct symt_function_signature
* sym
;
385 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
387 sym
->symt
.tag
= SymTagFunctionType
;
388 sym
->rettype
= ret_type
;
389 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 4);
390 sym
->call_conv
= call_conv
;
391 symt_add_type(module
, &sym
->symt
);
396 BOOL
symt_add_function_signature_parameter(struct module
* module
,
397 struct symt_function_signature
* sig_type
,
401 struct symt_function_arg_type
* arg
;
403 assert(sig_type
->symt
.tag
== SymTagFunctionType
);
404 arg
= pool_alloc(&module
->pool
, sizeof(*arg
));
405 if (!arg
) return FALSE
;
406 arg
->symt
.tag
= SymTagFunctionArgType
;
407 arg
->arg_type
= param
;
408 arg
->container
= &sig_type
->symt
;
409 p
= vector_add(&sig_type
->vchildren
, &module
->pool
);
410 if (!p
) return FALSE
; /* FIXME we leak arg */
416 struct symt_pointer
* symt_new_pointer(struct module
* module
, struct symt
* ref_type
, unsigned long size
)
418 struct symt_pointer
* sym
;
420 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
422 sym
->symt
.tag
= SymTagPointerType
;
423 sym
->pointsto
= ref_type
;
425 symt_add_type(module
, &sym
->symt
);
430 struct symt_typedef
* symt_new_typedef(struct module
* module
, struct symt
* ref
,
433 struct symt_typedef
* sym
;
435 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
437 sym
->symt
.tag
= SymTagTypedef
;
439 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
440 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
441 symt_add_type(module
, &sym
->symt
);
446 /******************************************************************
447 * SymEnumTypes (DBGHELP.@)
450 BOOL WINAPI
SymEnumTypes(HANDLE hProcess
, ULONG64 BaseOfDll
,
451 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
454 struct module_pair pair
;
455 char buffer
[sizeof(SYMBOL_INFO
) + 256];
456 SYMBOL_INFO
* sym_info
= (SYMBOL_INFO
*)buffer
;
462 TRACE("(%p %s %p %p)\n",
463 hProcess
, wine_dbgstr_longlong(BaseOfDll
), EnumSymbolsCallback
,
466 if (!(pair
.pcs
= process_find_by_handle(hProcess
))) return FALSE
;
467 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
468 if (!module_get_debug(&pair
)) return FALSE
;
470 sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
471 sym_info
->MaxNameLen
= sizeof(buffer
) - sizeof(SYMBOL_INFO
);
473 for (i
=0; i
<vector_length(&pair
.effective
->vtypes
); i
++)
475 type
= *(struct symt
**)vector_at(&pair
.effective
->vtypes
, i
);
476 sym_info
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
477 sym_info
->info
= 0; /* FIXME */
478 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
479 sym_info
->Size
= size
;
480 sym_info
->ModBase
= pair
.requested
->module
.BaseOfImage
;
481 sym_info
->Flags
= 0; /* FIXME */
482 sym_info
->Value
= 0; /* FIXME */
483 sym_info
->Address
= 0; /* FIXME */
484 sym_info
->Register
= 0; /* FIXME */
485 sym_info
->Scope
= 0; /* FIXME */
486 sym_info
->Tag
= type
->tag
;
487 tmp
= symt_get_name(type
);
490 sym_info
->NameLen
= min(strlen(tmp
),sym_info
->MaxNameLen
-1);
491 memcpy(sym_info
->Name
, tmp
, sym_info
->NameLen
);
492 sym_info
->Name
[sym_info
->NameLen
] = '\0';
495 sym_info
->Name
[sym_info
->NameLen
= 0] = '\0';
496 if (!EnumSymbolsCallback(sym_info
, sym_info
->Size
, UserContext
)) break;
501 struct enum_types_AtoW
503 char buffer
[sizeof(SYMBOL_INFOW
) + 256 * sizeof(WCHAR
)];
505 PSYM_ENUMERATESYMBOLS_CALLBACKW callback
;
508 static BOOL CALLBACK
enum_types_AtoW(PSYMBOL_INFO si
, ULONG addr
, PVOID _et
)
510 struct enum_types_AtoW
* et
= _et
;
511 SYMBOL_INFOW
* siW
= (SYMBOL_INFOW
*)et
->buffer
;
513 copy_symbolW(siW
, si
);
514 return et
->callback(siW
, addr
, et
->user
);
517 /******************************************************************
518 * SymEnumTypesW (DBGHELP.@)
521 BOOL WINAPI
SymEnumTypesW(HANDLE hProcess
, ULONG64 BaseOfDll
,
522 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
525 struct enum_types_AtoW et
;
527 et
.callback
= EnumSymbolsCallback
;
528 et
.user
= UserContext
;
530 return SymEnumTypes(hProcess
, BaseOfDll
, enum_types_AtoW
, &et
);
533 /******************************************************************
536 * Retrieves information about a symt (either symbol or type)
538 BOOL
symt_get_info(struct module
* module
, const struct symt
* type
,
539 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
)
543 if (!type
) return FALSE
;
545 /* helper to typecast pInfo to its expected type (_t) */
546 #define X(_t) (*((_t*)pInfo))
550 case TI_FINDCHILDREN
:
552 const struct vector
* v
;
555 TI_FINDCHILDREN_PARAMS
* tifp
= pInfo
;
559 case SymTagUDT
: v
= &((const struct symt_udt
*)type
)->vchildren
; break;
560 case SymTagEnum
: v
= &((const struct symt_enum
*)type
)->vchildren
; break;
561 case SymTagFunctionType
: v
= &((const struct symt_function_signature
*)type
)->vchildren
; break;
562 case SymTagFunction
: v
= &((const struct symt_function
*)type
)->vchildren
; break;
564 FIXME("Unsupported sym-tag %s for find-children\n",
565 symt_get_tag_str(type
->tag
));
568 for (i
= 0; i
< tifp
->Count
; i
++)
570 if (!(pt
= vector_at(v
, tifp
->Start
+ i
))) return FALSE
;
571 tifp
->ChildId
[i
] = symt_ptr2index(module
, *pt
);
577 return symt_get_address(type
, (ULONG64
*)pInfo
);
579 case TI_GET_BASETYPE
:
583 X(DWORD
) = ((const struct symt_basic
*)type
)->bt
;
593 case TI_GET_BITPOSITION
:
594 if (type
->tag
== SymTagData
&&
595 ((const struct symt_data
*)type
)->kind
== DataIsMember
&&
596 ((const struct symt_data
*)type
)->u
.member
.length
!= 0)
597 X(DWORD
) = ((const struct symt_data
*)type
)->u
.member
.offset
& 7;
601 case TI_GET_CHILDRENCOUNT
:
605 X(DWORD
) = vector_length(&((const struct symt_udt
*)type
)->vchildren
);
608 X(DWORD
) = vector_length(&((const struct symt_enum
*)type
)->vchildren
);
610 case SymTagFunctionType
:
611 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
614 X(DWORD
) = vector_length(&((const struct symt_function
*)type
)->vchildren
);
616 case SymTagPointerType
: /* MS does it that way */
617 case SymTagArrayType
: /* MS does it that way */
618 case SymTagThunk
: /* MS does it that way */
622 FIXME("Unsupported sym-tag %s for get-children-count\n",
623 symt_get_tag_str(type
->tag
));
626 case SymTagPublicSymbol
:
635 case SymTagArrayType
:
636 X(DWORD
) = symt_array_count(module
, (const struct symt_array
*)type
);
638 case SymTagFunctionType
:
639 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
640 * should be included in this value (and not in GET_CHILDREN_COUNT)
642 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
644 default: return FALSE
;
648 case TI_GET_DATAKIND
:
649 if (type
->tag
!= SymTagData
) return FALSE
;
650 X(DWORD
) = ((const struct symt_data
*)type
)->kind
;
657 X(DWORD64
) = ((const struct symt_basic
*)type
)->size
;
660 X(DWORD64
) = ((const struct symt_function
*)type
)->size
;
662 case SymTagPointerType
:
663 X(DWORD64
) = ((const struct symt_pointer
*)type
)->size
;
666 X(DWORD64
) = ((const struct symt_udt
*)type
)->size
;
669 X(DWORD64
) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
672 if (((const struct symt_data
*)type
)->kind
!= DataIsMember
||
673 !((const struct symt_data
*)type
)->u
.member
.length
)
675 X(DWORD64
) = ((const struct symt_data
*)type
)->u
.member
.length
;
677 case SymTagArrayType
:
678 if (!symt_get_info(module
, ((const struct symt_array
*)type
)->base_type
,
679 TI_GET_LENGTH
, pInfo
))
681 X(DWORD64
) *= symt_array_count(module
, (const struct symt_array
*)type
);
683 case SymTagPublicSymbol
:
684 X(DWORD64
) = ((const struct symt_public
*)type
)->size
;
687 return symt_get_info(module
, ((const struct symt_typedef
*)type
)->type
, TI_GET_LENGTH
, pInfo
);
689 X(DWORD64
) = ((const struct symt_thunk
*)type
)->size
;
695 FIXME("Unsupported sym-tag %s for get-length\n",
696 symt_get_tag_str(type
->tag
));
698 case SymTagFunctionType
:
703 case TI_GET_LEXICALPARENT
:
707 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_block
*)type
)->container
);
710 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->container
);
713 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->container
);
716 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_thunk
*)type
)->container
);
718 case SymTagFunctionArgType
:
719 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->container
);
722 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
723 symt_get_tag_str(type
->tag
));
744 switch (((const struct symt_data
*)type
)->kind
)
748 X(ULONG
) = ((const struct symt_data
*)type
)->u
.var
.offset
;
751 X(ULONG
) = ((const struct symt_data
*)type
)->u
.member
.offset
>> 3;
754 FIXME("Unknown kind (%u) for get-offset\n",
755 ((const struct symt_data
*)type
)->kind
);
760 FIXME("Unsupported sym-tag %s for get-offset\n",
761 symt_get_tag_str(type
->tag
));
768 const char* name
= symt_get_name(type
);
769 if (!name
) return FALSE
;
770 len
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
771 X(WCHAR
*) = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
772 if (!X(WCHAR
*)) return FALSE
;
773 MultiByteToWideChar(CP_ACP
, 0, name
, -1, X(WCHAR
*), len
);
778 X(DWORD
) = type
->tag
;
785 /* hierarchical => hierarchical */
786 case SymTagArrayType
:
787 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->base_type
);
789 case SymTagPointerType
:
790 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_pointer
*)type
)->pointsto
);
792 case SymTagFunctionType
:
793 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_signature
*)type
)->rettype
);
796 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_typedef
*)type
)->type
);
798 /* lexical => hierarchical */
800 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->type
);
803 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->type
);
806 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_enum
*)type
)->base_type
);
808 case SymTagFunctionArgType
:
809 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->arg_type
);
812 FIXME("Unsupported sym-tag %s for get-type\n",
813 symt_get_tag_str(type
->tag
));
815 case SymTagPublicSymbol
:
823 if (type
->tag
!= SymTagUDT
) return FALSE
;
824 X(DWORD
) = ((const struct symt_udt
*)type
)->kind
;
828 if (type
->tag
!= SymTagData
) return FALSE
;
829 switch (((const struct symt_data
*)type
)->kind
)
831 case DataIsConstant
: X(VARIANT
) = ((const struct symt_data
*)type
)->u
.value
; break;
835 struct location loc
= ((const struct symt_data
*)type
)->u
.var
;
837 struct module_format
* modfmt
;
839 if (loc
.kind
< loc_user
) return FALSE
;
840 for (i
= 0; i
< DFI_LAST
; i
++)
842 modfmt
= module
->format_info
[i
];
843 if (modfmt
&& modfmt
->loc_compute
)
845 modfmt
->loc_compute(module
->process
, modfmt
,
846 (const struct symt_function
*)((const struct symt_data
*)type
)->container
, &loc
);
850 if (loc
.kind
!= loc_absolute
) return FALSE
;
851 X(VARIANT
).n1
.n2
.vt
= VT_UI4
; /* FIXME */
852 X(VARIANT
).n1
.n2
.n3
.uiVal
= loc
.offset
;
855 default: return FALSE
;
859 case TI_GET_CALLING_CONVENTION
:
860 if (type
->tag
!= SymTagFunctionType
) return FALSE
;
861 if (((const struct symt_function_signature
*)type
)->call_conv
== -1)
863 FIXME("No support for calling convention for this signature\n");
864 X(DWORD
) = CV_CALL_FAR_C
; /* FIXME */
866 else X(DWORD
) = ((const struct symt_function_signature
*)type
)->call_conv
;
868 case TI_GET_ARRAYINDEXTYPEID
:
869 if (type
->tag
!= SymTagArrayType
) return FALSE
;
870 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_array
*)type
)->index_type
);
873 case TI_GET_CLASSPARENTID
:
874 /* FIXME: we don't support properly C++ for now, pretend this symbol doesn't
875 * belong to a parent class
881 case TI_GET_ADDRESSOFFSET
:
882 case TI_GET_SYMINDEX
:
883 case TI_GET_THISADJUST
:
884 case TI_GET_VIRTUALBASECLASS
:
885 case TI_GET_VIRTUALBASEPOINTEROFFSET
:
886 case TI_GET_VIRTUALTABLESHAPEID
:
888 FIXME("Unsupported GetInfo request (%u)\n", req
);
891 FIXME("Unknown GetInfo request (%u)\n", req
);
898 /******************************************************************
899 * SymGetTypeInfo (DBGHELP.@)
902 BOOL WINAPI
SymGetTypeInfo(HANDLE hProcess
, DWORD64 ModBase
,
903 ULONG TypeId
, IMAGEHLP_SYMBOL_TYPE_INFO GetType
,
906 struct module_pair pair
;
908 pair
.pcs
= process_find_by_handle(hProcess
);
909 if (!pair
.pcs
) return FALSE
;
911 pair
.requested
= module_find_by_addr(pair
.pcs
, ModBase
, DMT_UNKNOWN
);
912 if (!module_get_debug(&pair
))
914 FIXME("Someone didn't properly set ModBase (%s)\n", wine_dbgstr_longlong(ModBase
));
918 return symt_get_info(pair
.effective
, symt_index2ptr(pair
.effective
, TypeId
), GetType
, pInfo
);
921 /******************************************************************
922 * SymGetTypeFromName (DBGHELP.@)
925 BOOL WINAPI
SymGetTypeFromName(HANDLE hProcess
, ULONG64 BaseOfDll
,
926 PCSTR Name
, PSYMBOL_INFO Symbol
)
928 struct process
* pcs
= process_find_by_handle(hProcess
);
929 struct module_pair pair
;
932 if (!pcs
) return FALSE
;
933 pair
.requested
= module_find_by_addr(pcs
, BaseOfDll
, DMT_UNKNOWN
);
934 if (!module_get_debug(&pair
)) return FALSE
;
935 type
= symt_find_type_by_name(pair
.effective
, SymTagNull
, Name
);
936 if (!type
) return FALSE
;
937 Symbol
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);