]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Add location expression formatting function to dwarfstrings.h
authorPetr Machata <pmachata@redhat.com>
Thu, 15 Jan 2009 14:33:26 +0000 (15:33 +0100)
committerPetr Machata <pmachata@redhat.com>
Thu, 15 Jan 2009 14:33:26 +0000 (15:33 +0100)
* and fix a buglet along the way

src/ChangeLog
src/dwarfstrings.h

index 9115dd0d2bbc744e74f1d96414dcbe94d611a147..3bfa904942de59576c3680c2f4a57d1407556715 100644 (file)
@@ -1,3 +1,7 @@
+2009-01-14  Petr Machata  <pmachata@redhat.com>
+
+       * dwarfstrings.h (dwarf_locexpr_opcode_string): New.
+
 2009-01-14  Petr Machata  <pmachata@redhat.com>
 
        * dwarflint.c: Validation .debug_pubtypes.
index f70392ef64296f347159fe10948425b0f2f98b61..9987b2fd49c27939525f2781a6d9410e14d693e2 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef DWARFSTRINGS_H
 #define DWARFSTRINGS_H 1
 
+#include "../libdw/known-dwarf.h"
+
 static __attribute__ ((unused)) const char *
 dwarf_tag_string (unsigned int tag)
 {
@@ -356,8 +358,11 @@ dwarf_form_string (unsigned int form)
     result = known_forms[form];
 
   if (unlikely (result == NULL))
-    snprintf (buf, sizeof buf, gettext ("unknown form %" PRIx64),
-             (uint64_t) form);
+    {
+      snprintf (buf, sizeof buf, gettext ("unknown form %" PRIx64),
+               (uint64_t) form);
+      result = buf;
+    }
 
   return result;
 }
@@ -585,4 +590,35 @@ dwarf_discr_list_string (unsigned int code)
   return "???";
 }
 
+
+static __attribute__ ((unused)) const char *
+dwarf_locexpr_opcode_string (unsigned int code)
+{
+  static const char *const known[] =
+    {
+      /* Normally we can't affort building huge table of 64K entries,
+        most of them zero, just because there are a couple defined
+        values at the far end.  In case of opcodes, it's OK.  */
+#define ONE_KNOWN_DW_OP_DESC(NAME, CODE, DESC) ONE_KNOWN_DW_OP(NAME, CODE)
+#define ONE_KNOWN_DW_OP(NAME, CODE) [CODE] = #NAME,
+      ALL_KNOWN_DW_OP
+#undef ONE_KNOWN_DW_OP
+#undef ONE_KNOWN_DW_OP_DESC
+    };
+
+  const char *ret = NULL;
+  if (likely (code < sizeof (known) / sizeof (known[0])))
+    ret = known[code];
+
+  if (ret == NULL)
+    {
+      static char buf[40];
+      snprintf (buf, sizeof buf, gettext ("unknown opcode %" PRIx64),
+               (uint64_t) code);
+      ret = buf;
+    }
+
+  return ret;
+}
+
 #endif  /* dwarfstrings.h */