Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Garrison <garrison@mail.ru>
To: jimb@redhat.com
Cc: cagney@gnu.org,  gdb-patches@sources.redhat.com
Subject: Re: Patch: Handle relative paths in .debug_line
Date: Thu, 30 Sep 2004 00:40:00 -0000	[thread overview]
Message-ID: <415B569E.2080805@mail.ru> (raw)

Hi!

I've taken a look at dwarf standard, and I have a question (possibly
already answered elsewhere): it is specified that relative paths in list
are related to compilation directory, so why not make the substitution
while parsing the list? If it's OK please take a look at attached patch
(sorry if it wraps this time). It's against current CVS HEAD.

I'm not sure I got those make_cleanup() calls right, if so please correct
me.

--- dwarf2read.c.original       2004-09-27 23:28:12.000000000 +0400
+++ dwarf2read.c        2004-09-30 04:05:52.999436680 +0400
@@ -822,7 +822,7 @@

  static struct line_header *(dwarf_decode_line_header
                              (unsigned int offset,
-                             bfd *abfd, struct dwarf2_cu *cu));
+                             bfd *abfd, struct dwarf2_cu *cu, const char* comp_dir));

  static void dwarf_decode_lines (struct line_header *, char *, bfd *,
                                 struct dwarf2_cu *, struct partial_symtab *);
@@ -1359,7 +1359,7 @@
    bfd *abfd = objfile->obfd;
    struct line_header *lh;

-  lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
+  lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu, pst->dirname);
    if (lh == NULL)
      return;  /* No linetable, so no includes.  */

@@ -2652,7 +2652,7 @@
    if (attr)
      {
        unsigned int line_offset = DW_UNSND (attr);
-      line_header = dwarf_decode_line_header (line_offset, abfd, cu);
+      line_header = dwarf_decode_line_header (line_offset, abfd, cu, comp_dir);
        if (line_header)
          {
            make_cleanup ((make_cleanup_ftype *) free_line_header,
@@ -6013,6 +6013,23 @@
      return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
  }

+/* Create full path name from absolute and relative parts.
+   The result string should be freed by caller when necessary. */
+static char*
+make_full_path (const char *full_part, const char *rel_part)
+{
+  char *result;
+
+  int dir_len = strlen(full_part);
+
+  result = xmalloc(dir_len + 1 + strlen(rel_part) + 1);
+  strcpy (result, full_part);
+  result[dir_len] = '/';
+  strcpy (result + dir_len + 1, rel_part);
+
+  return result;
+}
+
  /* Free the line_header structure *LH, and any arrays and strings it
     refers to.  */
  static void
@@ -6026,18 +6043,19 @@
    if (lh->file_names)
      xfree (lh->file_names);

-  /* Similarly for the include directory names.  */
+  /* Similarly for the include directory names - they will be freed independently.  */
    if (lh->include_dirs)
      xfree (lh->include_dirs);

    xfree (lh);
  }

-
  /* Add an entry to LH's include directory table.  */
  static void
-add_include_dir (struct line_header *lh, char *include_dir)
+add_include_dir (struct line_header *lh, char *include_dir, const char *comp_dir)
  {
+  char* real_dir;
+
    /* Grow the array if necessary.  */
    if (lh->include_dirs_size == 0)
      {
@@ -6053,9 +6071,19 @@
                                      * sizeof (*lh->include_dirs)));
      }

-  lh->include_dirs[lh->num_include_dirs++] = include_dir;
+  if (!IS_ABSOLUTE_PATH(include_dir) && comp_dir != NULL)
+    {
+      real_dir = make_full_path(comp_dir, include_dir);
+      make_cleanup(xfree, real_dir);
+    }
+  else
+    {
+      real_dir = include_dir;
+    }
+
+  lh->include_dirs[lh->num_include_dirs++] = real_dir;
  }
-
+

  /* Add an entry to LH's file name table.  */
  static void
@@ -6100,7 +6128,7 @@
     freed.  */
  static struct line_header *
  dwarf_decode_line_header (unsigned int offset, bfd *abfd,
-                         struct dwarf2_cu *cu)
+                         struct dwarf2_cu *cu, const char* comp_dir)
  {
    struct cleanup *back_to;
    struct line_header *lh;
@@ -6168,7 +6196,7 @@
    while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
      {
        line_ptr += bytes_read;
-      add_include_dir (lh, cur_dir);
+      add_include_dir (lh, cur_dir, comp_dir);
      }
    line_ptr += bytes_read;

@@ -8669,12 +8697,7 @@

        if (dir)
          {
-          dir_len = strlen (dir);
-          full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
-          strcpy (full_name, dir);
-          full_name[dir_len] = '/';
-          strcpy (full_name + dir_len + 1, fe->name);
-          return full_name;
+          return make_full_path(dir, fe->name);
          }
        else
          return xstrdup (fe->name);
-----------
Kind regards,
Igor V. Kovalenko


             reply	other threads:[~2004-09-30  0:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-30  0:40 Garrison [this message]
2004-09-30  0:49 ` Garrison
2004-10-01 18:23   ` Igor Kovalenko
  -- strict thread matches above, loose matches on Subject: below --
2004-07-22 23:31 Bryce McKinlay
2004-07-23 21:13 ` Jim Blandy
2004-07-23 23:54   ` Bryce McKinlay
2004-07-29 20:19     ` Jim Blandy
2004-07-29 20:54       ` Bryce McKinlay
2004-07-31  4:16         ` Jim Blandy
2004-07-31 19:23           ` Bryce McKinlay
2004-07-31 20:51             ` Andrew Cagney
2004-08-01  0:24               ` Michael Chastain
2004-09-14 19:53           ` Andrew Cagney
2004-09-14 20:09             ` Bryce McKinlay
2004-09-24 19:12               ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=415B569E.2080805@mail.ru \
    --to=garrison@mail.ru \
    --cc=cagney@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=jimb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox