From: Mark Wielaard Date: Sun, 29 Jul 2012 21:47:28 +0000 (+0200) Subject: libdw: Add dwarfstrings functions. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fdf68c53b1dc3ff42d19fdbce5ddebbf8df2724d;p=thirdparty%2Felfutils.git libdw: Add dwarfstrings functions. Introduce dwarf_access_string, dwarf_attr_string, dwarf_calling_convention_string, dwarf_discr_list_string, dwarf_encoding_string, dwarf_form_string, dwarf_identifier_case_string, dwarf_inline_string, dwarf_lang_string, dwarf_line_extended_opcode_string, dwarf_line_standard_opcode_string, dwarf_locexpr_opcode_string, dwarf_ordering_string, dwarf_tag_string, dwarf_virtuality_string, dwarf_visibility_string from dwarf branch. Remove similar functions from readelf and tests. Signed-off-by: Mark Wielaard --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 53da0b049..38cdb8a69 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,44 @@ +2012-07-27 Mark Wielaard + + * Makefile.am (libdw_a_SOURCES): Add dwarf_aggregate_size.c, + dwarf_getlocation_implicit_pointer.c, + dwarf_access_string.c, dwarf_inline_string.c, + dwarf_attr_string.c dwarf_lang_string.c, + dwarf_calling_convention_string.c, + dwarf_line_extended_opcode_string.c, + dwarf_discr_list_string.c, + dwarf_line_standard_opcode_string.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 and dwarf_visibility_string.c + * dwarf_access_string.c: New file. + * dwarf_attr_string.c: Likewise. + * dwarf_calling_convention_string.c: Likewise. + * dwarf_discr_list_string.c: Likewise. + * dwarf_encoding_string.c: Likewise. + * dwarf_form_string.c: Likewise. + * dwarf_identifier_case_string.c: Likewise. + * dwarf_inline_string.c: Likewise. + * dwarf_lang_string.c: Likewise. + * dwarf_line_extended_opcode_string.c: Likewise. + * dwarf_line_standard_opcode_string.c: Likewise. + * dwarf_locexpr_opcode_string.c: Likewise. + * dwarf_ordering_string.c: Likewise. + * dwarf_tag_string.c: Likewise. + * dwarf_virtuality_string.c: Likewise. + * dwarf_visibility_string.c: Likewise. + * libdw.h: Declare dwarf_tag_string, dwarf_attr_string, + dwarf_lang_string, dwarf_inline_string, dwarf_encoding_string, + dwarf_access_string, dwarf_visibility_string, + dwarf_virtuality_string, dwarf_identifier_case_string, + dwarf_calling_convention_string, dwarf_ordering_string, + dwarf_discr_list_string, dwarf_locexpr_opcode_string, + dwarf_line_standard_opcode_string and + dwarf_line_extended_opcode_string. + * libdw.map (ELFUTILS_0.155): New symbol version directive for + new functions. + 2012-07-27 Mark Wielaard * Makefile.am (EXTRA_DIST): Add known-dwarf.h. diff --git a/libdw/Makefile.am b/libdw/Makefile.am index c6ac2646c..f695e891e 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -87,7 +87,17 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \ dwarf_frame_info.c dwarf_frame_cfa.c dwarf_frame_register.c \ dwarf_cfi_addrframe.c \ dwarf_getcfi.c dwarf_getcfi_elf.c dwarf_cfi_end.c \ - dwarf_aggregate_size.c dwarf_getlocation_implicit_pointer.c + dwarf_aggregate_size.c dwarf_getlocation_implicit_pointer.c \ + dwarf_access_string.c dwarf_inline_string.c \ + dwarf_attr_string.c dwarf_lang_string.c \ + dwarf_calling_convention_string.c \ + dwarf_line_extended_opcode_string.c \ + dwarf_discr_list_string.c \ + dwarf_line_standard_opcode_string.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 if MAINTAINER_MODE BUILT_SOURCES = $(srcdir)/known-dwarf.h diff --git a/libdw/dwarf_access_string.c b/libdw/dwarf_access_string.c new file mode 100644 index 000000000..6ad6e2423 --- /dev/null +++ b/libdw/dwarf_access_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_access_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_ACCESS(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_ACCESS +#undef ONE_KNOWN_DW_ACCESS + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_attr_string.c b/libdw/dwarf_attr_string.c new file mode 100644 index 000000000..a7c4ce43c --- /dev/null +++ b/libdw/dwarf_attr_string.c @@ -0,0 +1,48 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_attr_string (unsigned int attrnum) +{ + switch (attrnum) + { +#define ONE_KNOWN_DW_AT(NAME, CODE) case CODE: return #NAME; + ALL_KNOWN_DW_AT +#undef ONE_KNOWN_DW_AT + default: + return NULL; + } +} diff --git a/libdw/dwarf_calling_convention_string.c b/libdw/dwarf_calling_convention_string.c new file mode 100644 index 000000000..f91fdef8e --- /dev/null +++ b/libdw/dwarf_calling_convention_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_calling_convention_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_CC(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_CC +#undef ONE_KNOWN_DW_CC + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_discr_list_string.c b/libdw/dwarf_discr_list_string.c new file mode 100644 index 000000000..896705289 --- /dev/null +++ b/libdw/dwarf_discr_list_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_discr_list_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_DSC(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_DSC +#undef ONE_KNOWN_DW_DSC + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_encoding_string.c b/libdw/dwarf_encoding_string.c new file mode 100644 index 000000000..299957eb3 --- /dev/null +++ b/libdw/dwarf_encoding_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_encoding_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_ATE(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_ATE +#undef ONE_KNOWN_DW_ATE + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_form_string.c b/libdw/dwarf_form_string.c new file mode 100644 index 000000000..980c311f3 --- /dev/null +++ b/libdw/dwarf_form_string.c @@ -0,0 +1,50 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_form_string (unsigned int form) +{ + switch (form) + { +#define ONE_KNOWN_DW_FORM_DESC(NAME, CODE, DESC) ONE_KNOWN_DW_FORM(NAME, CODE) +#define ONE_KNOWN_DW_FORM(NAME, CODE) case CODE: return #NAME; + ALL_KNOWN_DW_FORM +#undef ONE_KNOWN_DW_FORM +#undef ONE_KNOWN_DW_FORM_DESC + default: + return NULL; + } +} diff --git a/libdw/dwarf_identifier_case_string.c b/libdw/dwarf_identifier_case_string.c new file mode 100644 index 000000000..53bcde438 --- /dev/null +++ b/libdw/dwarf_identifier_case_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_identifier_case_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_ID(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_ID +#undef ONE_KNOWN_DW_ID + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_inline_string.c b/libdw/dwarf_inline_string.c new file mode 100644 index 000000000..04c18a2df --- /dev/null +++ b/libdw/dwarf_inline_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_inline_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_INL(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_INL +#undef ONE_KNOWN_DW_INL + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_lang_string.c b/libdw/dwarf_lang_string.c new file mode 100644 index 000000000..d6dd288c6 --- /dev/null +++ b/libdw/dwarf_lang_string.c @@ -0,0 +1,48 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_lang_string (unsigned int lang) +{ + switch (lang) + { +#define ONE_KNOWN_DW_LANG_DESC(NAME, CODE, DESC) case CODE: return #NAME; + ALL_KNOWN_DW_LANG +#undef ONE_KNOWN_DW_LANG_DESC + default: + return NULL; + } +} diff --git a/libdw/dwarf_line_extended_opcode_string.c b/libdw/dwarf_line_extended_opcode_string.c new file mode 100644 index 000000000..c90061a74 --- /dev/null +++ b/libdw/dwarf_line_extended_opcode_string.c @@ -0,0 +1,52 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_line_extended_opcode_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_LNE(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_LNE +#undef ONE_KNOWN_DW_LNE + }; + + const char *ret = NULL; + if (likely (code < sizeof (known) / sizeof (known[0]))) + ret = known[code]; + + return ret; +} diff --git a/libdw/dwarf_line_standard_opcode_string.c b/libdw/dwarf_line_standard_opcode_string.c new file mode 100644 index 000000000..b154ec346 --- /dev/null +++ b/libdw/dwarf_line_standard_opcode_string.c @@ -0,0 +1,52 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_line_standard_opcode_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_LNS(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_LNS +#undef ONE_KNOWN_DW_LNS + }; + + const char *ret = NULL; + if (likely (code < sizeof (known) / sizeof (known[0]))) + ret = known[code]; + + return ret; +} diff --git a/libdw/dwarf_locexpr_opcode_string.c b/libdw/dwarf_locexpr_opcode_string.c new file mode 100644 index 000000000..beba721ec --- /dev/null +++ b/libdw/dwarf_locexpr_opcode_string.c @@ -0,0 +1,57 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +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]; + + return ret; +} diff --git a/libdw/dwarf_ordering_string.c b/libdw/dwarf_ordering_string.c new file mode 100644 index 000000000..4c8abc610 --- /dev/null +++ b/libdw/dwarf_ordering_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_ordering_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_ORD(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_ORD +#undef ONE_KNOWN_DW_ORD + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_tag_string.c b/libdw/dwarf_tag_string.c new file mode 100644 index 000000000..ad263267c --- /dev/null +++ b/libdw/dwarf_tag_string.c @@ -0,0 +1,48 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_tag_string (unsigned int tag) +{ + switch (tag) + { +#define ONE_KNOWN_DW_TAG(NAME, CODE) case CODE: return #NAME; + ALL_KNOWN_DW_TAG +#undef ONE_KNOWN_DW_TAG + default: + return NULL; + } +} diff --git a/libdw/dwarf_virtuality_string.c b/libdw/dwarf_virtuality_string.c new file mode 100644 index 000000000..129e0fdd8 --- /dev/null +++ b/libdw/dwarf_virtuality_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_virtuality_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_VIRTUALITY(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_VIRTUALITY +#undef ONE_KNOWN_DW_VIRTUALITY + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/dwarf_visibility_string.c b/libdw/dwarf_visibility_string.c new file mode 100644 index 000000000..ce99a5e0f --- /dev/null +++ b/libdw/dwarf_visibility_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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "known-dwarf.h" +#include "dwarf.h" + +const char * +dwarf_visibility_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_VIS(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_VIS +#undef ONE_KNOWN_DW_VIS + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} diff --git a/libdw/libdw.h b/libdw/libdw.h index f5fc4e238..4ed3a451d 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -1,5 +1,5 @@ /* Interfaces for libdw. - Copyright (C) 2002-2010 Red Hat, Inc. + Copyright (C) 2002-2010, 2012 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -830,6 +830,83 @@ extern const char *dwarf_errmsg (int err); extern Dwarf_OOM dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler); +/* Returns the tag name, without the DW_TAG_ prefix, if known. + Returns NULL if the given tag code is unknown. */ +extern const char *dwarf_tag_string (unsigned int code); + +/* Returns the attribute name, without the DW_AT_ prefix, if known. + Returns NULL if the given attribute code is unknown. */ +extern const char *dwarf_attr_string (unsigned int code); + +/* Returns the form name, without the DW_FORM_ prefix, if known. + Returns NULL if the given form code is unknown. */ +extern const char *dwarf_form_string (unsigned int code); + +/* Returns the language name, without the DW_LANG_ prefix, if known. + Returns NULL if the given language code is unknown. */ +extern const char *dwarf_lang_string (unsigned int code); + +/* Returns the inline name, without the DW_INL_ prefix, as used with + the DW_AT_inline attribute, if known. Returns NULL if the given + DW_LANG code is unknown. */ +extern const char *dwarf_inline_string (unsigned int code); + +/* Returns the encoding name, without the DW_ATE_ prefix, as used with + the DW_AT_encoding attribute, if known. Returns NULL if the given + DW_ATE code is unknown. */ +extern const char *dwarf_encoding_string (unsigned int code); + +/* Returns the access name, without the DW_ACCESS_ prefix, as used with + the DW_AT_accessibility attribute, if known. Returns NULL if the given + DW_ACCESS code is unknown. */ +extern const char *dwarf_access_string (unsigned int code); + +/* Returns the access name, without the DW_VIS_ prefix, as used with + the DW_AT_visibility attribute, if known. Returns NULL if the given + DW_VIS code is unknown. */ +extern const char *dwarf_visibility_string (unsigned int code); + +/* Returns the virtuality name, with the DW_VIRTUALITY_ prefix, as used + with the DW_AT_virtuality attribute, if known. Returns NULL if the + given DW_VIRTUALITY code is unknown. */ +extern const char *dwarf_virtuality_string (unsigned int code); + +/* Returns the identifier case name, without the DW_ID_ prefix, as used + with the DW_AT_identifier_case attribute, if known. Returns NULL if + the given DW_ID code is unknown. */ +extern const char *dwarf_identifier_case_string (unsigned int code); + +/* Returns the calling convention name, without the DW_CC_ prefix, as + used with the DW_AT_calling_convention attribute, if known. Returns + NULL if the given DW_CC code is unknown. */ +extern const char *dwarf_calling_convention_string (unsigned int code); + +/* Returns the ordering name, without the DW_ORD_ prefix, as + used with the DW_AT_ordering attribute, if known. Returns + NULL if the given DW_CC code is unknown. */ +extern const char *dwarf_ordering_string (unsigned int code); + +/* Returns the discriminant list name, without the DW_ORD_ prefix, as + used in the DW_AT_ordering attribute block, if known. Returns + NULL if the given DW_CC code is unknown. */ +extern const char *dwarf_discr_list_string (unsigned int code); + +/* Returns the operation name, without the DW_OP_ prefix, as + used in a DWARF location expression block, if known. Returns + NULL if the given DW_OP code is unknown. */ +extern const char *dwarf_locexpr_opcode_string (unsigned int code); + +/* Returns the standard line information opcode name, without the + DW_LNS_ prefix, as used in the line number program instructions, + if known. Returns NULL if the given DW_LNS opcode is unknown. */ +extern const char *dwarf_line_standard_opcode_string (unsigned int code); + +/* Returns the extended line information opcode name, without the + DW_LNE_ prefix, as used in the line number program instructions, + if known. Returns NULL if the given DW_LNE opcode is unknown. */ +extern const char *dwarf_line_extended_opcode_string (unsigned int code); + + /* Inline optimizations. */ #ifdef __OPTIMIZE__ /* Return attribute code of given attribute. */ diff --git a/libdw/libdw.map b/libdw/libdw.map index 1f71d03b5..c3d7c2551 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -254,3 +254,23 @@ ELFUTILS_0.149 { dwfl_dwarf_line; } ELFUTILS_0.148; + +ELFUTILS_0.155 { + global: + dwarf_tag_string; + dwarf_attr_string; + dwarf_form_string; + dwarf_lang_string; + dwarf_inline_string; + dwarf_encoding_string; + dwarf_access_string; + dwarf_visibility_string; + dwarf_virtuality_string; + dwarf_identifier_case_string; + dwarf_calling_convention_string; + dwarf_ordering_string; + dwarf_discr_list_string; + dwarf_locexpr_opcode_string; + dwarf_line_standard_opcode_string; + dwarf_line_extended_opcode_string; +} ELFUTILS_0.149; diff --git a/src/ChangeLog b/src/ChangeLog index 3c7e221d0..7acf9d92e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2012-07-27 Mark Wielaard + + * readelf.c (dwarf_tag_string): Removed. + (dwarf_attr_string): Likewise. + (dwarf_form_string): Likewise. + (dwarf_lang_string): Likewise. + (dwarf_inline_string): Likewise. + (dwarf_encoding_string): Likewise. + (dwarf_access_string): Likewise. + (dwarf_visibility_string): Likewise. + (dwarf_virtuality_string): Likewise. + (dwarf_identifier_case_string): Likewise. + (dwarf_calling_convention_string): Likewise. + (dwarf_ordering_string): Likewise. + (dwarf_discr_list_string): Likewise. + (dwarf_locexpr_opcode_string): Likewise. + 2012-07-27 Mark Wielaard * readelf.c (dwarf_tag_name): Renamed from dwarf_tag_string. diff --git a/src/readelf.c b/src/readelf.c index 11e633165..2711006db 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -51,8 +51,6 @@ #include "../libdwfl/libdwflP.h" #include "../libdw/memory-access.h" -#include "../libdw/known-dwarf.h" - /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); @@ -3183,239 +3181,6 @@ format_dwarf_addr (Dwfl_Module *dwflmod, return result; } -static const char * -dwarf_tag_string (unsigned int tag) -{ - switch (tag) - { -#define ONE_KNOWN_DW_TAG(NAME, CODE) case CODE: return #NAME; - ALL_KNOWN_DW_TAG -#undef ONE_KNOWN_DW_TAG - default: - return NULL; - } -} - - -static const char * -dwarf_attr_string (unsigned int attrnum) -{ - switch (attrnum) - { -#define ONE_KNOWN_DW_AT(NAME, CODE) case CODE: return #NAME; - ALL_KNOWN_DW_AT -#undef ONE_KNOWN_DW_AT - default: - return NULL; - } -} - - -static const char * -dwarf_form_string (unsigned int form) -{ - switch (form) - { -#define ONE_KNOWN_DW_FORM_DESC(NAME, CODE, DESC) ONE_KNOWN_DW_FORM(NAME, CODE) -#define ONE_KNOWN_DW_FORM(NAME, CODE) case CODE: return #NAME; - ALL_KNOWN_DW_FORM -#undef ONE_KNOWN_DW_FORM -#undef ONE_KNOWN_DW_FORM_DESC - default: - return NULL; - } -} - - -static const char * -dwarf_lang_string (unsigned int lang) -{ - switch (lang) - { -#define ONE_KNOWN_DW_LANG_DESC(NAME, CODE, DESC) case CODE: return #NAME; - ALL_KNOWN_DW_LANG -#undef ONE_KNOWN_DW_LANG_DESC - default: - return NULL; - } -} - - -static const char * -dwarf_inline_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_INL(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_INL -#undef ONE_KNOWN_DW_INL - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_encoding_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_ATE(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_ATE -#undef ONE_KNOWN_DW_ATE - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_access_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_ACCESS(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_ACCESS -#undef ONE_KNOWN_DW_ACCESS - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_visibility_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_VIS(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_VIS -#undef ONE_KNOWN_DW_VIS - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_virtuality_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_VIRTUALITY(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_VIRTUALITY -#undef ONE_KNOWN_DW_VIRTUALITY - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_identifier_case_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_ID(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_ID -#undef ONE_KNOWN_DW_ID - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_calling_convention_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_CC(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_CC -#undef ONE_KNOWN_DW_CC - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_ordering_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_ORD(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_ORD -#undef ONE_KNOWN_DW_ORD - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static const char * -dwarf_discr_list_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_DSC(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_DSC -#undef ONE_KNOWN_DW_DSC - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - - -static 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]; - - return ret; -} - /* Reused by all dwarf_foo_name functions. */ static char unknown_buf[16]; diff --git a/tests/ChangeLog b/tests/ChangeLog index 823f82ee1..24ba17e6b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2012-07-27 Mark Wielaard + + * allregs.c (dwarf_encoding_string): Removed. + * show-die-info.c (dwarf_tag_string): Removed. + (dwarf_attr_string): Removed. + 2012-07-27 Mark Wielaard * allregs.c (dwarf_encoding_string): Rewritten using known-dwarf diff --git a/tests/allregs.c b/tests/allregs.c index b103ce185..85bcb5cda 100644 --- a/tests/allregs.c +++ b/tests/allregs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005, 2006 Red Hat, Inc. +/* Copyright (C) 2005, 2006, 2012 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -28,24 +28,6 @@ #include ELFUTILS_HEADER(dwfl) #include -#include "../libdw/known-dwarf.h" - -static const char * -dwarf_encoding_string (unsigned int code) -{ - static const char *const known[] = - { -#define ONE_KNOWN_DW_ATE(NAME, CODE) [CODE] = #NAME, - ALL_KNOWN_DW_ATE -#undef ONE_KNOWN_DW_ATE - }; - - if (likely (code < sizeof (known) / sizeof (known[0]))) - return known[code]; - - return NULL; -} - static int first_module (Dwfl_Module *mod, diff --git a/tests/show-die-info.c b/tests/show-die-info.c index 0c298acd5..624a71dc8 100644 --- a/tests/show-die-info.c +++ b/tests/show-die-info.c @@ -26,34 +26,6 @@ #include #include -#include "../libdw/known-dwarf.h" - -static const char * -dwarf_tag_string (unsigned int tag) -{ - switch (tag) - { -#define ONE_KNOWN_DW_TAG(NAME, CODE) case CODE: return #NAME; - ALL_KNOWN_DW_TAG -#undef ONE_KNOWN_DW_TAG - default: - return NULL; - } -} - -static const char * -dwarf_attr_string (unsigned int attrnum) -{ - switch (attrnum) - { -#define ONE_KNOWN_DW_AT(NAME, CODE) case CODE: return #NAME; - ALL_KNOWN_DW_AT -#undef ONE_KNOWN_DW_AT - default: - return NULL; - } -} - void handle (Dwarf *dbg, Dwarf_Die *die, int n)