void mi_out_put (struct ui_out *uiout, struct ui_file *stream) { struct ui_out_data *data = ui_out_data (uiout); ui_file_put (data->buffer, do_write, stream); ui_file_rewind (data->buffer); }
char * ui_file_obsavestring (struct ui_file *file, struct obstack *obstack, long *length) { ui_file_put (file, do_ui_file_obsavestring, obstack); *length = obstack_object_size (obstack); obstack_1grow (obstack, '\0'); return obstack_finish (obstack); }
/* Print a floating-point value of type TYPE, pointed to in GDB by VALADDR, on STREAM. Use Ada formatting conventions: there must be a decimal point, and at least one digit before and after the point. We use GNAT format for NaNs and infinities. */ static void ada_print_floating (const gdb_byte *valaddr, struct type *type, struct ui_file *stream) { char buffer[64]; char *s, *result; int len; struct ui_file *tmp_stream = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); print_floating (valaddr, type, tmp_stream); ui_file_put (tmp_stream, ui_memcpy, buffer); do_cleanups (cleanups); result = buffer; len = strlen (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); return; } fprintf_filtered (stream, "%s", result); }
char * ui_file_xstrdup (struct ui_file *file, long *length) { struct accumulated_ui_file acc; acc.buffer = NULL; acc.length = 0; ui_file_put (file, do_ui_file_xstrdup, &acc); if (acc.buffer == NULL) acc.buffer = xstrdup (""); if (length != NULL) *length = acc.length; return acc.buffer; }
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; }