]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Add dwarf_endianity_string and dwarf_decimal_sign_string. mjw/dwarfstrings
authorMark Wielaard <mjw@redhat.com>
Sat, 11 Aug 2012 12:50:38 +0000 (14:50 +0200)
committerMark Wielaard <mjw@redhat.com>
Thu, 16 Aug 2012 20:26:23 +0000 (22:26 +0200)
dwarf_endianity_string for DW_END codes used with DW_AT_endianity.
dwarf_decimal_sign_string for DW_DS codes used with DW_AT_decimal_sign.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdw/ChangeLog
libdw/Makefile.am
libdw/dwarf_decimal_sign_string.c [new file with mode: 0644]
libdw/dwarf_endianity_string.c [new file with mode: 0644]
libdw/libdw.h
libdw/libdw.map
src/ChangeLog
src/readelf.c

index 38cdb8a6905f3c9c00ab7f03f041b5dfc786dd50..7fccf4d8a67b34b496cef47fea9fe22047cea45f 100644 (file)
@@ -1,3 +1,14 @@
+2012-08-11  Mark Wielaard  <mjw@redhat.com>
+
+       * Makefile.am (libdw_a_SOURCES): Add dwarf_endianity_string.c and
+       dwarf_decimal_sign_string.c.
+       * dwarf_endianity_string.c: New file.
+       * dwarf_decimal_sign_string.c: New file.
+       * libdw.h: Declare dwarf_endianity_string and
+       dwarf_decimal_sign_string.
+       * libdw.map (ELFUTILS_0.155): Add dwarf_endianity_string and
+       dwarf_decimal_sign_string.
+
 2012-07-27  Mark Wielaard  <mjw@redhat.com>
 
        * Makefile.am (libdw_a_SOURCES): Add dwarf_aggregate_size.c,
index f695e891ecbcdc62873dc0ac12ed49f7991a1dc7..e35e8e993aa1e81969caf7424ba89663414baec4 100644 (file)
@@ -97,7 +97,8 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \
                  dwarf_encoding_string.c dwarf_locexpr_opcode_string.c \
                  dwarf_form_string.c dwarf_ordering_string.c \
                  dwarf_tag_string.c dwarf_virtuality_string.c \
-                 dwarf_identifier_case_string.c dwarf_visibility_string.c
+                 dwarf_identifier_case_string.c dwarf_visibility_string.c \
+                 dwarf_endianity_string.c dwarf_decimal_sign_string.c
 
 if MAINTAINER_MODE
 BUILT_SOURCES = $(srcdir)/known-dwarf.h
diff --git a/libdw/dwarf_decimal_sign_string.c b/libdw/dwarf_decimal_sign_string.c
new file mode 100644 (file)
index 0000000..ee0f414
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright (C) 2012 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stddef.h>
+
+#include "known-dwarf.h"
+#include "dwarf.h"
+
+const char *
+dwarf_decimal_sign_string (unsigned int code)
+{
+  static const char *const known[] =
+    {
+#define ONE_KNOWN_DW_DS(NAME, CODE) [CODE] = #NAME,
+      ALL_KNOWN_DW_DS
+#undef ONE_KNOWN_DW_DS
+    };
+
+  if (likely (code < sizeof (known) / sizeof (known[0])))
+    return known[code];
+
+  return NULL;
+}
diff --git a/libdw/dwarf_endianity_string.c b/libdw/dwarf_endianity_string.c
new file mode 100644 (file)
index 0000000..d1c07f8
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright (C) 2012 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stddef.h>
+
+#include "known-dwarf.h"
+#include "dwarf.h"
+
+const char *
+dwarf_endianity_string (unsigned int code)
+{
+  static const char *const known[] =
+    {
+#define ONE_KNOWN_DW_END(NAME, CODE) [CODE] = #NAME,
+      ALL_KNOWN_DW_END
+#undef ONE_KNOWN_DW_END
+    };
+
+  if (likely (code < sizeof (known) / sizeof (known[0])))
+    return known[code];
+
+  return NULL;
+}
index 4ed3a451de5cbd1c3f3523f0e97b5efe6d4d81bc..c1e13195f2da4af3280b3c5cbb1d55507bd773c5 100644 (file)
@@ -906,6 +906,16 @@ extern const char *dwarf_line_standard_opcode_string (unsigned int code);
    if known.  Returns NULL if the given DW_LNE opcode is unknown.  */
 extern const char *dwarf_line_extended_opcode_string (unsigned int code);
 
