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
23 #define NONAMELESSSTRUCT
31 #include <sys/types.h>
37 #include "wine/debug.h"
38 #include "dbghelp_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
42 WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt);
44 inline static int cmp_addr(ULONG64 a1, ULONG64 a2)
46 if (a1 > a2) return 1;
47 if (a1 < a2) return -1;
51 inline static int cmp_sorttab_addr(const struct module* module, int idx, ULONG64 addr)
55 symt_get_info(&module->addr_sorttab[idx]->symt, TI_GET_ADDRESS, &ref);
56 return cmp_addr(ref, addr);
59 int symt_cmp_addr(const void* p1, const void* p2)
61 const struct symt* sym1 = *(const struct symt* const *)p1;
62 const struct symt* sym2 = *(const struct symt* const *)p2;
65 symt_get_info(sym1, TI_GET_ADDRESS, &a1);
66 symt_get_info(sym2, TI_GET_ADDRESS, &a2);
67 return cmp_addr(a1, a2);
70 static inline void re_append(char** mask, unsigned* len, char ch)
72 *mask = HeapReAlloc(GetProcessHeap(), 0, *mask, ++(*len));
73 (*mask)[*len - 2] = ch;
76 /* transforms a dbghelp's regular expression into a POSIX one
77 * Here are the valid dbghelp reg ex characters:
78 * * 0 or more characters
79 * ? a single character
81 * # 0 or more of preceding char
82 * + 1 or more of preceding char
83 * escapes \ on #, ?, [, ], *, +. don't work on -
85 static void compile_regex(const char* str, int numchar, regex_t* re, BOOL _case)
87 char* mask = HeapAlloc(GetProcessHeap(), 0, 1);
89 BOOL in_escape = FALSE;
90 unsigned flags = REG_NOSUB;
92 re_append(&mask, &len, '^');
94 while (*str && numchar--)
96 /* FIXME: this shouldn't be valid on '-' */
99 re_append(&mask, &len, '\\');
100 re_append(&mask, &len, *str);
105 case '\\': in_escape = TRUE; break;
106 case '*': re_append(&mask, &len, '.'); re_append(&mask, &len, '*'); break;
107 case '?': re_append(&mask, &len, '.'); break;
108 case '#': re_append(&mask, &len, '*'); break;
109 /* escape some valid characters in dbghelp reg exp:s */
110 case '$': re_append(&mask, &len, '\\'); re_append(&mask, &len, '$'); break;
111 /* +, [, ], - are the same in dbghelp & POSIX, use them as any other char */
112 default: re_append(&mask, &len, *str); break;
118 re_append(&mask, &len, '\\');
119 re_append(&mask, &len, '\\');
121 re_append(&mask, &len, '$');
122 mask[len - 1] = '\0';
123 if (_case) flags |= REG_ICASE;
124 if (regcomp(re, mask, flags)) FIXME("Couldn't compile %s\n", mask);
125 HeapFree(GetProcessHeap(), 0, mask);
128 struct symt_compiland* symt_new_compiland(struct module* module, unsigned src_idx)
130 struct symt_compiland* sym;
132 TRACE_(dbghelp_symt)("Adding compiland symbol %s:%s\n",
133 module->module.ModuleName, source_get(module, src_idx));
134 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
136 sym->symt.tag = SymTagCompiland;
137 sym->source = src_idx;
138 vector_init(&sym->vchildren, sizeof(struct symt*), 32);
143 struct symt_public* symt_new_public(struct module* module,
144 struct symt_compiland* compiland,
146 unsigned long address, unsigned size,
147 BOOL in_code, BOOL is_func)
149 struct symt_public* sym;
152 TRACE_(dbghelp_symt)("Adding public symbol %s:%s @%lx\n",
153 module->module.ModuleName, name, address);
154 if ((dbghelp_options & SYMOPT_AUTO_PUBLICS) &&
155 symt_find_nearest(module, address) != -1)
157 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
159 sym->symt.tag = SymTagPublicSymbol;
160 sym->hash_elt.name = pool_strdup(&module->pool, name);
161 hash_table_add(&module->ht_symbols, &sym->hash_elt);
162 module->sortlist_valid = FALSE;
163 sym->container = compiland ? &compiland->symt : NULL;
164 sym->address = address;
166 sym->in_code = in_code;
167 sym->is_function = is_func;
170 p = vector_add(&compiland->vchildren, &module->pool);
177 struct symt_data* symt_new_global_variable(struct module* module,
178 struct symt_compiland* compiland,
179 const char* name, unsigned is_static,
180 unsigned long addr, unsigned long size,
183 struct symt_data* sym;
187 TRACE_(dbghelp_symt)("Adding global symbol %s:%s @%lx %p\n",
188 module->module.ModuleName, name, addr, type);
189 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
191 sym->symt.tag = SymTagData;
192 sym->hash_elt.name = pool_strdup(&module->pool, name);
193 hash_table_add(&module->ht_symbols, &sym->hash_elt);
194 module->sortlist_valid = FALSE;
195 sym->kind = is_static ? DataIsFileStatic : DataIsGlobal;
196 sym->container = compiland ? &compiland->symt : NULL;
198 sym->u.address = addr;
199 if (type && size && symt_get_info(type, TI_GET_LENGTH, &tsz))
202 FIXME("Size mismatch for %s.%s between type (%s) and src (%lu)\n",
203 module->module.ModuleName, name,
204 wine_dbgstr_longlong(tsz), size);
208 p = vector_add(&compiland->vchildren, &module->pool);
215 struct symt_function* symt_new_function(struct module* module,
216 struct symt_compiland* compiland,
218 unsigned long addr, unsigned long size,
219 struct symt* sig_type)
221 struct symt_function* sym;
224 TRACE_(dbghelp_symt)("Adding global function %s:%s @%lx-%lx\n",
225 module->module.ModuleName, name, addr, addr + size - 1);
227 assert(!sig_type || sig_type->tag == SymTagFunctionType);
228 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
230 sym->symt.tag = SymTagFunction;
231 sym->hash_elt.name = pool_strdup(&module->pool, name);
232 hash_table_add(&module->ht_symbols, &sym->hash_elt);
233 module->sortlist_valid = FALSE;
234 sym->container = &compiland->symt;
236 sym->type = sig_type;
238 vector_init(&sym->vlines, sizeof(struct line_info), 64);
239 vector_init(&sym->vchildren, sizeof(struct symt*), 8);
242 p = vector_add(&compiland->vchildren, &module->pool);
249 void symt_add_func_line(struct module* module, struct symt_function* func,
250 unsigned source_idx, int line_num, unsigned long offset)
252 struct line_info* dli;
253 BOOL last_matches = FALSE;
255 if (func == NULL || !(dbghelp_options & SYMOPT_LOAD_LINES)) return;
257 TRACE_(dbghelp_symt)("(%p)%s:%lx %s:%u\n",
258 func, func->hash_elt.name, offset,
259 source_get(module, source_idx), line_num);
261 assert(func->symt.tag == SymTagFunction);
264 while ((dli = vector_iter_down(&func->vlines, dli)))
266 if (dli->is_source_file)
268 last_matches = (source_idx == dli->u.source_file);
275 /* we shouldn't have line changes on first line of function */
276 dli = vector_add(&func->vlines, &module->pool);
277 dli->is_source_file = 1;
278 dli->is_first = dli->is_last = 0;
279 dli->line_number = 0;
280 dli->u.source_file = source_idx;
282 dli = vector_add(&func->vlines, &module->pool);
283 dli->is_source_file = 0;
284 dli->is_first = dli->is_last = 0;
285 dli->line_number = line_num;
286 dli->u.pc_offset = func->address + offset;
289 /******************************************************************
290 * symt_add_func_local
292 * Adds a new local/parameter to a given function:
293 * In any cases, dt tells whether it's a local variable or a parameter
294 * If regno it's not 0:
295 * - then variable is stored in a register
296 * - otherwise, value is referenced by register + offset
297 * Otherwise, the variable is stored on the stack:
298 * - offset is then the offset from the frame register
300 struct symt_data* symt_add_func_local(struct module* module,
301 struct symt_function* func,
303 int regno, BOOL regrel, long offset,
304 struct symt_block* block,
305 struct symt* type, const char* name)
307 struct symt_data* locsym;
310 TRACE_(dbghelp_symt)("Adding local symbol (%s:%s): %s %p\n",
311 module->module.ModuleName, func->hash_elt.name,
315 assert(func->symt.tag == SymTagFunction);
316 assert(dt == DataIsParam || dt == DataIsLocal);
318 locsym = pool_alloc(&module->pool, sizeof(*locsym));
319 locsym->symt.tag = SymTagData;
320 locsym->hash_elt.name = pool_strdup(&module->pool, name);
321 locsym->hash_elt.next = NULL;
323 locsym->container = &block->symt;
325 locsym->u.s.reg_id = regno;
326 locsym->u.s.reg_rel = regrel ? TRUE : FALSE;
327 locsym->u.s.offset = offset * 8;
328 locsym->u.s.length = 0;
330 p = vector_add(&block->vchildren, &module->pool);
332 p = vector_add(&func->vchildren, &module->pool);
338 struct symt_block* symt_open_func_block(struct module* module,
339 struct symt_function* func,
340 struct symt_block* parent_block,
341 unsigned pc, unsigned len)
343 struct symt_block* block;
347 assert(func->symt.tag == SymTagFunction);
349 assert(!parent_block || parent_block->symt.tag == SymTagBlock);
350 block = pool_alloc(&module->pool, sizeof(*block));
351 block->symt.tag = SymTagBlock;
352 block->address = func->address + pc;
354 block->container = parent_block ? &parent_block->symt : &func->symt;
355 vector_init(&block->vchildren, sizeof(struct symt*), 4);
357 p = vector_add(&parent_block->vchildren, &module->pool);
359 p = vector_add(&func->vchildren, &module->pool);
365 struct symt_block* symt_close_func_block(struct module* module,
366 struct symt_function* func,
367 struct symt_block* block, unsigned pc)
370 assert(func->symt.tag == SymTagFunction);
372 if (pc) block->size = func->address + pc - block->address;
373 return (block->container->tag == SymTagBlock) ?
374 GET_ENTRY(block->container, struct symt_block, symt) : NULL;
377 struct symt_function_point* symt_add_function_point(struct module* module,
378 struct symt_function* func,
379 enum SymTagEnum point,
380 unsigned offset, const char* name)
382 struct symt_function_point* sym;
385 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
387 sym->symt.tag = point;
389 sym->offset = offset;
390 sym->name = name ? pool_strdup(&module->pool, name) : NULL;
391 p = vector_add(&func->vchildren, &module->pool);
397 BOOL symt_normalize_function(struct module* module, struct symt_function* func)
400 struct line_info* dli;
403 /* We aren't adding any more locals or line numbers to this function.
404 * Free any spare memory that we might have allocated.
406 assert(func->symt.tag == SymTagFunction);
408 /* EPP vector_pool_normalize(&func->vlines, &module->pool); */
409 /* EPP vector_pool_normalize(&func->vchildren, &module->pool); */
411 len = vector_length(&func->vlines);
414 dli = vector_at(&func->vlines, 0); dli->is_first = 1;
415 dli = vector_at(&func->vlines, len); dli->is_last = 1;
420 struct symt_thunk* symt_new_thunk(struct module* module,
421 struct symt_compiland* compiland,
422 const char* name, THUNK_ORDINAL ord,
423 unsigned long addr, unsigned long size)
425 struct symt_thunk* sym;
427 TRACE_(dbghelp_symt)("Adding global thunk %s:%s @%lx-%lx\n",
428 module->module.ModuleName, name, addr, addr + size - 1);
430 if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
432 sym->symt.tag = SymTagThunk;
433 sym->hash_elt.name = pool_strdup(&module->pool, name);
434 hash_table_add(&module->ht_symbols, &sym->hash_elt);
435 module->sortlist_valid = FALSE;
436 sym->container = &compiland->symt;
443 p = vector_add(&compiland->vchildren, &module->pool);
450 /* expect sym_info->MaxNameLen to be set before being called */
451 static void symt_fill_sym_info(const struct module_pair* pair,
452 const struct symt* sym, SYMBOL_INFO* sym_info)
457 if (!symt_get_info(sym, TI_GET_TYPE, &sym_info->TypeIndex))
458 sym_info->TypeIndex = 0;
459 sym_info->info = (DWORD)sym;
460 sym_info->Reserved[0] = sym_info->Reserved[1] = 0;
461 if (!symt_get_info(sym, TI_GET_LENGTH, &size) &&
462 (!sym_info->TypeIndex ||
463 !symt_get_info((struct symt*)sym_info->TypeIndex, TI_GET_LENGTH, &size)))
465 sym_info->Size = (DWORD)size;
466 sym_info->ModBase = pair->requested->module.BaseOfImage;
474 const struct symt_data* data = (const struct symt_data*)sym;
478 sym_info->Flags |= SYMFLAG_PARAMETER;
481 if (!data->u.s.reg_rel)
483 sym_info->Flags |= SYMFLAG_REGISTER;
484 sym_info->Register = data->u.s.reg_id;
485 sym_info->Address = 0;
489 sym_info->Flags |= SYMFLAG_LOCAL | SYMFLAG_REGREL;
490 /* FIXME: it's i386 dependent !!! */
491 sym_info->Register = data->u.s.reg_id ? data->u.s.reg_id : CV_REG_EBP;
492 sym_info->Address = data->u.s.offset / 8;
496 case DataIsFileStatic:
497 symt_get_info(sym, TI_GET_ADDRESS, &sym_info->Address);
498 sym_info->Register = 0;
501 sym_info->Flags |= SYMFLAG_VALUEPRESENT;
502 switch (data->u.value.n1.n2.vt)
504 case VT_I4: sym_info->Value = (ULONG)data->u.value.n1.n2.n3.lVal; break;
505 case VT_I2: sym_info->Value = (ULONG)(long)data->u.value.n1.n2.n3.iVal; break;
506 case VT_I1: sym_info->Value = (ULONG)(long)data->u.value.n1.n2.n3.cVal; break;
507 case VT_UI4: sym_info->Value = (ULONG)data->u.value.n1.n2.n3.ulVal; break;
508 case VT_UI2: sym_info->Value = (ULONG)data->u.value.n1.n2.n3.uiVal; break;
509 case VT_UI1: sym_info->Value = (ULONG)data->u.value.n1.n2.n3.bVal; break;
511 FIXME("Unsupported variant type (%u)\n", data->u.value.n1.n2.vt);
515 FIXME("Unhandled kind (%u) in sym data\n", data->kind);
519 case SymTagPublicSymbol:
520 sym_info->Flags |= SYMFLAG_EXPORT;
521 symt_get_info(sym, TI_GET_ADDRESS, &sym_info->Address);
524 sym_info->Flags |= SYMFLAG_FUNCTION;
525 symt_get_info(sym, TI_GET_ADDRESS, &sym_info->Address);
528 sym_info->Flags |= SYMFLAG_THUNK;
529 symt_get_info(sym, TI_GET_ADDRESS, &sym_info->Address);
532 symt_get_info(sym, TI_GET_ADDRESS, &sym_info->Address);
533 sym_info->Register = 0;
536 sym_info->Scope = 0; /* FIXME */
537 sym_info->Tag = sym->tag;
538 name = symt_get_name(sym);
539 if (sym_info->MaxNameLen)
541 if (sym->tag != SymTagPublicSymbol || !(dbghelp_options & SYMOPT_UNDNAME) ||
542 (sym_info->NameLen = UnDecorateSymbolName(name, sym_info->Name,
543 sym_info->MaxNameLen, UNDNAME_COMPLETE) == 0))
545 sym_info->NameLen = min(strlen(name), sym_info->MaxNameLen - 1);
546 memcpy(sym_info->Name, name, sym_info->NameLen);
547 sym_info->Name[sym_info->NameLen] = '\0';
550 TRACE_(dbghelp_symt)("%p => %s %lu %s\n",
551 sym, sym_info->Name, sym_info->Size,
552 wine_dbgstr_longlong(sym_info->Address));
557 PSYM_ENUMERATESYMBOLS_CALLBACK cb;
559 SYMBOL_INFO* sym_info;
563 char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
566 static BOOL send_symbol(const struct sym_enum* se, struct module_pair* pair,
567 const struct symt* sym)
569 symt_fill_sym_info(pair, sym, se->sym_info);
570 if (se->index && se->sym_info->info != se->index) return FALSE;
571 if (se->tag && se->sym_info->Tag != se->tag) return FALSE;
572 if (se->addr && !(se->addr >= se->sym_info->Address && se->addr < se->sym_info->Address + se->sym_info->Size)) return FALSE;
573 return !se->cb(se->sym_info, se->sym_info->Size, se->user);
576 static BOOL symt_enum_module(struct module_pair* pair, regex_t* regex,
577 const struct sym_enum* se)
580 struct symt_ht* sym = NULL;
581 struct hash_table_iter hti;
583 hash_table_iter_init(&pair->effective->ht_symbols, &hti, NULL);
584 while ((ptr = hash_table_iter_up(&hti)))
586 sym = GET_ENTRY(ptr, struct symt_ht, hash_elt);
587 if (sym->hash_elt.name &&
588 regexec(regex, sym->hash_elt.name, 0, NULL, 0) == 0)
590 se->sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
591 se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
592 if (send_symbol(se, pair, &sym->symt)) return TRUE;
598 /***********************************************************************
601 * Rebuild sorted list of symbols for a module.
603 static BOOL resort_symbols(struct module* module)
608 struct hash_table_iter hti;
610 if (!module_compute_num_syms(module)) return FALSE;
612 if (module->addr_sorttab)
613 module->addr_sorttab = HeapReAlloc(GetProcessHeap(), 0,
614 module->addr_sorttab,
615 module->module.NumSyms * sizeof(struct symt_ht*));
617 module->addr_sorttab = HeapAlloc(GetProcessHeap(), 0,
618 module->module.NumSyms * sizeof(struct symt_ht*));
619 if (!module->addr_sorttab) return FALSE;
622 hash_table_iter_init(&module->ht_symbols, &hti, NULL);
623 while ((ptr = hash_table_iter_up(&hti)))
625 sym = GET_ENTRY(ptr, struct symt_ht, hash_elt);
627 module->addr_sorttab[nsym++] = sym;
630 qsort(module->addr_sorttab, nsym, sizeof(struct symt_ht*), symt_cmp_addr);
631 return module->sortlist_valid = TRUE;
634 /* assume addr is in module */
635 int symt_find_nearest(struct module* module, DWORD addr)
638 ULONG64 ref_addr, ref_size;
640 if (!module->sortlist_valid || !module->addr_sorttab)
642 if (!resort_symbols(module)) return -1;
646 * Binary search to find closest symbol.
649 high = module->module.NumSyms;
651 symt_get_info(&module->addr_sorttab[0]->symt, TI_GET_ADDRESS, &ref_addr);
652 if (addr < ref_addr) return -1;
655 symt_get_info(&module->addr_sorttab[high - 1]->symt, TI_GET_ADDRESS, &ref_addr);
656 if (!symt_get_info(&module->addr_sorttab[high - 1]->symt, TI_GET_LENGTH, &ref_size) || !ref_size)
657 ref_size = 0x1000; /* arbitrary value */
658 if (addr >= ref_addr + ref_size) return -1;
661 while (high > low + 1)
663 mid = (high + low) / 2;
664 if (cmp_sorttab_addr(module, mid, addr) < 0)
669 if (low != high && high != module->module.NumSyms &&
670 cmp_sorttab_addr(module, high, addr) <= 0)
673 /* If found symbol is a public symbol, check if there are any other entries that
674 * might also have the same address, but would get better information
676 if (module->addr_sorttab[low]->symt.tag == SymTagPublicSymbol)
678 symt_get_info(&module->addr_sorttab[low]->symt, TI_GET_ADDRESS, &ref_addr);
680 module->addr_sorttab[low - 1]->symt.tag != SymTagPublicSymbol &&
681 !cmp_sorttab_addr(module, low - 1, ref_addr))
683 else if (low < module->module.NumSyms - 1 &&
684 module->addr_sorttab[low + 1]->symt.tag != SymTagPublicSymbol &&
685 !cmp_sorttab_addr(module, low + 1, ref_addr))
688 /* finally check that we fit into the found symbol */
689 symt_get_info(&module->addr_sorttab[low]->symt, TI_GET_ADDRESS, &ref_addr);
690 if (addr < ref_addr) return -1;
691 if (!symt_get_info(&module->addr_sorttab[high - 1]->symt, TI_GET_LENGTH, &ref_size) || !ref_size)
692 ref_size = 0x1000; /* arbitrary value */
693 if (addr >= ref_addr + ref_size) return -1;
698 static BOOL symt_enum_locals_helper(struct process* pcs, struct module_pair* pair,
699 regex_t* preg, const struct sym_enum* se,
702 struct symt** plsym = NULL;
703 struct symt* lsym = NULL;
704 DWORD pc = pcs->ctx_frame.InstructionOffset;
706 while ((plsym = vector_iter_up(v, plsym)))
713 struct symt_block* block = (struct symt_block*)lsym;
714 if (pc < block->address || block->address + block->size <= pc)
716 if (!symt_enum_locals_helper(pcs, pair, preg, se, &block->vchildren))
721 if (regexec(preg, symt_get_name(lsym), 0, NULL, 0) == 0)
723 if (send_symbol(se, pair, lsym)) return FALSE;
727 case SymTagFuncDebugStart:
728 case SymTagFuncDebugEnd:
731 FIXME("Unknown type: %u (%x)\n", lsym->tag, lsym->tag);
738 static BOOL symt_enum_locals(struct process* pcs, const char* mask,
739 const struct sym_enum* se)
741 struct module_pair pair;
743 DWORD pc = pcs->ctx_frame.InstructionOffset;
746 se->sym_info->SizeOfStruct = sizeof(*se->sym_info);
747 se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
749 pair.requested = module_find_by_addr(pcs, pc, DMT_UNKNOWN);
750 if (!module_get_debug(pcs, &pair)) return FALSE;
751 if ((idx = symt_find_nearest(pair.effective, pc)) == -1) return FALSE;
753 sym = pair.effective->addr_sorttab[idx];
754 if (sym->symt.tag == SymTagFunction)
759 compile_regex(mask ? mask : "*", -1, &preg,
760 dbghelp_options & SYMOPT_CASE_INSENSITIVE);
761 ret = symt_enum_locals_helper(pcs, &pair, &preg, se,
762 &((struct symt_function*)sym)->vchildren);
767 return send_symbol(se, &pair, &sym->symt);
770 /******************************************************************
773 * Helper for transforming an ANSI symbol info into an UNICODE one.
774 * Assume that MaxNameLen is the same for both version (A & W).
776 static void copy_symbolW(SYMBOL_INFOW* siw, const SYMBOL_INFO* si)
778 siw->SizeOfStruct = si->SizeOfStruct;
779 siw->TypeIndex = si->TypeIndex;
780 siw->Reserved[0] = si->Reserved[0];
781 siw->Reserved[1] = si->Reserved[1];
782 siw->Index = si->info; /* FIXME: see dbghelp.h */
783 siw->Size = si->Size;
784 siw->ModBase = si->ModBase;
785 siw->Flags = si->Flags;
786 siw->Value = si->Value;
787 siw->Address = si->Address;
788 siw->Register = si->Register;
789 siw->Scope = si->Scope;
791 siw->NameLen = si->NameLen;
792 siw->MaxNameLen = si->MaxNameLen;
793 MultiByteToWideChar(CP_ACP, 0, si->Name, -1, siw->Name, siw->MaxNameLen);
796 /******************************************************************
799 * Core routine for most of the enumeration of symbols
801 static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
802 const struct sym_enum* se)
804 struct process* pcs = process_find_by_handle(hProcess);
805 struct module_pair pair;
807 regex_t mod_regex, sym_regex;
811 /* do local variables ? */
812 if (!Mask || !(bang = strchr(Mask, '!')))
813 return symt_enum_locals(pcs, Mask, se);
815 if (bang == Mask) return FALSE;
817 compile_regex(Mask, bang - Mask, &mod_regex, TRUE);
818 compile_regex(bang + 1, -1, &sym_regex,
819 dbghelp_options & SYMOPT_CASE_INSENSITIVE);
821 for (pair.requested = pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
823 if (pair.requested->type == DMT_PE && module_get_debug(pcs, &pair))
825 if (regexec(&mod_regex, pair.requested->module.ModuleName, 0, NULL, 0) == 0 &&
826 symt_enum_module(&pair, &sym_regex, se))
830 /* not found in PE modules, retry on the ELF ones
832 if (!pair.requested && (dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES))
834 for (pair.requested = pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
836 if (pair.requested->type == DMT_ELF &&
837 !module_get_containee(pcs, pair.requested) &&
838 module_get_debug(pcs, &pair))
840 if (regexec(&mod_regex, pair.requested->module.ModuleName, 0, NULL, 0) == 0 &&
841 symt_enum_module(&pair, &sym_regex, se))
850 pair.requested = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
851 if (!module_get_debug(pcs, &pair))
854 /* we always ignore module name from Mask when BaseOfDll is defined */
855 if (Mask && (bang = strchr(Mask, '!')))
857 if (bang == Mask) return FALSE;
861 compile_regex(Mask ? Mask : "*", -1, &sym_regex,
862 dbghelp_options & SYMOPT_CASE_INSENSITIVE);
863 symt_enum_module(&pair, &sym_regex, se);
869 /******************************************************************
870 * SymEnumSymbols (DBGHELP.@)
872 * cases BaseOfDll = 0
873 * !foo fails always (despite what MSDN states)
874 * RE1!RE2 looks up all modules matching RE1, and in all these modules, lookup RE2
875 * no ! in Mask, lookup in local Context
876 * cases BaseOfDll != 0
877 * !foo fails always (despite what MSDN states)
878 * RE1!RE2 gets RE2 from BaseOfDll (whatever RE1 is)
880 BOOL WINAPI SymEnumSymbols(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
881 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
886 TRACE("(%p %s %s %p %p)\n",
887 hProcess, wine_dbgstr_longlong(BaseOfDll), debugstr_a(Mask),
888 EnumSymbolsCallback, UserContext);
890 se.cb = EnumSymbolsCallback;
891 se.user = UserContext;
895 se.sym_info = (PSYMBOL_INFO)se.buffer;
897 return sym_enum(hProcess, BaseOfDll, Mask, &se);
902 PSYM_ENUMERATESYMBOLS_CALLBACKW cb;
904 PSYMBOL_INFOW sym_info;
905 char buffer[sizeof(SYMBOL_INFOW) + MAX_SYM_NAME];
909 static BOOL CALLBACK sym_enumW(PSYMBOL_INFO si, ULONG size, PVOID ctx)
911 struct sym_enumW* sew = ctx;
913 copy_symbolW(sew->sym_info, si);
915 return (sew->cb)(sew->sym_info, size, sew->ctx);
918 /******************************************************************
919 * SymEnumSymbolsW (DBGHELP.@)
922 BOOL WINAPI SymEnumSymbolsW(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR Mask,
923 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
926 struct sym_enumW sew;
930 sew.ctx = UserContext;
931 sew.cb = EnumSymbolsCallback;
932 sew.sym_info = (PSYMBOL_INFOW)sew.buffer;
936 unsigned len = WideCharToMultiByte(CP_ACP, 0, Mask, -1, NULL, 0, NULL, NULL);
937 maskA = HeapAlloc(GetProcessHeap(), 0, len);
938 if (!maskA) return FALSE;
939 WideCharToMultiByte(CP_ACP, 0, Mask, -1, maskA, len, NULL, NULL);
941 ret = SymEnumSymbols(hProcess, BaseOfDll, maskA, sym_enumW, &sew);
942 HeapFree(GetProcessHeap(), 0, maskA);
950 PSYM_ENUMSYMBOLS_CALLBACK cb;
953 static BOOL CALLBACK sym_enumerate_cb(PSYMBOL_INFO syminfo, ULONG size, void* ctx)
955 struct sym_enumerate* se = (struct sym_enumerate*)ctx;
956 return (se->cb)(syminfo->Name, syminfo->Address, syminfo->Size, se->ctx);
959 /***********************************************************************
960 * SymEnumerateSymbols (DBGHELP.@)
962 BOOL WINAPI SymEnumerateSymbols(HANDLE hProcess, DWORD BaseOfDll,
963 PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback,
966 struct sym_enumerate se;
968 se.ctx = UserContext;
969 se.cb = EnumSymbolsCallback;
971 return SymEnumSymbols(hProcess, BaseOfDll, NULL, sym_enumerate_cb, &se);
974 /******************************************************************
975 * SymFromAddr (DBGHELP.@)
978 BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address,
979 DWORD64* Displacement, PSYMBOL_INFO Symbol)
981 struct process* pcs = process_find_by_handle(hProcess);
982 struct module_pair pair;
986 if (!pcs) return FALSE;
987 pair.requested = module_find_by_addr(pcs, Address, DMT_UNKNOWN);
988 if (!module_get_debug(pcs, &pair)) return FALSE;
989 if ((idx = symt_find_nearest(pair.effective, Address)) == -1) return FALSE;
991 sym = pair.effective->addr_sorttab[idx];
993 symt_fill_sym_info(&pair, &sym->symt, Symbol);
994 *Displacement = Address - Symbol->Address;
998 /******************************************************************
999 * SymFromAddrW (DBGHELP.@)
1002 BOOL WINAPI SymFromAddrW(HANDLE hProcess, DWORD64 Address,
1003 DWORD64* Displacement, PSYMBOL_INFOW Symbol)
1009 len = sizeof(*si) + Symbol->MaxNameLen * sizeof(WCHAR);
1010 si = HeapAlloc(GetProcessHeap(), 0, len);
1011 if (!si) return FALSE;
1013 si->SizeOfStruct = sizeof(*si);
1014 si->MaxNameLen = Symbol->MaxNameLen;
1015 if ((ret = SymFromAddr(hProcess, Address, Displacement, si)))
1017 copy_symbolW(Symbol, si);
1019 HeapFree(GetProcessHeap(), 0, si);
1023 /******************************************************************
1024 * SymGetSymFromAddr (DBGHELP.@)
1027 BOOL WINAPI SymGetSymFromAddr(HANDLE hProcess, DWORD Address,
1028 PDWORD Displacement, PIMAGEHLP_SYMBOL Symbol)
1030 char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
1031 SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
1033 DWORD64 Displacement64;
1035 if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
1036 si->SizeOfStruct = sizeof(*si);
1037 si->MaxNameLen = MAX_SYM_NAME;
1038 if (!SymFromAddr(hProcess, Address, &Displacement64, si))
1042 *Displacement = Displacement64;
1043 Symbol->Address = si->Address;
1044 Symbol->Size = si->Size;
1045 Symbol->Flags = si->Flags;
1046 len = min(Symbol->MaxNameLength, si->MaxNameLen);
1047 lstrcpynA(Symbol->Name, si->Name, len);
1051 /******************************************************************
1052 * SymGetSymFromAddr64 (DBGHELP.@)
1055 BOOL WINAPI SymGetSymFromAddr64(HANDLE hProcess, DWORD64 Address,
1056 PDWORD64 Displacement, PIMAGEHLP_SYMBOL64 Symbol)
1058 char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
1059 SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
1061 DWORD64 Displacement64;
1063 if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
1064 si->SizeOfStruct = sizeof(*si);
1065 si->MaxNameLen = MAX_SYM_NAME;
1066 if (!SymFromAddr(hProcess, Address, &Displacement64, si))
1070 *Displacement = Displacement64;
1071 Symbol->Address = si->Address;
1072 Symbol->Size = si->Size;
1073 Symbol->Flags = si->Flags;
1074 len = min(Symbol->MaxNameLength, si->MaxNameLen);
1075 lstrcpynA(Symbol->Name, si->Name, len);
1079 static BOOL find_name(struct process* pcs, struct module* module, const char* name,
1080 SYMBOL_INFO* symbol)
1082 struct hash_table_iter hti;
1084 struct symt_ht* sym = NULL;
1085 struct module_pair pair;
1087 if (!(pair.requested = module)) return FALSE;
1088 if (!module_get_debug(pcs, &pair)) return FALSE;
1090 hash_table_iter_init(&pair.effective->ht_symbols, &hti, name);
1091 while ((ptr = hash_table_iter_up(&hti)))
1093 sym = GET_ENTRY(ptr, struct symt_ht, hash_elt);
1095 if (!strcmp(sym->hash_elt.name, name))
1097 symt_fill_sym_info(&pair, &sym->symt, symbol);
1104 /******************************************************************
1105 * SymFromName (DBGHELP.@)
1108 BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
1110 struct process* pcs = process_find_by_handle(hProcess);
1111 struct module* module;
1114 TRACE("(%p, %s, %p)\n", hProcess, Name, Symbol);
1115 if (!pcs) return FALSE;
1116 if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
1117 name = strchr(Name, '!');
1121 assert(name - Name < sizeof(tmp));
1122 memcpy(tmp, Name, name - Name);
1123 tmp[name - Name] = '\0';
1124 module = module_find_by_name(pcs, tmp, DMT_UNKNOWN);
1125 return find_name(pcs, module, name + 1, Symbol);
1127 for (module = pcs->lmodules; module; module = module->next)
1129 if (module->type == DMT_PE && find_name(pcs, module, Name, Symbol))
1132 /* not found in PE modules, retry on the ELF ones
1134 if (dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES)
1136 for (module = pcs->lmodules; module; module = module->next)
1138 if (module->type == DMT_ELF && !module_get_containee(pcs, module) &&
1139 find_name(pcs, module, Name, Symbol))
1146 /***********************************************************************
1147 * SymGetSymFromName (DBGHELP.@)
1149 BOOL WINAPI SymGetSymFromName(HANDLE hProcess, PCSTR Name, PIMAGEHLP_SYMBOL Symbol)
1151 char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
1152 SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
1155 if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
1156 si->SizeOfStruct = sizeof(*si);
1157 si->MaxNameLen = MAX_SYM_NAME;
1158 if (!SymFromName(hProcess, Name, si)) return FALSE;
1160 Symbol->Address = si->Address;
1161 Symbol->Size = si->Size;
1162 Symbol->Flags = si->Flags;
1163 len = min(Symbol->MaxNameLength, si->MaxNameLen);
1164 lstrcpynA(Symbol->Name, si->Name, len);
1168 /******************************************************************
1169 * sym_fill_func_line_info
1171 * fills information about a file
1173 BOOL symt_fill_func_line_info(struct module* module, struct symt_function* func,
1174 DWORD addr, IMAGEHLP_LINE* line)
1176 struct line_info* dli = NULL;
1179 assert(func->symt.tag == SymTagFunction);
1181 while ((dli = vector_iter_down(&func->vlines, dli)))
1183 if (!dli->is_source_file)
1185 if (found || dli->u.pc_offset > addr) continue;
1186 line->LineNumber = dli->line_number;
1187 line->Address = dli->u.pc_offset;
1194 line->FileName = (char*)source_get(module, dli->u.source_file);
1201 /***********************************************************************
1202 * SymGetSymNext (DBGHELP.@)
1204 BOOL WINAPI SymGetSymNext(HANDLE hProcess, PIMAGEHLP_SYMBOL Symbol)
1207 * get module from Symbol.Address
1208 * get index in module.addr_sorttab of Symbol.Address
1210 * if out of module bounds, move to next module in process address space
1212 FIXME("(%p, %p): stub\n", hProcess, Symbol);
1213 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1217 /***********************************************************************
1218 * SymGetSymPrev (DBGHELP.@)
1221 BOOL WINAPI SymGetSymPrev(HANDLE hProcess, PIMAGEHLP_SYMBOL Symbol)
1223 FIXME("(%p, %p): stub\n", hProcess, Symbol);
1224 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1228 /******************************************************************
1229 * SymGetLineFromAddr (DBGHELP.@)
1232 BOOL WINAPI SymGetLineFromAddr(HANDLE hProcess, DWORD dwAddr,
1233 PDWORD pdwDisplacement, PIMAGEHLP_LINE Line)
1235 struct process* pcs = process_find_by_handle(hProcess);
1236 struct module_pair pair;
1239 TRACE("%p %08lx %p %p\n", hProcess, dwAddr, pdwDisplacement, Line);
1241 if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
1243 if (!pcs) return FALSE;
1244 pair.requested = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
1245 if (!module_get_debug(pcs, &pair)) return FALSE;
1246 if ((idx = symt_find_nearest(pair.effective, dwAddr)) == -1) return FALSE;
1248 if (pair.effective->addr_sorttab[idx]->symt.tag != SymTagFunction) return FALSE;
1249 if (!symt_fill_func_line_info(pair.effective,
1250 (struct symt_function*)pair.effective->addr_sorttab[idx],
1251 dwAddr, Line)) return FALSE;
1252 *pdwDisplacement = dwAddr - Line->Address;
1256 /******************************************************************
1257 * copy_line_64_from_32 (internal)
1260 static void copy_line_64_from_32(IMAGEHLP_LINE64* l64, const IMAGEHLP_LINE* l32)
1263 l64->Key = l32->Key;
1264 l64->LineNumber = l32->LineNumber;
1265 l64->FileName = l32->FileName;
1266 l64->Address = l32->Address;
1269 /******************************************************************
1270 * copy_line_W64_from_32 (internal)
1273 static void copy_line_W64_from_32(struct process* pcs, IMAGEHLP_LINEW64* l64, const IMAGEHLP_LINE* l32)
1277 l64->Key = l32->Key;
1278 l64->LineNumber = l32->LineNumber;
1279 len = MultiByteToWideChar(CP_ACP, 0, l32->FileName, -1, NULL, 0);
1280 if ((l64->FileName = fetch_buffer(pcs, len * sizeof(WCHAR))))
1281 MultiByteToWideChar(CP_ACP, 0, l32->FileName, -1, l64->FileName, len);
1282 l64->Address = l32->Address;
1285 /******************************************************************
1286 * copy_line_32_from_64 (internal)
1289 static void copy_line_32_from_64(IMAGEHLP_LINE* l32, const IMAGEHLP_LINE64* l64)
1292 l32->Key = l64->Key;
1293 l32->LineNumber = l64->LineNumber;
1294 l32->FileName = l64->FileName;
1295 l32->Address = l64->Address;
1298 /******************************************************************
1299 * SymGetLineFromAddr64 (DBGHELP.@)
1302 BOOL WINAPI SymGetLineFromAddr64(HANDLE hProcess, DWORD64 dwAddr,
1303 PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line)
1305 IMAGEHLP_LINE line32;
1307 if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
1308 if (!validate_addr64(dwAddr)) return FALSE;
1309 line32.SizeOfStruct = sizeof(line32);
1310 if (!SymGetLineFromAddr(hProcess, (DWORD)dwAddr, pdwDisplacement, &line32))
1312 copy_line_64_from_32(Line, &line32);
1316 /******************************************************************
1317 * SymGetLineFromAddrW64 (DBGHELP.@)
1320 BOOL WINAPI SymGetLineFromAddrW64(HANDLE hProcess, DWORD64 dwAddr,
1321 PDWORD pdwDisplacement, PIMAGEHLP_LINEW64 Line)
1323 struct process* pcs = process_find_by_handle(hProcess);
1324 IMAGEHLP_LINE line32;
1326 if (!pcs) return FALSE;
1327 if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
1328 if (!validate_addr64(dwAddr)) return FALSE;
1329 line32.SizeOfStruct = sizeof(line32);
1330 if (!SymGetLineFromAddr(hProcess, (DWORD)dwAddr, pdwDisplacement, &line32))
1332 copy_line_W64_from_32(pcs, Line, &line32);
1336 /******************************************************************
1337 * SymGetLinePrev (DBGHELP.@)
1340 BOOL WINAPI SymGetLinePrev(HANDLE hProcess, PIMAGEHLP_LINE Line)
1342 struct process* pcs = process_find_by_handle(hProcess);
1343 struct module_pair pair;
1344 struct line_info* li;
1345 BOOL in_search = FALSE;
1347 TRACE("(%p %p)\n", hProcess, Line);
1349 if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
1351 if (!pcs) return FALSE;
1352 pair.requested = module_find_by_addr(pcs, Line->Address, DMT_UNKNOWN);
1353 if (!module_get_debug(pcs, &pair)) return FALSE;
1355 if (Line->Key == 0) return FALSE;
1356 li = (struct line_info*)Line->Key;
1357 /* things are a bit complicated because when we encounter a DLIT_SOURCEFILE
1358 * element we have to go back until we find the prev one to get the real
1359 * source file name for the DLIT_OFFSET element just before
1360 * the first DLIT_SOURCEFILE
1362 while (!li->is_first)
1365 if (!li->is_source_file)
1367 Line->LineNumber = li->line_number;
1368 Line->Address = li->u.pc_offset;
1370 if (!in_search) return TRUE;
1376 Line->FileName = (char*)source_get(pair.effective, li->u.source_file);
1382 SetLastError(ERROR_NO_MORE_ITEMS); /* FIXME */
1386 /******************************************************************
1387 * SymGetLinePrev64 (DBGHELP.@)
1390 BOOL WINAPI SymGetLinePrev64(HANDLE hProcess, PIMAGEHLP_LINE64 Line)
1392 IMAGEHLP_LINE line32;
1394 line32.SizeOfStruct = sizeof(line32);
1395 copy_line_32_from_64(&line32, Line);
1396 if (!SymGetLinePrev(hProcess, &line32)) return FALSE;
1397 copy_line_64_from_32(Line, &line32);
1401 BOOL symt_get_func_line_next(struct module* module, PIMAGEHLP_LINE line)
1403 struct line_info* li;
1405 if (line->Key == 0) return FALSE;
1406 li = (struct line_info*)line->Key;
1407 while (!li->is_last)
1410 if (!li->is_source_file)
1412 line->LineNumber = li->line_number;
1413 line->Address = li->u.pc_offset;
1417 line->FileName = (char*)source_get(module, li->u.source_file);
1422 /******************************************************************
1423 * SymGetLineNext (DBGHELP.@)
1426 BOOL WINAPI SymGetLineNext(HANDLE hProcess, PIMAGEHLP_LINE Line)
1428 struct process* pcs = process_find_by_handle(hProcess);
1429 struct module_pair pair;
1431 TRACE("(%p %p)\n", hProcess, Line);
1433 if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
1434 if (!pcs) return FALSE;
1435 pair.requested = module_find_by_addr(pcs, Line->Address, DMT_UNKNOWN);
1436 if (!module_get_debug(pcs, &pair)) return FALSE;
1438 if (symt_get_func_line_next(pair.effective, Line)) return TRUE;
1439 SetLastError(ERROR_NO_MORE_ITEMS); /* FIXME */
1443 /******************************************************************
1444 * SymGetLineNext64 (DBGHELP.@)
1447 BOOL WINAPI SymGetLineNext64(HANDLE hProcess, PIMAGEHLP_LINE64 Line)
1449 IMAGEHLP_LINE line32;
1451 line32.SizeOfStruct = sizeof(line32);
1452 copy_line_32_from_64(&line32, Line);
1453 if (!SymGetLineNext(hProcess, &line32)) return FALSE;
1454 copy_line_64_from_32(Line, &line32);
1458 /***********************************************************************
1459 * SymFunctionTableAccess (DBGHELP.@)
1461 PVOID WINAPI SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
1463 WARN("(%p, 0x%08lx): stub\n", hProcess, AddrBase);
1467 /***********************************************************************
1468 * SymFunctionTableAccess64 (DBGHELP.@)
1470 PVOID WINAPI SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase)
1472 WARN("(%p, %s): stub\n", hProcess, wine_dbgstr_longlong(AddrBase));
1476 /***********************************************************************
1477 * SymUnDName (DBGHELP.@)
1479 BOOL WINAPI SymUnDName(PIMAGEHLP_SYMBOL sym, LPSTR UnDecName, DWORD UnDecNameLength)
1481 TRACE("(%p %s %lu)\n", sym, UnDecName, UnDecNameLength);
1482 return UnDecorateSymbolName(sym->Name, UnDecName, UnDecNameLength,
1483 UNDNAME_COMPLETE) != 0;
1486 static void* und_alloc(size_t len) { return HeapAlloc(GetProcessHeap(), 0, len); }
1487 static void und_free (void* ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
1489 /***********************************************************************
1490 * UnDecorateSymbolName (DBGHELP.@)
1492 DWORD WINAPI UnDecorateSymbolName(LPCSTR DecoratedName, LPSTR UnDecoratedName,
1493 DWORD UndecoratedLength, DWORD Flags)
1495 /* undocumented from msvcrt */
1496 static char* (*p_undname)(char*, const char*, int, void* (*)(size_t), void (*)(void*), unsigned short);
1497 static const WCHAR szMsvcrt[] = {'m','s','v','c','r','t','.','d','l','l',0};
1499 TRACE("(%s, %p, %ld, 0x%08lx)\n",
1500 debugstr_a(DecoratedName), UnDecoratedName, UndecoratedLength, Flags);
1504 if (!hMsvcrt) hMsvcrt = LoadLibraryW(szMsvcrt);
1505 if (hMsvcrt) p_undname = (void*)GetProcAddress(hMsvcrt, "__unDName");
1506 if (!p_undname) return 0;
1509 if (!UnDecoratedName) return 0;
1510 if (!p_undname(UnDecoratedName, DecoratedName, UndecoratedLength,
1511 und_alloc, und_free, Flags))
1513 return strlen(UnDecoratedName);
1516 /******************************************************************
1517 * SymMatchString (DBGHELP.@)
1520 BOOL WINAPI SymMatchString(PCSTR string, PCSTR re, BOOL _case)
1525 TRACE("%s %s %c\n", string, re, _case ? 'Y' : 'N');
1527 compile_regex(re, -1, &preg, _case);
1528 ret = regexec(&preg, string, 0, NULL, 0) == 0;
1533 /******************************************************************
1534 * SymSearch (DBGHELP.@)
1536 BOOL WINAPI SymSearch(HANDLE hProcess, ULONG64 BaseOfDll, DWORD Index,
1537 DWORD SymTag, PCSTR Mask, DWORD64 Address,
1538 PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
1539 PVOID UserContext, DWORD Options)
1543 TRACE("(%p %s %lu %lu %s %s %p %p %lx)\n",
1544 hProcess, wine_dbgstr_longlong(BaseOfDll), Index, SymTag, Mask,
1545 wine_dbgstr_longlong(Address), EnumSymbolsCallback,
1546 UserContext, Options);
1548 if (Options != SYMSEARCH_GLOBALSONLY)
1550 FIXME("Unsupported searching with options (%lx)\n", Options);
1551 SetLastError(ERROR_INVALID_PARAMETER);
1555 se.cb = EnumSymbolsCallback;
1556 se.user = UserContext;
1560 se.sym_info = (PSYMBOL_INFO)se.buffer;
1562 return sym_enum(hProcess, BaseOfDll, Mask, &se);
1565 /******************************************************************
1566 * SymSearchW (DBGHELP.@)
1568 BOOL WINAPI SymSearchW(HANDLE hProcess, ULONG64 BaseOfDll, DWORD Index,
1569 DWORD SymTag, PCWSTR Mask, DWORD64 Address,
1570 PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
1571 PVOID UserContext, DWORD Options)
1573 struct sym_enumW sew;
1577 TRACE("(%p %s %lu %lu %s %s %p %p %lx)\n",
1578 hProcess, wine_dbgstr_longlong(BaseOfDll), Index, SymTag, debugstr_w(Mask),
1579 wine_dbgstr_longlong(Address), EnumSymbolsCallback,
1580 UserContext, Options);
1582 sew.ctx = UserContext;
1583 sew.cb = EnumSymbolsCallback;
1584 sew.sym_info = (PSYMBOL_INFOW)sew.buffer;
1588 unsigned len = WideCharToMultiByte(CP_ACP, 0, Mask, -1, NULL, 0, NULL, NULL);
1589 maskA = HeapAlloc(GetProcessHeap(), 0, len);
1590 if (!maskA) return FALSE;
1591 WideCharToMultiByte(CP_ACP, 0, Mask, -1, maskA, len, NULL, NULL);
1593 ret = SymSearch(hProcess, BaseOfDll, Index, SymTag, maskA, Address,
1594 sym_enumW, &sew, Options);
1595 HeapFree(GetProcessHeap(), 0, maskA);