void error1(char*m,se_position position) { /* When there is nothing more to do than to exit or to go back into the debugger. */ int l = se_position2line(position); int c = se_position2column(position); int f = se_position2path_id(position); char* f1 = "Line : %d column %d in %s.\n"; char* f2 = "*** Error at Run Time ***: %s\n"; fprintf(SE_ERR,f1,l,c,p[f]); fprintf(SE_ERR,f2,m); #ifdef SE_EXCEPTIONS print_exception(); #endif #ifdef SE_SEDB sedb_break(se_dst,position); #else handle(SE_HANDLE_RUNTIME_ERROR, m); se_print_run_time_stack(); fprintf(SE_ERR,f1,l,c,p[f]); fprintf(SE_ERR,f2,m); exit(EXIT_FAILURE); #endif }
void print_exception(VM *vm, VALUE result) { // TODO: fprintf to stderr and teach dump_titled to optionally fprintf to stderr too printf("====== Exception of type '%s' ======\n", obj_to_cstring(NGS_TYPE_NAME(NORMAL_TYPE_INSTANCE_TYPE(result)))); // TODO: maybe macro to iterate attributes VALUE fields = NGS_TYPE_FIELDS(NORMAL_TYPE_INSTANCE_TYPE(result)); HASH_OBJECT_ENTRY *e; for(e=HASH_HEAD(fields); e; e=e->insertion_order_next) { if(obj_is_of_type(ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)], vm->Backtrace)) { printf("=== [ backtrace ] ===\n"); // Backtrace.frames = [{"closure": ..., "ip": ...}, ...] VALUE backtrace = ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]; VALUE frames; assert(get_normal_type_instace_attribute(backtrace, make_string("frames"), &frames) == METHOD_OK); unsigned int i; for(i = 0; i < OBJ_LEN(frames); i++) { VALUE frame, resolved_ip, ip; frame = ARRAY_ITEMS(frames)[i]; H(ip, frame, "ip"); resolved_ip = resolve_ip(vm, (IP)(GET_INT(ip) - 1)); if(IS_HASH(resolved_ip)) { VALUE file, first_line, first_column, last_line, last_column; HASH_OBJECT_ENTRY *closure_entry; char *closure_name = "<anonymous>"; H(file, resolved_ip, "file"); H(first_line, resolved_ip, "first_line"); H(first_column, resolved_ip, "first_column"); H(last_line, resolved_ip, "last_line"); H(last_column, resolved_ip, "last_column"); closure_entry = get_hash_key(frame, make_string("closure")); if(closure_entry && IS_CLOSURE(closure_entry->val) && (IS_HASH(CLOSURE_OBJ_ATTRS(closure_entry->val)))) { HASH_OBJECT_ENTRY *name_entry; name_entry = get_hash_key(CLOSURE_OBJ_ATTRS(closure_entry->val), make_string("name")); if(name_entry) { closure_name = obj_to_cstring(name_entry->val); } } // TODO: fix types printf("[Frame #%u] %s:%d:%d - %d:%d [in %s]\n", i, obj_to_cstring(file), (int) GET_INT(first_line), (int) GET_INT(first_column), (int) GET_INT(last_line), (int) GET_INT(last_column), closure_name); } else { printf("[Frame #%u] (no source location)\n", i); } } continue; } if(obj_is_of_type(ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)], vm->Exception)) { assert(IS_STRING(e->key)); printf("---8<--- %s - start ---8<---\n", obj_to_cstring(e->key)); print_exception(vm, ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]); printf("---8<--- %s - end ---8<---\n", obj_to_cstring(e->key)); continue; } if(IS_STRING(e->key)) { dump_titled(obj_to_cstring(e->key), ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]); } else { // Should not happen dump_titled("attribute key", e->key); dump_titled("attribute value", ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]); } } }
int main(int argc, char** argv) try { --argc; ++argv; switch (argc) { case 0: { Program program(std::cin); program.run(); break; } case 1: { std::ifstream file(argv[0]); if (!file.is_open()) throw std::runtime_error("bad input file"); Program program(file); program.run(); break; } default: throw std::runtime_error("usage: yarn [FILE]"); } } catch (const std::exception& e) { print_exception(e); return 1; }
static void print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen) { int err = 0, res; PyObject *cause, *context; if (seen != NULL) { /* Exception chaining */ PyObject *value_id = PyLong_FromVoidPtr(value); if (value_id == NULL || PySet_Add(seen, value_id) == -1) PyErr_Clear(); else if (PyExceptionInstance_Check(value)) { PyObject *check_id = NULL; cause = PyException_GetCause(value); context = PyException_GetContext(value); if (cause) { check_id = PyLong_FromVoidPtr(cause); if (check_id == NULL) { res = -1; } else { res = PySet_Contains(seen, check_id); Py_DECREF(check_id); } if (res == -1) PyErr_Clear(); if (res == 0) { print_exception_recursive( f, cause, seen); err |= PyFile_WriteString( cause_message, f); } } else if (context && !((PyBaseExceptionObject *)value)->suppress_context) { check_id = PyLong_FromVoidPtr(context); if (check_id == NULL) { res = -1; } else { res = PySet_Contains(seen, check_id); Py_DECREF(check_id); } if (res == -1) PyErr_Clear(); if (res == 0) { print_exception_recursive( f, context, seen); err |= PyFile_WriteString( context_message, f); } } Py_XDECREF(context); Py_XDECREF(cause); } Py_XDECREF(value_id); } print_exception(f, value); if (err != 0) PyErr_Clear(); }
void exception_print (struct ui_file *file, struct gdb_exception e) { if (e.reason < 0 && e.message != NULL) { print_flush (); print_exception (file, e); } }
void print_exception(const std::exception& e, int level = 0) { std::cerr << std::string(level, ' ') << "exception: " << e.what() << '\n'; try { std::rethrow_if_nested(e); } catch(const std::exception& e) { print_exception(e, level+1); } catch(...) {} }
void print_exception(const std::exception& e, const unsigned depth = 0) { for (unsigned i = 0; i < depth; ++i) std::cerr << " "; std::cerr << e.what() << '\n'; try { std::rethrow_if_nested(e); } catch (const std::exception& e) { print_exception(e, depth + 1); } catch (...) {} }
static int eval(const char *source, Scope *scope, bool debugMode) { wsky_ASTNode *node = parse(source, debugMode); if (!node) return 1; assert(node->type == wsky_ASTNodeType_SEQUENCE); ReturnValue rv = wsky_evalSequence((wsky_SequenceNode *)node, scope); wsky_ASTNode_delete(node); if (rv.exception) { print_exception(rv.exception); return 2; } rv = wsky_toString(rv.v); if (rv.exception) { print_exception(rv.exception); return 3; } wsky_String *string = (wsky_String *) rv.v.v.objectValue; printf("%s\n", string->string); return 0; }
static void print_any_exception (struct ui_file *file, const char *prefix, struct gdb_exception e) { if (e.reason < 0 && e.message != NULL) { target_terminal_ours (); wrap_here (""); /* Force out any buffered output. */ gdb_flush (gdb_stdout); annotate_error_begin (); /* Print the prefix. */ if (prefix != NULL && prefix[0] != '\0') fputs_filtered (prefix, file); print_exception (file, e); } }
void exception_fprintf (struct ui_file *file, struct gdb_exception e, const char *prefix, ...) { if (e.reason < 0 && e.message != NULL) { va_list args; print_flush (); /* Print the prefix. */ va_start (args, prefix); vfprintf_filtered (file, prefix, args); va_end (args); print_exception (file, e); } }
void error0(char* m, char* vv) { /* When there is nothing more to do than to exit or to go back into the debugger. */ static char*f="*** Error at Run Time ***: %s\n"; fprintf(SE_ERR,f,m); if (vv!=NULL) fprintf(SE_ERR,f,vv); #ifdef SE_EXCEPTIONS print_exception(); #endif #ifdef SE_SEDB sedb_break(se_dst,0); #else handle(SE_HANDLE_RUNTIME_ERROR, m); se_print_run_time_stack(); fprintf(SE_ERR,f,m); if (vv!=NULL) fprintf(SE_ERR,f,vv); exit(EXIT_FAILURE); #endif }
void print_exception(std::exception_ptr ep, const string& prefix, int level) { std::ostringstream ss; if (!prefix.empty()) ss << prefix << ": "; // print exception try { std::rethrow_exception(ep); } catch (const std::exception& e) { const boost::exception* be = boost::exception_detail::get_boost_exception(&e); if (be) { if (e.what() != string("Unknown exception")) ss << e.what() << endl; if (const char* const* api_function = boost::get_error_info<boost::errinfo_api_function>(*be)) ss << *api_function << ": "; if (const DWORD* errcode = boost::get_error_info<e_last_error>(*be)) ss << GetLastErrorString(*errcode) << endl; if (auto nt_status = boost::get_error_info<e_nt_status>(*be)) ss << GetNTStatusString(*nt_status) << endl; //ss << "\n" << boost::diagnostic_information_what(*be) << "\n"; if (optional<string> src = throw_location(*be)) ss << "at " << *src << endl; ss << diagnostic_information(*be); } else ss << e.what() << endl; } catch (...) { ss << "unkown exception" << endl; } cerr << std::regex_replace(ss.str(), std::regex("^"), string(level, ' ')); // print std or boost nested exception try { std::rethrow_exception(ep); } catch (const std::exception& e) { try { std::rethrow_if_nested(e); const boost::exception* be = boost::exception_detail::get_boost_exception(&e); if (be) { if (const boost::exception_ptr* nested = boost::get_error_info<boost::errinfo_nested_exception>(*be)) boost::rethrow_exception(*nested); } } catch (...) { print_exception(std::current_exception(), "caused by", level + 1); } } catch (...) {} }
int main(int argc, char *argv[]) { if ((argc == 2) && !strcmp(argv[1], "--list-devices")) return print_devices() ? EXIT_SUCCESS : EXIT_FAILURE; if ((argc == 3) && !strcmp(argv[1], "--use-device")) { try { cl::Device device; // The device is selected by the user if (!select_device(argv[2], device)) return EXIT_FAILURE; try { print_info("Initializing graphical user interface"); auto window = display::initialize("Voxel Renderer"); print_info("Selecting preferred interop interface"); interop::initialize(device, window->getSystemHandle()); print_info("Scheduler ready, interop is available"); print_info("Loading world from user-provided file"); print_warning("Not implemented yet"); World world; print_info("World ready"); try { display::run(window, world); display::finalize(window); } catch (const cl::Error &e) { print_exception("OpenCL runtime error", e); return EXIT_FAILURE; // Perhaps driver bug? } } catch (const cl::Error &e) { print_exception("OpenCL initialization failure", e); return EXIT_FAILURE; // Selected device unsupported? } } catch (const std::exception &e) { print_exception("A fatal error occurred", e); return EXIT_FAILURE; // Not an OpenCL error.. } catch (...) { print_error("Caught unhandled exception"); return EXIT_FAILURE; // Fatal error here.. } print_info("Exiting"); return EXIT_SUCCESS; } printf("Usage:\n\n\t%s %s [name]", argv[0], "--use-device"); printf( "\n\t%s %s\n", argv[0], "--list-devices"); printf("\nThis software requires OpenCL 1.2.\n"); return EXIT_FAILURE; // Argument parsing error }
std::ostream & operator<<(std::ostream & os, const CORBA::Exception &e) { print_exception(os, e); return os; }
int _ant_send_message(asm_t* self, uchar_t msg_id, uchar_t channel, const uchar_t data[], uchar_t data_size, ant_msg_t* response) { uchar_t msgbuffer[sizeof(ant_msg_t) + 1]; /* message + sync byte */ ant_msg_t *msg = (ant_msg_t*)(msgbuffer+1); uchar_t chksum, *p; size_t msg_size = (sizeof(msg->id) +sizeof(msg->size) +sizeof(msg->channel) +data_size); int i, error, retry=0; if (_keyboard_interrupted()) return MR_ABORTED; if (ant_is_recovering(self)) return MR_RECOVERING; /*@cstart(build message)*/ msgbuffer[0] = MESG_TX_SYNC; msg->size = data_size+1; /* +1 for channel */ msg->id = msg_id; msg->channel = channel; memcpy(msg->data, data, data_size); chksum = 0; for (i = 0, p = msgbuffer; i < (int)msg_size+1; i++, p++) chksum ^= *p; msg->data[data_size++] = chksum; msg->data[data_size++] = 0; msg->data[data_size] = 0; #if _DEBUG_LEVEL >= 1 print_log("#_ant_send_message: %s(%i) ", get_message_name(msg->id), (int)msg->channel); print_message_bytes(msg); print_log("-%u\n", (ushort_t)(ant_clock() & 0xFFFF)); #endif if (ant_is_waiting_for_response(self)) CHECK(MR_WRONG_STATE); /*@(build message)*/ _try_again: CHECK(_ant_write(self, msgbuffer, msg_size+4)); /* 4 == +sizeof(sync)+sizeof(checksum)+2*sizeof(0) */ error = _ant_wait_for_response(self, msg, response, 0); /*@cstart(time out handling)*/ if (error == MR_TIMEOUT && retry < 10 && msg_id != MESG_ACKNOWLEDGED_DATA_ID && msg_id != MESG_BURST_DATA_ID) { char zeros[15]; retry++; memset(zeros, 0, sizeof(zeros)); _ant_write(self, zeros, sizeof(zeros)); goto _try_again; } /*@(time out handling)*/ CHECK(error); BEGIN_EXCEPT; print_exception(); END_EXCEPT; return error; }
int main(int argc, char *argv[]) { int verbose=2; std::string srcFileName="-"; int maxTries=INT_MAX; std::string name="perfect"; //std::string writeCpp=""; std::string method="default"; int wV=0; unsigned maxHash=0; double maxTime=600; double maxMem=4000; double solveTime=0.0; std::string csvLogDst; urng.seed(time(0)); try { int ia = 1; while (ia < argc) { if (!strcmp(argv[ia], "--verbose")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --verbose"); verbose = atoi(argv[ia + 1]); ia += 2; } else if (!strcmp(argv[ia], "--input")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --input"); srcFileName = argv[ia + 1]; ia += 2; } else if (!strcmp(argv[ia], "--csv-log")) { if ((argc - ia) < 3) throw std::runtime_error("No argument to --csv-dst"); csvLogPrefix = argv[ia + 1]; csvLogDst = argv[ia + 2]; ia += 3; } else if (!strcmp(argv[ia], "--wa")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --wa"); wA = atoi(argv[ia + 1]); if (wA < 1) throw std::runtime_error("Can't have wa < 1"); if (wA > 12) throw std::runtime_error("wa > 12 is unexpectedly large (edit code if you are sure)."); ia += 2; } else if (!strcmp(argv[ia], "--wo")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --wo"); wO = atoi(argv[ia + 1]); if (wO < 1) throw std::runtime_error("Can't have wo < 1"); if (wO > 16) throw std::runtime_error("wo > 16 is unexpectedly large (edit code if you are sure)."); ia += 2; } else if (!strcmp(argv[ia], "--wv")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --wv"); wV = atoi(argv[ia + 1]); if (wV < 0) throw std::runtime_error("Can't have wv < 0"); ia += 2; } else if (!strcmp(argv[ia], "--wi")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --wi"); wI = atoi(argv[ia + 1]); if (wI < 1) throw std::runtime_error("Can't have wi < 1"); if (wI > 32) throw std::runtime_error("wo > 32 is unexpectedly large (edit code if you are sure)."); ia += 2; } else if (!strcmp(argv[ia], "--max-time")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --max-time"); maxTime = strtod(argv[ia + 1], 0); ia += 2; } else if (!strcmp(argv[ia], "--max-mem")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --max-mem"); maxMem = strtod(argv[ia + 1], 0); ia += 2; } else if (!strcmp(argv[ia], "--method")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --method"); method = argv[ia + 1]; ia += 2; } else if (!strcmp(argv[ia], "--max-hash")) { if ((argc - ia) < 2) throw std::runtime_error("No argument to --max-hash"); maxHash = atoi(argv[ia + 1]); ia += 2; } else if (!strcmp(argv[ia], "--minimal")) { if ((argc - ia) < 1) throw std::runtime_error("No argument to --minimal"); maxHash=UINT_MAX; ia += 1; /*} else if (!strcmp(argv[ia], "--write-cpp")) { if ((argc - ia) < 2) throw std::runtime_error("Not enough arguments to --write-cpp"); writeCpp = argv[ia + 1]; ia += 2;*/ } else { throw std::runtime_error(std::string("Didn't understand argument ") + argv[ia]); } } if(!csvLogDst.empty()){ if(csvLogDst=="-"){ pCsvDst = &std::cout; }else{ csvLogFile.open(csvLogDst); if(!csvLogFile.is_open()){ throw std::runtime_error("Couldn't open csv log destination."); } pCsvDst=&csvLogFile; } } if(verbose>0){ fprintf(stderr, "Setting limits of %f seconds CPU time and %f MB of memory.\n", maxTime, maxMem); setTimeAndSpaceLimit(maxTime, maxMem); } if (method == "default") { if (verbose > 0) { method = "minisat_weighted"; std::cerr << "Selecting default method = " << method << "\n"; } } if (verbose > 0) { std::cerr << "Loading input from " << (srcFileName == "-" ? "<stdin>" : srcFileName) << ".\n"; } key_value_set problem; if (srcFileName == "-") { problem = parse_key_value_set(std::cin); } else { std::ifstream srcFile(srcFileName); if (!srcFile.is_open()) throw std::runtime_error("Couldn't open source file " + srcFileName); problem = parse_key_value_set(srcFile); } if (verbose > 1) { std::cerr << "Input key value pairs:\n"; problem.print(std::cerr, " "); std::cerr << "nKeys = " << problem.size() << "\n"; std::cerr << "wKey = " << problem.getKeyWidth() << "\n"; std::cerr << "wValue = " << problem.getValueWidth() << "\n"; } if(maxHash==UINT_MAX){ if(verbose>0){ std::cerr << " Building minimal hash.\n"; } problem.setMaxHash(maxHash); }else if(maxHash>0){ if(verbose>0){ std::cerr << " Setting maxHash="<<maxHash<<"\n"; } problem.setMaxHash(maxHash); } if (wI == -1) { wI = problem.getKeyWidth(); if (verbose > 0) { std::cerr << "Auto-selecting wI = " << wI << "\n"; } } else { if (wI < (int) problem.getKeyWidth()) { throw std::runtime_error("Specified key width does not cover all keys."); } } if (wO == -1) { unsigned nKeys = problem.keys_size(); wO = (unsigned) ceil(log(nKeys) / log(2.0)); if (verbose > 0) { std::cerr << "Auto-selecting wO = " << wO << " based on nKeys = " << nKeys << "\n"; } } else { if ((1u << wO) < problem.keys_size()) { throw std::runtime_error("Specified output width cannot span number of keys."); } } if (verbose > 0) { std::cerr << "Group load factor is 2^wO / nKeyGroups = " << problem.keys_size() << " / " << (1 << wO) << " = " << problem.keys_size() / (double) (1 << wO) << "\n"; std::cerr << "True load factor is 2^wO / nKeysDistinct = " << problem.keys_size_distinct() << " / " << (1 << wO) << " = " << problem.keys_size_distinct() / (double) (1 << wO) << "\n"; } BitHash result; startTime=cpuTime(); tries = 1; bool success = false; while (tries < maxTries) { if (verbose > 0) { std::cerr << " Attempt " << tries << "\n"; } if (verbose > 0) { std::cerr << " Creating bit hash...\n"; } auto bh = (method == "minisat_weighted") ? makeWeightedBitHash(urng, problem, wO, wI, wA) : makeBitHash( urng, wO, wI, wA); if (verbose > 0) { std::cerr << " Converting to CNF...\n"; } cnf_problem prob; to_cnf(bh, problem.keys(), prob, problem.getMaxHash()); if (verbose > 0) { std::cerr << " Solving problem with minisat...\n"; } auto sol = minisat_solve(prob, verbose); if (sol.empty()) { if (verbose > 0) { std::cerr << " No solution\n"; } } else { if (verbose > 0) { std::cerr << " Checking raw...\n"; } if (verbose > 0) { std::cerr << " Substituting...\n"; } auto back = substitute(bh, prob, sol); if (verbose > 0) { std::cerr << " checking...\n"; } if (!back.is_solution(problem)) throw std::runtime_error("Failed post substitution check."); success = true; result = back; break; } tries++; } double finishTime=cpuTime(); solveTime=finishTime-startTime; if(pCsvDst){ (*pCsvDst)<<csvLogPrefix<<", "<<wO<<", "<<wI<<", "<<wA<<", "<<solveTime<<", "<<tries<<", "<<(success?"Success":"OutOfAttempts")<<"\n"; } if (!success) { if(pCsvDst) { exit(0); }else{ exit(1); } } if(verbose>1){ for(const auto &kv : problem){ auto key = *kv.first.variants_begin(); std::cerr<<" "<<key<<" -> "<<result(key)<<"\n"; } } // Print the two back to back result.print(std::cout); problem.print(std::cout); }catch(Minisat::OutOfMemoryException &e){ if(pCsvDst){ (*pCsvDst)<<csvLogPrefix<<", "<<wO<<", "<<wI<<", "<<wA<<", "<<solveTime<<", "<<tries<<", "<<"OutOfMemory"<<"\n"; pCsvDst->flush(); } std::cerr<<"Memory limit exceeded."; _exit(pCsvDst ? 0 : 1); }catch(std::exception &e){ if(pCsvDst){ (*pCsvDst)<<csvLogPrefix<<", "<<wO<<", "<<wI<<", "<<wA<<", "<<solveTime<<", "<<tries<<", "<<"Exception"<<"\n"; pCsvDst->flush(); } std::cerr<<"Caught exception : "; print_exception(e); std::cerr.flush(); _exit(pCsvDst ? 0 : 1); } return 0; }