static char * explicit_to_string_internal (int as_linespec, const struct explicit_location *explicit_loc) { struct ui_file *buf; char space, *result; int need_space = 0; struct cleanup *cleanup; space = as_linespec ? ':' : ' '; buf = mem_fileopen (); cleanup = make_cleanup_ui_file_delete (buf); if (explicit_loc->source_filename != NULL) { if (!as_linespec) fputs_unfiltered ("-source ", buf); fputs_unfiltered (explicit_loc->source_filename, buf); need_space = 1; } if (explicit_loc->function_name != NULL) { if (need_space) fputc_unfiltered (space, buf); if (!as_linespec) fputs_unfiltered ("-function ", buf); fputs_unfiltered (explicit_loc->function_name, buf); need_space = 1; } if (explicit_loc->label_name != NULL) { if (need_space) fputc_unfiltered (space, buf); if (!as_linespec) fputs_unfiltered ("-label ", buf); fputs_unfiltered (explicit_loc->label_name, buf); need_space = 1; } if (explicit_loc->line_offset.sign != LINE_OFFSET_UNKNOWN) { if (need_space) fputc_unfiltered (space, buf); if (!as_linespec) fputs_unfiltered ("-line ", buf); fprintf_filtered (buf, "%s%d", (explicit_loc->line_offset.sign == LINE_OFFSET_NONE ? "" : (explicit_loc->line_offset.sign == LINE_OFFSET_PLUS ? "+" : "-")), explicit_loc->line_offset.offset); } result = ui_file_xstrdup (buf, NULL); do_cleanups (cleanup); return result; }
static char * ada_varobj_scalar_image (struct type *type, LONGEST val) { struct ui_file *buf = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (buf); char *result; ada_print_scalar (type, val, buf); result = ui_file_xstrdup (buf, NULL); do_cleanups (cleanups); return result; }
static void ada_print_floating (const gdb_byte *valaddr, struct type *type, struct ui_file *stream) { char *s, *result; struct ui_file *tmp_stream = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); print_floating (valaddr, type, tmp_stream); result = ui_file_xstrdup (tmp_stream, NULL); make_cleanup (xfree, result); /* Modify for Ada rules. */ s = strstr (result, "inf"); if (s == NULL) s = strstr (result, "Inf"); if (s == NULL) s = strstr (result, "INF"); if (s != NULL) strcpy (s, "Inf"); if (s == NULL) { s = strstr (result, "nan"); if (s == NULL) s = strstr (result, "NaN"); if (s == NULL) s = strstr (result, "Nan"); if (s != NULL) { s[0] = s[2] = 'N'; if (result[0] == '-') result += 1; } } if (s == NULL && strchr (result, '.') == NULL) { s = strchr (result, 'e'); if (s == NULL) fprintf_filtered (stream, "%s.0", result); else fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s); } else fprintf_filtered (stream, "%s", result); do_cleanups (cleanups); }
static PyObject * frapy_str (PyObject *self) { char *s; PyObject *result; struct ui_file *strfile; strfile = mem_fileopen (); fprint_frame_id (strfile, ((frame_object *) self)->frame_id); s = ui_file_xstrdup (strfile, NULL); result = PyString_FromString (s); xfree (s); return result; }
static char * ada_varobj_get_value_image (struct value *value, struct value_print_options *opts) { char *result; struct ui_file *buffer; struct cleanup *old_chain; buffer = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (buffer); common_val_print (value, buffer, 0, opts, current_language); result = ui_file_xstrdup (buffer, NULL); do_cleanups (old_chain); return result; }
char * type_sprint(struct type *type, const char *varstring, int show) { struct ui_file *stb; struct cleanup *wipe; long length; char *type_name; stb = mem_fileopen(); wipe = make_cleanup_ui_file_delete(stb); type_print(type, varstring, stb, show); type_name = ui_file_xstrdup(stb, &length); do_cleanups(wipe); return type_name; }
static int frscm_print_frame_smob (SCM self, SCM port, scm_print_state *pstate) { frame_smob *f_smob = (frame_smob *) SCM_SMOB_DATA (self); struct ui_file *strfile; char *s; gdbscm_printf (port, "#<%s ", frame_smob_name); strfile = mem_fileopen (); fprint_frame_id (strfile, f_smob->frame_id); s = ui_file_xstrdup (strfile, NULL); gdbscm_printf (port, "%s", s); ui_file_delete (strfile); xfree (s); scm_puts (">", port); scm_remember_upto_here_1 (self); /* Non-zero means success. */ return 1; }
static char * tyscm_type_name (struct type *type, SCM *excp) { char *name = NULL; TRY { struct cleanup *old_chain; struct ui_file *stb; stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); LA_PRINT_TYPE (type, "", stb, -1, 0, &type_print_raw_options); name = ui_file_xstrdup (stb, NULL); do_cleanups (old_chain); } CATCH (except, RETURN_MASK_ALL) { *excp = gdbscm_scm_from_gdb_exception (except); return NULL; }
void do_setshow_command(char *arg, int from_tty, struct cmd_list_element *c) { if (c->type == set_cmd) { switch (c->var_type) { case var_string: { char *newstr; char *p; char *q; int ch; if (arg == NULL) arg = ""; newstr = (char *)xmalloc(strlen(arg) + 2); p = arg; q = newstr; while ((ch = *p++) != '\000') { if (ch == '\\') { /* \ at end of argument is used after spaces so they won't be lost. */ /* This is obsolete now that we no longer strip trailing whitespace and actually, the backslash didn't get here in my test, readline or something did something funky with a backslash right before a newline. */ if (*p == 0) break; ch = parse_escape(&p); if (ch == 0) break; /* C loses */ else if (ch > 0) *q++ = ch; } else *q++ = ch; } #if 0 if (*(p - 1) != '\\') *q++ = ' '; #endif /* 0 */ *q++ = '\0'; newstr = (char *)xrealloc(newstr, (q - newstr)); if (*(char **)c->var != NULL) xfree(*(char **)c->var); *(char **)c->var = newstr; } break; case var_string_noescape: if (arg == NULL) arg = ""; if (*(char **)c->var != NULL) xfree(*(char **)c->var); *(char **)c->var = savestring(arg, strlen(arg)); break; case var_optional_filename: if (arg == NULL) arg = ""; if (*(char **)c->var != NULL) xfree(*(char **)c->var); *(char **)c->var = savestring(arg, strlen(arg)); break; case var_filename: if (arg == NULL) error_no_arg(_("filename to set it to.")); if (*(char **)c->var != NULL) xfree (*(char **)c->var); *(char **)c->var = tilde_expand(arg); break; case var_boolean: *(int *)c->var = parse_binary_operation(arg); break; case var_auto_boolean: *(enum auto_boolean *)c->var = parse_auto_binary_operation(arg); break; case var_uinteger: if (arg == NULL) error_no_arg(_("integer to set it to.")); *(unsigned int *)c->var = (unsigned int)parse_and_eval_long(arg); if (*(unsigned int *)c->var == 0) *(unsigned int *)c->var = UINT_MAX; break; case var_integer: { unsigned int val; if (arg == NULL) error_no_arg(_("integer to set it to.")); val = (unsigned int)parse_and_eval_long(arg); if (val == 0) *(int *)c->var = INT_MAX; else if (val >= INT_MAX) error(_("integer %u out of range"), val); else *(int *)c->var = val; break; } case var_zinteger: if (arg == NULL) error_no_arg(_("integer to set it to.")); *(int *)c->var = (int)parse_and_eval_long(arg); break; case var_enum: { int i; int len; int nmatches = 0; const char *match = NULL; char *p; /* APPLE LOCAL: Give the valid options for all error messages for enum type commands. */ /* If an argument was supplied, parse it. */ if (arg != NULL) { p = strchr(arg, ' '); if (p) len = (p - arg); else len = strlen(arg); nmatches = 0; for (i = 0; c->enums[i]; i++) if (strncmp(arg, c->enums[i], len) == 0) { if (c->enums[i][len] == '\0') { match = c->enums[i]; nmatches = 1; break; /* exact match. */ } else { match = c->enums[i]; nmatches++; } } } if (nmatches == 1) *(const char **)c->var = match; else { /* If there was an error, print an informative error message. */ struct ui_file *tmp_error_stream = mem_fileopen(); make_cleanup_ui_file_delete (tmp_error_stream); if (arg == NULL) fprintf_unfiltered(tmp_error_stream, "Requires an argument."); else if (nmatches <= 0) fprintf_unfiltered(tmp_error_stream, "Undefined item: \"%s\".", arg); else if (nmatches > 1) fprintf_unfiltered(tmp_error_stream, "Ambiguous item \"%s\".", arg); fprintf_unfiltered(tmp_error_stream, " Valid arguments are "); for (i = 0; c->enums[i]; i++) { if (i != 0) fprintf_unfiltered(tmp_error_stream, ", "); fputs_unfiltered(c->enums[i], tmp_error_stream); } fprintf_unfiltered(tmp_error_stream, "."); error_stream(tmp_error_stream); } /* END APPLE LOCAL */ } break; default: error(_("gdb internal error: bad var_type in do_setshow_command")); } } else if (c->type == show_cmd) { struct cleanup *old_chain; struct ui_stream *stb; stb = ui_out_stream_new(uiout); old_chain = make_cleanup_ui_out_stream_delete(stb); /* Possibly call the pre hook: */ if (c->pre_show_hook) (c->pre_show_hook)(c); switch (c->var_type) { case var_string: { if (*(unsigned char **)c->var) fputstr_filtered(*(char **)c->var, '"', stb->stream); } break; case var_string_noescape: case var_optional_filename: case var_filename: case var_enum: if (*(char **)c->var) fputs_filtered(*(char **)c->var, stb->stream); break; case var_boolean: fputs_filtered(*(int *)c->var ? "on" : "off", stb->stream); break; case var_auto_boolean: switch (*(enum auto_boolean*)c->var) { case AUTO_BOOLEAN_TRUE: fputs_filtered("on", stb->stream); break; case AUTO_BOOLEAN_FALSE: fputs_filtered("off", stb->stream); break; case AUTO_BOOLEAN_AUTO: fputs_filtered("auto", stb->stream); break; default: internal_error(__FILE__, __LINE__, _("do_setshow_command: invalid var_auto_boolean")); break; } break; case var_uinteger: if (*(unsigned int *)c->var == UINT_MAX) { fputs_filtered("unlimited", stb->stream); break; } /* else fall through */ case var_zinteger: fprintf_filtered(stb->stream, "%u", *(unsigned int *)c->var); break; case var_integer: if (*(int *)c->var == INT_MAX) { fputs_filtered("unlimited", stb->stream); } else fprintf_filtered(stb->stream, "%d", *(int *)c->var); break; default: error(_("gdb internal error: bad var_type in do_setshow_command")); } /* FIXME: cagney/2005-02-10: Need to split this in half: code to convert the value into a string (esentially the above); and code to print the value out. For the latter there should be MI and CLI specific versions. */ if (ui_out_is_mi_like_p(uiout)) ui_out_field_stream(uiout, "value", stb); else { long length; char *value = ui_file_xstrdup(stb->stream, &length); make_cleanup(xfree, value); if (c->show_value_func != NULL) c->show_value_func(gdb_stdout, from_tty, c, value); else deprecated_show_value_hack(gdb_stdout, from_tty, c, value); } do_cleanups(old_chain); } else error(_("gdb internal error: bad cmd_type in do_setshow_command")); c->func(c, NULL, from_tty); if ((c->type == set_cmd) && deprecated_set_hook) deprecated_set_hook(c); }
void do_show_command (const char *arg, int from_tty, struct cmd_list_element *c) { struct ui_out *uiout = current_uiout; struct cleanup *old_chain; struct ui_file *stb; gdb_assert (c->type == show_cmd); stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); /* Possibly call the pre hook. */ if (c->pre_show_hook) (c->pre_show_hook) (c); switch (c->var_type) { case var_string: if (*(char **) c->var) fputstr_filtered (*(char **) c->var, '"', stb); break; case var_string_noescape: case var_optional_filename: case var_filename: case var_enum: if (*(char **) c->var) fputs_filtered (*(char **) c->var, stb); break; case var_boolean: fputs_filtered (*(int *) c->var ? "on" : "off", stb); break; case var_auto_boolean: switch (*(enum auto_boolean*) c->var) { case AUTO_BOOLEAN_TRUE: fputs_filtered ("on", stb); break; case AUTO_BOOLEAN_FALSE: fputs_filtered ("off", stb); break; case AUTO_BOOLEAN_AUTO: fputs_filtered ("auto", stb); break; default: internal_error (__FILE__, __LINE__, _("do_show_command: " "invalid var_auto_boolean")); break; } break; case var_uinteger: case var_zuinteger: if (c->var_type == var_uinteger && *(unsigned int *) c->var == UINT_MAX) fputs_filtered ("unlimited", stb); else fprintf_filtered (stb, "%u", *(unsigned int *) c->var); break; case var_integer: case var_zinteger: if (c->var_type == var_integer && *(int *) c->var == INT_MAX) fputs_filtered ("unlimited", stb); else fprintf_filtered (stb, "%d", *(int *) c->var); break; case var_zuinteger_unlimited: { if (*(int *) c->var == -1) fputs_filtered ("unlimited", stb); else fprintf_filtered (stb, "%d", *(int *) c->var); } break; default: error (_("gdb internal error: bad var_type in do_show_command")); } /* FIXME: cagney/2005-02-10: Need to split this in half: code to convert the value into a string (esentially the above); and code to print the value out. For the latter there should be MI and CLI specific versions. */ if (ui_out_is_mi_like_p (uiout)) ui_out_field_stream (uiout, "value", stb); else { char *value = ui_file_xstrdup (stb, NULL); make_cleanup (xfree, value); if (c->show_value_func != NULL) c->show_value_func (gdb_stdout, from_tty, c, value); else deprecated_show_value_hack (gdb_stdout, from_tty, c, value); } do_cleanups (old_chain); c->func (c, NULL, from_tty); }
static PyObject * archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) { static char *keywords[] = { "start_pc", "end_pc", "count", NULL }; CORE_ADDR start, end = 0; CORE_ADDR pc; gdb_py_ulongest start_temp; long count = 0, i; PyObject *result_list, *end_obj = NULL, *count_obj = NULL; struct gdbarch *gdbarch = NULL; ARCHPY_REQUIRE_VALID (self, gdbarch); if (!PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO", keywords, &start_temp, &end_obj, &count_obj)) return NULL; start = start_temp; if (end_obj) { if (PyLong_Check (end_obj)) end = PyLong_AsUnsignedLongLong (end_obj); else if (PyInt_Check (end_obj)) /* If the end_pc value is specified without a trailing 'L', end_obj will be an integer and not a long integer. */ end = PyInt_AsLong (end_obj); else { Py_DECREF (end_obj); Py_XDECREF (count_obj); PyErr_SetString (PyExc_TypeError, _("Argument 'end_pc' should be a (long) integer.")); return NULL; } if (end < start) { Py_DECREF (end_obj); Py_XDECREF (count_obj); PyErr_SetString (PyExc_ValueError, _("Argument 'end_pc' should be greater than or " "equal to the argument 'start_pc'.")); return NULL; } } if (count_obj) { count = PyInt_AsLong (count_obj); if (PyErr_Occurred () || count < 0) { Py_DECREF (count_obj); Py_XDECREF (end_obj); PyErr_SetString (PyExc_TypeError, _("Argument 'count' should be an non-negative " "integer.")); return NULL; } } result_list = PyList_New (0); if (result_list == NULL) return NULL; for (pc = start, i = 0; /* All args are specified. */ (end_obj && count_obj && pc <= end && i < count) /* end_pc is specified, but no count. */ || (end_obj && count_obj == NULL && pc <= end) /* end_pc is not specified, but a count is. */ || (end_obj == NULL && count_obj && i < count) /* Both end_pc and count are not specified. */ || (end_obj == NULL && count_obj == NULL && pc == start);) { int insn_len = 0; char *as = NULL; struct ui_file *memfile = mem_fileopen (); PyObject *insn_dict = PyDict_New (); volatile struct gdb_exception except; if (insn_dict == NULL) { Py_DECREF (result_list); ui_file_delete (memfile); return NULL; } if (PyList_Append (result_list, insn_dict)) { Py_DECREF (result_list); Py_DECREF (insn_dict); ui_file_delete (memfile); return NULL; /* PyList_Append Sets the exception. */ } TRY_CATCH (except, RETURN_MASK_ALL) { insn_len = gdb_print_insn (gdbarch, pc, memfile, NULL); } if (except.reason < 0) { Py_DECREF (result_list); ui_file_delete (memfile); gdbpy_convert_exception (except); return NULL; } as = ui_file_xstrdup (memfile, NULL); if (PyDict_SetItemString (insn_dict, "addr", gdb_py_long_from_ulongest (pc)) || PyDict_SetItemString (insn_dict, "asm", PyString_FromString (*as ? as : "<unknown>")) || PyDict_SetItemString (insn_dict, "length", PyInt_FromLong (insn_len))) { Py_DECREF (result_list); ui_file_delete (memfile); xfree (as); return NULL; } pc += insn_len; i++; ui_file_delete (memfile); xfree (as); }
void add_language (const struct language_defn *lang) { /* For the "set language" command. */ static const char **language_names = NULL; /* For the "help set language" command. */ char *language_set_doc = NULL; int i; struct ui_file *tmp_stream; if (lang->la_magic != LANG_MAGIC) { fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n", lang->la_name); internal_error (__FILE__, __LINE__, _("failed internal consistency check")); } if (!languages) { languages_allocsize = DEFAULT_ALLOCSIZE; languages = (const struct language_defn **) xmalloc (languages_allocsize * sizeof (*languages)); } if (languages_size >= languages_allocsize) { languages_allocsize *= 2; languages = (const struct language_defn **) xrealloc ((char *) languages, languages_allocsize * sizeof (*languages)); } languages[languages_size++] = lang; /* Build the language names array, to be used as enumeration in the set language" enum command. */ language_names = xrealloc (language_names, (languages_size + 1) * sizeof (const char *)); for (i = 0; i < languages_size; ++i) language_names[i] = languages[i]->la_name; language_names[i] = NULL; /* Build the "help set language" docs. */ tmp_stream = mem_fileopen (); fprintf_unfiltered (tmp_stream, _("Set the current source language.\n" "The currently understood settings are:\n\nlocal or " "auto Automatic setting based on source file\n")); for (i = 0; i < languages_size; ++i) { /* Already dealt with these above. */ if (languages[i]->la_language == language_unknown || languages[i]->la_language == language_auto) continue; /* FIXME: i18n: for now assume that the human-readable name is just a capitalization of the internal name. */ fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", languages[i]->la_name, /* Capitalize first letter of language name. */ toupper (languages[i]->la_name[0]), languages[i]->la_name + 1); } language_set_doc = ui_file_xstrdup (tmp_stream, NULL); ui_file_delete (tmp_stream); add_setshow_enum_cmd ("language", class_support, (const char **) language_names, &language, language_set_doc, _("Show the current source language."), NULL, set_language_command, show_language_command, &setlist, &showlist); xfree (language_set_doc); }
static void get_register (int regnum, map_arg arg) { int realnum; CORE_ADDR addr; enum lval_type lval; struct type *reg_vtype; gdb_byte buffer[MAX_REGISTER_SIZE]; int optim, format; struct cleanup *old_chain = NULL; struct ui_file *stb; long dummy; char *res; format = regformat[regnum]; if (format == 0) format = 'x'; reg_vtype = regtype[regnum]; if (reg_vtype == NULL) reg_vtype = register_type (get_current_arch (), regnum); if (!target_has_registers) { if (result_ptr->flags & GDBTK_MAKES_LIST) Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewStringObj ("", -1)); else Tcl_SetStringObj (result_ptr->obj_ptr, "", -1); return; } frame_register (get_selected_frame (NULL), regnum, &optim, &lval, &addr, &realnum, buffer); if (optim) { Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewStringObj ("Optimized out", -1)); return; } stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); if (format == 'r') { /* shouldn't happen. raw format is deprecated */ int j; char *ptr, buf[1024]; strcpy (buf, "0x"); ptr = buf + 2; for (j = 0; j < register_size (get_current_arch (), regnum); j++) { int idx = ((gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG) ? j : register_size (get_current_arch (), regnum) - 1 - j); sprintf (ptr, "%02x", (unsigned char) buffer[idx]); ptr += 2; } fputs_unfiltered (buf, stb); } else { struct value_print_options opts; get_formatted_print_options (&opts, format); opts.deref_ref = 1; opts.pretty = Val_pretty_default; if ((TYPE_CODE (reg_vtype) == TYPE_CODE_UNION) && (strcmp (FIELD_NAME (TYPE_FIELD (reg_vtype, 0)), gdbarch_register_name (get_current_arch (), regnum)) == 0)) { val_print (FIELD_TYPE (TYPE_FIELD (reg_vtype, 0)), buffer, 0, 0, stb, 0, NULL, &opts, current_language); } else val_print (reg_vtype, buffer, 0, 0, stb, 0, NULL, &opts, current_language); } res = ui_file_xstrdup (stb, &dummy); if (result_ptr->flags & GDBTK_MAKES_LIST) Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewStringObj (res, -1)); else Tcl_SetStringObj (result_ptr->obj_ptr, res, -1); xfree (res); do_cleanups (old_chain); }
char * c_compute_program (struct compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc) { struct ui_file *buf, *var_stream = NULL; char *code; struct cleanup *cleanup; struct compile_c_instance *context = (struct compile_c_instance *) inst; buf = mem_fileopen (); cleanup = make_cleanup_ui_file_delete (buf); write_macro_definitions (expr_block, expr_pc, buf); /* Do not generate local variable information for "raw" compilations. In this case we aren't emitting our own function and the user's code may only refer to globals. */ if (inst->scope != COMPILE_I_RAW_SCOPE) { unsigned char *registers_used; int i; /* Generate the code to compute variable locations, but do it before generating the function header, so we can define the register struct before the function body. This requires a temporary stream. */ var_stream = mem_fileopen (); make_cleanup_ui_file_delete (var_stream); registers_used = generate_c_for_variable_locations (context, var_stream, gdbarch, expr_block, expr_pc); make_cleanup (xfree, registers_used); fputs_unfiltered ("typedef unsigned int" " __attribute__ ((__mode__(__pointer__)))" " __gdb_uintptr;\n", buf); fputs_unfiltered ("typedef int" " __attribute__ ((__mode__(__pointer__)))" " __gdb_intptr;\n", buf); /* Iterate all log2 sizes in bytes supported by c_get_mode_for_size. */ for (i = 0; i < 4; ++i) { const char *mode = c_get_mode_for_size (1 << i); gdb_assert (mode != NULL); fprintf_unfiltered (buf, "typedef int" " __attribute__ ((__mode__(__%s__)))" " __gdb_int_%s;\n", mode, mode); } generate_register_struct (buf, gdbarch, registers_used); } add_code_header (inst->scope, buf); if (inst->scope == COMPILE_I_SIMPLE_SCOPE || inst->scope == COMPILE_I_PRINT_ADDRESS_SCOPE || inst->scope == COMPILE_I_PRINT_VALUE_SCOPE) { ui_file_put (var_stream, ui_file_write_for_put, buf); fputs_unfiltered ("#pragma GCC user_expression\n", buf); } /* The user expression has to be in its own scope, so that "extern" works properly. Otherwise gcc thinks that the "extern" declaration is in the same scope as the declaration provided by gdb. */ if (inst->scope != COMPILE_I_RAW_SCOPE) fputs_unfiltered ("{\n", buf); fputs_unfiltered ("#line 1 \"gdb command line\"\n", buf); switch (inst->scope) { case COMPILE_I_PRINT_ADDRESS_SCOPE: case COMPILE_I_PRINT_VALUE_SCOPE: fprintf_unfiltered (buf, "__auto_type " COMPILE_I_EXPR_VAL " = %s;\n" "typeof (%s) *" COMPILE_I_EXPR_PTR_TYPE ";\n" "memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s" COMPILE_I_EXPR_VAL ",\n" "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n" , input, input, (inst->scope == COMPILE_I_PRINT_ADDRESS_SCOPE ? "&" : "")); break; default: fputs_unfiltered (input, buf); break; } fputs_unfiltered ("\n", buf); /* For larger user expressions the automatic semicolons may be confusing. */ if (strchr (input, '\n') == NULL) fputs_unfiltered (";\n", buf); if (inst->scope != COMPILE_I_RAW_SCOPE) fputs_unfiltered ("}\n", buf); add_code_footer (inst->scope, buf); code = ui_file_xstrdup (buf, NULL); do_cleanups (cleanup); return code; }
static SCM gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest) { arch_smob *a_smob = arscm_get_arch_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); struct gdbarch *gdbarch = arscm_get_gdbarch (a_smob); const SCM keywords[] = { port_keyword, offset_keyword, size_keyword, count_keyword, SCM_BOOL_F }; int port_arg_pos = -1, offset_arg_pos = -1; int size_arg_pos = -1, count_arg_pos = -1; SCM port = SCM_BOOL_F; ULONGEST offset = 0; unsigned int count = 1; unsigned int size; ULONGEST start_arg; CORE_ADDR start, end; CORE_ADDR pc; unsigned int i; int using_port; SCM result; gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, keywords, "U#OUuu", start_scm, &start_arg, rest, &port_arg_pos, &port, &offset_arg_pos, &offset, &size_arg_pos, &size, &count_arg_pos, &count); /* START is first stored in a ULONGEST because we don't have a format char for CORE_ADDR, and it's not really worth it to have one yet. */ start = start_arg; if (port_arg_pos > 0) { SCM_ASSERT_TYPE (gdbscm_is_false (port) || gdbscm_is_true (scm_input_port_p (port)), port, port_arg_pos, FUNC_NAME, _("input port")); } using_port = gdbscm_is_true (port); if (offset_arg_pos > 0 && (port_arg_pos < 0 || gdbscm_is_false (port))) { gdbscm_out_of_range_error (FUNC_NAME, offset_arg_pos, gdbscm_scm_from_ulongest (offset), _("offset provided but port is missing")); } if (size_arg_pos > 0) { if (size == 0) return SCM_EOL; /* For now be strict about start+size overflowing. If it becomes a nuisance we can relax things later. */ if (start + size < start) { gdbscm_out_of_range_error (FUNC_NAME, 0, scm_list_2 (gdbscm_scm_from_ulongest (start), gdbscm_scm_from_ulongest (size)), _("start+size overflows")); } end = start + size - 1; } else end = ~(CORE_ADDR) 0; if (count == 0) return SCM_EOL; result = SCM_EOL; for (pc = start, i = 0; pc <= end && i < count; ) { int insn_len = 0; char *as = NULL; struct ui_file *memfile = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (memfile); TRY { if (using_port) { insn_len = gdbscm_print_insn_from_port (gdbarch, port, offset, pc, memfile, NULL); } else insn_len = gdb_print_insn (gdbarch, pc, memfile, NULL); } CATCH (except, RETURN_MASK_ALL) { GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); } END_CATCH as = ui_file_xstrdup (memfile, NULL); result = scm_cons (dascm_make_insn (pc, as, insn_len), result); pc += insn_len; i++; do_cleanups (cleanups); xfree (as); }