From d02f2ebf36ac60fd37b5ca29a0cb8bfccbe82c3b Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Mon, 26 Jan 2009 03:06:21 -0800 Subject: [PATCH] Small tweaks to attr values --- libdw/c++/dwarf | 9 +++++---- libdw/c++/values.cc | 15 ++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index b64d3fb56..3f2756b33 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -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 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 (); diff --git a/libdw/c++/values.cc b/libdw/c++/values.cc index 0879f5894..0523a30a5 100644 --- a/libdw/c++/values.cc +++ b/libdw/c++/values.cc @@ -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 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 (block.data), - block.length); + const uint8_t *const begin = reinterpret_cast (block.data); + const uint8_t *const end = begin + block.length; + return vector (begin, end); } // 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 (), "#"); } // dwarf::range_list -- 2.47.2