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 default: return "---";
79 const char* symt_get_name(const struct symt
* sym
)
84 case SymTagData
: return ((const struct symt_data
*)sym
)->hash_elt
.name
;
85 case SymTagFunction
: return ((const struct symt_function
*)sym
)->hash_elt
.name
;
86 case SymTagPublicSymbol
: return ((const struct symt_public
*)sym
)->hash_elt
.name
;
87 case SymTagBaseType
: return ((const struct symt_basic
*)sym
)->hash_elt
.name
;
88 case SymTagLabel
: return ((const struct symt_hierarchy_point
*)sym
)->hash_elt
.name
;
89 case SymTagThunk
: return ((const struct symt_thunk
*)sym
)->hash_elt
.name
;
91 case SymTagEnum
: return ((const struct symt_enum
*)sym
)->name
;
92 case SymTagTypedef
: return ((const struct symt_typedef
*)sym
)->hash_elt
.name
;
93 case SymTagUDT
: return ((const struct symt_udt
*)sym
)->hash_elt
.name
;
94 case SymTagCompiland
: return source_get(((const struct symt_compiland
*)sym
)->container
->module
,
95 ((const struct symt_compiland
*)sym
)->source
);
97 FIXME("Unsupported sym-tag %s\n", symt_get_tag_str(sym
->tag
));
100 case SymTagPointerType
:
101 case SymTagFunctionType
:
106 WCHAR
* symt_get_nameW(const struct symt
* sym
)
108 const char* name
= symt_get_name(sym
);
112 if (!name
) return NULL
;
113 sz
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
114 if ((nameW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
115 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sz
);
119 BOOL
symt_get_address(const struct symt
* type
, ULONG64
* addr
)
124 switch (((const struct symt_data
*)type
)->kind
)
127 case DataIsFileStatic
:
128 *addr
= ((const struct symt_data
*)type
)->u
.var
.offset
;
130 default: return FALSE
;
134 *addr
= ((const struct symt_function
*)type
)->address
;
136 case SymTagPublicSymbol
:
137 *addr
= ((const struct symt_public
*)type
)->address
;
139 case SymTagFuncDebugStart
:
140 case SymTagFuncDebugEnd
:
142 if (!((const struct symt_hierarchy_point
*)type
)->parent
||
143 !symt_get_address(((const struct symt_hierarchy_point
*)type
)->parent
, addr
))
145 *addr
+= ((const struct symt_hierarchy_point
*)type
)->loc
.offset
;
148 *addr
= ((const struct symt_thunk
*)type
)->address
;
150 case SymTagCompiland
:
151 *addr
= ((const struct symt_compiland
*)type
)->address
;
154 FIXME("Unsupported sym-tag %s for get-address\n", symt_get_tag_str(type
->tag
));
160 static struct symt
* symt_find_type_by_name(const struct module
* module
,
161 enum SymTagEnum sym_tag
,
162 const char* typename
)
165 struct symt_ht
* type
;
166 struct hash_table_iter hti
;
171 hash_table_iter_init(&module
->ht_types
, &hti
, typename
);
172 while ((ptr
= hash_table_iter_up(&hti
)))
174 type
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
176 if ((sym_tag
== SymTagNull
|| type
->symt
.tag
== sym_tag
) &&
177 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, typename
))
180 SetLastError(ERROR_INVALID_NAME
); /* FIXME ?? */
184 static void symt_add_type(struct module
* module
, struct symt
* symt
)
187 p
= vector_add(&module
->vtypes
, &module
->pool
);
192 struct symt_basic
* symt_new_basic(struct module
* module
, enum BasicType bt
,
193 const char* typename
, unsigned size
)
195 struct symt_basic
* sym
;
199 sym
= (struct symt_basic
*)symt_find_type_by_name(module
, SymTagBaseType
,
201 if (sym
&& sym
->bt
== bt
&& sym
->size
== size
)
204 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
206 sym
->symt
.tag
= SymTagBaseType
;
209 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
210 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
211 } else sym
->hash_elt
.name
= NULL
;
214 symt_add_type(module
, &sym
->symt
);
219 struct symt_udt
* symt_new_udt(struct module
* module
, const char* typename
,
220 unsigned size
, enum UdtKind kind
)
222 struct symt_udt
* sym
;
224 TRACE_(dbghelp_symt
)("Adding udt %s:%s\n",
225 debugstr_w(module
->module
.ModuleName
), typename
);
226 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
228 sym
->symt
.tag
= SymTagUDT
;
233 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, typename
);
234 hash_table_add(&module
->ht_types
, &sym
->hash_elt
);
235 } else sym
->hash_elt
.name
= NULL
;
236 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
237 symt_add_type(module
, &sym
->symt
);
242 BOOL
symt_set_udt_size(struct module
* module
, struct symt_udt
* udt
, unsigned size
)
244 assert(udt
->symt
.tag
== SymTagUDT
);
245 if (vector_length(&udt
->vchildren
) != 0)
247 if (udt
->size
!= size
)
248 FIXME_(dbghelp_symt
)("Changing size for %s from %u to %u\n",
249 udt
->hash_elt
.name
, udt
->size
, size
);
256 /******************************************************************
257 * symt_add_udt_element
259 * add an element to a udt (struct, class, union)
260 * the size & offset parameters are expressed in bits (not bytes) so that
261 * we can mix in the single call bytes aligned elements (regular fields) and
262 * the others (bit fields)
264 BOOL
symt_add_udt_element(struct module
* module
, struct symt_udt
* udt_type
,
265 const char* name
, struct symt
* elt_type
,
266 unsigned offset
, unsigned bit_offset
, unsigned bit_size
)
271 assert(udt_type
->symt
.tag
== SymTagUDT
);
273 TRACE_(dbghelp_symt
)("Adding %s to UDT %s\n", name
, udt_type
->hash_elt
.name
);
277 for (i
=0; i
<vector_length(&udt_type
->vchildren
); i
++)
279 m
= *(struct symt_data
**)vector_at(&udt_type
->vchildren
, i
);
281 assert(m
->symt
.tag
== SymTagData
);
282 if (strcmp(m
->hash_elt
.name
, name
) == 0)
287 if ((m
= pool_alloc(&module
->pool
, sizeof(*m
))) == NULL
) return FALSE
;
288 memset(m
, 0, sizeof(*m
));
289 m
->symt
.tag
= SymTagData
;
290 m
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : "";
291 m
->hash_elt
.next
= NULL
;
293 m
->kind
= DataIsMember
;
294 m
->container
= &udt_type
->symt
;
296 m
->u
.member
.offset
= offset
;
297 m
->u
.member
.bit_offset
= bit_offset
;
298 m
->u
.member
.bit_length
= bit_size
;
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
, ULONG_PTR 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
;
460 TRACE("(%p %s %p %p)\n",
461 hProcess
, wine_dbgstr_longlong(BaseOfDll
), EnumSymbolsCallback
,
464 if (!(pair
.pcs
= process_find_by_handle(hProcess
))) return FALSE
;
465 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
466 if (!module_get_debug(&pair
)) return FALSE
;
468 sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
469 sym_info
->MaxNameLen
= sizeof(buffer
) - sizeof(SYMBOL_INFO
);
471 for (i
=0; i
<vector_length(&pair
.effective
->vtypes
); i
++)
473 type
= *(struct symt
**)vector_at(&pair
.effective
->vtypes
, i
);
474 sym_info
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
475 sym_info
->Index
= 0; /* FIXME */
476 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
477 sym_info
->Size
= size
;
478 sym_info
->ModBase
= pair
.requested
->module
.BaseOfImage
;
479 sym_info
->Flags
= 0; /* FIXME */
480 sym_info
->Value
= 0; /* FIXME */
481 sym_info
->Address
= 0; /* FIXME */
482 sym_info
->Register
= 0; /* FIXME */
483 sym_info
->Scope
= 0; /* FIXME */
484 sym_info
->Tag
= type
->tag
;
485 symbol_setname(sym_info
, symt_get_name(type
));
486 if (!EnumSymbolsCallback(sym_info
, sym_info
->Size
, UserContext
)) break;
491 struct enum_types_AtoW
493 char buffer
[sizeof(SYMBOL_INFOW
) + 256 * sizeof(WCHAR
)];
495 PSYM_ENUMERATESYMBOLS_CALLBACKW callback
;
498 static BOOL CALLBACK
enum_types_AtoW(PSYMBOL_INFO si
, ULONG addr
, PVOID _et
)
500 struct enum_types_AtoW
* et
= _et
;
501 SYMBOL_INFOW
* siW
= (SYMBOL_INFOW
*)et
->buffer
;
503 copy_symbolW(siW
, si
);
504 return et
->callback(siW
, addr
, et
->user
);
507 /******************************************************************
508 * SymEnumTypesW (DBGHELP.@)
511 BOOL WINAPI
SymEnumTypesW(HANDLE hProcess
, ULONG64 BaseOfDll
,
512 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
515 struct enum_types_AtoW et
;
517 et
.callback
= EnumSymbolsCallback
;
518 et
.user
= UserContext
;
520 return SymEnumTypes(hProcess
, BaseOfDll
, enum_types_AtoW
, &et
);
523 /******************************************************************
526 * Retrieves information about a symt (either symbol or type)
528 BOOL
symt_get_info(struct module
* module
, const struct symt
* type
,
529 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
)
533 if (!type
) return FALSE
;
535 /* helper to typecast pInfo to its expected type (_t) */
536 #define X(_t) (*((_t*)pInfo))
540 case TI_FINDCHILDREN
:
542 const struct vector
* v
;
545 TI_FINDCHILDREN_PARAMS
* tifp
= pInfo
;
549 case SymTagUDT
: v
= &((const struct symt_udt
*)type
)->vchildren
; break;
550 case SymTagEnum
: v
= &((const struct symt_enum
*)type
)->vchildren
; break;
551 case SymTagFunctionType
: v
= &((const struct symt_function_signature
*)type
)->vchildren
; break;
552 case SymTagFunction
: v
= &((const struct symt_function
*)type
)->vchildren
; break;
554 FIXME("Unsupported sym-tag %s for find-children\n",
555 symt_get_tag_str(type
->tag
));
558 for (i
= 0; i
< tifp
->Count
; i
++)
560 if (!(pt
= vector_at(v
, tifp
->Start
+ i
))) return FALSE
;
561 tifp
->ChildId
[i
] = symt_ptr2index(module
, *pt
);
567 return symt_get_address(type
, (ULONG64
*)pInfo
);
569 case TI_GET_BASETYPE
:
573 X(DWORD
) = ((const struct symt_basic
*)type
)->bt
;
583 case TI_GET_BITPOSITION
:
584 if (type
->tag
== SymTagData
&&
585 ((const struct symt_data
*)type
)->kind
== DataIsMember
&&
586 ((const struct symt_data
*)type
)->u
.member
.bit_length
!= 0)
587 X(DWORD
) = ((const struct symt_data
*)type
)->u
.member
.bit_offset
;
591 case TI_GET_CHILDRENCOUNT
:
595 X(DWORD
) = vector_length(&((const struct symt_udt
*)type
)->vchildren
);
598 X(DWORD
) = vector_length(&((const struct symt_enum
*)type
)->vchildren
);
600 case SymTagFunctionType
:
601 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
604 X(DWORD
) = vector_length(&((const struct symt_function
*)type
)->vchildren
);
606 case SymTagPointerType
: /* MS does it that way */
607 case SymTagArrayType
: /* MS does it that way */
608 case SymTagThunk
: /* MS does it that way */
612 FIXME("Unsupported sym-tag %s for get-children-count\n",
613 symt_get_tag_str(type
->tag
));
616 case SymTagPublicSymbol
:
625 case SymTagArrayType
:
626 X(DWORD
) = symt_array_count(module
, (const struct symt_array
*)type
);
628 case SymTagFunctionType
:
629 /* this seems to be wrong for (future) C++ methods, where 'this' parameter
630 * should be included in this value (and not in GET_CHILDREN_COUNT)
632 X(DWORD
) = vector_length(&((const struct symt_function_signature
*)type
)->vchildren
);
634 default: return FALSE
;
638 case TI_GET_DATAKIND
:
639 if (type
->tag
!= SymTagData
) return FALSE
;
640 X(DWORD
) = ((const struct symt_data
*)type
)->kind
;
647 X(DWORD64
) = ((const struct symt_basic
*)type
)->size
;
650 X(DWORD64
) = ((const struct symt_function
*)type
)->size
;
652 case SymTagPointerType
:
653 X(DWORD64
) = ((const struct symt_pointer
*)type
)->size
;
656 X(DWORD64
) = ((const struct symt_udt
*)type
)->size
;
659 X(DWORD64
) = sizeof(int); /* FIXME: should be size of base-type of enum !!! */
662 if (((const struct symt_data
*)type
)->kind
!= DataIsMember
||
663 !((const struct symt_data
*)type
)->u
.member
.bit_length
)
665 X(DWORD64
) = ((const struct symt_data
*)type
)->u
.member
.bit_length
;
667 case SymTagArrayType
:
668 if (!symt_get_info(module
, ((const struct symt_array
*)type
)->base_type
,
669 TI_GET_LENGTH
, pInfo
))
671 X(DWORD64
) *= symt_array_count(module
, (const struct symt_array
*)type
);
673 case SymTagPublicSymbol
:
674 X(DWORD64
) = ((const struct symt_public
*)type
)->size
;
677 return symt_get_info(module
, ((const struct symt_typedef
*)type
)->type
, TI_GET_LENGTH
, pInfo
);
679 X(DWORD64
) = ((const struct symt_thunk
*)type
)->size
;
685 FIXME("Unsupported sym-tag %s for get-length\n",
686 symt_get_tag_str(type
->tag
));
688 case SymTagFunctionType
:
693 case TI_GET_LEXICALPARENT
:
697 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_block
*)type
)->container
);
700 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_data
*)type
)->container
);
703 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function
*)type
)->container
);
706 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_thunk
*)type
)->container
);
708 case SymTagFunctionArgType
:
709 X(DWORD
) = symt_ptr2index(module
, ((const struct symt_function_arg_type
*)type
)->container
);
712 FIXME("Unsupported sym-tag %s for get-lexical-parent\n",
713 symt_get_tag_str(type
->tag
));
734 switch (((const struct symt_data
*)type
)->kind
)
738 X(ULONG
) = ((const struct symt_data
*)type
)->u
.var
.offset
;
741 X(ULONG
) = ((const struct symt_data
*)type
)->u
.member
.offset
;
744 FIXME("Unknown kind (%u) for get-offset\n",
745 ((const struct symt_data
*)type
)->kind
);
750 FIXME("Unsupported sym-tag %s for get-offset\n",
751 symt_get_tag_str(type
->tag
));
757 if (type
->tag
== SymTagExe
)
759 DWORD len
= (lstrlenW(module
->modulename
) + 1) * sizeof(WCHAR
);
760 WCHAR
* wname
= HeapAlloc(GetProcessHeap(), 0, len
);
761 if (!wname
) return FALSE
;
762 memcpy(wname
, module
->modulename
, len
);
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 module_pair pair
;
931 pair
.pcs
= process_find_by_handle(hProcess
);
932 if (!pair
.pcs
) return FALSE
;
933 pair
.requested
= module_find_by_addr(pair
.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
->Index
= Symbol
->TypeIndex
= symt_ptr2index(pair
.effective
, type
);
938 symbol_setname(Symbol
, symt_get_name(type
));
939 symt_get_info(pair
.effective
, type
, TI_GET_LENGTH
, &size
);
941 Symbol
->ModBase
= pair
.requested
->module
.BaseOfImage
;
942 Symbol
->Tag
= type
->tag
;