static SCM gdbscm_register_breakpoint_x (SCM self) { breakpoint_smob *bp_smob = bpscm_get_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); volatile struct gdb_exception except; /* We only support registering breakpoints created with make-breakpoint. */ if (!bp_smob->is_scheme_bkpt) scm_misc_error (FUNC_NAME, _("not a Scheme breakpoint"), SCM_EOL); if (bpscm_is_valid (bp_smob)) scm_misc_error (FUNC_NAME, _("breakpoint is already registered"), SCM_EOL); pending_breakpoint_scm = self; TRY_CATCH (except, RETURN_MASK_ALL) { char *location = bp_smob->spec.location; int internal = bp_smob->spec.is_internal; switch (bp_smob->spec.type) { case bp_breakpoint: { create_breakpoint (get_current_arch (), location, NULL, -1, NULL, 0, 0, bp_breakpoint, 0, AUTO_BOOLEAN_TRUE, &bkpt_breakpoint_ops, 0, 1, internal, 0); break; } case bp_watchpoint: { enum target_hw_bp_type access_type = bp_smob->spec.access_type; if (access_type == hw_write) watch_command_wrapper (location, 0, internal); else if (access_type == hw_access) awatch_command_wrapper (location, 0, internal); else if (access_type == hw_read) rwatch_command_wrapper (location, 0, internal); else gdb_assert_not_reached ("invalid access type"); break; } default: gdb_assert_not_reached ("invalid breakpoint type"); } }
void event_location_deleter::operator() (event_location *location) const { if (location != NULL) { xfree (EL_STRING (location)); switch (EL_TYPE (location)) { case LINESPEC_LOCATION: xfree (EL_LINESPEC (location)); break; case ADDRESS_LOCATION: /* Nothing to do. */ break; case EXPLICIT_LOCATION: xfree (EL_EXPLICIT (location)->source_filename); xfree (EL_EXPLICIT (location)->function_name); xfree (EL_EXPLICIT (location)->label_name); break; case PROBE_LOCATION: xfree (EL_PROBE (location)); break; default: gdb_assert_not_reached ("unknown event location type"); } xfree (location); } }
static PyObject * make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind) { switch (kind) { case iter_items: { gdbpy_ref<> key (field_name (type, i)); if (key == NULL) return NULL; gdbpy_ref<> value (convert_field (type, i)); if (value == NULL) return NULL; gdbpy_ref<> item (PyTuple_New (2)); if (item == NULL) return NULL; PyTuple_SET_ITEM (item.get (), 0, key.release ()); PyTuple_SET_ITEM (item.get (), 1, value.release ()); return item.release (); } case iter_keys: return field_name (type, i); case iter_values: return convert_field (type, i); } gdb_assert_not_reached ("invalid gdbpy_iter_kind"); }
void throw_exception (struct gdb_exception exception) { prepare_to_throw_exception (); do_cleanups (all_cleanups ()); #if GDB_XCPT == GDB_XCPT_SJMP /* Jump to the containing catch_errors() call, communicating REASON to that call via setjmp's return value. Note that REASON can't be zero, by definition in defs.h. */ exceptions_state_mc (CATCH_THROWING); current_catcher->exception = exception; SIGLONGJMP (current_catcher->buf, exception.reason); #else if (exception.reason == RETURN_QUIT) { gdb_exception_RETURN_MASK_QUIT ex; gdb_exception_sliced_copy (&ex, &exception); throw ex; } else if (exception.reason == RETURN_ERROR) { gdb_exception_RETURN_MASK_ERROR ex; gdb_exception_sliced_copy (&ex, &exception); throw ex; } else gdb_assert_not_reached ("invalid return reason"); #endif }
static DWORD64 win32_get_current_dr (int dr) { win32_thread_info *th = inferior_target_data (current_thread); win32_require_context (th); #define RET_DR(DR) \ case DR: \ return th->context.Dr ## DR switch (dr) { RET_DR (0); RET_DR (1); RET_DR (2); RET_DR (3); RET_DR (6); RET_DR (7); } #undef RET_DR gdb_assert_not_reached ("unhandled dr"); }
int event_location_empty_p (const struct event_location *location) { switch (EL_TYPE (location)) { case LINESPEC_LOCATION: /* Linespecs are never "empty." (NULL is a valid linespec) */ return 0; case ADDRESS_LOCATION: return 0; case EXPLICIT_LOCATION: return (EL_EXPLICIT (location) == NULL || (EL_EXPLICIT (location)->source_filename == NULL && EL_EXPLICIT (location)->function_name == NULL && EL_EXPLICIT (location)->label_name == NULL && (EL_EXPLICIT (location)->line_offset.sign == LINE_OFFSET_UNKNOWN))); case PROBE_LOCATION: return EL_PROBE (location) == NULL; default: gdb_assert_not_reached ("unknown event location type"); } }
void gdbscm_throw (SCM exception) { scm_throw (gdbscm_exception_key (exception), gdbscm_exception_args (exception)); gdb_assert_not_reached ("scm_throw returned"); }
const char * event_location_to_string (struct event_location *location) { if (EL_STRING (location) == NULL) { switch (EL_TYPE (location)) { case LINESPEC_LOCATION: if (EL_LINESPEC (location) != NULL) EL_STRING (location) = xstrdup (EL_LINESPEC (location)); break; case ADDRESS_LOCATION: EL_STRING (location) = xstrprintf ("*%s", core_addr_to_string (EL_ADDRESS (location))); break; case EXPLICIT_LOCATION: EL_STRING (location) = explicit_location_to_string (EL_EXPLICIT (location)); break; case PROBE_LOCATION: EL_STRING (location) = xstrdup (EL_PROBE (location)); break; default: gdb_assert_not_reached ("unknown event location type"); } } return EL_STRING (location); }
int gdb_pipe_cloexec (int filedes[2]) { int result; #ifdef HAVE_PIPE2 result = pipe2 (filedes, O_CLOEXEC); if (result != -1) { maybe_mark_cloexec (filedes[0]); maybe_mark_cloexec (filedes[1]); } #else #ifdef HAVE_PIPE result = pipe (filedes); if (result != -1) { mark_cloexec (filedes[0]); mark_cloexec (filedes[1]); } #else /* HAVE_PIPE */ gdb_assert_not_reached (_("pipe not available on this host")); #endif /* HAVE_PIPE */ #endif /* HAVE_PIPE2 */ return result; }
struct regcache * init_register_cache (struct regcache *regcache, const struct target_desc *tdesc, unsigned char *regbuf) { if (regbuf == NULL) { #ifndef IN_PROCESS_AGENT /* Make sure to zero-initialize the register cache when it is created, in case there are registers the target never fetches. This way they'll read as zero instead of garbage. */ regcache->tdesc = tdesc; regcache->registers = xcalloc (1, tdesc->registers_size); regcache->registers_owned = 1; regcache->register_status = xcalloc (1, tdesc->num_registers); gdb_assert (REG_UNAVAILABLE == 0); #else gdb_assert_not_reached ("can't allocate memory from the heap"); #endif } else { regcache->tdesc = tdesc; regcache->registers = regbuf; regcache->registers_owned = 0; #ifndef IN_PROCESS_AGENT regcache->register_status = NULL; #endif } regcache->registers_valid = 0; return regcache; }
char * apply_ext_lang_type_printers (struct ext_lang_type_printers *printers, struct type *type) { int i; const struct extension_language_defn *extlang; ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) { char *result = NULL; enum ext_lang_rc rc; if (extlang->ops->apply_type_printers == NULL) continue; rc = extlang->ops->apply_type_printers (extlang, printers, type, &result); switch (rc) { case EXT_LANG_RC_OK: gdb_assert (result != NULL); return result; case EXT_LANG_RC_ERROR: return NULL; case EXT_LANG_RC_NOP: break; default: gdb_assert_not_reached ("bad return from apply_type_printers"); } }
static CORE_ADDR tic6x_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR start_pc, const CORE_ADDR current_pc, struct tic6x_unwind_cache *cache, struct frame_info *this_frame) { unsigned long inst; unsigned int src_reg, base_reg, dst_reg; int i; CORE_ADDR pc = start_pc; CORE_ADDR return_pc = start_pc; int frame_base_offset_to_sp = 0; /* Counter of non-stw instructions after first insn ` sub sp, xxx, sp'. */ int non_stw_insn_counter = 0; if (start_pc >= current_pc) return_pc = current_pc; cache->base = 0; /* The landmarks in prologue is one or two SUB instructions to SP. Instructions on setting up dsbt are in the last part of prologue, if needed. In maxim, prologue can be divided to three parts by two `sub sp, xx, sp' insns. */ /* Step 1: Look for the 1st and 2nd insn `sub sp, xx, sp', in which, the 2nd one is optional. */ while (pc < current_pc) { unsigned long inst = tic6x_fetch_instruction (gdbarch, pc); if ((inst & 0x1ffc) == 0x1dc0 || (inst & 0x1ffc) == 0x1bc0 || (inst & 0x0ffc) == 0x9c0) { /* SUBAW/SUBAH/SUB, and src1 is ucst 5. */ unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f, INST_S_BIT (inst), 0); unsigned int dst = tic6x_register_number ((inst >> 23) & 0x1f, INST_S_BIT (inst), 0); if (src2 == TIC6X_SP_REGNUM && dst == TIC6X_SP_REGNUM) { /* Extract const from insn SUBAW/SUBAH/SUB, and translate it to offset. The constant offset is decoded in bit 13-17 in all these three kinds of instructions. */ unsigned int ucst5 = (inst >> 13) & 0x1f; if ((inst & 0x1ffc) == 0x1dc0) /* SUBAW */ frame_base_offset_to_sp += ucst5 << 2; else if ((inst & 0x1ffc) == 0x1bc0) /* SUBAH */ frame_base_offset_to_sp += ucst5 << 1; else if ((inst & 0x0ffc) == 0x9c0) /* SUB */ frame_base_offset_to_sp += ucst5; else gdb_assert_not_reached ("unexpected instruction"); return_pc = pc + 4; } }
static SCM vlscm_unop (enum valscm_unary_opcode opcode, SCM x, const char *func_name) { struct gdbarch *gdbarch = get_current_arch (); const struct language_defn *language = current_language; struct value *arg1; SCM result = SCM_BOOL_F; struct value *res_val = NULL; SCM except_scm; struct cleanup *cleanups; cleanups = make_cleanup_value_free_to_mark (value_mark ()); arg1 = vlscm_convert_value_from_scheme (func_name, SCM_ARG1, x, &except_scm, gdbarch, language); if (arg1 == NULL) { do_cleanups (cleanups); gdbscm_throw (except_scm); } TRY { switch (opcode) { case VALSCM_NOT: /* Alas gdb and guile use the opposite meaning for "logical not". */ { struct type *type = language_bool_type (language, gdbarch); res_val = value_from_longest (type, (LONGEST) value_logical_not (arg1)); } break; case VALSCM_NEG: res_val = value_neg (arg1); break; case VALSCM_NOP: /* Seemingly a no-op, but if X was a Scheme value it is now a <gdb:value> object. */ res_val = arg1; break; case VALSCM_ABS: if (value_less (arg1, value_zero (value_type (arg1), not_lval))) res_val = value_neg (arg1); else res_val = arg1; break; case VALSCM_LOGNOT: res_val = value_complement (arg1); break; default: gdb_assert_not_reached ("unsupported operation"); } } CATCH (except, RETURN_MASK_ALL) { GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); }
static struct tdesc_type * tdesc_predefined_type (enum tdesc_type_kind kind) { for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++) if (tdesc_predefined_types[ix].kind == kind) return &tdesc_predefined_types[ix]; gdb_assert_not_reached ("bad predefined tdesc type"); }
struct block_symbol d_lookup_nested_symbol (struct type *parent_type, const char *nested_name, const struct block *block) { /* type_name_no_tag_required provides better error reporting using the original type. */ struct type *saved_parent_type = parent_type; parent_type = check_typedef (parent_type); switch (TYPE_CODE (parent_type)) { case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: case TYPE_CODE_ENUM: case TYPE_CODE_MODULE: { int size; const char *parent_name = type_name_no_tag_or_error (saved_parent_type); struct block_symbol sym = d_lookup_symbol_in_module (parent_name, nested_name, block, VAR_DOMAIN, 0); char *concatenated_name; if (sym.symbol != NULL) return sym; /* Now search all static file-level symbols. We have to do this for things like typedefs in the class. We do not try to guess any imported module as even the fully specified module search is already not D compliant and more assumptions could make it too magic. */ size = strlen (parent_name) + strlen (nested_name) + 2; concatenated_name = (char *) alloca (size); xsnprintf (concatenated_name, size, "%s.%s", parent_name, nested_name); sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN); if (sym.symbol != NULL) return sym; /* If no matching symbols were found, try searching any base classes. */ return find_symbol_in_baseclass (parent_type, nested_name, block); } case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: return null_block_symbol; default: gdb_assert_not_reached ("called with non-aggregate type."); } }
void throw_exception (gdb_exception &&exception) { if (exception.reason == RETURN_QUIT) throw gdb_exception_quit (std::move (exception)); else if (exception.reason == RETURN_ERROR) throw gdb_exception_error (std::move (exception)); else gdb_assert_not_reached ("invalid return reason"); }
static int color_number (const char *color) { for (int i = 0; i < ARRAY_SIZE (cli_colors); ++i) { if (color == cli_colors[i]) return i - 1; } gdb_assert_not_reached ("color not found"); }
throw_it (enum return_reason reason, enum errors error, const char *fmt, va_list ap) { if (reason == RETURN_QUIT) throw gdb_exception_quit (fmt, ap); else if (reason == RETURN_ERROR) throw gdb_exception_error (error, fmt, ap); else gdb_assert_not_reached ("invalid return reason"); }
/* If the text starting at P going up to (but not including) END starts with a character constant, set *TOK to point to that character constant, and return 1. Otherwise, return zero. Signal an error if it contains a malformed or incomplete character constant. */ static int get_character_constant (struct macro_buffer *tok, char *p, char *end) { /* ISO/IEC 9899:1999 (E) Section 6.4.4.4 paragraph 1 But of course, what really matters is that we handle it the same way GDB's C/C++ lexer does. So we call parse_escape in utils.c to handle escape sequences. */ if ((p + 1 <= end && *p == '\'') || (p + 2 <= end && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U') && p[1] == '\'')) { char *tok_start = p; int char_count = 0; if (*p == '\'') p++; else if (*p == 'L' || *p == 'u' || *p == 'U') p += 2; else gdb_assert_not_reached ("unexpected character constant"); for (;;) { if (p >= end) error (_("Unmatched single quote.")); else if (*p == '\'') { if (!char_count) error (_("A character constant must contain at least one " "character.")); p++; break; } else if (*p == '\\') { const char *s, *o; s = o = ++p; char_count += c_parse_escape (&s, NULL); p += s - o; } else { p++; char_count++; } } set_token (tok, tok_start, p); return 1; } else return 0; }
void gcc_convert_symbol (void *datum, struct gcc_c_context *gcc_context, enum gcc_c_oracle_request request, const char *identifier) { struct compile_c_instance *context = datum; domain_enum domain; int found = 0; switch (request) { case GCC_C_ORACLE_SYMBOL: domain = VAR_DOMAIN; break; case GCC_C_ORACLE_TAG: domain = STRUCT_DOMAIN; break; case GCC_C_ORACLE_LABEL: domain = LABEL_DOMAIN; break; default: gdb_assert_not_reached ("Unrecognized oracle request."); } /* We can't allow exceptions to escape out of this callback. Safest is to simply emit a gcc error. */ TRY { struct symbol *sym; sym = lookup_symbol (identifier, context->base.block, domain, NULL); if (sym != NULL) { convert_symbol_sym (context, identifier, sym, domain); found = 1; } else if (domain == VAR_DOMAIN) { struct bound_minimal_symbol bmsym; bmsym = lookup_minimal_symbol (identifier, NULL, NULL); if (bmsym.minsym != NULL) { convert_symbol_bmsym (context, bmsym); found = 1; } } } CATCH (e, RETURN_MASK_ALL) { C_CTX (context)->c_ops->error (C_CTX (context), e.message); }
static SCM gdbscm_percent_exception_print_style (void) { if (gdbscm_print_excp == gdbscm_print_excp_none) return none_symbol; if (gdbscm_print_excp == gdbscm_print_excp_message) return message_symbol; if (gdbscm_print_excp == gdbscm_print_excp_full) return full_symbol; gdb_assert_not_reached ("bad value for \"guile print-stack\""); }
event_location_up copy_event_location (const struct event_location *src) { struct event_location *dst; dst = XCNEW (struct event_location); EL_TYPE (dst) = EL_TYPE (src); if (EL_STRING (src) != NULL) EL_STRING (dst) = xstrdup (EL_STRING (src)); switch (EL_TYPE (src)) { case LINESPEC_LOCATION: EL_LINESPEC (dst)->match_type = EL_LINESPEC (src)->match_type; if (EL_LINESPEC (src)->spec_string != NULL) EL_LINESPEC (dst)->spec_string = xstrdup (EL_LINESPEC (src)->spec_string); break; case ADDRESS_LOCATION: EL_ADDRESS (dst) = EL_ADDRESS (src); break; case EXPLICIT_LOCATION: EL_EXPLICIT (dst)->func_name_match_type = EL_EXPLICIT (src)->func_name_match_type; if (EL_EXPLICIT (src)->source_filename != NULL) EL_EXPLICIT (dst)->source_filename = xstrdup (EL_EXPLICIT (src)->source_filename); if (EL_EXPLICIT (src)->function_name != NULL) EL_EXPLICIT (dst)->function_name = xstrdup (EL_EXPLICIT (src)->function_name); if (EL_EXPLICIT (src)->label_name != NULL) EL_EXPLICIT (dst)->label_name = xstrdup (EL_EXPLICIT (src)->label_name); EL_EXPLICIT (dst)->line_offset = EL_EXPLICIT (src)->line_offset; break; case PROBE_LOCATION: if (EL_PROBE (src) != NULL) EL_PROBE (dst) = xstrdup (EL_PROBE (src)); break; default: gdb_assert_not_reached ("unknown event location type"); } return event_location_up (dst); }
static const char * pascm_param_type_name (enum var_types param_type) { int i; for (i = 0; parameter_types[i].name != NULL; ++i) { if (parameter_types[i].value == param_type) return parameter_types[i].name; } gdb_assert_not_reached ("bad parameter type"); }
int tid_range_parser_finished (struct tid_range_parser *parser) { switch (parser->state) { case TID_RANGE_STATE_INFERIOR: return *parser->string == '\0'; case TID_RANGE_STATE_THREAD_RANGE: case TID_RANGE_STATE_STAR_RANGE: return parser->range_parser.finished; } gdb_assert_not_reached (_("unhandled state")); }
const char * tid_range_parser_string (struct tid_range_parser *parser) { switch (parser->state) { case TID_RANGE_STATE_INFERIOR: return parser->string; case TID_RANGE_STATE_THREAD_RANGE: case TID_RANGE_STATE_STAR_RANGE: return parser->range_parser.string; } gdb_assert_not_reached (_("unhandled state")); }
/* If the text starting at P going up to (but not including) END starts with a string literal, set *TOK to point to that string literal, and return 1. Otherwise, return zero. Signal an error if it contains a malformed or incomplete string literal. */ static int get_string_literal (struct macro_buffer *tok, char *p, char *end) { if ((p + 1 <= end && *p == '"') || (p + 2 <= end && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U') && p[1] == '"')) { char *tok_start = p; if (*p == '"') p++; else if (*p == 'L' || *p == 'u' || *p == 'U') p += 2; else gdb_assert_not_reached ("unexpected string literal"); for (;;) { if (p >= end) error (_("Unterminated string in expression.")); else if (*p == '"') { p++; break; } else if (*p == '\n') error (_("Newline characters may not appear in string " "constants.")); else if (*p == '\\') { const char *s, *o; s = o = ++p; c_parse_escape (&s, NULL); p += s - o; } else p++; } set_token (tok, tok_start, p); return 1; } else return 0; }
static void add_code_footer (enum compile_i_scope_types type, struct ui_file *buf) { switch (type) { case COMPILE_I_SIMPLE_SCOPE: case COMPILE_I_PRINT_ADDRESS_SCOPE: case COMPILE_I_PRINT_VALUE_SCOPE: fputs_unfiltered ("}\n", buf); break; case COMPILE_I_RAW_SCOPE: break; default: gdb_assert_not_reached (_("Unknown compiler scope reached.")); } }
void unmark_fd_no_cloexec (int fd) { int i, val; for (i = 0; VEC_iterate (int, open_fds, i, val); ++i) { if (fd == val) { VEC_unordered_remove (int, open_fds, i); return; } } gdb_assert_not_reached (_("fd not found in open_fds")); }
static int raw_bkpt_type_to_arm_hwbp_type (enum raw_bkpt_type raw_type) { switch (raw_type) { case raw_bkpt_type_hw: return arm_hwbp_break; case raw_bkpt_type_write_wp: return arm_hwbp_store; case raw_bkpt_type_read_wp: return arm_hwbp_load; case raw_bkpt_type_access_wp: return arm_hwbp_access; default: gdb_assert_not_reached ("unhandled raw type"); } }
static minimal_symbol_type msym_prefer_to_msym_type (lookup_msym_prefer prefer) { switch (prefer) { case lookup_msym_prefer::TEXT: return mst_text; case lookup_msym_prefer::TRAMPOLINE: return mst_solib_trampoline; case lookup_msym_prefer::GNU_IFUNC: return mst_text_gnu_ifunc; } /* Assert here instead of in a default switch case above so that -Wswitch warns if a new enumerator is added. */ gdb_assert_not_reached ("unhandled lookup_msym_prefer"); }