Transfer module ownership to do_module_cleanup
This changes the do_module_cleanup structure to simply hold on to the module itself. This lets us remove most members from do_module_cleanup. gdb/ChangeLog 2020-09-23 Tom Tromey <tom@tromey.com> * compile/compile-object-run.c (struct do_module_cleanup): Add parameters to constructor. Update destructor. <source_file, scope, scope_data, out_value_type, out_value_addr, munmap_list_head, objfile_name_string>: Remove. <module>: New member. (do_module_cleanup): Update. (compile_object_run): Update.
This commit is contained in:
parent
e947a8482a
commit
e616f60a6b
2 changed files with 38 additions and 42 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2020-09-23 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* compile/compile-object-run.c (struct do_module_cleanup): Add
|
||||||
|
parameters to constructor. Update destructor.
|
||||||
|
<source_file, scope, scope_data, out_value_type, out_value_addr,
|
||||||
|
munmap_list_head, objfile_name_string>: Remove.
|
||||||
|
<module>: New member.
|
||||||
|
(do_module_cleanup): Update.
|
||||||
|
(compile_object_run): Update.
|
||||||
|
|
||||||
2020-09-23 Tom Tromey <tom@tromey.com>
|
2020-09-23 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* compile/compile.c (eval_compile_command): Update.
|
* compile/compile.c (eval_compile_command): Update.
|
||||||
|
|
|
@ -32,13 +32,16 @@
|
||||||
|
|
||||||
struct do_module_cleanup
|
struct do_module_cleanup
|
||||||
{
|
{
|
||||||
do_module_cleanup () = default;
|
do_module_cleanup (int *ptr, compile_module_up &&mod)
|
||||||
|
: executedp (ptr),
|
||||||
|
module (std::move (mod))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
~do_module_cleanup ()
|
~do_module_cleanup ()
|
||||||
{
|
{
|
||||||
delete munmap_list_head;
|
delete module->munmap_list_head;
|
||||||
xfree (source_file);
|
xfree (module->source_file);
|
||||||
xfree (objfile_name_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DISABLE_COPY_AND_ASSIGN (do_module_cleanup);
|
DISABLE_COPY_AND_ASSIGN (do_module_cleanup);
|
||||||
|
@ -47,22 +50,8 @@ struct do_module_cleanup
|
||||||
The pointer may be NULL. */
|
The pointer may be NULL. */
|
||||||
int *executedp;
|
int *executedp;
|
||||||
|
|
||||||
/* .c file OBJFILE was built from. It needs to be xfree-d. */
|
/* The compile module. */
|
||||||
char *source_file = nullptr;
|
compile_module_up module;
|
||||||
|
|
||||||
/* Copy from struct compile_module. */
|
|
||||||
enum compile_i_scope_types scope;
|
|
||||||
void *scope_data;
|
|
||||||
|
|
||||||
/* Copy from struct compile_module. */
|
|
||||||
struct type *out_value_type;
|
|
||||||
CORE_ADDR out_value_addr;
|
|
||||||
|
|
||||||
/* Copy from struct compile_module. */
|
|
||||||
struct munmap_list *munmap_list_head = nullptr;
|
|
||||||
|
|
||||||
/* objfile_name of our objfile. */
|
|
||||||
char *objfile_name_string = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Cleanup everything after the inferior function dummy frame gets
|
/* Cleanup everything after the inferior function dummy frame gets
|
||||||
|
@ -80,22 +69,29 @@ do_module_cleanup (void *arg, int registers_valid)
|
||||||
|
|
||||||
/* This code cannot be in compile_object_run as OUT_VALUE_TYPE
|
/* This code cannot be in compile_object_run as OUT_VALUE_TYPE
|
||||||
no longer exists there. */
|
no longer exists there. */
|
||||||
if (data->scope == COMPILE_I_PRINT_ADDRESS_SCOPE
|
if (data->module->scope == COMPILE_I_PRINT_ADDRESS_SCOPE
|
||||||
|| data->scope == COMPILE_I_PRINT_VALUE_SCOPE)
|
|| data->module->scope == COMPILE_I_PRINT_VALUE_SCOPE)
|
||||||
{
|
{
|
||||||
struct value *addr_value;
|
struct value *addr_value;
|
||||||
struct type *ptr_type = lookup_pointer_type (data->out_value_type);
|
struct type *ptr_type
|
||||||
|
= lookup_pointer_type (data->module->out_value_type);
|
||||||
|
|
||||||
addr_value = value_from_pointer (ptr_type, data->out_value_addr);
|
addr_value = value_from_pointer (ptr_type,
|
||||||
|
data->module->out_value_addr);
|
||||||
|
|
||||||
/* SCOPE_DATA would be stale unless EXECUTEDP != NULL. */
|
/* SCOPE_DATA would be stale unless EXECUTEDP != NULL. */
|
||||||
compile_print_value (value_ind (addr_value), data->scope_data);
|
compile_print_value (value_ind (addr_value),
|
||||||
|
data->module->scope_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We have to make a copy of the name so that we can unlink the
|
||||||
|
underlying file -- removing the objfile will cause the name to be
|
||||||
|
freed, so we can't simply keep a reference to it. */
|
||||||
|
std::string objfile_name_s = objfile_name (data->module->objfile);
|
||||||
for (objfile *objfile : current_program_space->objfiles ())
|
for (objfile *objfile : current_program_space->objfiles ())
|
||||||
if ((objfile->flags & OBJF_USERLOADED) == 0
|
if ((objfile->flags & OBJF_USERLOADED) == 0
|
||||||
&& (strcmp (objfile_name (objfile), data->objfile_name_string) == 0))
|
&& objfile_name_s == objfile_name (objfile))
|
||||||
{
|
{
|
||||||
objfile->unlink ();
|
objfile->unlink ();
|
||||||
|
|
||||||
|
@ -106,10 +102,10 @@ do_module_cleanup (void *arg, int registers_valid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete the .c file. */
|
/* Delete the .c file. */
|
||||||
unlink (data->source_file);
|
unlink (data->module->source_file);
|
||||||
|
|
||||||
/* Delete the .o file. */
|
/* Delete the .o file. */
|
||||||
unlink (data->objfile_name_string);
|
unlink (objfile_name_s.c_str ());
|
||||||
|
|
||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
|
@ -135,23 +131,12 @@ compile_object_run (compile_module_up &&module)
|
||||||
{
|
{
|
||||||
struct value *func_val;
|
struct value *func_val;
|
||||||
struct do_module_cleanup *data;
|
struct do_module_cleanup *data;
|
||||||
const char *objfile_name_s = objfile_name (module->objfile);
|
|
||||||
int dtor_found, executed = 0;
|
int dtor_found, executed = 0;
|
||||||
struct symbol *func_sym = module->func_sym;
|
struct symbol *func_sym = module->func_sym;
|
||||||
CORE_ADDR regs_addr = module->regs_addr;
|
CORE_ADDR regs_addr = module->regs_addr;
|
||||||
struct objfile *objfile = module->objfile;
|
struct objfile *objfile = module->objfile;
|
||||||
|
|
||||||
data = new struct do_module_cleanup;
|
data = new struct do_module_cleanup (&executed, std::move (module));
|
||||||
data->executedp = &executed;
|
|
||||||
data->source_file = xstrdup (module->source_file);
|
|
||||||
data->objfile_name_string = xstrdup (objfile_name_s);
|
|
||||||
data->scope = module->scope;
|
|
||||||
data->scope_data = module->scope_data;
|
|
||||||
data->out_value_type = module->out_value_type;
|
|
||||||
data->out_value_addr = module->out_value_addr;
|
|
||||||
data->munmap_list_head = module->munmap_list_head;
|
|
||||||
|
|
||||||
xfree (module->source_file);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -178,9 +163,10 @@ compile_object_run (compile_module_up &&module)
|
||||||
}
|
}
|
||||||
if (func_type->num_fields () >= 2)
|
if (func_type->num_fields () >= 2)
|
||||||
{
|
{
|
||||||
gdb_assert (data->out_value_addr != 0);
|
gdb_assert (data->module->out_value_addr != 0);
|
||||||
vargs[current_arg] = value_from_pointer
|
vargs[current_arg] = value_from_pointer
|
||||||
(func_type->field (current_arg).type (), data->out_value_addr);
|
(func_type->field (current_arg).type (),
|
||||||
|
data->module->out_value_addr);
|
||||||
++current_arg;
|
++current_arg;
|
||||||
}
|
}
|
||||||
gdb_assert (current_arg == func_type->num_fields ());
|
gdb_assert (current_arg == func_type->num_fields ());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue