Commit 6efc0619 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: .gnu_link support: rewrote helper functions for better later unicodification.

parent c75fb89a
......@@ -802,26 +802,49 @@ static BOOL elf_load_debug_info_from_map(struct module* module,
* is the global debug file directory, and execdir has been turned
* into a relative path)." (from GDB manual)
*/
static char* elf_locate_debug_link (const char* filename, const char* moduleDir)
static char* elf_locate_debug_link(const char* filename, const char* loaded_file,
struct elf_file_map* fmap_link)
{
static const char globalDebugDir[] = "/usr/lib/debug";
const size_t moduleDirLen = strlen (moduleDir);
const size_t globalDebugDirLen = strlen (globalDebugDir);
struct stat statbuf;
static const char globalDebugDir[] = "/usr/lib/debug/";
const size_t globalDebugDirLen = strlen(globalDebugDir);
char* p;
char* slash;
p = HeapAlloc(GetProcessHeap(), 0,
globalDebugDirLen + strlen(loaded_file) + 1 + 6 + 1 + strlen(filename) + 1);
if (!p) return FALSE;
/* we prebuild the string with "execdir" */
strcpy(p, loaded_file);
slash = strrchr(p, '/');
if (slash == NULL) slash = p; else slash++;
/* testing execdir/filename */
strcpy(slash, filename);
if (elf_map_file(p, fmap_link)) goto found;
char* p = HeapAlloc (GetProcessHeap(), 0,
moduleDirLen + 1 + max (6, globalDebugDirLen) + 1 + strlen (filename)+1);
/* testing execdir/.debug/filename */
sprintf(slash, ".debug/%s", filename);
if (elf_map_file(p, fmap_link)) goto found;
sprintf (p, "%s/%s", moduleDir, filename);
if (stat(p, &statbuf) != -1 && !S_ISDIR(statbuf.st_mode)) return p;
/* testing globaldebugdir/execdir/filename */
memmove(p + globalDebugDirLen, p, slash - p);
memcpy(p, globalDebugDir, globalDebugDirLen);
slash += globalDebugDirLen;
strcpy(slash, filename);
if (elf_map_file(p, fmap_link)) goto found;
sprintf (p, "%s/.debug/%s", moduleDir, filename);
if (stat(p, &statbuf) != -1 && !S_ISDIR(statbuf.st_mode)) return p;
strcpy(p, filename);
if (elf_map_file(p, fmap_link)) goto found;
sprintf (p, "%s/%s/%s", globalDebugDir, moduleDir, filename);
if (stat(p, &statbuf) != -1 && !S_ISDIR(statbuf.st_mode)) return p;
HeapFree(GetProcessHeap(), 0, p);
strcpy (p, filename);
WARN("Couldn't locate or map %s\n", filename);
return NULL;
found:
TRACE("Located debug information file %s at %s\n", filename, p);
return p;
}
......@@ -845,19 +868,11 @@ static BOOL elf_debuglink_parse (struct module* module,
BOOL ret = FALSE;
const char* dbg_link = (char*)debuglink;
struct elf_file_map fmap_link;
char* moduleDir;
char* link_file;
char* slash;
moduleDir = HeapAlloc (GetProcessHeap(), 0, strlen (module->module.LoadedImageName) + 1);
strcpy (moduleDir, module->module.LoadedImageName);
slash = strrchr (moduleDir, '/');
if (slash != 0) *slash = 0;
link_file = elf_locate_debug_link(dbg_link, module->module.LoadedImageName, &fmap_link);
link_file = elf_locate_debug_link (dbg_link, moduleDir);
TRACE("Located debug information file %s at %s\n", dbg_link, link_file);
if (elf_map_file(link_file, &fmap_link))
if (link_file)
{
fmap_link.crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
fmap_link.with_crc = 1;
......@@ -868,12 +883,8 @@ static BOOL elf_debuglink_parse (struct module* module,
else
WARN("Couldn't load debug information from %s\n", link_file);
elf_unmap_file(&fmap_link);
HeapFree(GetProcessHeap(), 0, link_file);
}
else
WARN("Couldn't map %s\n", dbg_link);
HeapFree (GetProcessHeap(), 0, link_file);
HeapFree (GetProcessHeap(), 0, moduleDir);
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment