2004-04-06 00:21:27 +02:00
|
|
|
/*
|
|
|
|
* File symbol.c - management of symbols (lexical tree)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Eric Youngdale.
|
|
|
|
* 2004, Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
|
|
|
|
2004-04-19 04:58:27 +02:00
|
|
|
#define NONAMELESSUNION
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2004-05-17 23:08:31 +02:00
|
|
|
#include "wine/debug.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
#include "dbghelp_private.h"
|
2006-05-10 21:35:22 +02:00
|
|
|
#include "winnls.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
2004-04-30 06:15:41 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(dbghelp_symt);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2021-08-30 09:24:04 +02:00
|
|
|
extern char * CDECL __unDName(char *buffer, const char *mangled, int len,
|
|
|
|
void * (CDECL *pfn_alloc)(size_t), void (CDECL *pfn_free)(void *), unsigned short flags);
|
|
|
|
|
2007-03-19 20:44:25 +01:00
|
|
|
static inline int cmp_addr(ULONG64 a1, ULONG64 a2)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
if (a1 > a2) return 1;
|
|
|
|
if (a1 < a2) return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
static inline int cmp_sorttab_addr(struct module* module, int idx, ULONG64 addr)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-11-22 19:30:10 +01:00
|
|
|
ULONG64 ref;
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(&module->addr_sorttab[idx]->symt, &ref);
|
2004-04-06 00:21:27 +02:00
|
|
|
return cmp_addr(ref, addr);
|
|
|
|
}
|
|
|
|
|
2020-04-07 09:14:17 +02:00
|
|
|
int __cdecl symt_cmp_addr(const void* p1, const void* p2)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-05-18 23:29:09 +02:00
|
|
|
const struct symt* sym1 = *(const struct symt* const *)p1;
|
|
|
|
const struct symt* sym2 = *(const struct symt* const *)p2;
|
2004-11-22 19:30:10 +01:00
|
|
|
ULONG64 a1, a2;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(sym1, &a1);
|
|
|
|
symt_get_address(sym2, &a2);
|
2004-04-06 00:21:27 +02:00
|
|
|
return cmp_addr(a1, a2);
|
|
|
|
}
|
|
|
|
|
2021-10-06 10:02:31 +02:00
|
|
|
#define BASE_CUSTOM_SYMT 0x80000000
|
|
|
|
|
|
|
|
/* dbghelp exposes the internal symbols/types with DWORD indexes.
|
|
|
|
* - custom symbols are always stored with index starting at BASE_CUSTOM_SYMT
|
|
|
|
* - for all the others (non custom) symbols:
|
|
|
|
* + on 32bit machine, index is set to the actual adress of symt
|
|
|
|
* + on 64bit machine, we have a dedicated array to store symt exposed to caller
|
|
|
|
* index is the index in this array of the symbol
|
|
|
|
*/
|
2009-12-14 22:05:54 +01:00
|
|
|
DWORD symt_ptr2index(struct module* module, const struct symt* sym)
|
|
|
|
{
|
2021-10-06 10:02:31 +02:00
|
|
|
struct vector* vector;
|
|
|
|
DWORD offset;
|
2009-12-14 22:05:54 +01:00
|
|
|
const struct symt** c;
|
2021-10-06 10:02:31 +02:00
|
|
|
int len, i;
|
2009-12-14 22:05:54 +01:00
|
|
|
|
2021-10-06 10:02:31 +02:00
|
|
|
if (!sym) return 0;
|
|
|
|
if (sym->tag == SymTagCustom)
|
|
|
|
{
|
|
|
|
vector = &module->vcustom_symt;
|
|
|
|
offset = BASE_CUSTOM_SYMT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef _WIN64
|
|
|
|
vector = &module->vsymt;
|
|
|
|
offset = 1;
|
|
|
|
#else
|
|
|
|
return (DWORD)sym;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
len = vector_length(vector);
|
2009-12-14 22:05:54 +01:00
|
|
|
/* FIXME: this is inefficient */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
2021-10-06 10:02:31 +02:00
|
|
|
if (*(struct symt**)vector_at(vector, i) == sym)
|
|
|
|
return i + offset;
|
2009-12-14 22:05:54 +01:00
|
|
|
}
|
|
|
|
/* not found */
|
2021-10-06 10:02:31 +02:00
|
|
|
c = vector_add(vector, &module->pool);
|
2009-12-14 22:05:54 +01:00
|
|
|
if (c) *c = sym;
|
2021-10-06 10:02:31 +02:00
|
|
|
return len + offset;
|
2009-12-14 22:05:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct symt* symt_index2ptr(struct module* module, DWORD id)
|
|
|
|
{
|
2021-10-06 10:02:31 +02:00
|
|
|
struct vector* vector;
|
|
|
|
if (id >= BASE_CUSTOM_SYMT)
|
|
|
|
{
|
|
|
|
id -= BASE_CUSTOM_SYMT;
|
|
|
|
vector = &module->vcustom_symt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-14 22:05:54 +01:00
|
|
|
#ifdef _WIN64
|
2021-10-06 10:02:31 +02:00
|
|
|
if (!id--) return NULL;
|
|
|
|
vector = &module->vsymt;
|
2009-12-14 22:05:54 +01:00
|
|
|
#else
|
2021-10-06 10:02:31 +02:00
|
|
|
return (struct symt*)id;
|
2009-12-14 22:05:54 +01:00
|
|
|
#endif
|
2021-10-06 10:02:31 +02:00
|
|
|
}
|
|
|
|
return (id >= vector_length(vector)) ? NULL : *(struct symt**)vector_at(vector, id);
|
2009-12-14 22:05:54 +01:00
|
|
|
}
|
|
|
|
|
2009-06-25 22:27:38 +02:00
|
|
|
static BOOL symt_grow_sorttab(struct module* module, unsigned sz)
|
|
|
|
{
|
|
|
|
struct symt_ht** new;
|
2009-07-10 14:46:55 +02:00
|
|
|
unsigned int size;
|
2009-06-25 22:27:38 +02:00
|
|
|
|
2009-07-10 14:46:55 +02:00
|
|
|
if (sz <= module->sorttab_size) return TRUE;
|
2009-06-25 22:27:38 +02:00
|
|
|
if (module->addr_sorttab)
|
2009-07-10 14:46:55 +02:00
|
|
|
{
|
|
|
|
size = module->sorttab_size * 2;
|
2009-06-25 22:27:38 +02:00
|
|
|
new = HeapReAlloc(GetProcessHeap(), 0, module->addr_sorttab,
|
2009-07-10 14:46:55 +02:00
|
|
|
size * sizeof(struct symt_ht*));
|
|
|
|
}
|
2009-06-25 22:27:38 +02:00
|
|
|
else
|
2009-07-10 14:46:55 +02:00
|
|
|
{
|
|
|
|
size = 64;
|
|
|
|
new = HeapAlloc(GetProcessHeap(), 0, size * sizeof(struct symt_ht*));
|
|
|
|
}
|
2009-06-25 22:27:38 +02:00
|
|
|
if (!new) return FALSE;
|
2009-07-10 14:46:55 +02:00
|
|
|
module->sorttab_size = size;
|
2009-06-25 22:27:38 +02:00
|
|
|
module->addr_sorttab = new;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-25 22:27:31 +02:00
|
|
|
static void symt_add_module_ht(struct module* module, struct symt_ht* ht)
|
|
|
|
{
|
2009-06-25 22:27:38 +02:00
|
|
|
ULONG64 addr;
|
|
|
|
|
2009-06-25 22:27:31 +02:00
|
|
|
hash_table_add(&module->ht_symbols, &ht->hash_elt);
|
2009-06-25 22:27:38 +02:00
|
|
|
/* Don't store in sorttab a symbol without address, they are of
|
|
|
|
* no use here (e.g. constant values)
|
|
|
|
*/
|
2011-03-08 21:31:38 +01:00
|
|
|
if (symt_get_address(&ht->symt, &addr) &&
|
2009-06-25 22:27:38 +02:00
|
|
|
symt_grow_sorttab(module, module->num_symbols + 1))
|
|
|
|
{
|
|
|
|
module->addr_sorttab[module->num_symbols++] = ht;
|
|
|
|
module->sortlist_valid = FALSE;
|
|
|
|
}
|
2009-06-25 22:27:31 +02:00
|
|
|
}
|
|
|
|
|
2012-01-22 12:58:04 +01:00
|
|
|
static WCHAR* file_regex(const char* srcfile)
|
2009-02-04 13:13:08 +01:00
|
|
|
{
|
2012-01-22 12:58:04 +01:00
|
|
|
WCHAR* mask;
|
|
|
|
WCHAR* p;
|
2009-02-09 14:20:00 +01:00
|
|
|
|
2012-01-22 12:58:04 +01:00
|
|
|
if (!srcfile || !*srcfile)
|
2009-02-04 13:13:08 +01:00
|
|
|
{
|
2012-01-22 12:58:04 +01:00
|
|
|
if (!(p = mask = HeapAlloc(GetProcessHeap(), 0, 3 * sizeof(WCHAR)))) return NULL;
|
|
|
|
*p++ = '?';
|
|
|
|
*p++ = '#';
|
2009-02-04 13:13:08 +01:00
|
|
|
}
|
2012-01-22 12:58:04 +01:00
|
|
|
else
|
2009-02-04 13:13:08 +01:00
|
|
|
{
|
2012-01-22 12:58:04 +01:00
|
|
|
DWORD sz = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
|
|
|
|
WCHAR* srcfileW;
|
2009-02-04 13:02:08 +01:00
|
|
|
|
2012-01-22 12:58:04 +01:00
|
|
|
/* FIXME: we use here the largest conversion for every char... could be optimized */
|
|
|
|
p = mask = HeapAlloc(GetProcessHeap(), 0, (5 * strlen(srcfile) + 1 + sz) * sizeof(WCHAR));
|
|
|
|
if (!mask) return NULL;
|
|
|
|
srcfileW = mask + 5 * strlen(srcfile) + 1;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, sz);
|
2009-02-04 13:02:08 +01:00
|
|
|
|
2012-01-22 12:58:04 +01:00
|
|
|
while (*srcfileW)
|
|
|
|
{
|
|
|
|
switch (*srcfileW)
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
case '/':
|
|
|
|
*p++ = '[';
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = '/';
|
|
|
|
*p++ = ']';
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
*p++ = '?';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*p++ = *srcfileW;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
srcfileW++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
return mask;
|
2009-02-04 13:02:08 +01:00
|
|
|
}
|
|
|
|
|
2021-08-30 09:24:29 +02:00
|
|
|
struct symt_module* symt_new_module(struct module* module)
|
|
|
|
{
|
|
|
|
struct symt_module* sym;
|
|
|
|
|
2021-09-06 10:40:08 +02:00
|
|
|
TRACE_(dbghelp_symt)("Adding toplevel exe symbol %s\n", debugstr_w(module->modulename));
|
2021-08-30 09:24:29 +02:00
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagExe;
|
|
|
|
sym->module = module;
|
2021-10-06 10:00:53 +02:00
|
|
|
vector_init(&sym->vchildren, sizeof(struct symt*), 8);
|
2021-08-30 09:24:29 +02:00
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2006-11-24 22:17:21 +01:00
|
|
|
struct symt_compiland* symt_new_compiland(struct module* module,
|
2020-03-26 16:51:49 +01:00
|
|
|
ULONG_PTR address, unsigned src_idx)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct symt_compiland* sym;
|
2021-10-06 10:00:53 +02:00
|
|
|
struct symt_compiland** p;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
TRACE_(dbghelp_symt)("Adding compiland symbol %s:%s\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), source_get(module, src_idx));
|
2004-04-06 00:21:27 +02:00
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
2021-08-30 09:24:35 +02:00
|
|
|
sym->symt.tag = SymTagCompiland;
|
|
|
|
sym->container = module->top;
|
|
|
|
sym->address = address;
|
|
|
|
sym->source = src_idx;
|
2004-04-06 00:21:27 +02:00
|
|
|
vector_init(&sym->vchildren, sizeof(struct symt*), 32);
|
2021-09-08 08:34:02 +02:00
|
|
|
sym->user = NULL;
|
2021-10-06 10:00:53 +02:00
|
|
|
p = vector_add(&module->top->vchildren, &module->pool);
|
|
|
|
*p = sym;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symt_public* symt_new_public(struct module* module,
|
|
|
|
struct symt_compiland* compiland,
|
|
|
|
const char* name,
|
2018-11-25 10:15:48 +01:00
|
|
|
BOOL is_function,
|
2020-03-26 16:51:49 +01:00
|
|
|
ULONG_PTR address, unsigned size)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct symt_public* sym;
|
|
|
|
struct symt** p;
|
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
TRACE_(dbghelp_symt)("Adding public symbol %s:%s @%lx\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name, address);
|
2007-02-21 21:54:39 +01:00
|
|
|
if ((dbghelp_options & SYMOPT_AUTO_PUBLICS) &&
|
2006-12-05 22:13:23 +01:00
|
|
|
symt_find_nearest(module, address) != NULL)
|
2004-08-30 21:31:13 +02:00
|
|
|
return NULL;
|
2004-04-06 00:21:27 +02:00
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagPublicSymbol;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->container = compiland ? &compiland->symt : NULL;
|
2018-11-25 10:15:48 +01:00
|
|
|
sym->is_function = is_function;
|
2004-04-06 00:21:27 +02:00
|
|
|
sym->address = address;
|
|
|
|
sym->size = size;
|
2009-06-25 22:27:31 +02:00
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
2004-04-06 00:21:27 +02:00
|
|
|
if (compiland)
|
|
|
|
{
|
|
|
|
p = vector_add(&compiland->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symt_data* symt_new_global_variable(struct module* module,
|
|
|
|
struct symt_compiland* compiland,
|
|
|
|
const char* name, unsigned is_static,
|
2020-03-26 16:51:49 +01:00
|
|
|
struct location loc, ULONG_PTR size,
|
2004-04-06 00:21:27 +02:00
|
|
|
struct symt* type)
|
|
|
|
{
|
|
|
|
struct symt_data* sym;
|
|
|
|
struct symt** p;
|
2005-11-17 12:51:53 +01:00
|
|
|
DWORD64 tsz;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2011-01-29 20:38:04 +01:00
|
|
|
TRACE_(dbghelp_symt)("Adding global symbol %s:%s %d@%lx %p\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name, loc.kind, loc.offset, type);
|
2004-04-06 00:21:27 +02:00
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagData;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->kind = is_static ? DataIsFileStatic : DataIsGlobal;
|
|
|
|
sym->container = compiland ? &compiland->symt : NULL;
|
|
|
|
sym->type = type;
|
2011-01-29 20:38:04 +01:00
|
|
|
sym->u.var = loc;
|
2009-12-14 22:05:46 +01:00
|
|
|
if (type && size && symt_get_info(module, type, TI_GET_LENGTH, &tsz))
|
2004-05-18 23:29:09 +02:00
|
|
|
{
|
|
|
|
if (tsz != size)
|
2005-11-17 12:51:53 +01:00
|
|
|
FIXME("Size mismatch for %s.%s between type (%s) and src (%lu)\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name,
|
2005-11-17 12:51:53 +01:00
|
|
|
wine_dbgstr_longlong(tsz), size);
|
2004-05-18 23:29:09 +02:00
|
|
|
}
|
2009-06-25 22:27:31 +02:00
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
2004-04-06 00:21:27 +02:00
|
|
|
if (compiland)
|
|
|
|
{
|
|
|
|
p = vector_add(&compiland->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:57:50 +02:00
|
|
|
static void init_function_or_inlinesite(struct symt_function* sym,
|
|
|
|
struct module* module,
|
|
|
|
DWORD tag,
|
|
|
|
struct symt* container,
|
2004-04-06 00:21:27 +02:00
|
|
|
const char* name,
|
2020-03-26 16:51:49 +01:00
|
|
|
ULONG_PTR addr, ULONG_PTR size,
|
2004-04-19 04:58:27 +02:00
|
|
|
struct symt* sig_type)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-10-28 08:57:50 +02:00
|
|
|
assert(!sig_type || sig_type->tag == SymTagFunctionType);
|
|
|
|
sym->symt.tag = tag;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->container = container;
|
|
|
|
sym->address = addr;
|
|
|
|
sym->type = sig_type;
|
|
|
|
sym->size = size;
|
|
|
|
vector_init(&sym->vlines, sizeof(struct line_info), 64);
|
|
|
|
vector_init(&sym->vchildren, sizeof(struct symt*), 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symt_function* symt_new_function(struct module* module,
|
|
|
|
struct symt_compiland* compiland,
|
|
|
|
const char* name,
|
|
|
|
ULONG_PTR addr, ULONG_PTR size,
|
|
|
|
struct symt* sig_type)
|
|
|
|
{
|
|
|
|
struct symt_function* sym;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
TRACE_(dbghelp_symt)("Adding global function %s:%s @%lx-%lx\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name, addr, addr + size - 1);
|
2004-04-06 00:21:27 +02:00
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
2021-10-28 08:57:50 +02:00
|
|
|
struct symt** p;
|
|
|
|
init_function_or_inlinesite(sym, module, SymTagFunction, &compiland->symt, name, addr, size, sig_type);
|
|
|
|
sym->next_inlinesite = NULL; /* first of list */
|
2009-06-25 22:27:31 +02:00
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
2021-11-22 15:19:59 +01:00
|
|
|
if (compiland)
|
|
|
|
{
|
|
|
|
p = vector_add(&compiland->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
2021-10-28 08:57:50 +02:00
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symt_inlinesite* symt_new_inlinesite(struct module* module,
|
|
|
|
struct symt_function* func,
|
|
|
|
struct symt* container,
|
|
|
|
const char* name,
|
|
|
|
ULONG_PTR addr,
|
|
|
|
struct symt* sig_type)
|
|
|
|
{
|
|
|
|
struct symt_inlinesite* sym;
|
|
|
|
|
|
|
|
TRACE_(dbghelp_symt)("Adding inline site %s @%lx\n", name, addr);
|
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
struct symt** p;
|
|
|
|
assert(container);
|
|
|
|
init_function_or_inlinesite(&sym->func, module, SymTagInlineSite, container, name, addr, 0, sig_type);
|
|
|
|
vector_init(&sym->vranges, sizeof(struct addr_range), 2); /* FIXME: number of elts => to be set on input */
|
|
|
|
/* chain inline sites */
|
|
|
|
sym->func.next_inlinesite = func->next_inlinesite;
|
|
|
|
func->next_inlinesite = sym;
|
|
|
|
if (container->tag == SymTagFunction || container->tag == SymTagInlineSite)
|
|
|
|
p = vector_add(&((struct symt_function*)container)->vchildren, &module->pool);
|
|
|
|
else
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-10-28 08:57:50 +02:00
|
|
|
assert(container->tag == SymTagBlock);
|
|
|
|
p = vector_add(&((struct symt_block*)container)->vchildren, &module->pool);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2021-10-28 08:57:50 +02:00
|
|
|
*p = &sym->func.symt;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
void symt_add_func_line(struct module* module, struct symt_function* func,
|
2021-10-29 15:37:04 +02:00
|
|
|
unsigned source_idx, int line_num, ULONG_PTR addr)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct line_info* dli;
|
2021-09-07 09:27:01 +02:00
|
|
|
unsigned vlen;
|
|
|
|
struct line_info* prev;
|
2004-04-06 00:21:27 +02:00
|
|
|
BOOL last_matches = FALSE;
|
2007-05-15 02:05:12 +02:00
|
|
|
int i;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
if (func == NULL || !(dbghelp_options & SYMOPT_LOAD_LINES)) return;
|
|
|
|
|
2021-10-29 15:37:04 +02:00
|
|
|
TRACE_(dbghelp_symt)("(%p)%s:%Ix %s:%u\n",
|
|
|
|
func, func->hash_elt.name, addr,
|
2004-04-30 06:15:41 +02:00
|
|
|
source_get(module, source_idx), line_num);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2021-10-28 08:57:24 +02:00
|
|
|
assert(func->symt.tag == SymTagFunction || func->symt.tag == SymTagInlineSite);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-05-15 02:05:12 +02:00
|
|
|
for (i=vector_length(&func->vlines)-1; i>=0; i--)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-05-15 02:05:12 +02:00
|
|
|
dli = vector_at(&func->vlines, i);
|
2004-04-30 06:15:41 +02:00
|
|
|
if (dli->is_source_file)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
last_matches = (source_idx == dli->u.source_file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 09:27:01 +02:00
|
|
|
vlen = vector_length(&func->vlines);
|
|
|
|
prev = vlen ? vector_at(&func->vlines, vlen - 1) : NULL;
|
2021-11-08 14:57:32 +01:00
|
|
|
if (last_matches && prev && addr == prev->u.address)
|
|
|
|
{
|
|
|
|
WARN("Duplicate addition of line number in %s\n", func->hash_elt.name);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
if (!last_matches)
|
|
|
|
{
|
|
|
|
/* we shouldn't have line changes on first line of function */
|
|
|
|
dli = vector_add(&func->vlines, &module->pool);
|
2004-04-30 06:15:41 +02:00
|
|
|
dli->is_source_file = 1;
|
2021-09-07 09:27:01 +02:00
|
|
|
dli->is_first = (prev == NULL);
|
|
|
|
dli->is_last = 0;
|
2004-04-30 06:15:41 +02:00
|
|
|
dli->line_number = 0;
|
|
|
|
dli->u.source_file = source_idx;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2021-09-07 09:27:01 +02:00
|
|
|
/* clear previous last */
|
|
|
|
if (prev) prev->is_last = 0;
|
2004-04-06 00:21:27 +02:00
|
|
|
dli = vector_add(&func->vlines, &module->pool);
|
2004-04-30 06:15:41 +02:00
|
|
|
dli->is_source_file = 0;
|
2021-09-07 09:27:01 +02:00
|
|
|
dli->is_first = 0; /* only a source file can be first */
|
|
|
|
dli->is_last = 1;
|
2004-04-30 06:15:41 +02:00
|
|
|
dli->line_number = line_num;
|
2021-10-29 15:37:04 +02:00
|
|
|
dli->u.address = addr;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2006-02-06 11:27:32 +01:00
|
|
|
/******************************************************************
|
2006-06-18 21:31:55 +02:00
|
|
|
* symt_add_func_local
|
2006-02-06 11:27:32 +01:00
|
|
|
*
|
|
|
|
* Adds a new local/parameter to a given function:
|
2006-06-18 21:31:55 +02:00
|
|
|
* In any cases, dt tells whether it's a local variable or a parameter
|
2006-02-06 11:27:32 +01:00
|
|
|
* If regno it's not 0:
|
|
|
|
* - then variable is stored in a register
|
2006-06-18 21:31:55 +02:00
|
|
|
* - otherwise, value is referenced by register + offset
|
2006-02-06 11:27:32 +01:00
|
|
|
* Otherwise, the variable is stored on the stack:
|
2006-06-18 21:31:55 +02:00
|
|
|
* - offset is then the offset from the frame register
|
2006-02-06 11:27:32 +01:00
|
|
|
*/
|
2004-04-06 00:21:27 +02:00
|
|
|
struct symt_data* symt_add_func_local(struct module* module,
|
|
|
|
struct symt_function* func,
|
2006-06-18 21:31:55 +02:00
|
|
|
enum DataKind dt,
|
2006-11-24 22:17:38 +01:00
|
|
|
const struct location* loc,
|
2004-04-06 00:21:27 +02:00
|
|
|
struct symt_block* block,
|
|
|
|
struct symt* type, const char* name)
|
|
|
|
{
|
|
|
|
struct symt_data* locsym;
|
|
|
|
struct symt** p;
|
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
TRACE_(dbghelp_symt)("Adding local symbol (%s:%s): %s %p\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), func->hash_elt.name,
|
2004-04-30 06:15:41 +02:00
|
|
|
name, type);
|
2006-06-18 21:31:55 +02:00
|
|
|
|
2021-10-28 08:57:24 +02:00
|
|
|
assert(symt_check_tag(&func->symt, SymTagFunction) || symt_check_tag(&func->symt, SymTagInlineSite));
|
2006-06-18 21:31:55 +02:00
|
|
|
assert(dt == DataIsParam || dt == DataIsLocal);
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
locsym = pool_alloc(&module->pool, sizeof(*locsym));
|
|
|
|
locsym->symt.tag = SymTagData;
|
|
|
|
locsym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
locsym->hash_elt.next = NULL;
|
2006-06-18 21:31:55 +02:00
|
|
|
locsym->kind = dt;
|
2010-06-07 21:50:37 +02:00
|
|
|
locsym->container = block ? &block->symt : &func->symt;
|
2004-04-06 00:21:27 +02:00
|
|
|
locsym->type = type;
|
2006-11-24 22:17:38 +01:00
|
|
|
locsym->u.var = *loc;
|
2004-04-06 00:21:27 +02:00
|
|
|
if (block)
|
|
|
|
p = vector_add(&block->vchildren, &module->pool);
|
|
|
|
else
|
|
|
|
p = vector_add(&func->vchildren, &module->pool);
|
|
|
|
*p = &locsym->symt;
|
|
|
|
return locsym;
|
|
|
|
}
|
|
|
|
|
2021-09-28 17:21:24 +02:00
|
|
|
/******************************************************************
|
|
|
|
* symt_add_func_local
|
|
|
|
*
|
|
|
|
* Adds a new (local) constant to a given function
|
|
|
|
*/
|
|
|
|
struct symt_data* symt_add_func_constant(struct module* module,
|
|
|
|
struct symt_function* func,
|
|
|
|
struct symt_block* block,
|
|
|
|
struct symt* type, const char* name,
|
|
|
|
VARIANT* v)
|
|
|
|
{
|
|
|
|
struct symt_data* locsym;
|
|
|
|
struct symt** p;
|
|
|
|
|
|
|
|
TRACE_(dbghelp_symt)("Adding local constant (%s:%s): %s %p\n",
|
|
|
|
debugstr_w(module->modulename), func->hash_elt.name,
|
|
|
|
name, type);
|
|
|
|
|
2021-10-28 08:57:24 +02:00
|
|
|
assert(symt_check_tag(&func->symt, SymTagFunction) || symt_check_tag(&func->symt, SymTagInlineSite));
|
2021-09-28 17:21:24 +02:00
|
|
|
|
|
|
|
locsym = pool_alloc(&module->pool, sizeof(*locsym));
|
|
|
|
locsym->symt.tag = SymTagData;
|
|
|
|
locsym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
locsym->hash_elt.next = NULL;
|
|
|
|
locsym->kind = DataIsConstant;
|
|
|
|
locsym->container = block ? &block->symt : &func->symt;
|
|
|
|
locsym->type = type;
|
|
|
|
locsym->u.value = *v;
|
|
|
|
if (block)
|
|
|
|
p = vector_add(&block->vchildren, &module->pool);
|
|
|
|
else
|
|
|
|
p = vector_add(&func->vchildren, &module->pool);
|
|
|
|
*p = &locsym->symt;
|
|
|
|
return locsym;
|
|
|
|
}
|
2006-06-18 21:31:55 +02:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
struct symt_block* symt_open_func_block(struct module* module,
|
|
|
|
struct symt_function* func,
|
|
|
|
struct symt_block* parent_block,
|
2004-04-19 04:58:27 +02:00
|
|
|
unsigned pc, unsigned len)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct symt_block* block;
|
|
|
|
struct symt** p;
|
|
|
|
|
2021-10-28 08:57:24 +02:00
|
|
|
assert(symt_check_tag(&func->symt, SymTagFunction) || symt_check_tag(&func->symt, SymTagInlineSite));
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
assert(!parent_block || parent_block->symt.tag == SymTagBlock);
|
|
|
|
block = pool_alloc(&module->pool, sizeof(*block));
|
2004-04-19 04:58:27 +02:00
|
|
|
block->symt.tag = SymTagBlock;
|
2004-05-18 23:29:09 +02:00
|
|
|
block->address = func->address + pc;
|
2004-04-19 04:58:27 +02:00
|
|
|
block->size = len;
|
2004-04-06 00:21:27 +02:00
|
|
|
block->container = parent_block ? &parent_block->symt : &func->symt;
|
|
|
|
vector_init(&block->vchildren, sizeof(struct symt*), 4);
|
|
|
|
if (parent_block)
|
|
|
|
p = vector_add(&parent_block->vchildren, &module->pool);
|
|
|
|
else
|
|
|
|
p = vector_add(&func->vchildren, &module->pool);
|
|
|
|
*p = &block->symt;
|
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symt_block* symt_close_func_block(struct module* module,
|
2009-07-15 00:01:31 +02:00
|
|
|
const struct symt_function* func,
|
2004-04-06 00:21:27 +02:00
|
|
|
struct symt_block* block, unsigned pc)
|
|
|
|
{
|
2021-10-28 08:57:24 +02:00
|
|
|
assert(symt_check_tag(&func->symt, SymTagFunction) || symt_check_tag(&func->symt, SymTagInlineSite));
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2004-05-18 23:29:09 +02:00
|
|
|
if (pc) block->size = func->address + pc - block->address;
|
2004-04-06 00:21:27 +02:00
|
|
|
return (block->container->tag == SymTagBlock) ?
|
2016-03-08 11:44:26 +01:00
|
|
|
CONTAINING_RECORD(block->container, struct symt_block, symt) : NULL;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2008-02-06 21:55:47 +01:00
|
|
|
struct symt_hierarchy_point* symt_add_function_point(struct module* module,
|
|
|
|
struct symt_function* func,
|
|
|
|
enum SymTagEnum point,
|
|
|
|
const struct location* loc,
|
|
|
|
const char* name)
|
2004-04-19 04:58:27 +02:00
|
|
|
{
|
2008-02-06 21:55:47 +01:00
|
|
|
struct symt_hierarchy_point*sym;
|
2004-04-19 04:58:27 +02:00
|
|
|
struct symt** p;
|
|
|
|
|
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = point;
|
2008-02-06 21:55:47 +01:00
|
|
|
sym->parent = &func->symt;
|
2006-11-24 22:17:54 +01:00
|
|
|
sym->loc = *loc;
|
2008-02-06 21:55:47 +01:00
|
|
|
sym->hash_elt.name = name ? pool_strdup(&module->pool, name) : NULL;
|
2004-04-19 04:58:27 +02:00
|
|
|
p = vector_add(&func->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:58:04 +02:00
|
|
|
/* low and high are absolute addresses */
|
|
|
|
BOOL symt_add_inlinesite_range(struct module* module,
|
|
|
|
struct symt_inlinesite* inlined,
|
|
|
|
ULONG_PTR low, ULONG_PTR high)
|
|
|
|
{
|
|
|
|
struct addr_range* p;
|
|
|
|
|
|
|
|
p = vector_add(&inlined->vranges, &module->pool);
|
|
|
|
p->low = low;
|
|
|
|
p->high = high;
|
|
|
|
if (TRUE)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* see dbghelp_private.h for the assumptions */
|
|
|
|
for (i = 0; i < inlined->vranges.num_elts - 1; i++)
|
|
|
|
{
|
|
|
|
if (!addr_range_disjoint((struct addr_range*)vector_at(&inlined->vranges, i), p))
|
|
|
|
{
|
|
|
|
FIXME("Added addr_range isn't disjoint from siblings\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ( ; inlined->func.symt.tag != SymTagFunction; inlined = (struct symt_inlinesite*)symt_get_upper_inlined(inlined))
|
|
|
|
{
|
|
|
|
for (i = 0; i < inlined->vranges.num_elts; i++)
|
|
|
|
{
|
|
|
|
struct addr_range* ar = (struct addr_range*)vector_at(&inlined->vranges, i);
|
|
|
|
if (!addr_range_disjoint(ar, p) && !addr_range_inside(ar, p))
|
2021-12-15 13:32:00 +01:00
|
|
|
WARN("Added addr_range not compatible with parent\n");
|
2021-10-28 08:58:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-05-18 23:29:09 +02:00
|
|
|
struct symt_thunk* symt_new_thunk(struct module* module,
|
|
|
|
struct symt_compiland* compiland,
|
|
|
|
const char* name, THUNK_ORDINAL ord,
|
2020-03-26 16:51:49 +01:00
|
|
|
ULONG_PTR addr, ULONG_PTR size)
|
2004-05-18 23:29:09 +02:00
|
|
|
{
|
|
|
|
struct symt_thunk* sym;
|
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
TRACE_(dbghelp_symt)("Adding global thunk %s:%s @%lx-%lx\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name, addr, addr + size - 1);
|
2004-05-18 23:29:09 +02:00
|
|
|
|
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagThunk;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->container = &compiland->symt;
|
|
|
|
sym->address = addr;
|
|
|
|
sym->size = size;
|
|
|
|
sym->ordinal = ord;
|
2009-06-25 22:27:31 +02:00
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
2004-05-18 23:29:09 +02:00
|
|
|
if (compiland)
|
|
|
|
{
|
|
|
|
struct symt** p;
|
|
|
|
p = vector_add(&compiland->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2006-12-05 22:13:30 +01:00
|
|
|
struct symt_data* symt_new_constant(struct module* module,
|
|
|
|
struct symt_compiland* compiland,
|
|
|
|
const char* name, struct symt* type,
|
|
|
|
const VARIANT* v)
|
|
|
|
{
|
|
|
|
struct symt_data* sym;
|
|
|
|
|
|
|
|
TRACE_(dbghelp_symt)("Adding constant value %s:%s\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name);
|
2006-12-05 22:13:30 +01:00
|
|
|
|
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagData;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->kind = DataIsConstant;
|
|
|
|
sym->container = compiland ? &compiland->symt : NULL;
|
|
|
|
sym->type = type;
|
|
|
|
sym->u.value = *v;
|
2009-06-25 22:27:31 +02:00
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
2006-12-05 22:13:30 +01:00
|
|
|
if (compiland)
|
|
|
|
{
|
|
|
|
struct symt** p;
|
2008-02-06 21:55:47 +01:00
|
|
|
p = vector_add(&compiland->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symt_hierarchy_point* symt_new_label(struct module* module,
|
|
|
|
struct symt_compiland* compiland,
|
2020-03-26 16:51:49 +01:00
|
|
|
const char* name, ULONG_PTR address)
|
2008-02-06 21:55:47 +01:00
|
|
|
{
|
|
|
|
struct symt_hierarchy_point* sym;
|
|
|
|
|
|
|
|
TRACE_(dbghelp_symt)("Adding global label value %s:%s\n",
|
2021-09-06 10:40:08 +02:00
|
|
|
debugstr_w(module->modulename), name);
|
2008-02-06 21:55:47 +01:00
|
|
|
|
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagLabel;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->loc.kind = loc_absolute;
|
|
|
|
sym->loc.offset = address;
|
|
|
|
sym->parent = compiland ? &compiland->symt : NULL;
|
2009-06-25 22:27:31 +02:00
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
2008-02-06 21:55:47 +01:00
|
|
|
if (compiland)
|
|
|
|
{
|
|
|
|
struct symt** p;
|
2006-12-05 22:13:30 +01:00
|
|
|
p = vector_add(&compiland->vchildren, &module->pool);
|
|
|
|
*p = &sym->symt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2021-10-06 10:02:31 +02:00
|
|
|
struct symt_custom* symt_new_custom(struct module* module, const char* name,
|
|
|
|
DWORD64 addr, DWORD size)
|
|
|
|
{
|
|
|
|
struct symt_custom* sym;
|
|
|
|
|
|
|
|
TRACE_(dbghelp_symt)("Adding custom symbol %s:%s\n",
|
|
|
|
debugstr_w(module->modulename), name);
|
|
|
|
|
|
|
|
if ((sym = pool_alloc(&module->pool, sizeof(*sym))))
|
|
|
|
{
|
|
|
|
sym->symt.tag = SymTagCustom;
|
|
|
|
sym->hash_elt.name = pool_strdup(&module->pool, name);
|
|
|
|
sym->address = addr;
|
|
|
|
sym->size = size;
|
|
|
|
symt_add_module_ht(module, (struct symt_ht*)sym);
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/* expect sym_info->MaxNameLen to be set before being called */
|
2009-12-14 22:05:46 +01:00
|
|
|
static void symt_fill_sym_info(struct module_pair* pair,
|
2006-11-24 22:17:16 +01:00
|
|
|
const struct symt_function* func,
|
2004-04-06 00:21:27 +02:00
|
|
|
const struct symt* sym, SYMBOL_INFO* sym_info)
|
|
|
|
{
|
|
|
|
const char* name;
|
2005-11-17 12:51:53 +01:00
|
|
|
DWORD64 size;
|
2021-08-30 09:24:04 +02:00
|
|
|
char* tmp;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
if (!symt_get_info(pair->effective, sym, TI_GET_TYPE, &sym_info->TypeIndex))
|
2005-12-05 12:00:54 +01:00
|
|
|
sym_info->TypeIndex = 0;
|
2016-03-21 18:30:14 +01:00
|
|
|
sym_info->Index = symt_ptr2index(pair->effective, sym);
|
2006-01-23 16:26:57 +01:00
|
|
|
sym_info->Reserved[0] = sym_info->Reserved[1] = 0;
|
2009-12-14 22:05:46 +01:00
|
|
|
if (!symt_get_info(pair->effective, sym, TI_GET_LENGTH, &size) &&
|
2006-01-23 16:26:57 +01:00
|
|
|
(!sym_info->TypeIndex ||
|
2009-12-14 22:05:46 +01:00
|
|
|
!symt_get_info(pair->effective, symt_index2ptr(pair->effective, sym_info->TypeIndex),
|
|
|
|
TI_GET_LENGTH, &size)))
|
2005-12-19 18:20:47 +01:00
|
|
|
size = 0;
|
2005-11-17 12:51:53 +01:00
|
|
|
sym_info->Size = (DWORD)size;
|
2006-05-07 14:29:49 +02:00
|
|
|
sym_info->ModBase = pair->requested->module.BaseOfImage;
|
2004-04-06 00:21:27 +02:00
|
|
|
sym_info->Flags = 0;
|
2006-01-23 16:26:57 +01:00
|
|
|
sym_info->Value = 0;
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
switch (sym->tag)
|
|
|
|
{
|
|
|
|
case SymTagData:
|
|
|
|
{
|
2004-05-18 23:29:09 +02:00
|
|
|
const struct symt_data* data = (const struct symt_data*)sym;
|
2004-04-30 06:15:41 +02:00
|
|
|
switch (data->kind)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-04-30 06:15:41 +02:00
|
|
|
case DataIsParam:
|
2006-02-06 11:27:32 +01:00
|
|
|
sym_info->Flags |= SYMFLAG_PARAMETER;
|
|
|
|
/* fall through */
|
2006-11-24 22:17:47 +01:00
|
|
|
case DataIsLocal:
|
2012-01-02 21:28:04 +01:00
|
|
|
sym_info->Flags |= SYMFLAG_LOCAL;
|
2004-04-30 06:15:41 +02:00
|
|
|
{
|
2006-11-24 22:17:47 +01:00
|
|
|
struct location loc = data->u.var;
|
|
|
|
|
|
|
|
if (loc.kind >= loc_user)
|
2010-03-18 21:31:43 +01:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
struct module_format* modfmt;
|
|
|
|
|
|
|
|
for (i = 0; i < DFI_LAST; i++)
|
|
|
|
{
|
|
|
|
modfmt = pair->effective->format_info[i];
|
|
|
|
if (modfmt && modfmt->loc_compute)
|
|
|
|
{
|
|
|
|
modfmt->loc_compute(pair->pcs, modfmt, func, &loc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-24 22:17:47 +01:00
|
|
|
switch (loc.kind)
|
|
|
|
{
|
|
|
|
case loc_error:
|
|
|
|
/* for now we report error cases as a negative register number */
|
|
|
|
/* fall through */
|
|
|
|
case loc_register:
|
|
|
|
sym_info->Flags |= SYMFLAG_REGISTER;
|
|
|
|
sym_info->Register = loc.reg;
|
|
|
|
sym_info->Address = 0;
|
|
|
|
break;
|
|
|
|
case loc_regrel:
|
2012-01-02 21:28:04 +01:00
|
|
|
sym_info->Flags |= SYMFLAG_REGREL;
|
2011-04-11 20:47:19 +02:00
|
|
|
sym_info->Register = loc.reg;
|
|
|
|
if (loc.reg == CV_REG_NONE || (int)loc.reg < 0 /* error */)
|
|
|
|
FIXME("suspicious register value %x\n", loc.reg);
|
2006-11-24 22:17:47 +01:00
|
|
|
sym_info->Address = loc.offset;
|
|
|
|
break;
|
2010-05-31 22:08:28 +02:00
|
|
|
case loc_absolute:
|
|
|
|
sym_info->Flags |= SYMFLAG_VALUEPRESENT;
|
|
|
|
sym_info->Value = loc.offset;
|
|
|
|
break;
|
2006-11-24 22:17:47 +01:00
|
|
|
default:
|
|
|
|
FIXME("Shouldn't happen (kind=%d), debug reader backend is broken\n", loc.kind);
|
|
|
|
assert(0);
|
|
|
|
}
|
2004-04-30 06:15:41 +02:00
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
break;
|
2004-04-30 06:15:41 +02:00
|
|
|
case DataIsGlobal:
|
|
|
|
case DataIsFileStatic:
|
2011-01-29 20:38:04 +01:00
|
|
|
switch (data->u.var.kind)
|
|
|
|
{
|
|
|
|
case loc_tlsrel:
|
|
|
|
sym_info->Flags |= SYMFLAG_TLSREL;
|
|
|
|
/* fall through */
|
|
|
|
case loc_absolute:
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(sym, &sym_info->Address);
|
2011-01-29 20:38:04 +01:00
|
|
|
sym_info->Register = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Shouldn't happen (kind=%d), debug reader backend is broken\n", data->u.var.kind);
|
|
|
|
assert(0);
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
break;
|
2004-04-30 06:15:41 +02:00
|
|
|
case DataIsConstant:
|
2004-04-06 00:21:27 +02:00
|
|
|
sym_info->Flags |= SYMFLAG_VALUEPRESENT;
|
2021-09-28 17:21:24 +02:00
|
|
|
if (data->container &&
|
|
|
|
(data->container->tag == SymTagFunction || data->container->tag == SymTagBlock))
|
|
|
|
sym_info->Flags |= SYMFLAG_LOCAL;
|
2021-10-13 15:17:20 +02:00
|
|
|
switch (V_VT(&data->u.value))
|
2004-04-19 04:58:27 +02:00
|
|
|
{
|
2021-10-13 15:17:26 +02:00
|
|
|
case VT_I8: sym_info->Value = (LONG64)V_I8(&data->u.value); break;
|
|
|
|
case VT_I4: sym_info->Value = (LONG64)V_I4(&data->u.value); break;
|
|
|
|
case VT_I2: sym_info->Value = (LONG64)V_I2(&data->u.value); break;
|
|
|
|
case VT_I1: sym_info->Value = (LONG64)V_I1(&data->u.value); break;
|
|
|
|
case VT_UINT:sym_info->Value = V_UINT(&data->u.value); break;
|
|
|
|
case VT_UI8: sym_info->Value = V_UI8(&data->u.value); break;
|
|
|
|
case VT_UI4: sym_info->Value = V_UI4(&data->u.value); break;
|
|
|
|
case VT_UI2: sym_info->Value = V_UI2(&data->u.value); break;
|
|
|
|
case VT_UI1: sym_info->Value = V_UI1(&data->u.value); break;
|
|
|
|
case VT_BYREF: sym_info->Value = (DWORD_PTR)V_BYREF(&data->u.value); break;
|
2009-10-03 13:15:43 +02:00
|
|
|
case VT_EMPTY: sym_info->Value = 0; break;
|
2006-12-05 22:13:30 +01:00
|
|
|
default:
|
2021-10-13 15:17:20 +02:00
|
|
|
FIXME("Unsupported variant type (%u)\n", V_VT(&data->u.value));
|
2006-12-05 22:13:30 +01:00
|
|
|
sym_info->Value = 0;
|
|
|
|
break;
|
2004-04-19 04:58:27 +02:00
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
break;
|
|
|
|
default:
|
2004-04-30 06:15:41 +02:00
|
|
|
FIXME("Unhandled kind (%u) in sym data\n", data->kind);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SymTagPublicSymbol:
|
2018-11-25 10:15:48 +01:00
|
|
|
{
|
|
|
|
const struct symt_public* pub = (const struct symt_public*)sym;
|
|
|
|
if (pub->is_function)
|
|
|
|
sym_info->Flags |= SYMFLAG_PUBLIC_CODE;
|
|
|
|
else
|
|
|
|
sym_info->Flags |= SYMFLAG_EXPORT;
|
|
|
|
symt_get_address(sym, &sym_info->Address);
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
break;
|
|
|
|
case SymTagFunction:
|
2021-10-28 08:57:24 +02:00
|
|
|
case SymTagInlineSite:
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(sym, &sym_info->Address);
|
2004-04-06 00:21:27 +02:00
|
|
|
break;
|
2004-05-18 23:29:09 +02:00
|
|
|
case SymTagThunk:
|
|
|
|
sym_info->Flags |= SYMFLAG_THUNK;
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(sym, &sym_info->Address);
|
2004-05-18 23:29:09 +02:00
|
|
|
break;
|
2021-10-06 10:02:31 +02:00
|
|
|
case SymTagCustom:
|
|
|
|
symt_get_address(sym, &sym_info->Address);
|
|
|
|
sym_info->Flags |= SYMFLAG_VIRTUAL;
|
|
|
|
break;
|
2004-04-06 00:21:27 +02:00
|
|
|
default:
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(sym, &sym_info->Address);
|
2004-04-06 00:21:27 +02:00
|
|
|
sym_info->Register = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sym_info->Scope = 0; /* FIXME */
|
|
|
|
sym_info->Tag = sym->tag;
|
|
|
|
name = symt_get_name(sym);
|
2021-08-30 09:24:04 +02:00
|
|
|
if (sym_info->MaxNameLen &&
|
|
|
|
sym->tag == SymTagPublicSymbol && (dbghelp_options & SYMOPT_UNDNAME) &&
|
|
|
|
(tmp = __unDName(NULL, name, 0, malloc, free, UNDNAME_NAME_ONLY)) != NULL)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-08-30 09:24:04 +02:00
|
|
|
symbol_setname(sym_info, tmp);
|
|
|
|
free(tmp);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2021-08-30 09:24:04 +02:00
|
|
|
else
|
|
|
|
symbol_setname(sym_info, name);
|
|
|
|
|
2006-11-29 22:04:27 +01:00
|
|
|
TRACE_(dbghelp_symt)("%p => %s %u %s\n",
|
2004-10-11 23:00:17 +02:00
|
|
|
sym, sym_info->Name, sym_info->Size,
|
|
|
|
wine_dbgstr_longlong(sym_info->Address));
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:34 +02:00
|
|
|
struct sym_enum
|
|
|
|
{
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACK cb;
|
|
|
|
PVOID user;
|
|
|
|
SYMBOL_INFO* sym_info;
|
2006-05-10 21:35:37 +02:00
|
|
|
DWORD index;
|
|
|
|
DWORD tag;
|
|
|
|
DWORD64 addr;
|
2006-05-10 21:35:34 +02:00
|
|
|
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
|
|
|
};
|
2006-05-10 21:35:37 +02:00
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
static BOOL send_symbol(const struct sym_enum* se, struct module_pair* pair,
|
2006-11-24 22:17:16 +01:00
|
|
|
const struct symt_function* func, const struct symt* sym)
|
2006-05-10 21:35:37 +02:00
|
|
|
{
|
2006-11-24 22:17:16 +01:00
|
|
|
symt_fill_sym_info(pair, func, sym, se->sym_info);
|
2016-03-21 18:30:14 +01:00
|
|
|
if (se->index && se->sym_info->Index != se->index) return FALSE;
|
2006-05-10 21:35:37 +02:00
|
|
|
if (se->tag && se->sym_info->Tag != se->tag) return FALSE;
|
|
|
|
if (se->addr && !(se->addr >= se->sym_info->Address && se->addr < se->sym_info->Address + se->sym_info->Size)) return FALSE;
|
|
|
|
return !se->cb(se->sym_info, se->sym_info->Size, se->user);
|
|
|
|
}
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
static BOOL symt_enum_module(struct module_pair* pair, const WCHAR* match,
|
2006-05-10 21:35:34 +02:00
|
|
|
const struct sym_enum* se)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
void* ptr;
|
|
|
|
struct symt_ht* sym = NULL;
|
|
|
|
struct hash_table_iter hti;
|
2012-01-22 12:57:59 +01:00
|
|
|
WCHAR* nameW;
|
|
|
|
BOOL ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-05-07 14:29:49 +02:00
|
|
|
hash_table_iter_init(&pair->effective->ht_symbols, &hti, NULL);
|
2004-04-06 00:21:27 +02:00
|
|
|
while ((ptr = hash_table_iter_up(&hti)))
|
|
|
|
{
|
2016-03-08 11:44:26 +01:00
|
|
|
sym = CONTAINING_RECORD(ptr, struct symt_ht, hash_elt);
|
2012-01-22 12:57:59 +01:00
|
|
|
nameW = symt_get_nameW(&sym->symt);
|
|
|
|
ret = SymMatchStringW(nameW, match, FALSE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
if (ret)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-10 21:35:34 +02:00
|
|
|
se->sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
|
|
|
|
se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
|
2006-11-24 22:17:16 +01:00
|
|
|
if (send_symbol(se, pair, NULL, &sym->symt)) return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2012-01-22 12:57:59 +01:00
|
|
|
}
|
2004-07-04 02:10:54 +02:00
|
|
|
return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
static inline unsigned where_to_insert(struct module* module, unsigned high, const struct symt_ht* elt)
|
2009-06-25 22:27:45 +02:00
|
|
|
{
|
|
|
|
unsigned low = 0, mid = high / 2;
|
|
|
|
ULONG64 addr;
|
|
|
|
|
|
|
|
if (!high) return 0;
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(&elt->symt, &addr);
|
2009-06-25 22:27:45 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (cmp_sorttab_addr(module, mid, addr))
|
|
|
|
{
|
|
|
|
case 0: return mid;
|
|
|
|
case -1: low = mid + 1; break;
|
|
|
|
case 1: high = mid; break;
|
|
|
|
}
|
|
|
|
mid = low + (high - low) / 2;
|
|
|
|
} while (low < high);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* resort_symbols
|
|
|
|
*
|
|
|
|
* Rebuild sorted list of symbols for a module.
|
|
|
|
*/
|
|
|
|
static BOOL resort_symbols(struct module* module)
|
|
|
|
{
|
2011-03-08 21:31:47 +01:00
|
|
|
int delta;
|
|
|
|
|
2009-06-25 22:27:38 +02:00
|
|
|
if (!(module->module.NumSyms = module->num_symbols))
|
2006-12-05 22:13:27 +01:00
|
|
|
return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2011-03-08 21:31:47 +01:00
|
|
|
/* we know that set from 0 up to num_sorttab is already sorted
|
|
|
|
* so sort the remaining (new) symbols, and merge the two sets
|
|
|
|
* (unless the first set is empty)
|
|
|
|
*/
|
|
|
|
delta = module->num_symbols - module->num_sorttab;
|
|
|
|
qsort(&module->addr_sorttab[module->num_sorttab], delta, sizeof(struct symt_ht*), symt_cmp_addr);
|
|
|
|
if (module->num_sorttab)
|
2009-06-25 22:27:45 +02:00
|
|
|
{
|
2011-03-08 21:31:47 +01:00
|
|
|
int i, ins_idx = module->num_sorttab, prev_ins_idx;
|
|
|
|
static struct symt_ht** tmp;
|
|
|
|
static unsigned num_tmp;
|
2009-06-25 22:27:45 +02:00
|
|
|
|
2011-03-08 21:31:47 +01:00
|
|
|
if (num_tmp < delta)
|
|
|
|
{
|
|
|
|
static struct symt_ht** new;
|
|
|
|
if (tmp)
|
|
|
|
new = HeapReAlloc(GetProcessHeap(), 0, tmp, delta * sizeof(struct symt_ht*));
|
|
|
|
else
|
|
|
|
new = HeapAlloc(GetProcessHeap(), 0, delta * sizeof(struct symt_ht*));
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
module->num_sorttab = 0;
|
|
|
|
return resort_symbols(module);
|
|
|
|
}
|
|
|
|
tmp = new;
|
|
|
|
num_tmp = delta;
|
|
|
|
}
|
2009-06-25 22:27:45 +02:00
|
|
|
memcpy(tmp, &module->addr_sorttab[module->num_sorttab], delta * sizeof(struct symt_ht*));
|
|
|
|
qsort(tmp, delta, sizeof(struct symt_ht*), symt_cmp_addr);
|
|
|
|
|
|
|
|
for (i = delta - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
prev_ins_idx = ins_idx;
|
2011-03-08 21:31:38 +01:00
|
|
|
ins_idx = where_to_insert(module, ins_idx, tmp[i]);
|
2009-06-25 22:27:45 +02:00
|
|
|
memmove(&module->addr_sorttab[ins_idx + i + 1],
|
|
|
|
&module->addr_sorttab[ins_idx],
|
|
|
|
(prev_ins_idx - ins_idx) * sizeof(struct symt_ht*));
|
|
|
|
module->addr_sorttab[ins_idx + i] = tmp[i];
|
|
|
|
}
|
|
|
|
}
|
2009-06-25 22:27:38 +02:00
|
|
|
module->num_sorttab = module->num_symbols;
|
2004-04-06 00:21:27 +02:00
|
|
|
return module->sortlist_valid = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
static void symt_get_length(struct module* module, const struct symt* symt, ULONG64* size)
|
2008-09-06 22:20:06 +02:00
|
|
|
{
|
|
|
|
DWORD type_index;
|
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
if (symt_get_info(module, symt, TI_GET_LENGTH, size) && *size)
|
2008-09-06 22:20:06 +02:00
|
|
|
return;
|
|
|
|
|
2009-12-14 22:05:46 +01:00
|
|
|
if (symt_get_info(module, symt, TI_GET_TYPE, &type_index) &&
|
|
|
|
symt_get_info(module, symt_index2ptr(module, type_index), TI_GET_LENGTH, size)) return;
|
2008-09-06 22:20:06 +02:00
|
|
|
*size = 0x1000; /* arbitrary value */
|
|
|
|
}
|
|
|
|
|
2019-03-14 02:40:53 +01:00
|
|
|
/* needed by symt_find_nearest */
|
2018-12-09 01:41:20 +01:00
|
|
|
static int symt_get_best_at(struct module* module, int idx_sorttab)
|
2018-11-25 10:15:50 +01:00
|
|
|
{
|
|
|
|
ULONG64 ref_addr;
|
|
|
|
int idx_sorttab_orig = idx_sorttab;
|
|
|
|
if (module->addr_sorttab[idx_sorttab]->symt.tag == SymTagPublicSymbol)
|
|
|
|
{
|
|
|
|
symt_get_address(&module->addr_sorttab[idx_sorttab]->symt, &ref_addr);
|
|
|
|
while (idx_sorttab > 0 &&
|
|
|
|
module->addr_sorttab[idx_sorttab]->symt.tag == SymTagPublicSymbol &&
|
|
|
|
!cmp_sorttab_addr(module, idx_sorttab - 1, ref_addr))
|
|
|
|
idx_sorttab--;
|
|
|
|
if (module->addr_sorttab[idx_sorttab]->symt.tag == SymTagPublicSymbol)
|
|
|
|
{
|
|
|
|
idx_sorttab = idx_sorttab_orig;
|
|
|
|
while (idx_sorttab < module->num_sorttab - 1 &&
|
|
|
|
module->addr_sorttab[idx_sorttab]->symt.tag == SymTagPublicSymbol &&
|
|
|
|
!cmp_sorttab_addr(module, idx_sorttab + 1, ref_addr))
|
|
|
|
idx_sorttab++;
|
|
|
|
}
|
2019-03-14 02:40:53 +01:00
|
|
|
/* if no better symbol was found restore the original */
|
2018-11-25 10:15:50 +01:00
|
|
|
if (module->addr_sorttab[idx_sorttab]->symt.tag == SymTagPublicSymbol)
|
|
|
|
idx_sorttab = idx_sorttab_orig;
|
|
|
|
}
|
|
|
|
return idx_sorttab;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/* assume addr is in module */
|
2009-12-14 22:06:06 +01:00
|
|
|
struct symt_ht* symt_find_nearest(struct module* module, DWORD_PTR addr)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
int mid, high, low;
|
2005-11-17 12:51:53 +01:00
|
|
|
ULONG64 ref_addr, ref_size;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2004-08-09 20:50:21 +02:00
|
|
|
if (!module->sortlist_valid || !module->addr_sorttab)
|
|
|
|
{
|
2006-12-05 22:13:23 +01:00
|
|
|
if (!resort_symbols(module)) return NULL;
|
2004-08-09 20:50:21 +02:00
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Binary search to find closest symbol.
|
|
|
|
*/
|
|
|
|
low = 0;
|
2006-12-05 22:13:30 +01:00
|
|
|
high = module->num_sorttab;
|
2004-05-18 23:29:09 +02:00
|
|
|
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(&module->addr_sorttab[0]->symt, &ref_addr);
|
2021-08-21 22:30:10 +02:00
|
|
|
if (addr < ref_addr) return NULL;
|
2018-11-25 10:15:50 +01:00
|
|
|
|
2004-05-18 23:29:09 +02:00
|
|
|
if (high)
|
|
|
|
{
|
2011-03-08 21:31:38 +01:00
|
|
|
symt_get_address(&module->addr_sorttab[high - 1]->symt, &ref_addr);
|
2009-12-14 22:05:46 +01:00
|
|
|
symt_get_length(module, &module->addr_sorttab[high - 1]->symt, &ref_size);
|
2006-12-05 22:13:23 +01:00
|
|
|
if (addr >= ref_addr + ref_size) return NULL;
|
2004-05-18 23:29:09 +02:00
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
while (high > low + 1)
|
|
|
|
{
|
|
|
|
mid = (high + low) / 2;
|
|
|
|
if (cmp_sorttab_addr(module, mid, addr) < 0)
|
|
|
|
low = mid;
|
|
|
|
else
|
|
|
|
high = mid;
|
|
|
|
}
|
2006-12-05 22:13:30 +01:00
|
|
|
if (low != high && high != module->num_sorttab &&
|
2004-04-06 00:21:27 +02:00
|
|
|
cmp_sorttab_addr(module, high, addr) <= 0)
|
|
|
|
low = high;
|
|
|
|
|
|
|
|
/* If found symbol is a public symbol, check if there are any other entries that
|
|
|
|
* might also have the same address, but would get better information
|
|
|
|
*/
|
2018-11-25 10:15:50 +01:00
|
|
|
low = symt_get_best_at(module, low);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-12-05 22:13:23 +01:00
|
|
|
return module->addr_sorttab[low];
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2006-11-24 22:17:10 +01:00
|
|
|
static BOOL symt_enum_locals_helper(struct module_pair* pair,
|
2012-01-22 12:57:59 +01:00
|
|
|
const WCHAR* match, const struct sym_enum* se,
|
2007-04-19 23:00:04 +02:00
|
|
|
struct symt_function* func, const struct vector* v)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct symt* lsym = NULL;
|
2021-10-26 11:45:32 +02:00
|
|
|
DWORD_PTR pc = pair->pcs->localscope_pc;
|
2008-09-24 21:50:05 +02:00
|
|
|
unsigned int i;
|
2012-01-22 12:57:59 +01:00
|
|
|
WCHAR* nameW;
|
|
|
|
BOOL ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-05-15 02:05:12 +02:00
|
|
|
for (i=0; i<vector_length(v); i++)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-05-15 02:05:12 +02:00
|
|
|
lsym = *(struct symt**)vector_at(v, i);
|
2004-04-06 00:21:27 +02:00
|
|
|
switch (lsym->tag)
|
|
|
|
{
|
|
|
|
case SymTagBlock:
|
|
|
|
{
|
|
|
|
struct symt_block* block = (struct symt_block*)lsym;
|
|
|
|
if (pc < block->address || block->address + block->size <= pc)
|
|
|
|
continue;
|
2012-01-22 12:57:59 +01:00
|
|
|
if (!symt_enum_locals_helper(pair, match, se, func, &block->vchildren))
|
2004-04-06 00:21:27 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SymTagData:
|
2012-01-22 12:57:59 +01:00
|
|
|
nameW = symt_get_nameW(lsym);
|
|
|
|
ret = SymMatchStringW(nameW, match,
|
|
|
|
!(dbghelp_options & SYMOPT_CASE_INSENSITIVE));
|
|
|
|
HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
if (ret)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-11-24 22:17:16 +01:00
|
|
|
if (send_symbol(se, pair, func, lsym)) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
break;
|
2004-04-19 04:58:27 +02:00
|
|
|
case SymTagLabel:
|
|
|
|
case SymTagFuncDebugStart:
|
|
|
|
case SymTagFuncDebugEnd:
|
2006-11-24 22:17:54 +01:00
|
|
|
case SymTagCustom:
|
2021-10-28 08:57:24 +02:00
|
|
|
case SymTagInlineSite:
|
2004-04-19 04:58:27 +02:00
|
|
|
break;
|
2004-04-06 00:21:27 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unknown type: %u (%x)\n", lsym->tag, lsym->tag);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
static BOOL symt_enum_locals(struct process* pcs, const WCHAR* mask,
|
2006-05-10 21:35:34 +02:00
|
|
|
const struct sym_enum* se)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-07 14:29:49 +02:00
|
|
|
struct module_pair pair;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-05-10 21:35:34 +02:00
|
|
|
se->sym_info->SizeOfStruct = sizeof(*se->sym_info);
|
|
|
|
se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-11-24 22:17:10 +01:00
|
|
|
pair.pcs = pcs;
|
2021-10-26 11:45:32 +02:00
|
|
|
pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc, DMT_UNKNOWN);
|
2006-11-24 22:17:10 +01:00
|
|
|
if (!module_get_debug(&pair)) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2021-10-26 11:45:32 +02:00
|
|
|
if (symt_check_tag(pcs->localscope_symt, SymTagFunction) ||
|
|
|
|
symt_check_tag(pcs->localscope_symt, SymTagInlineSite))
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-10-26 11:45:32 +02:00
|
|
|
struct symt_function* func = (struct symt_function*)pcs->localscope_symt;
|
|
|
|
return symt_enum_locals_helper(&pair, mask ? mask : L"*", se, func, &func->vchildren);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2010-04-07 22:23:52 +02:00
|
|
|
return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2021-08-30 09:24:04 +02:00
|
|
|
/**********************************************************
|
|
|
|
* symbol_setname
|
|
|
|
*
|
|
|
|
* Properly sets Name and NameLen in SYMBOL_INFO
|
|
|
|
* according to MaxNameLen value
|
|
|
|
*/
|
|
|
|
void symbol_setname(SYMBOL_INFO* sym_info, const char* name)
|
|
|
|
{
|
|
|
|
SIZE_T len = 0;
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
sym_info->NameLen = strlen(name);
|
|
|
|
if (sym_info->MaxNameLen)
|
|
|
|
{
|
|
|
|
len = min(sym_info->NameLen, sym_info->MaxNameLen - 1);
|
|
|
|
memcpy(sym_info->Name, name, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sym_info->NameLen = 0;
|
|
|
|
sym_info->Name[len] = '\0';
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* copy_symbolW
|
|
|
|
*
|
2008-11-23 20:53:43 +01:00
|
|
|
* Helper for transforming an ANSI symbol info into a UNICODE one.
|
2006-05-10 21:35:22 +02:00
|
|
|
* Assume that MaxNameLen is the same for both version (A & W).
|
|
|
|
*/
|
2007-03-04 17:00:50 +01:00
|
|
|
void copy_symbolW(SYMBOL_INFOW* siw, const SYMBOL_INFO* si)
|
2006-05-10 21:35:22 +02:00
|
|
|
{
|
|
|
|
siw->SizeOfStruct = si->SizeOfStruct;
|
|
|
|
siw->TypeIndex = si->TypeIndex;
|
|
|
|
siw->Reserved[0] = si->Reserved[0];
|
|
|
|
siw->Reserved[1] = si->Reserved[1];
|
2016-03-21 18:30:14 +01:00
|
|
|
siw->Index = si->Index;
|
2006-05-10 21:35:22 +02:00
|
|
|
siw->Size = si->Size;
|
|
|
|
siw->ModBase = si->ModBase;
|
|
|
|
siw->Flags = si->Flags;
|
|
|
|
siw->Value = si->Value;
|
|
|
|
siw->Address = si->Address;
|
|
|
|
siw->Register = si->Register;
|
|
|
|
siw->Scope = si->Scope;
|
|
|
|
siw->Tag = si->Tag;
|
|
|
|
siw->NameLen = si->NameLen;
|
|
|
|
siw->MaxNameLen = si->MaxNameLen;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, si->Name, -1, siw->Name, siw->MaxNameLen);
|
|
|
|
}
|
2006-05-10 21:35:34 +02:00
|
|
|
|
2021-10-28 08:58:17 +02:00
|
|
|
/* return the lowest inline site inside a function */
|
|
|
|
struct symt_inlinesite* symt_find_lowest_inlined(struct symt_function* func, DWORD64 addr)
|
|
|
|
{
|
|
|
|
struct symt_inlinesite* current;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(func->symt.tag == SymTagFunction);
|
|
|
|
for (current = func->next_inlinesite; current; current = current->func.next_inlinesite)
|
|
|
|
{
|
|
|
|
for (i = 0; i < current->vranges.num_elts; ++i)
|
|
|
|
{
|
|
|
|
struct addr_range* ar = (struct addr_range*)vector_at(¤t->vranges, i);
|
|
|
|
/* first matching range gives the lowest inline site; see dbghelp_private.h for details */
|
|
|
|
if (ar->low <= addr && addr < ar->high)
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:57:50 +02:00
|
|
|
/* from an inline function, get either the enclosing inlined function, or the top function when no inlined */
|
|
|
|
struct symt* symt_get_upper_inlined(struct symt_inlinesite* inlined)
|
|
|
|
{
|
|
|
|
struct symt* symt = &inlined->func.symt;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
assert(symt);
|
|
|
|
if (symt->tag == SymTagBlock)
|
|
|
|
symt = ((struct symt_block*)symt)->container;
|
|
|
|
else
|
|
|
|
symt = ((struct symt_function*)symt)->container;
|
|
|
|
} while (symt->tag == SymTagBlock);
|
|
|
|
assert(symt->tag == SymTagFunction || symt->tag == SymTagInlineSite);
|
|
|
|
return symt;
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:58:31 +02:00
|
|
|
/* lookup in module for an inline site (from addr and inline_ctx) */
|
|
|
|
struct symt_inlinesite* symt_find_inlined_site(struct module* module, DWORD64 addr, DWORD inline_ctx)
|
|
|
|
{
|
|
|
|
struct symt_ht* symt = symt_find_nearest(module, addr);
|
|
|
|
|
|
|
|
if (symt_check_tag(&symt->symt, SymTagFunction))
|
|
|
|
{
|
|
|
|
struct symt_function* func = (struct symt_function*)symt;
|
|
|
|
struct symt_inlinesite* curr = symt_find_lowest_inlined(func, addr);
|
|
|
|
DWORD depth = IFC_DEPTH(inline_ctx);
|
|
|
|
|
|
|
|
if (curr)
|
|
|
|
for ( ; &curr->func != func; curr = (struct symt_inlinesite*)symt_get_upper_inlined(curr))
|
|
|
|
if (depth-- == 0) return curr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:58:17 +02:00
|
|
|
DWORD symt_get_inlinesite_depth(HANDLE hProcess, DWORD64 addr)
|
|
|
|
{
|
|
|
|
struct module_pair pair;
|
|
|
|
DWORD depth = 0;
|
|
|
|
|
|
|
|
if (module_init_pair(&pair, hProcess, addr))
|
|
|
|
{
|
|
|
|
struct symt_ht* symt = symt_find_nearest(pair.effective, addr);
|
|
|
|
if (symt_check_tag(&symt->symt, SymTagFunction))
|
|
|
|
{
|
|
|
|
struct symt_inlinesite* inlined = symt_find_lowest_inlined((struct symt_function*)symt, addr);
|
|
|
|
if (inlined)
|
|
|
|
{
|
|
|
|
for ( ; &inlined->func.symt != &symt->symt; inlined = (struct symt_inlinesite*)symt_get_upper_inlined(inlined))
|
|
|
|
++depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
2006-05-10 21:35:34 +02:00
|
|
|
* sym_enum
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
2006-05-10 21:35:34 +02:00
|
|
|
* Core routine for most of the enumeration of symbols
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
2012-01-22 12:57:59 +01:00
|
|
|
static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR Mask,
|
2006-05-10 21:35:34 +02:00
|
|
|
const struct sym_enum* se)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-07 14:29:49 +02:00
|
|
|
struct module_pair pair;
|
2012-01-22 12:57:59 +01:00
|
|
|
const WCHAR* bang;
|
|
|
|
WCHAR* mod;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-11-24 22:17:10 +01:00
|
|
|
pair.pcs = process_find_by_handle(hProcess);
|
2009-12-09 00:01:29 +01:00
|
|
|
if (!pair.pcs) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
if (BaseOfDll == 0)
|
|
|
|
{
|
2004-05-24 21:08:19 +02:00
|
|
|
/* do local variables ? */
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!Mask || !(bang = wcschr(Mask, '!')))
|
2006-11-24 22:17:10 +01:00
|
|
|
return symt_enum_locals(pair.pcs, Mask, se);
|
2004-05-24 21:08:19 +02:00
|
|
|
|
|
|
|
if (bang == Mask) return FALSE;
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
mod = HeapAlloc(GetProcessHeap(), 0, (bang - Mask + 1) * sizeof(WCHAR));
|
|
|
|
if (!mod) return FALSE;
|
|
|
|
memcpy(mod, Mask, (bang - Mask) * sizeof(WCHAR));
|
|
|
|
mod[bang - Mask] = 0;
|
|
|
|
|
2006-11-24 22:17:10 +01:00
|
|
|
for (pair.requested = pair.pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-11-24 22:17:10 +01:00
|
|
|
if (pair.requested->type == DMT_PE && module_get_debug(&pair))
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-09-06 10:40:14 +02:00
|
|
|
if (SymMatchStringW(pair.requested->modulename, mod, FALSE) &&
|
2012-01-22 12:57:59 +01:00
|
|
|
symt_enum_module(&pair, bang + 1, se))
|
2004-07-04 02:10:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* not found in PE modules, retry on the ELF ones
|
|
|
|
*/
|
2019-06-07 01:44:31 +02:00
|
|
|
if (!pair.requested && dbghelp_opt_native)
|
2004-07-04 02:10:54 +02:00
|
|
|
{
|
2006-11-24 22:17:10 +01:00
|
|
|
for (pair.requested = pair.pcs->lmodules; pair.requested; pair.requested = pair.requested->next)
|
2004-07-04 02:10:54 +02:00
|
|
|
{
|
2009-03-13 17:48:00 +01:00
|
|
|
if ((pair.requested->type == DMT_ELF || pair.requested->type == DMT_MACHO) &&
|
2006-11-24 22:17:10 +01:00
|
|
|
!module_get_containee(pair.pcs, pair.requested) &&
|
|
|
|
module_get_debug(&pair))
|
2004-07-04 02:10:54 +02:00
|
|
|
{
|
2021-09-06 10:40:14 +02:00
|
|
|
if (SymMatchStringW(pair.requested->modulename, mod, FALSE) &&
|
2012-01-22 12:57:59 +01:00
|
|
|
symt_enum_module(&pair, bang + 1, se))
|
2004-07-04 02:10:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-22 12:57:59 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mod);
|
2004-05-24 21:08:19 +02:00
|
|
|
return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2006-11-24 22:17:10 +01:00
|
|
|
pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
|
|
|
|
if (!module_get_debug(&pair))
|
2004-05-24 21:08:19 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* we always ignore module name from Mask when BaseOfDll is defined */
|
2020-04-06 19:43:35 +02:00
|
|
|
if (Mask && (bang = wcschr(Mask, '!')))
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-05-24 21:08:19 +02:00
|
|
|
if (bang == Mask) return FALSE;
|
|
|
|
Mask = bang + 1;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2004-05-24 21:08:19 +02:00
|
|
|
|
2021-10-19 15:50:54 +02:00
|
|
|
symt_enum_module(&pair, Mask ? Mask : L"*", se);
|
2004-05-24 21:08:19 +02:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
static inline BOOL doSymEnumSymbols(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR Mask,
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
struct sym_enum se;
|
|
|
|
|
|
|
|
se.cb = EnumSymbolsCallback;
|
|
|
|
se.user = UserContext;
|
|
|
|
se.index = 0;
|
|
|
|
se.tag = 0;
|
|
|
|
se.addr = 0;
|
|
|
|
se.sym_info = (PSYMBOL_INFO)se.buffer;
|
|
|
|
|
|
|
|
return sym_enum(hProcess, BaseOfDll, Mask, &se);
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:34 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymEnumSymbols (DBGHELP.@)
|
|
|
|
*
|
|
|
|
* cases BaseOfDll = 0
|
|
|
|
* !foo fails always (despite what MSDN states)
|
|
|
|
* RE1!RE2 looks up all modules matching RE1, and in all these modules, lookup RE2
|
|
|
|
* no ! in Mask, lookup in local Context
|
|
|
|
* cases BaseOfDll != 0
|
|
|
|
* !foo fails always (despite what MSDN states)
|
|
|
|
* RE1!RE2 gets RE2 from BaseOfDll (whatever RE1 is)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumSymbols(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
2012-01-22 12:57:59 +01:00
|
|
|
BOOL ret;
|
|
|
|
PWSTR maskW = NULL;
|
2006-05-10 21:35:34 +02:00
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
TRACE("(%p %s %s %p %p)\n",
|
2006-05-10 21:35:34 +02:00
|
|
|
hProcess, wine_dbgstr_longlong(BaseOfDll), debugstr_a(Mask),
|
|
|
|
EnumSymbolsCallback, UserContext);
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
if (Mask)
|
|
|
|
{
|
|
|
|
DWORD sz = MultiByteToWideChar(CP_ACP, 0, Mask, -1, NULL, 0);
|
|
|
|
if (!(maskW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
|
|
|
|
return FALSE;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, Mask, -1, maskW, sz);
|
|
|
|
}
|
|
|
|
ret = doSymEnumSymbols(hProcess, BaseOfDll, maskW, EnumSymbolsCallback, UserContext);
|
|
|
|
HeapFree(GetProcessHeap(), 0, maskW);
|
|
|
|
return ret;
|
2006-05-10 21:35:34 +02:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:41 +02:00
|
|
|
struct sym_enumW
|
|
|
|
{
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACKW cb;
|
|
|
|
void* ctx;
|
|
|
|
PSYMBOL_INFOW sym_info;
|
2021-08-30 09:24:17 +02:00
|
|
|
char buffer[sizeof(SYMBOL_INFOW) + MAX_SYM_NAME * sizeof(WCHAR)];
|
2006-05-10 21:35:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK sym_enumW(PSYMBOL_INFO si, ULONG size, PVOID ctx)
|
|
|
|
{
|
|
|
|
struct sym_enumW* sew = ctx;
|
|
|
|
|
|
|
|
copy_symbolW(sew->sym_info, si);
|
|
|
|
|
|
|
|
return (sew->cb)(sew->sym_info, size, sew->ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymEnumSymbolsW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumSymbolsW(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR Mask,
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
struct sym_enumW sew;
|
|
|
|
|
|
|
|
sew.ctx = UserContext;
|
|
|
|
sew.cb = EnumSymbolsCallback;
|
|
|
|
sew.sym_info = (PSYMBOL_INFOW)sew.buffer;
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
return doSymEnumSymbols(hProcess, BaseOfDll, Mask, sym_enumW, &sew);
|
2006-05-10 21:35:41 +02:00
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
struct sym_enumerate
|
|
|
|
{
|
|
|
|
void* ctx;
|
|
|
|
PSYM_ENUMSYMBOLS_CALLBACK cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK sym_enumerate_cb(PSYMBOL_INFO syminfo, ULONG size, void* ctx)
|
|
|
|
{
|
2009-01-19 10:24:06 +01:00
|
|
|
struct sym_enumerate* se = ctx;
|
2004-04-06 00:21:27 +02:00
|
|
|
return (se->cb)(syminfo->Name, syminfo->Address, syminfo->Size, se->ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymEnumerateSymbols (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumerateSymbols(HANDLE hProcess, DWORD BaseOfDll,
|
|
|
|
PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
struct sym_enumerate se;
|
|
|
|
|
|
|
|
se.ctx = UserContext;
|
|
|
|
se.cb = EnumSymbolsCallback;
|
|
|
|
|
|
|
|
return SymEnumSymbols(hProcess, BaseOfDll, NULL, sym_enumerate_cb, &se);
|
|
|
|
}
|
|
|
|
|
2008-06-20 05:02:44 +02:00
|
|
|
struct sym_enumerate64
|
|
|
|
{
|
|
|
|
void* ctx;
|
|
|
|
PSYM_ENUMSYMBOLS_CALLBACK64 cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK sym_enumerate_cb64(PSYMBOL_INFO syminfo, ULONG size, void* ctx)
|
|
|
|
{
|
2009-01-19 10:24:06 +01:00
|
|
|
struct sym_enumerate64* se = ctx;
|
2008-06-20 05:02:44 +02:00
|
|
|
return (se->cb)(syminfo->Name, syminfo->Address, syminfo->Size, se->ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymEnumerateSymbols64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumerateSymbols64(HANDLE hProcess, DWORD64 BaseOfDll,
|
|
|
|
PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
struct sym_enumerate64 se;
|
|
|
|
|
|
|
|
se.ctx = UserContext;
|
|
|
|
se.cb = EnumSymbolsCallback;
|
|
|
|
|
|
|
|
return SymEnumSymbols(hProcess, BaseOfDll, NULL, sym_enumerate_cb64, &se);
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymFromAddr (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2004-10-11 23:00:17 +02:00
|
|
|
BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address,
|
|
|
|
DWORD64* Displacement, PSYMBOL_INFO Symbol)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-07 14:29:49 +02:00
|
|
|
struct module_pair pair;
|
2004-04-06 00:21:27 +02:00
|
|
|
struct symt_ht* sym;
|
|
|
|
|
2021-10-13 15:17:33 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, Address)) return FALSE;
|
2006-12-05 22:13:23 +01:00
|
|
|
if ((sym = symt_find_nearest(pair.effective, Address)) == NULL) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-11-24 22:17:16 +01:00
|
|
|
symt_fill_sym_info(&pair, NULL, &sym->symt, Symbol);
|
2013-12-01 22:07:20 +01:00
|
|
|
if (Displacement)
|
2018-11-25 10:15:50 +01:00
|
|
|
*Displacement = (Address >= Symbol->Address) ? (Address - Symbol->Address) : (DWORD64)-1;
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymFromAddrW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFromAddrW(HANDLE hProcess, DWORD64 Address,
|
|
|
|
DWORD64* Displacement, PSYMBOL_INFOW Symbol)
|
|
|
|
{
|
|
|
|
PSYMBOL_INFO si;
|
|
|
|
unsigned len;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
len = sizeof(*si) + Symbol->MaxNameLen * sizeof(WCHAR);
|
|
|
|
si = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (!si) return FALSE;
|
|
|
|
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
|
|
|
si->MaxNameLen = Symbol->MaxNameLen;
|
|
|
|
if ((ret = SymFromAddr(hProcess, Address, Displacement, si)))
|
|
|
|
{
|
|
|
|
copy_symbolW(Symbol, si);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, si);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetSymFromAddr (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetSymFromAddr(HANDLE hProcess, DWORD Address,
|
|
|
|
PDWORD Displacement, PIMAGEHLP_SYMBOL Symbol)
|
|
|
|
{
|
2006-01-23 16:26:57 +01:00
|
|
|
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
2004-04-06 00:21:27 +02:00
|
|
|
SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
|
|
|
|
size_t len;
|
2004-10-11 23:00:17 +02:00
|
|
|
DWORD64 Displacement64;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
2006-01-23 16:26:57 +01:00
|
|
|
si->MaxNameLen = MAX_SYM_NAME;
|
2004-10-11 23:00:17 +02:00
|
|
|
if (!SymFromAddr(hProcess, Address, &Displacement64, si))
|
2004-04-06 00:21:27 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2004-10-11 23:00:17 +02:00
|
|
|
if (Displacement)
|
|
|
|
*Displacement = Displacement64;
|
2004-04-06 00:21:27 +02:00
|
|
|
Symbol->Address = si->Address;
|
|
|
|
Symbol->Size = si->Size;
|
|
|
|
Symbol->Flags = si->Flags;
|
|
|
|
len = min(Symbol->MaxNameLength, si->MaxNameLen);
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynA(Symbol->Name, si->Name, len);
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-25 11:35:49 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetSymFromAddr64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetSymFromAddr64(HANDLE hProcess, DWORD64 Address,
|
|
|
|
PDWORD64 Displacement, PIMAGEHLP_SYMBOL64 Symbol)
|
|
|
|
{
|
|
|
|
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
|
|
|
SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
|
|
|
|
size_t len;
|
|
|
|
DWORD64 Displacement64;
|
|
|
|
|
|
|
|
if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
|
|
|
si->MaxNameLen = MAX_SYM_NAME;
|
|
|
|
if (!SymFromAddr(hProcess, Address, &Displacement64, si))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (Displacement)
|
|
|
|
*Displacement = Displacement64;
|
|
|
|
Symbol->Address = si->Address;
|
|
|
|
Symbol->Size = si->Size;
|
|
|
|
Symbol->Flags = si->Flags;
|
|
|
|
len = min(Symbol->MaxNameLength, si->MaxNameLen);
|
|
|
|
lstrcpynA(Symbol->Name, si->Name, len);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:29:49 +02:00
|
|
|
static BOOL find_name(struct process* pcs, struct module* module, const char* name,
|
|
|
|
SYMBOL_INFO* symbol)
|
|
|
|
{
|
|
|
|
struct hash_table_iter hti;
|
|
|
|
void* ptr;
|
|
|
|
struct symt_ht* sym = NULL;
|
|
|
|
struct module_pair pair;
|
|
|
|
|
2006-11-24 22:17:10 +01:00
|
|
|
pair.pcs = pcs;
|
2006-05-07 14:29:49 +02:00
|
|
|
if (!(pair.requested = module)) return FALSE;
|
2006-11-24 22:17:10 +01:00
|
|
|
if (!module_get_debug(&pair)) return FALSE;
|
2006-05-07 14:29:49 +02:00
|
|
|
|
|
|
|
hash_table_iter_init(&pair.effective->ht_symbols, &hti, name);
|
|
|
|
while ((ptr = hash_table_iter_up(&hti)))
|
|
|
|
{
|
2016-03-08 11:44:26 +01:00
|
|
|
sym = CONTAINING_RECORD(ptr, struct symt_ht, hash_elt);
|
2006-05-07 14:29:49 +02:00
|
|
|
|
|
|
|
if (!strcmp(sym->hash_elt.name, name))
|
|
|
|
{
|
2006-11-24 22:17:16 +01:00
|
|
|
symt_fill_sym_info(&pair, NULL, &sym->symt, symbol);
|
2006-05-07 14:29:49 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymFromName (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2006-01-23 16:37:48 +01:00
|
|
|
BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
struct module* module;
|
2004-05-24 21:08:19 +02:00
|
|
|
const char* name;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", hProcess, Name, Symbol);
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
|
2004-05-24 21:08:19 +02:00
|
|
|
name = strchr(Name, '!');
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
char tmp[128];
|
|
|
|
assert(name - Name < sizeof(tmp));
|
|
|
|
memcpy(tmp, Name, name - Name);
|
|
|
|
tmp[name - Name] = '\0';
|
2007-03-13 17:33:02 +01:00
|
|
|
module = module_find_by_nameA(pcs, tmp);
|
2006-09-06 18:55:40 +02:00
|
|
|
return find_name(pcs, module, name + 1, Symbol);
|
2004-05-24 21:08:19 +02:00
|
|
|
}
|
2006-05-07 14:29:49 +02:00
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-07 14:29:49 +02:00
|
|
|
if (module->type == DMT_PE && find_name(pcs, module, Name, Symbol))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* not found in PE modules, retry on the ELF ones
|
|
|
|
*/
|
2019-06-07 01:44:31 +02:00
|
|
|
if (dbghelp_opt_native)
|
2006-05-07 14:29:49 +02:00
|
|
|
{
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
2004-05-24 21:08:19 +02:00
|
|
|
{
|
2009-03-13 17:48:00 +01:00
|
|
|
if ((module->type == DMT_ELF || module->type == DMT_MACHO) &&
|
|
|
|
!module_get_containee(pcs, module) &&
|
2006-05-07 14:29:49 +02:00
|
|
|
find_name(pcs, module, Name, Symbol))
|
2004-05-24 21:08:19 +02:00
|
|
|
return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-04-22 12:20:18 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymFromNameW (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFromNameW(HANDLE process, const WCHAR *name, SYMBOL_INFOW *symbol)
|
|
|
|
{
|
|
|
|
SYMBOL_INFO *si;
|
|
|
|
DWORD len;
|
|
|
|
char *tmp;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", process, debugstr_w(name), symbol);
|
|
|
|
|
2021-08-30 09:24:17 +02:00
|
|
|
len = sizeof(*si) + symbol->MaxNameLen;
|
2021-04-22 12:20:18 +02:00
|
|
|
if (!(si = HeapAlloc(GetProcessHeap(), 0, len))) return FALSE;
|
|
|
|
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (!(tmp = HeapAlloc(GetProcessHeap(), 0, len)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, si);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, name, -1, tmp, len, NULL, NULL);
|
|
|
|
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
|
|
|
si->MaxNameLen = symbol->MaxNameLen;
|
|
|
|
if ((ret = SymFromName(process, tmp, si)))
|
|
|
|
copy_symbolW(symbol, si);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, tmp);
|
|
|
|
HeapFree(GetProcessHeap(), 0, si);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-23 12:41:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymGetSymFromName64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetSymFromName64(HANDLE hProcess, PCSTR Name, PIMAGEHLP_SYMBOL64 Symbol)
|
|
|
|
{
|
|
|
|
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
|
|
|
SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
|
|
|
si->MaxNameLen = MAX_SYM_NAME;
|
|
|
|
if (!SymFromName(hProcess, Name, si)) return FALSE;
|
|
|
|
|
|
|
|
Symbol->Address = si->Address;
|
|
|
|
Symbol->Size = si->Size;
|
|
|
|
Symbol->Flags = si->Flags;
|
|
|
|
len = min(Symbol->MaxNameLength, si->MaxNameLen);
|
|
|
|
lstrcpynA(Symbol->Name, si->Name, len);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymGetSymFromName (DBGHELP.@)
|
|
|
|
*/
|
2006-01-23 16:37:48 +01:00
|
|
|
BOOL WINAPI SymGetSymFromName(HANDLE hProcess, PCSTR Name, PIMAGEHLP_SYMBOL Symbol)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-01-23 16:26:57 +01:00
|
|
|
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
2004-04-06 00:21:27 +02:00
|
|
|
SYMBOL_INFO*si = (SYMBOL_INFO*)buffer;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (Symbol->SizeOfStruct < sizeof(*Symbol)) return FALSE;
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
2006-01-23 16:26:57 +01:00
|
|
|
si->MaxNameLen = MAX_SYM_NAME;
|
2004-04-06 00:21:27 +02:00
|
|
|
if (!SymFromName(hProcess, Name, si)) return FALSE;
|
|
|
|
|
|
|
|
Symbol->Address = si->Address;
|
|
|
|
Symbol->Size = si->Size;
|
|
|
|
Symbol->Flags = si->Flags;
|
|
|
|
len = min(Symbol->MaxNameLength, si->MaxNameLen);
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynA(Symbol->Name, si->Name, len);
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:26:43 +02:00
|
|
|
struct internal_line_t
|
|
|
|
{
|
|
|
|
BOOL unicode;
|
|
|
|
PVOID key;
|
|
|
|
DWORD line_number;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
CHAR* file_nameA;
|
|
|
|
WCHAR* file_nameW;
|
|
|
|
};
|
|
|
|
DWORD64 address;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void init_internal_line(struct internal_line_t* intl, BOOL unicode)
|
|
|
|
{
|
|
|
|
intl->unicode = unicode;
|
|
|
|
intl->key = NULL;
|
|
|
|
intl->line_number = 0;
|
|
|
|
intl->file_nameA = NULL;
|
|
|
|
intl->address = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL internal_line_copy_toA32(const struct internal_line_t* intl, IMAGEHLP_LINE* l32)
|
|
|
|
{
|
|
|
|
if (intl->unicode) return FALSE;
|
|
|
|
l32->Key = intl->key;
|
|
|
|
l32->LineNumber = intl->line_number;
|
|
|
|
l32->FileName = intl->file_nameA;
|
|
|
|
l32->Address = intl->address;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL internal_line_copy_toA64(const struct internal_line_t* intl, IMAGEHLP_LINE64* l64)
|
|
|
|
{
|
|
|
|
if (intl->unicode) return FALSE;
|
|
|
|
l64->Key = intl->key;
|
|
|
|
l64->LineNumber = intl->line_number;
|
|
|
|
l64->FileName = intl->file_nameA;
|
|
|
|
l64->Address = intl->address;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL internal_line_copy_toW64(const struct internal_line_t* intl, IMAGEHLP_LINEW64* l64)
|
|
|
|
{
|
|
|
|
if (!intl->unicode) return FALSE;
|
|
|
|
l64->Key = intl->key;
|
|
|
|
l64->LineNumber = intl->line_number;
|
|
|
|
l64->FileName = intl->file_nameW;
|
|
|
|
l64->Address = intl->address;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL internal_line_set_nameA(struct process* pcs, struct internal_line_t* intl, char* str, BOOL copy)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (intl->unicode)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
|
|
|
if (!(intl->file_nameW = fetch_buffer(pcs, len * sizeof(WCHAR)))) return FALSE;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, -1, intl->file_nameW, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (copy)
|
|
|
|
{
|
|
|
|
len = strlen(str) + 1;
|
|
|
|
if (!(intl->file_nameA = fetch_buffer(pcs, len))) return FALSE;
|
|
|
|
memcpy(intl->file_nameA, str, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
intl->file_nameA = str;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL internal_line_set_nameW(struct process* pcs, struct internal_line_t* intl, WCHAR* wstr, BOOL copy)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (intl->unicode)
|
|
|
|
{
|
|
|
|
if (copy)
|
|
|
|
{
|
|
|
|
len = (lstrlenW(wstr) + 1) * sizeof(WCHAR);
|
|
|
|
if (!(intl->file_nameW = fetch_buffer(pcs, len))) return FALSE;
|
|
|
|
memcpy(intl->file_nameW, wstr, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
intl->file_nameW = wstr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (!(intl->file_nameA = fetch_buffer(pcs, len))) return FALSE;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, wstr, -1, intl->file_nameA, len, NULL, NULL);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-29 15:37:31 +02:00
|
|
|
static BOOL get_line_from_function(struct module_pair* pair, struct symt_function* func, DWORD64 addr,
|
|
|
|
PDWORD pdwDisplacement, struct internal_line_t* intl)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-09-07 09:26:43 +02:00
|
|
|
struct line_info* dli = NULL;
|
2021-10-29 15:37:17 +02:00
|
|
|
struct line_info* found_dli = NULL;
|
2021-09-07 09:26:43 +02:00
|
|
|
int i;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2021-10-29 15:37:31 +02:00
|
|
|
for (i = vector_length(&func->vlines) - 1; i >= 0; i--)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-05-15 02:05:12 +02:00
|
|
|
dli = vector_at(&func->vlines, i);
|
2004-04-30 06:15:41 +02:00
|
|
|
if (!dli->is_source_file)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-10-29 15:37:17 +02:00
|
|
|
if (found_dli || dli->u.address > addr) continue;
|
2021-09-07 09:26:43 +02:00
|
|
|
intl->line_number = dli->line_number;
|
2021-10-29 15:36:51 +02:00
|
|
|
intl->address = dli->u.address;
|
2021-09-07 09:26:43 +02:00
|
|
|
intl->key = dli;
|
2021-10-29 15:37:17 +02:00
|
|
|
found_dli = dli;
|
2004-04-06 00:21:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-10-29 15:37:17 +02:00
|
|
|
if (found_dli)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-09-07 09:26:43 +02:00
|
|
|
BOOL ret;
|
2019-06-13 10:29:58 +02:00
|
|
|
if (dbghelp_opt_native)
|
|
|
|
{
|
|
|
|
/* Return native file paths when using winedbg */
|
2021-10-29 15:37:31 +02:00
|
|
|
ret = internal_line_set_nameA(pair->pcs, intl, (char*)source_get(pair->effective, dli->u.source_file), FALSE);
|
2019-06-13 10:29:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-29 15:37:31 +02:00
|
|
|
WCHAR *dospath = wine_get_dos_file_name(source_get(pair->effective, dli->u.source_file));
|
|
|
|
ret = internal_line_set_nameW(pair->pcs, intl, dospath, TRUE);
|
2019-06-13 10:29:58 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, dospath );
|
|
|
|
}
|
2021-10-29 15:37:17 +02:00
|
|
|
if (ret) *pdwDisplacement = addr - found_dli->u.address;
|
2021-09-07 09:26:43 +02:00
|
|
|
return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-29 15:37:31 +02:00
|
|
|
/******************************************************************
|
|
|
|
* get_line_from_addr
|
|
|
|
*
|
|
|
|
* fills source file information from an address
|
|
|
|
*/
|
|
|
|
static BOOL get_line_from_addr(HANDLE hProcess, DWORD64 addr,
|
|
|
|
PDWORD pdwDisplacement, struct internal_line_t* intl)
|
|
|
|
{
|
|
|
|
struct module_pair pair;
|
|
|
|
struct symt_ht* symt;
|
|
|
|
|
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
|
|
|
if ((symt = symt_find_nearest(pair.effective, addr)) == NULL) return FALSE;
|
|
|
|
|
|
|
|
if (symt->symt.tag != SymTagFunction && symt->symt.tag != SymTagInlineSite) return FALSE;
|
|
|
|
return get_line_from_function(&pair, (struct symt_function*)symt, addr, pdwDisplacement, intl);
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
2009-04-23 12:41:29 +02:00
|
|
|
* SymGetSymNext64 (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
2009-04-23 12:41:29 +02:00
|
|
|
BOOL WINAPI SymGetSymNext64(HANDLE hProcess, PIMAGEHLP_SYMBOL64 Symbol)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
/* algo:
|
|
|
|
* get module from Symbol.Address
|
|
|
|
* get index in module.addr_sorttab of Symbol.Address
|
|
|
|
* increment index
|
|
|
|
* if out of module bounds, move to next module in process address space
|
|
|
|
*/
|
|
|
|
FIXME("(%p, %p): stub\n", hProcess, Symbol);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-04-23 12:41:29 +02:00
|
|
|
* SymGetSymNext (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
2009-04-23 12:41:29 +02:00
|
|
|
BOOL WINAPI SymGetSymNext(HANDLE hProcess, PIMAGEHLP_SYMBOL Symbol)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", hProcess, Symbol);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymGetSymPrev64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetSymPrev64(HANDLE hProcess, PIMAGEHLP_SYMBOL64 Symbol)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", hProcess, Symbol);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2009-04-23 12:41:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymGetSymPrev (DBGHELP.@)
|
|
|
|
*/
|
2004-04-06 00:21:27 +02:00
|
|
|
BOOL WINAPI SymGetSymPrev(HANDLE hProcess, PIMAGEHLP_SYMBOL Symbol)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", hProcess, Symbol);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:06:17 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetLineFromAddr (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLineFromAddr(HANDLE hProcess, DWORD dwAddr,
|
|
|
|
PDWORD pdwDisplacement, PIMAGEHLP_LINE Line)
|
|
|
|
{
|
2021-09-07 09:26:43 +02:00
|
|
|
struct internal_line_t intl;
|
2009-12-14 22:06:17 +01:00
|
|
|
|
2021-09-07 09:26:43 +02:00
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
if (!get_line_from_addr(hProcess, dwAddr, pdwDisplacement, &intl)) return FALSE;
|
|
|
|
return internal_line_copy_toA32(&intl, Line);
|
2009-12-14 22:06:17 +01:00
|
|
|
}
|
|
|
|
|
2005-11-29 11:45:28 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetLineFromAddr64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLineFromAddr64(HANDLE hProcess, DWORD64 dwAddr,
|
|
|
|
PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line)
|
|
|
|
{
|
2021-09-07 09:26:43 +02:00
|
|
|
struct internal_line_t intl;
|
2009-12-14 22:06:17 +01:00
|
|
|
|
2021-09-07 09:26:43 +02:00
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
2005-11-29 11:45:28 +01:00
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
2021-09-07 09:26:43 +02:00
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
if (!get_line_from_addr(hProcess, dwAddr, pdwDisplacement, &intl)) return FALSE;
|
|
|
|
return internal_line_copy_toA64(&intl, Line);
|
2005-11-29 11:45:28 +01:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:26 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetLineFromAddrW64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLineFromAddrW64(HANDLE hProcess, DWORD64 dwAddr,
|
|
|
|
PDWORD pdwDisplacement, PIMAGEHLP_LINEW64 Line)
|
|
|
|
{
|
2021-09-07 09:26:43 +02:00
|
|
|
struct internal_line_t intl;
|
2006-05-10 21:35:26 +02:00
|
|
|
|
2021-09-07 09:26:43 +02:00
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, TRUE);
|
|
|
|
if (!get_line_from_addr(hProcess, dwAddr, pdwDisplacement, &intl)) return FALSE;
|
|
|
|
return internal_line_copy_toW64(&intl, Line);
|
2006-05-10 21:35:26 +02:00
|
|
|
}
|
|
|
|
|
2021-09-07 09:26:55 +02:00
|
|
|
static BOOL symt_get_func_line_prev(HANDLE hProcess, struct internal_line_t* intl, void* key, DWORD64 addr)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-07 14:29:49 +02:00
|
|
|
struct module_pair pair;
|
2004-04-06 00:21:27 +02:00
|
|
|
struct line_info* li;
|
2021-09-07 09:26:55 +02:00
|
|
|
struct line_info* srcli;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2021-10-13 15:17:33 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2021-09-07 09:26:55 +02:00
|
|
|
if (key == NULL) return FALSE;
|
|
|
|
|
|
|
|
li = key;
|
|
|
|
|
2004-04-30 06:15:41 +02:00
|
|
|
while (!li->is_first)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
li--;
|
2004-04-30 06:15:41 +02:00
|
|
|
if (!li->is_source_file)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-09-07 09:26:55 +02:00
|
|
|
intl->line_number = li->line_number;
|
2021-10-29 15:36:51 +02:00
|
|
|
intl->address = li->u.address;
|
2021-09-07 09:26:55 +02:00
|
|
|
intl->key = li;
|
|
|
|
/* search source file */
|
|
|
|
for (srcli = li; !srcli->is_source_file; srcli--);
|
|
|
|
|
|
|
|
return internal_line_set_nameA(pair.pcs, intl, (char*)source_get(pair.effective, srcli->u.source_file), FALSE);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS); /* FIXME */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-29 11:45:28 +01:00
|
|
|
/******************************************************************
|
2021-09-07 09:26:55 +02:00
|
|
|
* SymGetLinePrev64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLinePrev64(HANDLE hProcess, PIMAGEHLP_LINE64 Line)
|
|
|
|
{
|
|
|
|
struct internal_line_t intl;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
if (!symt_get_func_line_prev(hProcess, &intl, Line->Key, Line->Address)) return FALSE;
|
|
|
|
return internal_line_copy_toA64(&intl, Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetLinePrev (DBGHELP.@)
|
2005-11-29 11:45:28 +01:00
|
|
|
*
|
|
|
|
*/
|
2009-12-14 22:06:17 +01:00
|
|
|
BOOL WINAPI SymGetLinePrev(HANDLE hProcess, PIMAGEHLP_LINE Line)
|
2005-11-29 11:45:28 +01:00
|
|
|
{
|
2021-09-07 09:26:55 +02:00
|
|
|
struct internal_line_t intl;
|
2005-11-29 11:45:28 +01:00
|
|
|
|
2021-09-07 09:26:55 +02:00
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
if (!symt_get_func_line_prev(hProcess, &intl, Line->Key, Line->Address)) return FALSE;
|
|
|
|
return internal_line_copy_toA32(&intl, Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetLinePrevW64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLinePrevW64(HANDLE hProcess, PIMAGEHLP_LINEW64 Line)
|
|
|
|
{
|
|
|
|
struct internal_line_t intl;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, TRUE);
|
|
|
|
if (!symt_get_func_line_prev(hProcess, &intl, Line->Key, Line->Address)) return FALSE;
|
|
|
|
return internal_line_copy_toW64(&intl, Line);
|
2005-11-29 11:45:28 +01:00
|
|
|
}
|
2009-12-14 22:06:17 +01:00
|
|
|
|
2021-09-07 09:26:49 +02:00
|
|
|
static BOOL symt_get_func_line_next(HANDLE hProcess, struct internal_line_t* intl, void* key, DWORD64 addr)
|
2004-04-19 04:58:27 +02:00
|
|
|
{
|
2021-09-07 09:26:49 +02:00
|
|
|
struct module_pair pair;
|
2004-04-19 04:58:27 +02:00
|
|
|
struct line_info* li;
|
2021-09-07 09:26:49 +02:00
|
|
|
struct line_info* srcli;
|
|
|
|
|
|
|
|
if (key == NULL) return FALSE;
|
2021-10-13 15:17:33 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
2004-04-19 04:58:27 +02:00
|
|
|
|
2021-09-07 09:26:49 +02:00
|
|
|
/* search current source file */
|
|
|
|
for (srcli = key; !srcli->is_source_file; srcli--);
|
|
|
|
|
|
|
|
li = key;
|
2004-04-30 06:15:41 +02:00
|
|
|
while (!li->is_last)
|
2004-04-19 04:58:27 +02:00
|
|
|
{
|
|
|
|
li++;
|
2004-04-30 06:15:41 +02:00
|
|
|
if (!li->is_source_file)
|
2004-04-19 04:58:27 +02:00
|
|
|
{
|
2021-09-07 09:26:49 +02:00
|
|
|
intl->line_number = li->line_number;
|
2021-10-29 15:36:51 +02:00
|
|
|
intl->address = li->u.address;
|
2021-09-07 09:26:49 +02:00
|
|
|
intl->key = li;
|
|
|
|
return internal_line_set_nameA(pair.pcs, intl, (char*)source_get(pair.effective, srcli->u.source_file), FALSE);
|
2004-04-19 04:58:27 +02:00
|
|
|
}
|
2021-09-07 09:26:49 +02:00
|
|
|
srcli = li;
|
2004-04-19 04:58:27 +02:00
|
|
|
}
|
2021-09-07 09:26:49 +02:00
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS); /* FIXME */
|
2004-04-19 04:58:27 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
2009-12-14 22:06:17 +01:00
|
|
|
* SymGetLineNext64 (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2009-12-14 22:06:17 +01:00
|
|
|
BOOL WINAPI SymGetLineNext64(HANDLE hProcess, PIMAGEHLP_LINE64 Line)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2021-09-07 09:26:49 +02:00
|
|
|
struct internal_line_t intl;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
2021-09-07 09:26:49 +02:00
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
if (!symt_get_func_line_next(hProcess, &intl, Line->Key, Line->Address)) return FALSE;
|
|
|
|
return internal_line_copy_toA64(&intl, Line);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2005-11-29 11:45:28 +01:00
|
|
|
/******************************************************************
|
2009-12-14 22:06:17 +01:00
|
|
|
* SymGetLineNext (DBGHELP.@)
|
2005-11-29 11:45:28 +01:00
|
|
|
*
|
|
|
|
*/
|
2009-12-14 22:06:17 +01:00
|
|
|
BOOL WINAPI SymGetLineNext(HANDLE hProcess, PIMAGEHLP_LINE Line)
|
2005-11-29 11:45:28 +01:00
|
|
|
{
|
2021-09-07 09:26:49 +02:00
|
|
|
struct internal_line_t intl;
|
2005-11-29 11:45:28 +01:00
|
|
|
|
2021-09-07 09:26:49 +02:00
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
if (!symt_get_func_line_next(hProcess, &intl, Line->Key, Line->Address)) return FALSE;
|
|
|
|
return internal_line_copy_toA32(&intl, Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetLineNextW64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLineNextW64(HANDLE hProcess, PIMAGEHLP_LINEW64 Line)
|
|
|
|
{
|
|
|
|
struct internal_line_t intl;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", hProcess, Line);
|
|
|
|
|
|
|
|
if (Line->SizeOfStruct < sizeof(*Line)) return FALSE;
|
|
|
|
init_internal_line(&intl, TRUE);
|
|
|
|
if (!symt_get_func_line_next(hProcess, &intl, Line->Key, Line->Address)) return FALSE;
|
|
|
|
return internal_line_copy_toW64(&intl, Line);
|
2005-11-29 11:45:28 +01:00
|
|
|
}
|
2009-12-14 22:06:17 +01:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymUnDName (DBGHELP.@)
|
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
BOOL WINAPI SymUnDName(PIMAGEHLP_SYMBOL sym, PSTR UnDecName, DWORD UnDecNameLength)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2009-04-23 12:41:29 +02:00
|
|
|
return UnDecorateSymbolName(sym->Name, UnDecName, UnDecNameLength,
|
|
|
|
UNDNAME_COMPLETE) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymUnDName64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymUnDName64(PIMAGEHLP_SYMBOL64 sym, PSTR UnDecName, DWORD UnDecNameLength)
|
|
|
|
{
|
2006-11-29 22:04:27 +01:00
|
|
|
return UnDecorateSymbolName(sym->Name, UnDecName, UnDecNameLength,
|
2004-11-19 19:02:47 +01:00
|
|
|
UNDNAME_COMPLETE) != 0;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-06 08:22:22 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* UnDecorateSymbolName (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI UnDecorateSymbolName(const char *decorated_name, char *undecorated_name,
|
|
|
|
DWORD undecorated_length, DWORD flags)
|
|
|
|
{
|
|
|
|
TRACE("(%s, %p, %d, 0x%08x)\n",
|
|
|
|
debugstr_a(decorated_name), undecorated_name, undecorated_length, flags);
|
|
|
|
|
|
|
|
if (!undecorated_name || !undecorated_length)
|
|
|
|
return 0;
|
2021-04-22 03:25:00 +02:00
|
|
|
if (!__unDName(undecorated_name, decorated_name, undecorated_length, malloc, free, flags))
|
2015-08-06 08:22:22 +02:00
|
|
|
return 0;
|
|
|
|
return strlen(undecorated_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnDecorateSymbolNameW (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI UnDecorateSymbolNameW(const WCHAR *decorated_name, WCHAR *undecorated_name,
|
|
|
|
DWORD undecorated_length, DWORD flags)
|
|
|
|
{
|
|
|
|
char *buf, *ptr;
|
|
|
|
int len, ret = 0;
|
|
|
|
|
|
|
|
TRACE("(%s, %p, %d, 0x%08x)\n",
|
|
|
|
debugstr_w(decorated_name), undecorated_name, undecorated_length, flags);
|
|
|
|
|
|
|
|
if (!undecorated_name || !undecorated_length)
|
2004-11-19 19:02:47 +01:00
|
|
|
return 0;
|
2015-08-06 08:22:22 +02:00
|
|
|
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, decorated_name, -1, NULL, 0, NULL, NULL);
|
|
|
|
if ((buf = HeapAlloc(GetProcessHeap(), 0, len)))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, decorated_name, -1, buf, len, NULL, NULL);
|
2021-04-22 03:25:00 +02:00
|
|
|
if ((ptr = __unDName(NULL, buf, 0, malloc, free, flags)))
|
2015-08-06 08:22:22 +02:00
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ptr, -1, undecorated_name, undecorated_length);
|
|
|
|
undecorated_name[undecorated_length - 1] = 0;
|
2020-04-06 19:43:35 +02:00
|
|
|
ret = lstrlenW(undecorated_name);
|
2021-04-22 03:25:00 +02:00
|
|
|
free(ptr);
|
2015-08-06 08:22:22 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2005-12-19 18:16:35 +01:00
|
|
|
|
2012-01-22 12:57:53 +01:00
|
|
|
#define WILDCHAR(x) (-(x))
|
|
|
|
|
|
|
|
static int re_fetch_char(const WCHAR** re)
|
|
|
|
{
|
|
|
|
switch (**re)
|
|
|
|
{
|
|
|
|
case '\\': (*re)++; return *(*re)++;
|
|
|
|
case '*': case '[': case '?': case '+': case '#': case ']': return WILDCHAR(*(*re)++);
|
|
|
|
default: return *(*re)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int re_match_char(WCHAR ch1, WCHAR ch2, BOOL _case)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
return _case ? ch1 - ch2 : towupper(ch1) - towupper(ch2);
|
2012-01-22 12:57:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const WCHAR* re_match_one(const WCHAR* string, const WCHAR* elt, BOOL _case)
|
|
|
|
{
|
|
|
|
int ch1, prev = 0;
|
|
|
|
unsigned state = 0;
|
|
|
|
|
|
|
|
switch (ch1 = re_fetch_char(&elt))
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return (ch1 >= 0 && re_match_char(*string, ch1, _case) == 0) ? ++string : NULL;
|
|
|
|
case WILDCHAR('?'): return *string ? ++string : NULL;
|
|
|
|
case WILDCHAR('*'): assert(0);
|
|
|
|
case WILDCHAR('['): break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ch1 = re_fetch_char(&elt);
|
|
|
|
if (ch1 == WILDCHAR(']')) return NULL;
|
|
|
|
if (state == 1 && ch1 == '-') state = 2;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (re_match_char(*string, ch1, _case) == 0) return ++string;
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
state = 1;
|
|
|
|
prev = ch1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (prev >= 0 && ch1 >= 0 && re_match_char(prev, *string, _case) <= 0 &&
|
|
|
|
re_match_char(*string, ch1, _case) <= 0)
|
|
|
|
return ++string;
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* re_match_multi
|
|
|
|
*
|
|
|
|
* match a substring of *pstring according to *pre regular expression
|
|
|
|
* pstring and pre are only updated in case of successful match
|
|
|
|
*/
|
|
|
|
static BOOL re_match_multi(const WCHAR** pstring, const WCHAR** pre, BOOL _case)
|
|
|
|
{
|
|
|
|
const WCHAR* re_end = *pre;
|
|
|
|
const WCHAR* string_end = *pstring;
|
|
|
|
const WCHAR* re_beg;
|
|
|
|
const WCHAR* string_beg;
|
|
|
|
const WCHAR* next;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
while (*re_end && *string_end)
|
|
|
|
{
|
|
|
|
string_beg = string_end;
|
|
|
|
re_beg = re_end;
|
|
|
|
switch (ch = re_fetch_char(&re_end))
|
|
|
|
{
|
|
|
|
case WILDCHAR(']'): case WILDCHAR('+'): case WILDCHAR('#'): return FALSE;
|
|
|
|
case WILDCHAR('*'):
|
|
|
|
/* transform '*' into '?#' */
|
2021-10-19 15:50:54 +02:00
|
|
|
re_beg = L"?";
|
2012-01-22 12:57:53 +01:00
|
|
|
goto closure;
|
|
|
|
case WILDCHAR('['):
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(ch = re_fetch_char(&re_end))) return FALSE;
|
|
|
|
} while (ch != WILDCHAR(']'));
|
|
|
|
/* fall through */
|
|
|
|
case WILDCHAR('?'):
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*re_end)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
if (!(next = re_match_one(string_end, re_beg, _case))) return FALSE;
|
|
|
|
string_beg++;
|
|
|
|
/* fall through */
|
|
|
|
case '#':
|
|
|
|
re_end++;
|
|
|
|
closure:
|
|
|
|
while ((next = re_match_one(string_end, re_beg, _case))) string_end = next;
|
|
|
|
for ( ; string_end >= string_beg; string_end--)
|
|
|
|
{
|
|
|
|
if (re_match_multi(&string_end, &re_end, _case)) goto found;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
if (!(next = re_match_one(string_end, re_beg, _case))) return FALSE;
|
|
|
|
string_end = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*re_end || *string_end) return FALSE;
|
|
|
|
|
|
|
|
found:
|
|
|
|
*pre = re_end;
|
|
|
|
*pstring = string_end;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-12-19 18:16:35 +01:00
|
|
|
/******************************************************************
|
2011-10-31 20:07:32 +01:00
|
|
|
* SymMatchStringA (DBGHELP.@)
|
2005-12-19 18:16:35 +01:00
|
|
|
*
|
|
|
|
*/
|
2011-10-31 20:07:32 +01:00
|
|
|
BOOL WINAPI SymMatchStringA(PCSTR string, PCSTR re, BOOL _case)
|
2005-12-19 18:16:35 +01:00
|
|
|
{
|
2012-01-22 12:57:53 +01:00
|
|
|
WCHAR* strW;
|
|
|
|
WCHAR* reW;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
DWORD sz;
|
2005-12-19 18:16:35 +01:00
|
|
|
|
2012-01-22 12:57:53 +01:00
|
|
|
if (!string || !re)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-12-19 18:16:35 +01:00
|
|
|
TRACE("%s %s %c\n", string, re, _case ? 'Y' : 'N');
|
|
|
|
|
2012-01-22 12:57:53 +01:00
|
|
|
sz = MultiByteToWideChar(CP_ACP, 0, string, -1, NULL, 0);
|
|
|
|
if ((strW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, string, -1, strW, sz);
|
|
|
|
sz = MultiByteToWideChar(CP_ACP, 0, re, -1, NULL, 0);
|
|
|
|
if ((reW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, re, -1, reW, sz);
|
|
|
|
|
|
|
|
if (strW && reW)
|
|
|
|
ret = SymMatchStringW(strW, reW, _case);
|
|
|
|
HeapFree(GetProcessHeap(), 0, strW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, reW);
|
2005-12-19 18:16:35 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:08:00 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymMatchStringW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymMatchStringW(PCWSTR string, PCWSTR re, BOOL _case)
|
|
|
|
{
|
|
|
|
TRACE("%s %s %c\n", debugstr_w(string), debugstr_w(re), _case ? 'Y' : 'N');
|
|
|
|
|
2012-01-22 12:57:53 +01:00
|
|
|
if (!string || !re)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return re_match_multi(&string, &re, _case);
|
2011-10-31 20:08:00 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
static inline BOOL doSymSearch(HANDLE hProcess, ULONG64 BaseOfDll, DWORD Index,
|
|
|
|
DWORD SymTag, PCWSTR Mask, DWORD64 Address,
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
|
|
|
|
PVOID UserContext, DWORD Options)
|
2005-12-26 12:57:26 +01:00
|
|
|
{
|
2006-05-10 21:35:37 +02:00
|
|
|
struct sym_enum se;
|
|
|
|
|
2005-12-26 12:57:26 +01:00
|
|
|
if (Options != SYMSEARCH_GLOBALSONLY)
|
|
|
|
{
|
2006-11-29 22:04:27 +01:00
|
|
|
FIXME("Unsupported searching with options (%x)\n", Options);
|
2005-12-26 12:57:26 +01:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-05-10 21:35:37 +02:00
|
|
|
|
|
|
|
se.cb = EnumSymbolsCallback;
|
|
|
|
se.user = UserContext;
|
|
|
|
se.index = Index;
|
|
|
|
se.tag = SymTag;
|
|
|
|
se.addr = Address;
|
|
|
|
se.sym_info = (PSYMBOL_INFO)se.buffer;
|
|
|
|
|
|
|
|
return sym_enum(hProcess, BaseOfDll, Mask, &se);
|
2005-12-26 12:57:26 +01:00
|
|
|
}
|
2006-05-10 21:35:44 +02:00
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymSearch (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSearch(HANDLE hProcess, ULONG64 BaseOfDll, DWORD Index,
|
|
|
|
DWORD SymTag, PCSTR Mask, DWORD64 Address,
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
|
|
|
|
PVOID UserContext, DWORD Options)
|
|
|
|
{
|
|
|
|
LPWSTR maskW = NULL;
|
|
|
|
BOOLEAN ret;
|
|
|
|
|
|
|
|
TRACE("(%p %s %u %u %s %s %p %p %x)\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(BaseOfDll), Index, SymTag, Mask,
|
|
|
|
wine_dbgstr_longlong(Address), EnumSymbolsCallback,
|
|
|
|
UserContext, Options);
|
|
|
|
|
|
|
|
if (Mask)
|
|
|
|
{
|
|
|
|
DWORD sz = MultiByteToWideChar(CP_ACP, 0, Mask, -1, NULL, 0);
|
|
|
|
|
|
|
|
if (!(maskW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
|
|
|
|
return FALSE;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, Mask, -1, maskW, sz);
|
|
|
|
}
|
|
|
|
ret = doSymSearch(hProcess, BaseOfDll, Index, SymTag, maskW, Address,
|
|
|
|
EnumSymbolsCallback, UserContext, Options);
|
|
|
|
HeapFree(GetProcessHeap(), 0, maskW);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:44 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymSearchW (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSearchW(HANDLE hProcess, ULONG64 BaseOfDll, DWORD Index,
|
|
|
|
DWORD SymTag, PCWSTR Mask, DWORD64 Address,
|
|
|
|
PSYM_ENUMERATESYMBOLS_CALLBACKW EnumSymbolsCallback,
|
|
|
|
PVOID UserContext, DWORD Options)
|
|
|
|
{
|
|
|
|
struct sym_enumW sew;
|
|
|
|
|
2006-11-29 22:04:27 +01:00
|
|
|
TRACE("(%p %s %u %u %s %s %p %p %x)\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(BaseOfDll), Index, SymTag, debugstr_w(Mask),
|
2006-05-10 21:35:44 +02:00
|
|
|
wine_dbgstr_longlong(Address), EnumSymbolsCallback,
|
|
|
|
UserContext, Options);
|
|
|
|
|
|
|
|
sew.ctx = UserContext;
|
|
|
|
sew.cb = EnumSymbolsCallback;
|
|
|
|
sew.sym_info = (PSYMBOL_INFOW)sew.buffer;
|
|
|
|
|
2012-01-22 12:57:59 +01:00
|
|
|
return doSymSearch(hProcess, BaseOfDll, Index, SymTag, Mask, Address,
|
|
|
|
sym_enumW, &sew, Options);
|
2006-05-10 21:35:44 +02:00
|
|
|
}
|
2008-09-29 21:30:29 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymAddSymbol (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymAddSymbol(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR name,
|
|
|
|
DWORD64 addr, DWORD size, DWORD flags)
|
|
|
|
{
|
2021-10-06 10:02:31 +02:00
|
|
|
struct module_pair pair;
|
|
|
|
|
|
|
|
TRACE("(%p %s %s %u)\n", hProcess, wine_dbgstr_a(name), wine_dbgstr_longlong(addr), size);
|
2008-09-29 21:30:29 +02:00
|
|
|
|
2021-10-13 15:17:33 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, BaseOfDll)) return FALSE;
|
2021-10-06 10:02:31 +02:00
|
|
|
|
|
|
|
return symt_new_custom(pair.effective, name, addr, size) != NULL;
|
2008-09-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymAddSymbolW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2021-10-06 10:02:31 +02:00
|
|
|
BOOL WINAPI SymAddSymbolW(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR nameW,
|
2008-09-29 21:30:29 +02:00
|
|
|
DWORD64 addr, DWORD size, DWORD flags)
|
|
|
|
{
|
2021-10-06 10:02:31 +02:00
|
|
|
char name[MAX_SYM_NAME];
|
2008-09-29 21:30:29 +02:00
|
|
|
|
2021-10-06 10:02:31 +02:00
|
|
|
TRACE("(%p %s %s %u)\n", hProcess, wine_dbgstr_w(nameW), wine_dbgstr_longlong(addr), size);
|
2008-09-29 21:30:29 +02:00
|
|
|
|
2021-10-06 10:02:31 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, nameW, -1, name, ARRAY_SIZE(name), NULL, NULL);
|
2008-09-29 21:30:29 +02:00
|
|
|
|
2021-10-06 10:02:31 +02:00
|
|
|
return SymAddSymbol(hProcess, BaseOfDll, name, addr, size, flags);
|
2008-09-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-02-04 13:13:08 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymEnumLines (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
|
|
|
|
PCSTR srcfile, PSYM_ENUMLINES_CALLBACK cb, PVOID user)
|
|
|
|
{
|
|
|
|
struct module_pair pair;
|
|
|
|
struct hash_table_iter hti;
|
|
|
|
struct symt_ht* sym;
|
2012-01-22 12:58:04 +01:00
|
|
|
WCHAR* srcmask;
|
2009-02-04 13:13:08 +01:00
|
|
|
struct line_info* dli;
|
|
|
|
void* ptr;
|
|
|
|
SRCCODEINFO sci;
|
|
|
|
const char* file;
|
|
|
|
|
|
|
|
if (!cb) return FALSE;
|
|
|
|
if (!(dbghelp_options & SYMOPT_LOAD_LINES)) return TRUE;
|
|
|
|
|
2021-10-13 15:17:33 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, base)) return FALSE;
|
2009-02-04 13:13:08 +01:00
|
|
|
if (compiland) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland);
|
2012-01-22 12:58:04 +01:00
|
|
|
if (!(srcmask = file_regex(srcfile))) return FALSE;
|
2009-02-04 13:13:08 +01:00
|
|
|
|
|
|
|
sci.SizeOfStruct = sizeof(sci);
|
|
|
|
sci.ModBase = base;
|
|
|
|
|
|
|
|
hash_table_iter_init(&pair.effective->ht_symbols, &hti, NULL);
|
|
|
|
while ((ptr = hash_table_iter_up(&hti)))
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2016-03-08 11:44:26 +01:00
|
|
|
sym = CONTAINING_RECORD(ptr, struct symt_ht, hash_elt);
|
2009-02-04 13:13:08 +01:00
|
|
|
if (sym->symt.tag != SymTagFunction) continue;
|
|
|
|
|
|
|
|
sci.FileName[0] = '\0';
|
|
|
|
for (i=0; i<vector_length(&((struct symt_function*)sym)->vlines); i++)
|
|
|
|
{
|
|
|
|
dli = vector_at(&((struct symt_function*)sym)->vlines, i);
|
|
|
|
if (dli->is_source_file)
|
|
|
|
{
|
|
|
|
file = source_get(pair.effective, dli->u.source_file);
|
2012-01-22 12:58:04 +01:00
|
|
|
if (!file) sci.FileName[0] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD sz = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
|
|
|
|
WCHAR* fileW;
|
|
|
|
|
|
|
|
if ((fileW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, sz);
|
|
|
|
if (SymMatchStringW(fileW, srcmask, FALSE))
|
|
|
|
strcpy(sci.FileName, file);
|
|
|
|
else
|
|
|
|
sci.FileName[0] = '\0';
|
|
|
|
HeapFree(GetProcessHeap(), 0, fileW);
|
|
|
|
}
|
2009-02-04 13:13:08 +01:00
|
|
|
}
|
|
|
|
else if (sci.FileName[0])
|
|
|
|
{
|
|
|
|
sci.Key = dli;
|
|
|
|
sci.Obj[0] = '\0'; /* FIXME */
|
|
|
|
sci.LineNumber = dli->line_number;
|
2021-10-29 15:36:51 +02:00
|
|
|
sci.Address = dli->u.address;
|
2009-02-04 13:13:08 +01:00
|
|
|
if (!cb(&sci, user)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-22 12:58:04 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, srcmask);
|
2009-02-04 13:13:08 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-02-09 09:45:22 +01:00
|
|
|
|
|
|
|
BOOL WINAPI SymGetLineFromName(HANDLE hProcess, PCSTR ModuleName, PCSTR FileName,
|
|
|
|
DWORD dwLineNumber, PLONG plDisplacement, PIMAGEHLP_LINE Line)
|
|
|
|
{
|
|
|
|
FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess, ModuleName, FileName,
|
|
|
|
dwLineNumber, plDisplacement, Line);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI SymGetLineFromName64(HANDLE hProcess, PCSTR ModuleName, PCSTR FileName,
|
|
|
|
DWORD dwLineNumber, PLONG lpDisplacement, PIMAGEHLP_LINE64 Line)
|
|
|
|
{
|
|
|
|
FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess, ModuleName, FileName,
|
|
|
|
dwLineNumber, lpDisplacement, Line);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI SymGetLineFromNameW64(HANDLE hProcess, PCWSTR ModuleName, PCWSTR FileName,
|
|
|
|
DWORD dwLineNumber, PLONG plDisplacement, PIMAGEHLP_LINEW64 Line)
|
|
|
|
{
|
|
|
|
FIXME("(%p) (%s, %s, %d %p %p): stub\n", hProcess, debugstr_w(ModuleName), debugstr_w(FileName),
|
|
|
|
dwLineNumber, plDisplacement, Line);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-05-19 13:58:53 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymFromIndex (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFromIndex(HANDLE hProcess, ULONG64 BaseOfDll, DWORD index, PSYMBOL_INFO symbol)
|
|
|
|
{
|
|
|
|
FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(BaseOfDll), index, symbol);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymFromIndexW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFromIndexW(HANDLE hProcess, ULONG64 BaseOfDll, DWORD index, PSYMBOL_INFOW symbol)
|
|
|
|
{
|
|
|
|
FIXME("hProcess = %p, BaseOfDll = %s, index = %d, symbol = %p\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(BaseOfDll), index, symbol);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-30 03:38:40 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymSetHomeDirectory (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
PCHAR WINAPI SymSetHomeDirectory(HANDLE hProcess, PCSTR dir)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %s): stub\n", hProcess, dir);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymSetHomeDirectoryW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
PWSTR WINAPI SymSetHomeDirectoryW(HANDLE hProcess, PCWSTR dir)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %s): stub\n", hProcess, debugstr_w(dir));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-10-19 15:51:24 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymFromInlineContext (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFromInlineContext(HANDLE hProcess, DWORD64 addr, ULONG inline_ctx, PDWORD64 disp, PSYMBOL_INFO si)
|
|
|
|
{
|
2021-10-28 08:58:31 +02:00
|
|
|
struct module_pair pair;
|
|
|
|
struct symt_inlinesite* inlined;
|
|
|
|
|
2021-10-26 11:45:20 +02:00
|
|
|
TRACE("(%p, %#I64x, 0x%x, %p, %p)\n", hProcess, addr, inline_ctx, disp, si);
|
|
|
|
|
|
|
|
switch (IFC_MODE(inline_ctx))
|
|
|
|
{
|
|
|
|
case IFC_MODE_IGNORE:
|
|
|
|
case IFC_MODE_REGULAR:
|
|
|
|
return SymFromAddr(hProcess, addr, disp, si);
|
|
|
|
case IFC_MODE_INLINE:
|
2021-10-28 08:58:31 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
|
|
|
inlined = symt_find_inlined_site(pair.effective, addr, inline_ctx);
|
|
|
|
if (inlined)
|
|
|
|
{
|
|
|
|
symt_fill_sym_info(&pair, NULL, &inlined->func.symt, si);
|
|
|
|
*disp = addr - inlined->func.address;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2021-10-26 11:45:20 +02:00
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-10-19 15:51:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymFromInlineContextW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFromInlineContextW(HANDLE hProcess, DWORD64 addr, ULONG inline_ctx, PDWORD64 disp, PSYMBOL_INFOW siW)
|
|
|
|
{
|
|
|
|
PSYMBOL_INFO si;
|
|
|
|
unsigned len;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %#I64x, 0x%x, %p, %p)\n", hProcess, addr, inline_ctx, disp, siW);
|
|
|
|
|
|
|
|
len = sizeof(*si) + siW->MaxNameLen * sizeof(WCHAR);
|
|
|
|
si = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (!si) return FALSE;
|
|
|
|
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
|
|
|
si->MaxNameLen = siW->MaxNameLen;
|
|
|
|
if ((ret = SymFromInlineContext(hProcess, addr, inline_ctx, disp, si)))
|
|
|
|
{
|
|
|
|
copy_symbolW(siW, si);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, si);
|
|
|
|
return ret;
|
|
|
|
}
|
2021-10-19 15:51:31 +02:00
|
|
|
|
2021-10-26 11:45:26 +02:00
|
|
|
static BOOL get_line_from_inline_context(HANDLE hProcess, DWORD64 addr, ULONG inline_ctx, DWORD64 mod_addr, PDWORD disp,
|
|
|
|
struct internal_line_t* intl)
|
|
|
|
{
|
2021-10-29 15:37:31 +02:00
|
|
|
struct module_pair pair;
|
|
|
|
struct symt_inlinesite* inlined;
|
|
|
|
|
|
|
|
if (!module_init_pair(&pair, hProcess, mod_addr ? mod_addr : addr)) return FALSE;
|
2021-10-26 11:45:26 +02:00
|
|
|
switch (IFC_MODE(inline_ctx))
|
|
|
|
{
|
|
|
|
case IFC_MODE_INLINE:
|
2021-10-29 15:37:31 +02:00
|
|
|
inlined = symt_find_inlined_site(pair.effective, addr, inline_ctx);
|
|
|
|
if (inlined && get_line_from_function(&pair, &inlined->func, addr, disp, intl))
|
|
|
|
return TRUE;
|
|
|
|
/* fall through: check if we can find line info at top function level */
|
2021-10-26 11:45:26 +02:00
|
|
|
case IFC_MODE_IGNORE:
|
|
|
|
case IFC_MODE_REGULAR:
|
|
|
|
return get_line_from_addr(hProcess, addr, disp, intl);
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 15:51:31 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetLineFromInlineContext (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLineFromInlineContext(HANDLE hProcess, DWORD64 addr, ULONG inline_ctx, DWORD64 mod_addr, PDWORD disp, PIMAGEHLP_LINE64 line)
|
|
|
|
{
|
2021-10-26 11:45:26 +02:00
|
|
|
struct internal_line_t intl;
|
|
|
|
|
|
|
|
TRACE("(%p, %#I64x, 0x%x, %#I64x, %p, %p)\n",
|
2021-10-19 15:51:31 +02:00
|
|
|
hProcess, addr, inline_ctx, mod_addr, disp, line);
|
2021-10-26 11:45:26 +02:00
|
|
|
|
|
|
|
if (line->SizeOfStruct < sizeof(*line)) return FALSE;
|
|
|
|
init_internal_line(&intl, FALSE);
|
|
|
|
|
|
|
|
if (!get_line_from_inline_context(hProcess, addr, inline_ctx, mod_addr, disp, &intl)) return FALSE;
|
|
|
|
return internal_line_copy_toA64(&intl, line);
|
2021-10-19 15:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetLineFromInlineContextW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetLineFromInlineContextW(HANDLE hProcess, DWORD64 addr, ULONG inline_ctx, DWORD64 mod_addr, PDWORD disp, PIMAGEHLP_LINEW64 line)
|
|
|
|
{
|
2021-10-26 11:45:26 +02:00
|
|
|
struct internal_line_t intl;
|
|
|
|
|
|
|
|
TRACE("(%p, %#I64x, 0x%x, %#I64x, %p, %p)\n",
|
2021-10-19 15:51:31 +02:00
|
|
|
hProcess, addr, inline_ctx, mod_addr, disp, line);
|
2021-10-26 11:45:26 +02:00
|
|
|
|
|
|
|
if (line->SizeOfStruct < sizeof(*line)) return FALSE;
|
|
|
|
init_internal_line(&intl, TRUE);
|
|
|
|
|
|
|
|
if (!get_line_from_inline_context(hProcess, addr, inline_ctx, mod_addr, disp, &intl)) return FALSE;
|
|
|
|
return internal_line_copy_toW64(&intl, line);
|
2021-10-19 15:51:31 +02:00
|
|
|
}
|