dbghelp: make dwarf2 parser handle file paths relative to working dir better

Peter Oberndorfer kumbayo84 at arcor.de
Sun Nov 5 16:30:52 CST 2006


with the switch to the dwarf2 format winedbg would not show source lines anymore
instead it displays a error like "Unable to open file './process.c'"
this is because gcc4 embeds relative source filenames, while gcc3 used absolute names

Changelog:
dbghelp: make dwarf2 parser handle file paths relative to working dir better
needed for files produced by gcc4
-------------- next part --------------
From 05cd87ff527c7cdfffd3e8750c9e023f40219690 Mon Sep 17 00:00:00 2001
From: Peter Oberndorfer <kumbayo84 at arcor.de>
Date: Sun, 5 Nov 2006 22:02:46 +0100
Subject: [PATCH] dbghelp: make dwarf2 parser handle file paths relative to working dir better

needed for files produced by gcc4
---
 dlls/dbghelp/dwarf.c |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c
index 91e7eac..60669dc 100644
--- a/dlls/dbghelp/dwarf.c
+++ b/dlls/dbghelp/dwarf.c
@@ -1583,6 +1583,7 @@ static void dwarf2_set_line_number(struc
 
 static void dwarf2_parse_line_numbers(const dwarf2_section_t* sections,        
                                       dwarf2_parse_context_t* ctx,
+                                      const char* compile_dir,
                                       unsigned long offset)
 {
     dwarf2_traverse_context_t   traverse;
@@ -1620,13 +1621,28 @@ static void dwarf2_parse_line_numbers(co
 
     vector_init(&dirs, sizeof(const char*), 4);
     p = vector_add(&dirs, &ctx->pool);
-    *p = ".";
+    *p = compile_dir ? compile_dir : ".";
     while (*traverse.data)
     {
-        TRACE("Got include %s\n", (const char*)traverse.data);
+        const char*  rel = (const char*)traverse.data;
+        unsigned     rellen = strlen(rel);
+        TRACE("Got include %s\n", rel);
+        traverse.data += rellen + 1;
         p = vector_add(&dirs, &ctx->pool);
-        *p = (const char *)traverse.data;
-        traverse.data += strlen((const char *)traverse.data) + 1;
+
+        if (*rel == '/' || !compile_dir)
+            *p = rel;
+        else
+        {
+           /* include directory relative to compile directory */
+           unsigned  baselen = strlen(compile_dir);
+           char*     tmp = pool_alloc(&ctx->pool, baselen + 1 + rellen + 1);
+           strcpy(tmp, compile_dir);
+           if (tmp[baselen - 1] != '/') tmp[baselen++] = '/';
+           strcpy(&tmp[baselen], rel);
+           *p = tmp;
+        }
+
     }
     traverse.data++;
 
@@ -1793,9 +1809,15 @@ static BOOL dwarf2_parse_compilation_uni
         struct attribute            name;
         dwarf2_debug_info_t**       pdi = NULL;
         struct attribute            stmt_list;
+        struct attribute            comp_dir;
 
         dwarf2_find_name(&ctx, di, &name, "compiland");
-        di->symt = &symt_new_compiland(module, source_new(module, NULL, name.u.string))->symt;
+
+        /* get working directory of current compilation unit */
+        if (!dwarf2_find_attribute(&ctx, di, DW_AT_comp_dir, &comp_dir))
+            comp_dir.u.string = NULL;
+
+        di->symt = &symt_new_compiland(module, source_new(module, comp_dir.u.string, name.u.string))->symt;
 
         if (di->abbrev->have_child)
         {
@@ -1806,7 +1828,7 @@ static BOOL dwarf2_parse_compilation_uni
         }
         if (dwarf2_find_attribute(&ctx, di, DW_AT_stmt_list, &stmt_list))
         {
-            dwarf2_parse_line_numbers(sections, &ctx, stmt_list.u.uvalue);
+            dwarf2_parse_line_numbers(sections, &ctx, comp_dir.u.string, stmt_list.u.uvalue);
         }
         ret = TRUE;
     }
-- 
1.4.3.3



More information about the wine-patches mailing list