aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile-cplus-templates.c8
-rw-r--r--gdb/compile/compile-loc2c.c1
-rw-r--r--gdb/compile/compile-object-load.c25
-rw-r--r--gdb/compile/compile.c65
4 files changed, 51 insertions, 48 deletions
diff --git a/gdb/compile/compile-cplus-templates.c b/gdb/compile/compile-cplus-templates.c
index 4b2bf46..b3d0794 100644
--- a/gdb/compile/compile-cplus-templates.c
+++ b/gdb/compile/compile-cplus-templates.c
@@ -591,12 +591,10 @@ print_conversion_node (const struct demangle_component *comp,
case DEMANGLE_COMPONENT_QUAL_NAME:
{
/* Print out the qualified name. */
- struct cleanup *back_to;
- char *ret = cp_comp_to_string (d_left (comp), 10);
+ gdb::unique_xmalloc_ptr<char> ret
+ = cp_comp_to_string (d_left (comp), 10);
- back_to = make_cleanup (xfree, ret);
- fprintf_unfiltered (stream, "%s::", ret);
- do_cleanups (back_to);
+ fprintf_unfiltered (stream, "%s::", ret.get ());
/* Follow the rest of the name. */
comp = d_right (comp);
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 856d4c2..d5a2555 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -723,6 +723,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
break;
case DW_OP_addr:
+ uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
op_ptr += addr_size;
/* Some versions of GCC emit DW_OP_addr before
DW_OP_GNU_push_tls_address. In this case the value is an
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index fd6661c..b5431d8 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -624,44 +624,45 @@ compile_object_load (const compile_file_names &file_names,
unsigned dptr_type_len = TYPE_LENGTH (dptr_type);
struct compile_module *retval;
struct type *regs_type, *out_value_type = NULL;
- char *filename, **matching;
+ char **matching;
struct objfile *objfile;
int expect_parameters;
struct type *expect_return_type;
struct munmap_list *munmap_list_head = NULL;
- filename = tilde_expand (file_names.object_file ());
- cleanups = make_cleanup (xfree, filename);
+ gdb::unique_xmalloc_ptr<char> filename
+ (tilde_expand (file_names.object_file ()));
- gdb_bfd_ref_ptr abfd (gdb_bfd_open (filename, gnutarget, -1));
+ gdb_bfd_ref_ptr abfd (gdb_bfd_open (filename.get (), gnutarget, -1));
if (abfd == NULL)
error (_("\"%s\": could not open as compiled module: %s"),
- filename, bfd_errmsg (bfd_get_error ()));
+ filename.get (), bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching))
error (_("\"%s\": not in loadable format: %s"),
- filename, gdb_bfd_errmsg (bfd_get_error (), matching));
+ filename.get (), gdb_bfd_errmsg (bfd_get_error (), matching));
if ((bfd_get_file_flags (abfd.get ()) & (EXEC_P | DYNAMIC)) != 0)
- error (_("\"%s\": not in object format."), filename);
+ error (_("\"%s\": not in object format."), filename.get ());
setup_sections_data.last_size = 0;
setup_sections_data.last_section_first = abfd->sections;
setup_sections_data.last_prot = -1;
setup_sections_data.last_max_alignment = 1;
setup_sections_data.munmap_list_headp = &munmap_list_head;
- make_cleanup (munmap_listp_free_cleanup, &munmap_list_head);
+ cleanups = make_cleanup (munmap_listp_free_cleanup, &munmap_list_head);
bfd_map_over_sections (abfd.get (), setup_sections, &setup_sections_data);
setup_sections (abfd.get (), NULL, &setup_sections_data);
storage_needed = bfd_get_symtab_upper_bound (abfd.get ());
if (storage_needed < 0)
error (_("Cannot read symbols of compiled module \"%s\": %s"),
- filename, bfd_errmsg (bfd_get_error ()));
+ filename.get (), bfd_errmsg (bfd_get_error ()));
/* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in
"Reading symbols from ..." message for automatically generated file. */
- objfile = symbol_file_add_from_bfd (abfd.get (), filename, 0, NULL, 0, NULL);
+ objfile = symbol_file_add_from_bfd (abfd.get (), filename.get (),
+ 0, NULL, 0, NULL);
cleanups_free_objfile = make_cleanup_free_objfile (objfile);
func_sym = lookup_global_symbol_from_objfile (objfile,
@@ -713,7 +714,7 @@ compile_object_load (const compile_file_names &file_names,
number_of_symbols = bfd_canonicalize_symtab (abfd.get (), symbol_table);
if (number_of_symbols < 0)
error (_("Cannot parse symbols of compiled module \"%s\": %s"),
- filename, bfd_errmsg (bfd_get_error ()));
+ filename.get (), bfd_errmsg (bfd_get_error ()));
missing_symbols = 0;
for (symp = symbol_table; symp < symbol_table + number_of_symbols; symp++)
@@ -764,7 +765,7 @@ compile_object_load (const compile_file_names &file_names,
default:
warning (_("Could not find symbol \"%s\" "
"for compiled module \"%s\"."),
- sym->name, filename);
+ sym->name, filename.get ());
missing_symbols++;
}
}
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 74ffa64..7c8fe15 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -39,6 +39,8 @@
#include "osabi.h"
#include "gdb_wait.h"
#include "valprint.h"
+#include "common/gdb_optional.h"
+#include "common/gdb_unlinker.h"
@@ -283,15 +285,17 @@ get_expr_block_and_pc (CORE_ADDR *pc)
return block;
}
-/* Call gdb_buildargv, set its result for S into *ARGVP but calculate also the
- number of parsed arguments into *ARGCP. If gdb_buildargv has returned NULL
- then *ARGCP is set to zero. */
+/* Call buildargv (via gdb_argv), set its result for S into *ARGVP but
+ calculate also the number of parsed arguments into *ARGCP. If
+ buildargv has returned NULL then *ARGCP is set to zero. */
static void
build_argc_argv (const char *s, int *argcp, char ***argvp)
{
- *argvp = gdb_buildargv (s);
- *argcp = countargv (*argvp);
+ gdb_argv args (s);
+
+ *argcp = args.count ();
+ *argvp = args.release ();
}
/* String for 'set compile-args' and 'show compile-args'. */
@@ -457,16 +461,6 @@ cleanup_compile_instance (void *arg)
delete inst;
}
-/* A cleanup function to unlink a file. */
-
-static void
-cleanup_unlink_file (void *arg)
-{
- const char *filename = (const char *) arg;
-
- unlink (filename);
-}
-
/* A helper function suitable for use as the "print_callback" in the
compiler object. */
@@ -485,7 +479,7 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
enum compile_i_scope_types scope)
{
compile::compile_instance *compiler;
- struct cleanup *cleanup, *inner_cleanup;
+ struct cleanup *cleanup;
const struct block *expr_block;
CORE_ADDR trash_pc, expr_pc;
int argc;
@@ -569,7 +563,7 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
/* Set compiler command-line arguments. */
get_args (compiler, gdbarch, &argc, &argv);
- make_cleanup_freeargv (argv);
+ gdb_argv argv_holder (argv);
if (compiler->version ()>= GCC_FE_VERSION_1)
error_message = compiler->set_arguments (argc, argv);
@@ -593,14 +587,18 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
compile_file_names fnames = get_new_file_names ();
- src = gdb_fopen_cloexec (fnames.source_file (), "w");
- if (src == NULL)
- perror_with_name (_("Could not open source file for writing"));
- inner_cleanup = make_cleanup (cleanup_unlink_file,
- (void *) fnames.source_file ());
- if (fputs (code.c_str (), src) == EOF)
- perror_with_name (_("Could not write to source file"));
- fclose (src);
+ gdb::optional<gdb::unlinker> source_remover;
+
+ {
+ gdb_file_up src = gdb_fopen_cloexec (fnames.source_file (), "w");
+ if (src == NULL)
+ perror_with_name (_("Could not open source file for writing"));
+
+ source_remover.emplace (fnames.source_file ());
+
+ if (fputs (code.c_str (), src.get ()) == EOF)
+ perror_with_name (_("Could not write to source file"));
+ }
if (compile_debug)
fprintf_unfiltered (gdb_stdlog, "source file produced: %s\n\n",
@@ -620,7 +618,9 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
fprintf_unfiltered (gdb_stdlog, "object file produced: %s\n\n",
fnames.object_file ());
- discard_cleanups (inner_cleanup);
+ /* Keep the source file. */
+ source_remover->keep ();
+
do_cleanups (cleanup);
return fnames;
@@ -642,14 +642,13 @@ void
eval_compile_command (struct command_line *cmd, const char *cmd_string,
enum compile_i_scope_types scope, void *scope_data)
{
- struct cleanup *cleanup_unlink;
struct compile_module *compile_module;
compile_file_names fnames = compile_to_object (cmd, cmd_string, scope);
- cleanup_unlink = make_cleanup (cleanup_unlink_file,
- (void *) fnames.object_file ());
- make_cleanup (cleanup_unlink_file, (void *) fnames.source_file ());
+ gdb::unlinker object_remover (fnames.object_file ());
+ gdb::unlinker source_remover (fnames.source_file ());
+
compile_module = compile_object_load (fnames, scope, scope_data);
if (compile_module == NULL)
{
@@ -658,7 +657,11 @@ eval_compile_command (struct command_line *cmd, const char *cmd_string,
COMPILE_I_PRINT_VALUE_SCOPE, scope_data);
return;
}
- discard_cleanups (cleanup_unlink);
+
+ /* Keep the files. */
+ source_remover.keep ();
+ object_remover.keep ();
+
compile_object_run (compile_module);
}