From 095a07b9554f6b12455d831c3f55bb96afcb12a5 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Thu, 21 Jan 2021 10:04:34 +0200 Subject: [PATCH] backtrace: use space delimeter by default Multiline backtrace is inherently dangerous in smp since it's easy for lines to get intermixed. It also doesn't make sense when the backtrace is printed as part of an exception. With this patch, test_exception_future_with_backtrace produces the following warning: ``` WARN 2021-01-21 14:32:05,060 [shard 0] seastar - Exceptional future ignored: seastar::internal::backtraced (expected Backtrace: 0x5a2089 0x5a2362 0x5a26d9 0x490533 0x490624 0x45c5a6 0x45cb69 0x490673 0x43308c), backtrace: 0x5a2089 0x5a2362 0x5a26d9 0x4b4287 0x4b439c 0x434f62 0x4b43d1 0x45cc04 0x490673 0x43308c ``` While previously, the warning looked like this: ``` WARN 2021-01-21 14:34:17,271 [shard 0] seastar - Exceptional future ignored: seastar::internal::backtraced (expected Backtrace: 0x5a209c 0x5a2386 0x5a26fd 0x490508 0x4905f4 0x45c676 0x45cc39 0x490643 0x43308c ), backtrace: 0x5a209c 0x5a2386 0x5a26fd 0x4b425c 0x4b437c 0x434f62 0x4b43b1 0x45ccd4 0x490643 0x43308c ``` Signed-off-by: Benny Halevy --- include/seastar/util/backtrace.hh | 8 ++++++-- src/util/backtrace.cc | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/seastar/util/backtrace.hh b/include/seastar/util/backtrace.hh index d128f4431c9..7baff99db21 100644 --- a/include/seastar/util/backtrace.hh +++ b/include/seastar/util/backtrace.hh @@ -70,12 +70,15 @@ public: private: vector_type _frames; size_t _hash; + char _delimeter; private: size_t calculate_hash() const noexcept; public: - simple_backtrace() = default; - simple_backtrace(vector_type f) noexcept : _frames(std::move(f)) {} + simple_backtrace(char delimeter = ' ') noexcept : _delimeter(delimeter) {} + simple_backtrace(vector_type f, char delimeter = ' ') noexcept : _frames(std::move(f)), _delimeter(delimeter) {} + size_t hash() const noexcept { return _hash; } + char delimeter() const noexcept { return _delimeter; } friend std::ostream& operator<<(std::ostream& out, const simple_backtrace&); @@ -128,6 +131,7 @@ public: ~tasktrace(); size_t hash() const noexcept { return _hash; } + char delimeter() const noexcept { return _main.delimeter(); } friend std::ostream& operator<<(std::ostream& out, const tasktrace&); diff --git a/src/util/backtrace.cc b/src/util/backtrace.cc index fb3db14a95a..40bba1438f0 100644 --- a/src/util/backtrace.cc +++ b/src/util/backtrace.cc @@ -108,8 +108,10 @@ std::ostream& operator<<(std::ostream& out, const frame& f) { } std::ostream& operator<<(std::ostream& out, const simple_backtrace& b) { + char delim[2] = {'\0', '\0'}; for (auto f : b._frames) { - out << " " << f << "\n"; + out << delim << f; + delim[0] = b.delimeter(); } return out; } @@ -117,11 +119,11 @@ std::ostream& operator<<(std::ostream& out, const simple_backtrace& b) { std::ostream& operator<<(std::ostream& out, const tasktrace& b) { out << b._main; for (auto&& e : b._prev) { - out << " --------\n"; + out << "\n --------"; std::visit(make_visitor([&] (const shared_backtrace& sb) { - out << sb; + out << '\n' << sb; }, [&] (const task_entry& f) { - out << " " << f << "\n"; + out << "\n " << f; }), e); } return out;