diff options
author | Tom Tromey <tom@tromey.com> | 2017-08-14 00:03:02 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-09-03 13:03:10 -0600 |
commit | 8f84fb0ee87e8f149523e13815c58e1b664d184f (patch) | |
tree | 24e32c98b3a0c898b7a32bf905b23f4b38f4f79e /gdb/compile/compile-c-symbols.c | |
parent | 18e9961f02b326923553f34682f4dcca0f25702e (diff) | |
download | gdb-8f84fb0ee87e8f149523e13815c58e1b664d184f.zip gdb-8f84fb0ee87e8f149523e13815c58e1b664d184f.tar.gz gdb-8f84fb0ee87e8f149523e13815c58e1b664d184f.tar.bz2 |
Use std::string and unique_xmalloc_ptr in compile/ code
Change various things in the compile/ code to use std::string or
unique_xmalloc_ptr as appropriate. This allows the removal of some
cleanups.
ChangeLog
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.
Diffstat (limited to 'gdb/compile/compile-c-symbols.c')
-rw-r--r-- | gdb/compile/compile-c-symbols.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 15e1d6d..1cdea85 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -107,7 +107,6 @@ error_symbol_once (struct compile_c_instance *context, { struct symbol_error search; struct symbol_error *err; - char *message; if (context->symbol_err_map == NULL) return; @@ -117,10 +116,9 @@ error_symbol_once (struct compile_c_instance *context, 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 ()); } @@ -128,10 +126,11 @@ error_symbol_once (struct compile_c_instance *context, /* 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. @@ -170,7 +169,7 @@ convert_one_symbol (struct compile_c_instance *context, 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)) { @@ -290,13 +289,11 @@ convert_one_symbol (struct compile_c_instance *context, 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); } } @@ -604,13 +601,11 @@ generate_vla_size (struct compile_c_instance *compiler, || 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; @@ -663,8 +658,8 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler, 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; @@ -672,10 +667,9 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler, 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 { |