]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Use common code for C and C++ range_fmt
authorPetr Machata <pmachata@redhat.com>
Wed, 7 Oct 2009 13:59:38 +0000 (15:59 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:11 +0000 (14:55 +0200)
* Also move it to coverage code so that coverage formatting can take
  advantage of it.

src/dwarflint-coverage.cc
src/dwarflint-coverage.h
src/dwarflint-coverage.hh
src/dwarflint-hl.cc
src/dwarflint.c
src/dwarflint.h

index aa9b17c3f133e31a0ce78eca01653dc4214b4228..4e456029244241bedef5c7a8160da51a1bcf00dc 100644 (file)
@@ -39,7 +39,6 @@ extern "C"
 #include <string.h>
 #include <inttypes.h>
 
-
 namespace
 {
   template <class X>
@@ -249,6 +248,22 @@ namespace
   }
 }
 
+std::string
+range_fmt (uint64_t start, uint64_t end)
+{
+  std::ostringstream os;
+  os << std::hex << "[0x" << start << ", 0x" << end << ")";
+  return os.str ();
+}
+
+char *
+range_fmt (char *buf, size_t buf_size, uint64_t start, uint64_t end)
+{
+  std::string s = range_fmt (start, end);
+  strncpy (buf, s.c_str (), buf_size);
+  return buf;
+}
+
 bool
 coverage_is_overlap (struct coverage const *cov,
                     uint64_t start, uint64_t length)
index ed4f00fe89cd4c59e7cd5df42d1d39cbeabc27e3..f21c55b190e03caf5e01066469181a565b134bab 100644 (file)
@@ -81,6 +81,9 @@ struct coverage
 #endif
 };
 
+char *range_fmt (char *buf, size_t buf_size,
+                uint64_t start, uint64_t end);
+
 struct coverage *coverage_clone (struct coverage const *cov)
   __attribute__ ((malloc));
 void coverage_free (struct coverage *cov);
index ec3a681137b3e18db54d0f7f16d1970153764f2a..176a274a10e32f1d58f0660999d1476f848c65dc 100644 (file)
@@ -31,6 +31,8 @@
 #include <sstream>
 #include "dwarflint-coverage.h"
 
+std::string range_fmt (uint64_t start, uint64_t end);
+
 namespace cov
 {
   class _format_base
@@ -44,7 +46,7 @@ namespace cov
     {
       if (_m_seen)
        _m_os << _m_delim;
-      _m_os << "[" << start << ", " << start + length << ")";
+      _m_os << range_fmt (start, start + length);
       _m_seen = true;
       return true;
     }
index f033f6b22fc3294e3b44a942893b61968328d25a..f59ee0b272933b6ba33269fefcaf0bae07cf1610 100644 (file)
@@ -99,13 +99,6 @@ hl_ctx_delete (hl_ctx *hlctx)
   delete hlctx;
 }
 
-std::string
-range_fmt (uint64_t start, uint64_t end)
-{
-  char buf[128];
-  return std::string (range_fmt (buf, sizeof buf, start, end));
-}
-
 static const expected_at_map expected_at;
 //static const expected_children_map expected_children;
 
index 1753e171c31f117c2f7731cedb9336129364a9ca..fd302c2504f6e96b4070e4575ec0e07295863297 100644 (file)
@@ -344,13 +344,6 @@ wr_message (enum message_category category, const struct where *wh,
   va_end (ap);
 }
 
-char *
-range_fmt (char *buf, size_t buf_size, uint64_t start, uint64_t end)
-{
-  snprintf (buf, buf_size, "[%#" PRIx64 ", %#" PRIx64 ")", start, end);
-  return buf;
-}
-
 void
 wr_format_padding_message (enum message_category category,
                           struct where *wh,
index ce8ba5936efdc78e3167bfcf050b6003c8b503c5..b6b44efd90cffb6b2516ed721806a262ef49d464 100644 (file)
@@ -193,8 +193,6 @@ extern "C"
                                     struct where *wh,
                                     uint64_t start, uint64_t end);
 
-  extern char *range_fmt (char *buf, size_t buf_size, uint64_t start, uint64_t end);
-
   struct relocation
   {
     uint64_t offset;
@@ -312,8 +310,6 @@ extern "C"
 
 #ifdef __cplusplus
 }
-
-extern std::string range_fmt (uint64_t start, uint64_t end);
 #endif
 
 #endif/*DWARFLINT_HL_H*/