]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: More moving code around
authorPetr Machata <pmachata@redhat.com>
Thu, 8 Oct 2009 18:18:10 +0000 (20:18 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:11 +0000 (14:55 +0200)
src/Makefile.am
src/dwarflint-config.cc [new file with mode: 0644]
src/dwarflint-config.h [new file with mode: 0644]
src/dwarflint-main.cc
src/dwarflint-where.c [new file with mode: 0644]
src/dwarflint.c
src/dwarflint.h

index 87ece19375a149b3d4d0a57d38851dfaf50ccc6c..1b2bf1bf2f5ff287f904235a3147e8cf16c329e8 100644 (file)
@@ -84,7 +84,9 @@ dwarflint_SOURCES = dwarfstrings.c \
                    dwarflint-hl.cc dwarflint-expected-at.cc dwarflint-expected.hh \
                    dwarflint-coverage.cc dwarflint-coverage.h \
                    dwarflint-readctx.c  dwarflint-readctx.h \
-                   dwarflint-messages.cc dwarflint-messages.h dwarflint-where.h
+                   dwarflint-messages.cc dwarflint-messages.h \
+                   dwarflint-where.c dwarflint-where.h \
+                   dwarflint-config.cc dwarflint-config.h
 
 readelf_SOURCES = readelf.c dwarfstrings.c
 
diff --git a/src/dwarflint-config.cc b/src/dwarflint-config.cc
new file mode 100644 (file)
index 0000000..81fe871
--- /dev/null
@@ -0,0 +1,14 @@
+#include "dwarflint-config.h"
+
+/* If true, we accept silently files without debuginfo.  */
+bool tolerate_nodebug = false;
+
+/* True if no message is to be printed if the run is succesful.  */
+bool be_quiet = false; /* -q */
+bool be_verbose = false; /* -v */
+bool be_strict = false; /* --strict */
+bool be_gnu = false; /* --gnu */
+bool be_tolerant = false; /* --tolerant */
+bool show_refs = false; /* --ref */
+bool do_high_level = true; /* ! --nohl */
+bool dump_die_offsets = false; /* --dump-offsets */
diff --git a/src/dwarflint-config.h b/src/dwarflint-config.h
new file mode 100644 (file)
index 0000000..6392778
--- /dev/null
@@ -0,0 +1,21 @@
+#ifdef __cplusplus
+extern "C"
+{
+#else
+#include <stdbool.h>
+#endif
+
+  /* Whole-program options.  */
+  extern bool tolerate_nodebug;
+  extern bool be_quiet; /* -q */
+  extern bool be_verbose; /* -v */
+  extern bool be_strict; /* --strict */
+  extern bool be_gnu; /* --gnu */
+  extern bool be_tolerant; /* --tolerant */
+  extern bool show_refs; /* --ref */
+  extern bool do_high_level; /* ! --nohl */
+  extern bool dump_die_offsets; /* --dump-offsets */
+
+#ifdef __cplusplus
+}
+#endif
index a9ecc20485707f0fb86db33c2029c78a55fa1745..4cf4a202e4573644bcd0a1f94b640e139352cf1b 100644 (file)
@@ -36,6 +36,7 @@
 #include <iostream>
 
 #include "dwarflint.h"
+#include "dwarflint-config.h"
 
 /* Bug report address.  */
 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
@@ -79,19 +80,6 @@ Pedantic checking of DWARF stored in ELF files.");
 /* Strings for arguments in help texts.  */
 static const char args_doc[] = N_("FILE...");
 
-/* If true, we accept silently files without debuginfo.  */
-bool tolerate_nodebug = false;
-
-/* True if no message is to be printed if the run is succesful.  */
-bool be_quiet = false; /* -q */
-bool be_verbose = false; /* -v */
-bool be_strict = false; /* --strict */
-bool be_gnu = false; /* --gnu */
-bool be_tolerant = false; /* --tolerant */
-bool show_refs = false; /* --ref */
-bool do_high_level = true; /* ! --nohl */
-bool dump_die_offsets = false; /* --dump-offsets */
-
 /* Messages that are accepted (and made into warning).  */
 struct message_criteria warning_criteria;
 
diff --git a/src/dwarflint-where.c b/src/dwarflint-where.c
new file mode 100644 (file)
index 0000000..3d89cb4
--- /dev/null
@@ -0,0 +1,181 @@
+#include "dwarflint-where.h"
+#include "dwarflint-config.h"
+
+#include <inttypes.h>
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+const char *
+where_fmt (const struct where *wh, char *ptr)
+{
+  if (wh == NULL)
+    return "";
+
+  static char buf[256];
+
+  struct section_info
+  {
+    const char *name;
+    const char *addr1n;
+    const char *addr1f;
+    const char *addr2n;
+    const char *addr2f;
+    const char *addr3n;
+    const char *addr3f;
+  };
+
+  static struct section_info section_names[] =
+    {
+      [sec_info] = {".debug_info", "CU", "%"PRId64,
+                   "DIE", "%#"PRIx64, NULL, NULL},
+
+      [sec_abbrev] = {".debug_abbrev", "section", "%"PRId64,
+                     "abbreviation", "%"PRId64, "abbr. attribute", "%#"PRIx64},
+
+      [sec_aranges] = {".debug_aranges", "table", "%"PRId64,
+                      "arange", "%#"PRIx64, NULL, NULL},
+
+      [sec_pubnames] = {".debug_pubnames", "pubname table", "%"PRId64,
+                       "pubname", "%#"PRIx64, NULL, NULL},
+
+      [sec_pubtypes] = {".debug_pubtypes", "pubtype table", "%"PRId64,
+                       "pubtype", "%#"PRIx64, NULL, NULL},
+
+      [sec_str] = {".debug_str", "offset", "%#"PRIx64,
+                  NULL, NULL, NULL, NULL},
+
+      [sec_line] = {".debug_line", "table", "%"PRId64,
+                   "offset", "%#"PRIx64, NULL, NULL},
+
+      [sec_loc] = {".debug_loc", "loclist", "%#"PRIx64,
+                  "offset", "%#"PRIx64, NULL, NULL},
+
+      [sec_mac] = {".debug_mac", NULL, NULL, NULL, NULL, NULL, NULL},
+
+      [sec_ranges] = {".debug_ranges", "rangelist", "%#"PRIx64,
+                     "offset", "%#"PRIx64, NULL, NULL},
+
+      [sec_locexpr] = {"location expression", "offset", "%#"PRIx64,
+                      NULL, NULL, NULL, NULL},
+
+      [sec_rel] = {".rel", "relocation", "%"PRId64,
+                  "offset", "%#"PRIx64, NULL, NULL},
+      [sec_rela] = {".rela", "relocation", "%"PRId64,
+                   "offset", "%#"PRIx64, NULL, NULL},
+    };
+
+  static struct section_info special_formats[] =
+    {
+      [wf_cudie] = {".debug_info", "CU DIE", "%"PRId64, NULL, NULL, NULL, NULL}
+    };
+
+  assert (wh->section < sizeof (section_names) / sizeof (*section_names));
+  struct section_info *inf
+    = (wh->formatting == wf_plain)
+    ? section_names + wh->section
+    : special_formats + wh->formatting;
+
+  assert (inf->name);
+
+  assert ((inf->addr1n == NULL) == (inf->addr1f == NULL));
+  assert ((inf->addr2n == NULL) == (inf->addr2f == NULL));
+  assert ((inf->addr3n == NULL) == (inf->addr3f == NULL));
+
+  assert ((wh->addr1 != (uint64_t)-1) ? inf->addr1n != NULL : true);
+  assert ((wh->addr2 != (uint64_t)-1) ? inf->addr2n != NULL : true);
+  assert ((wh->addr3 != (uint64_t)-1) ? inf->addr3n != NULL : true);
+
+  assert ((wh->addr3 != (uint64_t)-1) ? (wh->addr2 != (uint64_t)-1) : true);
+  assert ((wh->addr2 != (uint64_t)-1) ? (wh->addr1 != (uint64_t)-1) : true);
+
+  /* GCC insists on checking format parameters and emits a warning
+     when we don't use string literal.  With -Werror this ends up
+     being hard error.  So instead we walk around this warning by
+     using function pointer.  */
+  int (*x_asprintf)(char **strp, const char *fmt, ...) = asprintf;
+
+#define SETUP_ADDR(N)                                                  \
+  char *addr##N##s;                                                    \
+  if (wh->addr##N == (uint64_t)-1)                                     \
+    addr##N##s = NULL;                                                 \
+  else if (x_asprintf (&addr##N##s, inf->addr##N##f, wh->addr##N) < 0) \
+    addr##N##s = "(fmt error)"
+
+  SETUP_ADDR (1);
+  SETUP_ADDR (2);
+  SETUP_ADDR (3);
+#undef SETUP_ADDR
+
+  char *orig = ptr;
+  bool is_reloc = wh->section == sec_rel || wh->section == sec_rela;
+  if (ptr == NULL)
+    {
+      ptr = stpcpy (buf, inf->name);
+      if (is_reloc)
+       {
+         struct where *ref = wh->ref;
+         assert (ref != NULL);
+         if (ref->section == sec_locexpr)
+           {
+             ref = ref->next;
+             assert (ref != NULL);
+             assert (ref->section != sec_locexpr);
+           }
+         ptr = stpcpy (ptr, section_names[ref->section].name);
+       }
+
+      if (addr1s != NULL)
+       ptr = stpcpy (ptr, ": ");
+    }
+
+  if (addr3s != NULL)
+    ptr = stpcpy (stpcpy (stpcpy (ptr, inf->addr3n), " "), addr3s);
+  else if (addr2s != NULL)
+    ptr = stpcpy (stpcpy (stpcpy (ptr, inf->addr2n), " "), addr2s);
+  else if (addr1s != NULL)
+    ptr = stpcpy (stpcpy (stpcpy (ptr, inf->addr1n), " "), addr1s);
+
+  if (wh->ref != NULL && !is_reloc)
+    {
+      ptr = stpcpy (ptr, " (");
+      ptr = (char *)where_fmt (wh->ref, ptr);
+      *ptr++ = ')';
+      *ptr = 0;
+    }
+
+  if (orig == NULL)
+    return buf;
+  else
+    return ptr;
+}
+
+void
+where_fmt_chain (const struct where *wh, const char *severity)
+{
+  if (wh != NULL && show_refs)
+    for (struct where *it = wh->next; it != NULL; it = it->next)
+      printf ("%s: %s: caused by this reference.\n",
+             severity, where_fmt (it, NULL));
+}
+
+void
+where_reset_1 (struct where *wh, uint64_t addr)
+{
+  wh->addr1 = addr;
+  wh->addr2 = wh->addr3 = (uint64_t)-1;
+}
+
+void
+where_reset_2 (struct where *wh, uint64_t addr)
+{
+  wh->addr2 = addr;
+  wh->addr3 = (uint64_t)-1;
+}
+
+void
+where_reset_3 (struct where *wh, uint64_t addr)
+{
+  wh->addr3 = addr;
+}
index 7361e826104782d92423f37e5022d8dc285410e0..e83647c6e2e185a09e7e307da21c187d3b2ffaee 100644 (file)
@@ -47,6 +47,7 @@
 #include "dwarfstrings.h"
 #include "dwarflint.h"
 #include "dwarflint-readctx.h"
+#include "dwarflint-config.h"
 #include "dwarf-opcodes.h"
 
 /* True if coverage analysis of .debug_ranges vs. ELF sections should
@@ -228,179 +229,6 @@ static bool check_line_structural (struct elf_file *file,
                                   struct sec *sec,
                                   struct cu *cu_chain);
 
-const char *
-where_fmt (const struct where *wh, char *ptr)
-{
-  if (wh == NULL)
-    return "";
-
-  static char buf[256];
-
-  struct section_info
-  {
-    const char *name;
-    const char *addr1n;
-    const char *addr1f;
-    const char *addr2n;
-    const char *addr2f;
-    const char *addr3n;
-    const char *addr3f;
-  };
-
-  static struct section_info section_names[] =
-    {
-      [sec_info] = {".debug_info", "CU", "%"PRId64,
-                   "DIE", "%#"PRIx64, NULL, NULL},
-
-      [sec_abbrev] = {".debug_abbrev", "section", "%"PRId64,
-                     "abbreviation", "%"PRId64, "abbr. attribute", "%#"PRIx64},
-
-      [sec_aranges] = {".debug_aranges", "table", "%"PRId64,
-                      "arange", "%#"PRIx64, NULL, NULL},
-
-      [sec_pubnames] = {".debug_pubnames", "pubname table", "%"PRId64,
-                       "pubname", "%#"PRIx64, NULL, NULL},
-
-      [sec_pubtypes] = {".debug_pubtypes", "pubtype table", "%"PRId64,
-                       "pubtype", "%#"PRIx64, NULL, NULL},
-
-      [sec_str] = {".debug_str", "offset", "%#"PRIx64,
-                  NULL, NULL, NULL, NULL},
-
-      [sec_line] = {".debug_line", "table", "%"PRId64,
-                   "offset", "%#"PRIx64, NULL, NULL},
-
-      [sec_loc] = {".debug_loc", "loclist", "%#"PRIx64,
-                  "offset", "%#"PRIx64, NULL, NULL},
-
-      [sec_mac] = {".debug_mac", NULL, NULL, NULL, NULL, NULL, NULL},
-
-      [sec_ranges] = {".debug_ranges", "rangelist", "%#"PRIx64,
-                     "offset", "%#"PRIx64, NULL, NULL},
-
-      [sec_locexpr] = {"location expression", "offset", "%#"PRIx64,
-                      NULL, NULL, NULL, NULL},
-
-      [sec_rel] = {".rel", "relocation", "%"PRId64,
-                  "offset", "%#"PRIx64, NULL, NULL},
-      [sec_rela] = {".rela", "relocation", "%"PRId64,
-                   "offset", "%#"PRIx64, NULL, NULL},
-    };
-
-  static struct section_info special_formats[] =
-    {
-      [wf_cudie] = {".debug_info", "CU DIE", "%"PRId64, NULL, NULL, NULL, NULL}
-    };
-
-  assert (wh->section < sizeof (section_names) / sizeof (*section_names));
-  struct section_info *inf
-    = (wh->formatting == wf_plain)
-    ? section_names + wh->section
-    : special_formats + wh->formatting;
-
-  assert (inf->name);
-
-  assert ((inf->addr1n == NULL) == (inf->addr1f == NULL));
-  assert ((inf->addr2n == NULL) == (inf->addr2f == NULL));
-  assert ((inf->addr3n == NULL) == (inf->addr3f == NULL));
-
-  assert ((wh->addr1 != (uint64_t)-1) ? inf->addr1n != NULL : true);
-  assert ((wh->addr2 != (uint64_t)-1) ? inf->addr2n != NULL : true);
-  assert ((wh->addr3 != (uint64_t)-1) ? inf->addr3n != NULL : true);
-
-  assert ((wh->addr3 != (uint64_t)-1) ? (wh->addr2 != (uint64_t)-1) : true);
-  assert ((wh->addr2 != (uint64_t)-1) ? (wh->addr1 != (uint64_t)-1) : true);
-
-  /* GCC insists on checking format parameters and emits a warning
-     when we don't use string literal.  With -Werror this ends up
-     being hard error.  So instead we walk around this warning by
-     using function pointer.  */
-  int (*x_asprintf)(char **strp, const char *fmt, ...) = asprintf;
-
-#define SETUP_ADDR(N)                                                  \
-  char *addr##N##s;                                                    \
-  if (wh->addr##N == (uint64_t)-1)                                     \
-    addr##N##s = NULL;                                                 \
-  else if (x_asprintf (&addr##N##s, inf->addr##N##f, wh->addr##N) < 0) \
-    addr##N##s = "(fmt error)"
-
-  SETUP_ADDR (1);
-  SETUP_ADDR (2);
-  SETUP_ADDR (3);
-#undef SETUP_ADDR
-
-  char *orig = ptr;
-  bool is_reloc = wh->section == sec_rel || wh->section == sec_rela;
-  if (ptr == NULL)
-    {
-      ptr = stpcpy (buf, inf->name);
-      if (is_reloc)
-       {
-         struct where *ref = wh->ref;
-         assert (ref != NULL);
-         if (ref->section == sec_locexpr)
-           {
-             ref = ref->next;
-             assert (ref != NULL);
-             assert (ref->section != sec_locexpr);
-           }
-         ptr = stpcpy (ptr, section_names[ref->section].name);
-       }
-
-      if (addr1s != NULL)
-       ptr = stpcpy (ptr, ": ");
-    }
-
-  if (addr3s != NULL)
-    ptr = stpcpy (stpcpy (stpcpy (ptr, inf->addr3n), " "), addr3s);
-  else if (addr2s != NULL)
-    ptr = stpcpy (stpcpy (stpcpy (ptr, inf->addr2n), " "), addr2s);
-  else if (addr1s != NULL)
-    ptr = stpcpy (stpcpy (stpcpy (ptr, inf->addr1n), " "), addr1s);
-
-  if (wh->ref != NULL && !is_reloc)
-    {
-      ptr = stpcpy (ptr, " (");
-      ptr = (char *)where_fmt (wh->ref, ptr);
-      *ptr++ = ')';
-      *ptr = 0;
-    }
-
-  if (orig == NULL)
-    return buf;
-  else
-    return ptr;
-}
-
-void
-where_fmt_chain (const struct where *wh, const char *severity)
-{
-  if (wh != NULL && show_refs)
-    for (struct where *it = wh->next; it != NULL; it = it->next)
-      printf ("%s: %s: caused by this reference.\n",
-             severity, where_fmt (it, NULL));
-}
-
-void
-where_reset_1 (struct where *wh, uint64_t addr)
-{
-  wh->addr1 = addr;
-  wh->addr2 = wh->addr3 = (uint64_t)-1;
-}
-
-void
-where_reset_2 (struct where *wh, uint64_t addr)
-{
-  wh->addr2 = addr;
-  wh->addr3 = (uint64_t)-1;
-}
-
-void
-where_reset_3 (struct where *wh, uint64_t addr)
-{
-  wh->addr3 = addr;
-}
-
 static bool
 address_aligned (uint64_t addr, uint64_t align)
 {
index 22dd219046560399da009b358e88cbc5fc8109a9..bb815951f83b532601808d45508ef95a38ac52fa 100644 (file)
@@ -51,17 +51,6 @@ extern "C"
   extern bool check_range_out_of_scope (struct hl_ctx *hlctx);
   extern void process_file (Elf *elf, const char *fname, bool only_one);
 
-  /* Whole-program options.  */
-  extern bool tolerate_nodebug;
-  extern bool be_quiet; /* -q */
-  extern bool be_verbose; /* -v */
-  extern bool be_strict; /* --strict */
-  extern bool be_gnu; /* --gnu */
-  extern bool be_tolerant; /* --tolerant */
-  extern bool show_refs; /* --ref */
-  extern bool do_high_level; /* ! --nohl */
-  extern bool dump_die_offsets; /* --dump-offsets */
-
   struct relocation
   {
     uint64_t offset;