This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH/RFC handle missing DW_AT_comp_dir attribute


This problem was found by a colleague while using GDB with the ADS tools.

These tools do not set the DW_AT_comp_dir attribute in a compilation unit 
entry, so GDB will crash trying to reference a NULL pointer.

Regardless of whether ADS is correct not to generate this directive (the 
Dwarf spec appears not to require it to), GDB should not be falling over 
in this way.  The following patch fixes the problem:

<date>  Ian Rickards  <irickard@arm.com>

	* dwarf2.c (concat_filename): If we can't establish the directory 
	just return the filename.


Index: dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.32
diff -p -r1.32 dwarf2.c
*** dwarf2.c	27 Jun 2002 11:51:42 -0000	1.32
--- dwarf2.c	17 Jul 2002 10:38:03 -0000
*************** concat_filename (table, file)
*** 856,868 ****
    filename = table->files[file - 1].name;
    if (IS_ABSOLUTE_PATH(filename))
      return filename;
- 
    else
      {
        char* dirname = (table->files[file - 1].dir
  		       ? table->dirs[table->files[file - 1].dir - 1]
  		       : table->comp_dir);
!       return (char*) concat (dirname, "/", filename, NULL);
      }
  }
  
--- 856,873 ----
    filename = table->files[file - 1].name;
    if (IS_ABSOLUTE_PATH(filename))
      return filename;
    else
      {
        char* dirname = (table->files[file - 1].dir
  		       ? table->dirs[table->files[file - 1].dir - 1]
  		       : table->comp_dir);
! 
!       /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.  The
! 	 best we can do is return the filename part.  */
!       if (dirname == NULL)
! 	return filename;
!       else
! 	return (char*) concat (dirname, "/", filename, NULL);
      }
  }
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]