]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: New module checked_read
authorPetr Machata <pmachata@redhat.com>
Tue, 21 Sep 2010 20:13:26 +0000 (22:13 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 21 Sep 2010 20:13:26 +0000 (22:13 +0200)
- a bunch of functions that I couldn't place just right are there

14 files changed:
dwarflint/Makefile.am
dwarflint/check_debug_abbrev.cc
dwarflint/check_debug_abbrev.hh
dwarflint/check_debug_aranges.cc
dwarflint/check_debug_info.cc
dwarflint/check_debug_line.cc
dwarflint/check_debug_loc_range.cc
dwarflint/check_debug_pub.cc
dwarflint/checked_read.cc [new file with mode: 0644]
dwarflint/checked_read.h [new file with mode: 0644]
dwarflint/low.c
dwarflint/low.h
dwarflint/readctx.c
dwarflint/readctx.h

index ea22753dae471c2ac400674812944c7e458a53f3..673d94f926cd187b6f4fdf1b56146243a368095a 100644 (file)
@@ -46,6 +46,7 @@ dwarflint_SOURCES = \
        expected-at.cc expected.hh \
        coverage.cc coverage.h \
        readctx.c readctx.h \
+       checked_read.cc checked_read.h \
        pri.cc pri.hh \
        messages.cc messages.h \
        section_id.cc section_id.h \
index ad4c284329516fa5760dbf4961148c4369324a59..8cff94e230a263c04eaf5b201099a2fd39880a8b 100644 (file)
@@ -1,5 +1,5 @@
 /* Pedantic checking of DWARF files
-   Copyright (C) 2009 Red Hat, Inc.
+   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
@@ -32,6 +32,7 @@
 #include "pri.hh"
 #include "tables.hh"
 #include "sections.hh"
+#include "checked_read.h"
 
 #include <dwarf.h>
 #include <sstream>
@@ -522,3 +523,15 @@ check_debug_abbrev::~check_debug_abbrev ()
       free (it->second.abbr);
     }
 }
+
+int
+check_sibling_form (dwarf_version_h ver, uint64_t form)
+{
+  if (!dwver_form_allowed (ver, DW_AT_sibling, form))
+    return -2;
+  else if (form == DW_FORM_ref_addr)
+    return -1;
+  else
+    return 0;
+}
+
index 11cd1dec87bfb71bfd06fac5165cad461edd7a2e..e9bb451c2ff0486452a367d5fdc8c515dba27f20 100644 (file)
@@ -1,5 +1,5 @@
 /* Low-level checking of .debug_abbrev.
-   Copyright (C) 2009 Red Hat, Inc.
+   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
@@ -48,4 +48,6 @@ public:
   ~check_debug_abbrev ();
 };
 
+int check_sibling_form (dwarf_version_h ver, uint64_t form);
+
 #endif//DWARFLINT_CHECK_DEBUG_ABBREV_HH
index 3eacb462e74f2b6a5eac54c9865c543d2265c501..4283254a721cc77d3718272b00d280eed85191f8 100644 (file)
@@ -38,6 +38,7 @@
 #include "check_debug_info.hh"
 #include "check_debug_loc_range.hh"
 #include "cu_coverage.hh"
+#include "checked_read.h"
 
 checkdescriptor const *
 check_debug_aranges::descriptor ()
index 353f4a2900d3021621987b68805d4a2c0d43ece0..e6e91aea7d79ae8a9f5a5dfe6e2c5b298bef1a47 100644 (file)
@@ -36,6 +36,7 @@
 #include "pri.hh"
 #include "option.hh"
 #include "sections.hh"
+#include "checked_read.h"
 #include "check_debug_loc_range.hh"
 #include "check_debug_abbrev.hh"
 #include "check_debug_info.hh"
index e57fdb8d5e195478c925058b5cfc933bec2e2ee7..a4ea2551420ef991bbdd2868790586f325730dd4 100644 (file)
@@ -27,6 +27,7 @@
 #include "check_debug_info.hh"
 #include "sections.hh"
 #include "pri.hh"
+#include "checked_read.h"
 
 #include <dwarf.h>
 #include "../libdw/known-dwarf.h"
index c348fd3c3b1f9b875a507aa805bb7ba0996479a1..da82e00c497fed9769e81bc2b677898a41aade9c 100644 (file)
@@ -41,6 +41,7 @@
 #include "check_debug_loc_range.hh"
 #include "check_debug_info.hh"
 #include "sections.hh"
+#include "checked_read.h"
 #include "../src/dwarf-opcodes.h"
 #include "pri.hh"
 
index 1db93bf9a4fee24d0bff620f70a3d5d69292b274..2a7c0dd3faa2eac497d5c0f2d3dfa5012cb30bc0 100644 (file)
 #include "check_debug_info.hh"
 #include "sections.hh"
 #include "pri.hh"
-
-namespace
-{
-  template <class A, class B>
-  struct where xwhere (A a, B b)
-  {
-    return WHERE (a, b);
-  }
-}
+#include "checked_read.h"
 
 template<section_id sec_id>
 check_debug_pub<sec_id>::check_debug_pub (checkstack &stack, dwarflint &lint)
diff --git a/dwarflint/checked_read.cc b/dwarflint/checked_read.cc
new file mode 100644 (file)
index 0000000..fd5edeb
--- /dev/null
@@ -0,0 +1,131 @@
+/* Pedantic checking of DWARF files
+   Copyright (C) 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>.  */
+
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+#include "checked_read.h"
+#include "messages.h"
+
+bool
+read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep,
+                int *offset_sizep, struct where *where)
+{
+  if (size32 == DWARF3_LENGTH_64_BIT)
+    {
+      if (!read_ctx_read_8ubyte (ctx, sizep))
+       {
+         wr_error (where, ": can't read 64bit CU length.\n");
+         return false;
+       }
+
+      *offset_sizep = 8;
+    }
+  else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE)
+    {
+      wr_error (where, ": unrecognized CU length escape value: "
+               "%" PRIx32 ".\n", size32);
+      return false;
+    }
+  else
+    {
+      *sizep = size32;
+      *offset_sizep = 4;
+    }
+
+  return true;
+}
+
+bool
+read_address_size (struct read_ctx *ctx,
+                  bool addr_64,
+                  int *address_sizep,
+                  struct where const *where)
+{
+  uint8_t address_size;
+  if (!read_ctx_read_ubyte (ctx, &address_size))
+    {
+      wr_error (where, ": can't read address size.\n");
+      return false;
+    }
+
+  if (address_size != 4 && address_size != 8)
+    {
+      /* Keep going.  Deduce the address size from ELF header, and try
+        to parse it anyway.  */
+      wr_error (where,
+               ": invalid address size: %d (only 4 or 8 allowed).\n",
+               address_size);
+      address_size = addr_64 ? 8 : 4;
+    }
+  else if ((address_size == 8) != addr_64)
+    /* Keep going, we may still be able to parse it.  */
+    wr_error (where,
+             ": CU reports address size of %d in %d-bit ELF.\n",
+             address_size, addr_64 ? 64 : 32);
+
+  *address_sizep = address_size;
+  return true;
+}
+
+bool
+checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
+                     struct where *where, const char *what)
+{
+  const unsigned char *ptr = ctx->ptr;
+  int st = read_ctx_read_uleb128 (ctx, ret);
+  if (st < 0)
+    wr_error (where, ": can't read %s.\n", what);
+  else if (st > 0)
+    {
+      char buf[19]; // 16 hexa digits, "0x", terminating zero
+      sprintf (buf, "%#" PRIx64, *ret);
+      wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
+    }
+  return st >= 0;
+}
+
+bool
+checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
+                     struct where *where, const char *what)
+{
+  const unsigned char *ptr = ctx->ptr;
+  int st = read_ctx_read_sleb128 (ctx, ret);
+  if (st < 0)
+    wr_error (where, ": can't read %s.\n", what);
+  else if (st > 0)
+    {
+      char buf[20]; // sign, "0x", 16 hexa digits, terminating zero
+      int64_t val = *ret;
+      sprintf (buf, "%s%#" PRIx64, val < 0 ? "-" : "", val < 0 ? -val : val);
+      wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
+    }
+  return st >= 0;
+}
diff --git a/dwarflint/checked_read.h b/dwarflint/checked_read.h
new file mode 100644 (file)
index 0000000..caeba92
--- /dev/null
@@ -0,0 +1,54 @@
+/* Pedantic checking of DWARF files
+   Copyright (C) 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>.  */
+
+#ifndef DWARFLINT_CHECKED_READ_HH
+#define DWARFLINT_CHECKED_READ_HH
+
+#include "readctx.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+bool read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep,
+                     int *offset_sizep, struct where *where);
+
+bool read_address_size (struct read_ctx *ctx,
+                       bool addr_64,
+                       int *address_sizep,
+                       struct where const *where);
+
+bool checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
+                          struct where *where, const char *what);
+
+bool checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
+                          struct where *where, const char *what);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif//DWARFLINT_CHECKED_READ_HH
index 6a4e649a21761c80ad1c7d4bd631cc2068686ef6..da078859e605c0402edc815bdde4ea43e9813c1f 100644 (file)
@@ -60,52 +60,6 @@ necessary_alignment (uint64_t start, uint64_t length, uint64_t align)
   return address_aligned (start + length, align) && length < align;
 }
 
