diff options
author | Ben Burdette <bburdette@protonmail.com> | 2022-05-12 13:59:58 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@protonmail.com> | 2022-05-12 13:59:58 -0600 |
commit | 1ea13084c9aac84e7877f9051f656eb5ea519d8a (patch) | |
tree | 75e3764fb0fe447ef041093c2c72539908ace3c9 /src/libexpr/eval.hh | |
parent | 2c9fafdc9e43f6da39c289888dedbbbf0ea0b208 (diff) |
template-ize debugThrow
Diffstat (limited to 'src/libexpr/eval.hh')
-rw-r--r-- | src/libexpr/eval.hh | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index add104a84..1e728002a 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -128,10 +128,30 @@ public: bool debugQuit; std::list<DebugTrace> debugTraces; + template<class E> [[gnu::noinline, gnu::noreturn]] - void debugThrow(const Error &error, const Env & env, const Expr & expr) const; + void debugThrow(const E &error, const Env & env, const Expr & expr) const + { + if (debuggerHook) + debuggerHook(&error, env, expr); + + throw error; + } + + template<class E> [[gnu::noinline, gnu::noreturn]] - void debugThrowLastTrace(Error & e) const; + void debugThrowLastTrace(E & e) const + { + // Call this in the situation where Expr and Env are inaccessible. + // The debugger will start in the last context that's in the + // DebugTrace stack. + if (debuggerHook && !debugTraces.empty()) { + const DebugTrace & last = debugTraces.front(); + debuggerHook(&e, last.env, last.expr); + } + + throw e; + } private: SrcToStore srcToStore; |