[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master e0c15aa: Inhibit exception backtrace selectiv
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master e0c15aa: Inhibit exception backtrace selectively |
Date: |
Wed, 17 Mar 2021 14:20:13 -0400 (EDT) |
branch: master
commit e0c15aab366387a0d0b994e35e166a7eafe9069e
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Inhibit exception backtrace selectively
---
authenticity_test.cpp | 4 ++++
handle_exceptions_test.cpp | 3 +++
input_realization.cpp | 2 ++
input_sequence_test.cpp | 2 ++
progress_meter_test.cpp | 2 ++
test_tools.hpp | 7 +++++++
tn_range.tpp | 2 ++
unwind.cpp | 9 +++++++--
unwind.hpp | 21 ++++++++++++++++++---
9 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/authenticity_test.cpp b/authenticity_test.cpp
index 9e4fdfc..4c8d386 100644
--- a/authenticity_test.cpp
+++ b/authenticity_test.cpp
@@ -30,6 +30,7 @@
#include "miscellany.hpp"
#include "system_command.hpp"
#include "test_tools.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
#include <boost/filesystem/convenience.hpp> // basename()
#include <boost/filesystem/operations.hpp>
@@ -450,11 +451,14 @@ void PasskeyTest::TestDataFile() const
<< "\nto print:"
<< std::endl
;
+ {
+ scoped_unwind_toggler meaningless_name;
LMI_TEST_EQUAL
("At least one required file is missing, altered, or invalid."
" Try reinstalling."
,Authenticity::Assay(BeginDate_, Pwd_)
);
+ }
InitializeDataFile();
CheckNominal(__FILE__, __LINE__);
diff --git a/handle_exceptions_test.cpp b/handle_exceptions_test.cpp
index 851e692..6bbe6ff 100644
--- a/handle_exceptions_test.cpp
+++ b/handle_exceptions_test.cpp
@@ -24,6 +24,7 @@
#include "handle_exceptions.hpp"
#include "test_tools.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
#include <stdexcept>
@@ -46,6 +47,7 @@ int test_main(int, char*[])
{
try
{
+ scoped_unwind_toggler meaningless_name;
throw std::runtime_error(" This message should appear on stderr.");
}
catch(...)
@@ -60,6 +62,7 @@ int test_main(int, char*[])
// exception derived from it.
try
{
+ scoped_unwind_toggler meaningless_name;
std::cout << "Expect a success message..." << std::endl;
throw sneaky_exception("ERROR");
}
diff --git a/input_realization.cpp b/input_realization.cpp
index 35a8829..d474413 100644
--- a/input_realization.cpp
+++ b/input_realization.cpp
@@ -35,6 +35,7 @@
#include "miscellany.hpp" // each_equal()
#include "round_to.hpp"
#include "ssize_lmi.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
#include "value_cast.hpp"
#include <algorithm>
@@ -54,6 +55,7 @@ std::string realize_sequence_string
{
try
{
+ scoped_unwind_toggler meaningless_name;
InputSequence s
(sequence_string.value()
,input.years_to_maturity()
diff --git a/input_sequence_test.cpp b/input_sequence_test.cpp
index f77c048..c2737d5 100644
--- a/input_sequence_test.cpp
+++ b/input_sequence_test.cpp
@@ -24,6 +24,7 @@
#include "input_sequence.hpp"
#include "test_tools.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
#include <algorithm>
#include <iterator> // ostream_iterator
@@ -65,6 +66,7 @@ void input_sequence_test::check
{
try
{
+ scoped_unwind_toggler meaningless_name;
InputSequence const seq(e, n, 90, 95, 0, 2002, k, o, w);
std::vector<double> const& v(seq.seriatim_numbers());
diff --git a/progress_meter_test.cpp b/progress_meter_test.cpp
index 273fe7d..0ab41a5 100644
--- a/progress_meter_test.cpp
+++ b/progress_meter_test.cpp
@@ -24,6 +24,7 @@
#include "progress_meter.hpp"
#include "test_tools.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
#include <sstream>
@@ -187,6 +188,7 @@ void progress_meter_test::test_postcondition_failure()
{
if(1 == i)
{
+ scoped_unwind_toggler meaningless_name;
throw "Thrown and caught before meter incremented.";
}
LMI_TEST(meter->reflect_progress());
diff --git a/test_tools.hpp b/test_tools.hpp
index eaa217d..77d220c 100644
--- a/test_tools.hpp
+++ b/test_tools.hpp
@@ -61,6 +61,8 @@
#include "config.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
+
#include <cstdlib> // EXIT_SUCCESS, EXIT_FAILURE
#include <exception>
#include <ostream>
@@ -147,8 +149,12 @@ bool whats_what(std::string const& observed, what_regex
const& expected);
/// - their types match exactly, and
/// - lmi_test::whats_what() deems the observed what() equivalent to
/// macro argument WHAT.
+///
+/// Don't display a backtrace--it would be superfluous clutter here.
#define LMI_TEST_THROW(expression,TYPE,WHAT) \
+ { \
+ scoped_unwind_toggler meaningless_name; \
try \
{ \
expression; \
@@ -193,6 +199,7 @@ bool whats_what(std::string const& observed, what_regex
const& expected);
lmi_test::record_success(); \
} \
} \
+ } \
#define INVOKE_LMI_TEST(exp,file,line) \
if(!(exp)) \
diff --git a/tn_range.tpp b/tn_range.tpp
index 3814f89..844a111 100644
--- a/tn_range.tpp
+++ b/tn_range.tpp
@@ -22,6 +22,7 @@
#include "tn_range.hpp"
#include "alert.hpp"
+#include "unwind.hpp" // scoped_unwind_toggler
#include "value_cast.hpp"
#include <cmath> // pow(), signbit()
@@ -669,6 +670,7 @@ std::string tn_range<Number,Trammel>::diagnose_invalidity
Number n;
try
{
+ scoped_unwind_toggler meaningless_name;
n = value_cast<Number>(s);
}
catch(std::exception const&)
diff --git a/unwind.cpp b/unwind.cpp
index 8260cc9..7a1b16d 100644
--- a/unwind.cpp
+++ b/unwind.cpp
@@ -23,6 +23,8 @@
#include "unwind.hpp"
+bool g_unwind = true;
+
#if defined LMI_X86_64 && defined LMI_POSIX && defined __GLIBCXX__
#define UNW_LOCAL_ONLY
@@ -186,8 +188,11 @@ void print_backtrace()
extern "C"
void __cxa_throw(void* thrown_exception, std::type_info* tinfo, void
(*dest)(void*))
{
- identify_exception(thrown_exception, tinfo);
- print_backtrace();
+ if(g_unwind)
+ {
+ identify_exception(thrown_exception, tinfo);
+ print_backtrace();
+ }
original_cxa_throw(thrown_exception, tinfo, dest);
}
diff --git a/unwind.hpp b/unwind.hpp
index 91a6c52..6fee447 100644
--- a/unwind.hpp
+++ b/unwind.hpp
@@ -24,8 +24,23 @@
#include "config.hpp"
-// Deliberately empty. This header is just lmi's canonical place to
-// include "config.hpp". The exception unwinder exposes nothing to any
-// other lmi code.
+extern bool g_unwind;
+
+class scoped_unwind_toggler
+{
+ public:
+ scoped_unwind_toggler(bool z = false)
+ :original_g_unwind {g_unwind}
+ {
+ g_unwind = z;
+ }
+ ~scoped_unwind_toggler()
+ {
+ g_unwind = original_g_unwind;
+ }
+
+ private:
+ bool const original_g_unwind = g_unwind;
+};
#endif // unwind_hpp
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master e0c15aa: Inhibit exception backtrace selectively,
Greg Chicares <=