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
28 #include <sys/types.h>
31 #include "wine/debug.h"
32 #include "dbghelp_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
36 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt
);
38 static const WCHAR starW
[] = {'*','\0'};
40 static inline int cmp_addr(ULONG64 a1
, ULONG64 a2
)
42 if (a1
> a2
) return 1;
43 if (a1
< a2
) return -1;
47 static inline int cmp_sorttab_addr(struct module
* module
, int idx
, ULONG64 addr
)
50 symt_get_address(&module
->addr_sorttab
[idx
]->symt
, &ref
);
51 return cmp_addr(ref
, addr
);
54 int __cdecl
symt_cmp_addr(const void* p1
, const void* p2
)
56 const struct symt
* sym1
= *(const struct symt
* const *)p1
;
57 const struct symt
* sym2
= *(const struct symt
* const *)p2
;
60 symt_get_address(sym1
, &a1
);
61 symt_get_address(sym2
, &a2
);
62 return cmp_addr(a1
, a2
);
65 DWORD
symt_ptr2index(struct module
* module
, const struct symt
* sym
)
68 const struct symt
** c
;
69 int len
= vector_length(&module
->vsymt
), i
;
71 /* FIXME: this is inefficient */
72 for (i
= 0; i
< len
; i
++)
74 if (*(struct symt
**)vector_at(&module
->vsymt
, i
) == sym
)
78 c
= vector_add(&module
->vsymt
, &module
->pool
);
86 struct symt
* symt_index2ptr(struct module
* module
, DWORD id
)
89 if (!id
-- || id
>= vector_length(&module
->vsymt
)) return NULL
;
90 return *(struct symt
**)vector_at(&module
->vsymt
, id
);
92 return (struct symt
*)id
;
96 static BOOL
symt_grow_sorttab(struct module
* module
, unsigned sz
)
101 if (sz
<= module
->sorttab_size
) return TRUE
;
102 if (module
->addr_sorttab
)
104 size
= module
->sorttab_size
* 2;
105 new = HeapReAlloc(GetProcessHeap(), 0, module
->addr_sorttab
,
106 size
* sizeof(struct symt_ht
*));
111 new = HeapAlloc(GetProcessHeap(), 0, size
* sizeof(struct symt_ht
*));
113 if (!new) return FALSE
;
114 module
->sorttab_size
= size
;
115 module
->addr_sorttab
= new;
119 static void symt_add_module_ht(struct module
* module
, struct symt_ht
* ht
)
123 hash_table_add(&module
->ht_symbols
, &ht
->hash_elt
);
124 /* Don't store in sorttab a symbol without address, they are of
125 * no use here (e.g. constant values)
127 if (symt_get_address(&ht
->symt
, &addr
) &&
128 symt_grow_sorttab(module
, module
->num_symbols
+ 1))
130 module
->addr_sorttab
[module
->num_symbols
++] = ht
;
131 module
->sortlist_valid
= FALSE
;
135 static WCHAR
* file_regex(const char* srcfile
)
140 if (!srcfile
|| !*srcfile
)
142 if (!(p
= mask
= HeapAlloc(GetProcessHeap(), 0, 3 * sizeof(WCHAR
)))) return NULL
;
148 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, NULL
, 0);
151 /* FIXME: we use here the largest conversion for every char... could be optimized */
152 p
= mask
= HeapAlloc(GetProcessHeap(), 0, (5 * strlen(srcfile
) + 1 + sz
) * sizeof(WCHAR
));
153 if (!mask
) return NULL
;
154 srcfileW
= mask
+ 5 * strlen(srcfile
) + 1;
155 MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, srcfileW
, sz
);
183 struct symt_compiland
* symt_new_compiland(struct module
* module
,
184 ULONG_PTR address
, unsigned src_idx
)
186 struct symt_compiland
* sym
;
188 TRACE_(dbghelp_symt
)("Adding compiland symbol %s:%s\n",
189 debugstr_w(module
->module
.ModuleName
), source_get(module
, src_idx
));
190 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
192 sym
->symt
.tag
= SymTagCompiland
;
193 sym
->address
= address
;
194 sym
->source
= src_idx
;
195 vector_init(&sym
->vchildren
, sizeof(struct symt
*), 32);
200 struct symt_public
* symt_new_public(struct module
* module
,
201 struct symt_compiland
* compiland
,
204 ULONG_PTR address
, unsigned size
)
206 struct symt_public
* sym
;
209 TRACE_(dbghelp_symt
)("Adding public symbol %s:%s @%lx\n",
210 debugstr_w(module
->module
.ModuleName
), name
, address
);
211 if ((dbghelp_options
& SYMOPT_AUTO_PUBLICS
) &&
212 symt_find_nearest(module
, address
) != NULL
)
214 if ((sym
= pool_alloc(&module
->pool
, sizeof(*sym
))))
216 sym
->symt
.tag
= SymTagPublicSymbol
;
217 sym
->hash_elt
.name
= pool_strdup(&module
->pool
, name
);
218 sym
->container
= compiland
? &compiland
->symt
: NULL
;
219 sym
->is_function
= is_function
;
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
, ULONG_PTR 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 ULONG_PTR addr
, ULONG_PTR 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
, ULONG_PTR 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 CONTAINING_RECORD(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 ULONG_PTR addr
, ULONG_PTR 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
, ULONG_PTR 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
->Index
= 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_PTR
)data
->u
.value
.n1
.n2
.n3
.iVal
; break;
658 case VT_I1
: sym_info
->Value
= (ULONG
)(LONG_PTR
)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
:
677 const struct symt_public
* pub
= (const struct symt_public
*)sym
;
678 if (pub
->is_function
)
679 sym_info
->Flags
|= SYMFLAG_PUBLIC_CODE
;
681 sym_info
->Flags
|= SYMFLAG_EXPORT
;
682 symt_get_address(sym
, &sym_info
->Address
);
686 symt_get_address(sym
, &sym_info
->Address
);
689 sym_info
->Flags
|= SYMFLAG_THUNK
;
690 symt_get_address(sym
, &sym_info
->Address
);
693 symt_get_address(sym
, &sym_info
->Address
);
694 sym_info
->Register
= 0;
697 sym_info
->Scope
= 0; /* FIXME */
698 sym_info
->Tag
= sym
->tag
;
699 name
= symt_get_name(sym
);
700 if (sym_info
->MaxNameLen
)
702 if (sym
->tag
!= SymTagPublicSymbol
|| !(dbghelp_options
& SYMOPT_UNDNAME
) ||
703 ((sym_info
->NameLen
= UnDecorateSymbolName(name
, sym_info
->Name
,
704 sym_info
->MaxNameLen
, UNDNAME_NAME_ONLY
)) == 0))
706 sym_info
->NameLen
= min(strlen(name
), sym_info
->MaxNameLen
- 1);
707 memcpy(sym_info
->Name
, name
, sym_info
->NameLen
);
708 sym_info
->Name
[sym_info
->NameLen
] = '\0';
711 TRACE_(dbghelp_symt
)("%p => %s %u %s\n",
712 sym
, sym_info
->Name
, sym_info
->Size
,
713 wine_dbgstr_longlong(sym_info
->Address
));
718 PSYM_ENUMERATESYMBOLS_CALLBACK cb
;
720 SYMBOL_INFO
* sym_info
;
724 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
727 static BOOL
send_symbol(const struct sym_enum
* se
, struct module_pair
* pair
,
728 const struct symt_function
* func
, const struct symt
* sym
)
730 symt_fill_sym_info(pair
, func
, sym
, se
->sym_info
);
731 if (se
->index
&& se
->sym_info
->Index
!= se
->index
) return FALSE
;
732 if (se
->tag
&& se
->sym_info
->Tag
!= se
->tag
) return FALSE
;
733 if (se
->addr
&& !(se
->addr
>= se
->sym_info
->Address
&& se
->addr
< se
->sym_info
->Address
+ se
->sym_info
->Size
)) return FALSE
;
734 return !se
->cb(se
->sym_info
, se
->sym_info
->Size
, se
->user
);
737 static BOOL
symt_enum_module(struct module_pair
* pair
, const WCHAR
* match
,
738 const struct sym_enum
* se
)
741 struct symt_ht
* sym
= NULL
;
742 struct hash_table_iter hti
;
746 hash_table_iter_init(&pair
->effective
->ht_symbols
, &hti
, NULL
);
747 while ((ptr
= hash_table_iter_up(&hti
)))
749 sym
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
750 nameW
= symt_get_nameW(&sym
->symt
);
751 ret
= SymMatchStringW(nameW
, match
, FALSE
);
752 HeapFree(GetProcessHeap(), 0, nameW
);
755 se
->sym_info
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
756 se
->sym_info
->MaxNameLen
= sizeof(se
->buffer
) - sizeof(SYMBOL_INFO
);
757 if (send_symbol(se
, pair
, NULL
, &sym
->symt
)) return TRUE
;
763 static inline unsigned where_to_insert(struct module
* module
, unsigned high
, const struct symt_ht
* elt
)
765 unsigned low
= 0, mid
= high
/ 2;
769 symt_get_address(&elt
->symt
, &addr
);
772 switch (cmp_sorttab_addr(module
, mid
, addr
))
775 case -1: low
= mid
+ 1; break;
776 case 1: high
= mid
; break;
778 mid
= low
+ (high
- low
) / 2;
779 } while (low
< high
);
783 /***********************************************************************
786 * Rebuild sorted list of symbols for a module.
788 static BOOL
resort_symbols(struct module
* module
)
792 if (!(module
->module
.NumSyms
= module
->num_symbols
))
795 /* we know that set from 0 up to num_sorttab is already sorted
796 * so sort the remaining (new) symbols, and merge the two sets
797 * (unless the first set is empty)
799 delta
= module
->num_symbols
- module
->num_sorttab
;
800 qsort(&module
->addr_sorttab
[module
->num_sorttab
], delta
, sizeof(struct symt_ht
*), symt_cmp_addr
);
801 if (module
->num_sorttab
)
803 int i
, ins_idx
= module
->num_sorttab
, prev_ins_idx
;
804 static struct symt_ht
** tmp
;
805 static unsigned num_tmp
;
809 static struct symt_ht
** new;
811 new = HeapReAlloc(GetProcessHeap(), 0, tmp
, delta
* sizeof(struct symt_ht
*));
813 new = HeapAlloc(GetProcessHeap(), 0, delta
* sizeof(struct symt_ht
*));
816 module
->num_sorttab
= 0;
817 return resort_symbols(module
);
822 memcpy(tmp
, &module
->addr_sorttab
[module
->num_sorttab
], delta
* sizeof(struct symt_ht
*));
823 qsort(tmp
, delta
, sizeof(struct symt_ht
*), symt_cmp_addr
);
825 for (i
= delta
- 1; i
>= 0; i
--)
827 prev_ins_idx
= ins_idx
;
828 ins_idx
= where_to_insert(module
, ins_idx
, tmp
[i
]);
829 memmove(&module
->addr_sorttab
[ins_idx
+ i
+ 1],
830 &module
->addr_sorttab
[ins_idx
],
831 (prev_ins_idx
- ins_idx
) * sizeof(struct symt_ht
*));
832 module
->addr_sorttab
[ins_idx
+ i
] = tmp
[i
];
835 module
->num_sorttab
= module
->num_symbols
;
836 return module
->sortlist_valid
= TRUE
;
839 static void symt_get_length(struct module
* module
, const struct symt
* symt
, ULONG64
* size
)
843 if (symt_get_info(module
, symt
, TI_GET_LENGTH
, size
) && *size
)
846 if (symt_get_info(module
, symt
, TI_GET_TYPE
, &type_index
) &&
847 symt_get_info(module
, symt_index2ptr(module
, type_index
), TI_GET_LENGTH
, size
)) return;
848 *size
= 0x1000; /* arbitrary value */
851 /* needed by symt_find_nearest */
852 static int symt_get_best_at(struct module
* module
, int idx_sorttab
)
855 int idx_sorttab_orig
= idx_sorttab
;
856 if (module
->addr_sorttab
[idx_sorttab
]->symt
.tag
== SymTagPublicSymbol
)
858 symt_get_address(&module
->addr_sorttab
[idx_sorttab
]->symt
, &ref_addr
);
859 while (idx_sorttab
> 0 &&
860 module
->addr_sorttab
[idx_sorttab
]->symt
.tag
== SymTagPublicSymbol
&&
861 !cmp_sorttab_addr(module
, idx_sorttab
- 1, ref_addr
))
863 if (module
->addr_sorttab
[idx_sorttab
]->symt
.tag
== SymTagPublicSymbol
)
865 idx_sorttab
= idx_sorttab_orig
;
866 while (idx_sorttab
< module
->num_sorttab
- 1 &&
867 module
->addr_sorttab
[idx_sorttab
]->symt
.tag
== SymTagPublicSymbol
&&
868 !cmp_sorttab_addr(module
, idx_sorttab
+ 1, ref_addr
))
871 /* if no better symbol was found restore the original */
872 if (module
->addr_sorttab
[idx_sorttab
]->symt
.tag
== SymTagPublicSymbol
)
873 idx_sorttab
= idx_sorttab_orig
;
878 /* assume addr is in module */
879 struct symt_ht
* symt_find_nearest(struct module
* module
, DWORD_PTR addr
)
882 ULONG64 ref_addr
, ref_size
;
884 if (!module
->sortlist_valid
|| !module
->addr_sorttab
)
886 if (!resort_symbols(module
)) return NULL
;
890 * Binary search to find closest symbol.
893 high
= module
->num_sorttab
;
895 symt_get_address(&module
->addr_sorttab
[0]->symt
, &ref_addr
);
896 if (addr
<= ref_addr
)
898 low
= symt_get_best_at(module
, 0);
899 return module
->addr_sorttab
[low
];
904 symt_get_address(&module
->addr_sorttab
[high
- 1]->symt
, &ref_addr
);
905 symt_get_length(module
, &module
->addr_sorttab
[high
- 1]->symt
, &ref_size
);
906 if (addr
>= ref_addr
+ ref_size
) return NULL
;
909 while (high
> low
+ 1)
911 mid
= (high
+ low
) / 2;
912 if (cmp_sorttab_addr(module
, mid
, addr
) < 0)
917 if (low
!= high
&& high
!= module
->num_sorttab
&&
918 cmp_sorttab_addr(module
, high
, addr
) <= 0)
921 /* If found symbol is a public symbol, check if there are any other entries that
922 * might also have the same address, but would get better information
924 low
= symt_get_best_at(module
, low
);
926 return module
->addr_sorttab
[low
];
929 static BOOL
symt_enum_locals_helper(struct module_pair
* pair
,
930 const WCHAR
* match
, const struct sym_enum
* se
,
931 struct symt_function
* func
, const struct vector
* v
)
933 struct symt
* lsym
= NULL
;
934 DWORD pc
= pair
->pcs
->ctx_frame
.InstructionOffset
;
939 for (i
=0; i
<vector_length(v
); i
++)
941 lsym
= *(struct symt
**)vector_at(v
, i
);
946 struct symt_block
* block
= (struct symt_block
*)lsym
;
947 if (pc
< block
->address
|| block
->address
+ block
->size
<= pc
)
949 if (!symt_enum_locals_helper(pair
, match
, se
, func
, &block
->vchildren
))
954 nameW
= symt_get_nameW(lsym
);
955 ret
= SymMatchStringW(nameW
, match
,
956 !(dbghelp_options
& SYMOPT_CASE_INSENSITIVE
));
957 HeapFree(GetProcessHeap(), 0, nameW
);
960 if (send_symbol(se
, pair
, func
, lsym
)) return FALSE
;
964 case SymTagFuncDebugStart
:
965 case SymTagFuncDebugEnd
:
969 FIXME("Unknown type: %u (%x)\n", lsym
->tag
, lsym
->tag
);
976 static BOOL
symt_enum_locals(struct process
* pcs
, const WCHAR
* mask
,
977 const struct sym_enum
* se
)
979 struct module_pair pair
;
981 DWORD_PTR pc
= pcs
->ctx_frame
.InstructionOffset
;
983 se
->sym_info
->SizeOfStruct
= sizeof(*se
->sym_info
);
984 se
->sym_info
->MaxNameLen
= sizeof(se
->buffer
) - sizeof(SYMBOL_INFO
);
987 pair
.requested
= module_find_by_addr(pair
.pcs
, pc
, DMT_UNKNOWN
);
988 if (!module_get_debug(&pair
)) return FALSE
;
989 if ((sym
= symt_find_nearest(pair
.effective
, pc
)) == NULL
) return FALSE
;
991 if (sym
->symt
.tag
== SymTagFunction
)
993 return symt_enum_locals_helper(&pair
, mask
? mask
: starW
, se
, (struct symt_function
*)sym
,
994 &((struct symt_function
*)sym
)->vchildren
);
999 /******************************************************************
1002 * Helper for transforming an ANSI symbol info into a UNICODE one.
1003 * Assume that MaxNameLen is the same for both version (A & W).
1005 void copy_symbolW(SYMBOL_INFOW
* siw
, const SYMBOL_INFO
* si
)
1007 siw
->SizeOfStruct
= si
->SizeOfStruct
;
1008 siw
->TypeIndex
= si
->TypeIndex
;
1009 siw
->Reserved
[0] = si
->Reserved
[0];
1010 siw
->Reserved
[1] = si
->Reserved
[1];
1011 siw
->Index
= si
->Index
;
1012 siw
->Size
= si
->Size
;
1013 siw
->ModBase
= si
->ModBase
;
1014 siw
->Flags
= si
->Flags
;
1015 siw
->Value
= si
->Value
;
1016 siw
->Address
= si
->Address
;
1017 siw
->Register
= si
->Register
;
1018 siw
->Scope
= si
->Scope
;
1020 siw
->NameLen
= si
->NameLen
;
1021 siw
->MaxNameLen
= si
->MaxNameLen
;
1022 MultiByteToWideChar(CP_ACP
, 0, si
->Name
, -1, siw
->Name
, siw
->MaxNameLen
);
1025 /******************************************************************
1028 * Core routine for most of the enumeration of symbols
1030 static BOOL
sym_enum(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1031 const struct sym_enum
* se
)
1033 struct module_pair pair
;
1037 pair
.pcs
= process_find_by_handle(hProcess
);
1038 if (!pair
.pcs
) return FALSE
;
1041 /* do local variables ? */
1042 if (!Mask
|| !(bang
= wcschr(Mask
, '!')))
1043 return symt_enum_locals(pair
.pcs
, Mask
, se
);
1045 if (bang
== Mask
) return FALSE
;
1047 mod
= HeapAlloc(GetProcessHeap(), 0, (bang
- Mask
+ 1) * sizeof(WCHAR
));
1048 if (!mod
) return FALSE
;
1049 memcpy(mod
, Mask
, (bang
- Mask
) * sizeof(WCHAR
));
1050 mod
[bang
- Mask
] = 0;
1052 for (pair
.requested
= pair
.pcs
->lmodules
; pair
.requested
; pair
.requested
= pair
.requested
->next
)
1054 if (pair
.requested
->type
== DMT_PE
&& module_get_debug(&pair
))
1056 if (SymMatchStringW(pair
.requested
->module
.ModuleName
, mod
, FALSE
) &&
1057 symt_enum_module(&pair
, bang
+ 1, se
))
1061 /* not found in PE modules, retry on the ELF ones
1063 if (!pair
.requested
&& dbghelp_opt_native
)
1065 for (pair
.requested
= pair
.pcs
->lmodules
; pair
.requested
; pair
.requested
= pair
.requested
->next
)
1067 if ((pair
.requested
->type
== DMT_ELF
|| pair
.requested
->type
== DMT_MACHO
) &&
1068 !module_get_containee(pair
.pcs
, pair
.requested
) &&
1069 module_get_debug(&pair
))
1071 if (SymMatchStringW(pair
.requested
->module
.ModuleName
, mod
, FALSE
) &&
1072 symt_enum_module(&pair
, bang
+ 1, se
))
1077 HeapFree(GetProcessHeap(), 0, mod
);
1080 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
1081 if (!module_get_debug(&pair
))
1084 /* we always ignore module name from Mask when BaseOfDll is defined */
1085 if (Mask
&& (bang
= wcschr(Mask
, '!')))
1087 if (bang
== Mask
) return FALSE
;
1091 symt_enum_module(&pair
, Mask
? Mask
: starW
, se
);
1096 static inline BOOL
doSymEnumSymbols(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1097 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1102 se
.cb
= EnumSymbolsCallback
;
1103 se
.user
= UserContext
;
1107 se
.sym_info
= (PSYMBOL_INFO
)se
.buffer
;
1109 return sym_enum(hProcess
, BaseOfDll
, Mask
, &se
);
1112 /******************************************************************
1113 * SymEnumSymbols (DBGHELP.@)
1115 * cases BaseOfDll = 0
1116 * !foo fails always (despite what MSDN states)
1117 * RE1!RE2 looks up all modules matching RE1, and in all these modules, lookup RE2
1118 * no ! in Mask, lookup in local Context
1119 * cases BaseOfDll != 0
1120 * !foo fails always (despite what MSDN states)
1121 * RE1!RE2 gets RE2 from BaseOfDll (whatever RE1 is)
1123 BOOL WINAPI
SymEnumSymbols(HANDLE hProcess
, ULONG64 BaseOfDll
, PCSTR Mask
,
1124 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
1130 TRACE("(%p %s %s %p %p)\n",
1131 hProcess
, wine_dbgstr_longlong(BaseOfDll
), debugstr_a(Mask
),
1132 EnumSymbolsCallback
, UserContext
);
1136 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, NULL
, 0);
1137 if (!(maskW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1139 MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, maskW
, sz
);
1141 ret
= doSymEnumSymbols(hProcess
, BaseOfDll
, maskW
, EnumSymbolsCallback
, UserContext
);
1142 HeapFree(GetProcessHeap(), 0, maskW
);
1148 PSYM_ENUMERATESYMBOLS_CALLBACKW cb
;
1150 PSYMBOL_INFOW sym_info
;
1151 char buffer
[sizeof(SYMBOL_INFOW
) + MAX_SYM_NAME
];
1155 static BOOL CALLBACK
sym_enumW(PSYMBOL_INFO si
, ULONG size
, PVOID ctx
)
1157 struct sym_enumW
* sew
= ctx
;
1159 copy_symbolW(sew
->sym_info
, si
);
1161 return (sew
->cb
)(sew
->sym_info
, size
, sew
->ctx
);
1164 /******************************************************************
1165 * SymEnumSymbolsW (DBGHELP.@)
1168 BOOL WINAPI
SymEnumSymbolsW(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR Mask
,
1169 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
1172 struct sym_enumW sew
;
1174 sew
.ctx
= UserContext
;
1175 sew
.cb
= EnumSymbolsCallback
;
1176 sew
.sym_info
= (PSYMBOL_INFOW
)sew
.buffer
;
1178 return doSymEnumSymbols(hProcess
, BaseOfDll
, Mask
, sym_enumW
, &sew
);
1181 struct sym_enumerate
1184 PSYM_ENUMSYMBOLS_CALLBACK cb
;
1187 static BOOL CALLBACK
sym_enumerate_cb(PSYMBOL_INFO syminfo
, ULONG size
, void* ctx
)
1189 struct sym_enumerate
* se
= ctx
;
1190 return (se
->cb
)(syminfo
->Name
, syminfo
->Address
, syminfo
->Size
, se
->ctx
);
1193 /***********************************************************************
1194 * SymEnumerateSymbols (DBGHELP.@)
1196 BOOL WINAPI
SymEnumerateSymbols(HANDLE hProcess
, DWORD BaseOfDll
,
1197 PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback
,
1200 struct sym_enumerate se
;
1202 se
.ctx
= UserContext
;
1203 se
.cb
= EnumSymbolsCallback
;
1205 return SymEnumSymbols(hProcess
, BaseOfDll
, NULL
, sym_enumerate_cb
, &se
);
1208 struct sym_enumerate64
1211 PSYM_ENUMSYMBOLS_CALLBACK64 cb
;
1214 static BOOL CALLBACK
sym_enumerate_cb64(PSYMBOL_INFO syminfo
, ULONG size
, void* ctx
)
1216 struct sym_enumerate64
* se
= ctx
;
1217 return (se
->cb
)(syminfo
->Name
, syminfo
->Address
, syminfo
->Size
, se
->ctx
);
1220 /***********************************************************************
1221 * SymEnumerateSymbols64 (DBGHELP.@)
1223 BOOL WINAPI
SymEnumerateSymbols64(HANDLE hProcess
, DWORD64 BaseOfDll
,
1224 PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback
,
1227 struct sym_enumerate64 se
;
1229 se
.ctx
= UserContext
;
1230 se
.cb
= EnumSymbolsCallback
;
1232 return SymEnumSymbols(hProcess
, BaseOfDll
, NULL
, sym_enumerate_cb64
, &se
);
1235 /******************************************************************
1236 * SymFromAddr (DBGHELP.@)
1239 BOOL WINAPI
SymFromAddr(HANDLE hProcess
, DWORD64 Address
,
1240 DWORD64
* Displacement
, PSYMBOL_INFO Symbol
)
1242 struct module_pair pair
;
1243 struct symt_ht
* sym
;
1245 pair
.pcs
= process_find_by_handle(hProcess
);
1246 if (!pair
.pcs
) return FALSE
;
1247 pair
.requested
= module_find_by_addr(pair
.pcs
, Address
, DMT_UNKNOWN
);
1248 if (!module_get_debug(&pair
)) return FALSE
;
1249 if ((sym
= symt_find_nearest(pair
.effective
, Address
)) == NULL
) return FALSE
;
1251 symt_fill_sym_info(&pair
, NULL
, &sym
->symt
, Symbol
);
1253 *Displacement
= (Address
>= Symbol
->Address
) ? (Address
- Symbol
->Address
) : (DWORD64
)-1;
1257 /******************************************************************
1258 * SymFromAddrW (DBGHELP.@)
1261 BOOL WINAPI
SymFromAddrW(HANDLE hProcess
, DWORD64 Address
,
1262 DWORD64
* Displacement
, PSYMBOL_INFOW Symbol
)
1268 len
= sizeof(*si
) + Symbol
->MaxNameLen
* sizeof(WCHAR
);
1269 si
= HeapAlloc(GetProcessHeap(), 0, len
);
1270 if (!si
) return FALSE
;
1272 si
->SizeOfStruct
= sizeof(*si
);
1273 si
->MaxNameLen
= Symbol
->MaxNameLen
;
1274 if ((ret
= SymFromAddr(hProcess
, Address
, Displacement
, si
)))
1276 copy_symbolW(Symbol
, si
);
1278 HeapFree(GetProcessHeap(), 0, si
);
1282 /******************************************************************
1283 * SymGetSymFromAddr (DBGHELP.@)
1286 BOOL WINAPI
SymGetSymFromAddr(HANDLE hProcess
, DWORD Address
,
1287 PDWORD Displacement
, PIMAGEHLP_SYMBOL Symbol
)
1289 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1290 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1292 DWORD64 Displacement64
;
1294 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1295 si
->SizeOfStruct
= sizeof(*si
);
1296 si
->MaxNameLen
= MAX_SYM_NAME
;
1297 if (!SymFromAddr(hProcess
, Address
, &Displacement64
, si
))
1301 *Displacement
= Displacement64
;
1302 Symbol
->Address
= si
->Address
;
1303 Symbol
->Size
= si
->Size
;
1304 Symbol
->Flags
= si
->Flags
;
1305 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1306 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1310 /******************************************************************
1311 * SymGetSymFromAddr64 (DBGHELP.@)
1314 BOOL WINAPI
SymGetSymFromAddr64(HANDLE hProcess
, DWORD64 Address
,
1315 PDWORD64 Displacement
, PIMAGEHLP_SYMBOL64 Symbol
)
1317 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1318 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1320 DWORD64 Displacement64
;
1322 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1323 si
->SizeOfStruct
= sizeof(*si
);
1324 si
->MaxNameLen
= MAX_SYM_NAME
;
1325 if (!SymFromAddr(hProcess
, Address
, &Displacement64
, si
))
1329 *Displacement
= Displacement64
;
1330 Symbol
->Address
= si
->Address
;
1331 Symbol
->Size
= si
->Size
;
1332 Symbol
->Flags
= si
->Flags
;
1333 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1334 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1338 static BOOL
find_name(struct process
* pcs
, struct module
* module
, const char* name
,
1339 SYMBOL_INFO
* symbol
)
1341 struct hash_table_iter hti
;
1343 struct symt_ht
* sym
= NULL
;
1344 struct module_pair pair
;
1347 if (!(pair
.requested
= module
)) return FALSE
;
1348 if (!module_get_debug(&pair
)) return FALSE
;
1350 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, name
);
1351 while ((ptr
= hash_table_iter_up(&hti
)))
1353 sym
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
1355 if (!strcmp(sym
->hash_elt
.name
, name
))
1357 symt_fill_sym_info(&pair
, NULL
, &sym
->symt
, symbol
);
1364 /******************************************************************
1365 * SymFromName (DBGHELP.@)
1368 BOOL WINAPI
SymFromName(HANDLE hProcess
, PCSTR Name
, PSYMBOL_INFO Symbol
)
1370 struct process
* pcs
= process_find_by_handle(hProcess
);
1371 struct module
* module
;
1374 TRACE("(%p, %s, %p)\n", hProcess
, Name
, Symbol
);
1375 if (!pcs
) return FALSE
;
1376 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1377 name
= strchr(Name
, '!');
1381 assert(name
- Name
< sizeof(tmp
));
1382 memcpy(tmp
, Name
, name
- Name
);
1383 tmp
[name
- Name
] = '\0';
1384 module
= module_find_by_nameA(pcs
, tmp
);
1385 return find_name(pcs
, module
, name
+ 1, Symbol
);
1387 for (module
= pcs
->lmodules
; module
; module
= module
->next
)
1389 if (module
->type
== DMT_PE
&& find_name(pcs
, module
, Name
, Symbol
))
1392 /* not found in PE modules, retry on the ELF ones
1394 if (dbghelp_opt_native
)
1396 for (module
= pcs
->lmodules
; module
; module
= module
->next
)
1398 if ((module
->type
== DMT_ELF
|| module
->type
== DMT_MACHO
) &&
1399 !module_get_containee(pcs
, module
) &&
1400 find_name(pcs
, module
, Name
, Symbol
))
1407 /***********************************************************************
1408 * SymGetSymFromName64 (DBGHELP.@)
1410 BOOL WINAPI
SymGetSymFromName64(HANDLE hProcess
, PCSTR Name
, PIMAGEHLP_SYMBOL64 Symbol
)
1412 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1413 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1416 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1417 si
->SizeOfStruct
= sizeof(*si
);
1418 si
->MaxNameLen
= MAX_SYM_NAME
;
1419 if (!SymFromName(hProcess
, Name
, si
)) return FALSE
;
1421 Symbol
->Address
= si
->Address
;
1422 Symbol
->Size
= si
->Size
;
1423 Symbol
->Flags
= si
->Flags
;
1424 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1425 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1429 /***********************************************************************
1430 * SymGetSymFromName (DBGHELP.@)
1432 BOOL WINAPI
SymGetSymFromName(HANDLE hProcess
, PCSTR Name
, PIMAGEHLP_SYMBOL Symbol
)
1434 char buffer
[sizeof(SYMBOL_INFO
) + MAX_SYM_NAME
];
1435 SYMBOL_INFO
*si
= (SYMBOL_INFO
*)buffer
;
1438 if (Symbol
->SizeOfStruct
< sizeof(*Symbol
)) return FALSE
;
1439 si
->SizeOfStruct
= sizeof(*si
);
1440 si
->MaxNameLen
= MAX_SYM_NAME
;
1441 if (!SymFromName(hProcess
, Name
, si
)) return FALSE
;
1443 Symbol
->Address
= si
->Address
;
1444 Symbol
->Size
= si
->Size
;
1445 Symbol
->Flags
= si
->Flags
;
1446 len
= min(Symbol
->MaxNameLength
, si
->MaxNameLen
);
1447 lstrcpynA(Symbol
->Name
, si
->Name
, len
);
1451 /******************************************************************
1452 * sym_fill_func_line_info
1454 * fills information about a file
1456 BOOL
symt_fill_func_line_info(const struct module
* module
, const struct symt_function
* func
,
1457 DWORD64 addr
, IMAGEHLP_LINE64
* line
)
1459 struct line_info
* dli
= NULL
;
1463 assert(func
->symt
.tag
== SymTagFunction
);
1465 for (i
=vector_length(&func
->vlines
)-1; i
>=0; i
--)
1467 dli
= vector_at(&func
->vlines
, i
);
1468 if (!dli
->is_source_file
)
1470 if (found
|| dli
->u
.pc_offset
> addr
) continue;
1471 line
->LineNumber
= dli
->line_number
;
1472 line
->Address
= dli
->u
.pc_offset
;
1479 if (dbghelp_opt_native
)
1481 /* Return native file paths when using winedbg */
1482 line
->FileName
= (char*)source_get(module
, dli
->u
.source_file
);
1486 WCHAR
*dospath
= wine_get_dos_file_name(source_get(module
, dli
->u
.source_file
));
1487 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, dospath
, -1, NULL
, 0, NULL
, NULL
);
1488 line
->FileName
= fetch_buffer(module
->process
, len
);
1489 WideCharToMultiByte(CP_ACP
, 0, dospath
, -1, line
->FileName
, len
, NULL
, NULL
);
1490 HeapFree( GetProcessHeap(), 0, dospath
);
1498 /***********************************************************************
1499 * SymGetSymNext64 (DBGHELP.@)
1501 BOOL WINAPI
SymGetSymNext64(HANDLE hProcess
, PIMAGEHLP_SYMBOL64 Symbol
)
1504 * get module from Symbol.Address
1505 * get index in module.addr_sorttab of Symbol.Address
1507 * if out of module bounds, move to next module in process address space
1509 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1510 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1514 /***********************************************************************
1515 * SymGetSymNext (DBGHELP.@)
1517 BOOL WINAPI
SymGetSymNext(HANDLE hProcess
, PIMAGEHLP_SYMBOL Symbol
)
1519 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1520 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1524 /***********************************************************************
1525 * SymGetSymPrev64 (DBGHELP.@)
1527 BOOL WINAPI
SymGetSymPrev64(HANDLE hProcess
, PIMAGEHLP_SYMBOL64 Symbol
)
1529 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1530 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1534 /***********************************************************************
1535 * SymGetSymPrev (DBGHELP.@)
1537 BOOL WINAPI
SymGetSymPrev(HANDLE hProcess
, PIMAGEHLP_SYMBOL Symbol
)
1539 FIXME("(%p, %p): stub\n", hProcess
, Symbol
);
1540 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1544 /******************************************************************
1545 * copy_line_64_from_32 (internal)
1548 static void copy_line_64_from_32(IMAGEHLP_LINE64
* l64
, const IMAGEHLP_LINE
* l32
)
1551 l64
->Key
= l32
->Key
;
1552 l64
->LineNumber
= l32
->LineNumber
;
1553 l64
->FileName
= l32
->FileName
;
1554 l64
->Address
= l32
->Address
;
1557 /******************************************************************
1558 * copy_line_W64_from_32 (internal)
1561 static void copy_line_W64_from_64(struct process
* pcs
, IMAGEHLP_LINEW64
* l64w
, const IMAGEHLP_LINE64
* l64
)
1565 l64w
->Key
= l64
->Key
;
1566 l64w
->LineNumber
= l64
->LineNumber
;
1567 len
= MultiByteToWideChar(CP_ACP
, 0, l64
->FileName
, -1, NULL
, 0);
1568 if ((l64w
->FileName
= fetch_buffer(pcs
, len
* sizeof(WCHAR
))))
1569 MultiByteToWideChar(CP_ACP
, 0, l64
->FileName
, -1, l64w
->FileName
, len
);
1570 l64w
->Address
= l64
->Address
;
1573 /******************************************************************
1574 * copy_line_32_from_64 (internal)
1577 static void copy_line_32_from_64(IMAGEHLP_LINE
* l32
, const IMAGEHLP_LINE64
* l64
)
1580 l32
->Key
= l64
->Key
;
1581 l32
->LineNumber
= l64
->LineNumber
;
1582 l32
->FileName
= l64
->FileName
;
1583 l32
->Address
= l64
->Address
;
1586 /******************************************************************
1587 * SymGetLineFromAddr (DBGHELP.@)
1590 BOOL WINAPI
SymGetLineFromAddr(HANDLE hProcess
, DWORD dwAddr
,
1591 PDWORD pdwDisplacement
, PIMAGEHLP_LINE Line
)
1593 IMAGEHLP_LINE64 il64
;
1595 il64
.SizeOfStruct
= sizeof(il64
);
1596 if (!SymGetLineFromAddr64(hProcess
, dwAddr
, pdwDisplacement
, &il64
))
1598 copy_line_32_from_64(Line
, &il64
);
1602 /******************************************************************
1603 * SymGetLineFromAddr64 (DBGHELP.@)
1606 BOOL WINAPI
SymGetLineFromAddr64(HANDLE hProcess
, DWORD64 dwAddr
,
1607 PDWORD pdwDisplacement
, PIMAGEHLP_LINE64 Line
)
1609 struct module_pair pair
;
1610 struct symt_ht
* symt
;
1612 TRACE("%p %s %p %p\n", hProcess
, wine_dbgstr_longlong(dwAddr
), pdwDisplacement
, Line
);
1614 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1616 pair
.pcs
= process_find_by_handle(hProcess
);
1617 if (!pair
.pcs
) return FALSE
;
1618 pair
.requested
= module_find_by_addr(pair
.pcs
, dwAddr
, DMT_UNKNOWN
);
1619 if (!module_get_debug(&pair
)) return FALSE
;
1620 if ((symt
= symt_find_nearest(pair
.effective
, dwAddr
)) == NULL
) return FALSE
;
1622 if (symt
->symt
.tag
!= SymTagFunction
) return FALSE
;
1623 if (!symt_fill_func_line_info(pair
.effective
, (struct symt_function
*)symt
,
1624 dwAddr
, Line
)) return FALSE
;
1625 *pdwDisplacement
= dwAddr
- Line
->Address
;
1629 /******************************************************************
1630 * SymGetLineFromAddrW64 (DBGHELP.@)
1633 BOOL WINAPI
SymGetLineFromAddrW64(HANDLE hProcess
, DWORD64 dwAddr
,
1634 PDWORD pdwDisplacement
, PIMAGEHLP_LINEW64 Line
)
1636 IMAGEHLP_LINE64 il64
;
1638 il64
.SizeOfStruct
= sizeof(il64
);
1639 if (!SymGetLineFromAddr64(hProcess
, dwAddr
, pdwDisplacement
, &il64
))
1641 copy_line_W64_from_64(process_find_by_handle(hProcess
), Line
, &il64
);
1645 /******************************************************************
1646 * SymGetLinePrev64 (DBGHELP.@)
1649 BOOL WINAPI
SymGetLinePrev64(HANDLE hProcess
, PIMAGEHLP_LINE64 Line
)
1651 struct module_pair pair
;
1652 struct line_info
* li
;
1653 BOOL in_search
= FALSE
;
1655 TRACE("(%p %p)\n", hProcess
, Line
);
1657 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1659 pair
.pcs
= process_find_by_handle(hProcess
);
1660 if (!pair
.pcs
) return FALSE
;
1661 pair
.requested
= module_find_by_addr(pair
.pcs
, Line
->Address
, DMT_UNKNOWN
);
1662 if (!module_get_debug(&pair
)) return FALSE
;
1664 if (Line
->Key
== 0) return FALSE
;
1666 /* things are a bit complicated because when we encounter a DLIT_SOURCEFILE
1667 * element we have to go back until we find the prev one to get the real
1668 * source file name for the DLIT_OFFSET element just before
1669 * the first DLIT_SOURCEFILE
1671 while (!li
->is_first
)
1674 if (!li
->is_source_file
)
1676 Line
->LineNumber
= li
->line_number
;
1677 Line
->Address
= li
->u
.pc_offset
;
1679 if (!in_search
) return TRUE
;
1685 Line
->FileName
= (char*)source_get(pair
.effective
, li
->u
.source_file
);
1691 SetLastError(ERROR_NO_MORE_ITEMS
); /* FIXME */
1695 /******************************************************************
1696 * SymGetLinePrev (DBGHELP.@)
1699 BOOL WINAPI
SymGetLinePrev(HANDLE hProcess
, PIMAGEHLP_LINE Line
)
1701 IMAGEHLP_LINE64 line64
;
1703 line64
.SizeOfStruct
= sizeof(line64
);
1704 copy_line_64_from_32(&line64
, Line
);
1705 if (!SymGetLinePrev64(hProcess
, &line64
)) return FALSE
;
1706 copy_line_32_from_64(Line
, &line64
);
1710 BOOL
symt_get_func_line_next(const struct module
* module
, PIMAGEHLP_LINE64 line
)
1712 struct line_info
* li
;
1714 if (line
->Key
== 0) return FALSE
;
1716 while (!li
->is_last
)
1719 if (!li
->is_source_file
)
1721 line
->LineNumber
= li
->line_number
;
1722 line
->Address
= li
->u
.pc_offset
;
1726 line
->FileName
= (char*)source_get(module
, li
->u
.source_file
);
1731 /******************************************************************
1732 * SymGetLineNext64 (DBGHELP.@)
1735 BOOL WINAPI
SymGetLineNext64(HANDLE hProcess
, PIMAGEHLP_LINE64 Line
)
1737 struct module_pair pair
;
1739 TRACE("(%p %p)\n", hProcess
, Line
);
1741 if (Line
->SizeOfStruct
< sizeof(*Line
)) return FALSE
;
1742 pair
.pcs
= process_find_by_handle(hProcess
);
1743 if (!pair
.pcs
) return FALSE
;
1744 pair
.requested
= module_find_by_addr(pair
.pcs
, Line
->Address
, DMT_UNKNOWN
);
1745 if (!module_get_debug(&pair
)) return FALSE
;
1747 if (symt_get_func_line_next(pair
.effective
, Line
)) return TRUE
;
1748 SetLastError(ERROR_NO_MORE_ITEMS
); /* FIXME */
1752 /******************************************************************
1753 * SymGetLineNext (DBGHELP.@)
1756 BOOL WINAPI
SymGetLineNext(HANDLE hProcess
, PIMAGEHLP_LINE Line
)
1758 IMAGEHLP_LINE64 line64
;
1760 line64
.SizeOfStruct
= sizeof(line64
);
1761 copy_line_64_from_32(&line64
, Line
);
1762 if (!SymGetLineNext64(hProcess
, &line64
)) return FALSE
;
1763 copy_line_32_from_64(Line
, &line64
);
1767 /***********************************************************************
1768 * SymUnDName (DBGHELP.@)
1770 BOOL WINAPI
SymUnDName(PIMAGEHLP_SYMBOL sym
, PSTR UnDecName
, DWORD UnDecNameLength
)
1772 return UnDecorateSymbolName(sym
->Name
, UnDecName
, UnDecNameLength
,
1773 UNDNAME_COMPLETE
) != 0;
1776 /***********************************************************************
1777 * SymUnDName64 (DBGHELP.@)
1779 BOOL WINAPI
SymUnDName64(PIMAGEHLP_SYMBOL64 sym
, PSTR UnDecName
, DWORD UnDecNameLength
)
1781 return UnDecorateSymbolName(sym
->Name
, UnDecName
, UnDecNameLength
,
1782 UNDNAME_COMPLETE
) != 0;
1785 static void * CDECL
und_alloc(size_t len
) { return HeapAlloc(GetProcessHeap(), 0, len
); }
1786 static void CDECL
und_free (void* ptr
) { HeapFree(GetProcessHeap(), 0, ptr
); }
1788 static char *und_name(char *buffer
, const char *mangled
, int buflen
, unsigned short flags
)
1790 /* undocumented from msvcrt */
1791 static HANDLE hMsvcrt
;
1792 static char* (CDECL
*p_undname
)(char*, const char*, int, void* (CDECL
*)(size_t), void (CDECL
*)(void*), unsigned short);
1793 static const WCHAR szMsvcrt
[] = {'m','s','v','c','r','t','.','d','l','l',0};
1797 if (!hMsvcrt
) hMsvcrt
= LoadLibraryW(szMsvcrt
);
1798 if (hMsvcrt
) p_undname
= (void*)GetProcAddress(hMsvcrt
, "__unDName");
1799 if (!p_undname
) return NULL
;
1802 return p_undname(buffer
, mangled
, buflen
, und_alloc
, und_free
, flags
);
1805 /***********************************************************************
1806 * UnDecorateSymbolName (DBGHELP.@)
1808 DWORD WINAPI
UnDecorateSymbolName(const char *decorated_name
, char *undecorated_name
,
1809 DWORD undecorated_length
, DWORD flags
)
1811 TRACE("(%s, %p, %d, 0x%08x)\n",
1812 debugstr_a(decorated_name
), undecorated_name
, undecorated_length
, flags
);
1814 if (!undecorated_name
|| !undecorated_length
)
1816 if (!und_name(undecorated_name
, decorated_name
, undecorated_length
, flags
))
1818 return strlen(undecorated_name
);
1821 /***********************************************************************
1822 * UnDecorateSymbolNameW (DBGHELP.@)
1824 DWORD WINAPI
UnDecorateSymbolNameW(const WCHAR
*decorated_name
, WCHAR
*undecorated_name
,
1825 DWORD undecorated_length
, DWORD flags
)
1830 TRACE("(%s, %p, %d, 0x%08x)\n",
1831 debugstr_w(decorated_name
), undecorated_name
, undecorated_length
, flags
);
1833 if (!undecorated_name
|| !undecorated_length
)
1836 len
= WideCharToMultiByte(CP_ACP
, 0, decorated_name
, -1, NULL
, 0, NULL
, NULL
);
1837 if ((buf
= HeapAlloc(GetProcessHeap(), 0, len
)))
1839 WideCharToMultiByte(CP_ACP
, 0, decorated_name
, -1, buf
, len
, NULL
, NULL
);
1840 if ((ptr
= und_name(NULL
, buf
, 0, flags
)))
1842 MultiByteToWideChar(CP_ACP
, 0, ptr
, -1, undecorated_name
, undecorated_length
);
1843 undecorated_name
[undecorated_length
- 1] = 0;
1844 ret
= lstrlenW(undecorated_name
);
1847 HeapFree(GetProcessHeap(), 0, buf
);
1853 #define WILDCHAR(x) (-(x))
1855 static int re_fetch_char(const WCHAR
** re
)
1859 case '\\': (*re
)++; return *(*re
)++;
1860 case '*': case '[': case '?': case '+': case '#': case ']': return WILDCHAR(*(*re
)++);
1861 default: return *(*re
)++;
1865 static inline int re_match_char(WCHAR ch1
, WCHAR ch2
, BOOL _case
)
1867 return _case
? ch1
- ch2
: towupper(ch1
) - towupper(ch2
);
1870 static const WCHAR
* re_match_one(const WCHAR
* string
, const WCHAR
* elt
, BOOL _case
)
1875 switch (ch1
= re_fetch_char(&elt
))
1878 return (ch1
>= 0 && re_match_char(*string
, ch1
, _case
) == 0) ? ++string
: NULL
;
1879 case WILDCHAR('?'): return *string
? ++string
: NULL
;
1880 case WILDCHAR('*'): assert(0);
1881 case WILDCHAR('['): break;
1886 ch1
= re_fetch_char(&elt
);
1887 if (ch1
== WILDCHAR(']')) return NULL
;
1888 if (state
== 1 && ch1
== '-') state
= 2;
1891 if (re_match_char(*string
, ch1
, _case
) == 0) return ++string
;
1902 if (prev
>= 0 && ch1
>= 0 && re_match_char(prev
, *string
, _case
) <= 0 &&
1903 re_match_char(*string
, ch1
, _case
) <= 0)
1912 /******************************************************************
1915 * match a substring of *pstring according to *pre regular expression
1916 * pstring and pre are only updated in case of successful match
1918 static BOOL
re_match_multi(const WCHAR
** pstring
, const WCHAR
** pre
, BOOL _case
)
1920 const WCHAR
* re_end
= *pre
;
1921 const WCHAR
* string_end
= *pstring
;
1922 const WCHAR
* re_beg
;
1923 const WCHAR
* string_beg
;
1927 while (*re_end
&& *string_end
)
1929 string_beg
= string_end
;
1931 switch (ch
= re_fetch_char(&re_end
))
1933 case WILDCHAR(']'): case WILDCHAR('+'): case WILDCHAR('#'): return FALSE
;
1935 /* transform '*' into '?#' */
1936 {static const WCHAR qmW
[] = {'?',0}; re_beg
= qmW
;}
1941 if (!(ch
= re_fetch_char(&re_end
))) return FALSE
;
1942 } while (ch
!= WILDCHAR(']'));
1952 if (!(next
= re_match_one(string_end
, re_beg
, _case
))) return FALSE
;
1958 while ((next
= re_match_one(string_end
, re_beg
, _case
))) string_end
= next
;
1959 for ( ; string_end
>= string_beg
; string_end
--)
1961 if (re_match_multi(&string_end
, &re_end
, _case
)) goto found
;
1965 if (!(next
= re_match_one(string_end
, re_beg
, _case
))) return FALSE
;
1970 if (*re_end
|| *string_end
) return FALSE
;
1974 *pstring
= string_end
;
1978 /******************************************************************
1979 * SymMatchStringA (DBGHELP.@)
1982 BOOL WINAPI
SymMatchStringA(PCSTR string
, PCSTR re
, BOOL _case
)
1991 SetLastError(ERROR_INVALID_HANDLE
);
1994 TRACE("%s %s %c\n", string
, re
, _case
? 'Y' : 'N');
1996 sz
= MultiByteToWideChar(CP_ACP
, 0, string
, -1, NULL
, 0);
1997 if ((strW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
1998 MultiByteToWideChar(CP_ACP
, 0, string
, -1, strW
, sz
);
1999 sz
= MultiByteToWideChar(CP_ACP
, 0, re
, -1, NULL
, 0);
2000 if ((reW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2001 MultiByteToWideChar(CP_ACP
, 0, re
, -1, reW
, sz
);
2004 ret
= SymMatchStringW(strW
, reW
, _case
);
2005 HeapFree(GetProcessHeap(), 0, strW
);
2006 HeapFree(GetProcessHeap(), 0, reW
);
2010 /******************************************************************
2011 * SymMatchStringW (DBGHELP.@)
2014 BOOL WINAPI
SymMatchStringW(PCWSTR string
, PCWSTR re
, BOOL _case
)
2016 TRACE("%s %s %c\n", debugstr_w(string
), debugstr_w(re
), _case
? 'Y' : 'N');
2020 SetLastError(ERROR_INVALID_HANDLE
);
2023 return re_match_multi(&string
, &re
, _case
);
2026 static inline BOOL
doSymSearch(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
2027 DWORD SymTag
, PCWSTR Mask
, DWORD64 Address
,
2028 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
2029 PVOID UserContext
, DWORD Options
)
2033 if (Options
!= SYMSEARCH_GLOBALSONLY
)
2035 FIXME("Unsupported searching with options (%x)\n", Options
);
2036 SetLastError(ERROR_INVALID_PARAMETER
);
2040 se
.cb
= EnumSymbolsCallback
;
2041 se
.user
= UserContext
;
2045 se
.sym_info
= (PSYMBOL_INFO
)se
.buffer
;
2047 return sym_enum(hProcess
, BaseOfDll
, Mask
, &se
);
2050 /******************************************************************
2051 * SymSearch (DBGHELP.@)
2053 BOOL WINAPI
SymSearch(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
2054 DWORD SymTag
, PCSTR Mask
, DWORD64 Address
,
2055 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback
,
2056 PVOID UserContext
, DWORD Options
)
2058 LPWSTR maskW
= NULL
;
2061 TRACE("(%p %s %u %u %s %s %p %p %x)\n",
2062 hProcess
, wine_dbgstr_longlong(BaseOfDll
), Index
, SymTag
, Mask
,
2063 wine_dbgstr_longlong(Address
), EnumSymbolsCallback
,
2064 UserContext
, Options
);
2068 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, NULL
, 0);
2070 if (!(maskW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2072 MultiByteToWideChar(CP_ACP
, 0, Mask
, -1, maskW
, sz
);
2074 ret
= doSymSearch(hProcess
, BaseOfDll
, Index
, SymTag
, maskW
, Address
,
2075 EnumSymbolsCallback
, UserContext
, Options
);
2076 HeapFree(GetProcessHeap(), 0, maskW
);
2080 /******************************************************************
2081 * SymSearchW (DBGHELP.@)
2083 BOOL WINAPI
SymSearchW(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD Index
,
2084 DWORD SymTag
, PCWSTR Mask
, DWORD64 Address
,
2085 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback
,
2086 PVOID UserContext
, DWORD Options
)
2088 struct sym_enumW sew
;
2090 TRACE("(%p %s %u %u %s %s %p %p %x)\n",
2091 hProcess
, wine_dbgstr_longlong(BaseOfDll
), Index
, SymTag
, debugstr_w(Mask
),
2092 wine_dbgstr_longlong(Address
), EnumSymbolsCallback
,
2093 UserContext
, Options
);
2095 sew
.ctx
= UserContext
;
2096 sew
.cb
= EnumSymbolsCallback
;
2097 sew
.sym_info
= (PSYMBOL_INFOW
)sew
.buffer
;
2099 return doSymSearch(hProcess
, BaseOfDll
, Index
, SymTag
, Mask
, Address
,
2100 sym_enumW
, &sew
, Options
);
2103 /******************************************************************
2104 * SymAddSymbol (DBGHELP.@)
2107 BOOL WINAPI
SymAddSymbol(HANDLE hProcess
, ULONG64 BaseOfDll
, PCSTR name
,
2108 DWORD64 addr
, DWORD size
, DWORD flags
)
2110 WCHAR nameW
[MAX_SYM_NAME
];
2112 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, ARRAY_SIZE(nameW
));
2113 return SymAddSymbolW(hProcess
, BaseOfDll
, nameW
, addr
, size
, flags
);
2116 /******************************************************************
2117 * SymAddSymbolW (DBGHELP.@)
2120 BOOL WINAPI
SymAddSymbolW(HANDLE hProcess
, ULONG64 BaseOfDll
, PCWSTR name
,
2121 DWORD64 addr
, DWORD size
, DWORD flags
)
2123 struct module_pair pair
;
2125 TRACE("(%p %s %s %u)\n", hProcess
, wine_dbgstr_w(name
), wine_dbgstr_longlong(addr
), size
);
2127 pair
.pcs
= process_find_by_handle(hProcess
);
2128 if (!pair
.pcs
) return FALSE
;
2129 pair
.requested
= module_find_by_addr(pair
.pcs
, BaseOfDll
, DMT_UNKNOWN
);
2130 if (!module_get_debug(&pair
)) return FALSE
;
2132 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2136 /******************************************************************
2137 * SymSetScopeFromAddr (DBGHELP.@)
2139 BOOL WINAPI
SymSetScopeFromAddr(HANDLE hProcess
, ULONG64 addr
)
2141 struct process
* pcs
;
2143 FIXME("(%p %s): stub\n", hProcess
, wine_dbgstr_longlong(addr
));
2145 if (!(pcs
= process_find_by_handle(hProcess
))) return FALSE
;
2149 /******************************************************************
2150 * SymEnumLines (DBGHELP.@)
2153 BOOL WINAPI
SymEnumLines(HANDLE hProcess
, ULONG64 base
, PCSTR compiland
,
2154 PCSTR srcfile
, PSYM_ENUMLINES_CALLBACK cb
, PVOID user
)
2156 struct module_pair pair
;
2157 struct hash_table_iter hti
;
2158 struct symt_ht
* sym
;
2160 struct line_info
* dli
;
2165 if (!cb
) return FALSE
;
2166 if (!(dbghelp_options
& SYMOPT_LOAD_LINES
)) return TRUE
;
2168 pair
.pcs
= process_find_by_handle(hProcess
);
2169 if (!pair
.pcs
) return FALSE
;
2170 if (compiland
) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland
);
2171 pair
.requested
= module_find_by_addr(pair
.pcs
, base
, DMT_UNKNOWN
);
2172 if (!module_get_debug(&pair
)) return FALSE
;
2173 if (!(srcmask
= file_regex(srcfile
))) return FALSE
;
2175 sci
.SizeOfStruct
= sizeof(sci
);
2178 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, NULL
);
2179 while ((ptr
= hash_table_iter_up(&hti
)))
2183 sym
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
2184 if (sym
->symt
.tag
!= SymTagFunction
) continue;
2186 sci
.FileName
[0] = '\0';
2187 for (i
=0; i
<vector_length(&((struct symt_function
*)sym
)->vlines
); i
++)
2189 dli
= vector_at(&((struct symt_function
*)sym
)->vlines
, i
);
2190 if (dli
->is_source_file
)
2192 file
= source_get(pair
.effective
, dli
->u
.source_file
);
2193 if (!file
) sci
.FileName
[0] = '\0';
2196 DWORD sz
= MultiByteToWideChar(CP_ACP
, 0, file
, -1, NULL
, 0);
2199 if ((fileW
= HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
))))
2200 MultiByteToWideChar(CP_ACP
, 0, file
, -1, fileW
, sz
);
2201 if (SymMatchStringW(fileW
, srcmask
, FALSE
))
2202 strcpy(sci
.FileName
, file
);
2204 sci
.FileName
[0] = '\0';
2205 HeapFree(GetProcessHeap(), 0, fileW
);
2208 else if (sci
.FileName
[0])
2211 sci
.Obj
[0] = '\0'; /* FIXME */
2212 sci
.LineNumber
= dli
->line_number
;
2213 sci
.Address
= dli
->u
.pc_offset
;
2214 if (!cb(&sci
, user
)) break;
2218 HeapFree(GetProcessHeap(), 0, srcmask
);
2222 BOOL WINAPI
SymGetLineFromName(HANDLE hProcess
, PCSTR ModuleName
, PCSTR FileName
,
2223 DWORD dwLineNumber
, PLONG plDisplacement
, PIMAGEHLP_LINE Line
)
2225 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, ModuleName
, FileName
,
2226 dwLineNumber
, plDisplacement
, Line
);
2230 BOOL WINAPI
SymGetLineFromName64(HANDLE hProcess
, PCSTR ModuleName
, PCSTR FileName
,
2231 DWORD dwLineNumber
, PLONG lpDisplacement
, PIMAGEHLP_LINE64 Line
)
2233 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, ModuleName
, FileName
,
2234 dwLineNumber
, lpDisplacement
, Line
);
2238 BOOL WINAPI
SymGetLineFromNameW64(HANDLE hProcess
, PCWSTR ModuleName
, PCWSTR FileName
,
2239 DWORD dwLineNumber
, PLONG plDisplacement
, PIMAGEHLP_LINEW64 Line
)
2241 FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess
, debugstr_w(ModuleName
), debugstr_w(FileName
),
2242 dwLineNumber
, plDisplacement
, Line
);
2246 /******************************************************************
2247 * SymFromIndex (DBGHELP.@)
2250 BOOL WINAPI
SymFromIndex(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD index
, PSYMBOL_INFO symbol
)
2252 FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
2253 hProcess
, wine_dbgstr_longlong(BaseOfDll
), index
, symbol
);
2258 /******************************************************************
2259 * SymFromIndexW (DBGHELP.@)
2262 BOOL WINAPI
SymFromIndexW(HANDLE hProcess
, ULONG64 BaseOfDll
, DWORD index
, PSYMBOL_INFOW symbol
)
2264 FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
2265 hProcess
, wine_dbgstr_longlong(BaseOfDll
), index
, symbol
);
2270 /******************************************************************
2271 * SymSetHomeDirectory (DBGHELP.@)
2274 PCHAR WINAPI
SymSetHomeDirectory(HANDLE hProcess
, PCSTR dir
)
2276 FIXME("(%p, %s): stub\n", hProcess
, dir
);
2281 /******************************************************************
2282 * SymSetHomeDirectoryW (DBGHELP.@)
2285 PWSTR WINAPI
SymSetHomeDirectoryW(HANDLE hProcess
, PCWSTR dir
)
2287 FIXME("(%p, %s): stub\n", hProcess
, debugstr_w(dir
));