diff options
author | Mark Wielaard <mjw@redhat.com> | 2012-08-11 14:50:38 +0200 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2012-08-16 22:26:23 +0200 |
commit | bcae57f780b5ef3c5a5a05c31ff35886927fe0c9 (patch) | |
tree | d5a97c7d5b1184041c2829d7c4df05efe9b37224 | |
parent | a985e57862fa0aed33314de079cd44908a6b59cc (diff) | |
download | elfutils-mjw/dwarfstrings.tar.gz |
Add dwarf_endianity_string and dwarf_decimal_sign_string.mjw/dwarfstrings
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>
-rw-r--r-- | libdw/ChangeLog | 11 | ||||
-rw-r--r-- | libdw/Makefile.am | 3 | ||||
-rw-r--r-- | libdw/dwarf_decimal_sign_string.c | 51 | ||||
-rw-r--r-- | libdw/dwarf_endianity_string.c | 51 | ||||
-rw-r--r-- | libdw/libdw.h | 10 | ||||
-rw-r--r-- | libdw/libdw.map | 2 | ||||
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/readelf.c | 30 |
8 files changed, 164 insertions, 1 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 38cdb8a6..7fccf4d8 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -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, diff --git a/libdw/Makefile.am b/libdw/Makefile.am index f695e891..e35e8e99 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 00000000..ee0f4148 --- /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 00000000..d1c07f8f --- /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 4ed3a451..c1e13195 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 c3d7c255..4f31b1ad 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 7acf9d92..adeaa243 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -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. diff --git a/src/readelf.c b/src/readelf.c index 2711006d..c649c84c 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -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; |