From 7af4097d802834a91bfc010870e7a9a1a7061342 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Sun, 18 Jun 2006 21:32:20 +0200 Subject: [PATCH] dbghelp: Added the ability to define a source file by dir+filename instead of only filename. --- dlls/dbghelp/coff.c | 2 +- dlls/dbghelp/dbghelp_private.h | 5 ++--- dlls/dbghelp/dwarf.c | 11 +++++------ dlls/dbghelp/elf_module.c | 2 +- dlls/dbghelp/msc.c | 8 +++++--- dlls/dbghelp/source.c | 23 +++++++++++++++++++---- dlls/dbghelp/stabs.c | 23 ++++------------------- dlls/dbghelp/symbol.c | 6 +++--- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/dlls/dbghelp/coff.c b/dlls/dbghelp/coff.c index d2b0c2249c9..e0ff3550d9b 100644 --- a/dlls/dbghelp/coff.c +++ b/dlls/dbghelp/coff.c @@ -120,7 +120,7 @@ static int coff_add_file(struct CoffFileSet* coff_files, struct module* module, file = coff_files->files + coff_files->nfiles; file->startaddr = 0xffffffff; file->endaddr = 0; - file->compiland = symt_new_compiland(module, filename); + file->compiland = symt_new_compiland(module, source_new(module, NULL, filename)); file->linetab_offset = -1; file->linecnt = 0; file->entries = NULL; diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 62ef4a612b0..6af37ee22f0 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -422,7 +422,7 @@ extern struct module* extern BOOL pe_load_debug_info(const struct process* pcs, struct module* module); /* source.c */ -extern unsigned source_new(struct module* module, const char* source); +extern unsigned source_new(struct module* module, const char* basedir, const char* source); extern const char* source_get(const struct module* module, unsigned idx); /* stabs.c */ @@ -442,8 +442,7 @@ extern const char* symt_get_name(const struct symt* sym); extern int symt_cmp_addr(const void* p1, const void* p2); extern int symt_find_nearest(struct module* module, DWORD addr); extern struct symt_compiland* - symt_new_compiland(struct module* module, - const char* filename); + symt_new_compiland(struct module* module, unsigned src_idx); extern struct symt_public* symt_new_public(struct module* module, struct symt_compiland* parent, diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c index c7eabdd9dfc..701fd5ced5b 100644 --- a/dlls/dbghelp/dwarf.c +++ b/dlls/dbghelp/dwarf.c @@ -1436,7 +1436,7 @@ static void dwarf2_parse_line_numbers(const dwarf2_section_t* sections, while (traverse.data < traverse.end_data) { - unsigned long address; + unsigned long address = 0; unsigned file = 1; unsigned line = 1; unsigned is_stmt = default_stmt; @@ -1467,10 +1467,10 @@ static void dwarf2_parse_line_numbers(const dwarf2_section_t* sections, address += insn_size * dwarf2_leb128_as_unsigned(&traverse); break; case DW_LNS_advance_line: - line += dwarf2_leb128_as_unsigned(&traverse); + line += dwarf2_leb128_as_signed(&traverse); break; case DW_LNS_set_file: - file = dwarf2_leb128_as_signed(&traverse); + file = dwarf2_leb128_as_unsigned(&traverse); break; case DW_LNS_set_column: dwarf2_leb128_as_unsigned(&traverse); @@ -1496,8 +1496,7 @@ static void dwarf2_parse_line_numbers(const dwarf2_section_t* sections, end_sequence = TRUE; break; case DW_LNE_set_address: - address = dwarf2_parse_addr(&traverse); - address += ctx->module->module.BaseOfImage; + address = ctx->module->module.BaseOfImage + dwarf2_parse_addr(&traverse); break; case DW_LNE_define_file: traverse.data += strlen((const char *)traverse.data) + 1; @@ -1579,7 +1578,7 @@ static BOOL dwarf2_parse_compilation_unit(const dwarf2_section_t* sections, TRACE("beginning at 0x%lx, for %lu\n", di->offset, di->abbrev->entry_code); dwarf2_find_name(&ctx, di, &name, "compiland"); - di->symt = &symt_new_compiland(module, name.string)->symt; + di->symt = &symt_new_compiland(module, source_new(module, NULL, name.string))->symt; if (di->abbrev->have_child) { diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index 33e78bdd881..f8b57f5d037 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -292,7 +292,7 @@ static void elf_hash_symtab(struct module* module, struct pool* pool, if (ELF32_ST_TYPE(symp->st_info) == STT_FILE) { - compiland = symname ? symt_new_compiland(module, symname) : NULL; + compiland = symname ? symt_new_compiland(module, source_new(module, NULL, symname)) : NULL; continue; } for (j = 0; thunks[j].symname; j++) diff --git a/dlls/dbghelp/msc.c b/dlls/dbghelp/msc.c index 76b889c5303..2bde2bfca09 100644 --- a/dlls/dbghelp/msc.c +++ b/dlls/dbghelp/msc.c @@ -1136,10 +1136,10 @@ static struct codeview_linetab* codeview_snarf_linetab(struct module* module, p_fn = (const struct p_string*)(start + file_segcount); memset(filename, 0, sizeof(filename)); memcpy(filename, p_fn->name, p_fn->namelen); - source = source_new(module, filename); + source = source_new(module, NULL, filename); } else - source = source_new(module, (const char*)(start + file_segcount)); + source = source_new(module, NULL, (const char*)(start + file_segcount)); for (k = 0; k < file_segcount; k++, this_seg++) { @@ -1465,7 +1465,9 @@ static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root case S_OBJNAME_V1: TRACE("S-ObjName %s\n", terminate_string(&sym->objname_v1.p_name)); - compiland = symt_new_compiland(msc_dbg->module, terminate_string(&sym->objname_v1.p_name)); + compiland = symt_new_compiland(msc_dbg->module, + source_new(msc_dbg->module, NULL, + terminate_string(&sym->objname_v1.p_name))); break; case S_LABEL_V1: diff --git a/dlls/dbghelp/source.c b/dlls/dbghelp/source.c index fcfad563944..133cd2fbd3d 100644 --- a/dlls/dbghelp/source.c +++ b/dlls/dbghelp/source.c @@ -54,16 +54,30 @@ static unsigned source_find(const struct module* module, const char* name) * * checks if source exists. if not, add it */ -unsigned source_new(struct module* module, const char* name) +unsigned source_new(struct module* module, const char* base, const char* name) { int len; unsigned ret; + const char* full; if (!name) return (unsigned)-1; - if (module->sources && (ret = source_find(module, name)) != (unsigned)-1) + if (!base || *name == '/') + full = name; + else + { + unsigned bsz = strlen(base); + char* tmp = HeapAlloc(GetProcessHeap(), 0, bsz + 1 + strlen(name) + 1); + + if (!tmp) return (unsigned)-1; + full = tmp; + strcpy(tmp, base); + if (tmp[bsz - 1] != '/') tmp[bsz++] = '/'; + strcpy(&tmp[bsz], name); + } + if (module->sources && (ret = source_find(module, full)) != (unsigned)-1) return ret; - len = strlen(name) + 1; + len = strlen(full) + 1; if (module->sources_used + len + 1 > module->sources_alloc) { /* Alloc by block of 256 bytes */ @@ -75,9 +89,10 @@ unsigned source_new(struct module* module, const char* name) module->sources_alloc); } ret = module->sources_used; - strcpy(module->sources + module->sources_used, name); + strcpy(module->sources + module->sources_used, full); module->sources_used += len; module->sources[module->sources_used] = '\0'; + if (full != name) HeapFree(GetProcessHeap(), 0, (char*)full); return ret; } diff --git a/dlls/dbghelp/stabs.c b/dlls/dbghelp/stabs.c index acc3e908cd6..bf5922a4042 100644 --- a/dlls/dbghelp/stabs.c +++ b/dlls/dbghelp/stabs.c @@ -1173,7 +1173,6 @@ BOOL stabs_parse(struct module* module, unsigned long load_offset, struct symt_function* curr_func = NULL; struct symt_block* block = NULL; struct symt_compiland* compiland = NULL; - char currpath[PATH_MAX]; /* path to current file */ char srcpath[PATH_MAX]; /* path to directory source file is in */ int i; int nstab; @@ -1475,30 +1474,16 @@ BOOL stabs_parse(struct module* module, unsigned long load_offset, int len = strlen(ptr); if (ptr[len-1] != '/') { - if (ptr[0] == '/') - strcpy(currpath, ptr); - else - { - strcpy(currpath, srcpath); - strcat(currpath, ptr); - } stabs_reset_includes(); - compiland = symt_new_compiland(module, currpath); - source_idx = source_new(module, currpath); + source_idx = source_new(module, srcpath, ptr); + compiland = symt_new_compiland(module, source_idx); } else strcpy(srcpath, ptr); } break; case N_SOL: - if (*ptr != '/') - { - strcpy(currpath, srcpath); - strcat(currpath, ptr); - } - else - strcpy(currpath, ptr); - source_idx = source_new(module, currpath); + source_idx = source_new(module, srcpath, ptr); break; case N_UNDF: strs += strtabinc; @@ -1518,7 +1503,7 @@ BOOL stabs_parse(struct module* module, unsigned long load_offset, stabs_add_include(stabs_new_include(ptr, stab_ptr->n_value)); assert(incl_stk < (int)(sizeof(incl) / sizeof(incl[0])) - 1); incl[++incl_stk] = source_idx; - source_idx = source_new(module, ptr); + source_idx = source_new(module, NULL, ptr); break; case N_EINCL: assert(incl_stk >= 0); diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c index 24b1e36f1cb..2d1e4ede090 100644 --- a/dlls/dbghelp/symbol.c +++ b/dlls/dbghelp/symbol.c @@ -125,16 +125,16 @@ static void compile_regex(const char* str, int numchar, regex_t* re, BOOL _case) HeapFree(GetProcessHeap(), 0, mask); } -struct symt_compiland* symt_new_compiland(struct module* module, const char* name) +struct symt_compiland* symt_new_compiland(struct module* module, unsigned src_idx) { struct symt_compiland* sym; TRACE_(dbghelp_symt)("Adding compiland symbol %s:%s\n", - module->module.ModuleName, name); + module->module.ModuleName, source_get(module, src_idx)); if ((sym = pool_alloc(&module->pool, sizeof(*sym)))) { sym->symt.tag = SymTagCompiland; - sym->source = source_new(module, name); + sym->source = src_idx; vector_init(&sym->vchildren, sizeof(struct symt*), 32); } return sym;