summaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile-c-support.c62
-rw-r--r--gdb/compile/compile-c-symbols.c21
-rw-r--r--gdb/compile/compile-internal.h2
-rw-r--r--gdb/compile/compile-loc2c.c107
-rw-r--r--gdb/compile/compile.c9
-rw-r--r--gdb/compile/compile.h4
6 files changed, 95 insertions, 110 deletions
diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c
index 877bfb726eb..7ad0a872f23 100644
--- a/gdb/compile/compile-c-support.c
+++ b/gdb/compile/compile-c-support.c
@@ -333,15 +333,12 @@ c_compute_program (struct compile_instance *inst,
const struct block *expr_block,
CORE_ADDR expr_pc)
{
- struct ui_file *buf, *var_stream = NULL;
- std::string code;
- struct cleanup *cleanup;
struct compile_c_instance *context = (struct compile_c_instance *) inst;
- buf = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (buf);
+ string_file buf;
+ string_file var_stream;
- write_macro_definitions (expr_block, expr_pc, 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
@@ -355,21 +352,17 @@ c_compute_program (struct compile_instance *inst,
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);
+ buf.puts ("typedef unsigned int"
+ " __attribute__ ((__mode__(__pointer__)))"
+ " __gdb_uintptr;\n");
+ buf.puts ("typedef int"
+ " __attribute__ ((__mode__(__pointer__)))"
+ " __gdb_intptr;\n");
/* Iterate all log2 sizes in bytes supported by c_get_mode_for_size. */
for (i = 0; i < 4; ++i)
@@ -377,24 +370,23 @@ c_compute_program (struct compile_instance *inst,
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);
+ buf.printf ("typedef int"
+ " __attribute__ ((__mode__(__%s__)))"
+ " __gdb_int_%s;\n",
+ mode, mode);
}
- generate_register_struct (buf, gdbarch, registers_used);
+ generate_register_struct (&buf, gdbarch, registers_used);
}
- add_code_header (inst->scope, buf);
+ 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);
+ buf.write (var_stream.c_str (), var_stream.size ());
+ buf.puts ("#pragma GCC user_expression\n");
}
/* The user expression has to be in its own scope, so that "extern"
@@ -402,15 +394,15 @@ c_compute_program (struct compile_instance *inst,
declaration is in the same scope as the declaration provided by
gdb. */
if (inst->scope != COMPILE_I_RAW_SCOPE)
- fputs_unfiltered ("{\n", buf);
+ buf.puts ("{\n");
- fputs_unfiltered ("#line 1 \"gdb command line\"\n", buf);
+ buf.puts ("#line 1 \"gdb command line\"\n");
switch (inst->scope)
{
case COMPILE_I_PRINT_ADDRESS_SCOPE:
case COMPILE_I_PRINT_VALUE_SCOPE:
- fprintf_unfiltered (buf,
+ buf.printf (
"__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"
@@ -420,22 +412,20 @@ c_compute_program (struct compile_instance *inst,
? "&" : ""));
break;
default:
- fputs_unfiltered (input, buf);
+ buf.puts (input);
break;
}
- fputs_unfiltered ("\n", buf);
+ buf.puts ("\n");
/* For larger user expressions the automatic semicolons may be
confusing. */
if (strchr (input, '\n') == NULL)
- fputs_unfiltered (";\n", buf);
+ buf.puts (";\n");
if (inst->scope != COMPILE_I_RAW_SCOPE)
- fputs_unfiltered ("}\n", buf);
+ buf.puts ("}\n");
- add_code_footer (inst->scope, buf);
- code = ui_file_as_string (buf);
- do_cleanups (cleanup);
- return code;
+ add_code_footer (inst->scope, &buf);
+ return std::move (buf.string ());
}
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 60100061cc0..9282cfc0251 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -584,7 +584,7 @@ symbol_seen (htab_t hashtab, struct symbol *sym)
static void
generate_vla_size (struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc,
@@ -640,7 +640,7 @@ generate_vla_size (struct compile_c_instance *compiler,
static void
generate_c_for_for_one_variable (struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
unsigned char *registers_used,
CORE_ADDR pc,
@@ -651,14 +651,14 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
{
if (is_dynamic_type (SYMBOL_TYPE (sym)))
{
- struct ui_file *size_file = mem_fileopen ();
- struct cleanup *cleanup = make_cleanup_ui_file_delete (size_file);
+ /* We need to emit to a temporary buffer in case an error
+ occurs in the middle. */
+ string_file local_file;
- generate_vla_size (compiler, size_file, gdbarch, registers_used, pc,
+ generate_vla_size (compiler, local_file, gdbarch, registers_used, pc,
SYMBOL_TYPE (sym), sym);
- ui_file_put (size_file, ui_file_write_for_put, stream);
- do_cleanups (cleanup);
+ stream.write (local_file.c_str (), local_file.size ());
}
if (SYMBOL_COMPUTED_OPS (sym) != NULL)
@@ -667,14 +667,13 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
struct cleanup *cleanup = make_cleanup (xfree, generated_name);
/* We need to emit to a temporary buffer in case an error
occurs in the middle. */
- struct ui_file *local_file = mem_fileopen ();
+ string_file local_file;
- make_cleanup_ui_file_delete (local_file);
SYMBOL_COMPUTED_OPS (sym)->generate_c_location (sym, local_file,
gdbarch,
registers_used,
pc, generated_name);
- ui_file_put (local_file, ui_file_write_for_put, stream);
+ stream.write (local_file.c_str (), local_file.size ());
do_cleanups (cleanup);
}
@@ -719,7 +718,7 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
unsigned char *
generate_c_for_variable_locations (struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
const struct block *block,
CORE_ADDR pc)
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index 4bf5bf926f8..0c53f8c4432 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -135,7 +135,7 @@ extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe);
extern unsigned char *generate_c_for_variable_locations
(struct compile_c_instance *compiler,
- struct ui_file *stream,
+ string_file &stream,
struct gdbarch *gdbarch,
const struct block *block,
CORE_ADDR pc);
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 81684d133c6..f1296e8304e 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -435,9 +435,9 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
/* Emit code to push a constant. */
static void
-push (int indent, struct ui_file *stream, ULONGEST l)
+push (int indent, string_file &stream, ULONGEST l)
{
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[++__gdb_tos] = (" GCC_UINTPTR ") %s;\n",
hex_string (l));
}
@@ -445,57 +445,57 @@ push (int indent, struct ui_file *stream, ULONGEST l)
/* Emit code to push an arbitrary expression. This works like
printf. */
-static void pushf (int indent, struct ui_file *stream, const char *format, ...)
+static void pushf (int indent, string_file &stream, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
static void
-pushf (int indent, struct ui_file *stream, const char *format, ...)
+pushf (int indent, string_file &stream, const char *format, ...)
{
va_list args;
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos + 1] = ");
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos + 1] = ");
va_start (args, format);
- vfprintf_filtered (stream, format, args);
+ stream.vprintf (format, args);
va_end (args);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
- fprintfi_filtered (indent, stream, "++__gdb_tos;\n");
+ fprintfi_filtered (indent, &stream, "++__gdb_tos;\n");
}
/* Emit code for a unary expression -- one which operates in-place on
the top-of-stack. This works like printf. */
-static void unary (int indent, struct ui_file *stream, const char *format, ...)
+static void unary (int indent, string_file &stream, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
static void
-unary (int indent, struct ui_file *stream, const char *format, ...)
+unary (int indent, string_file &stream, const char *format, ...)
{
va_list args;
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos] = ");
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos] = ");
va_start (args, format);
- vfprintf_filtered (stream, format, args);
+ stream.vprintf (format, args);
va_end (args);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
}
/* Emit code for a unary expression -- one which uses the top two
stack items, popping the topmost one. This works like printf. */
-static void binary (int indent, struct ui_file *stream, const char *format, ...)
+static void binary (int indent, string_file &stream, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
static void
-binary (int indent, struct ui_file *stream, const char *format, ...)
+binary (int indent, string_file &stream, const char *format, ...)
{
va_list args;
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos - 1] = ");
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos - 1] = ");
va_start (args, format);
- vfprintf_filtered (stream, format, args);
+ stream.vprintf (format, args);
va_end (args);
- fprintf_filtered (stream, ";\n");
- fprintfi_filtered (indent, stream, "--__gdb_tos;\n");
+ stream.puts (";\n");
+ fprintfi_filtered (indent, &stream, "--__gdb_tos;\n");
}
/* Print the name of a label given its "SCOPE", an arbitrary integer
@@ -503,10 +503,9 @@ binary (int indent, struct ui_file *stream, const char *format, ...)
corresponding to the label's point of definition. */
static void
-print_label (struct ui_file *stream, unsigned int scope, int target)
+print_label (string_file &stream, unsigned int scope, int target)
{
- fprintf_filtered (stream, "__label_%u_%s",
- scope, pulongest (target));
+ stream.printf ("__label_%u_%s", scope, pulongest (target));
}
/* Emit code that pushes a register's address on the stack.
@@ -514,7 +513,7 @@ print_label (struct ui_file *stream, unsigned int scope, int target)
register was needed by this expression. */
static void
-pushf_register_address (int indent, struct ui_file *stream,
+pushf_register_address (int indent, string_file &stream,
unsigned char *registers_used,
struct gdbarch *gdbarch, int regnum)
{
@@ -535,7 +534,7 @@ pushf_register_address (int indent, struct ui_file *stream,
register's value before it is pushed. */
static void
-pushf_register (int indent, struct ui_file *stream,
+pushf_register (int indent, string_file &stream,
unsigned char *registers_used,
struct gdbarch *gdbarch, int regnum, uint64_t offset)
{
@@ -584,7 +583,7 @@ pushf_register (int indent, struct ui_file *stream,
things. */
static void
-do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
+do_compile_dwarf_expr_to_c (int indent, string_file &stream,
const char *type_name,
const char *result_name,
struct symbol *sym, CORE_ADDR pc,
@@ -609,9 +608,9 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
++scope;
- fprintfi_filtered (indent, stream, "__attribute__ ((unused)) %s %s;\n",
+ fprintfi_filtered (indent, &stream, "__attribute__ ((unused)) %s %s;\n",
type_name, result_name);
- fprintfi_filtered (indent, stream, "{\n");
+ fprintfi_filtered (indent, &stream, "{\n");
indent += 2;
stack_depth = compute_stack_depth (byte_order, addr_size,
@@ -648,20 +647,20 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
"compiled code."),
SYMBOL_PRINT_NAME (sym));
- fprintfi_filtered (indent, stream, "%s = %s;\n",
+ fprintfi_filtered (indent, &stream, "%s = %s;\n",
result_name,
core_addr_to_string (value_address (val)));
- fprintfi_filtered (indent - 2, stream, "}\n");
+ fprintfi_filtered (indent - 2, &stream, "}\n");
do_cleanups (cleanup);
return;
}
- fprintfi_filtered (indent, stream, GCC_UINTPTR " __gdb_stack[%d];\n",
+ fprintfi_filtered (indent, &stream, GCC_UINTPTR " __gdb_stack[%d];\n",
stack_depth);
if (need_tempvar)
- fprintfi_filtered (indent, stream, GCC_UINTPTR " __gdb_tmp;\n");
- fprintfi_filtered (indent, stream, "int __gdb_tos = -1;\n");
+ fprintfi_filtered (indent, &stream, GCC_UINTPTR " __gdb_tmp;\n");
+ fprintfi_filtered (indent, &stream, "int __gdb_tos = -1;\n");
if (initial != NULL)
pushf (indent, stream, "%s", core_addr_to_string (*initial));
@@ -672,13 +671,13 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
uint64_t uoffset, reg;
int64_t offset;
- print_spaces (indent - 2, stream);
+ print_spaces (indent - 2, &stream);
if (info[op_ptr - base].label)
{
print_label (stream, scope, op_ptr - base);
- fprintf_filtered (stream, ":;");
+ stream.puts (":;");
}
- fprintf_filtered (stream, "/* %s */\n", get_DW_OP_name (op));
+ stream.printf ("/* %s */\n", get_DW_OP_name (op));
/* This is handy for debugging the generated code:
fprintf_filtered (stream, "if (__gdb_tos != %d) abort ();\n",
@@ -919,7 +918,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
break;
case DW_OP_drop:
- fprintfi_filtered (indent, stream, "--__gdb_tos;\n");
+ fprintfi_filtered (indent, &stream, "--__gdb_tos;\n");
break;
case DW_OP_pick:
@@ -929,13 +928,13 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
break;
case DW_OP_swap:
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_tmp = __gdb_stack[__gdb_tos - 1];\n");
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos - 1] = "
"__gdb_stack[__gdb_tos];\n");
- fprintfi_filtered (indent, stream, ("__gdb_stack[__gdb_tos] = "
- "__gdb_tmp;\n"));
+ fprintfi_filtered (indent, &stream, ("__gdb_stack[__gdb_tos] = "
+ "__gdb_tmp;\n"));
break;
case DW_OP_over:
@@ -943,15 +942,15 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
break;
case DW_OP_rot:
- fprintfi_filtered (indent, stream, ("__gdb_tmp = "
- "__gdb_stack[__gdb_tos];\n"));
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream, ("__gdb_tmp = "
+ "__gdb_stack[__gdb_tos];\n"));
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos] = "
"__gdb_stack[__gdb_tos - 1];\n");
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos - 1] = "
"__gdb_stack[__gdb_tos -2];\n");
- fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos - 2] = "
+ fprintfi_filtered (indent, &stream, "__gdb_stack[__gdb_tos - 2] = "
"__gdb_tmp;\n");
break;
@@ -973,7 +972,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
/* Cast to a pointer of the desired type, then
dereference. */
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"__gdb_stack[__gdb_tos] = "
"*((__gdb_int_%s *) "
"__gdb_stack[__gdb_tos]);\n",
@@ -1099,19 +1098,19 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
case DW_OP_skip:
offset = extract_signed_integer (op_ptr, 2, byte_order);
op_ptr += 2;
- fprintfi_filtered (indent, stream, "goto ");
+ fprintfi_filtered (indent, &stream, "goto ");
print_label (stream, scope, op_ptr + offset - base);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
break;
case DW_OP_bra:
offset = extract_signed_integer (op_ptr, 2, byte_order);
op_ptr += 2;
- fprintfi_filtered (indent, stream,
+ fprintfi_filtered (indent, &stream,
"if ((( " GCC_INTPTR
") __gdb_stack[__gdb_tos--]) != 0) goto ");
print_label (stream, scope, op_ptr + offset - base);
- fprintf_filtered (stream, ";\n");
+ stream.puts (";\n");
break;
case DW_OP_nop:
@@ -1122,9 +1121,9 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
}
}
- fprintfi_filtered (indent, stream, "%s = __gdb_stack[__gdb_tos];\n",
+ fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n",
result_name);
- fprintfi_filtered (indent - 2, stream, "}\n");
+ fprintfi_filtered (indent - 2, &stream, "}\n");
do_cleanups (cleanup);
}
@@ -1132,7 +1131,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
/* See compile.h. */
void
-compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name,
+compile_dwarf_expr_to_c (string_file &stream, const char *result_name,
struct symbol *sym, CORE_ADDR pc,
struct gdbarch *arch, unsigned char *registers_used,
unsigned int addr_size,
@@ -1147,7 +1146,7 @@ compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name,
/* See compile.h. */
void
-compile_dwarf_bounds_to_c (struct ui_file *stream,
+compile_dwarf_bounds_to_c (string_file &stream,
const char *result_name,
const struct dynamic_prop *prop,
struct symbol *sym, CORE_ADDR pc,
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 0ae212501fe..b525f61eee8 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -494,22 +494,19 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
/* From the provided expression, build a scope to pass to the
compiler. */
- std::string input_buf;
+ string_file input_buf;
const char *input;
if (cmd != NULL)
{
- struct ui_file *stream = mem_fileopen ();
struct command_line *iter;
- make_cleanup_ui_file_delete (stream);
for (iter = cmd->body_list[0]; iter; iter = iter->next)
{
- fputs_unfiltered (iter->line, stream);
- fputs_unfiltered ("\n", stream);
+ input_buf.puts (iter->line);
+ input_buf.puts ("\n");
}
- input_buf = ui_file_as_string (stream);
input = input_buf.c_str ();
}
else if (cmd_string != NULL)
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index a46ee6d7989..743859932ab 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -55,7 +55,7 @@ extern void eval_compile_command (struct command_line *cmd,
PER_CU is the per-CU object used for looking up various other
things. */
-extern void compile_dwarf_expr_to_c (struct ui_file *stream,
+extern void compile_dwarf_expr_to_c (string_file &stream,
const char *result_name,
struct symbol *sym,
CORE_ADDR pc,
@@ -90,7 +90,7 @@ extern void compile_dwarf_expr_to_c (struct ui_file *stream,
PER_CU is the per-CU object used for looking up various other
things. */
-extern void compile_dwarf_bounds_to_c (struct ui_file *stream,
+extern void compile_dwarf_bounds_to_c (string_file &stream,
const char *result_name,
const struct dynamic_prop *prop,
struct symbol *sym, CORE_ADDR pc,