2 * File symbol.c - management of symbols (lexical tree)
4 * Copyright (C) 1993, 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
22 #define NONAMELESSUNION
30 #include <sys/types.h>
33 #include "wine/debug.h"
34 #include "dbghelp_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
38 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt
);
40 static const WCHAR starW
[] = {'*','\0'};
42 static inline int cmp_addr(ULONG64 a1
, ULONG64 a2
)
44 if (a1
> a2
) return 1;
45 if (a1
< a2
) return -1;
49 static inline int cmp_sorttab_addr(struct module
* module
, int idx
, ULONG64 addr
)
52 symt_get_address(&module
->addr_sorttab
[idx
]->symt
, &ref
);
53 return cmp_addr(ref
, addr
);
56 int symt_cmp_addr(const void* p1
, const void* p2
)
58 const struct symt
* sym1
= *(const struct symt
* const *)p1
;
59 const struct symt
* sym2
= *(const struct symt
* const *)p2
;
62 symt_get_address(sym1
, &a1
);
63 symt_get_address(sym2
, &a2
);
64 return cmp_addr(a1
, a2
);
67 DWORD
symt_ptr2index(struct module
* module
, const struct symt
* sym
)
70 const struct symt
** c
;
71 int len
= vector_length(&module
->vsymt
), i
;
73 /* FIXME: this is inefficient */
74 for (i
= 0; i
< len
; i
++)
76 if (*(struct symt
**)vector_at(&module
->vsymt
, i
) == sym
)
80 c
= vector_add(&module
->vsymt
, &module
->pool
);
88 struct symt
* symt_index2ptr(struct module
* module
, DWORD id
)
91 if (!id
-- || id
>= vector_length(&module
->vsymt
)) return NULL
;
92 return *(struct symt
**)vector_at(&module
->vsymt
, id
);
94 return (struct symt
*)id
;
98 static BOOL
symt_grow_sorttab(struct module
* module
, unsigned sz
)
100 struct symt_ht
** new;
103 if (sz
<= module
->sorttab_size
) return TRUE
;
104 if (module
->addr_sorttab
)
106 size
= module
->sorttab_size
* 2;
107 new = HeapReAlloc(GetProcessHeap(), 0, module
->addr_sorttab
,
108 size
* sizeof(struct symt_ht
*));
113 new = HeapAlloc(GetProcessHeap(), 0, size
* sizeof(struct symt_ht
*));
115 if (!new) return FALSE
;
116 module
->sorttab_size
= size
;
117 module
->addr_sorttab
= new;
121 static void symt_add_module_ht(struct module
* module
, struct symt_ht
* ht
)
125 hash_table_add(&module
->ht_symbols
, &ht
->hash_elt
);
126 /* Don't store in sorttab a symbol without address, they are of
127 * no use here (e.g. constant values)
129 if (symt_get_address(&ht
->symt
, &addr
) &&
130 symt_grow_sorttab(module
, module
->num_symbols
+ 1))
132 module
->addr_sorttab
[module
->num_symbols
++] = ht
;
133 module
->sortlist_valid
= FALSE
;
137 static WCHAR
* file_regex(const char* srcfile
)
142 if (!srcfile
|| !*srcfile
)
144 if (!(p
= mask
= HeapAlloc(GetProcessHeap(), 0, 3 * sizeof(WCHAR
)))) return NULL
;
150 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, NULL
, 0);
153 /* FIXME: we use here the largest conversion for every char... could be optimized */
154 p
= mask
= HeapAlloc(GetProcessHeap(), 0, (5 * strlen(srcfile
) + 1 + sz
) * sizeof(WCHAR
));
155 if (!mask
) return NULL
;
156 srcfileW
= mask
+ 5 * strlen(srcfile
) + 1;
157 MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, srcfileW
, sz
);
185 struct symt_compiland
* symt_new_compiland(struct module
* module
,
186 unsigned long address
, unsigned src_idx
)
188 struct symt_compiland
* sym
;
190 TRACE_(dbghelp_symt
)("Adding compiland symbol %s:%s\n",
191 debugstr_w(module
->module
.ModuleName
), source_get(module
, src_idx
));
192 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
194 sym
->symt
.tag
= SymTagCompiland
;
195 sym
->address
= address
;
196 sym
->source
= src_idx
;
197 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 32);
202 struct symt_public
* symt_new_public(struct module
* module
,
203 struct symt_compiland
* compiland
,
205 unsigned long address
, unsigned size
)
207 struct symt_public
* sym
;
210 TRACE_(dbghelp_symt
)("Adding public symbol %s:%s @%lx\n",
211 debugstr_w(module
->module
.ModuleName
), name
, address
);
212 if ((dbghelp_options
& SYMOPT_AUTO_PUBLICS
) &&
213 symt_find_nearest(module
, address
) != NULL
)
215 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
217 sym
->symt
.tag
= SymTagPublicSymbol
;
218 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
219 sym
->container
= compiland
? &compiland
->symt
: NULL
;
220 sym
->address
= address
;
222 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
225 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
232 struct symt_data
* symt_new_global_variable(struct module
* module
,
233 struct symt_compiland
* compiland
,
234 const char* name
, unsigned is_static
,
235 struct location loc
, unsigned long size
,
238 struct symt_data
* sym
;
242 TRACE_(dbghelp_symt
)("Adding global symbol %s:%s %d@%lx %p\n",
243 debugstr_w(module
->module
.ModuleName
), name
, loc
.kind
, loc
.offset
, type
);
244 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
246 sym
->symt
.tag
= SymTagData
;
247 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
248 sym
->kind
= is_static
? DataIsFileStatic
: DataIsGlobal
;
249 sym
->container
= compiland
? &compiland
->symt
: NULL
;
252 if (type
&& size
&& symt_get_info(module
, type
, TI_GET_LENGTH
, &tsz
))
255 FIXME("Size mismatch for %s.%s between type (%s) and src (%lu)\n",
256 debugstr_w(module
->module
.ModuleName
), name
,
257 wine_dbgstr_longlong(tsz
), size
);
259 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
262 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
269 struct symt_function
* symt_new_function(struct module
* module
,
270 struct symt_compiland
* compiland
,
272 unsigned long addr
, unsigned long size
,
273 struct symt
* sig_type
)
275 struct symt_function
* sym
;
278 TRACE_(dbghelp_symt
)("Adding global function %s:%s @%lx-%lx\n",
279 debugstr_w(module
->module
.ModuleName
), name
, addr
, addr
+ size
- 1);
281 assert(!sig_type
|| sig_type
->tag
== SymTagFunctionType
);
282 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
284 sym
->symt
.tag
= SymTagFunction
;
285 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
286 sym
->container
= &compiland
->symt
;
288 sym
->type
= sig_type
;
290 vector_init(&sym
->vlines
, sizeof(struct line_info
), 64);
291 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
292 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
295 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
302 void symt_add_func_line(struct module
* module
, struct symt_function
* func
,
303 unsigned source_idx
, int line_num
, unsigned long offset
)
305 struct line_info
* dli
;
306 BOOL last_matches
= FALSE
;
309 if (func
== NULL
|| !(dbghelp_options
& SYMOPT_LOAD_LINES
)) return;
311 TRACE_(dbghelp_symt
)("(%p)%s:%lx %s:%u\n",
312 func
, func
->hash_elt
.name
, offset
,
313 source_get(module
, source_idx
), line_num
);
315 assert(func
->symt
.tag
== SymTagFunction
);
317 for (i
=vector_length(&func
->vlines
)-1; i
>=0; i
--)
319 dli
= vector_at(&func
->vlines
, i
);
320 if (dli
->is_source_file
)
322 last_matches
= (source_idx
== dli
->u
.source_file
);
329 /* we shouldn't have line changes on first line of function */
330 dli
= vector_add(&func
->vlines
, &module
->pool
);
331 dli
->is_source_file
= 1;
332 dli
->is_first
= dli
->is_last
= 0;
333 dli
->line_number
= 0;
334 dli
->u
.source_file
= source_idx
;
336 dli
= vector_add(&func
->vlines
, &module
->pool
);
337 dli
->is_source_file
= 0;
338 dli
->is_first
= dli
->is_last
= 0;
339 dli
->line_number
= line_num
;
340 dli
->u
.pc_offset
= func
->address
+ offset
;
343 /******************************************************************
344 * symt_add_func_local
346 * Adds a new local/parameter to a given function:
347 * In any cases, dt tells whether it's a local variable or a parameter
348 * If regno it's not 0:
349 * - then variable is stored in a register
350 * - otherwise, value is referenced by register + offset
351 * Otherwise, the variable is stored on the stack:
352 * - offset is then the offset from the frame register
354 struct symt_data
* symt_add_func_local(struct module
* module
,
355 struct symt_function
* func
,
357 const struct location
* loc
,
358 struct symt_block
* block
,
359 struct symt
* type
, const char* name
)
361 struct symt_data
* locsym
;
364 TRACE_(dbghelp_symt
)("Adding local symbol (%s:%s): %s %p\n",
365 debugstr_w(module
->module
.ModuleName
), func
->hash_elt
.name
,
369 assert(func
->symt
.tag
== SymTagFunction
);
370 assert(dt
== DataIsParam
|| dt
== DataIsLocal
);
372 locsym
= pool_alloc(&module
->pool
, sizeof(*locsym
));
373 locsym
->symt
.tag
= SymTagData
;
374 locsym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
375 locsym
->hash_elt
.next
= NULL
;
377 locsym
->container
= block
? &block
->symt
: &func
->symt
;
379 locsym
->u
.var
= *loc
;
381 p
= vector_add(&block
->vchildren
, &module
->pool
);
383 p
= vector_add(&func
->vchildren
, &module
->pool
);
389 struct symt_block
* symt_open_func_block(struct module
* module
,
390 struct symt_function
* func
,
391 struct symt_block
* parent_block
,
392 unsigned pc
, unsigned len
)
394 struct symt_block
* block
;
398 assert(func
->symt
.tag
== SymTagFunction
);
400 assert(!parent_block
|| parent_block
->symt
.tag
== SymTagBlock
);
401 block
= pool_alloc(&module
->pool
, sizeof(*block
));
402 block
->symt
.tag
= SymTagBlock
;
403 block
->address
= func
->address
+ pc
;
405 block
->container
= parent_block
? &parent_block
->symt
: &func
->symt
;
406 vector_init(&block
->vchildren
, sizeof(struct symt
*), 4);
408 p
= vector_add(&parent_block
->vchildren
, &module
->pool
);
410 p
= vector_add(&func
->vchildren
, &module
->pool
);
416 struct symt_block
* symt_close_func_block(struct module
* module
,
417 const struct symt_function
* func
,
418 struct symt_block
* block
, unsigned pc
)
421 assert(func
->symt
.tag
== SymTagFunction
);
423 if (pc
) block
->size
= func
->address
+ pc
- block
->address
;
424 return (block
->container
->tag
== SymTagBlock
) ?
425 GET_ENTRY(block
->container
, struct symt_block
, symt
) : NULL
;
428 struct symt_hierarchy_point
* symt_add_function_point(struct module
* module
,
429 struct symt_function
* func
,
430 enum SymTagEnum point
,
431 const struct location
* loc
,
434 struct symt_hierarchy_point
*sym
;
437 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
439 sym
->symt
.tag
= point
;
440 sym
->parent
= &func
->symt
;
442 sym
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : NULL
;
443 p
= vector_add(&func
->vchildren
, &module
->pool
);
449 BOOL
symt_normalize_function(struct module
* module
, const struct symt_function
* func
)
452 struct line_info
* dli
;
455 /* We aren't adding any more locals or line numbers to this function.
456 * Free any spare memory that we might have allocated.
458 assert(func
->symt
.tag
== SymTagFunction
);
460 /* EPP vector_pool_normalize(&func->vlines, &module->pool); */
461 /* EPP vector_pool_normalize(&func->vchildren, &module->pool); */
463 len
= vector_length(&func
->vlines
);
466 dli
= vector_at(&func
->vlines
, 0); dli
->is_first
= 1;
467 dli
= vector_at(&func
->vlines
, len
); dli
->is_last
= 1;
472 struct symt_thunk
* symt_new_thunk(struct module
* module
,
473 struct symt_compiland
* compiland
,
474 const char* name
, THUNK_ORDINAL ord
,
475 unsigned long addr
, unsigned long size
)
477 struct symt_thunk
* sym
;
479 TRACE_(dbghelp_symt
)("Adding global thunk %s:%s @%lx-%lx\n",
480 debugstr_w(module
->module
.ModuleName
), name
, addr
, addr
+ size
- 1);
482 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
484 sym
->symt
.tag
= SymTagThunk
;
485 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
486 sym
->container
= &compiland
->symt
;
490 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
494 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
501 struct symt_data
* symt_new_constant(struct module
* module
,
502 struct symt_compiland
* compiland
,
503 const char* name
, struct symt
* type
,
506 struct symt_data
* sym
;
508 TRACE_(dbghelp_symt
)("Adding constant value %s:%s\n",
509 debugstr_w(module
->module
.ModuleName
), name
);
511 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
513 sym
->symt
.tag
= SymTagData
;
514 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
515 sym
->kind
= DataIsConstant
;
516 sym
->container
= compiland
? &compiland
->symt
: NULL
;
519 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
523 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
530 struct symt_hierarchy_point
* symt_new_label(struct module
* module
,
531 struct symt_compiland
* compiland
,
532 const char* name
, unsigned long address
)
534 struct symt_hierarchy_point
* sym
;
536 TRACE_(dbghelp_symt
)("Adding global label value %s:%s\n",
537 debugstr_w(module
->module
.ModuleName
), name
);
539 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
541 sym
->symt
.tag
= SymTagLabel
;
542 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
543 sym
->loc
.kind
= loc_absolute
;
544 sym
->loc
.offset
= address
;
545 sym
->parent
= compiland
? &compiland
->symt
: NULL
;
546 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
550 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
557 /* expect sym_info->MaxNameLen to be set before being called */
558 static void symt_fill_sym_info(struct module_pair
* pair
,
559 const struct symt_function
* func
,
560 const struct symt
* sym
, SYMBOL_INFO
* sym_info
)
565 if (!symt_get_info(pair
->effective
, sym
, TI_GET_TYPE
, &sym_info
->TypeIndex
))
566 sym_info
->TypeIndex
= 0;
567 sym_info
->info
= symt_ptr2index(pair
->effective
, sym
);
568 sym_info
->Reserved
[0] = sym_info
->Reserved
[1] = 0;
569 if (!symt_get_info(pair
->effective
, sym
, TI_GET_LENGTH
, &size
) &&
570 (!sym_info
->TypeIndex
||
571 !symt_get_info(pair
->effective
, symt_index2ptr(pair
->effective
, sym_info
->TypeIndex
),
572 TI_GET_LENGTH
, &size
)))
574 sym_info
->Size
= (DWORD
)size
;
575 sym_info
->ModBase
= pair
->requested
->module
.BaseOfImage
;
583 const struct symt_data
* data
= (const struct symt_data
*)sym
;
587 sym_info
->Flags
|= SYMFLAG_PARAMETER
;
590 sym_info
->Flags
|= SYMFLAG_LOCAL
;
592 struct location loc
= data
->u
.var
;
594 if (loc
.kind
>= loc_user
)
597 struct module_format
* modfmt
;
599 for (i
= 0; i
< DFI_LAST
; i
++)
601 modfmt
= pair
->effective
->format_info
[i
];
602 if (modfmt
&& modfmt
->loc_compute
)
604 modfmt
->loc_compute(pair
->pcs
, modfmt
, func
, &loc
);
612 /* for now we report error cases as a negative register number */
615 sym_info
->Flags
|= SYMFLAG_REGISTER
;
616 sym_info
->Register
= loc
.reg
;
617 sym_info
->Address
= 0;
620 sym_info
->Flags
|= SYMFLAG_REGREL
;
621 sym_info
->Register
= loc
.reg
;
622 if (loc
.reg
== CV_REG_NONE
|| (int)loc
.reg
< 0 /* error */)
623 FIXME("suspicious register value %x\n", loc
.reg
);
624 sym_info
->Address
= loc
.offset
;
627 sym_info
->Flags
|= SYMFLAG_VALUEPRESENT
;
628 sym_info
->Value
= loc
.offset
;
631 FIXME("Shouldn't happen (kind=%d), debug reader backend is broken\n", loc
.kind
);
637 case DataIsFileStatic
:
638 switch (data
->u
.var
.kind
)
641 sym_info
->Flags
|= SYMFLAG_TLSREL
;
644 symt_get_address(sym
, &sym_info
->Address
);
645 sym_info
->Register
= 0;
648 FIXME("Shouldn't happen (kind=%d), debug reader backend is broken\n", data
->u
.var
.kind
);
653 sym_info
->Flags
|= SYMFLAG_VALUEPRESENT
;
654 switch (data
->u
.value
.n1
.n2
.vt
)
656 case VT_I4
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.lVal
; break;
657 case VT_I2
: sym_info
->Value
= (ULONG
)(long)data
->u
.value
.n1
.n2
.n3
.iVal
; break;
658 case VT_I1
: sym_info
->Value
= (ULONG
)(long)data
->u
.value
.n1
.n2
.n3
.cVal
; break;
659 case VT_UI4
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.ulVal
; break;
660 case VT_UI2
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.uiVal
; break;
661 case VT_UI1
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.bVal
; break;
662 case VT_I1
| VT_BYREF
: sym_info
->Value
= (ULONG64
)(DWORD_PTR
)data
->u
.value
.n1
.n2
.n3
.byref
; break;
663 case VT_EMPTY
: sym_info
->Value
= 0; break;
665 FIXME("Unsupported variant type (%u)\n", data
->u
.value
.n1
.n2
.vt
);
671 FIXME("Unhandled kind (%u) in sym data\n", data
->kind
);
675 case SymTagPublicSymbol
:
676 sym_info
->Flags
|= SYMFLAG_EXPORT
;
677 symt_get_address(sym
, &sym_info
->Address
);
680 sym_info
->Flags
|= SYMFLAG_FUNCTION
;
681 symt_get_address(sym
, &sym_info
->Address
);
684 sym_info
->Flags
|= SYMFLAG_THUNK
;
685 symt_get_address(sym
, &sym_info
->Address
);
688 symt_get_address(sym
, &sym_info
->Address
);
689 sym_info
->Register
= 0;
692 sym_info
->Scope
= 0; /* FIXME */
693 sym_info
->Tag
= sym
->tag
;
694 name
= symt_get_name(sym
);
695 if (sym_info
->MaxNameLen
)
697 if (sym
->tag
!= SymTagPublicSymbol
|| !(dbghelp_options
& SYMOPT_UNDNAME
) ||
698 ((sym_info
->NameLen
= UnDecorateSymbolName(name
, sym_info
->Name
,
699 sym_info
->MaxNameLen
, UNDNAME_NAME_ONLY
)) == 0))
701 sym_info
->NameLen
= min(strlen(name
), sym_info
->MaxNameLen
- 1);
702 memcpy(sym_info
->Name
, name
, sym_info
->NameLen
);
703 sym_info
->Name
[sym_info
->NameLen
] = '\0';
706 TRACE_(dbghelp_symt
)("%p => %s %u %s\n",
707 sym
, sym_info
->Name
, sym_info
->Size
,
708 wine_dbgstr_longlong(sym_info
->Address
));
713 PSYM_ENUMERATESYMBOLS_CALLBACK cb
;
715 SYMBOL_INFO
* sym_info
;
719 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
722 static BOOL
send_symbol(const struct sym_enum
* se
, struct module_pair
* pair
,
723 const struct symt_function
* func
, const struct symt
* sym
)
725 symt_fill_sym_info(pair
, func
, sym
, se
->sym_info
);
726 if (se
->index
&& se
->sym_info
->info
!= se
->index
) return FALSE
;
727 if (se
->tag
&& se
->sym_info
->Tag
!= se
->tag
) return FALSE
;
728 if (se
->addr
&& !(se
->addr
>= se
->sym_info
->Address
&& se
->addr
< se
->sym_info
->Address
+ se
->sym_info
->Size
)) return FALSE
;
729 return !se
->cb(se
->sym_info
, se
->sym_info
->Size
, se
->user
);
732 static BOOL
symt_enum_module(struct module_pair
* pair
, const WCHAR
* match
,
733 const struct sym_enum
* se
)
736 struct symt_ht
* sym
= NULL
;
737 struct hash_table_iter hti
;
741 hash_table_iter_init(&pair
->effective
->ht_symbols
, &hti
, NULL
);
742 while ((ptr
= hash_table_iter_up(&hti
)))
744 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
745 nameW
= symt_get_nameW(&sym
->symt
);
746 ret
= SymMatchStringW(nameW
, match
, FALSE
);
747 HeapFree(GetProcessHeap(), 0, nameW
);
750 se
->sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
751 se
->sym_info
->MaxNameLen
= sizeof(se
->buffer
) - sizeof(SYMBOL_INFO
);
752 if (send_symbol(se
, pair
, NULL
, &sym
->symt
)) return TRUE
;
758 static inline unsigned where_to_insert(struct module
* module
, unsigned high
, const struct symt_ht
* elt
)
760 unsigned low
= 0, mid
= high
/ 2;
764 symt_get_address(&elt
->symt
, &addr
);
767 switch (cmp_sorttab_addr(module
, mid
, addr
))
770 case -1: low
= mid
+ 1; break;
771 case 1: high
= mid
; break;
773 mid
= low
+ (high
- low
) / 2;
774 } while (low
< high
);
778 /***********************************************************************
781 * Rebuild sorted list of symbols for a module.
783 static BOOL
resort_symbols(struct module
* module
)
787 if (!(module
->module
.NumSyms
= module
->num_symbols
))
790 /* we know that set from 0 up to num_sorttab is already sorted
791 * so sort the remaining (new) symbols, and merge the two sets
792 * (unless the first set is empty)
794 delta
= module
->num_symbols
- module
->num_sorttab
;
795 qsort(&module
->addr_sorttab
[module
->num_sorttab
], delta
, sizeof(struct symt_ht
*), symt_cmp_addr
);
796 if (module
->num_sorttab
)
798 int i
, ins_idx
= module
->num_sorttab
, prev_ins_idx
;
799 static struct symt_ht
** tmp
;
800 static unsigned num_tmp
;
804 static struct symt_ht
** new;
806 new = HeapReAlloc(GetProcessHeap(), 0, tmp
, delta
* sizeof(struct symt_ht
*));
808 new = HeapAlloc(GetProcessHeap(), 0, delta
* sizeof(struct symt_ht
*));
811 module
->num_sorttab
= 0;
812 return resort_symbols(module
);
817 memcpy(tmp
, &module
->addr_sorttab
[module
->num_sorttab
], delta
* sizeof(struct symt_ht
*));
818 qsort(tmp
, delta
, sizeof(struct symt_ht
*), symt_cmp_addr
);
820 for (i
= delta
- 1; i
>= 0; i
--)
822 prev_ins_idx
= ins_idx
;
823 ins_idx
= where_to_insert(module
, ins_idx
, tmp
[i
]);
824 memmove(&module
->addr_sorttab
[ins_idx
+ i
+ 1],
825 &module
->addr_sorttab
[ins_idx
],
826 (prev_ins_idx
- ins_idx
) * sizeof(struct symt_ht
*));
827 module
->addr_sorttab
[ins_idx
+ i
] = tmp
[i
];
830 module
->num_sorttab
= module
->num_symbols
;
831 return module
->sortlist_valid
= TRUE
;
834 static void symt_get_length(struct module
* module
, const struct symt
* symt
, ULONG64
* size
)
838 if (symt_get_info(module
, symt
, TI_GET_LENGTH
, size
) && *size
)
841 if (symt_get_info(module
, symt
, TI_GET_TYPE
, &type_index
) &&
842 symt_get_info(module
, symt_index2ptr(module
, type_index
), TI_GET_LENGTH
, size
)) return;
843 *size
= 0x1000; /* arbitrary value */
846 /* assume addr is in module */
847 struct symt_ht
* symt_find_nearest(struct module
* module
, DWORD_PTR addr
)
850 ULONG64 ref_addr
, ref_size
;
852 if (!module
->sortlist_valid
|| !module
->addr_sorttab
)
854 if (!resort_symbols(module
)) return NULL
;
858 * Binary search to find closest symbol.
861 high
= module
->num_sorttab
;
863 symt_get_address(&module
->addr_sorttab
[0]->symt
, &ref_addr
);
864 if (addr
< ref_addr
) return NULL
;
867 symt_get_address(&module
->addr_sorttab
[high
- 1]->symt
, &ref_addr
);
868 symt_get_length(module
, &module
->addr_sorttab
[high
- 1]->symt
, &ref_size
);
869 if (addr
>= ref_addr
+ ref_size
) return NULL
;
872 while (high
> low
+ 1)
874 mid
= (high
+ low
) / 2;
875 if (cmp_sorttab_addr(module
, mid
, addr
) < 0)
880 if (low
!= high
&& high
!= module
->num_sorttab
&&
881 cmp_sorttab_addr(module
, high
, addr
) <= 0)
884 /* If found symbol is a public symbol, check if there are any other entries that
885 * might also have the same address, but would get better information
887 if (module
->addr_sorttab
[low
]->symt
.tag
== SymTagPublicSymbol
)
889 symt_get_address(&module
->addr_sorttab
[low
]->symt
, &ref_addr
);
891 module
->addr_sorttab
[low
- 1]->symt
.tag
!= SymTagPublicSymbol
&&
892 !cmp_sorttab_addr(module
, low
- 1, ref_addr
))
894 else if (low
< module
->num_sorttab
- 1 &&
895 module
->addr_sorttab
[low
+ 1]->symt
.tag
!= SymTagPublicSymbol
&&
896 !cmp_sorttab_addr(module
, low
+ 1, ref_addr
))
899 /* finally check that we fit into the found symbol */
900 symt_get_address(&module
->addr_sorttab
[low
]->symt
, &ref_addr
);
901 if (addr
< ref_addr
) return NULL
;
902 symt_get_length(module
, &module
->addr_sorttab
[low
]->symt
, &ref_size
);
903 if (addr
>= ref_addr
+ ref_size
) return NULL
;
905 return module
->addr_sorttab
[low
];
908 static BOOL
symt_enum_locals_helper(struct module_pair
* pair
,
909 const WCHAR
* match
, const struct sym_enum
* se
,
910 struct symt_function
* func
, const struct vector
* v
)
912 struct symt
* lsym
= NULL
;
913 DWORD pc
= pair
->pcs
->ctx_frame
.InstructionOffset
;
918 for (i
=0; i
<vector_length(v
); i
++)
920 lsym
= *(struct symt
**)vector_at(v
, i
);
925 struct symt_block
* block
= (struct symt_block
*)lsym
;
926 if (pc
< block
->address
|| block
->address
+ block
->size
<= pc
)
928 if (!symt_enum_locals_helper(pair
, match
, se
, func
, &block
->vchildren
))
933 nameW
= symt_get_nameW(lsym
);
934 ret
= SymMatchStringW(nameW
, match
,
935 !(dbghelp_options
& SYMOPT_CASE_INSENSITIVE
));
936 HeapFree(GetProcessHeap(), 0, nameW
);
939 if (send_symbol(se
, pair
, func
, lsym
)) return FALSE
;
943 case SymTagFuncDebugStart
:
944 case SymTagFuncDebugEnd
:
948 FIXME("Unknown type: %u (%x)\n", lsym
->tag
, lsym
->tag
);
955 static BOOL
symt_enum_locals(struct process
* pcs
, const WCHAR
* mask
,
956 const struct sym_enum
* se
)
958 struct module_pair pair
;
960 DWORD_PTR pc
= pcs
->ctx_frame
.InstructionOffset
;
962 se
->sym_info
->SizeOfStruct
= sizeof(*se
->sym_info
);
963 se
->sym_info
->MaxNameLen
= sizeof(se
->buffer
) - sizeof(SYMBOL_INFO
);
966 pair
.requested
= module_find_by_addr(pair
.pcs
, pc
, DMT_UNKNOWN
);
967 if (!module_get_debug(&pair
)) return FALSE
;
968 if ((sym
= symt_find_nearest(pair
.effective
, pc
)) == NULL
) return FALSE
;
970 if (sym
->symt
.tag
== SymTagFunction
)
972 return symt_enum_locals_helper(&pair
, mask
? mask
: starW
, se
, (struct symt_function
*)sym
,
973 &((struct symt_function
*)sym
)->vchildren
);
978 /******************************************************************
981 * Helper for transforming an ANSI symbol info into a UNICODE one.
982 * Assume that MaxNameLen is the same for both version (A & W).
984 void copy_symbolW(SYMBOL_INFOW
* siw
, const SYMBOL_INFO
* si
)
986 siw
->SizeOfStruct
= si
->SizeOfStruct
;
987 siw
->TypeIndex
= si
->TypeIndex
;
988 siw
->Reserved
[0] = si
->Reserved
[0];
989 siw
->Reserved
[1] = si
->Reserved
[1];
990 siw
->Index
= si
->info
; /* FIXME: see dbghelp.h */
991 siw
->Size
= si
->Size
;
992 siw
->ModBase
= si
->ModBase
;
993 siw
->Flags
= si
->Flags
;
994 siw
->Value
= si
->Value
;
995 siw
->Address
= si
->Address
;
996 siw
->Register
= si
->Register
;
997 siw
->Scope
= si
->Scope
;
999 siw
->NameLen
= si
->NameLen
;
1000 siw
->MaxNameLen
= si
->MaxNameLen
;
1001 MultiByteToWideChar(CP_ACP
, 0, si
->Name
, -1, siw
->Name
, siw
->MaxNameLen
);
1004 /******************************************************************
1007 * Core routine for most of the enumeration of symbols
1009 static BOOL
sym_enum(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1010 const struct sym_enum
* se
)
1012 struct module_pair pair
;
1016 pair
.pcs
= process_find_by_handle(hProcess
);
1017 if (!pair
.pcs
) return FALSE
;
1020 /* do local variables ? */
1021 if (!Mask
|| !(bang
= strchrW(Mask
, '!')))
1022 return symt_enum_locals(pair
.pcs
, Mask
, se
);
1024 if (bang
== Mask
) return FALSE
;
1026 mod
= HeapAlloc(GetProcessHeap(), 0, (bang
- Mask
+ 1) * sizeof(WCHAR
));
1027 if (!mod
) return FALSE
;
1028 memcpy(mod
, Mask
, (bang
- Mask
) * sizeof(WCHAR
));
1029 mod
[bang
- Mask
] = 0;
1031 for (pair
.requested
= pair
.pcs
->lmodules
; pair
.requested
; pair
.requested
= pair
.requested
->next
)
1033 if (pair
.requested
->type
== DMT_PE
&& module_get_debug(&pair
))
1035 if (SymMatchStringW(pair
.requested
->module
.ModuleName
, mod
, FALSE
) &&
1036 symt_enum_module(&pair
, bang
+ 1, se
))
1040 /* not found in PE modules, retry on the ELF ones
1042 if (!pair
.requested
&& (dbghelp_options
& SYMOPT_WINE_WITH_NATIVE_MODULES
))
1044 for (pair
.requested
= pair
.pcs
->lmodules
; pair
.requested
; pair
.requested
= pair
.requested
->next
)
1046 if ((pair
.requested
->type
== DMT_ELF
|| pair
.requested
->type
== DMT_MACHO
) &&
1047 !module_get_containee(pair
.pcs
, pair
.requested
) &&
1048 module_get_debug(&pair
))
1050 if (SymMatchStringW(pair
.requested
->module
.ModuleName
, mod
, FALSE
) &&
1051 symt_enum_module(&pair
, bang
+ 1, se
))
1056 HeapFree(GetProcessHeap(), 0, mod
);
1059 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
1060 if (!module_get_debug(&pair
))
1063 /* we always ignore module name from Mask when BaseOfDll is defined */
1064 if (Mask
&& (bang
= strchrW(Mask
, '!')))
1066 if (bang
== Mask
) return FALSE
;
1070 symt_enum_module(&pair
, Mask
? Mask
: starW
, se
);
1075 static inline BOOL
doSymEnumSymbols(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1076 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1081 se
.cb
= EnumSymbolsCallback
;
1082 se
.user
= UserContext
;
1086 se
.sym_info
= (PSYMBOL_INFO
)se
.buffer
;
1088 return sym_enum(hProcess
, BaseOfDll
, Mask
, &se
);
1091 /******************************************************************
1092 * SymEnumSymbols (DBGHELP.@)
1094 * cases BaseOfDll = 0
1095 * !foo fails always (despite what MSDN states)
1096 * RE1!RE2 looks up all modules matching RE1, and in all these modules, lookup RE2
1097 * no ! in Mask, lookup in local Context
1098 * cases BaseOfDll != 0
1099 * !foo fails always (despite what MSDN states)
1100 * RE1!RE2 gets RE2 from BaseOfDll (whatever RE1 is)
1102 BOOL WINAPI
SymEnumSymbols(HANDLE hProcess
, ULONG64 BaseOfDll
, PCSTR Mask
,
1103 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1109 TRACE("(%p %s %s %p %p)\n",
1110 hProcess
, wine_dbgstr_longlong(BaseOfDll
), debugstr_a(Mask
),
1111 EnumSymbolsCallback
, UserContext
);
1115 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, NULL
, 0);
1116 if (!(maskW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1118 MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, maskW
, sz
);
1120 ret
= doSymEnumSymbols(hProcess
, BaseOfDll
, maskW
, EnumSymbolsCallback
, UserContext
);
1121 HeapFree(GetProcessHeap(), 0, maskW
);
1127 PSYM_ENUMERATESYMBOLS_CALLBACKW cb
;
1129 PSYMBOL_INFOW sym_info
;
1130 char buffer
[sizeof(SYMBOL_INFOW
) + MAX_SYM_NAME
];
1134 static BOOL CALLBACK
sym_enumW(PSYMBOL_INFO si
, ULONG size
, PVOID ctx
)
1136 struct sym_enumW
* sew
= ctx
;
1138 copy_symbolW(sew
->sym_info
, si
);
1140 return (sew
->cb
)(sew
->sym_info
, size
, sew
->ctx
);
1143 /******************************************************************
1144 * SymEnumSymbolsW (DBGHELP.@)
1147 BOOL WINAPI
SymEnumSymbolsW(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1148 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
1151 struct sym_enumW sew
;
1153 sew
.ctx
= UserContext
;
1154 sew
.cb
= EnumSymbolsCallback
;
1155 sew
.sym_info
= (PSYMBOL_INFOW
)sew
.buffer
;
1157 return doSymEnumSymbols(hProcess
, BaseOfDll
, Mask
, sym_enumW
, &sew
);
1160 struct sym_enumerate
1163 PSYM_ENUMSYMBOLS_CALLBACK cb
;
1166 static BOOL CALLBACK
sym_enumerate_cb(PSYMBOL_INFO syminfo
, ULONG size
, void* ctx
)
1168 struct sym_enumerate
* se
= ctx
;
1169 return (se
->cb
)(syminfo
->Name
, syminfo
->Address
, syminfo
->Size
, se
->ctx
);
1172 /***********************************************************************
1173 * SymEnumerateSymbols (DBGHELP.@)
1175 BOOL WINAPI
SymEnumerateSymbols(HANDLE hProcess
, DWORD BaseOfDll
,
1176 PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback
,
1179 struct sym_enumerate se
;
1181 se
.ctx
= UserContext
;
1182 se
.cb
= EnumSymbolsCallback
;
1184 return SymEnumSymbols(hProcess
, BaseOfDll
, NULL
, sym_enumerate_cb
, &se
);
1187 struct sym_enumerate64
1190 PSYM_ENUMSYMBOLS_CALLBACK64 cb
;
1193 static BOOL CALLBACK
sym_enumerate_cb64(PSYMBOL_INFO syminfo
, ULONG size
, void* ctx
)
1195 struct sym_enumerate64
* se
= ctx
;
1196 return (se
->cb
)(syminfo
->Name
, syminfo
->Address
, syminfo
->Size
, se
->ctx
);
1199 /***********************************************************************
1200 * SymEnumerateSymbols64 (DBGHELP.@)
1202 BOOL WINAPI
SymEnumerateSymbols64(HANDLE hProcess
, DWORD64 BaseOfDll
,
1203 PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback
,
1206 struct sym_enumerate64 se
;
1208 se
.ctx
= UserContext
;
1209 se
.cb
= EnumSymbolsCallback
;
1211 return SymEnumSymbols(hProcess
, BaseOfDll
, NULL
, sym_enumerate_cb64
, &se
);
1214 /******************************************************************
1215 * SymFromAddr (DBGHELP.@)
1218 BOOL WINAPI
SymFromAddr(HANDLE hProcess
, DWORD64 Address
,
1219 DWORD64
* Displacement
, PSYMBOL_INFO Symbol
)
1221 struct module_pair pair
;
1222 struct symt_ht
* sym
;
1224 pair
.pcs
= process_find_by_handle(hProcess
);
1225 if (!pair
.pcs
) return FALSE
;
1226 pair
.requested
= module_find_by_addr(pair
.pcs
, Address
, DMT_UNKNOWN
);
1227 if (!module_get_debug(&pair
)) return FALSE
;
1228 if ((sym
= symt_find_nearest(pair
.effective
, Address
)) == NULL
) return FALSE
;
1230 symt_fill_sym_info(&pair
, NULL
, &sym
->symt
, Symbol
);
1232 *Displacement
= Address
- Symbol
->Address
;
1236 /******************************************************************
1237 * SymFromAddrW (DBGHELP.@)
1240 BOOL WINAPI
SymFromAddrW(HANDLE hProcess
, DWORD64 Address
,
1241 DWORD64
* Displacement
, PSYMBOL_INFOW Symbol
)
1247 len
= sizeof(*si
) + Symbol
->MaxNameLen
* sizeof(WCHAR
);
1248 si
= HeapAlloc(GetProcessHeap(), 0, len
);
1249 if (!si
) return FALSE
;
1251 si
->SizeOfStruct
= sizeof(*si
);
1252 si
->MaxNameLen
= Symbol
->MaxNameLen
;
1253 if ((ret
= SymFromAddr(hProcess
, Address
, Displacement
, si
)))
1255 copy_symbolW(Symbol
, si
);
1257 HeapFree(GetProcessHeap(), 0, si
);
1261 /******************************************************************
1262 * SymGetSymFromAddr (DBGHELP.@)
1265 BOOL WINAPI
SymGetSymFromAddr(HANDLE hProcess
, DWORD Address
,
1266 PDWORD Displacement
, PIMAGEHLP_SYMBOL Symbol
)
1268 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1269 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1271 DWORD64 Displacement64
;
1273 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1274 si
->SizeOfStruct
= sizeof(*si
);
1275 si
->MaxNameLen
= MAX_SYM_NAME
;
1276 if (!SymFromAddr(hProcess
, Address
, &Displacement64
, si
))
1280 *Displacement
= Displacement64
;
1281 Symbol
->Address
= si
->Address
;
1282 Symbol
->Size
= si
->Size
;
1283 Symbol
->Flags
= si
->Flags
;
1284 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1285 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1289 /******************************************************************
1290 * SymGetSymFromAddr64 (DBGHELP.@)
1293 BOOL WINAPI
SymGetSymFromAddr64(HANDLE hProcess
, DWORD64 Address
,
1294 PDWORD64 Displacement
, PIMAGEHLP_SYMBOL64 Symbol
)
1296 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1297 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1299 DWORD64 Displacement64
;
1301 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1302 si
->SizeOfStruct
= sizeof(*si
);
1303 si
->MaxNameLen
= MAX_SYM_NAME
;
1304 if (!SymFromAddr(hProcess
, Address
, &Displacement64
, si
))
1308 *Displacement
= Displacement64
;
1309 Symbol
->Address
= si
->Address
;
1310 Symbol
->Size
= si
->Size
;
1311 Symbol
->Flags
= si
->Flags
;
1312 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1313 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1317 static BOOL
find_name(struct process
* pcs
, struct module
* module
, const char* name
,
1318 SYMBOL_INFO
* symbol
)
1320 struct hash_table_iter hti
;
1322 struct symt_ht
* sym
= NULL
;
1323 struct module_pair pair
;
1326 if (!(pair
.requested
= module
)) return FALSE
;
1327 if (!module_get_debug(&pair
)) return FALSE
;
1329 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, name
);
1330 while ((ptr
= hash_table_iter_up(&hti
)))
1332 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
1334 if (!strcmp(sym
->hash_elt
.name
, name
))
1336 symt_fill_sym_info(&pair
, NULL
, &sym
->symt
, symbol
);
1343 /******************************************************************
1344 * SymFromName (DBGHELP.@)
1347 BOOL WINAPI
SymFromName(HANDLE hProcess
, PCSTR Name
, PSYMBOL_INFO Symbol
)
1349 struct process
* pcs
= process_find_by_handle(hProcess
);
1350 struct module
* module
;
1353 TRACE("(%p, %s, %p)\n", hProcess
, Name
, Symbol
);
1354 if (!pcs
) return FALSE
;
1355 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1356 name
= strchr(Name
, '!');
1360 assert(name
- Name
< sizeof(tmp
));
1361 memcpy(tmp
, Name
, name
- Name
);
1362 tmp
[name
- Name
] = '\0';
1363 module
= module_find_by_nameA(pcs
, tmp
);
1364 return find_name(pcs
, module
, name
+ 1, Symbol
);
1366 for (module
= pcs
->lmodules
; module
; module
= module
->next
)
1368 if (module
->type
== DMT_PE
&& find_name(pcs
, module
, Name
, Symbol
))
1371 /* not found in PE modules, retry on the ELF ones
1373 if (dbghelp_options
& SYMOPT_WINE_WITH_NATIVE_MODULES
)
1375 for (module
= pcs
->lmodules
; module
; module
= module
->next
)
1377 if ((module
->type
== DMT_ELF
|| module
->type
== DMT_MACHO
) &&
1378 !module_get_containee(pcs
, module
) &&
1379 find_name(pcs
, module
, Name
, Symbol
))
1386 /***********************************************************************
1387 * SymGetSymFromName64 (DBGHELP.@)
1389 BOOL WINAPI
SymGetSymFromName64(HANDLE hProcess
, PCSTR Name
, PIMAGEHLP_SYMBOL64 Symbol
)
1391 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1392 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1395 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1396 si
->SizeOfStruct
= sizeof(*si
);
1397 si
->MaxNameLen
= MAX_SYM_NAME
;
1398 if (!SymFromName(hProcess
, Name
, si
)) return FALSE
;
1400 Symbol
->Address
= si
->Address
;
1401 Symbol
->Size
= si
->Size
;
1402 Symbol
->Flags
= si
->Flags
;
1403 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1404 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1408 /***********************************************************************
1409 * SymGetSymFromName (DBGHELP.@)
1411 BOOL WINAPI
SymGetSymFromName(HANDLE hProcess
, PCSTR Name
, PIMAGEHLP_SYMBOL Symbol
)
1413 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1414 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1417 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1418 si
->SizeOfStruct
= sizeof(*si
);
1419 si
->MaxNameLen
= MAX_SYM_NAME
;
1420 if (!SymFromName(hProcess
, Name
, si
)) return FALSE
;
1422 Symbol
->Address
= si
->Address
;
1423 Symbol
->Size
= si
->Size
;
1424 Symbol
->Flags
= si
->Flags
;
1425 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1426 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1430 /******************************************************************
1431 * sym_fill_func_line_info
1433 * fills information about a file
1435 BOOL
symt_fill_func_line_info(const struct module
* module
, const struct symt_function
* func
,
1436 DWORD64 addr
, IMAGEHLP_LINE64
* line
)
1438 struct line_info
* dli
= NULL
;
1442 assert(func
->symt
.tag
== SymTagFunction
);
1444 for (i
=vector_length(&func
->vlines
)-1; i
>=0; i
--)
1446 dli
= vector_at(&func
->vlines
, i
);
1447 if (!dli
->is_source_file
)
1449 if (found
|| dli
->u
.pc_offset
> addr
) continue;
1450 line
->LineNumber
= dli
->line_number
;
1451 line
->Address
= dli
->u
.pc_offset
;
1458 line
->FileName
= (char*)source_get(module
, dli
->u
.source_file
);
1465 /***********************************************************************
1466 * SymGetSymNext64 (DBGHELP.@)
1468 BOOL WINAPI
SymGetSymNext64(HANDLE hProcess
, PIMAGEHLP_SYMBOL64 Symbol
)
1471 * get module from Symbol.Address
1472 * get index in module.addr_sorttab of Symbol.Address
1474 * if out of module bounds, move to next module in process address space
1476 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1477 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1481 /***********************************************************************
1482 * SymGetSymNext (DBGHELP.@)
1484 BOOL WINAPI
SymGetSymNext(HANDLE hProcess
, PIMAGEHLP_SYMBOL Symbol
)
1486 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1487 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1491 /***********************************************************************
1492 * SymGetSymPrev64 (DBGHELP.@)
1494 BOOL WINAPI
SymGetSymPrev64(HANDLE hProcess
, PIMAGEHLP_SYMBOL64 Symbol
)
1496 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1497 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1501 /***********************************************************************
1502 * SymGetSymPrev (DBGHELP.@)
1504 BOOL WINAPI
SymGetSymPrev(HANDLE hProcess
, PIMAGEHLP_SYMBOL Symbol
)
1506 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1507 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1511 /******************************************************************
1512 * copy_line_64_from_32 (internal)
1515 static void copy_line_64_from_32(IMAGEHLP_LINE64
* l64
, const IMAGEHLP_LINE
* l32
)
1518 l64
->Key
= l32
->Key
;
1519 l64
->LineNumber
= l32
->LineNumber
;
1520 l64
->FileName
= l32
->FileName
;
1521 l64
->Address
= l32
->Address
;
1524 /******************************************************************
1525 * copy_line_W64_from_32 (internal)
1528 static void copy_line_W64_from_64(struct process
* pcs
, IMAGEHLP_LINEW64
* l64w
, const IMAGEHLP_LINE64
* l64
)
1532 l64w
->Key
= l64
->Key
;
1533 l64w
->LineNumber
= l64
->LineNumber
;
1534 len
= MultiByteToWideChar(CP_ACP
, 0, l64
->FileName
, -1, NULL
, 0);
1535 if ((l64w
->FileName
= fetch_buffer(pcs
, len
* sizeof(WCHAR
))))
1536 MultiByteToWideChar(CP_ACP
, 0, l64
->FileName
, -1, l64w
->FileName
, len
);
1537 l64w
->Address
= l64
->Address
;
1540 /******************************************************************
1541 * copy_line_32_from_64 (internal)
1544 static void copy_line_32_from_64(IMAGEHLP_LINE
* l32
, const IMAGEHLP_LINE64
* l64
)
1547 l32
->Key
= l64
->Key
;
1548 l32
->LineNumber
= l64
->LineNumber
;
1549 l32
->FileName
= l64
->FileName
;
1550 l32
->Address
= l64
->Address
;
1553 /******************************************************************
1554 * SymGetLineFromAddr (DBGHELP.@)
1557 BOOL WINAPI
SymGetLineFromAddr(HANDLE hProcess
, DWORD dwAddr
,
1558 PDWORD pdwDisplacement
, PIMAGEHLP_LINE Line
)
1560 IMAGEHLP_LINE64 il64
;
1562 il64
.SizeOfStruct
= sizeof(il64
);
1563 if (!SymGetLineFromAddr64(hProcess
, dwAddr
, pdwDisplacement
, &il64
))
1565 copy_line_32_from_64(Line
, &il64
);
1569 /******************************************************************
1570 * SymGetLineFromAddr64 (DBGHELP.@)
1573 BOOL WINAPI
SymGetLineFromAddr64(HANDLE hProcess
, DWORD64 dwAddr
,
1574 PDWORD pdwDisplacement
, PIMAGEHLP_LINE64 Line
)
1576 struct module_pair pair
;
1577 struct symt_ht
* symt
;
1579 TRACE("%p %s %p %p\n", hProcess
, wine_dbgstr_longlong(dwAddr
), pdwDisplacement
, Line
);
1581 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1583 pair
.pcs
= process_find_by_handle(hProcess
);
1584 if (!pair
.pcs
) return FALSE
;
1585 pair
.requested
= module_find_by_addr(pair
.pcs
, dwAddr
, DMT_UNKNOWN
);
1586 if (!module_get_debug(&pair
)) return FALSE
;
1587 if ((symt
= symt_find_nearest(pair
.effective
, dwAddr
)) == NULL
) return FALSE
;
1589 if (symt
->symt
.tag
!= SymTagFunction
) return FALSE
;
1590 if (!symt_fill_func_line_info(pair
.effective
, (struct symt_function
*)symt
,
1591 dwAddr
, Line
)) return FALSE
;
1592 *pdwDisplacement
= dwAddr
- Line
->Address
;
1596 /******************************************************************
1597 * SymGetLineFromAddrW64 (DBGHELP.@)
1600 BOOL WINAPI
SymGetLineFromAddrW64(HANDLE hProcess
, DWORD64 dwAddr
,
1601 PDWORD pdwDisplacement
, PIMAGEHLP_LINEW64 Line
)
1603 IMAGEHLP_LINE64 il64
;
1605 il64
.SizeOfStruct
= sizeof(il64
);
1606 if (!SymGetLineFromAddr64(hProcess
, dwAddr
, pdwDisplacement
, &il64
))
1608 copy_line_W64_from_64(process_find_by_handle(hProcess
), Line
, &il64
);
1612 /******************************************************************
1613 * SymGetLinePrev64 (DBGHELP.@)
1616 BOOL WINAPI
SymGetLinePrev64(HANDLE hProcess
, PIMAGEHLP_LINE64 Line
)
1618 struct module_pair pair
;
1619 struct line_info
* li
;
1620 BOOL in_search
= FALSE
;
1622 TRACE("(%p %p)\n", hProcess
, Line
);
1624 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1626 pair
.pcs
= process_find_by_handle(hProcess
);
1627 if (!pair
.pcs
) return FALSE
;
1628 pair
.requested
= module_find_by_addr(pair
.pcs
, Line
->Address
, DMT_UNKNOWN
);
1629 if (!module_get_debug(&pair
)) return FALSE
;
1631 if (Line
->Key
== 0) return FALSE
;
1633 /* things are a bit complicated because when we encounter a DLIT_SOURCEFILE
1634 * element we have to go back until we find the prev one to get the real
1635 * source file name for the DLIT_OFFSET element just before
1636 * the first DLIT_SOURCEFILE
1638 while (!li
->is_first
)
1641 if (!li
->is_source_file
)
1643 Line
->LineNumber
= li
->line_number
;
1644 Line
->Address
= li
->u
.pc_offset
;
1646 if (!in_search
) return TRUE
;
1652 Line
->FileName
= (char*)source_get(pair
.effective
, li
->u
.source_file
);
1658 SetLastError(ERROR_NO_MORE_ITEMS
); /* FIXME */
1662 /******************************************************************
1663 * SymGetLinePrev (DBGHELP.@)
1666 BOOL WINAPI
SymGetLinePrev(HANDLE hProcess
, PIMAGEHLP_LINE Line
)
1668 IMAGEHLP_LINE64 line64
;
1670 line64
.SizeOfStruct
= sizeof(line64
);
1671 copy_line_64_from_32(&line64
, Line
);
1672 if (!SymGetLinePrev64(hProcess
, &line64
)) return FALSE
;
1673 copy_line_32_from_64(Line
, &line64
);
1677 BOOL
symt_get_func_line_next(const struct module
* module
, PIMAGEHLP_LINE64 line
)
1679 struct line_info
* li
;
1681 if (line
->Key
== 0) return FALSE
;
1683 while (!li
->is_last
)
1686 if (!li
->is_source_file
)
1688 line
->LineNumber
= li
->line_number
;
1689 line
->Address
= li
->u
.pc_offset
;
1693 line
->FileName
= (char*)source_get(module
, li
->u
.source_file
);
1698 /******************************************************************
1699 * SymGetLineNext64 (DBGHELP.@)
1702 BOOL WINAPI
SymGetLineNext64(HANDLE hProcess
, PIMAGEHLP_LINE64 Line
)
1704 struct module_pair pair
;
1706 TRACE("(%p %p)\n", hProcess
, Line
);
1708 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1709 pair
.pcs
= process_find_by_handle(hProcess
);
1710 if (!pair
.pcs
) return FALSE
;
1711 pair
.requested
= module_find_by_addr(pair
.pcs
, Line
->Address
, DMT_UNKNOWN
);
1712 if (!module_get_debug(&pair
)) return FALSE
;
1714 if (symt_get_func_line_next(pair
.effective
, Line
)) return TRUE
;
1715 SetLastError(ERROR_NO_MORE_ITEMS
); /* FIXME */
1719 /******************************************************************
1720 * SymGetLineNext (DBGHELP.@)
1723 BOOL WINAPI
SymGetLineNext(HANDLE hProcess
, PIMAGEHLP_LINE Line
)
1725 IMAGEHLP_LINE64 line64
;
1727 line64
.SizeOfStruct
= sizeof(line64
);
1728 copy_line_64_from_32(&line64
, Line
);
1729 if (!SymGetLineNext64(hProcess
, &line64
)) return FALSE
;
1730 copy_line_32_from_64(Line
, &line64
);
1734 /***********************************************************************
1735 * SymUnDName (DBGHELP.@)
1737 BOOL WINAPI
SymUnDName(PIMAGEHLP_SYMBOL sym
, PSTR UnDecName
, DWORD UnDecNameLength
)
1739 return UnDecorateSymbolName(sym
->Name
, UnDecName
, UnDecNameLength
,
1740 UNDNAME_COMPLETE
) != 0;
1743 /***********************************************************************
1744 * SymUnDName64 (DBGHELP.@)
1746 BOOL WINAPI
SymUnDName64(PIMAGEHLP_SYMBOL64 sym
, PSTR UnDecName
, DWORD UnDecNameLength
)
1748 return UnDecorateSymbolName(sym
->Name
, UnDecName
, UnDecNameLength
,
1749 UNDNAME_COMPLETE
) != 0;
1752 static void * CDECL
und_alloc(size_t len
) { return HeapAlloc(GetProcessHeap(), 0, len
); }
1753 static void CDECL
und_free (void* ptr
) { HeapFree(GetProcessHeap(), 0, ptr
); }
1755 /***********************************************************************
1756 * UnDecorateSymbolName (DBGHELP.@)
1758 DWORD WINAPI
UnDecorateSymbolName(PCSTR DecoratedName
, PSTR UnDecoratedName
,
1759 DWORD UndecoratedLength
, DWORD Flags
)
1761 /* undocumented from msvcrt */
1762 static HANDLE hMsvcrt
;
1763 static char* (CDECL
*p_undname
)(char*, const char*, int, void* (CDECL
*)(size_t), void (CDECL
*)(void*), unsigned short);
1764 static const WCHAR szMsvcrt
[] = {'m','s','v','c','r','t','.','d','l','l',0};
1766 TRACE("(%s, %p, %d, 0x%08x)\n",
1767 debugstr_a(DecoratedName
), UnDecoratedName
, UndecoratedLength
, Flags
);
1771 if (!hMsvcrt
) hMsvcrt
= LoadLibraryW(szMsvcrt
);
1772 if (hMsvcrt
) p_undname
= (void*)GetProcAddress(hMsvcrt
, "__unDName");
1773 if (!p_undname
) return 0;
1776 if (!UnDecoratedName
) return 0;
1777 if (!p_undname(UnDecoratedName
, DecoratedName
, UndecoratedLength
,
1778 und_alloc
, und_free
, Flags
))
1780 return strlen(UnDecoratedName
);
1783 #define WILDCHAR(x) (-(x))
1785 static int re_fetch_char(const WCHAR
** re
)
1789 case '\\': (*re
)++; return *(*re
)++;
1790 case '*': case '[': case '?': case '+': case '#': case ']': return WILDCHAR(*(*re
)++);
1791 default: return *(*re
)++;
1795 static inline int re_match_char(WCHAR ch1
, WCHAR ch2
, BOOL _case
)
1797 return _case
? ch1
- ch2
: toupperW(ch1
) - toupperW(ch2
);
1800 static const WCHAR
* re_match_one(const WCHAR
* string
, const WCHAR
* elt
, BOOL _case
)
1805 switch (ch1
= re_fetch_char(&elt
))
1808 return (ch1
>= 0 && re_match_char(*string
, ch1
, _case
) == 0) ? ++string
: NULL
;
1809 case WILDCHAR('?'): return *string
? ++string
: NULL
;
1810 case WILDCHAR('*'): assert(0);
1811 case WILDCHAR('['): break;
1816 ch1
= re_fetch_char(&elt
);
1817 if (ch1
== WILDCHAR(']')) return NULL
;
1818 if (state
== 1 && ch1
== '-') state
= 2;
1821 if (re_match_char(*string
, ch1
, _case
) == 0) return ++string
;
1832 if (prev
>= 0 && ch1
>= 0 && re_match_char(prev
, *string
, _case
) <= 0 &&
1833 re_match_char(*string
, ch1
, _case
) <= 0)
1842 /******************************************************************
1845 * match a substring of *pstring according to *pre regular expression
1846 * pstring and pre are only updated in case of successful match
1848 static BOOL
re_match_multi(const WCHAR
** pstring
, const WCHAR
** pre
, BOOL _case
)
1850 const WCHAR
* re_end
= *pre
;
1851 const WCHAR
* string_end
= *pstring
;
1852 const WCHAR
* re_beg
;
1853 const WCHAR
* string_beg
;
1857 while (*re_end
&& *string_end
)
1859 string_beg
= string_end
;
1861 switch (ch
= re_fetch_char(&re_end
))
1863 case WILDCHAR(']'): case WILDCHAR('+'): case WILDCHAR('#'): return FALSE
;
1865 /* transform '*' into '?#' */
1866 {static const WCHAR qmW
[] = {'?',0}; re_beg
= qmW
;}
1871 if (!(ch
= re_fetch_char(&re_end
))) return FALSE
;
1872 } while (ch
!= WILDCHAR(']'));
1882 if (!(next
= re_match_one(string_end
, re_beg
, _case
))) return FALSE
;
1888 while ((next
= re_match_one(string_end
, re_beg
, _case
))) string_end
= next
;
1889 for ( ; string_end
>= string_beg
; string_end
--)
1891 if (re_match_multi(&string_end
, &re_end
, _case
)) goto found
;
1895 if (!(next
= re_match_one(string_end
, re_beg
, _case
))) return FALSE
;
1901 if (*re_end
|| *string_end
) return FALSE
;
1905 *pstring
= string_end
;
1909 /******************************************************************
1910 * SymMatchStringA (DBGHELP.@)
1913 BOOL WINAPI
SymMatchStringA(PCSTR string
, PCSTR re
, BOOL _case
)
1922 SetLastError(ERROR_INVALID_HANDLE
);
1925 TRACE("%s %s %c\n", string
, re
, _case
? 'Y' : 'N');
1927 sz
= MultiByteToWideChar(CP_ACP
, 0, string
, -1, NULL
, 0);
1928 if ((strW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1929 MultiByteToWideChar(CP_ACP
, 0, string
, -1, strW
, sz
);
1930 sz
= MultiByteToWideChar(CP_ACP
, 0, re
, -1, NULL
, 0);
1931 if ((reW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1932 MultiByteToWideChar(CP_ACP
, 0, re
, -1, reW
, sz
);
1935 ret
= SymMatchStringW(strW
, reW
, _case
);
1936 HeapFree(GetProcessHeap(), 0, strW
);
1937 HeapFree(GetProcessHeap(), 0, reW
);
1941 /******************************************************************
1942 * SymMatchStringW (DBGHELP.@)
1945 BOOL WINAPI
SymMatchStringW(PCWSTR string
, PCWSTR re
, BOOL _case
)
1947 TRACE("%s %s %c\n", debugstr_w(string
), debugstr_w(re
), _case
? 'Y' : 'N');
1951 SetLastError(ERROR_INVALID_HANDLE
);
1954 return re_match_multi(&string
, &re
, _case
);
1957 static inline BOOL
doSymSearch(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
1958 DWORD SymTag
, PCWSTR Mask
, DWORD64 Address
,
1959 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1960 PVOID UserContext
, DWORD Options
)
1964 if (Options
!= SYMSEARCH_GLOBALSONLY
)
1966 FIXME("Unsupported searching with options (%x)\n", Options
);
1967 SetLastError(ERROR_INVALID_PARAMETER
);
1971 se
.cb
= EnumSymbolsCallback
;
1972 se
.user
= UserContext
;
1976 se
.sym_info
= (PSYMBOL_INFO
)se
.buffer
;
1978 return sym_enum(hProcess
, BaseOfDll
, Mask
, &se
);
1981 /******************************************************************
1982 * SymSearch (DBGHELP.@)
1984 BOOL WINAPI
SymSearch(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
1985 DWORD SymTag
, PCSTR Mask
, DWORD64 Address
,
1986 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1987 PVOID UserContext
, DWORD Options
)
1989 LPWSTR maskW
= NULL
;
1992 TRACE("(%p %s %u %u %s %s %p %p %x)\n",
1993 hProcess
, wine_dbgstr_longlong(BaseOfDll
), Index
, SymTag
, Mask
,
1994 wine_dbgstr_longlong(Address
), EnumSymbolsCallback
,
1995 UserContext
, Options
);
1999 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, NULL
, 0);
2001 if (!(maskW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2003 MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, maskW
, sz
);
2005 ret
= doSymSearch(hProcess
, BaseOfDll
, Index
, SymTag
, maskW
, Address
,
2006 EnumSymbolsCallback
, UserContext
, Options
);
2007 HeapFree(GetProcessHeap(), 0, maskW
);
2011 /******************************************************************
2012 * SymSearchW (DBGHELP.@)
2014 BOOL WINAPI
SymSearchW(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
2015 DWORD SymTag
, PCWSTR Mask
, DWORD64 Address
,
2016 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
2017 PVOID UserContext
, DWORD Options
)
2019 struct sym_enumW sew
;
2021 TRACE("(%p %s %u %u %s %s %p %p %x)\n",
2022 hProcess
, wine_dbgstr_longlong(BaseOfDll
), Index
, SymTag
, debugstr_w(Mask
),
2023 wine_dbgstr_longlong(Address
), EnumSymbolsCallback
,
2024 UserContext
, Options
);
2026 sew
.ctx
= UserContext
;
2027 sew
.cb
= EnumSymbolsCallback
;
2028 sew
.sym_info
= (PSYMBOL_INFOW
)sew
.buffer
;
2030 return doSymSearch(hProcess
, BaseOfDll
, Index
, SymTag
, Mask
, Address
,
2031 sym_enumW
, &sew
, Options
);
2034 /******************************************************************
2035 * SymAddSymbol (DBGHELP.@)
2038 BOOL WINAPI
SymAddSymbol(HANDLE hProcess
, ULONG64 BaseOfDll
, PCSTR name
,
2039 DWORD64 addr
, DWORD size
, DWORD flags
)
2041 WCHAR nameW
[MAX_SYM_NAME
];
2043 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
) / sizeof(WCHAR
));
2044 return SymAddSymbolW(hProcess
, BaseOfDll
, nameW
, addr
, size
, flags
);
2047 /******************************************************************
2048 * SymAddSymbolW (DBGHELP.@)
2051 BOOL WINAPI
SymAddSymbolW(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR name
,
2052 DWORD64 addr
, DWORD size
, DWORD flags
)
2054 struct module_pair pair
;
2056 TRACE("(%p %s %s %u)\n", hProcess
, wine_dbgstr_w(name
), wine_dbgstr_longlong(addr
), size
);
2058 pair
.pcs
= process_find_by_handle(hProcess
);
2059 if (!pair
.pcs
) return FALSE
;
2060 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
2061 if (!module_get_debug(&pair
)) return FALSE
;
2063 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2067 /******************************************************************
2068 * SymSetScopeFromAddr (DBGHELP.@)
2070 BOOL WINAPI
SymSetScopeFromAddr(HANDLE hProcess
, ULONG64 addr
)
2072 struct process
* pcs
;
2074 FIXME("(%p %s): stub\n", hProcess
, wine_dbgstr_longlong(addr
));
2076 if (!(pcs
= process_find_by_handle(hProcess
))) return FALSE
;
2080 /******************************************************************
2081 * SymEnumLines (DBGHELP.@)
2084 BOOL WINAPI
SymEnumLines(HANDLE hProcess
, ULONG64 base
, PCSTR compiland
,
2085 PCSTR srcfile
, PSYM_ENUMLINES_CALLBACK cb
, PVOID user
)
2087 struct module_pair pair
;
2088 struct hash_table_iter hti
;
2089 struct symt_ht
* sym
;
2091 struct line_info
* dli
;
2096 if (!cb
) return FALSE
;
2097 if (!(dbghelp_options
& SYMOPT_LOAD_LINES
)) return TRUE
;
2099 pair
.pcs
= process_find_by_handle(hProcess
);
2100 if (!pair
.pcs
) return FALSE
;
2101 if (compiland
) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland
);
2102 pair
.requested
= module_find_by_addr(pair
.pcs
, base
, DMT_UNKNOWN
);
2103 if (!module_get_debug(&pair
)) return FALSE
;
2104 if (!(srcmask
= file_regex(srcfile
))) return FALSE
;
2106 sci
.SizeOfStruct
= sizeof(sci
);
2109 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, NULL
);
2110 while ((ptr
= hash_table_iter_up(&hti
)))
2114 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
2115 if (sym
->symt
.tag
!= SymTagFunction
) continue;
2117 sci
.FileName
[0] = '\0';
2118 for (i
=0; i
<vector_length(&((struct symt_function
*)sym
)->vlines
); i
++)
2120 dli
= vector_at(&((struct symt_function
*)sym
)->vlines
, i
);
2121 if (dli
->is_source_file
)
2123 file
= source_get(pair
.effective
, dli
->u
.source_file
);
2124 if (!file
) sci
.FileName
[0] = '\0';
2127 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, file
, -1, NULL
, 0);
2130 if ((fileW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2131 MultiByteToWideChar(CP_ACP
, 0, file
, -1, fileW
, sz
);
2132 if (SymMatchStringW(fileW
, srcmask
, FALSE
))
2133 strcpy(sci
.FileName
, file
);
2135 sci
.FileName
[0] = '\0';
2136 HeapFree(GetProcessHeap(), 0, fileW
);
2139 else if (sci
.FileName
[0])
2142 sci
.Obj
[0] = '\0'; /* FIXME */
2143 sci
.LineNumber
= dli
->line_number
;
2144 sci
.Address
= dli
->u
.pc_offset
;
2145 if (!cb(&sci
, user
)) break;
2149 HeapFree(GetProcessHeap(), 0, srcmask
);
2153 BOOL WINAPI
SymGetLineFromName(HANDLE hProcess
, PCSTR ModuleName
, PCSTR FileName
,
2154 DWORD dwLineNumber
, PLONG plDisplacement
, PIMAGEHLP_LINE Line
)
2156 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, ModuleName
, FileName
,
2157 dwLineNumber
, plDisplacement
, Line
);
2161 BOOL WINAPI
SymGetLineFromName64(HANDLE hProcess
, PCSTR ModuleName
, PCSTR FileName
,
2162 DWORD dwLineNumber
, PLONG lpDisplacement
, PIMAGEHLP_LINE64 Line
)
2164 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, ModuleName
, FileName
,
2165 dwLineNumber
, lpDisplacement
, Line
);
2169 BOOL WINAPI
SymGetLineFromNameW64(HANDLE hProcess
, PCWSTR ModuleName
, PCWSTR FileName
,
2170 DWORD dwLineNumber
, PLONG plDisplacement
, PIMAGEHLP_LINEW64 Line
)
2172 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, debugstr_w(ModuleName
), debugstr_w(FileName
),
2173 dwLineNumber
, plDisplacement
, Line
);
2177 /******************************************************************
2178 * SymFromIndex (DBGHELP.@)
2181 BOOL WINAPI
SymFromIndex(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD index
, PSYMBOL_INFO symbol
)
2183 FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
2184 hProcess
, wine_dbgstr_longlong(BaseOfDll
), index
, symbol
);
2189 /******************************************************************
2190 * SymFromIndexW (DBGHELP.@)
2193 BOOL WINAPI
SymFromIndexW(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD index
, PSYMBOL_INFOW symbol
)
2195 FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
2196 hProcess
, wine_dbgstr_longlong(BaseOfDll
), index
, symbol
);
2201 /******************************************************************
2202 * SymSetHomeDirectory (DBGHELP.@)
2205 PCHAR WINAPI
SymSetHomeDirectory(HANDLE hProcess
, PCSTR dir
)
2207 FIXME("(%p, %s): stub\n", hProcess
, dir
);
2212 /******************************************************************
2213 * SymSetHomeDirectoryW (DBGHELP.@)
2216 PWSTR WINAPI
SymSetHomeDirectoryW(HANDLE hProcess
, PCWSTR dir
)
2218 FIXME("(%p, %s): stub\n", hProcess
, debugstr_w(dir
));