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(a)redhat.com>
---
libdw/ChangeLog | 11 +++++++++
libdw/Makefile.am | 3 ++-
libdw/dwarf_decimal_sign_string.c | 51 +++++++++++++++++++++++++++++++++++++++
libdw/dwarf_endianity_string.c | 51 +++++++++++++++++++++++++++++++++++++++
libdw/libdw.h | 10 ++++++++
libdw/libdw.map | 2 ++
src/ChangeLog | 7 ++++++
src/readelf.c | 33 +++++++++++++++++++++++++
8 files changed, 167 insertions(+), 1 deletion(-)
create mode 100644 libdw/dwarf_decimal_sign_string.c
create mode 100644 libdw/dwarf_endianity_string.c
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 38cdb8a..7fccf4d 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,14 @@
+2012-08-11 Mark Wielaard <mjw(a)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(a)redhat.com>
* Makefile.am (libdw_a_SOURCES): Add dwarf_aggregate_size.c,
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index f695e89..e35e8e9 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -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
index 0000000..ee0f414
--- /dev/null
+++ b/libdw/dwarf_decimal_sign_string.c
@@ -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
index 0000000..d1c07f8
--- /dev/null
+++ b/libdw/dwarf_endianity_string.c
@@ -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;
+}
diff --git a/libdw/libdw.h b/libdw/libdw.h
index 4ed3a45..c1e1319 100644
--- a/libdw/libdw.h
+++ b/libdw/libdw.h
@@ -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__
diff --git a/libdw/libdw.map b/libdw/libdw.map
index c3d7c25..4f31b1a 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -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;
diff --git a/src/ChangeLog b/src/ChangeLog
index 7acf9d9..adeaa24 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2012-08-11 Mark Wielaard <mjw(a)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(a)redhat.com>
* readelf.c (dwarf_tag_string): Removed.
diff --git a/src/readelf.c b/src/readelf.c
index 53625e1..3c1ba3d 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -3373,6 +3373,33 @@ 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
+ snprintf (unknown_buf, sizeof unknown_buf, "unknown_%#x", code);
+ 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))
+ {
+ snprintf (unknown_buf, sizeof unknown_buf, "unknown_%#x", code);
+ result = unknown_buf;
+ }
+ return result;
+}
static void
print_block (size_t n, const void *block)
@@ -5046,6 +5073,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;
--
1.7.11.2