]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Tolerate attributes from all DWARF versions, be less strict
authorPetr Machata <pmachata@redhat.com>
Wed, 23 Mar 2011 17:44:30 +0000 (18:44 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 23 Mar 2011 17:44:30 +0000 (18:44 +0100)
dwarflint/Makefile.am
dwarflint/check_debug_abbrev.cc
dwarflint/dwarf_version.cc
dwarflint/dwarf_version.hh
dwarflint/tests/DW_AT-later-version.bz2 [new file with mode: 0644]
dwarflint/tests/run-DW_AT-later-version.sh [new file with mode: 0755]
dwarflint/tests/run-bad.sh
dwarflint/tests/run-libdl-2.12.so.debug.sh

index 4317edc32b544401e137b70e31c959e29a803fd7..2247d0e94659e894ec4ee0eba6fcec8629bf101e 100644 (file)
@@ -106,7 +106,8 @@ EXTRA_TESTS = tests/run-debug_abbrev-duplicate-attribute.sh \
        tests/run-bad.sh \
        tests/run-check_self_referential_die.sh \
        tests/run-DW_AT_high_pc-relative.sh \
-       tests/run-DW_AT_high_pc-below.sh
+       tests/run-DW_AT_high_pc-below.sh \
+       tests/run-DW_AT-later-version.sh
 
 TESTS = $(EXTRA_TESTS) \
        tests/test-coverage \
@@ -138,7 +139,8 @@ EXTRA_DIST = $(EXTRA_TESTS) \
        tests/garbage-12.bz2 \
        tests/check_self_referential_die.bz2 \
        tests/DW_AT_high_pc-relative.bz2 \
-       tests/DW_AT_high_pc-below.bz2
+       tests/DW_AT_high_pc-below.bz2 \
+       tests/DW_AT-later-version.bz2
 
 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
                              bindir=$(DESTDIR)$(bindir) \
index 39b5f316de25fd4e9a90b2e0a3e62053ec2aadc8..c8038c6d353db77614336376972ef80e8700a556 100644 (file)
@@ -156,6 +156,7 @@ namespace
 
     // Tolerate failure here.
     dwarf_version const *ver = NULL;
+    static dwarf_version const *latest_ver = dwarf_version::get_latest ();
     where.addr1 = 0;
 
     bool failed = false;
@@ -285,7 +286,7 @@ namespace
                  << "couldn't load CU headers for processing .debug_abbrev; "
                     "assuming latest DWARF flavor."
                  << std::endl;
-               ver = dwarf_version::get_latest ();
+               ver = latest_ver;
              }
 
            assert (ver != NULL);
@@ -397,11 +398,24 @@ namespace
            attribute const *attribute = ver->get_attribute (attrib_name);
            if (attribute == NULL)
              {
-               wr_error (where)
-                 << "invalid or unknown name " << pri::hex (attrib_name)
-                 << '.' << std::endl;
-               // libdw should handle unknown attribute, as long as
-               // the form is kosher, so don't fail the check.
+               // GCC commonly emits DWARF 2 with trivial extensions
+               // (such as attribute names) from newer versions.  In
+               // GNU mode, don't even mind this.  In non-gnu, emit
+               // warning.  We explicitly don't do this for forms,
+               // where the consumer wouldn't know how to read or
+               // skip the datum.
+               attribute = latest_ver->get_attribute (attrib_name);
+               if (attribute == NULL)
+                 // libdw should handle unknown attribute, as long as
+                 // the form is kosher, so don't fail the check.
+                 wr_message (where, mc_abbrevs | mc_impact_1)
+                   << "invalid or unknown name " << pri::hex (attrib_name)
+                   << '.' << std::endl;
+               else if (opt_nognu)
+                 wr_message (where, mc_abbrevs | mc_impact_1)
+                   << "attribute " << *attribute
+                   << " from later DWARF version."
+                   << std::endl;
              }
 
            form const *form = check_debug_abbrev::check_form
@@ -410,7 +424,7 @@ namespace
              // Error message has been emitted in check_form.
              failed = true;
 
-           if (form == NULL || attribute == NULL)
+           if (form == NULL)
              continue;
 
            std::pair<std::map<unsigned, uint64_t>::iterator, bool> inserted
