]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Check for missind debuginfo sections separately
authorPetr Machata <pmachata@redhat.com>
Tue, 14 Sep 2010 14:14:17 +0000 (16:14 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 14 Sep 2010 14:14:17 +0000 (16:14 +0200)
dwarflint/Makefile.am
dwarflint/check_nodebug.cc [new file with mode: 0644]
dwarflint/sections.cc

index 1f6c84e20cc66031dfd18114469497685fde16f6..d08953e7a0bfca7e125c36dea68f3a392419ebb2 100644 (file)
@@ -70,6 +70,7 @@ dwarflint_SOURCES = \
        check_expected_trees.cc \
        check_dups_abstract_origin.cc \
        check_duplicate_DW_tag_variable.cc \
+       check_nodebug.cc \
        ../src/dwarfstrings.c
 
 TESTS = tests/run-debug_abbrev-duplicate-attribute.sh \
diff --git a/dwarflint/check_nodebug.cc b/dwarflint/check_nodebug.cc
new file mode 100644 (file)
index 0000000..cdbc842
--- /dev/null
@@ -0,0 +1,73 @@
+/* Pedantic checking of DWARF files
+   Copyright (C) 2009,2010 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>.  */
+
+#include "checks.hh"
+#include "options.h"
+#include "messages.h"
+#include "sections.hh"
+
+class check_nodebug
+  : public check<check_nodebug>
+{
+public:
+  static checkdescriptor const *descriptor ()
+  {
+    static checkdescriptor cd
+      (checkdescriptor::create ("check_nodebug")
+       .groups ("@low"));
+    return &cd;
+  }
+
+  check_nodebug (checkstack &stack, dwarflint &lint);
+
+private:
+  void not_available (section_id sec_id)
+  {
+    wr_error (WHERE (sec_id, NULL))
+      << "data not found." << std::endl;
+  }
+
+  template <section_id sec_id>
+  void request (checkstack &stack, dwarflint &lint)
+  {
+    if (lint.toplev_check<section<sec_id> > (stack) == NULL)
+      not_available (sec_id);
+  }
+
+};
+
+static reg<check_nodebug> reg_nodebug;
+
+check_nodebug::check_nodebug (checkstack &stack, dwarflint &lint)
+{
+  if (tolerate_nodebug)
+    return;
+
+  // We demand .debug_info and .debug_abbrev, the rest is optional.
+  // Presence of the other sections is (or should be) requested if
+  // there are pending references from .debug_info.
+  request<sec_abbrev> (stack, lint);
+  request<sec_info> (stack, lint);
+}
index 91ecaac112f1ab8054701b64e54aba7b63bebd18..a8932334a5be8f1b8621f462a81284f753e08403 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <cstdlib>
 #include <cstring>
-#include <sstream>
 #include "../libelf/gelf.h"
 
 #include "sections.hh"
@@ -426,44 +425,6 @@ load_sections::~load_sections ()
   elf_end (file.elf);
 }
 
-namespace
-{
-  message_category
-  secid_to_cat (section_id secid)
-  {
-    switch (secid)
-      {
-      case sec_info: return mc_info;
-      case sec_abbrev: return mc_abbrevs;
-      case sec_aranges: return mc_aranges;
-      case sec_str: return mc_strings;
-      case sec_line: return mc_line;
-      case sec_loc: return mc_loc;
-      case sec_ranges: return mc_ranges;
-      case sec_mac: return mc_mac;
-
-      case sec_pubnames:
-      case sec_pubtypes:
-       return mc_pubtables;
-
-      case sec_rel:
-      case sec_rela:
-       return mc_reloc;
-
-       // xxx don't have one
-      case sec_invalid:
-      case sec_locexpr:
-      case rel_value:
-      case rel_address:
-      case rel_exec:
-       break;
-      };
-    std::stringstream ss;
-    ss << "Couldn't convert secid " << secid << " to mc.";
-    throw std::runtime_error (ss.str ());
-  }
-}
-
 sec &
 section_base::get_sec_or_throw (section_id secid)
 {
@@ -471,12 +432,6 @@ section_base::get_sec_or_throw (section_id secid)
     if (s->data != NULL)
       return *s;
 
-  if (!tolerate_nodebug)
-    wr_message (WHERE (secid, NULL),
-               cat (mc_impact_4, mc_acc_suboptimal, mc_elf,
-                    secid_to_cat (secid)))
-      << "data not found." << std::endl;
-
   throw check_base::failed ();
 }