]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Look up abbreviations with bisect search.
authorPetr Machata <pmachata@redhat.com>
Fri, 9 Jan 2009 23:34:48 +0000 (00:34 +0100)
committerPetr Machata <pmachata@redhat.com>
Fri, 9 Jan 2009 23:34:48 +0000 (00:34 +0100)
src/ChangeLog
src/dwarflint.c

index f25860837d9b5a0d2ae097d9835d73d39d384f99..bdc8ab0caf5c98840e94dc385546f3f1e5abbd93 100644 (file)
@@ -1,3 +1,8 @@
+2009-01-09  Petr Machata  <pmachata@redhat.com>
+
+       * dwarflint.c: Sort the abbrev tables and look up abbreviations
+       with bisect search.
+
 2009-01-09  Petr Machata  <pmachata@redhat.com>
 
        * dwarflint.c: Better checking for zero padding and unreferenced
index 53d4cecb3f852e02809c6ea58b7873cdcc30f30b..b706914687796ab79eb5bb23d485917cfa43a263 100644 (file)
@@ -815,6 +815,20 @@ abbrev_table_load (struct read_ctx *ctx)
       while (!null_attrib);
     }
 
+  for (section = section_chain; section != NULL; section = section->next)
+    {
+      int cmp_abbrs (const void *a, const void *b)
+      {
+       struct abbrev *aa = (struct abbrev *)a;
+       struct abbrev *bb = (struct abbrev *)b;
+       return aa->code - bb->code;
+      }
+
+      /* The array is most likely already sorted in the file, but just
+        to be sure...  */
+      qsort (section->abbr, section->size, sizeof (*section->abbr), cmp_abbrs);
+    }
+
   return section_chain;
 
  free_and_out:
@@ -840,9 +854,23 @@ abbrev_table_free (struct abbrev_table *abbr)
 static struct abbrev *
 abbrev_table_find_abbrev (struct abbrev_table *abbrevs, uint64_t abbrev_code)
 {
-  for (size_t i = 0; i < abbrevs->size; ++i)
-    if (abbrevs->abbr[i].code == abbrev_code)
-      return abbrevs->abbr + i;
+  size_t a = 0;
+  size_t b = abbrevs->size;
+  struct abbrev *ab = NULL;
+
+  while (a < b)
+    {
+      size_t i = (a + b) / 2;
+      ab = abbrevs->abbr + i;
+
+      if (ab->code > abbrev_code)
+       b = i;
+      else if (ab->code < abbrev_code)
+       a = i + 1;
+      else
+       return ab;
+    }
+
   return NULL;
 }
 
@@ -1107,7 +1135,7 @@ check_debug_info_structural (struct read_ctx *ctx,
          check_cu_structural (&cu_ctx, cu_off, abbrev_chain, strings,
                               dwarf_64, die_addrs, die_refs, strings_coverage);
          if (cu_ctx.ptr != cu_ctx.end && !check_zero_padding (&cu_ctx))
-           WARNING (PRI_CU "%" PRIx64 "..%" PRIx64
+           WARNING (PRI_CU ": 0x%" PRIx64 "..0x%" PRIx64
                     ": unreferenced data.\n",
                     cu_off, read_ctx_get_offset (ctx), size);
        }
@@ -1201,9 +1229,9 @@ read_die_chain (struct read_ctx *ctx, uint64_t cu_off,
          sibling_addr = 0;
        }
       else if (prev_abbrev != NULL && prev_abbrev->has_children)
-       ERROR (PRI_CU_DIE
-              ": This DIE had children, but no DW_AT_sibling attribute.\n",
-              cu_off, prev_die_off);
+       WARNING (PRI_CU_DIE
+                ": This DIE had children, but no DW_AT_sibling attribute.\n",
+                cu_off, prev_die_off);
 
       /* The section ended.  */
       if (read_ctx_eof (ctx) || abbr_code == 0)