From 1fd26a03b214739ba6781c2619ad4dca23709375 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Wed, 2 Jun 2021 00:13:48 -0400 Subject: [PATCH] tracer: annotate both ends of the stack trace Add a matching "--- BEGIN TRACE..." line to complement the "--- END TRACE..." line. Signed-off-by: Zygo Blaxell --- src/bees.cc | 6 ++++++ src/bees.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/bees.cc b/src/bees.cc index 98ce192..d40a964 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -42,11 +42,16 @@ do_cmd_help(char *argv[]) // tracing ---------------------------------------- thread_local BeesTracer *BeesTracer::tl_next_tracer = nullptr; +thread_local bool BeesTracer::tl_first = true; thread_local bool BeesTracer::tl_silent = false; BeesTracer::~BeesTracer() { if (!tl_silent && current_exception()) { + if (tl_first) { + BEESLOGNOTICE("--- BEGIN TRACE --- exception ---"); + tl_first = false; + } try { m_func(); } catch (exception &e) { @@ -61,6 +66,7 @@ BeesTracer::~BeesTracer() tl_next_tracer = m_next_tracer; if (!m_next_tracer) { tl_silent = false; + tl_first = true; } } diff --git a/src/bees.h b/src/bees.h index 48f94ad..52f4031 100644 --- a/src/bees.h +++ b/src/bees.h @@ -197,6 +197,7 @@ class BeesTracer { thread_local static BeesTracer *tl_next_tracer; thread_local static bool tl_silent; + thread_local static bool tl_first; public: BeesTracer(function f, bool silent = false); ~BeesTracer();