]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Move addr_record stuff to file of its own
authorPetr Machata <pmachata@redhat.com>
Wed, 21 Oct 2009 19:28:12 +0000 (21:28 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:11 +0000 (14:55 +0200)
src/Makefile.am
src/dwarflint/addr-record.cc [new file with mode: 0644]
src/dwarflint/addr-record.h [new file with mode: 0644]
src/dwarflint/low.c
src/dwarflint/low.h

index 31dc8a945310bec9acb4d87f89293181611ac157..19eb6982f8d2c92932d39ad363ce1f52d460fa9b 100644 (file)
@@ -89,6 +89,7 @@ dwarflint_SOURCES = dwarfstrings.c \
                    dwarflint/config.cc dwarflint/config.h \
                    dwarflint/checks.cc dwarflint/checks.hh \
                    dwarflint/checks-low.cc dwarflint/checks-low.hh \
+                   dwarflint/addr-record.cc dwarflint/addr-record.h \
                    dwarflint/checks-high.hh \
                    dwarflint/check_matching_ranges.cc \
                    dwarflint/check_range_out_of_scope.cc \
diff --git a/src/dwarflint/addr-record.cc b/src/dwarflint/addr-record.cc
new file mode 100644 (file)
index 0000000..6eb4dac
--- /dev/null
@@ -0,0 +1,58 @@
+#include "addr-record.h"
+#include "misc.h"
+
+size_t
+addr_record_find_addr (struct addr_record *ar, uint64_t addr)
+{
+  size_t a = 0;
+  size_t b = ar->size;
+
+  while (a < b)
+    {
+      size_t i = (a + b) / 2;
+      uint64_t v = ar->addrs[i];
+
+      if (v > addr)
+       b = i;
+      else if (v < addr)
+       a = i + 1;
+      else
+       return i;
+    }
+
+  return a;
+}
+
+bool
+addr_record_has_addr (struct addr_record *ar, uint64_t addr)
+{
+  if (ar->size == 0
+      || addr < ar->addrs[0]
+      || addr > ar->addrs[ar->size - 1])
+    return false;
+
+  size_t a = addr_record_find_addr (ar, addr);
+  return a < ar->size && ar->addrs[a] == addr;
+}
+
+void
+addr_record_add (struct addr_record *ar, uint64_t addr)
+{
+  size_t a = addr_record_find_addr (ar, addr);
+  if (a >= ar->size || ar->addrs[a] != addr)
+    {
+      REALLOC (ar, addrs);
+      size_t len = ar->size - a;
+      memmove (ar->addrs + a + 1, ar->addrs + a, len * sizeof (*ar->addrs));
+
+      ar->addrs[a] = addr;
+      ar->size++;
+    }
+}
+
+void
+addr_record_free (struct addr_record *ar)
+{
+  if (ar != NULL)
+    free (ar->addrs);
+}
diff --git a/src/dwarflint/addr-record.h b/src/dwarflint/addr-record.h
new file mode 100644 (file)
index 0000000..95185ff
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef DWARFLINT_ADDR_RECORD_H
+#define DWARFLINT_ADDR_RECORD_H
+
+#include <stdlib.h>
+#include <stdint.h>
+#ifdef __cplusplus
+extern "C"
+{
+#else
+# include <stdbool.h>
+#endif
+
+/* Functions and data structures for address record handling.  We use
+   that to check that all DIE references actually point to an existing
+   die, not somewhere mid-DIE, where it just happens to be
+   interpretable as a DIE.  */
+
+struct addr_record
+{
+  size_t size;
+  size_t alloc;
+  uint64_t *addrs;
+};
+
+size_t addr_record_find_addr (struct addr_record *ar, uint64_t addr);
+bool addr_record_has_addr (struct addr_record *ar, uint64_t addr);
+void addr_record_add (struct addr_record *ar, uint64_t addr);
+void addr_record_free (struct addr_record *ar);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif//DWARFLINT_ADDR_RECORD_H
index c7487b985a0553a0d5da4376696653b3de55b4d3..e85e03540dc335c5dba3b914c23f335b6fa4d2aa 100644 (file)
@@ -69,16 +69,6 @@ check_category (enum message_category cat)
 /* Functions and data structures related to raw (i.e. unassisted by
    libdw) Dwarf abbreviation handling.  */
 
-/* Functions and data structures for address record handling.  We use
-   that to check that all DIE references actually point to an existing
-   die, not somewhere mid-DIE, where it just happens to be
-   interpretable as a DIE.  */
-
-static size_t addr_record_find_addr (struct addr_record *ar, uint64_t addr);
-static bool addr_record_has_addr (struct addr_record *ar, uint64_t addr);
-static void addr_record_add (struct addr_record *ar, uint64_t addr);
-static void addr_record_free (struct addr_record *ar);
-
 
 /* Functions and data structures for reference handling.  Just like
    the above, we use this to check validity of DIE references.  Unlike
@@ -610,63 +600,6 @@ abbrev_table_find_abbrev (struct abbrev_table *abbrevs, uint64_t abbrev_code)
   return NULL;
 }
 
-static size_t
-addr_record_find_addr (struct addr_record *ar, uint64_t addr)
-{
-  size_t a = 0;
-  size_t b = ar->size;
-
-  while (a < b)
-    {
-      size_t i = (a + b) / 2;
-      uint64_t v = ar->addrs[i];
-
-      if (v > addr)
-       b = i;
-      else if (v < addr)
-       a = i + 1;
-      else
-       return i;
-    }
-
-  return a;
-}
-
-static bool
-addr_record_has_addr (struct addr_record *ar, uint64_t addr)
-{
-  if (ar->size == 0
-      || addr < ar->addrs[0]
-      || addr > ar->addrs[ar->size - 1])
-    return false;
-
-  size_t a = addr_record_find_addr (ar, addr);
-  return a < ar->size && ar->addrs[a] == addr;
-}
-
-static void
-addr_record_add (struct addr_record *ar, uint64_t addr)
-{
-  size_t a = addr_record_find_addr (ar, addr);
-  if (a >= ar->size || ar->addrs[a] != addr)
-    {
-      REALLOC (ar, addrs);
-      size_t len = ar->size - a;
-      memmove (ar->addrs + a + 1, ar->addrs + a, len * sizeof (*ar->addrs));
-
-      ar->addrs[a] = addr;
-      ar->size++;
-    }
-}
-
-static void
-addr_record_free (struct addr_record *ar)
-{
-  if (ar != NULL)
-    free (ar->addrs);
-}
-
-
 static void
 ref_record_add (struct ref_record *rr, uint64_t addr, struct where *referrer)
 {
index 6bdfe35fd20dc34fe832b73af9aa212500e59ca3..a8b7539e036bdf21d29f897b5a1790fa931bcc60 100644 (file)
@@ -31,6 +31,7 @@
 #include "coverage.h"
 #include "messages.h"
 #include "readctx.h"
+#include "addr-record.h"
 
 #ifdef __cplusplus
 # include <string>
@@ -256,13 +257,6 @@ extern "C"
     struct ref *refs;
   };
 
-  struct addr_record
-  {
-    size_t size;
-    size_t alloc;
-    uint64_t *addrs;
-  };
-
   struct cu
   {
     struct cu *next;