-bool
-checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
-                     struct where *where, const char *what)
-{
-  const unsigned char *ptr = ctx->ptr;
-  int st = read_ctx_read_uleb128 (ctx, ret);
-  if (st < 0)
-    wr_error (where, ": can't read %s.\n", what);
-  else if (st > 0)
-    {
-      char buf[19]; // 16 hexa digits, "0x", terminating zero
-      sprintf (buf, "%#" PRIx64, *ret);
-      wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
-    }
-  return st >= 0;
-}
-
-bool
-checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
-                     struct where *where, const char *what)
-{
-  const unsigned char *ptr = ctx->ptr;
-  int st = read_ctx_read_sleb128 (ctx, ret);
-  if (st < 0)
-    wr_error (where, ": can't read %s.\n", what);
-  else if (st > 0)
-    {
-      char buf[20]; // sign, "0x", 16 hexa digits, terminating zero
-      int64_t val = *ret;
-      sprintf (buf, "%s%#" PRIx64, val < 0 ? "-" : "", val < 0 ? -val : val);
-      wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
-    }
-  return st >= 0;
-}
-
-int
-check_sibling_form (dwarf_version_h ver, uint64_t form)
-{
-  if (!dwver_form_allowed (ver, DW_AT_sibling, form))
-    return -2;
-  else if (form == DW_FORM_ref_addr)
-    return -1;
-  else
-    return 0;
-}
-
 bool
 is_location_attrib (uint64_t name)
 {
index b10ce402fb3ff0a19f9163519bb5ba4b63f2a1f0..0527c5c2de458ac547705bdbca8fd63ca6a8855c 100644 (file)
@@ -120,11 +120,6 @@ extern "C"
   extern int check_sibling_form (dwarf_version_h ver, uint64_t form);
   extern bool is_location_attrib (uint64_t name);
 
-  bool checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
-                            struct where *where, const char *what);
-  bool checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
-                            struct where *where, const char *what);
-
   struct abbrev_attrib
   {
     struct where where;
index a8ca038b3d9851b9d64281391a8187d22b84307c..afd041dc90bd6e0aa93a65a1fd7d2dcb14dfdd98 100644 (file)
@@ -318,67 +318,6 @@ read_ctx_eof (struct read_ctx *ctx)
   return !read_ctx_need_data (ctx, 1);
 }
 
