Skip to content

Commit

Permalink
backtrace: use space delimeter by default
Browse files Browse the repository at this point in the history
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_exception> (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_exception> (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 <bhalevy@scylladb.com>
  • Loading branch information
bhalevy committed Feb 2, 2021
1 parent a23ebac commit 095a07b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions include/seastar/util/backtrace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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&);

Expand Down Expand Up @@ -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&);

Expand Down
10 changes: 6 additions & 4 deletions src/util/backtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,22 @@ 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;
}

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;
Expand Down

0 comments on commit 095a07b

Please sign in to comment.