]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Consolidate/clean-up xif->throw_libdw paths.
authorRoland McGrath <roland@redhat.com>
Mon, 30 Mar 2009 03:50:20 +0000 (20:50 -0700)
committerRoland McGrath <roland@redhat.com>
Mon, 30 Mar 2009 03:50:20 +0000 (20:50 -0700)
libdw/ChangeLog
libdw/Makefile.am
libdw/c++/dwarf
libdw/c++/exception.cc [new file with mode: 0644]
libdw/c++/line_info.cc
libdw/c++/values.cc

index f4e602e516a9e4f0637bc665d54ba9ed92f8ac20..9c6e117424d2d27707b1f4f717ffa605544e3c4f 100644 (file)
@@ -1,3 +1,8 @@
+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.
index 9a2cff63c3ee4ef97ec992c7aafdb20f9edb2806..3919945a7b56e1fa16b97c0f191761639665d46b 100644 (file)
@@ -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
index 035248c061ccfda66228f4ed54b33ea364bd4cb4..1c4755962dc4428435ff490d8b7169a25ab7b82e 100644 (file)
@@ -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<typename raw, typename raw_element, typename element,
@@ -394,14 +406,19 @@ namespace elfutils
       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:
@@ -492,13 +509,13 @@ namespace elfutils
        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:
@@ -533,7 +550,7 @@ namespace elfutils
        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;
@@ -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 (file)
index 0000000..15a0cef
--- /dev/null
@@ -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
+   <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);
+}
index cbdc638be27ce7d0497a05e0a89ea28f10f1bc01..676f81ff6c44d7e2f67b46ee7f5d92168aa3b998 100644 (file)
@@ -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.  */
index 9fd96dfaa5f7d2f88f1a2b43c44c59883cea9401..8b278c49b9013f7aac83f78cc019c34fccc08708 100644 (file)
@@ -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)