2004-04-06 00:21:27 +02:00
|
|
|
/*
|
|
|
|
* File source.c - source files management
|
|
|
|
*
|
|
|
|
* Copyright (C) 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "dbghelp_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
|
|
|
|
2011-01-08 14:15:31 +01:00
|
|
|
static struct module* rb_module;
|
|
|
|
struct source_rb
|
|
|
|
{
|
|
|
|
struct wine_rb_entry entry;
|
|
|
|
unsigned source;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void *source_rb_alloc(size_t size)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *source_rb_realloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void source_rb_free(void *ptr)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int source_rb_compare(const void *key, const struct wine_rb_entry *entry)
|
|
|
|
{
|
|
|
|
const struct source_rb *t = WINE_RB_ENTRY_VALUE(entry, const struct source_rb, entry);
|
|
|
|
|
|
|
|
return strcmp((const char*)key, rb_module->sources + t->source);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct wine_rb_functions source_rb_functions =
|
|
|
|
{
|
|
|
|
source_rb_alloc,
|
|
|
|
source_rb_realloc,
|
|
|
|
source_rb_free,
|
|
|
|
source_rb_compare,
|
|
|
|
};
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* source_find
|
|
|
|
*
|
|
|
|
* check whether a source file has already been stored
|
|
|
|
*/
|
2011-01-08 14:15:31 +01:00
|
|
|
static unsigned source_find(const char* name)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2011-01-08 14:15:31 +01:00
|
|
|
struct wine_rb_entry* e;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2011-01-08 14:15:31 +01:00
|
|
|
e = wine_rb_get(&rb_module->sources_offsets_tree, name);
|
|
|
|
if (!e) return -1;
|
|
|
|
return WINE_RB_ENTRY_VALUE(e, struct source_rb, entry)->source;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* source_new
|
|
|
|
*
|
|
|
|
* checks if source exists. if not, add it
|
|
|
|
*/
|
2006-06-18 21:32:20 +02:00
|
|
|
unsigned source_new(struct module* module, const char* base, const char* name)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2011-01-31 15:36:23 +01:00
|
|
|
unsigned ret = -1;
|
2006-06-18 21:32:20 +02:00
|
|
|
const char* full;
|
2006-10-28 18:27:26 +02:00
|
|
|
char* tmp = NULL;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2011-01-31 15:36:23 +01:00
|
|
|
if (!name) return ret;
|
2006-06-18 21:32:20 +02:00
|
|
|
if (!base || *name == '/')
|
|
|
|
full = name;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned bsz = strlen(base);
|
|
|
|
|
2006-10-28 18:27:26 +02:00
|
|
|
tmp = HeapAlloc(GetProcessHeap(), 0, bsz + 1 + strlen(name) + 1);
|
2011-01-31 15:36:23 +01:00
|
|
|
if (!tmp) return ret;
|
2006-06-18 21:32:20 +02:00
|
|
|
full = tmp;
|
|
|
|
strcpy(tmp, base);
|
|
|
|
if (tmp[bsz - 1] != '/') tmp[bsz++] = '/';
|
|
|
|
strcpy(&tmp[bsz], name);
|
|
|
|
}
|
2011-01-08 14:15:31 +01:00
|
|
|
rb_module = module;
|
|
|
|
if (!module->sources || (ret = source_find(full)) == (unsigned)-1)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2011-01-08 14:15:25 +01:00
|
|
|
char* new;
|
2006-11-05 17:51:35 +01:00
|
|
|
int len = strlen(full) + 1;
|
2011-01-08 14:15:31 +01:00
|
|
|
struct source_rb* rb;
|
|
|
|
|
2006-11-05 17:51:35 +01:00
|
|
|
if (module->sources_used + len + 1 > module->sources_alloc)
|
|
|
|
{
|
|
|
|
if (!module->sources)
|
2009-07-10 14:46:55 +02:00
|
|
|
{
|
|
|
|
module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255;
|
2011-01-08 14:15:25 +01:00
|
|
|
new = HeapAlloc(GetProcessHeap(), 0, module->sources_alloc);
|
2009-07-10 14:46:55 +02:00
|
|
|
}
|
2006-11-05 17:51:35 +01:00
|
|
|
else
|
2009-07-10 14:46:55 +02:00
|
|
|
{
|
|
|
|
module->sources_alloc = max( module->sources_alloc * 2,
|
|
|
|
(module->sources_used + len + 1 + 255) & ~255 );
|
2011-01-08 14:15:25 +01:00
|
|
|
new = HeapReAlloc(GetProcessHeap(), 0, module->sources,
|
|
|
|
module->sources_alloc);
|
2009-07-10 14:46:55 +02:00
|
|
|
}
|
2011-01-08 14:15:25 +01:00
|
|
|
if (!new) goto done;
|
|
|
|
module->sources = new;
|
2006-11-05 17:51:35 +01:00
|
|
|
}
|
|
|
|
ret = module->sources_used;
|
|
|
|
memcpy(module->sources + module->sources_used, full, len);
|
|
|
|
module->sources_used += len;
|
|
|
|
module->sources[module->sources_used] = '\0';
|
2011-01-08 14:15:31 +01:00
|
|
|
if ((rb = pool_alloc(&module->pool, sizeof(*rb))))
|
|
|
|
{
|
|
|
|
rb->source = ret;
|
|
|
|
wine_rb_put(&module->sources_offsets_tree, full, &rb->entry);
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2011-01-08 14:15:25 +01:00
|
|
|
done:
|
2006-10-28 18:27:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, tmp);
|
2004-04-06 00:21:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* source_get
|
|
|
|
*
|
|
|
|
* returns a stored source file name
|
|
|
|
*/
|
|
|
|
const char* source_get(const struct module* module, unsigned idx)
|
|
|
|
{
|
|
|
|
if (idx == -1) return "";
|
|
|
|
assert(module->sources);
|
|
|
|
return module->sources + idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2011-05-31 13:12:44 +02:00
|
|
|
* SymEnumSourceFilesW (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2011-05-31 13:12:44 +02:00
|
|
|
BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask,
|
|
|
|
PSYM_ENUMSOURCEFILES_CALLBACKW cbSrcFiles,
|
|
|
|
PVOID UserContext)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-05-07 14:29:49 +02:00
|
|
|
struct module_pair pair;
|
2011-05-31 13:12:44 +02:00
|
|
|
SOURCEFILEW sf;
|
2004-04-06 00:21:27 +02:00
|
|
|
char* ptr;
|
2011-05-31 13:12:44 +02:00
|
|
|
WCHAR* conversion_buffer = NULL;
|
|
|
|
DWORD conversion_buffer_len = 0;
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
if (!cbSrcFiles) return FALSE;
|
2006-11-24 22:17:10 +01:00
|
|
|
pair.pcs = process_find_by_handle(hProcess);
|
|
|
|
if (!pair.pcs) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
if (ModBase)
|
|
|
|
{
|
2006-11-24 22:17:10 +01:00
|
|
|
pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
|
|
|
|
if (!module_get_debug(&pair)) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Mask[0] == '!')
|
|
|
|
{
|
2011-05-31 13:12:44 +02:00
|
|
|
pair.requested = module_find_by_nameW(pair.pcs, Mask + 1);
|
2006-11-24 22:17:10 +01:00
|
|
|
if (!module_get_debug(&pair)) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported yet (should get info from current context)\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-05-07 14:29:49 +02:00
|
|
|
if (!pair.effective->sources) return FALSE;
|
|
|
|
for (ptr = pair.effective->sources; *ptr; ptr += strlen(ptr) + 1)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2011-05-31 13:12:44 +02:00
|
|
|
DWORD len = MultiByteToWideChar(CP_ACP, 0, ptr, -1, NULL, 0);
|
|
|
|
|
|
|
|
if (len > conversion_buffer_len)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, conversion_buffer);
|
|
|
|
conversion_buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!conversion_buffer) return FALSE;
|
|
|
|
conversion_buffer_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ptr, -1, conversion_buffer, len);
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/* FIXME: not using Mask */
|
|
|
|
sf.ModBase = ModBase;
|
2011-05-31 13:12:44 +02:00
|
|
|
sf.FileName = conversion_buffer;
|
2004-04-06 00:21:27 +02:00
|
|
|
if (!cbSrcFiles(&sf, UserContext)) break;
|
|
|
|
}
|
|
|
|
|
2011-05-31 13:12:44 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, conversion_buffer);
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2005-11-03 10:51:26 +01:00
|
|
|
|
2011-05-31 13:12:44 +02:00
|
|
|
struct enum_sources_files_context
|
|
|
|
{
|
|
|
|
PSYM_ENUMSOURCEFILES_CALLBACK callbackA;
|
|
|
|
PVOID caller_context;
|
|
|
|
char *conversion_buffer;
|
|
|
|
DWORD conversion_buffer_len;
|
|
|
|
DWORD callback_error;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK enum_source_files_W_to_A(PSOURCEFILEW source_file, PVOID context)
|
|
|
|
{
|
|
|
|
struct enum_sources_files_context *ctx = context;
|
|
|
|
SOURCEFILE source_fileA;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, source_file->FileName, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (len > ctx->conversion_buffer_len)
|
|
|
|
{
|
|
|
|
char *ptr = ctx->conversion_buffer ? HeapReAlloc(GetProcessHeap(), 0, ctx->conversion_buffer, len) :
|
|
|
|
HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
ctx->callback_error = ERROR_OUTOFMEMORY;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->conversion_buffer = ptr;
|
|
|
|
ctx->conversion_buffer_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, source_file->FileName, -1, ctx->conversion_buffer, len, NULL, NULL);
|
|
|
|
|
|
|
|
source_fileA.ModBase = source_file->ModBase;
|
|
|
|
source_fileA.FileName = ctx->conversion_buffer;
|
|
|
|
return ctx->callbackA(&source_fileA, ctx->caller_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymEnumSourceFiles (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask,
|
|
|
|
PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
WCHAR *maskW = NULL;
|
|
|
|
PSYM_ENUMSOURCEFILES_CALLBACKW callbackW;
|
|
|
|
PVOID context;
|
|
|
|
struct enum_sources_files_context callback_context = {cbSrcFiles, UserContext};
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (Mask)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar(CP_ACP, 0, Mask, -1, NULL, 0);
|
|
|
|
|
|
|
|
maskW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!maskW)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, Mask, -1, maskW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbSrcFiles)
|
|
|
|
{
|
|
|
|
callbackW = enum_source_files_W_to_A;
|
|
|
|
context = &callback_context;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callbackW = NULL;
|
|
|
|
context = UserContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = SymEnumSourceFilesW(hProcess, ModBase, maskW, callbackW, context);
|
|
|
|
|
|
|
|
if (callback_context.callback_error)
|
|
|
|
{
|
|
|
|
SetLastError(callback_context.callback_error);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, callback_context.conversion_buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, maskW);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-16 19:33:29 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymEnumSourceLines (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumSourceLines(HANDLE hProcess, ULONG64 base, PCSTR obj,
|
|
|
|
PCSTR file, DWORD line, DWORD flags,
|
|
|
|
PSYM_ENUMLINES_CALLBACK EnumLinesCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
FIXME("%p %s %s %s %u %u %p %p: stub!\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(base), debugstr_a(obj), debugstr_a(file),
|
|
|
|
line, flags, EnumLinesCallback, UserContext);
|
|
|
|
SetLastError(ERROR_NOT_SUPPORTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymEnumSourceLinesW(DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumSourceLinesW(HANDLE hProcess, ULONG64 base, PCWSTR obj,
|
|
|
|
PCWSTR file, DWORD line, DWORD flags,
|
|
|
|
PSYM_ENUMLINES_CALLBACKW EnumLinesCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
|
|
|
FIXME("%p %s %s %s %u %u %p %p: stub!\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(base), debugstr_w(obj), debugstr_w(file),
|
|
|
|
line, flags, EnumLinesCallback, UserContext);
|
|
|
|
SetLastError(ERROR_NOT_SUPPORTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:30:12 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetSourceFileToken (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetSourceFileToken(HANDLE hProcess, ULONG64 base,
|
|
|
|
PCSTR src, PVOID* token, DWORD* size)
|
|
|
|
{
|
|
|
|
FIXME("%p %s %s %p %p: stub!\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(base), debugstr_a(src), token, size);
|
|
|
|
SetLastError(ERROR_NOT_SUPPORTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-05-10 21:35:30 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetSourceFileTokenW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetSourceFileTokenW(HANDLE hProcess, ULONG64 base,
|
|
|
|
PCWSTR src, PVOID* token, DWORD* size)
|
|
|
|
{
|
|
|
|
FIXME("%p %s %s %p %p: stub!\n",
|
|
|
|
hProcess, wine_dbgstr_longlong(base), debugstr_w(src), token, size);
|
|
|
|
SetLastError(ERROR_NOT_SUPPORTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|