Skip to content
Snippets Groups Projects

Decode trace symbols only when trace requested (GCC)

Merged Sebastian Hahta requested to merge exception-trace into master
2 files
+ 64
51
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -7,29 +7,29 @@ namespace ftl {
class Formatter {
public:
Formatter() {}
~Formatter() {}
~Formatter() {}
template <typename Type>
inline Formatter & operator << (const Type & value)
{
stream_ << value;
return *this;
}
template <typename Type>
inline Formatter & operator << (const Type & value)
{
stream_ << value;
return *this;
}
inline std::string str() const { return stream_.str(); }
inline operator std::string () const { return stream_.str(); }
inline std::string str() const { return stream_.str(); }
inline operator std::string () const { return stream_.str(); }
enum ConvertToString
{
to_str
};
inline std::string operator >> (ConvertToString) { return stream_.str(); }
enum ConvertToString
{
to_str
};
inline std::string operator >> (ConvertToString) { return stream_.str(); }
private:
std::stringstream stream_;
std::stringstream stream_;
Formatter(const Formatter &);
Formatter & operator = (Formatter &);
Formatter(const Formatter &);
Formatter & operator = (Formatter &);
};
class exception : public std::exception
@@ -39,22 +39,30 @@ class exception : public std::exception
explicit exception(const Formatter &msg);
~exception();
const char * what () const throw () {
const char* what() const throw () {
processed_ = true;
return msg_.c_str();
}
return msg_.c_str();
}
const char * trace () const throw () {
return trace_.c_str();
}
std::string trace() const throw () {
return decode_backtrace();
}
void ignore() const { processed_ = true; }
private:
std::string decode_backtrace() const;
std::string msg_;
std::string trace_;
mutable bool processed_;
#ifdef __GNUC__
static const int TRACE_SIZE_MAX_ = 16;
void* trace_[TRACE_SIZE_MAX_];
int trace_size_;
#endif
};
}
#define FTL_Error(A) (ftl::exception(ftl::Formatter() << __FILE__ << ":" << __LINE__ << ": " << A))
Loading