+2009-03-29 Roland McGrath <roland@redhat.com>
+
+ * c++/exception.cc: New file.
+ * Makefile.am (libdwpp_a_SOURCES): Add it.
+
2009-03-25 Roland McGrath <roland@redhat.com>
* c++/dwarf, c++/values.cc: Proper dwarf_constant support.
# 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
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<typename raw, typename raw_element, typename element,
friend class attr_value;
protected:
+ inline void xif (bool fail) const
+ {
+ dwarf::xif (_m_die.cu, fail);
+ }
+
inline debug_info_entry ()
{
memset (&_m_die, 0, sizeof _m_die);
}
- inline debug_info_entry (::Dwarf *dw, ::Dwarf_Off off)
+ inline debug_info_entry (const dwarf &dw, ::Dwarf_Off off)
{
- xif (::dwarf_offdie (dw, off, &_m_die) == NULL);
+ dw.xif (::dwarf_offdie (dw._m_dw, off, &_m_die) == NULL);
}
public:
inline const_iterator (const debug_info_entry &parent)
{
int result = ::dwarf_child (parent.thisdie (), &_m_die._m_die);
- xif (result < 0);
+ parent.xif (result < 0);
}
// Construct from a reference attribute.
inline const_iterator (Dwarf_Attribute *attr)
{
- xif (::dwarf_formref_die (attr, &_m_die._m_die) == NULL);
+ dwarf::xif (attr, ::dwarf_formref_die (attr, &_m_die._m_die) == NULL);
}
public:
inline const_iterator &operator++ () // prefix
{
int result = ::dwarf_siblingof (&_m_die._m_die, &_m_die._m_die);
- xif (result < 0);
+ _m_die.xif (result < 0);
if (result > 0) // Hit the end.
*this = const_iterator ();
return *this;
_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;
}
--- /dev/null
+/* -*- 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
+ <http://www.openinventionnetwork.com>. */
+
+#include <config.h>
+#include <cassert>
+#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);
+}
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);
}
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;
}
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;
}
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;
}
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);
// 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);
}
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. */
}
// 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)
dwarf::attr_value::string () const
{
const char *result = dwarf_formstring (thisattr ());
- xif (result == NULL);
+ xif (thisattr(), result == NULL);
return result;
}
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:
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;
}
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)