@@ -418,7 +432,8 @@ namespace
            if (!inserted.second)
              {
                wr_error (where)
-                 << "duplicate attribute " << *attribute
+                 << "duplicate attribute "
+                 << elfutils::dwarf::attributes::name (attrib_name)
                  << " (first was at " << pri::hex (inserted.first->second)
                  << ")." << std::endl;
                // I think we may allow such files for high-level
index fc4595a65ee46f2e7b7cf9113f680d66cfe7c7b9..a74e1699b87c1f84ef34395b352a422510b52167 100644 (file)
@@ -45,6 +45,9 @@
 #include "dwarf_mips.hh"
 #include "check_debug_info.hh"
 
+global_opt<void_option>
+  opt_nognu ("Don't use GNU extension.", "nognu");
+
 dw_class_set::dw_class_set (dw_class a, dw_class b, dw_class c,
                            dw_class d, dw_class e)
 {
@@ -118,7 +121,7 @@ form::width (cu_head const *cu_head) const
 std::ostream &
 operator << (std::ostream &os, form const &obj)
 {
-  return os << elfutils::dwarf::forms::name (obj.name ());
+  return os << elfutils::dwarf::forms::identifier (obj.name ());
 }
 
 namespace
@@ -139,7 +142,7 @@ attribute::attribute (int a_name, dw_class_set const &a_classes)
 std::ostream &
 operator << (std::ostream &os, attribute const &obj)
 {
-  return os << elfutils::dwarf::attributes::name (obj.name ());
+  return os << elfutils::dwarf::attributes::identifier (obj.name ());
 }
 
 
@@ -230,9 +233,6 @@ dwarf_version::extend (dwarf_version const *source,
   return new dwarf_version_union (source, extension);
 }
 
-global_opt<void_option>
-  nognu ("Don't use GNU extension.", "nognu");
-
 namespace
 {
   dwarf_version const *get_ext ()
@@ -244,7 +244,7 @@ namespace
     // need the version to know how to read these attributes in the
     // first place.
 
-    if (nognu)
+    if (opt_nognu)
       return dwarf_mips_ext ();
     else
       return dwarf_version::extend (dwarf_mips_ext (), dwarf_gnu_ext ());
index 43df29e964691eeca09ba0d5426b0469394cfb9c..f130b8d25d6bbb0b8bf7a9983f53f32a107e9e2f 100644 (file)
@@ -31,6 +31,9 @@
 #include <iosfwd>
 #include "check_debug_info.ii"
 #include "dwarf_version.ii"
+#include "option.hh"
+
+extern global_opt<void_option> opt_nognu;
 
 enum dw_class
   {
diff --git a/dwarflint/tests/DW_AT-later-version.bz2 b/dwarflint/tests/DW_AT-later-version.bz2
new file mode 100644 (file)
index 0000000..2a5690b
Binary files /dev/null and b/dwarflint/tests/DW_AT-later-version.bz2 differ
diff --git a/dwarflint/tests/run-DW_AT-later-version.sh b/dwarflint/tests/run-DW_AT-later-version.sh
new file mode 100755 (executable)
index 0000000..b2f0265
--- /dev/null
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2011 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>.
+
+. $srcdir/../tests/test-subr.sh
+
+srcdir=$srcdir/tests
+
+testfiles DW_AT-later-version
+
+testrun_compare ./dwarflint --nognu DW_AT-later-version <<EOF
+warning: .debug_abbrev: abbr. attribute 0x15: attribute DW_AT_endianity from later DWARF version.
+warning: .debug_info: DIE 0xb: DW_AT_low_pc value not below DW_AT_high_pc.
+EOF
index 6e6db3ff3d97b010d7ab8b3c3c868857f066f873..3080f3e9a25020ba12ffb7e96b3f663f55094707 100755 (executable)
@@ -87,7 +87,7 @@ error: .debug_abbrev: abbr. attribute 0x34: attribute location with invalid form
 EOF
 
 testrun_compare ./dwarflint garbage-7 <<EOF
-error: .debug_abbrev: abbr. attribute 0x7e: invalid or unknown name 0x703.
+warning: .debug_abbrev: abbr. attribute 0x7e: invalid or unknown name 0x703.
 error: .debug_abbrev: abbr. attribute 0x7e: invalid form 0x0.
 error: .debug_abbrev: abbreviation 122: missing zero to mark end-of-table.
 EOF
index c02a8095f4735d39ca8265b348b915d85269572d..f3fbcfb4cbd5a40b9e546897a21edded922c3f49 100755 (executable)
@@ -31,11 +31,11 @@ testfiles libdl-2.12.so.debug
 
 # Here we test that dwarflint can tolerate invalid attribute name.
 testrun_compare ./dwarflint --check=@low --nognu --ignore-bloat libdl-2.12.so.debug <<EOF
-error: .debug_abbrev: abbr. attribute 0xbe: invalid or unknown name 0x2107.
-error: .debug_abbrev: abbr. attribute 0x330: invalid or unknown name 0x2107.
-error: .debug_abbrev: abbr. attribute 0xa28: invalid or unknown name 0x2107.
-error: .debug_abbrev: abbr. attribute 0x108e: invalid or unknown name 0x2107.
-error: .debug_abbrev: abbr. attribute 0x1300: invalid or unknown name 0x2107.
+warning: .debug_abbrev: abbr. attribute 0xbe: invalid or unknown name 0x2107.
+warning: .debug_abbrev: abbr. attribute 0x330: invalid or unknown name 0x2107.
+warning: .debug_abbrev: abbr. attribute 0xa28: invalid or unknown name 0x2107.
+warning: .debug_abbrev: abbr. attribute 0x108e: invalid or unknown name 0x2107.
+warning: .debug_abbrev: abbr. attribute 0x1300: invalid or unknown name 0x2107.
 warning: .debug_info: DIE 0xd9a8: DW_AT_low_pc value not below DW_AT_high_pc.
 warning: .debug_info: DIE 0xdcd7: DW_AT_low_pc value not below DW_AT_high_pc.
 warning: .debug_info: CU 55709: no aranges table is associated with this CU.