This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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]

Re: dwarf_output overview


On Wed, 2010-08-18 at 20:06 +0200, Mark Wielaard wrote:
> On Wed, 2010-08-18 at 10:59 -0700, Roland McGrath wrote:
> > > But then I get in similar trouble inside the subr::equal_to template
> > > code. Specifically the elfutils::subr::equal_to<std::basic_string<char,
> > > std::char_traits<char>, std::allocator<char> >, char const*>::operator()
> > > instance, which will crash and burn trying to compare the empty string
> > > and the NULL. Still looking into that. 
> > 
> > I think those comparisons should work like dwarf::directory_table::table_equal 
> > and ignore the first element anyway.  I did a tweak to dwarf_data to do that.
> 
> Yes, that is what I ended up doing too.

Actually my approach was slightly different. I changed the line_info
directory_table extractors to skip the zeroth entry. So the table_equal
implementations can just compare only the "real" entries. If we don't do
this then the NULL (zero) entries are still there and will blow up the
dwarf_output copy constructor. (Try src/dwarfcmp-test -T src/ar src/ar)

Patch attached. What do you think?

Cheers,

Mark
diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf
index c698c1e..d99c7e1 100644
--- a/libdw/c++/dwarf
+++ b/libdw/c++/dwarf
@@ -1610,14 +1610,10 @@ namespace elfutils
       template<typename table>
       inline bool table_equal (const table &other) const
       {
-	/* We ignore the first element, the compilation directory.
-	   This is not encoded in the .debug_line table, but in
-	   the DW_AT_comp_dir attribute of the referring CU.
-	   The directory table itself matches regardless.  */
 	const_iterator i = begin ();
 	typename table::const_iterator j = other.begin ();
 	return subr::container_equal
-	  (++i, end (), ++j, other.end (),
+	  (i, end (), j, other.end (),
 	   subr::deref<directory_table, table,
 	   	       subr::name_equal<typename table::value_type> > ());
       }
diff --git a/libdw/c++/dwarf_data b/libdw/c++/dwarf_data
index daf0aa2..1a75d9e 100644
--- a/libdw/c++/dwarf_data
+++ b/libdw/c++/dwarf_data
@@ -318,11 +318,8 @@ namespace elfutils
       template<typename table>
       inline bool operator== (const table &other) const
       {
-	/* We ignore the first element, the compilation directory.
-	   This is actually part of the CU, not part of the line info.
-	   The directory table itself matches regardless.  */
 	return (size () == other.size ()
-		&& subr::container_tail_equal (*this, other, 1));
+		&& subr::container_equal (*this, other));
       }
       template<typename table>
       inline bool operator!= (const table &other) const
diff --git a/libdw/c++/line_info.cc b/libdw/c++/line_info.cc
index b913da6..89e0952 100644
--- a/libdw/c++/line_info.cc
+++ b/libdw/c++/line_info.cc
@@ -176,7 +176,11 @@ dwarf::source_file::to_string () const
 size_t
 dwarf::directory_table::size () const
 {
-  return _m_files->ndirs;
+  /* We ignore the first element, the compilation directory.
+     This is not encoded in the .debug_line table, but in
+     the DW_AT_comp_dir attribute of the referring CU.
+     The directory table itself matches regardless.  */
+  return _m_files->ndirs - 1;
 }
 
 static inline dwarf::directory_table::const_iterator
@@ -189,7 +193,11 @@ directory_table_array (Dwarf_Files *files)
 dwarf::directory_table::const_iterator
 dwarf::directory_table::begin () const
 {
-  return directory_table_array (_m_files);
+  /* We ignore the first element, the compilation directory.
+     This is not encoded in the .debug_line table, but in
+     the DW_AT_comp_dir attribute of the referring CU.
+     The directory table itself matches regardless.  */
+  return directory_table_array (_m_files) + 1;
 }
 
 dwarf::directory_table::const_iterator

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