-bool
-read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep,
-                int *offset_sizep, struct where *where)
-{
-  if (size32 == DWARF3_LENGTH_64_BIT)
-    {
-      if (!read_ctx_read_8ubyte (ctx, sizep))
-       {
-         wr_error (where, ": can't read 64bit CU length.\n");
-         return false;
-       }
-
-      *offset_sizep = 8;
-    }
-  else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE)
-    {
-      wr_error (where, ": unrecognized CU length escape value: "
-               "%" PRIx32 ".\n", size32);
-      return false;
-    }
-  else
-    {
-      *sizep = size32;
-      *offset_sizep = 4;
-    }
-
-  return true;
-}
-
-bool
-read_address_size (struct read_ctx *ctx,
-                  bool addr_64,
-                  int *address_sizep,
-                  struct where const *where)
-{
-  uint8_t address_size;
-  if (!read_ctx_read_ubyte (ctx, &address_size))
-    {
-      wr_error (where, ": can't read address size.\n");
-      return false;
-    }
-
-  if (address_size != 4 && address_size != 8)
-    {
-      /* Keep going.  Deduce the address size from ELF header, and try
-        to parse it anyway.  */
-      wr_error (where,
-               ": invalid address size: %d (only 4 or 8 allowed).\n",
-               address_size);
-      address_size = addr_64 ? 8 : 4;
-    }
-  else if ((address_size == 8) != addr_64)
-    /* Keep going, we may still be able to parse it.  */
-    wr_error (where,
-             ": CU reports address size of %d in %d-bit ELF.\n",
-             address_size, addr_64 ? 64 : 32);
-
-  *address_sizep = address_size;
-  return true;
-}
-
 static void
 update_off (struct read_ctx *ctx,
            uint64_t *ret_off)
index 99b1c7da553bcb23f9c2add6a703e847d84245ae..29fc451c03ad5a1d8d011feb460037b2876bb261 100644 (file)
@@ -29,9 +29,6 @@
 #include <stdbool.h>
 #include "../libelf/libelf.h"
 
-// xxx We don't really like this one
-#include "where.h"
-
 #ifdef __cplusplus
 extern "C"
 {
@@ -77,18 +74,6 @@ const char *read_ctx_read_str (struct read_ctx *ctx);
 bool read_ctx_skip (struct read_ctx *ctx, uint64_t len);
 bool read_ctx_eof (struct read_ctx *ctx);
 
-/* The following procedures build on the ones above and do their own
-   error reporting in addition.  */
-
-bool read_size_extra (struct read_ctx *ctx, uint32_t size32,
-                     uint64_t *sizep, int *offset_sizep,
-                     struct where *where);
-
-bool read_address_size (struct read_ctx *ctx,
-                       bool addr_64,
-                       int *address_sizep,
-                       struct where const *where);
-
 /* See if what remains in the read context is just a zero padding.  If
    yes, return true.  If it isn't, revert the read pointer back as if
    nothing had happened and return false.  Furthermore, in any case,