From 8a6f1aa5aab4398799809fdeed07ac09001df47b Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Wed, 7 Oct 2009 15:59:38 +0200 Subject: [PATCH] dwarflint: Use common code for C and C++ range_fmt * Also move it to coverage code so that coverage formatting can take advantage of it. --- src/dwarflint-coverage.cc | 17 ++++++++++++++++- src/dwarflint-coverage.h | 3 +++ src/dwarflint-coverage.hh | 4 +++- src/dwarflint-hl.cc | 7 ------- src/dwarflint.c | 7 ------- src/dwarflint.h | 4 ---- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/dwarflint-coverage.cc b/src/dwarflint-coverage.cc index aa9b17c3f..4e4560292 100644 --- a/src/dwarflint-coverage.cc +++ b/src/dwarflint-coverage.cc @@ -39,7 +39,6 @@ extern "C" #include #include - namespace { template @@ -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) diff --git a/src/dwarflint-coverage.h b/src/dwarflint-coverage.h index ed4f00fe8..f21c55b19 100644 --- a/src/dwarflint-coverage.h +++ b/src/dwarflint-coverage.h @@ -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); diff --git a/src/dwarflint-coverage.hh b/src/dwarflint-coverage.hh index ec3a68113..176a274a1 100644 --- a/src/dwarflint-coverage.hh +++ b/src/dwarflint-coverage.hh @@ -31,6 +31,8 @@ #include #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; } diff --git a/src/dwarflint-hl.cc b/src/dwarflint-hl.cc index f033f6b22..f59ee0b27 100644 --- a/src/dwarflint-hl.cc +++ b/src/dwarflint-hl.cc @@ -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; diff --git a/src/dwarflint.c b/src/dwarflint.c index 1753e171c..fd302c250 100644 --- a/src/dwarflint.c +++ b/src/dwarflint.c @@ -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, diff --git a/src/dwarflint.h b/src/dwarflint.h index ce8ba5936..b6b44efd9 100644 --- a/src/dwarflint.h +++ b/src/dwarflint.h @@ -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*/ -- 2.47.3