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 #include "dbghelp_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
25 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt
);
27 static const WCHAR starW
[] = {'*','\0'};
29 static inline int cmp_addr(ULONG64 a1
, ULONG64 a2
)
31 if (a1
> a2
) return 1;
32 if (a1
< a2
) return -1;
36 static inline int cmp_sorttab_addr(struct module
* module
, int idx
, ULONG64 addr
)
39 symt_get_address(&module
->addr_sorttab
[idx
]->symt
, &ref
);
40 return cmp_addr(ref
, addr
);
43 int symt_cmp_addr(const void* p1
, const void* p2
)
45 const struct symt
* sym1
= *(const struct symt
* const *)p1
;
46 const struct symt
* sym2
= *(const struct symt
* const *)p2
;
49 symt_get_address(sym1
, &a1
);
50 symt_get_address(sym2
, &a2
);
51 return cmp_addr(a1
, a2
);
54 DWORD
symt_ptr2index(struct module
* module
, const struct symt
* sym
)
57 const struct symt
** c
;
58 int len
= vector_length(&module
->vsymt
);
59 struct hash_table_iter hti
;
61 struct symt_idx_to_ptr
*idx_to_ptr
;
62 /* place enough storage on the stack to represent a pointer in %p form */
63 char ptrbuf
[3 + (sizeof(void *) * 2)];
65 /* make a string representation of the pointer to use as a hash key */
66 sprintf(ptrbuf
, "%p", sym
);
67 hash_table_iter_init(&module
->ht_symaddr
, &hti
, ptrbuf
);
69 /* try to find the pointer in our ht */
70 while ((ptr
= hash_table_iter_up(&hti
))) {
71 idx_to_ptr
= GET_ENTRY(ptr
, struct symt_idx_to_ptr
, hash_elt
);
72 if (idx_to_ptr
->sym
== sym
)
73 return idx_to_ptr
->idx
;
77 /* add the symbol to our symbol vector */
78 c
= vector_add(&module
->vsymt
, &module
->pool
);
80 /* add an idx to ptr mapping so we can find it again by address */
81 if ((idx_to_ptr
= pool_alloc(&module
->pool
, sizeof(*idx_to_ptr
))))
83 idx_to_ptr
->hash_elt
.name
= pool_strdup(&module
->pool
, ptrbuf
);
84 idx_to_ptr
->sym
= sym
;
85 idx_to_ptr
->idx
= len
+ 1;
86 hash_table_add(&module
->ht_symaddr
, &idx_to_ptr
->hash_elt
);
96 struct symt
* symt_index2ptr(struct module
* module
, DWORD id
)
99 if (!id
-- || id
>= vector_length(&module
->vsymt
)) return NULL
;
100 return *(struct symt
**)vector_at(&module
->vsymt
, id
);
102 return (struct symt
*)id
;
106 static BOOL
symt_grow_sorttab(struct module
* module
, unsigned sz
)
108 struct symt_ht
** new;
111 if (sz
<= module
->sorttab_size
) return TRUE
;
112 if (module
->addr_sorttab
)
114 size
= module
->sorttab_size
* 2;
115 new = HeapReAlloc(GetProcessHeap(), 0, module
->addr_sorttab
,
116 size
* sizeof(struct symt_ht
*));
121 new = HeapAlloc(GetProcessHeap(), 0, size
* sizeof(struct symt_ht
*));
123 if (!new) return FALSE
;
124 module
->sorttab_size
= size
;
125 module
->addr_sorttab
= new;
129 static void symt_add_module_ht(struct module
* module
, struct symt_ht
* ht
)
133 hash_table_add(&module
->ht_symbols
, &ht
->hash_elt
);
134 /* Don't store in sorttab a symbol without address, they are of
135 * no use here (e.g. constant values)
137 if (symt_get_address(&ht
->symt
, &addr
) &&
138 symt_grow_sorttab(module
, module
->num_symbols
+ 1))
140 module
->addr_sorttab
[module
->num_symbols
++] = ht
;
141 module
->sortlist_valid
= FALSE
;
145 static WCHAR
* file_regex(const char* srcfile
)
150 if (!srcfile
|| !*srcfile
)
152 if (!(p
= mask
= HeapAlloc(GetProcessHeap(), 0, 3 * sizeof(WCHAR
)))) return NULL
;
158 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, NULL
, 0);
161 /* FIXME: we use here the largest conversion for every char... could be optimized */
162 p
= mask
= HeapAlloc(GetProcessHeap(), 0, (5 * strlen(srcfile
) + 1 + sz
) * sizeof(WCHAR
));
163 if (!mask
) return NULL
;
164 srcfileW
= mask
+ 5 * strlen(srcfile
) + 1;
165 MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, srcfileW
, sz
);
193 struct symt_compiland
* symt_new_compiland(struct module
* module
,
194 unsigned long address
, unsigned src_idx
)
196 struct symt_compiland
* sym
;
198 TRACE_(dbghelp_symt
)("Adding compiland symbol %s:%s\n",
199 debugstr_w(module
->module
.ModuleName
), source_get(module
, src_idx
));
200 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
202 sym
->symt
.tag
= SymTagCompiland
;
203 sym
->address
= address
;
204 sym
->source
= src_idx
;
205 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 32);
210 struct symt_public
* symt_new_public(struct module
* module
,
211 struct symt_compiland
* compiland
,
213 unsigned long address
, unsigned size
)
215 struct symt_public
* sym
;
218 TRACE_(dbghelp_symt
)("Adding public symbol %s:%s @%lx\n",
219 debugstr_w(module
->module
.ModuleName
), name
, address
);
220 if ((dbghelp_options
& SYMOPT_AUTO_PUBLICS
) &&
221 symt_find_nearest(module
, address
) != NULL
)
223 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
225 sym
->symt
.tag
= SymTagPublicSymbol
;
226 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
227 sym
->container
= compiland
? &compiland
->symt
: NULL
;
228 sym
->address
= address
;
230 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
233 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
240 struct symt_data
* symt_new_global_variable(struct module
* module
,
241 struct symt_compiland
* compiland
,
242 const char* name
, unsigned is_static
,
243 struct location loc
, unsigned long size
,
246 struct symt_data
* sym
;
250 TRACE_(dbghelp_symt
)("Adding global symbol %s:%s %d@%lx %p\n",
251 debugstr_w(module
->module
.ModuleName
), name
, loc
.kind
, loc
.offset
, type
);
252 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
254 sym
->symt
.tag
= SymTagData
;
255 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
256 sym
->kind
= is_static
? DataIsFileStatic
: DataIsGlobal
;
257 sym
->container
= compiland
? &compiland
->symt
: NULL
;
260 if (type
&& size
&& symt_get_info(module
, type
, TI_GET_LENGTH
, &tsz
))
263 FIXME("Size mismatch for %s.%s between type (%s) and src (%lu)\n",
264 debugstr_w(module
->module
.ModuleName
), name
,
265 wine_dbgstr_longlong(tsz
), size
);
267 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
270 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
277 struct symt_function
* symt_new_function(struct module
* module
,
278 struct symt_compiland
* compiland
,
280 unsigned long addr
, unsigned long size
,
281 struct symt
* sig_type
)
283 struct symt_function
* sym
;
286 TRACE_(dbghelp_symt
)("Adding global function %s:%s @%lx-%lx\n",
287 debugstr_w(module
->module
.ModuleName
), name
, addr
, addr
+ size
- 1);
289 assert(!sig_type
|| sig_type
->tag
== SymTagFunctionType
);
290 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
292 sym
->symt
.tag
= SymTagFunction
;
293 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
294 sym
->container
= &compiland
->symt
;
296 sym
->type
= sig_type
;
298 vector_init(&sym
->vlines
, sizeof(struct line_info
), 64);
299 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 8);
300 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
303 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
310 void symt_add_func_line(struct module
* module
, struct symt_function
* func
,
311 unsigned source_idx
, int line_num
, unsigned long offset
)
313 struct line_info
* dli
;
314 BOOL last_matches
= FALSE
;
317 if (func
== NULL
|| !(dbghelp_options
& SYMOPT_LOAD_LINES
)) return;
319 TRACE_(dbghelp_symt
)("(%p)%s:%lx %s:%u\n",
320 func
, func
->hash_elt
.name
, offset
,
321 source_get(module
, source_idx
), line_num
);
323 assert(func
->symt
.tag
== SymTagFunction
);
325 for (i
=vector_length(&func
->vlines
)-1; i
>=0; i
--)
327 dli
= vector_at(&func
->vlines
, i
);
328 if (dli
->is_source_file
)
330 last_matches
= (source_idx
== dli
->u
.source_file
);
337 /* we shouldn't have line changes on first line of function */
338 dli
= vector_add(&func
->vlines
, &module
->pool
);
339 dli
->is_source_file
= 1;
340 dli
->is_first
= dli
->is_last
= 0;
341 dli
->line_number
= 0;
342 dli
->u
.source_file
= source_idx
;
344 dli
= vector_add(&func
->vlines
, &module
->pool
);
345 dli
->is_source_file
= 0;
346 dli
->is_first
= dli
->is_last
= 0;
347 dli
->line_number
= line_num
;
348 dli
->u
.pc_offset
= func
->address
+ offset
;
351 /******************************************************************
352 * symt_add_func_local
354 * Adds a new local/parameter to a given function:
355 * In any cases, dt tells whether it's a local variable or a parameter
356 * If regno it's not 0:
357 * - then variable is stored in a register
358 * - otherwise, value is referenced by register + offset
359 * Otherwise, the variable is stored on the stack:
360 * - offset is then the offset from the frame register
362 struct symt_data
* symt_add_func_local(struct module
* module
,
363 struct symt_function
* func
,
365 const struct location
* loc
,
366 struct symt_block
* block
,
367 struct symt
* type
, const char* name
)
369 struct symt_data
* locsym
;
372 TRACE_(dbghelp_symt
)("Adding local symbol (%s:%s): %s %p\n",
373 debugstr_w(module
->module
.ModuleName
), func
->hash_elt
.name
,
377 assert(func
->symt
.tag
== SymTagFunction
);
378 assert(dt
== DataIsParam
|| dt
== DataIsLocal
);
380 locsym
= pool_alloc(&module
->pool
, sizeof(*locsym
));
381 locsym
->symt
.tag
= SymTagData
;
382 locsym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
383 locsym
->hash_elt
.next
= NULL
;
385 locsym
->container
= block
? &block
->symt
: &func
->symt
;
387 locsym
->u
.var
= *loc
;
389 p
= vector_add(&block
->vchildren
, &module
->pool
);
391 p
= vector_add(&func
->vchildren
, &module
->pool
);
397 struct symt_block
* symt_open_func_block(struct module
* module
,
398 struct symt_function
* func
,
399 struct symt_block
* parent_block
,
400 unsigned pc
, unsigned len
)
402 struct symt_block
* block
;
406 assert(func
->symt
.tag
== SymTagFunction
);
408 assert(!parent_block
|| parent_block
->symt
.tag
== SymTagBlock
);
409 block
= pool_alloc(&module
->pool
, sizeof(*block
));
410 block
->symt
.tag
= SymTagBlock
;
411 block
->address
= func
->address
+ pc
;
413 block
->container
= parent_block
? &parent_block
->symt
: &func
->symt
;
414 vector_init(&block
->vchildren
, sizeof(struct symt
*), 4);
416 p
= vector_add(&parent_block
->vchildren
, &module
->pool
);
418 p
= vector_add(&func
->vchildren
, &module
->pool
);
424 struct symt_block
* symt_close_func_block(struct module
* module
,
425 const struct symt_function
* func
,
426 struct symt_block
* block
, unsigned pc
)
429 assert(func
->symt
.tag
== SymTagFunction
);
431 if (pc
) block
->size
= func
->address
+ pc
- block
->address
;
432 return (block
->container
->tag
== SymTagBlock
) ?
433 GET_ENTRY(block
->container
, struct symt_block
, symt
) : NULL
;
436 struct symt_hierarchy_point
* symt_add_function_point(struct module
* module
,
437 struct symt_function
* func
,
438 enum SymTagEnum point
,
439 const struct location
* loc
,
442 struct symt_hierarchy_point
*sym
;
445 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
447 sym
->symt
.tag
= point
;
448 sym
->parent
= &func
->symt
;
450 sym
->hash_elt
.name
= name
? pool_strdup(&module
->pool
, name
) : NULL
;
451 p
= vector_add(&func
->vchildren
, &module
->pool
);
457 BOOL
symt_normalize_function(struct module
* module
, const struct symt_function
* func
)
460 struct line_info
* dli
;
463 /* We aren't adding any more locals or line numbers to this function.
464 * Free any spare memory that we might have allocated.
466 assert(func
->symt
.tag
== SymTagFunction
);
468 /* EPP vector_pool_normalize(&func->vlines, &module->pool); */
469 /* EPP vector_pool_normalize(&func->vchildren, &module->pool); */
471 len
= vector_length(&func
->vlines
);
474 dli
= vector_at(&func
->vlines
, 0); dli
->is_first
= 1;
475 dli
= vector_at(&func
->vlines
, len
); dli
->is_last
= 1;
480 struct symt_thunk
* symt_new_thunk(struct module
* module
,
481 struct symt_compiland
* compiland
,
482 const char* name
, THUNK_ORDINAL ord
,
483 unsigned long addr
, unsigned long size
)
485 struct symt_thunk
* sym
;
487 TRACE_(dbghelp_symt
)("Adding global thunk %s:%s @%lx-%lx\n",
488 debugstr_w(module
->module
.ModuleName
), name
, addr
, addr
+ size
- 1);
490 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
492 sym
->symt
.tag
= SymTagThunk
;
493 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
494 sym
->container
= &compiland
->symt
;
498 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
502 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
509 struct symt_data
* symt_new_constant(struct module
* module
,
510 struct symt_compiland
* compiland
,
511 const char* name
, struct symt
* type
,
514 struct symt_data
* sym
;
516 TRACE_(dbghelp_symt
)("Adding constant value %s:%s\n",
517 debugstr_w(module
->module
.ModuleName
), name
);
519 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
521 sym
->symt
.tag
= SymTagData
;
522 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
523 sym
->kind
= DataIsConstant
;
524 sym
->container
= compiland
? &compiland
->symt
: NULL
;
527 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
531 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
538 struct symt_hierarchy_point
* symt_new_label(struct module
* module
,
539 struct symt_compiland
* compiland
,
540 const char* name
, unsigned long address
)
542 struct symt_hierarchy_point
* sym
;
544 TRACE_(dbghelp_symt
)("Adding global label value %s:%s\n",
545 debugstr_w(module
->module
.ModuleName
), name
);
547 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
549 sym
->symt
.tag
= SymTagLabel
;
550 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
551 sym
->loc
.kind
= loc_absolute
;
552 sym
->loc
.offset
= address
;
553 sym
->parent
= compiland
? &compiland
->symt
: NULL
;
554 symt_add_module_ht(module
, (struct symt_ht
*)sym
);
558 p
= vector_add(&compiland
->vchildren
, &module
->pool
);
565 /* expect sym_info->MaxNameLen to be set before being called */
566 static void symt_fill_sym_info(struct module_pair
* pair
,
567 const struct symt_function
* func
,
568 const struct symt
* sym
, SYMBOL_INFO
* sym_info
)
573 if (!symt_get_info(pair
->effective
, sym
, TI_GET_TYPE
, &sym_info
->TypeIndex
))
574 sym_info
->TypeIndex
= 0;
575 sym_info
->info
= symt_ptr2index(pair
->effective
, sym
);
576 sym_info
->Reserved
[0] = sym_info
->Reserved
[1] = 0;
577 if (!symt_get_info(pair
->effective
, sym
, TI_GET_LENGTH
, &size
) &&
578 (!sym_info
->TypeIndex
||
579 !symt_get_info(pair
->effective
, symt_index2ptr(pair
->effective
, sym_info
->TypeIndex
),
580 TI_GET_LENGTH
, &size
)))
582 sym_info
->Size
= (DWORD
)size
;
583 sym_info
->ModBase
= pair
->requested
->module
.BaseOfImage
;
591 const struct symt_data
* data
= (const struct symt_data
*)sym
;
595 sym_info
->Flags
|= SYMFLAG_PARAMETER
;
598 sym_info
->Flags
|= SYMFLAG_LOCAL
;
600 struct location loc
= data
->u
.var
;
602 if (loc
.kind
>= loc_user
)
605 struct module_format
* modfmt
;
607 for (i
= 0; i
< DFI_LAST
; i
++)
609 modfmt
= pair
->effective
->format_info
[i
];
610 if (modfmt
&& modfmt
->loc_compute
)
612 modfmt
->loc_compute(pair
->pcs
, modfmt
, func
, &loc
);
620 /* for now we report error cases as a negative register number */
623 sym_info
->Flags
|= SYMFLAG_REGISTER
;
624 sym_info
->Register
= loc
.reg
;
625 sym_info
->Address
= 0;
628 sym_info
->Flags
|= SYMFLAG_REGREL
;
629 sym_info
->Register
= loc
.reg
;
630 if (loc
.reg
== CV_REG_NONE
|| (int)loc
.reg
< 0 /* error */)
631 FIXME("suspicious register value %x\n", loc
.reg
);
632 sym_info
->Address
= loc
.offset
;
635 sym_info
->Flags
|= SYMFLAG_VALUEPRESENT
;
636 sym_info
->Value
= loc
.offset
;
639 FIXME("Shouldn't happen (kind=%d), debug reader backend is broken\n", loc
.kind
);
645 case DataIsFileStatic
:
646 switch (data
->u
.var
.kind
)
649 sym_info
->Flags
|= SYMFLAG_TLSREL
;
652 symt_get_address(sym
, &sym_info
->Address
);
653 sym_info
->Register
= 0;
656 FIXME("Shouldn't happen (kind=%d), debug reader backend is broken\n", data
->u
.var
.kind
);
661 sym_info
->Flags
|= SYMFLAG_VALUEPRESENT
;
662 switch (data
->u
.value
.n1
.n2
.vt
)
664 case VT_I4
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.lVal
; break;
665 case VT_I2
: sym_info
->Value
= (ULONG
)(long)data
->u
.value
.n1
.n2
.n3
.iVal
; break;
666 case VT_I1
: sym_info
->Value
= (ULONG
)(long)data
->u
.value
.n1
.n2
.n3
.cVal
; break;
667 case VT_UI4
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.ulVal
; break;
668 case VT_UI2
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.uiVal
; break;
669 case VT_UI1
: sym_info
->Value
= (ULONG
)data
->u
.value
.n1
.n2
.n3
.bVal
; break;
670 case VT_I1
| VT_BYREF
: sym_info
->Value
= (ULONG64
)(DWORD_PTR
)data
->u
.value
.n1
.n2
.n3
.byref
; break;
671 case VT_EMPTY
: sym_info
->Value
= 0; break;
673 FIXME("Unsupported variant type (%u)\n", data
->u
.value
.n1
.n2
.vt
);
679 FIXME("Unhandled kind (%u) in sym data\n", data
->kind
);
683 case SymTagPublicSymbol
:
684 sym_info
->Flags
|= SYMFLAG_EXPORT
;
685 symt_get_address(sym
, &sym_info
->Address
);
688 sym_info
->Flags
|= SYMFLAG_FUNCTION
;
689 symt_get_address(sym
, &sym_info
->Address
);
692 sym_info
->Flags
|= SYMFLAG_THUNK
;
693 symt_get_address(sym
, &sym_info
->Address
);
696 symt_get_address(sym
, &sym_info
->Address
);
697 sym_info
->Register
= 0;
700 sym_info
->Scope
= 0; /* FIXME */
701 sym_info
->Tag
= sym
->tag
;
702 name
= symt_get_name(sym
);
703 if (sym_info
->MaxNameLen
)
705 if (sym
->tag
!= SymTagPublicSymbol
|| !(dbghelp_options
& SYMOPT_UNDNAME
) ||
706 ((sym_info
->NameLen
= UnDecorateSymbolName(name
, sym_info
->Name
,
707 sym_info
->MaxNameLen
, UNDNAME_NAME_ONLY
)) == 0))
709 sym_info
->NameLen
= min(strlen(name
), sym_info
->MaxNameLen
- 1);
710 memcpy(sym_info
->Name
, name
, sym_info
->NameLen
);
711 sym_info
->Name
[sym_info
->NameLen
] = '\0';
714 TRACE_(dbghelp_symt
)("%p => %s %u %s\n",
715 sym
, sym_info
->Name
, sym_info
->Size
,
716 wine_dbgstr_longlong(sym_info
->Address
));
721 PSYM_ENUMERATESYMBOLS_CALLBACK cb
;
723 SYMBOL_INFO
* sym_info
;
727 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
730 static BOOL
send_symbol(const struct sym_enum
* se
, struct module_pair
* pair
,
731 const struct symt_function
* func
, const struct symt
* sym
)
733 symt_fill_sym_info(pair
, func
, sym
, se
->sym_info
);
734 if (se
->index
&& se
->sym_info
->info
!= se
->index
) return FALSE
;
735 if (se
->tag
&& se
->sym_info
->Tag
!= se
->tag
) return FALSE
;
736 if (se
->addr
&& !(se
->addr
>= se
->sym_info
->Address
&& se
->addr
< se
->sym_info
->Address
+ se
->sym_info
->Size
)) return FALSE
;
737 return !se
->cb(se
->sym_info
, se
->sym_info
->Size
, se
->user
);
740 static BOOL
symt_enum_module(struct module_pair
* pair
, const WCHAR
* match
,
741 const struct sym_enum
* se
)
744 struct symt_ht
* sym
= NULL
;
745 struct hash_table_iter hti
;
749 hash_table_iter_init(&pair
->effective
->ht_symbols
, &hti
, NULL
);
750 while ((ptr
= hash_table_iter_up(&hti
)))
752 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
753 nameW
= symt_get_nameW(&sym
->symt
);
754 ret
= SymMatchStringW(nameW
, match
, FALSE
);
755 HeapFree(GetProcessHeap(), 0, nameW
);
758 se
->sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
759 se
->sym_info
->MaxNameLen
= sizeof(se
->buffer
) - sizeof(SYMBOL_INFO
);
760 if (send_symbol(se
, pair
, NULL
, &sym
->symt
)) return TRUE
;
766 static inline unsigned where_to_insert(struct module
* module
, unsigned high
, const struct symt_ht
* elt
)
768 unsigned low
= 0, mid
= high
/ 2;
772 symt_get_address(&elt
->symt
, &addr
);
775 switch (cmp_sorttab_addr(module
, mid
, addr
))
778 case -1: low
= mid
+ 1; break;
779 case 1: high
= mid
; break;
781 mid
= low
+ (high
- low
) / 2;
782 } while (low
< high
);
786 /***********************************************************************
789 * Rebuild sorted list of symbols for a module.
791 static BOOL
resort_symbols(struct module
* module
)
795 if (!(module
->module
.NumSyms
= module
->num_symbols
))
798 /* we know that set from 0 up to num_sorttab is already sorted
799 * so sort the remaining (new) symbols, and merge the two sets
800 * (unless the first set is empty)
802 delta
= module
->num_symbols
- module
->num_sorttab
;
803 qsort(&module
->addr_sorttab
[module
->num_sorttab
], delta
, sizeof(struct symt_ht
*), symt_cmp_addr
);
804 if (module
->num_sorttab
)
806 int i
, ins_idx
= module
->num_sorttab
, prev_ins_idx
;
807 static struct symt_ht
** tmp
;
808 static unsigned num_tmp
;
812 static struct symt_ht
** new;
814 new = HeapReAlloc(GetProcessHeap(), 0, tmp
, delta
* sizeof(struct symt_ht
*));
816 new = HeapAlloc(GetProcessHeap(), 0, delta
* sizeof(struct symt_ht
*));
819 module
->num_sorttab
= 0;
820 return resort_symbols(module
);
825 memcpy(tmp
, &module
->addr_sorttab
[module
->num_sorttab
], delta
* sizeof(struct symt_ht
*));
826 qsort(tmp
, delta
, sizeof(struct symt_ht
*), symt_cmp_addr
);
828 for (i
= delta
- 1; i
>= 0; i
--)
830 prev_ins_idx
= ins_idx
;
831 ins_idx
= where_to_insert(module
, ins_idx
, tmp
[i
]);
832 memmove(&module
->addr_sorttab
[ins_idx
+ i
+ 1],
833 &module
->addr_sorttab
[ins_idx
],
834 (prev_ins_idx
- ins_idx
) * sizeof(struct symt_ht
*));
835 module
->addr_sorttab
[ins_idx
+ i
] = tmp
[i
];
838 module
->num_sorttab
= module
->num_symbols
;
839 return module
->sortlist_valid
= TRUE
;
842 static void symt_get_length(struct module
* module
, const struct symt
* symt
, ULONG64
* size
)
846 if (symt_get_info(module
, symt
, TI_GET_LENGTH
, size
) && *size
)
849 if (symt_get_info(module
, symt
, TI_GET_TYPE
, &type_index
) &&
850 symt_get_info(module
, symt_index2ptr(module
, type_index
), TI_GET_LENGTH
, size
)) return;
851 *size
= 0x1000; /* arbitrary value */
854 /* assume addr is in module */
855 struct symt_ht
* symt_find_nearest(struct module
* module
, DWORD_PTR addr
)
858 ULONG64 ref_addr
, ref_size
;
860 if (!module
->sortlist_valid
|| !module
->addr_sorttab
)
862 if (!resort_symbols(module
)) return NULL
;
866 * Binary search to find closest symbol.
869 high
= module
->num_sorttab
;
871 symt_get_address(&module
->addr_sorttab
[0]->symt
, &ref_addr
);
872 if (addr
< ref_addr
) return NULL
;
875 symt_get_address(&module
->addr_sorttab
[high
- 1]->symt
, &ref_addr
);
876 symt_get_length(module
, &module
->addr_sorttab
[high
- 1]->symt
, &ref_size
);
877 if (addr
>= ref_addr
+ ref_size
) return NULL
;
880 while (high
> low
+ 1)
882 mid
= (high
+ low
) / 2;
883 if (cmp_sorttab_addr(module
, mid
, addr
) < 0)
888 if (low
!= high
&& high
!= module
->num_sorttab
&&
889 cmp_sorttab_addr(module
, high
, addr
) <= 0)
892 /* If found symbol is a public symbol, check if there are any other entries that
893 * might also have the same address, but would get better information
895 if (module
->addr_sorttab
[low
]->symt
.tag
== SymTagPublicSymbol
)
897 symt_get_address(&module
->addr_sorttab
[low
]->symt
, &ref_addr
);
899 module
->addr_sorttab
[low
- 1]->symt
.tag
!= SymTagPublicSymbol
&&
900 !cmp_sorttab_addr(module
, low
- 1, ref_addr
))
902 else if (low
< module
->num_sorttab
- 1 &&
903 module
->addr_sorttab
[low
+ 1]->symt
.tag
!= SymTagPublicSymbol
&&
904 !cmp_sorttab_addr(module
, low
+ 1, ref_addr
))
907 /* finally check that we fit into the found symbol */
908 symt_get_address(&module
->addr_sorttab
[low
]->symt
, &ref_addr
);
909 if (addr
< ref_addr
) return NULL
;
910 symt_get_length(module
, &module
->addr_sorttab
[low
]->symt
, &ref_size
);
911 if (addr
>= ref_addr
+ ref_size
) return NULL
;
913 return module
->addr_sorttab
[low
];
916 static BOOL
symt_enum_locals_helper(struct module_pair
* pair
,
917 const WCHAR
* match
, const struct sym_enum
* se
,
918 struct symt_function
* func
, const struct vector
* v
)
920 struct symt
* lsym
= NULL
;
921 DWORD pc
= pair
->pcs
->ctx_frame
.InstructionOffset
;
926 for (i
=0; i
<vector_length(v
); i
++)
928 lsym
= *(struct symt
**)vector_at(v
, i
);
933 struct symt_block
* block
= (struct symt_block
*)lsym
;
934 if (pc
< block
->address
|| block
->address
+ block
->size
<= pc
)
936 if (!symt_enum_locals_helper(pair
, match
, se
, func
, &block
->vchildren
))
941 nameW
= symt_get_nameW(lsym
);
942 ret
= SymMatchStringW(nameW
, match
,
943 !(dbghelp_options
& SYMOPT_CASE_INSENSITIVE
));
944 HeapFree(GetProcessHeap(), 0, nameW
);
947 if (send_symbol(se
, pair
, func
, lsym
)) return FALSE
;
951 case SymTagFuncDebugStart
:
952 case SymTagFuncDebugEnd
:
956 FIXME("Unknown type: %u (%x)\n", lsym
->tag
, lsym
->tag
);
963 static BOOL
symt_enum_locals(struct process
* pcs
, const WCHAR
* mask
,
964 const struct sym_enum
* se
)
966 struct module_pair pair
;
968 DWORD_PTR pc
= pcs
->ctx_frame
.InstructionOffset
;
970 se
->sym_info
->SizeOfStruct
= sizeof(*se
->sym_info
);
971 se
->sym_info
->MaxNameLen
= sizeof(se
->buffer
) - sizeof(SYMBOL_INFO
);
974 pair
.requested
= module_find_by_addr(pair
.pcs
, pc
, DMT_UNKNOWN
);
975 if (!module_get_debug(&pair
)) return FALSE
;
976 if ((sym
= symt_find_nearest(pair
.effective
, pc
)) == NULL
) return FALSE
;
978 if (sym
->symt
.tag
== SymTagFunction
)
980 return symt_enum_locals_helper(&pair
, mask
? mask
: starW
, se
, (struct symt_function
*)sym
,
981 &((struct symt_function
*)sym
)->vchildren
);
986 /******************************************************************
989 * Helper for transforming an ANSI symbol info into a UNICODE one.
990 * Assume that MaxNameLen is the same for both version (A & W).
992 void copy_symbolW(SYMBOL_INFOW
* siw
, const SYMBOL_INFO
* si
)
994 siw
->SizeOfStruct
= si
->SizeOfStruct
;
995 siw
->TypeIndex
= si
->TypeIndex
;
996 siw
->Reserved
[0] = si
->Reserved
[0];
997 siw
->Reserved
[1] = si
->Reserved
[1];
998 siw
->Index
= si
->info
; /* FIXME: see dbghelp.h */
999 siw
->Size
= si
->Size
;
1000 siw
->ModBase
= si
->ModBase
;
1001 siw
->Flags
= si
->Flags
;
1002 siw
->Value
= si
->Value
;
1003 siw
->Address
= si
->Address
;
1004 siw
->Register
= si
->Register
;
1005 siw
->Scope
= si
->Scope
;
1007 siw
->NameLen
= si
->NameLen
;
1008 siw
->MaxNameLen
= si
->MaxNameLen
;
1009 MultiByteToWideChar(CP_ACP
, 0, si
->Name
, -1, siw
->Name
, siw
->MaxNameLen
);
1012 /******************************************************************
1015 * Core routine for most of the enumeration of symbols
1017 static BOOL
sym_enum(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1018 const struct sym_enum
* se
)
1020 struct module_pair pair
;
1024 pair
.pcs
= process_find_by_handle(hProcess
);
1025 if (!pair
.pcs
) return FALSE
;
1028 /* do local variables ? */
1029 if (!Mask
|| !(bang
= strchrW(Mask
, '!')))
1030 return symt_enum_locals(pair
.pcs
, Mask
, se
);
1032 if (bang
== Mask
) return FALSE
;
1034 mod
= HeapAlloc(GetProcessHeap(), 0, (bang
- Mask
+ 1) * sizeof(WCHAR
));
1035 if (!mod
) return FALSE
;
1036 memcpy(mod
, Mask
, (bang
- Mask
) * sizeof(WCHAR
));
1037 mod
[bang
- Mask
] = 0;
1039 for (pair
.requested
= pair
.pcs
->lmodules
; pair
.requested
; pair
.requested
= pair
.requested
->next
)
1041 if (pair
.requested
->type
== DMT_PE
&& module_get_debug(&pair
))
1043 if (SymMatchStringW(pair
.requested
->module
.ModuleName
, mod
, FALSE
) &&
1044 symt_enum_module(&pair
, bang
+ 1, se
))
1048 /* not found in PE modules, retry on the ELF ones
1050 if (!pair
.requested
&& (dbghelp_options
& SYMOPT_WINE_WITH_NATIVE_MODULES
))
1052 for (pair
.requested
= pair
.pcs
->lmodules
; pair
.requested
; pair
.requested
= pair
.requested
->next
)
1054 if ((pair
.requested
->type
== DMT_ELF
|| pair
.requested
->type
== DMT_MACHO
) &&
1055 !module_get_containee(pair
.pcs
, pair
.requested
) &&
1056 module_get_debug(&pair
))
1058 if (SymMatchStringW(pair
.requested
->module
.ModuleName
, mod
, FALSE
) &&
1059 symt_enum_module(&pair
, bang
+ 1, se
))
1064 HeapFree(GetProcessHeap(), 0, mod
);
1067 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
1068 if (!module_get_debug(&pair
))
1071 /* we always ignore module name from Mask when BaseOfDll is defined */
1072 if (Mask
&& (bang
= strchrW(Mask
, '!')))
1074 if (bang
== Mask
) return FALSE
;
1078 symt_enum_module(&pair
, Mask
? Mask
: starW
, se
);
1083 static inline BOOL
doSymEnumSymbols(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1084 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1089 se
.cb
= EnumSymbolsCallback
;
1090 se
.user
= UserContext
;
1094 se
.sym_info
= (PSYMBOL_INFO
)se
.buffer
;
1096 return sym_enum(hProcess
, BaseOfDll
, Mask
, &se
);
1099 /******************************************************************
1100 * SymEnumSymbols (DBGHELP.@)
1102 * cases BaseOfDll = 0
1103 * !foo fails always (despite what MSDN states)
1104 * RE1!RE2 looks up all modules matching RE1, and in all these modules, lookup RE2
1105 * no ! in Mask, lookup in local Context
1106 * cases BaseOfDll != 0
1107 * !foo fails always (despite what MSDN states)
1108 * RE1!RE2 gets RE2 from BaseOfDll (whatever RE1 is)
1110 BOOL WINAPI
SymEnumSymbols(HANDLE hProcess
, ULONG64 BaseOfDll
, PCSTR Mask
,
1111 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1117 TRACE("(%p %s %s %p %p)\n",
1118 hProcess
, wine_dbgstr_longlong(BaseOfDll
), debugstr_a(Mask
),
1119 EnumSymbolsCallback
, UserContext
);
1123 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, NULL
, 0);
1124 if (!(maskW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1126 MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, maskW
, sz
);
1128 ret
= doSymEnumSymbols(hProcess
, BaseOfDll
, maskW
, EnumSymbolsCallback
, UserContext
);
1129 HeapFree(GetProcessHeap(), 0, maskW
);
1135 PSYM_ENUMERATESYMBOLS_CALLBACKW cb
;
1137 PSYMBOL_INFOW sym_info
;
1138 char buffer
[sizeof(SYMBOL_INFOW
) + MAX_SYM_NAME
];
1142 static BOOL CALLBACK
sym_enumW(PSYMBOL_INFO si
, ULONG size
, PVOID ctx
)
1144 struct sym_enumW
* sew
= ctx
;
1146 copy_symbolW(sew
->sym_info
, si
);
1148 return (sew
->cb
)(sew
->sym_info
, size
, sew
->ctx
);
1151 /******************************************************************
1152 * SymEnumSymbolsW (DBGHELP.@)
1155 BOOL WINAPI
SymEnumSymbolsW(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1156 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
1159 struct sym_enumW sew
;
1161 sew
.ctx
= UserContext
;
1162 sew
.cb
= EnumSymbolsCallback
;
1163 sew
.sym_info
= (PSYMBOL_INFOW
)sew
.buffer
;
1165 return doSymEnumSymbols(hProcess
, BaseOfDll
, Mask
, sym_enumW
, &sew
);
1168 struct sym_enumerate
1171 PSYM_ENUMSYMBOLS_CALLBACK cb
;
1174 static BOOL CALLBACK
sym_enumerate_cb(PSYMBOL_INFO syminfo
, ULONG size
, void* ctx
)
1176 struct sym_enumerate
* se
= ctx
;
1177 return (se
->cb
)(syminfo
->Name
, syminfo
->Address
, syminfo
->Size
, se
->ctx
);
1180 /***********************************************************************
1181 * SymEnumerateSymbols (DBGHELP.@)
1183 BOOL WINAPI
SymEnumerateSymbols(HANDLE hProcess
, DWORD BaseOfDll
,
1184 PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback
,
1187 struct sym_enumerate se
;
1189 se
.ctx
= UserContext
;
1190 se
.cb
= EnumSymbolsCallback
;
1192 return SymEnumSymbols(hProcess
, BaseOfDll
, NULL
, sym_enumerate_cb
, &se
);
1195 struct sym_enumerate64
1198 PSYM_ENUMSYMBOLS_CALLBACK64 cb
;
1201 static BOOL CALLBACK
sym_enumerate_cb64(PSYMBOL_INFO syminfo
, ULONG size
, void* ctx
)
1203 struct sym_enumerate64
* se
= ctx
;
1204 return (se
->cb
)(syminfo
->Name
, syminfo
->Address
, syminfo
->Size
, se
->ctx
);
1207 /***********************************************************************
1208 * SymEnumerateSymbols64 (DBGHELP.@)
1210 BOOL WINAPI
SymEnumerateSymbols64(HANDLE hProcess
, DWORD64 BaseOfDll
,
1211 PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback
,
1214 struct sym_enumerate64 se
;
1216 se
.ctx
= UserContext
;
1217 se
.cb
= EnumSymbolsCallback
;
1219 return SymEnumSymbols(hProcess
, BaseOfDll
, NULL
, sym_enumerate_cb64
, &se
);
1222 /******************************************************************
1223 * SymFromAddr (DBGHELP.@)
1226 BOOL WINAPI
SymFromAddr(HANDLE hProcess
, DWORD64 Address
,
1227 DWORD64
* Displacement
, PSYMBOL_INFO Symbol
)
1229 struct module_pair pair
;
1230 struct symt_ht
* sym
;
1232 pair
.pcs
= process_find_by_handle(hProcess
);
1233 if (!pair
.pcs
) return FALSE
;
1234 pair
.requested
= module_find_by_addr(pair
.pcs
, Address
, DMT_UNKNOWN
);
1235 if (!module_get_debug(&pair
)) return FALSE
;
1236 if ((sym
= symt_find_nearest(pair
.effective
, Address
)) == NULL
) return FALSE
;
1238 symt_fill_sym_info(&pair
, NULL
, &sym
->symt
, Symbol
);
1240 *Displacement
= Address
- Symbol
->Address
;
1244 /******************************************************************
1245 * SymFromAddrW (DBGHELP.@)
1248 BOOL WINAPI
SymFromAddrW(HANDLE hProcess
, DWORD64 Address
,
1249 DWORD64
* Displacement
, PSYMBOL_INFOW Symbol
)
1255 len
= sizeof(*si
) + Symbol
->MaxNameLen
* sizeof(WCHAR
);
1256 si
= HeapAlloc(GetProcessHeap(), 0, len
);
1257 if (!si
) return FALSE
;
1259 si
->SizeOfStruct
= sizeof(*si
);
1260 si
->MaxNameLen
= Symbol
->MaxNameLen
;
1261 if ((ret
= SymFromAddr(hProcess
, Address
, Displacement
, si
)))
1263 copy_symbolW(Symbol
, si
);
1265 HeapFree(GetProcessHeap(), 0, si
);
1269 /******************************************************************
1270 * SymGetSymFromAddr (DBGHELP.@)
1273 BOOL WINAPI
SymGetSymFromAddr(HANDLE hProcess
, DWORD Address
,
1274 PDWORD Displacement
, PIMAGEHLP_SYMBOL Symbol
)
1276 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1277 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1279 DWORD64 Displacement64
;
1281 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1282 si
->SizeOfStruct
= sizeof(*si
);
1283 si
->MaxNameLen
= MAX_SYM_NAME
;
1284 if (!SymFromAddr(hProcess
, Address
, &Displacement64
, si
))
1288 *Displacement
= Displacement64
;
1289 Symbol
->Address
= si
->Address
;
1290 Symbol
->Size
= si
->Size
;
1291 Symbol
->Flags
= si
->Flags
;
1292 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1293 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1297 /******************************************************************
1298 * SymGetSymFromAddr64 (DBGHELP.@)
1301 BOOL WINAPI
SymGetSymFromAddr64(HANDLE hProcess
, DWORD64 Address
,
1302 PDWORD64 Displacement
, PIMAGEHLP_SYMBOL64 Symbol
)
1304 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1305 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1307 DWORD64 Displacement64
;
1309 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1310 si
->SizeOfStruct
= sizeof(*si
);
1311 si
->MaxNameLen
= MAX_SYM_NAME
;
1312 if (!SymFromAddr(hProcess
, Address
, &Displacement64
, si
))
1316 *Displacement
= Displacement64
;
1317 Symbol
->Address
= si
->Address
;
1318 Symbol
->Size
= si
->Size
;
1319 Symbol
->Flags
= si
->Flags
;
1320 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1321 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1325 static BOOL
find_name(struct process
* pcs
, struct module
* module
, const char* name
,
1326 SYMBOL_INFO
* symbol
)
1328 struct hash_table_iter hti
;
1330 struct symt_ht
* sym
= NULL
;
1331 struct module_pair pair
;
1334 if (!(pair
.requested
= module
)) return FALSE
;
1335 if (!module_get_debug(&pair
)) return FALSE
;
1337 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, name
);
1338 while ((ptr
= hash_table_iter_up(&hti
)))
1340 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
1342 if (!strcmp(sym
->hash_elt
.name
, name
))
1344 symt_fill_sym_info(&pair
, NULL
, &sym
->symt
, symbol
);
1351 /******************************************************************
1352 * SymFromName (DBGHELP.@)
1355 BOOL WINAPI
SymFromName(HANDLE hProcess
, PCSTR Name
, PSYMBOL_INFO Symbol
)
1357 struct process
* pcs
= process_find_by_handle(hProcess
);
1358 struct module
* module
;
1361 TRACE("(%p, %s, %p)\n", hProcess
, Name
, Symbol
);
1362 if (!pcs
) return FALSE
;
1363 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1364 name
= strchr(Name
, '!');
1368 assert(name
- Name
< sizeof(tmp
));
1369 memcpy(tmp
, Name
, name
- Name
);
1370 tmp
[name
- Name
] = '\0';
1371 module
= module_find_by_nameA(pcs
, tmp
);
1372 return find_name(pcs
, module
, name
+ 1, Symbol
);
1374 for (module
= pcs
->lmodules
; module
; module
= module
->next
)
1376 if (module
->type
== DMT_PE
&& find_name(pcs
, module
, Name
, Symbol
))
1379 /* not found in PE modules, retry on the ELF ones
1381 if (dbghelp_options
& SYMOPT_WINE_WITH_NATIVE_MODULES
)
1383 for (module
= pcs
->lmodules
; module
; module
= module
->next
)
1385 if ((module
->type
== DMT_ELF
|| module
->type
== DMT_MACHO
) &&
1386 !module_get_containee(pcs
, module
) &&
1387 find_name(pcs
, module
, Name
, Symbol
))
1394 /***********************************************************************
1395 * SymGetSymFromName64 (DBGHELP.@)
1397 BOOL WINAPI
SymGetSymFromName64(HANDLE hProcess
, PCSTR Name
, PIMAGEHLP_SYMBOL64 Symbol
)
1399 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1400 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1403 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1404 si
->SizeOfStruct
= sizeof(*si
);
1405 si
->MaxNameLen
= MAX_SYM_NAME
;
1406 if (!SymFromName(hProcess
, Name
, si
)) return FALSE
;
1408 Symbol
->Address
= si
->Address
;
1409 Symbol
->Size
= si
->Size
;
1410 Symbol
->Flags
= si
->Flags
;
1411 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1412 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1416 /***********************************************************************
1417 * SymGetSymFromName (DBGHELP.@)
1419 BOOL WINAPI
SymGetSymFromName(HANDLE hProcess
, PCSTR Name
, PIMAGEHLP_SYMBOL Symbol
)
1421 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1422 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1425 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1426 si
->SizeOfStruct
= sizeof(*si
);
1427 si
->MaxNameLen
= MAX_SYM_NAME
;
1428 if (!SymFromName(hProcess
, Name
, si
)) return FALSE
;
1430 Symbol
->Address
= si
->Address
;
1431 Symbol
->Size
= si
->Size
;
1432 Symbol
->Flags
= si
->Flags
;
1433 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1434 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1438 /******************************************************************
1439 * sym_fill_func_line_info
1441 * fills information about a file
1443 BOOL
symt_fill_func_line_info(const struct module
* module
, const struct symt_function
* func
,
1444 DWORD64 addr
, IMAGEHLP_LINE64
* line
)
1446 struct line_info
* dli
= NULL
;
1450 assert(func
->symt
.tag
== SymTagFunction
);
1452 for (i
=vector_length(&func
->vlines
)-1; i
>=0; i
--)
1454 dli
= vector_at(&func
->vlines
, i
);
1455 if (!dli
->is_source_file
)
1457 if (found
|| dli
->u
.pc_offset
> addr
) continue;
1458 line
->LineNumber
= dli
->line_number
;
1459 line
->Address
= dli
->u
.pc_offset
;
1466 line
->FileName
= (char*)source_get(module
, dli
->u
.source_file
);
1473 /***********************************************************************
1474 * SymGetSymNext64 (DBGHELP.@)
1476 BOOL WINAPI
SymGetSymNext64(HANDLE hProcess
, PIMAGEHLP_SYMBOL64 Symbol
)
1479 * get module from Symbol.Address
1480 * get index in module.addr_sorttab of Symbol.Address
1482 * if out of module bounds, move to next module in process address space
1484 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1485 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1489 /***********************************************************************
1490 * SymGetSymNext (DBGHELP.@)
1492 BOOL WINAPI
SymGetSymNext(HANDLE hProcess
, PIMAGEHLP_SYMBOL Symbol
)
1494 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1495 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1499 /***********************************************************************
1500 * SymGetSymPrev64 (DBGHELP.@)
1502 BOOL WINAPI
SymGetSymPrev64(HANDLE hProcess
, PIMAGEHLP_SYMBOL64 Symbol
)
1504 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1505 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1509 /***********************************************************************
1510 * SymGetSymPrev (DBGHELP.@)
1512 BOOL WINAPI
SymGetSymPrev(HANDLE hProcess
, PIMAGEHLP_SYMBOL Symbol
)
1514 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1515 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1519 /******************************************************************
1520 * copy_line_64_from_32 (internal)
1523 static void copy_line_64_from_32(IMAGEHLP_LINE64
* l64
, const IMAGEHLP_LINE
* l32
)
1526 l64
->Key
= l32
->Key
;
1527 l64
->LineNumber
= l32
->LineNumber
;
1528 l64
->FileName
= l32
->FileName
;
1529 l64
->Address
= l32
->Address
;
1532 /******************************************************************
1533 * copy_line_W64_from_32 (internal)
1536 static void copy_line_W64_from_64(struct process
* pcs
, IMAGEHLP_LINEW64
* l64w
, const IMAGEHLP_LINE64
* l64
)
1540 l64w
->Key
= l64
->Key
;
1541 l64w
->LineNumber
= l64
->LineNumber
;
1542 len
= MultiByteToWideChar(CP_ACP
, 0, l64
->FileName
, -1, NULL
, 0);
1543 if ((l64w
->FileName
= fetch_buffer(pcs
, len
* sizeof(WCHAR
))))
1544 MultiByteToWideChar(CP_ACP
, 0, l64
->FileName
, -1, l64w
->FileName
, len
);
1545 l64w
->Address
= l64
->Address
;
1548 /******************************************************************
1549 * copy_line_32_from_64 (internal)
1552 static void copy_line_32_from_64(IMAGEHLP_LINE
* l32
, const IMAGEHLP_LINE64
* l64
)
1555 l32
->Key
= l64
->Key
;
1556 l32
->LineNumber
= l64
->LineNumber
;
1557 l32
->FileName
= l64
->FileName
;
1558 l32
->Address
= l64
->Address
;
1561 /******************************************************************
1562 * SymGetLineFromAddr (DBGHELP.@)
1565 BOOL WINAPI
SymGetLineFromAddr(HANDLE hProcess
, DWORD dwAddr
,
1566 PDWORD pdwDisplacement
, PIMAGEHLP_LINE Line
)
1568 IMAGEHLP_LINE64 il64
;
1570 il64
.SizeOfStruct
= sizeof(il64
);
1571 if (!SymGetLineFromAddr64(hProcess
, dwAddr
, pdwDisplacement
, &il64
))
1573 copy_line_32_from_64(Line
, &il64
);
1577 /******************************************************************
1578 * SymGetLineFromAddr64 (DBGHELP.@)
1581 BOOL WINAPI
SymGetLineFromAddr64(HANDLE hProcess
, DWORD64 dwAddr
,
1582 PDWORD pdwDisplacement
, PIMAGEHLP_LINE64 Line
)
1584 struct module_pair pair
;
1585 struct symt_ht
* symt
;
1587 TRACE("%p %s %p %p\n", hProcess
, wine_dbgstr_longlong(dwAddr
), pdwDisplacement
, Line
);
1589 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1591 pair
.pcs
= process_find_by_handle(hProcess
);
1592 if (!pair
.pcs
) return FALSE
;
1593 pair
.requested
= module_find_by_addr(pair
.pcs
, dwAddr
, DMT_UNKNOWN
);
1594 if (!module_get_debug(&pair
)) return FALSE
;
1595 if ((symt
= symt_find_nearest(pair
.effective
, dwAddr
)) == NULL
) return FALSE
;
1597 if (symt
->symt
.tag
!= SymTagFunction
) return FALSE
;
1598 if (!symt_fill_func_line_info(pair
.effective
, (struct symt_function
*)symt
,
1599 dwAddr
, Line
)) return FALSE
;
1600 *pdwDisplacement
= dwAddr
- Line
->Address
;
1604 /******************************************************************
1605 * SymGetLineFromAddrW64 (DBGHELP.@)
1608 BOOL WINAPI
SymGetLineFromAddrW64(HANDLE hProcess
, DWORD64 dwAddr
,
1609 PDWORD pdwDisplacement
, PIMAGEHLP_LINEW64 Line
)
1611 IMAGEHLP_LINE64 il64
;
1613 il64
.SizeOfStruct
= sizeof(il64
);
1614 if (!SymGetLineFromAddr64(hProcess
, dwAddr
, pdwDisplacement
, &il64
))
1616 copy_line_W64_from_64(process_find_by_handle(hProcess
), Line
, &il64
);
1620 /******************************************************************
1621 * SymGetLinePrev64 (DBGHELP.@)
1624 BOOL WINAPI
SymGetLinePrev64(HANDLE hProcess
, PIMAGEHLP_LINE64 Line
)
1626 struct module_pair pair
;
1627 struct line_info
* li
;
1628 BOOL in_search
= FALSE
;
1630 TRACE("(%p %p)\n", hProcess
, Line
);
1632 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1634 pair
.pcs
= process_find_by_handle(hProcess
);
1635 if (!pair
.pcs
) return FALSE
;
1636 pair
.requested
= module_find_by_addr(pair
.pcs
, Line
->Address
, DMT_UNKNOWN
);
1637 if (!module_get_debug(&pair
)) return FALSE
;
1639 if (Line
->Key
== 0) return FALSE
;
1641 /* things are a bit complicated because when we encounter a DLIT_SOURCEFILE
1642 * element we have to go back until we find the prev one to get the real
1643 * source file name for the DLIT_OFFSET element just before
1644 * the first DLIT_SOURCEFILE
1646 while (!li
->is_first
)
1649 if (!li
->is_source_file
)
1651 Line
->LineNumber
= li
->line_number
;
1652 Line
->Address
= li
->u
.pc_offset
;
1654 if (!in_search
) return TRUE
;
1660 Line
->FileName
= (char*)source_get(pair
.effective
, li
->u
.source_file
);
1666 SetLastError(ERROR_NO_MORE_ITEMS
); /* FIXME */
1670 /******************************************************************
1671 * SymGetLinePrev (DBGHELP.@)
1674 BOOL WINAPI
SymGetLinePrev(HANDLE hProcess
, PIMAGEHLP_LINE Line
)
1676 IMAGEHLP_LINE64 line64
;
1678 line64
.SizeOfStruct
= sizeof(line64
);
1679 copy_line_64_from_32(&line64
, Line
);
1680 if (!SymGetLinePrev64(hProcess
, &line64
)) return FALSE
;
1681 copy_line_32_from_64(Line
, &line64
);
1685 BOOL
symt_get_func_line_next(const struct module
* module
, PIMAGEHLP_LINE64 line
)
1687 struct line_info
* li
;
1689 if (line
->Key
== 0) return FALSE
;
1691 while (!li
->is_last
)
1694 if (!li
->is_source_file
)
1696 line
->LineNumber
= li
->line_number
;
1697 line
->Address
= li
->u
.pc_offset
;
1701 line
->FileName
= (char*)source_get(module
, li
->u
.source_file
);
1706 /******************************************************************
1707 * SymGetLineNext64 (DBGHELP.@)
1710 BOOL WINAPI
SymGetLineNext64(HANDLE hProcess
, PIMAGEHLP_LINE64 Line
)
1712 struct module_pair pair
;
1714 TRACE("(%p %p)\n", hProcess
, Line
);
1716 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1717 pair
.pcs
= process_find_by_handle(hProcess
);
1718 if (!pair
.pcs
) return FALSE
;
1719 pair
.requested
= module_find_by_addr(pair
.pcs
, Line
->Address
, DMT_UNKNOWN
);
1720 if (!module_get_debug(&pair
)) return FALSE
;
1722 if (symt_get_func_line_next(pair
.effective
, Line
)) return TRUE
;
1723 SetLastError(ERROR_NO_MORE_ITEMS
); /* FIXME */
1727 /******************************************************************
1728 * SymGetLineNext (DBGHELP.@)
1731 BOOL WINAPI
SymGetLineNext(HANDLE hProcess
, PIMAGEHLP_LINE Line
)
1733 IMAGEHLP_LINE64 line64
;
1735 line64
.SizeOfStruct
= sizeof(line64
);
1736 copy_line_64_from_32(&line64
, Line
);
1737 if (!SymGetLineNext64(hProcess
, &line64
)) return FALSE
;
1738 copy_line_32_from_64(Line
, &line64
);
1742 /***********************************************************************
1743 * SymUnDName (DBGHELP.@)
1745 BOOL WINAPI
SymUnDName(PIMAGEHLP_SYMBOL sym
, PSTR UnDecName
, DWORD UnDecNameLength
)
1747 return UnDecorateSymbolName(sym
->Name
, UnDecName
, UnDecNameLength
,
1748 UNDNAME_COMPLETE
) != 0;
1751 /***********************************************************************
1752 * SymUnDName64 (DBGHELP.@)
1754 BOOL WINAPI
SymUnDName64(PIMAGEHLP_SYMBOL64 sym
, PSTR UnDecName
, DWORD UnDecNameLength
)
1756 return UnDecorateSymbolName(sym
->Name
, UnDecName
, UnDecNameLength
,
1757 UNDNAME_COMPLETE
) != 0;
1760 static void * CDECL
und_alloc(size_t len
) { return HeapAlloc(GetProcessHeap(), 0, len
); }
1761 static void CDECL
und_free (void* ptr
) { HeapFree(GetProcessHeap(), 0, ptr
); }
1763 /***********************************************************************
1764 * UnDecorateSymbolName (DBGHELP.@)
1766 DWORD WINAPI
UnDecorateSymbolName(PCSTR DecoratedName
, PSTR UnDecoratedName
,
1767 DWORD UndecoratedLength
, DWORD Flags
)
1769 /* undocumented from msvcrt */
1770 static HANDLE hMsvcrt
;
1771 static char* (CDECL
*p_undname
)(char*, const char*, int, void* (CDECL
*)(size_t), void (CDECL
*)(void*), unsigned short);
1772 static const WCHAR szMsvcrt
[] = {'m','s','v','c','r','t','.','d','l','l',0};
1774 TRACE("(%s, %p, %d, 0x%08x)\n",
1775 debugstr_a(DecoratedName
), UnDecoratedName
, UndecoratedLength
, Flags
);
1779 if (!hMsvcrt
) hMsvcrt
= LoadLibraryW(szMsvcrt
);
1780 if (hMsvcrt
) p_undname
= (void*)GetProcAddress(hMsvcrt
, "__unDName");
1781 if (!p_undname
) return 0;
1784 if (!UnDecoratedName
) return 0;
1785 if (!p_undname(UnDecoratedName
, DecoratedName
, UndecoratedLength
,
1786 und_alloc
, und_free
, Flags
))
1788 return strlen(UnDecoratedName
);
1791 #define WILDCHAR(x) (-(x))
1793 static int re_fetch_char(const WCHAR
** re
)
1797 case '\\': (*re
)++; return *(*re
)++;
1798 case '*': case '[': case '?': case '+': case '#': case ']': return WILDCHAR(*(*re
)++);
1799 default: return *(*re
)++;
1803 static inline int re_match_char(WCHAR ch1
, WCHAR ch2
, BOOL _case
)
1805 return _case
? ch1
- ch2
: toupperW(ch1
) - toupperW(ch2
);
1808 static const WCHAR
* re_match_one(const WCHAR
* string
, const WCHAR
* elt
, BOOL _case
)
1813 switch (ch1
= re_fetch_char(&elt
))
1816 return (ch1
>= 0 && re_match_char(*string
, ch1
, _case
) == 0) ? ++string
: NULL
;
1817 case WILDCHAR('?'): return *string
? ++string
: NULL
;
1818 case WILDCHAR('*'): assert(0);
1819 case WILDCHAR('['): break;
1824 ch1
= re_fetch_char(&elt
);
1825 if (ch1
== WILDCHAR(']')) return NULL
;
1826 if (state
== 1 && ch1
== '-') state
= 2;
1829 if (re_match_char(*string
, ch1
, _case
) == 0) return ++string
;
1840 if (prev
>= 0 && ch1
>= 0 && re_match_char(prev
, *string
, _case
) <= 0 &&
1841 re_match_char(*string
, ch1
, _case
) <= 0)
1850 /******************************************************************
1853 * match a substring of *pstring according to *pre regular expression
1854 * pstring and pre are only updated in case of successful match
1856 static BOOL
re_match_multi(const WCHAR
** pstring
, const WCHAR
** pre
, BOOL _case
)
1858 const WCHAR
* re_end
= *pre
;
1859 const WCHAR
* string_end
= *pstring
;
1860 const WCHAR
* re_beg
;
1861 const WCHAR
* string_beg
;
1865 while (*re_end
&& *string_end
)
1867 string_beg
= string_end
;
1869 switch (ch
= re_fetch_char(&re_end
))
1871 case WILDCHAR(']'): case WILDCHAR('+'): case WILDCHAR('#'): return FALSE
;
1873 /* transform '*' into '?#' */
1874 {static const WCHAR qmW
[] = {'?',0}; re_beg
= qmW
;}
1879 if (!(ch
= re_fetch_char(&re_end
))) return FALSE
;
1880 } while (ch
!= WILDCHAR(']'));
1890 if (!(next
= re_match_one(string_end
, re_beg
, _case
))) return FALSE
;
1896 while ((next
= re_match_one(string_end
, re_beg
, _case
))) string_end
= next
;
1897 for ( ; string_end
>= string_beg
; string_end
--)
1899 if (re_match_multi(&string_end
, &re_end
, _case
)) goto found
;
1903 if (!(next
= re_match_one(string_end
, re_beg
, _case
))) return FALSE
;
1909 if (*re_end
|| *string_end
) return FALSE
;
1913 *pstring
= string_end
;
1917 /******************************************************************
1918 * SymMatchStringA (DBGHELP.@)
1921 BOOL WINAPI
SymMatchStringA(PCSTR string
, PCSTR re
, BOOL _case
)
1930 SetLastError(ERROR_INVALID_HANDLE
);
1933 TRACE("%s %s %c\n", string
, re
, _case
? 'Y' : 'N');
1935 sz
= MultiByteToWideChar(CP_ACP
, 0, string
, -1, NULL
, 0);
1936 if ((strW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1937 MultiByteToWideChar(CP_ACP
, 0, string
, -1, strW
, sz
);
1938 sz
= MultiByteToWideChar(CP_ACP
, 0, re
, -1, NULL
, 0);
1939 if ((reW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1940 MultiByteToWideChar(CP_ACP
, 0, re
, -1, reW
, sz
);
1943 ret
= SymMatchStringW(strW
, reW
, _case
);
1944 HeapFree(GetProcessHeap(), 0, strW
);
1945 HeapFree(GetProcessHeap(), 0, reW
);
1949 /******************************************************************
1950 * SymMatchStringW (DBGHELP.@)
1953 BOOL WINAPI
SymMatchStringW(PCWSTR string
, PCWSTR re
, BOOL _case
)
1955 TRACE("%s %s %c\n", debugstr_w(string
), debugstr_w(re
), _case
? 'Y' : 'N');
1959 SetLastError(ERROR_INVALID_HANDLE
);
1962 return re_match_multi(&string
, &re
, _case
);
1965 static inline BOOL
doSymSearch(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
1966 DWORD SymTag
, PCWSTR Mask
, DWORD64 Address
,
1967 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1968 PVOID UserContext
, DWORD Options
)
1972 if (Options
!= SYMSEARCH_GLOBALSONLY
)
1974 FIXME("Unsupported searching with options (%x)\n", Options
);
1975 SetLastError(ERROR_INVALID_PARAMETER
);
1979 se
.cb
= EnumSymbolsCallback
;
1980 se
.user
= UserContext
;
1984 se
.sym_info
= (PSYMBOL_INFO
)se
.buffer
;
1986 return sym_enum(hProcess
, BaseOfDll
, Mask
, &se
);
1989 /******************************************************************
1990 * SymSearch (DBGHELP.@)
1992 BOOL WINAPI
SymSearch(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
1993 DWORD SymTag
, PCSTR Mask
, DWORD64 Address
,
1994 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1995 PVOID UserContext
, DWORD Options
)
1997 LPWSTR maskW
= NULL
;
2000 TRACE("(%p %s %u %u %s %s %p %p %x)\n",
2001 hProcess
, wine_dbgstr_longlong(BaseOfDll
), Index
, SymTag
, Mask
,
2002 wine_dbgstr_longlong(Address
), EnumSymbolsCallback
,
2003 UserContext
, Options
);
2007 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, NULL
, 0);
2009 if (!(maskW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2011 MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, maskW
, sz
);
2013 ret
= doSymSearch(hProcess
, BaseOfDll
, Index
, SymTag
, maskW
, Address
,
2014 EnumSymbolsCallback
, UserContext
, Options
);
2015 HeapFree(GetProcessHeap(), 0, maskW
);
2019 /******************************************************************
2020 * SymSearchW (DBGHELP.@)
2022 BOOL WINAPI
SymSearchW(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
2023 DWORD SymTag
, PCWSTR Mask
, DWORD64 Address
,
2024 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
2025 PVOID UserContext
, DWORD Options
)
2027 struct sym_enumW sew
;
2029 TRACE("(%p %s %u %u %s %s %p %p %x)\n",
2030 hProcess
, wine_dbgstr_longlong(BaseOfDll
), Index
, SymTag
, debugstr_w(Mask
),
2031 wine_dbgstr_longlong(Address
), EnumSymbolsCallback
,
2032 UserContext
, Options
);
2034 sew
.ctx
= UserContext
;
2035 sew
.cb
= EnumSymbolsCallback
;
2036 sew
.sym_info
= (PSYMBOL_INFOW
)sew
.buffer
;
2038 return doSymSearch(hProcess
, BaseOfDll
, Index
, SymTag
, Mask
, Address
,
2039 sym_enumW
, &sew
, Options
);
2042 /******************************************************************
2043 * SymAddSymbol (DBGHELP.@)
2046 BOOL WINAPI
SymAddSymbol(HANDLE hProcess
, ULONG64 BaseOfDll
, PCSTR name
,
2047 DWORD64 addr
, DWORD size
, DWORD flags
)
2049 WCHAR nameW
[MAX_SYM_NAME
];
2051 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
) / sizeof(WCHAR
));
2052 return SymAddSymbolW(hProcess
, BaseOfDll
, nameW
, addr
, size
, flags
);
2055 /******************************************************************
2056 * SymAddSymbolW (DBGHELP.@)
2059 BOOL WINAPI
SymAddSymbolW(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR name
,
2060 DWORD64 addr
, DWORD size
, DWORD flags
)
2062 struct module_pair pair
;
2064 TRACE("(%p %s %s %u)\n", hProcess
, wine_dbgstr_w(name
), wine_dbgstr_longlong(addr
), size
);
2066 pair
.pcs
= process_find_by_handle(hProcess
);
2067 if (!pair
.pcs
) return FALSE
;
2068 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
2069 if (!module_get_debug(&pair
)) return FALSE
;
2071 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2075 /******************************************************************
2076 * SymSetScopeFromAddr (DBGHELP.@)
2078 BOOL WINAPI
SymSetScopeFromAddr(HANDLE hProcess
, ULONG64 addr
)
2080 struct process
* pcs
;
2082 FIXME("(%p %s): stub\n", hProcess
, wine_dbgstr_longlong(addr
));
2084 if (!(pcs
= process_find_by_handle(hProcess
))) return FALSE
;
2088 /******************************************************************
2089 * SymEnumLines (DBGHELP.@)
2092 BOOL WINAPI
SymEnumLines(HANDLE hProcess
, ULONG64 base
, PCSTR compiland
,
2093 PCSTR srcfile
, PSYM_ENUMLINES_CALLBACK cb
, PVOID user
)
2095 struct module_pair pair
;
2096 struct hash_table_iter hti
;
2097 struct symt_ht
* sym
;
2099 struct line_info
* dli
;
2104 if (!cb
) return FALSE
;
2105 if (!(dbghelp_options
& SYMOPT_LOAD_LINES
)) return TRUE
;
2107 pair
.pcs
= process_find_by_handle(hProcess
);
2108 if (!pair
.pcs
) return FALSE
;
2109 if (compiland
) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland
);
2110 pair
.requested
= module_find_by_addr(pair
.pcs
, base
, DMT_UNKNOWN
);
2111 if (!module_get_debug(&pair
)) return FALSE
;
2112 if (!(srcmask
= file_regex(srcfile
))) return FALSE
;
2114 sci
.SizeOfStruct
= sizeof(sci
);
2117 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, NULL
);
2118 while ((ptr
= hash_table_iter_up(&hti
)))
2122 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
2123 if (sym
->symt
.tag
!= SymTagFunction
) continue;
2125 sci
.FileName
[0] = '\0';
2126 for (i
=0; i
<vector_length(&((struct symt_function
*)sym
)->vlines
); i
++)
2128 dli
= vector_at(&((struct symt_function
*)sym
)->vlines
, i
);
2129 if (dli
->is_source_file
)
2131 file
= source_get(pair
.effective
, dli
->u
.source_file
);
2132 if (!file
) sci
.FileName
[0] = '\0';
2135 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, file
, -1, NULL
, 0);
2138 if ((fileW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2139 MultiByteToWideChar(CP_ACP
, 0, file
, -1, fileW
, sz
);
2140 if (SymMatchStringW(fileW
, srcmask
, FALSE
))
2141 strcpy(sci
.FileName
, file
);
2143 sci
.FileName
[0] = '\0';
2144 HeapFree(GetProcessHeap(), 0, fileW
);
2147 else if (sci
.FileName
[0])
2150 sci
.Obj
[0] = '\0'; /* FIXME */
2151 sci
.LineNumber
= dli
->line_number
;
2152 sci
.Address
= dli
->u
.pc_offset
;
2153 if (!cb(&sci
, user
)) break;
2157 HeapFree(GetProcessHeap(), 0, srcmask
);
2161 BOOL WINAPI
SymGetLineFromName(HANDLE hProcess
, PCSTR ModuleName
, PCSTR FileName
,
2162 DWORD dwLineNumber
, PLONG plDisplacement
, PIMAGEHLP_LINE Line
)
2164 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, ModuleName
, FileName
,
2165 dwLineNumber
, plDisplacement
, Line
);
2169 BOOL WINAPI
SymGetLineFromName64(HANDLE hProcess
, PCSTR ModuleName
, PCSTR FileName
,
2170 DWORD dwLineNumber
, PLONG lpDisplacement
, PIMAGEHLP_LINE64 Line
)
2172 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, ModuleName
, FileName
,
2173 dwLineNumber
, lpDisplacement
, Line
);
2177 BOOL WINAPI
SymGetLineFromNameW64(HANDLE hProcess
, PCWSTR ModuleName
, PCWSTR FileName
,
2178 DWORD dwLineNumber
, PLONG plDisplacement
, PIMAGEHLP_LINEW64 Line
)
2180 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, debugstr_w(ModuleName
), debugstr_w(FileName
),
2181 dwLineNumber
, plDisplacement
, Line
);
2185 /******************************************************************
2186 * SymFromIndex (DBGHELP.@)
2189 BOOL WINAPI
SymFromIndex(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD index
, PSYMBOL_INFO symbol
)
2191 FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
2192 hProcess
, wine_dbgstr_longlong(BaseOfDll
), index
, symbol
);
2197 /******************************************************************
2198 * SymFromIndexW (DBGHELP.@)
2201 BOOL WINAPI
SymFromIndexW(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD index
, PSYMBOL_INFOW symbol
)
2203 FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
2204 hProcess
, wine_dbgstr_longlong(BaseOfDll
), index
, symbol
);
2209 /******************************************************************
2210 * SymSetHomeDirectory (DBGHELP.@)
2213 PCHAR WINAPI
SymSetHomeDirectory(HANDLE hProcess
, PCSTR dir
)
2215 FIXME("(%p, %s): stub\n", hProcess
, dir
);
2220 /******************************************************************
2221 * SymSetHomeDirectoryW (DBGHELP.@)
2224 PWSTR WINAPI
SymSetHomeDirectoryW(HANDLE hProcess
, PCWSTR dir
)
2226 FIXME("(%p, %s): stub\n", hProcess
, debugstr_w(dir
));