]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
<dwarf>: Don't swallow last attribute
authorPetr Machata <pmachata@redhat.com>
Wed, 25 Mar 2009 14:25:00 +0000 (15:25 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 25 Mar 2009 14:25:00 +0000 (15:25 +0100)
libdw/ChangeLog
libdw/c++/dwarf
tests/ChangeLog
tests/Makefile.am
tests/dwarf-attributes.cc [new file with mode: 0644]
tests/run-dwarf-attributes.sh [new file with mode: 0755]

index f9320db6ca23bcf71593e0795239961929c7e67a..f2a73f2b52028587ef94ff202d0c37182125983d 100644 (file)
@@ -1,3 +1,8 @@
+2009-03-24  Petr Machata  <pmachata@redhat.com>
+
+       * c++/dwarf (dwarf::debug_info_entry::raw_attributes):
+       Fix iteration over attributes.
+
 2009-03-24  Roland McGrath  <roland@redhat.com>
 
        * Makefile.am (libdwpp_a_SOURCES): New variable.
index aba8b0a05b8469bcbcb0bc214e1a8d3dde942670..c6a31a91304ddb0ab66d905d30150f087cc2ae2e 100644 (file)
@@ -612,7 +612,7 @@ namespace elfutils
        inline bool operator== (const const_iterator &other) const
        {
          return (_m_die._m_die.addr == other._m_die._m_die.addr
-                 && _m_offset == other._m_offset);
+                 && _m_attr.valp == other._m_attr.valp);
        }
        inline bool operator!= (const const_iterator &other) const
        {
@@ -637,7 +637,7 @@ namespace elfutils
 
        inline attribute operator* () const
        {
-         if (unlikely (_m_offset == 1))
+         if (unlikely (_m_offset == 1 && _m_attr.valp == NULL))
            throw std::runtime_error ("dereferencing end iterator");
          return attribute (_m_die, _m_attr);
        }
index 5affd0c477dacec8d146af48f70dc00d3da32650..e68018e7199912381aed33ea0825be94fddc80a1 100644 (file)
@@ -1,3 +1,9 @@
+2009-03-25  Petr Machata  <pmachata@redhat.com>
+
+       * dwarf-attributes.cc: New file.
+       * Makefile.am (noinst_PROGRAMS): Add it.
+       (dwarf_attributes_SOURCES, dwarf_attributes_LDADD): New variables.
+
 2009-03-24  Roland McGrath  <roland@redhat.com>
 
        * dwarf-print.cc: New file.
index e075fd037dfc0e36d339fda718b9b9970666319d..d554f1a577a2705db8620569135962e782d48353 100644 (file)
@@ -61,7 +61,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
                  dwfl-bug-addr-overflow arls dwfl-bug-fd-leak \
                  dwfl-addr-sect dwfl-bug-report early-offscn \
                  dwfl-bug-getmodules \
-                 dwarf-print
+                 dwarf-print dwarf-attributes
 # get-ciefde
 asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
            asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -88,7 +88,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
        run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \
        run-disasm-x86.sh run-disasm-x86-64.sh \
        run-early-offscn.sh \
-       run-dwarfcmp-self.sh run-dwarflint-self.sh
+       run-dwarfcmp-self.sh run-dwarflint-self.sh run-dwarf-attributes.sh
 # run-show-ciefde.sh
 
 if !STANDALONE
@@ -192,6 +192,9 @@ libdwpp = ../libdw/libdwpp.a $(libdw)
 dwarf_print_SOURCES = dwarf-print.cc
 dwarf_print_LDADD = $(libdwpp) $(libmudflap) -ldl
 
+dwarf_attributes_SOURCES = dwarf-attributes.cc
+dwarf_attributes_LDADD = $(libdwpp) $(libmudflap) -ldl
+
 arextract_LDADD = $(libelf) $(libmudflap)
 arsymtest_LDADD = $(libelf) $(libmudflap)
 newfile_LDADD = $(libelf) $(libmudflap)
diff --git a/tests/dwarf-attributes.cc b/tests/dwarf-attributes.cc
new file mode 100644 (file)
index 0000000..9e9b291
--- /dev/null
@@ -0,0 +1,112 @@
+/* Test program for elfutils::dwarf basics.
+   Copyright (C) 2009 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by the
+   Free Software Foundation; version 2 of the License.
+
+   Red Hat elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <clocale>
+#include <libintl.h>
+#include <ostream>
+#include <iomanip>
+#include <known-dwarf.h>
+
+#include "c++/dwarf"
+
+using namespace elfutils;
+
+const char *
+dwarf_attr_string (unsigned int attrnum)
+{
+  switch (attrnum)
+    {
+#define ONE_KNOWN_DW_AT(NAME, TAG)     \
+      case TAG: return #NAME;
+      ALL_KNOWN_DW_AT
+#undef ONE_KNOWN_DW_AT
+    default:
+       static char buf[40];
+       if (attrnum < DW_AT_lo_user)
+         snprintf (buf, sizeof buf, "unknown attribute %hx",
+                   attrnum);
+       else
+         snprintf (buf, sizeof buf, "unknown user attribute %hx",
+                   attrnum);
+       return buf;
+    }
+}
+
+static Dwarf *
+open_file (const char *fname)
+{
+  int fd = open (fname, O_RDONLY);
+  if (unlikely (fd == -1))
+    error (2, errno, gettext ("cannot open '%s'"), fname);
+  Dwarf *dw = dwarf_begin (fd, DWARF_C_READ);
+  if (dw == NULL)
+    {
+      error (2, 0,
+            gettext ("cannot create DWARF descriptor for '%s': %s"),
+            fname, dwarf_errmsg (-1));
+    }
+  return dw;
+}
+
+void
+process_file (char const *file)
+{
+  dwarf dw (open_file (file));
+
+  std::cout << file << ":\n";
+
+  elfutils::dwarf::compile_unit const &cu = *dw.compile_units ().begin ();
+  for (elfutils::dwarf::debug_info_entry::attributes::const_iterator
+        it = cu.attributes ().begin (); it != cu.attributes ().end (); ++it)
+    {
+      elfutils::dwarf::attribute at = *it;
+      std::cout << (*it).first << std::endl;
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* Set locale.  */
+  (void) setlocale (LC_ALL, "");
+
+  /* Make sure the message catalog can be found.  */
+  (void) bindtextdomain (PACKAGE_TARNAME, LOCALEDIR);
+
+  /* Initialize the message catalog.  */
+  (void) textdomain (PACKAGE_TARNAME);
+
+  for (int i = 1; i < argc; ++i)
+    process_file (argv[i]);
+
+  return 0;
+}
diff --git a/tests/run-dwarf-attributes.sh b/tests/run-dwarf-attributes.sh
new file mode 100755 (executable)
index 0000000..05e9b3e
--- /dev/null
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Red Hat, Inc.
+# This file is part of Red Hat elfutils.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# Red Hat elfutils is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# Red Hat elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Red Hat elfutils; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+#
+# Red Hat elfutils is an included package of the Open Invention Network.
+# An included package of the Open Invention Network is a package for which
+# Open Invention Network licensees cross-license their patents.  No patent
+# license is granted, either expressly or impliedly, by designation as an
+# included package.  Should you wish to participate in the Open Invention
+# Network licensing program, please visit www.openinventionnetwork.com
+# <http://www.openinventionnetwork.com>.
+
+. $srcdir/test-subr.sh
+
+testfiles testfile
+
+testrun_compare ./dwarf-attributes testfile <<\EOF
+testfile:
+16
+18
+17
+3
+27
+37
+19
+EOF
+
+exit 0