From: Roland McGrath Date: Mon, 30 Mar 2009 03:50:20 +0000 (-0700) Subject: Consolidate/clean-up xif->throw_libdw paths. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2dcbbf0e84b73851e65573e3899b5b30914ecead;p=thirdparty%2Felfutils.git Consolidate/clean-up xif->throw_libdw paths. --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index f4e602e51..9c6e11742 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2009-03-29 Roland McGrath + + * c++/exception.cc: New file. + * Makefile.am (libdwpp_a_SOURCES): Add it. + 2009-03-25 Roland McGrath * c++/dwarf, c++/values.cc: Proper dwarf_constant support. diff --git a/libdw/Makefile.am b/libdw/Makefile.am index 9a2cff63c..3919945a7 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -90,6 +90,7 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \ # XXX need to figure out C++ dso crapola lib_LIBRARIES += libdwpp.a libdwpp_a_SOURCES = c++/values.cc \ + c++/exception.cc \ c++/known.cc \ c++/line_info.cc \ c++/edit-values.cc diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index 035248c06..1c4755962 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -262,15 +262,27 @@ namespace elfutils typedef known_enum< ::DW_AT_location> ops; private: - // XXX make this an instance method to include irritant context - static void throw_libdw (void) // XXX raises (...) + static void throw_libdw (::Dwarf *dw); // XXX raises (...) + static void throw_libdw (::Dwarf_CU *); // XXX raises (...) + + inline void xif (bool fail) const { - throw std::runtime_error(::dwarf_errmsg (-1)); + if (unlikely (fail)) + throw_libdw (_m_dw); } - static inline void xif (bool fail) + static inline void xif (::Dwarf_CU *cu, bool fail) { if (unlikely (fail)) - throw_libdw (); + throw_libdw (cu); + } + + static inline void xif (const ::Dwarf_Attribute *attr, bool fail) + { + xif (attr->cu, fail); + } + static inline void xif (const ::Dwarf_Die *die, bool fail) + { + xif (die->cu, fail); } template 0) // Hit the end. *this = const_iterator (); return *this; @@ -643,7 +660,7 @@ namespace elfutils _m_attr.valp = NULL; int result = ::dwarf_getattrs (&_m_die._m_die, &getattrs_callback, (void *) this, _m_offset); - xif (result < 0); + _m_die.xif (result < 0); _m_offset = result; return *this; } diff --git a/libdw/c++/exception.cc b/libdw/c++/exception.cc new file mode 100644 index 000000000..15a0cef1a --- /dev/null +++ b/libdw/c++/exception.cc @@ -0,0 +1,76 @@ +/* -*- C++ -*- exceptions for libdw. + Copyright (C) 2009 Red Hat, Inc. + This file is part of Red Hat elfutils. + + Red Hat elfutils is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by the + Free Software Foundation; version 2 of the License. + + Red Hat 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 a copy of the GNU General Public License along + with Red Hat elfutils; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. + + In addition, as a special exception, Red Hat, Inc. gives You the + additional right to link the code of Red Hat elfutils with code licensed + under any Open Source Initiative certified open source license + (http://www.opensource.org/licenses/index.php) which requires the + distribution of source code with any binary distribution and to + distribute linked combinations of the two. Non-GPL Code permitted under + this exception must only link to the code of Red Hat elfutils through + those well defined interfaces identified in the file named EXCEPTION + found in the source code files (the "Approved Interfaces"). The files + of Non-GPL Code may instantiate templates or use macros or inline + functions from the Approved Interfaces without causing the resulting + work to be covered by the GNU General Public License. Only Red Hat, + Inc. may make changes or additions to the list of Approved Interfaces. + Red Hat's grant of this exception is conditioned upon your not adding + any new exceptions. If you wish to add a new Approved Interface or + exception, please contact Red Hat. You must obey the GNU General Public + License in all respects for all of the Red Hat elfutils code and other + code used in conjunction with Red Hat elfutils except the Non-GPL Code + covered by this exception. If you modify this file, you may extend this + exception to your version of the file, but you are not obligated to do + so. If you do not wish to provide this exception without modification, + you must delete this exception statement from your version and license + this file solely under the GPL without exception. + + Red Hat elfutils is an included package of the Open Invention Network. + An included package of the Open Invention Network is a package for which + Open Invention Network licensees cross-license their patents. No patent + license is granted, either expressly or impliedly, by designation as an + included package. Should you wish to participate in the Open Invention + Network licensing program, please visit www.openinventionnetwork.com + . */ + +#include +#include +#include "dwarf" + +extern "C" +{ +#include "libdwP.h" +} + +using namespace elfutils; +using namespace std; + + +/* Throw + */ +void +dwarf::throw_libdw (::Dwarf *dw) +{ + throw std::runtime_error (::dwarf_errmsg (-1)); +} + +// This is just for things that can't find the Dwarf pointer directly. +void +dwarf::throw_libdw (::Dwarf_CU *cu) +{ + throw_libdw (cu->dbg); +} diff --git a/libdw/c++/line_info.cc b/libdw/c++/line_info.cc index cbdc638be..676f81ff6 100644 --- a/libdw/c++/line_info.cc +++ b/libdw/c++/line_info.cc @@ -21,7 +21,7 @@ dwarf::attr_value::line_info () const CUDIE (cudie, _m_attr.cu); Dwarf_Lines *lines; size_t n; - xif (dwarf_getsrclines (&cudie, &lines, &n) < 0); + xif (thisattr (), dwarf_getsrclines (&cudie, &lines, &n) < 0); return line_info_table (_m_attr.cu->files); } @@ -96,10 +96,10 @@ dwarf::source_file::mtime () const Dwarf_Files *files; Dwarf_Word idx; - xif (get_files (thisattr (), &files, &idx)); + xif (thisattr (), get_files (thisattr (), &files, &idx)); Dwarf_Word result; - xif (dwarf_filesrc (files, idx, &result, NULL) == NULL); + xif (thisattr (), dwarf_filesrc (files, idx, &result, NULL) == NULL); return result; } @@ -111,10 +111,10 @@ dwarf::source_file::size () const Dwarf_Files *files; Dwarf_Word idx; - xif (get_files (thisattr (), &files, &idx)); + xif (thisattr (), get_files (thisattr (), &files, &idx)); Dwarf_Word result; - xif (dwarf_filesrc (files, idx, NULL, &result) == NULL); + xif (thisattr (), dwarf_filesrc (files, idx, NULL, &result) == NULL); return result; } @@ -126,10 +126,10 @@ dwarf::source_file::name () const Dwarf_Files *files; Dwarf_Word idx; - xif (get_files (thisattr (), &files, &idx)); + xif (thisattr (), get_files (thisattr (), &files, &idx)); const char *result = dwarf_filesrc (files, idx, NULL, NULL); - xif (result == NULL); + xif (thisattr (), result == NULL); return result; } @@ -147,12 +147,12 @@ dwarf::source_file::to_string () const Dwarf_Files *files; Dwarf_Word idx; - xif (get_files (thisattr (), &files, &idx)); + xif (thisattr (), get_files (thisattr (), &files, &idx)); Dwarf_Word file_mtime; Dwarf_Word file_size; const char *result = dwarf_filesrc (files, idx, &file_mtime, &file_size); - xif (result == NULL); + xif (thisattr (), result == NULL); if (likely (file_mtime == 0) && likely (file_size == 0)) return plain_string (result); @@ -214,7 +214,7 @@ dwarf::file_table::find (const source_file &src) const // Same table, just cons an iterator using its index. Dwarf_Files *files; Dwarf_Word idx; - xif (get_files (&src._m_attr, &files, &idx)); + xif (files->cu, get_files (&src._m_attr, &files, &idx)); return const_iterator (*this, idx); } @@ -307,11 +307,11 @@ dwarf::line_entry::operator== (const dwarf::line_entry &other) const Dwarf_Word atime; Dwarf_Word asize; const char *aname = dwarf_linesrc (a, &atime, &asize); - xif (aname == NULL); + xif (a->files->cu, aname == NULL); Dwarf_Word btime; Dwarf_Word bsize; const char *bname = dwarf_linesrc (b, &btime, &bsize); - xif (bname == NULL); + xif (b->files->cu, bname == NULL); /* The mtime and size only count when encoded as nonzero. If either side is zero, we don't consider the field. */ diff --git a/libdw/c++/values.cc b/libdw/c++/values.cc index 9fd96dfaa..8b278c49b 100644 --- a/libdw/c++/values.cc +++ b/libdw/c++/values.cc @@ -225,13 +225,13 @@ dwarf::attr_value::to_string () const } // A few cases are trivial. -#define SIMPLE(type, name, form) \ - type \ - dwarf::attr_value::name () const \ - { \ - type result; \ - xif (dwarf_form##form (thisattr (), &result) < 0); \ - return result; \ +#define SIMPLE(type, name, form) \ + type \ + dwarf::attr_value::name () const \ + { \ + type result; \ + xif (thisattr (), dwarf_form##form (thisattr (), &result) < 0); \ + return result; \ } SIMPLE (bool, flag, flag) @@ -246,7 +246,7 @@ const char * dwarf::attr_value::string () const { const char *result = dwarf_formstring (thisattr ()); - xif (result == NULL); + xif (thisattr(), result == NULL); return result; } @@ -286,7 +286,7 @@ dwarf::attr_value::constant_block () const case DW_FORM_block1: case DW_FORM_block2: case DW_FORM_block4: - xif (dwarf_formblock (thisattr (), &block) < 0); + xif (thisattr(), dwarf_formblock (thisattr (), &block) < 0); break; case DW_FORM_data1: @@ -418,8 +418,8 @@ range_list_advance (int secndx, dwarf::range_list::const_iterator & dwarf::range_list::const_iterator::operator++ () { - xif (range_list_advance (IDX_debug_ranges, _m_cu, _m_base, - _m_begin, _m_end, _m_offset, NULL)); + xif (_m_cu, range_list_advance (IDX_debug_ranges, _m_cu, _m_base, + _m_begin, _m_end, _m_offset, NULL)); return *this; } @@ -523,7 +523,8 @@ dwarf::location_attr::const_iterator::operator++ () else { // Advance to next list entry. - xif (range_list_advance (IDX_debug_loc, _m_attr._m_attr._m_attr.cu, + xif (_m_attr._m_attr.thisattr (), + range_list_advance (IDX_debug_loc, _m_attr._m_attr._m_attr.cu, _m_base, _m_begin, _m_end, _m_offset, &_m_attr._m_attr._m_attr.valp)); if (_m_offset > 1)