From 550f0f724bb95ec836021983aef0865895761595 Mon Sep 17 00:00:00 2001 From: Simon Pintarelli Date: Thu, 13 Jun 2024 14:50:29 +0200 Subject: [PATCH] call_sirius -> dump core if `SIRIUS_COREDUMP=1` env is defined --- src/api/sirius_api.cpp | 68 ++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/api/sirius_api.cpp b/src/api/sirius_api.cpp index 92ea2da3e..afba65349 100644 --- a/src/api/sirius_api.cpp +++ b/src/api/sirius_api.cpp @@ -239,37 +239,47 @@ template static void call_sirius(F&& f__, int* error_code__) { - // try { - f__(); - if (error_code__) { - *error_code__ = SIRIUS_SUCCESS; + auto val = env::get_value_ptr("SIRIUS_COREDUMP"); + bool coredump = false; + if(val != nullptr) { + coredump = *val == 1; + } + if (coredump) { + f__(); return; } - // } catch (std::runtime_error const& e) { - // if (error_code__) { - // *error_code__ = SIRIUS_ERROR_RUNTIME; - // sirius_print_error(*error_code__, e.what()); - // return; - // } else { - // sirius_exit(SIRIUS_ERROR_RUNTIME, e.what()); - // } - // } catch (std::exception const& e) { - // if (error_code__) { - // *error_code__ = SIRIUS_ERROR_EXCEPTION; - // sirius_print_error(*error_code__, e.what()); - // return; - // } else { - // sirius_exit(SIRIUS_ERROR_EXCEPTION, e.what()); - // } - // } catch (...) { - // if (error_code__) { - // *error_code__ = SIRIUS_ERROR_UNKNOWN; - // sirius_print_error(*error_code__); - // return; - // } else { - // sirius_exit(SIRIUS_ERROR_UNKNOWN); - // } - // } + + try { + f__(); + if (error_code__) { + *error_code__ = SIRIUS_SUCCESS; + return; + } + } catch (std::runtime_error const& e) { + if (error_code__) { + *error_code__ = SIRIUS_ERROR_RUNTIME; + sirius_print_error(*error_code__, e.what()); + return; + } else { + sirius_exit(SIRIUS_ERROR_RUNTIME, e.what()); + } + } catch (std::exception const& e) { + if (error_code__) { + *error_code__ = SIRIUS_ERROR_EXCEPTION; + sirius_print_error(*error_code__, e.what()); + return; + } else { + sirius_exit(SIRIUS_ERROR_EXCEPTION, e.what()); + } + } catch (...) { + if (error_code__) { + *error_code__ = SIRIUS_ERROR_UNKNOWN; + sirius_print_error(*error_code__); + return; + } else { + sirius_exit(SIRIUS_ERROR_UNKNOWN); + } + } } template