Skip to content
Snippets Groups Projects
Commit e423f7fd authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Remove automatic backtrace display on failure

To display backtrace on failure one must now invoke pugs with the
--backtrace (or -b)  option
parent add70397
No related branches found
No related tags found
1 merge request!115Remove automatic backtrace display on failure
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
#include <rang.hpp> #include <rang.hpp>
#include <regex> #include <regex>
bool BacktraceManager::s_show = false;
void
BacktraceManager::setShow(bool show_backtrace)
{
s_show = show_backtrace;
}
BacktraceManager::BacktraceManager() BacktraceManager::BacktraceManager()
{ {
const int size = 100; const int size = 100;
...@@ -26,6 +34,7 @@ BacktraceManager::BacktraceManager() ...@@ -26,6 +34,7 @@ BacktraceManager::BacktraceManager()
std::ostream& std::ostream&
operator<<(std::ostream& os, const BacktraceManager& btm) operator<<(std::ostream& os, const BacktraceManager& btm)
{ {
if (BacktraceManager::s_show) {
const std::vector<std::string>& lines = btm.m_lines; const std::vector<std::string>& lines = btm.m_lines;
const std::regex mangled_function(R"%(\(.*\+)%"); const std::regex mangled_function(R"%(\(.*\+)%");
...@@ -49,6 +58,10 @@ operator<<(std::ostream& os, const BacktraceManager& btm) ...@@ -49,6 +58,10 @@ operator<<(std::ostream& os, const BacktraceManager& btm)
os << line << '\n'; os << line << '\n';
} }
} }
} else {
os << rang::fg::yellow << "\n[To display backtrace launch pugs with the --backtrace option]" << rang::style::reset
<< '\n';
}
return os; return os;
} }
...@@ -7,9 +7,12 @@ ...@@ -7,9 +7,12 @@
class BacktraceManager class BacktraceManager
{ {
private: private:
static bool s_show;
std::vector<std::string> m_lines; std::vector<std::string> m_lines;
public: public:
static void setShow(bool show_backtrace);
BacktraceManager(); BacktraceManager();
friend std::ostream& operator<<(std::ostream& os, const BacktraceManager& btm); friend std::ostream& operator<<(std::ostream& os, const BacktraceManager& btm);
......
#include <utils/PugsUtils.hpp> #include <utils/PugsUtils.hpp>
#include <utils/BacktraceManager.hpp>
#include <utils/BuildInfo.hpp> #include <utils/BuildInfo.hpp>
#include <utils/ConsoleManager.hpp> #include <utils/ConsoleManager.hpp>
#include <utils/FPEManager.hpp> #include <utils/FPEManager.hpp>
...@@ -104,6 +105,9 @@ initialize(int& argc, char* argv[]) ...@@ -104,6 +105,9 @@ initialize(int& argc, char* argv[])
app.add_flag("--fpe,!--no-fpe", enable_fpe, "Trap floating point exceptions [default: true]"); app.add_flag("--fpe,!--no-fpe", enable_fpe, "Trap floating point exceptions [default: true]");
bool show_backtrace = false;
app.add_flag("-b,--backtrace,!--no-backtrace", show_backtrace, "Show backtrace on failure [default: false]");
app.add_flag("--signal,!--no-signal", enable_signals, "Catches signals [default: true]"); app.add_flag("--signal,!--no-signal", enable_signals, "Catches signals [default: true]");
bool pause_on_error = false; bool pause_on_error = false;
...@@ -118,6 +122,7 @@ initialize(int& argc, char* argv[]) ...@@ -118,6 +122,7 @@ initialize(int& argc, char* argv[])
std::exit(app.exit(e, std::cout, std::cerr)); std::exit(app.exit(e, std::cout, std::cerr));
} }
BacktraceManager::setShow(show_backtrace);
ConsoleManager::init(enable_color); ConsoleManager::init(enable_color);
SignalManager::setPauseForDebug(pause_on_error); SignalManager::setPauseForDebug(pause_on_error);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment