WSL/SLF GitLab Repository

Commit 1224b454 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A display bug has been fixed in the Date class, the exceptions code has been...

A display bug has been fixed in the Date class, the exceptions code has been cleaned up a little bit and the call stack should now be even less intimidating!
parent aa50376d
......@@ -68,6 +68,8 @@ ELSE(MSVC)
#ENDIF(BUILD_SHARED_LIBS)
ENDIF(MSVC)
#The following pre-processor variables are automatically defined:
# __linux, __GNUC__, __CYGWIN__, _WIN32, __MINGW32__, __APPLE__
IF(UNIX)
IF(APPLE)
SET(DLL_EXT "dylib*")
......
......@@ -30,7 +30,7 @@ using namespace std;
namespace mio {
#ifdef MINGW
#ifdef __MINGW32__
//some version of MINGW have a buggy 64 bits implementation of difftime
//this is Mingw bug 2152
static __inline__
......@@ -122,7 +122,7 @@ void Date::setFromSys() {
const time_t curr = time(NULL);// current time in UTC
tm local = *gmtime(&curr);// current time in UTC, stored as tm
const time_t utc = mktime(&local);// convert GMT tm to GMT time_t
#ifndef MINGW
#ifndef __MINGW32__
double tz = - difftime(utc,curr)/3600.; //time zone shift (sign so that if curr>utc, tz>0)
#else //workaround for Mingw bug 2152
double tz = - mio::difftime(utc,curr)/3600.; //time zone shift (sign so that if curr>utc, tz>0)
......@@ -1056,15 +1056,23 @@ void Date::plausibilityCheck(const int& in_year, const int& in_month, const int&
|| (in_hour < 0) || (in_hour > 24)
|| (in_minute < 0) || (in_minute > 59)) {
ostringstream ss;
ss << "Invalid Date requested: " << in_year << "-" << in_month;
ss << "-" << in_day << "T" << in_hour << ":" << in_minute;
ss << std::fixed << std::setfill('0') << std::setprecision(0);
ss << "Invalid Date requested: " << std::setw(4) << in_year << "-";
ss << std::setw(2) << in_month << "-";
ss << std::setw(2) << in_day << "T";
ss << std::setw(2) << in_hour << ":";
ss << std::setw(2) << in_minute;
throw IOException(ss.str(), AT);
}
if ((in_hour == 24) && (in_minute != 0)) {
ostringstream ss;
ss << "Invalid Date requested: " << in_year << "-" << in_month;
ss << "-" << in_day << "T" << in_hour << ":" << in_minute;
ss << std::fixed << std::setfill('0') << std::setprecision(0);
ss << "Invalid Date requested: " << std::setw(4) << in_year << "-";
ss << std::setw(2) << in_month << "-";
ss << std::setw(2) << in_day << "T";
ss << std::setw(2) << in_hour << ":";
ss << std::setw(2) << in_minute;
throw IOException(ss.str(), AT);
}
}
......
......@@ -42,7 +42,7 @@ using namespace std;
namespace mio {
#if defined(MSG_BOX)
void messageBox(const std::string& msg) {
void messageBox(const std::string& msg) {
#if defined(__linux) && !defined(ANDROID) && !defined(__CYGWIN__)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
MessageBoxX11("Oops, something went wrong!", box_msg.c_str());
......@@ -62,8 +62,50 @@ namespace mio {
SInt32 error = 0;
CFUserNotificationCreate(NULL, 0, kCFUserNotificationStopAlertLevel, &error, dict);
#endif
}
#endif
//this method is only called for Linux
std::string IOException::resolveSymbols(char *symbols, const unsigned int& ii, bool& found_main) const
{
#ifdef __GNUC__
found_main=false;
std::ostringstream ss;
char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;
for (char *p = symbols; *p; ++p) {
// find parantheses and +address offset surrounding mangled name
if (*p == '(') mangled_name = p;
else if (*p == '+') offset_begin = p;
else if (*p == ')') offset_end = p;
}
if (mangled_name && offset_begin && offset_end && mangled_name < offset_begin) {
//the line could be processed, attempt to demangle the symbol
*mangled_name++ = '\0'; *offset_begin++ = '\0'; *offset_end++ = '\0';
if (string(mangled_name)=="main") found_main=true;
int status;
char *real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);
// if demangling is successful, output the demangled function name
if (status == 0) {
const std::string tmp(real_name);
const size_t pos = tmp.find_first_of("(");
const std::string func_name = tmp.substr(0, pos);
const std::string func_args = tmp.substr(pos);
ss << "\t(" << ii << ") in \033[4m" << func_name << "\033[0m\033[01;30m" << func_args << " from \033[3m" << symbols << "\033[23m";
} else { // otherwise, output the mangled function name
ss << "\t(" << ii << ") in " << mangled_name << " from \033[3m" << symbols << "\033[23m";
}
free(real_name);
} else { // otherwise, print the whole line
ss << "\t(" << ii << ") at " << symbols;
}
return ss.str();
#else
return "\tat " + string(symbols);
#endif
}
#ifdef _POPC_
IOException::IOException(const std::string& message, const std::string& position) : POPException(STD_EXCEPTION)
......@@ -85,40 +127,12 @@ IOException::IOException(const std::string& message, const std::string& position
char** symbols = backtrace_symbols(tracearray, tracesize); //translate pointers to strings
std::string backtrace_info = "\n\033[01;30m**** backtrace ****\n"; //we use ASCII color codes to make the backtrace less visible/aggressive
for (unsigned int ii=1; ii<(unsigned)tracesize; ii++) {
#ifdef __GNUC__
std::ostringstream ss;
char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;
for (char *p = symbols[ii]; *p; ++p) {
// find parantheses and +address offset surrounding mangled name
if (*p == '(') mangled_name = p;
else if (*p == '+') offset_begin = p;
else if (*p == ')') offset_end = p;
}
if (mangled_name && offset_begin && offset_end && mangled_name < offset_begin) {
//the line could be processed, attempt to demangle the symbol
*mangled_name++ = '\0'; *offset_begin++ = '\0'; *offset_end++ = '\0';
int status;
char *real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);
// if demangling is successful, output the demangled function name
if (status == 0) {
const std::string tmp(real_name);
const size_t pos = tmp.find_first_of("(");
const std::string func_name = tmp.substr(0, pos);
const std::string func_args = tmp.substr(pos);
ss << "\t(" << ii << ") in \033[4m" << func_name << "\033[0m\033[01;30m" << func_args << " from " << symbols[ii] << " " << offset_end << "+" << offset_begin;
} else { // otherwise, output the mangled function name
ss << "\t(" << ii << ") in " << mangled_name << " from " << symbols[ii] << " " << offset_end << "+" << offset_begin;
}
free(real_name);
} else { // otherwise, print the whole line
ss << "\t(" << ii << ") at " << symbols[ii];
}
backtrace_info += ss.str()+"\n";
#else
backtrace_info += "\tat " + string(symbols[ii]) + "\n";
#endif
bool found_main;
const string line = resolveSymbols( symbols[ii], ii, found_main );
if (found_main) break; //we hit "main" so we stop here
backtrace_info += line+"\n";
}
backtrace_info += "\033[0m"; //back to normal color
backtrace_info += "\n\033[0m"; //back to normal color
full_output = backtrace_info + "[" + where + "] \033[31;1m" + message + "\033[0m\n";
free(symbols);
#else
......
......@@ -49,6 +49,7 @@ class MIO_API IOException : public POPException {
virtual const char* what() const throw();
protected:
std::string resolveSymbols(char *symbols, const unsigned int& ii, bool& found_main) const;
std::string msg, full_output;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment