void RemoteProxyClient::interrupt() { boost::system::error_code ec; DOUT(this->dinfo()); if ( this->m_local_socket.is_open() ) { TRY_CATCH( this->m_local_socket.shutdown( boost::asio::socket_base::shutdown_both, ec ) ); TRY_CATCH( this->m_local_socket.close(ec) ); } if ( this->m_remote_socket.lowest_layer().is_open() ) { this->m_remote_socket.lowest_layer().cancel(ec); } this->m_local_connected = this->m_remote_connected = false; }
static PyObject * infpy_threads (PyObject *self, PyObject *args) { int i; struct threadlist_entry *entry; inferior_object *inf_obj = (inferior_object *) self; PyObject *tuple; volatile struct gdb_exception except; INFPY_REQUIRE_VALID (inf_obj); TRY_CATCH (except, RETURN_MASK_ALL) update_thread_list (); GDB_PY_HANDLE_EXCEPTION (except); tuple = PyTuple_New (inf_obj->nthreads); if (!tuple) return NULL; for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads; i++, entry = entry->next) { Py_INCREF (entry->thread_obj); PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj); } return tuple; }
static void mi_breakpoint_modified (struct breakpoint *b) { struct mi_interp *mi = top_level_interpreter_data (); struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ()); volatile struct gdb_exception e; if (mi_suppress_notification.breakpoint) return; if (b->number <= 0) return; target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "breakpoint-modified"); /* We want the output from gdb_breakpoint_query to go to mi->event_channel. One approach would be to just call gdb_breakpoint_query, and then use mi_out_put to send the current content of mi_outout into mi->event_channel. However, that will break if anything is output to mi_uiout prior to calling the breakpoint_created notifications. So, we use ui_out_redirect. */ ui_out_redirect (mi_uiout, mi->event_channel); TRY_CATCH (e, RETURN_MASK_ERROR) gdb_breakpoint_query (mi_uiout, b->number, NULL); ui_out_redirect (mi_uiout, NULL); gdb_flush (mi->event_channel); }
static void record_btrace_enable_warn (struct thread_info *tp) { volatile struct gdb_exception error; TRY_CATCH (error, RETURN_MASK_ERROR) btrace_enable (tp); if (error.message != NULL) warning ("%s", error.message); }
static char * gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, char *prompt) { int n; char *p = NULL, *p_start, *p_end, *q; volatile struct gdb_exception except; TRY_CATCH (except, RETURN_MASK_ALL) p = command_line_input (prompt, 0, "python"); /* Detect user interrupt (Ctrl-C). */ if (except.reason == RETURN_QUIT) return NULL; /* Handle errors by raising Python exceptions. */ if (except.reason < 0) { /* The thread state is nulled during gdbpy_readline_wrapper, with the original value saved in the following undocumented variable (see Python's Parser/myreadline.c and Modules/readline.c). */ PyEval_RestoreThread (_PyOS_ReadlineTState); gdbpy_convert_exception (except); PyEval_SaveThread (); return NULL; } /* Detect EOF (Ctrl-D). */ if (p == NULL) { q = PyMem_Malloc (1); if (q != NULL) q[0] = '\0'; return q; } n = strlen (p); /* Copy the line to Python and return. */ q = PyMem_Malloc (n + 2); if (q != NULL) { strncpy (q, p, n); q[n] = '\n'; q[n + 1] = '\0'; } return q; }
void write_gcore_file (bfd *obfd) { volatile struct gdb_exception except; target_prepare_to_generate_core (); TRY_CATCH (except, RETURN_MASK_ALL) write_gcore_file_1 (obfd); target_done_generating_core (); if (except.reason < 0) throw_exception (except); }
errorCode initSchema(EXIPSchema* schema, InitSchemaType initializationType) { errorCode tmp_err_code = UNEXPECTED_ERROR; TRY(initAllocList(&schema->memList)); schema->staticGrCount = 0; SET_CONTENT_INDEX(schema->docGrammar.props, 0); schema->docGrammar.count = 0; schema->docGrammar.props = 0; schema->docGrammar.rule = NULL; schema->simpleTypeTable.count = 0; schema->simpleTypeTable.sType = NULL; schema->grammarTable.count = 0; schema->grammarTable.grammar = NULL; schema->enumTable.count = 0; schema->enumTable.enumDef = NULL; /* Create and initialize initial string table entries */ TRY_CATCH(createDynArray(&schema->uriTable.dynArray, sizeof(UriEntry), DEFAULT_URI_ENTRIES_NUMBER), freeAllocList(&schema->memList)); TRY_CATCH(createUriTableEntries(&schema->uriTable, initializationType != INIT_SCHEMA_SCHEMA_LESS_MODE), freeAllocList(&schema->memList)); if(initializationType == INIT_SCHEMA_SCHEMA_ENABLED) { /* Create and initialize enumDef table */ TRY_CATCH(createDynArray(&schema->enumTable.dynArray, sizeof(EnumDefinition), DEFAULT_ENUM_TABLE), freeAllocList(&schema->memList)); } /* Create the schema grammar table */ TRY_CATCH(createDynArray(&schema->grammarTable.dynArray, sizeof(EXIGrammar), DEFAULT_GRAMMAR_TABLE), freeAllocList(&schema->memList)); if(initializationType != INIT_SCHEMA_SCHEMA_LESS_MODE) { /* Create and initialize simple type table */ TRY_CATCH(createDynArray(&schema->simpleTypeTable.dynArray, sizeof(SimpleType), DEFAULT_SIMPLE_GRAMMAR_TABLE), freeAllocList(&schema->memList)); TRY_CATCH(createBuiltInTypesDefinitions(&schema->simpleTypeTable, &schema->memList), freeAllocList(&schema->memList)); // Must be done after createBuiltInTypesDefinitions() TRY_CATCH(generateBuiltInTypesGrammars(schema), freeAllocList(&schema->memList)); schema->staticGrCount = SIMPLE_TYPE_COUNT; } return tmp_err_code; }
errorCode decodeBinary(EXIStream* strm, char** binary_val, Index* nbytes) { errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR; UnsignedInteger length = 0; unsigned int int_val = 0; UnsignedInteger i = 0; DEBUG_MSG(INFO, DEBUG_STREAM_IO, (">> (binary)")); TRY(decodeUnsignedInteger(strm, &length)); *nbytes = (Index) length; (*binary_val) = (char*) EXIP_MALLOC(length); // This memory should be manually freed after the content handler is invoked if((*binary_val) == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; for(i = 0; i < length; i++) { TRY_CATCH(readBits(strm, 8, &int_val), EXIP_MFREE(*binary_val)); (*binary_val)[i]=(char) int_val; } return EXIP_OK; }
static int record_btrace_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt) { volatile struct gdb_exception except; int old, ret; /* Removing breakpoints requires accessing memory. Allow it for the duration of this function. */ old = record_btrace_allow_memory_access; record_btrace_allow_memory_access = 1; ret = 0; TRY_CATCH (except, RETURN_MASK_ALL) ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch, bp_tgt); record_btrace_allow_memory_access = old; if (except.reason < 0) throw_exception (except); return ret; }
errorCode decodeHeader(EXIStream* strm, boolean outOfBandOpts) { errorCode tmp_err_code = UNEXPECTED_ERROR; unsigned int bits_val = 0; boolean boolVal = FALSE; DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">Start EXI header decoding\n")); TRY(readBits(strm, 2, &bits_val)); if(bits_val == 2) // The header Distinguishing Bits i.e. no EXI Cookie { strm->header.has_cookie = 0; DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI cookie detected\n")); } else if(bits_val == 0)// ASCII code for $ = 00100100 (36) { TRY(readBits(strm, 6, &bits_val)); if(bits_val != 36) return INVALID_EXI_HEADER; TRY(readBits(strm, 8, &bits_val)); if(bits_val != 69) // ASCII code for E = 01000101 (69) return INVALID_EXI_HEADER; TRY(readBits(strm, 8, &bits_val)); if(bits_val != 88) // ASCII code for X = 01011000 (88) return INVALID_EXI_HEADER; TRY(readBits(strm, 8, &bits_val)); if(bits_val != 73) // ASCII code for I = 01001001 (73) return INVALID_EXI_HEADER; strm->header.has_cookie = 1; DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI cookie detected\n")); TRY(readBits(strm, 2, &bits_val)); if(bits_val != 2) // The header Distinguishing Bits are required return INVALID_EXI_HEADER; } else { return INVALID_EXI_HEADER; } // Read the Presence Bit for EXI Options TRY(readNextBit(strm, &boolVal)); if(boolVal == TRUE) // There are EXI options { strm->header.has_options = TRUE; // validation checks. If the options are included then // they cannot be set by an out-of-band mechanism. // If out-of-band options are set - // rise a warning and overwrite them. // Only the options from the header will be used if(outOfBandOpts == TRUE) { DEBUG_MSG(WARNING, DEBUG_CONTENT_IO, (">Ignored out-of-band set EXI options\n")); makeDefaultOpts(&strm->header.opts); } } else // Out-of-band set EXI options { DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI options field in the header\n")); strm->header.has_options = FALSE; if(outOfBandOpts == FALSE) { DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">No EXI options in the header and no out-of-band options specified. \n")); return HEADER_OPTIONS_MISMATCH; } } // Read the Version type TRY(readNextBit(strm, &boolVal)); strm->header.is_preview_version = boolVal; strm->header.version_number = 1; do { TRY(readBits(strm, 4, &bits_val)); strm->header.version_number += bits_val; if(bits_val < 15) break; } while(1); DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI version: %d\n", strm->header.version_number)); if(strm->header.has_options == 1) { Parser optionsParser; struct ops_AppData appD; TRY(initParser(&optionsParser, strm->buffer, &appD)); optionsParser.strm.context.bitPointer = strm->context.bitPointer; optionsParser.strm.context.bufferIndx = strm->context.bufferIndx; optionsParser.strm.gStack = NULL; makeDefaultOpts(&optionsParser.strm.header.opts); SET_STRICT(optionsParser.strm.header.opts.enumOpt); optionsParser.handler.fatalError = ops_fatalError; optionsParser.handler.error = ops_fatalError; optionsParser.handler.startDocument = ops_startDocument; optionsParser.handler.endDocument = ops_endDocument; optionsParser.handler.startElement = ops_startElement; optionsParser.handler.attribute = ops_attribute; optionsParser.handler.stringData = ops_stringData; optionsParser.handler.endElement = ops_endElement; optionsParser.handler.intData = ops_intData; optionsParser.handler.booleanData = ops_boolData; appD.o_strm = &optionsParser.strm; appD.parsed_ops = &strm->header.opts; appD.prevElementLnID = 0; appD.prevElementUriID = 0; appD.permanentAllocList = &strm->memList; TRY_CATCH(setSchema(&optionsParser, (EXIPSchema*) &ops_schema), destroyParser(&optionsParser)); TRY_CATCH(createValueTable(&optionsParser.strm.valueTable), destroyParser(&optionsParser)); while(tmp_err_code == ERR_OK) { tmp_err_code = parseNext(&optionsParser); } destroyParser(&optionsParser); if(tmp_err_code != PARSING_COMPLETE) return tmp_err_code; strm->buffer.bufContent = optionsParser.strm.buffer.bufContent; strm->context.bitPointer = optionsParser.strm.context.bitPointer; strm->context.bufferIndx = optionsParser.strm.context.bufferIndx; if(WITH_COMPRESSION(strm->header.opts.enumOpt) || GET_ALIGNMENT(strm->header.opts.enumOpt) != BIT_PACKED) { // Padding bits if(strm->context.bitPointer != 0) { strm->context.bitPointer = 0; strm->context.bufferIndx += 1; } } } return checkOptionValues(&strm->header.opts); }
int RemoteProxyClient::test_local_connection(const std::string& name, const std::vector<LocalEndpoint> &_local_ep) { int result = 500; try { this->m_local_ep = _local_ep; for (auto rep : this->m_host.m_remote_ep) { if (rep.m_name == name) { this->m_endpoint = rep; break; } } DOUT(this->dinfo() << "Test host, found remote connection: " << this->m_endpoint.m_name << " is connected locally? " << this->m_local_connected); if (this->m_local_connected) { return 429; } this->m_local_connected = false; std::vector<int> indexes(this->m_local_ep.size()); for (int index = 0; index < indexes.size(); index++) { indexes[index] = index; } std::shuffle(std::begin(indexes), std::end(indexes), std::default_random_engine(static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count()))); for (int i = 0; i < indexes.size(); i++) { DOUT(this->dinfo() << "Test Host Random i: " << i << " index " << indexes[i] << " size: " << indexes.size()); } std::string ep; for (int index = 0; index < this->m_local_ep.size(); index++) { int proxy_index = indexes[index]; ep = this->m_local_ep[proxy_index].m_hostname + ":" + mylib::to_string(this->m_local_ep[proxy_index].m_port); try { this->dolog(this->dinfo() + "Test Host Performing local connection to: " + ep ); boost::asio::sockect_connect(this->m_local_socket, this->m_io_service, this->m_local_ep[proxy_index].m_hostname, this->m_local_ep[proxy_index].m_port); this->m_local_connected = true; break; } catch( std::exception &exc ) { DOUT(this->dinfo() << " Failed connection to: " << ep << " " << exc.what() ); } } if (!this->m_local_connected) { return 422; } try { this->dolog(this->dinfo() + "Performing logon procedure to " + ep); if (this->m_host.m_plugin.connect_handler(this->m_local_socket, this->m_endpoint)) { result = 200; this->dolog(this->dinfo() + "Test Host Completed successfully " + ep); } } catch(std::exception& exc) { result = 401; } this->dolog(this->dinfo() + "Test Host done test logon procedure to " + ep); this->m_local_connected = false; if (this->m_local_socket.is_open()) { boost::system::error_code ec; TRY_CATCH(this->m_local_socket.shutdown(boost::asio::socket_base::shutdown_both, ec)); TRY_CATCH(this->m_local_socket.close(ec)); } } catch(boost::system::system_error &boost_error) { DOUT(this->dinfo() << "Test Host Boost or system error"); result = 500; } catch(std::exception &exc) { this->dolog(this->dinfo() + exc.what()); result = 500; } return result; }