]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Small tweaks to attr values
authorRoland McGrath <roland@redhat.com>
Mon, 26 Jan 2009 11:06:21 +0000 (03:06 -0800)
committerRoland McGrath <roland@redhat.com>
Mon, 26 Jan 2009 11:06:21 +0000 (03:06 -0800)
libdw/c++/dwarf
libdw/c++/values.cc

index b64d3fb560c7f4d4a8abf9658a4b073ee86f9e15..3f2756b33d738b2f2238063e407d3b92d9ddbc0d 100644 (file)
@@ -61,6 +61,7 @@
 #include <list>
 #include <map>
 #include <set>
+#include <vector>
 #include <stack>
 #include <algorithm>
 #include <functional>
@@ -928,7 +929,7 @@ namespace elfutils
       ::Dwarf_Word constant () const;
       ::Dwarf_Sword signed_constant () const;
       // XXX better type??
-      std::string constant_block () const;
+      std::vector<uint8_t> constant_block () const;
 
       // XXX known enums
       // dwarf_enum dwarf_constant () const;
@@ -945,13 +946,13 @@ namespace elfutils
       inline bool operator== (const value &other) const
       {
        const value_space what = what_space ();
-       if (other.what_space () == what)
+       if (likely (other.what_space () == what))
          switch (what)
            {
            case VS_reference:
            case VS_unit_reference:
-             // return reference () == other.reference ();
-             return true;      // XXX temporary stub
+             // XXX Reference identity check (?)
+             return reference ().offset () == other.reference ().offset ();
 
            case VS_flag:
              return flag () == other.flag ();
index 0879f5894843b7c8aa899b7f9549a7b5ca802c3a..0523a30a54810084733c6fb168c856f81462c688 100644 (file)
@@ -140,11 +140,11 @@ dwarf::attr_value::what_space () const
 }
 
 static string
-hex_string (Dwarf_Word value)
+hex_string (Dwarf_Word value, const char *before = "", const char *after = "")
 {
   std::ostringstream os;
   os.setf(std::ios::hex, std::ios::basefield);
-  os << value;
+  os << before << value << after;
   return os.str ();
 }
 
@@ -201,7 +201,7 @@ dwarf::attr_value::to_string () const
 
     case VS_reference:
     case VS_unit_reference:
-      return "XXX";
+      return hex_string (reference ().offset (), "[", "]");
 
     case VS_source_file:
       return source_file ().to_string ();
@@ -242,7 +242,7 @@ dwarf::attr_value::string () const
   return result;
 }
 
-string
+vector<uint8_t>
 dwarf::attr_value::constant_block () const
 {
   Dwarf_Block block;
@@ -284,8 +284,9 @@ dwarf::attr_value::constant_block () const
       throw std::runtime_error ("XXX wrong form");
     }
 
-  return std::string (reinterpret_cast<const char *> (block.data),
-                     block.length);
+  const uint8_t *const begin = reinterpret_cast<const uint8_t *> (block.data);
+  const uint8_t *const end = begin + block.length;
+  return vector<uint8_t> (begin, end);
 }
 \f
 // dwarf::source_file
@@ -427,7 +428,7 @@ dwarf::location_attr::to_string () const
 {
   if (singleton ())
     return "XXX";
-  return hex_string (_m_attr.constant ());
+  return hex_string (_m_attr.constant (), "#");
 }
 \f
 // dwarf::range_list