46 #ifndef EXCEPTIONS_HPP 47 #define EXCEPTIONS_HPP 50 #include "config_HAVE_ASSERTS.hpp" 51 #include "config_HAVE_PRINT_STACK.hpp" 78 inline T&
throw_error(
const T& t,
const std::string& expression,
94 int code = EXIT_FAILURE)
98 throw std::string(std::string(
"error -> ") + expression + std::string(
"\n"));
100 throw std::string(std::string(
"error -> ") + expression + std::string(
"\n\t") + std::string(pp) +
101 std::string(
"\n\t") + std::string(
file) + std::string(
":") + std::to_string(
line));
103 static T t_local = t;
128 throw std::string(std::string(
"warning -> ") + expression + std::string(
"\n"));
130 throw std::string(std::string(
"warning -> ") + expression + std::string(
"\n\t") + std::string(pp) +
131 std::string(
"\n\t") + std::string(
file) + std::string(
":") + std::to_string(
line));
145 int code = EXIT_FAILURE)
147 return throw_error(t, std::string(expression), pp, file, line, code);
150 #define PRINT_STACK \ 153 const size_t print_stack_max_depth = 100; \ 154 size_t print_stack_stack_depth; \ 155 void* print_stack_stack_addrs[print_stack_max_depth]; \ 156 char** print_stack_stack_strings; \ 159 ssize_t readlink_res = readlink("/proc/self/exe", buf, sizeof(buf)); \ 160 if(readlink_res == -1) \ 161 printf("Failed command: %s\n", "readlink"); \ 162 buf[readlink_res] = '\0'; \ 163 std::string program(buf); \ 164 print_stack_stack_depth = static_cast<size_t>(backtrace(print_stack_stack_addrs, print_stack_max_depth)); \ 165 print_stack_stack_strings = \ 166 backtrace_symbols(print_stack_stack_addrs, static_cast<int>(print_stack_stack_depth)); \ 168 printf("Call stack\n"); \ 170 for(size_t print_stack_i = 0; print_stack_i < print_stack_stack_depth; print_stack_i++) \ 172 size_t print_stack_sz = 2000; \ 173 char* print_stack_function = static_cast<char*>(malloc(print_stack_sz)); \ 174 char* print_stack_address = static_cast<char*>(malloc(print_stack_sz)); \ 175 char *print_stack_begin = nullptr, *print_stack_end = nullptr; \ 176 size_t print_stack_first = 0, print_stack_last = 0; \ 177 size_t print_stack_counter; \ 178 print_stack_counter = 0; \ 180 for(char* print_stack_j = print_stack_stack_strings[print_stack_i]; *print_stack_j; \ 181 ++print_stack_j, print_stack_counter++) \ 183 if(*print_stack_j == '(') \ 185 print_stack_begin = print_stack_j; \ 187 else if(*print_stack_j == '+') \ 189 print_stack_end = print_stack_j; \ 191 else if(*print_stack_j == '[') \ 193 print_stack_first = print_stack_counter; \ 195 else if(*print_stack_j == ']') \ 197 print_stack_last = print_stack_counter; \ 200 if(print_stack_begin && print_stack_end) \ 202 *print_stack_begin++ = 0; \ 203 *print_stack_end = 0; \ 206 int print_stack_status; \ 207 char* print_stack_ret = \ 208 abi::__cxa_demangle(print_stack_begin, print_stack_function, &print_stack_sz, &print_stack_status); \ 209 if(print_stack_ret) \ 212 print_stack_function = print_stack_ret; \ 217 strncpy(print_stack_function, print_stack_begin, print_stack_sz); \ 218 strncat(print_stack_function, "()", print_stack_sz); \ 219 print_stack_function[print_stack_sz - 1] = 0; \ 221 printf("%s:%s\n", print_stack_stack_strings[print_stack_i], print_stack_function); \ 222 if(print_stack_first && print_stack_last) \ 224 std::string print_stack_command; \ 225 print_stack_command += "addr2line"; \ 226 strncpy(print_stack_address, &((print_stack_stack_strings[print_stack_i])[print_stack_first + 1]), \ 227 print_stack_last - print_stack_first - 1); \ 228 print_stack_address[print_stack_last - print_stack_first] = '\0'; \ 229 print_stack_command += " -C " + std::string(print_stack_address) + " -e " + program; \ 230 int print_stack_res = std::system(print_stack_command.c_str()); \ 231 if(is_failure(print_stack_res)) \ 232 printf("Failed command: %s\n", print_stack_command.c_str()); \ 238 printf("%s\n", print_stack_stack_strings[print_stack_i]); \ 239 if(print_stack_first && print_stack_last) \ 241 std::string print_stack_command; \ 242 print_stack_command += "addr2line"; \ 243 strncpy(print_stack_address, &((print_stack_stack_strings[print_stack_i])[print_stack_first + 1]), \ 244 print_stack_last - print_stack_first - 1); \ 245 print_stack_address[print_stack_last - print_stack_first] = '\0'; \ 246 print_stack_command += " -C " + std::string(print_stack_address) + " -e " + program; \ 247 int print_stack_res = std::system(print_stack_command.c_str()); \ 248 if(is_failure(print_stack_res)) \ 249 printf("Failed command: %s\n", print_stack_command.c_str()); \ 253 free(print_stack_function); \ 254 free(print_stack_address); \ 256 free(print_stack_stack_strings); \ 263 #define THROW_ERROR(str_expr) throw_error(0, (str_expr), __PRETTY_FUNCTION__, __FILE__, __LINE__) 266 #define THROW_ERROR_CODE(code, str_expr) \ 270 throw_error(0, (str_expr), __PRETTY_FUNCTION__, __FILE__, __LINE__, code); \ 275 #define THROW_ASSERT(cond, str_expr) \ 285 THROW_ERROR(std::string(str_expr) + " (" + #cond + ")"); \ 289 #define THROW_ASSERT(cond, str_expr) 291 #define THROW_UNREACHABLE(str_expr) \ 295 THROW_ERROR(std::string("This point should never be reached - " + std::string(str_expr))); \ 300 #define THROW_WARNING(str_expr) \ 301 ((error_on_warning) ? ((void)(THROW_ERROR(str_expr))) : \ 302 ((void)(std::cerr << std::string("Warning: ") + (str_expr) << std::endl))) 305 #define NOT_YET_IMPLEMENTED() \ 306 ((error_on_warning) ? \ 307 ((void)(THROW_ERROR(std::string("Not yet implemented")))) : \ 308 (throw_warning((std::string("Not yet implemented")), __PRETTY_FUNCTION__, __FILE__, __LINE__))) 312 #define THROW_WARNING_ASSERT(cond, str_expr) \ 313 ((cond) ? (void)0 : (THROW_WARNING(std::string(str_expr) + " (" + #cond + ")"))) 315 #define THROW_WARNING_ASSERT(cond, str_expr) (void)0 349 bool IsError(
const int error_value);
bool is_failure(const int error_value)
Return true if the return value corresponds to a failure (not to an error)
Not supported variable length array.
bool error_on_warning
Transform warning into errors.
int exit_code
Autoheader include.
void throw_warning(const std::string &expression, const char *pp, const char *file, int line)
Prints a warning, along with information about the source code.
void line(int x1, int y1, int x2, int y2, unsigned int color)
pointer_plus_expr not removed
varargs with cross-compiler
Not trapped by panda torture script.
task graph structure not yet supported
bool IsError(const int error_value)
Return true if the return_value corresponds to an error.
T & throw_error(const T &t, const std::string &expression, const char *pp, const char *file, int line, int code=EXIT_FAILURE)
Template function used to throw an exception.
irreducible loops are not currently supported
nested functions are not currently supported
throw_error_code
Error code returned by THROW_ERROR_CODE.
pragma pattern not yet supported