+/* Returns the endianity name, without the DW_END_ prefix, as used in
+   the DW_AT_endianity attribute, if known.  Returns NULL if the given
+   DW_END code is unknown.  */
+extern const char *dwarf_endianity_string (unsigned int code);
+
+/* Returns the decimal sign name, without the DW_DS_ prefix, as used in
+   the DW_AT_decimal_sign attribute, if known.  Returns NULL if the given
+   DW_DS code is unknown.  */
+extern const char *dwarf_decimal_sign_string (unsigned int code);
+
 
 /* Inline optimizations.  */
 #ifdef __OPTIMIZE__
index c3d7c2551e68f967df2a8a20927f37ed7f54a7dc..4f31b1ad65053b57cb68e037bf7b1bf8309a3874 100644 (file)
@@ -273,4 +273,6 @@ ELFUTILS_0.155 {
     dwarf_locexpr_opcode_string;
     dwarf_line_standard_opcode_string;
     dwarf_line_extended_opcode_string;
+    dwarf_endianity_string;
+    dwarf_decimal_sign_string;
 } ELFUTILS_0.149;
index 7acf9d92e79a8e306d544e93a072ef4379126082..adeaa24354bc78d3c214cc0644bbf68739d6cb33 100644 (file)
@@ -1,3 +1,10 @@
+2012-08-11  Mark Wielaard  <mjw@redhat.com>
+
+       * readelf.c (dwarf_endianity_name): New function.
+       (dwarf_decimal_sign_string): Likewise.
+       (attr_callback): Use dwarf_endianity_name for DW_AT_endianity
+       and use dwarf_decimal_sign_string for DW_AT_decimal_sign.
+
 2012-07-27  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (dwarf_tag_string): Removed.
index 2711006db6ea6390ca91ae765a1f9088ee6fc48f..c649c84c4dfbcbdb3712d5013fdf99e7d9c02b6a 100644 (file)
@@ -3352,6 +3352,30 @@ dwarf_discr_list_name (unsigned int code)
   return result;
 }
 
+static const char *
+dwarf_endianity_name (unsigned int code)
+{
+  const char *result = dwarf_endianity_string (code);
+  if (unlikely (result == NULL))
+    {
+      if (code >= DW_END_lo_user && code <= DW_END_hi_user)
+       snprintf (unknown_buf, sizeof unknown_buf, "lo_user+%#x",
+                 code - DW_END_lo_user);
+      else
+       return "???"; /* Numeric value is always already printed. */
+      result = unknown_buf;
+    }
+  return result;
+}
+
+static const char *
+dwarf_decimal_sign_name (unsigned int code)
+{
+  const char *result = dwarf_decimal_sign_string (code);
+  if (unlikely (result == NULL))
+    result = "???"; /* Numeric value is always already printed. */
+  return result;
+}
 
 static void
 print_block (size_t n, const void *block)
@@ -5025,6 +5049,12 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
        case DW_AT_discr_list:
          valuestr = dwarf_discr_list_name (num);
          break;
+       case DW_AT_endianity:
+         valuestr = dwarf_endianity_name (num);
+         break;
+       case DW_AT_decimal_sign:
+         valuestr = dwarf_decimal_sign_name (num);
+         break;
        default:
          /* Nothing.  */
          break;