+2017-09-03 Tom Tromey <tom@tromey.com>
+
+ * compile/compile.c (compile_register_name_mangled): Return
+ std::string.
+ * compile/compile-loc2c.c (pushf_register_address): Update.
+ (pushf_register): Update.
+ * compile/compile-c-types.c (convert_array): Update.
+ * compile/compile-c-symbols.c (generate_vla_size): Update.
+ (error_symbol_once): Use a gdb::unique_xmalloc_ptr.
+ (symbol_substitution_name): Return a gdb::unique_xmalloc_ptr.
+ (convert_one_symbol): Update.
+ (generate_c_for_for_one_variable): Update.
+ * compile/compile-c-support.c (c_get_range_decl_name): Return a
+ std::string.
+ (generate_register_struct): Update.
+ * compile/compile-internal.h (c_get_range_decl_name): Return a
+ std::string.
+ (compile_register_name_mangled): Return std::string.
+
2017-09-03 Tom Tromey <tom@tromey.com>
* utils.c (perror_string): Return a std::string.
/* See compile-internal.h. */
-char *
+std::string
c_get_range_decl_name (const struct dynamic_prop *prop)
{
- return xstrprintf ("__gdb_prop_%s", host_address_to_string (prop));
+ return string_printf ("__gdb_prop_%s", host_address_to_string (prop));
}
\f
if (registers_used[i])
{
struct type *regtype = check_typedef (register_type (gdbarch, i));
- char *regname = compile_register_name_mangled (gdbarch, i);
- struct cleanup *cleanups = make_cleanup (xfree, regname);
+ std::string regname = compile_register_name_mangled (gdbarch, i);
seen = 1;
switch (TYPE_CODE (regtype))
{
case TYPE_CODE_PTR:
- fprintf_filtered (stream, "__gdb_uintptr %s", regname);
+ fprintf_filtered (stream, "__gdb_uintptr %s",
+ regname.c_str ());
break;
case TYPE_CODE_INT:
fprintf_unfiltered (stream,
"int %s"
" __attribute__ ((__mode__(__%s__)))",
- regname,
+ regname.c_str (),
mode);
break;
}
" unsigned char %s[%d]"
" __attribute__((__aligned__("
"__BIGGEST_ALIGNMENT__)))",
- regname,
+ regname.c_str (),
TYPE_LENGTH (regtype));
}
fputs_unfiltered (";\n", stream);
-
- do_cleanups (cleanups);
}
}
{
struct symbol_error search;
struct symbol_error *err;
- char *message;
if (context->symbol_err_map == NULL)
return;
if (err == NULL || err->message == NULL)
return;
- message = err->message;
+ gdb::unique_xmalloc_ptr<char> message (err->message);
err->message = NULL;
- make_cleanup (xfree, message);
- error (_("%s"), message);
+ error (_("%s"), message.get ());
}
\f
/* Compute the name of the pointer representing a local symbol's
address. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
symbol_substitution_name (struct symbol *sym)
{
- return concat ("__", SYMBOL_NATURAL_NAME (sym), "_ptr", (char *) NULL);
+ return gdb::unique_xmalloc_ptr<char>
+ (concat ("__", SYMBOL_NATURAL_NAME (sym), "_ptr", (char *) NULL));
}
/* Convert a given symbol, SYM, to the compiler's representation.
gcc_decl decl;
enum gcc_c_symbol_kind kind;
CORE_ADDR addr = 0;
- char *symbol_name = NULL;
+ gdb::unique_xmalloc_ptr<char> symbol_name;
switch (SYMBOL_CLASS (sym.symbol))
{
SYMBOL_NATURAL_NAME (sym.symbol),
kind,
sym_type,
- symbol_name, addr,
+ symbol_name.get (), addr,
filename, line);
C_CTX (context)->c_ops->bind (C_CTX (context), decl, is_global);
}
-
- xfree (symbol_name);
}
}
|| TYPE_HIGH_BOUND_KIND (type) == PROP_LOCLIST)
{
const struct dynamic_prop *prop = &TYPE_RANGE_DATA (type)->high;
- char *name = c_get_range_decl_name (prop);
- struct cleanup *cleanup = make_cleanup (xfree, name);
+ std::string name = c_get_range_decl_name (prop);
- dwarf2_compile_property_to_c (stream, name,
+ dwarf2_compile_property_to_c (stream, name.c_str (),
gdbarch, registers_used,
prop, pc, sym);
- do_cleanups (cleanup);
}
}
break;
if (SYMBOL_COMPUTED_OPS (sym) != NULL)
{
- char *generated_name = symbol_substitution_name (sym);
- struct cleanup *cleanup = make_cleanup (xfree, generated_name);
+ gdb::unique_xmalloc_ptr<char> generated_name
+ = symbol_substitution_name (sym);
/* We need to emit to a temporary buffer in case an error
occurs in the middle. */
string_file local_file;
SYMBOL_COMPUTED_OPS (sym)->generate_c_location (sym, local_file,
gdbarch,
registers_used,
- pc, generated_name);
+ pc,
+ generated_name.get ());
stream.write (local_file.c_str (), local_file.size ());
-
- do_cleanups (cleanup);
}
else
{
|| TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST)
{
gcc_type result;
- char *upper_bound;
if (TYPE_VECTOR (type))
return C_CTX (context)->c_ops->error (C_CTX (context),
_("variably-sized vector type"
" is not supported"));
- upper_bound = c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
+ std::string upper_bound
+ = c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
result = C_CTX (context)->c_ops->build_vla_array_type (C_CTX (context),
element_type,
- upper_bound);
- xfree (upper_bound);
+ upper_bound.c_str ());
return result;
}
else
/* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
to a form suitable for the compiler source. The register names
- should not clash with inferior defined macros. Returned pointer is
- never NULL. Returned pointer needs to be deallocated by xfree. */
+ should not clash with inferior defined macros. */
-extern char *compile_register_name_mangled (struct gdbarch *gdbarch,
- int regnum);
+extern std::string compile_register_name_mangled (struct gdbarch *gdbarch,
+ int regnum);
/* Convert compiler source register name to register number of
GDBARCH. Returned value is always >= 0, function throws an error
extern const char *c_get_mode_for_size (int size);
-/* Given a dynamic property, return an xmallocd name that is used to
- represent its size. The result must be freed by the caller. The
- contents of the resulting string will be the same each time for
- each call with the same argument. */
+/* Given a dynamic property, return a name that is used to represent
+ its size. The contents of the resulting string will be the same
+ each time for each call with the same argument. */
struct dynamic_prop;
-extern char *c_get_range_decl_name (const struct dynamic_prop *prop);
+extern std::string c_get_range_decl_name (const struct dynamic_prop *prop);
/* Type used to hold and pass around the source and object file names
to use for compilation. */
unsigned char *registers_used,
struct gdbarch *gdbarch, int regnum)
{
- char *regname = compile_register_name_mangled (gdbarch, regnum);
- struct cleanup *cleanups = make_cleanup (xfree, regname);
+ std::string regname = compile_register_name_mangled (gdbarch, regnum);
registers_used[regnum] = 1;
pushf (indent, stream,
"(" GCC_UINTPTR ") &" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
- regname);
-
- do_cleanups (cleanups);
+ regname.c_str ());
}
/* Emit code that pushes a register's value on the stack.
unsigned char *registers_used,
struct gdbarch *gdbarch, int regnum, uint64_t offset)
{
- char *regname = compile_register_name_mangled (gdbarch, regnum);
- struct cleanup *cleanups = make_cleanup (xfree, regname);
+ std::string regname = compile_register_name_mangled (gdbarch, regnum);
registers_used[regnum] = 1;
if (offset == 0)
pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
- regname);
+ regname.c_str ());
else
pushf (indent, stream,
COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + (" GCC_UINTPTR ") %s",
- regname, hex_string (offset));
-
- do_cleanups (cleanups);
+ regname.c_str (), hex_string (offset));
}
/* Compile a DWARF expression to C code.
/* See compile/compile-internal.h. */
-char *
+std::string
compile_register_name_mangled (struct gdbarch *gdbarch, int regnum)
{
const char *regname = gdbarch_register_name (gdbarch, regnum);
- return xstrprintf ("__%s", regname);
+ return string_printf ("__%s", regname);
}
/* See compile/compile-internal.h. */