[PATCH 27/31] [DbgHelp]: source files

Eric Pouech eric.pouech at wanadoo.fr
Sun Jun 18 14:32:20 CDT 2006


- added the ability to define a source file by dir+filename
  instead of only filename

A+
---

 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 d2b0c22..e0ff355 100644
--- a/dlls/dbghelp/coff.c
+++ b/dlls/dbghelp/coff.c
@@ -120,7 +120,7 @@ static int coff_add_file(struct CoffFile
     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 62ef4a6..6af37ee 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 
 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 acdc746..01aa246 100644
--- a/dlls/dbghelp/dwarf.c
+++ b/dlls/dbghelp/dwarf.c
@@ -1436,7 +1436,7 @@ static void dwarf2_parse_line_numbers(co
 
     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(co
                     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(co
                         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(traverse.data) + 1;
@@ -1579,7 +1578,7 @@ static BOOL dwarf2_parse_compilation_uni
         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 d25ebb4..8f03bdd 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -289,7 +289,7 @@ static void elf_hash_symtab(struct modul
 
         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 76b889c..2bde2bf 100644
--- a/dlls/dbghelp/msc.c
+++ b/dlls/dbghelp/msc.c
@@ -1136,10 +1136,10 @@ static struct codeview_linetab* codeview
             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 m
 
         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 fcfad56..133cd2f 100644
--- a/dlls/dbghelp/source.c
+++ b/dlls/dbghelp/source.c
@@ -54,16 +54,30 @@ static unsigned source_find(const struct
  *
  * 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* modul
                                           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 acc3e90..bf5922a 100644
--- a/dlls/dbghelp/stabs.c
+++ b/dlls/dbghelp/stabs.c
@@ -1173,7 +1173,6 @@ BOOL stabs_parse(struct module* module, 
     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 @@ #endif
                 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 @@ #endif
             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 24b1e36..2d1e4ed 100644
--- a/dlls/dbghelp/symbol.c
+++ b/dlls/dbghelp/symbol.c
@@ -125,16 +125,16 @@ static void compile_regex(const char* st
     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;



More information about the wine-patches mailing list