From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: [commit] Handle files without DW_AT_comp_dir
Date: Mon, 04 Jun 2007 12:36:00 -0000 [thread overview]
Message-ID: <20070604123615.GA22533@caradoc.them.org> (raw)
Joseph Myers discovered a case where GCC emits an absolute path in
DW_AT_name, no DW_AT_comp_dir, and relative pathnames in the directory
table. GDB could not handle this, and failed to locate header files
in the correct paths.
The GCC behavior is a bug, and I think Joseph's working on a fix for
it. But it's been around for a long time, so I think it's worthwhile
to handle it in GDB. I tested the patch below on x86_64-linux and
checked it in.
--
Daniel Jacobowitz
CodeSourcery
2007-06-04 Daniel Jacobowitz <dan@codesourcery.com>
* defs.h (ldirname): New prototype.
* dwarf2read.c (read_file_scope): Use DW_AT_name if DW_AT_comp_dir is
missing.
* utils.c (ldirname): New function.
* xml-tdesc.c (file_read_description_xml): Use ldirname.
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.206
diff -u -p -r1.206 defs.h
--- defs.h 31 May 2007 17:00:06 -0000 1.206
+++ defs.h 4 Jun 2007 12:32:21 -0000
@@ -417,6 +417,8 @@ extern unsigned long gnu_debuglink_crc32
ULONGEST strtoulst (const char *num, const char **trailer, int base);
+char *ldirname (const char *filename);
+
/* From demangle.c */
extern void set_demangling_style (char *);
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.220
diff -u -p -r1.220 dwarf2read.c
--- dwarf2read.c 18 May 2007 19:42:42 -0000 1.220
+++ dwarf2read.c 4 Jun 2007 12:32:23 -0000
@@ -2783,7 +2783,7 @@ read_file_scope (struct die_info *die, s
CORE_ADDR lowpc = ((CORE_ADDR) -1);
CORE_ADDR highpc = ((CORE_ADDR) 0);
struct attribute *attr;
- char *name = "<unknown>";
+ char *name = NULL;
char *comp_dir = NULL;
struct die_info *child_die;
bfd *abfd = objfile->obfd;
@@ -2806,21 +2806,29 @@ read_file_scope (struct die_info *die, s
{
name = DW_STRING (attr);
}
+
attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
if (attr)
+ comp_dir = DW_STRING (attr);
+ else if (name != NULL && IS_ABSOLUTE_PATH (name))
{
- comp_dir = DW_STRING (attr);
- if (comp_dir)
- {
- /* Irix 6.2 native cc prepends <machine>.: to the compilation
- directory, get rid of it. */
- char *cp = strchr (comp_dir, ':');
+ comp_dir = ldirname (name);
+ if (comp_dir != NULL)
+ make_cleanup (xfree, comp_dir);
+ }
+ if (comp_dir != NULL)
+ {
+ /* Irix 6.2 native cc prepends <machine>.: to the compilation
+ directory, get rid of it. */
+ char *cp = strchr (comp_dir, ':');
- if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
- comp_dir = cp + 1;
- }
+ if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
+ comp_dir = cp + 1;
}
+ if (name == NULL)
+ name = "<unknown>";
+
attr = dwarf2_attr (die, DW_AT_language, cu);
if (attr)
{
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.176
diff -u -p -r1.176 utils.c
--- utils.c 30 Mar 2007 09:31:31 -0000 1.176
+++ utils.c 4 Jun 2007 12:32:23 -0000
@@ -3195,3 +3195,31 @@ strtoulst (const char *num, const char *
else
return result;
}
+
+/* Simple, portable version of dirname that does not modify its
+ argument. */
+
+char *
+ldirname (const char *filename)
+{
+ const char *base = lbasename (filename);
+ char *dirname;
+
+ while (base > filename && IS_DIR_SEPARATOR (base[-1]))
+ --base;
+
+ if (base == filename)
+ return NULL;
+
+ dirname = xmalloc (base - filename + 2);
+ memcpy (dirname, filename, base - filename);
+
+ /* On DOS based file systems, convert "d:foo" to "d:.", so that we
+ create "d:./bar" later instead of the (different) "d:/bar". */
+ if (base - filename == 2 && IS_ABSOLUTE_PATH (base)
+ && !IS_DIR_SEPARATOR (filename[0]))
+ dirname[base++ - filename] = '.';
+
+ dirname[base - filename] = '\0';
+ return dirname;
+}
Index: xml-tdesc.c
===================================================================
RCS file: /cvs/src/src/gdb/xml-tdesc.c,v
retrieving revision 1.5
diff -u -p -r1.5 xml-tdesc.c
--- xml-tdesc.c 13 Feb 2007 15:48:05 -0000 1.5
+++ xml-tdesc.c 4 Jun 2007 12:32:23 -0000
@@ -487,7 +487,6 @@ file_read_description_xml (const char *f
struct target_desc *tdesc;
char *tdesc_str;
struct cleanup *back_to;
- const char *base;
char *dirname;
tdesc_str = fetch_xml_from_file (filename, NULL);
@@ -499,28 +498,9 @@ file_read_description_xml (const char *f
back_to = make_cleanup (xfree, tdesc_str);
- /* Simple, portable version of dirname that does not modify its
- argument. */
- base = lbasename (filename);
- while (base > filename && IS_DIR_SEPARATOR (base[-1]))
- --base;
- if (base > filename)
- {
- dirname = xmalloc (base - filename + 2);
- memcpy (dirname, filename, base - filename);
-
- /* On DOS based file systems, convert "d:foo" to "d:.", so that
- we create "d:./bar" later instead of the (different)
- "d:/bar". */
- if (base - filename == 2 && IS_ABSOLUTE_PATH (base)
- && !IS_DIR_SEPARATOR (filename[0]))
- dirname[base++ - filename] = '.';
-
- dirname[base - filename] = '\0';
- make_cleanup (xfree, dirname);
- }
- else
- dirname = NULL;
+ dirname = ldirname (filename);
+ if (dirname != NULL)
+ make_cleanup (xfree, dirname);
tdesc = tdesc_parse_xml (tdesc_str, fetch_xml_from_file, dirname);
do_cleanups (back_to);
next reply other threads:[~2007-06-04 12:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-04 12:36 Daniel Jacobowitz [this message]
2012-04-06 12:37 ` Jan Kratochvil
2012-04-07 22:37 ` Daniel Jacobowitz
2012-04-07 23:27 ` Joseph S. Myers
2012-04-09 15:48 ` Jan Kratochvil
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=20070604123615.GA22533@caradoc.them.org \
--to=drow@false.org \
--cc=gdb-patches@sourceware.org \
/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