aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-09-23 09:32:54 -0600
committerTom Tromey <tom@tromey.com>2020-09-23 09:32:55 -0600
commit0dbf6ee6a074208ef8f95ee3d2f7e4369265e456 (patch)
tree3f47a6acb2a060b47a28b125409127d61cbc8967
parentebe824f5dcf96c8f70e07affb44c3a1679849e28 (diff)
downloadgdb-0dbf6ee6a074208ef8f95ee3d2f7e4369265e456.zip
gdb-0dbf6ee6a074208ef8f95ee3d2f7e4369265e456.tar.gz
gdb-0dbf6ee6a074208ef8f95ee3d2f7e4369265e456.tar.bz2
Use new/delete for do_module_cleanup
This changes do_module_cleanup to use new and delete. It also removes the use of the struct hack from this object -- this requires more allocations for now, but this will be removed in a subsequent patch. gdb/ChangeLog 2020-09-23 Tom Tromey <tom@tromey.com> * compile/compile-object-run.c (struct do_module_cleanup): Add constructor, destructor. <objfile_name_string>: Don't use struct hack. (do_module_cleanup): Use delete. (compile_object_run): Use new.
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/compile/compile-object-run.c28
2 files changed, 26 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 84d2700..f379905 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2020-09-23 Tom Tromey <tom@tromey.com>
+ * compile/compile-object-run.c (struct do_module_cleanup): Add
+ constructor, destructor.
+ <objfile_name_string>: Don't use struct hack.
+ (do_module_cleanup): Use delete.
+ (compile_object_run): Use new.
+
+2020-09-23 Tom Tromey <tom@tromey.com>
+
* compile/compile-cplus-types.c
(compile_cplus_convert_struct_or_union): Use std::vector.
(compile_cplus_convert_func): Likewise.
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 985c6f3..31731b4 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -32,12 +32,23 @@
struct do_module_cleanup
{
+ do_module_cleanup () = default;
+
+ ~do_module_cleanup ()
+ {
+ delete munmap_list_head;
+ xfree (source_file);
+ xfree (objfile_name_string);
+ }
+
+ DISABLE_COPY_AND_ASSIGN (do_module_cleanup);
+
/* Boolean to set true upon a call of do_module_cleanup.
The pointer may be NULL. */
int *executedp;
/* .c file OBJFILE was built from. It needs to be xfree-d. */
- char *source_file;
+ char *source_file = nullptr;
/* Copy from struct compile_module. */
enum compile_i_scope_types scope;
@@ -48,10 +59,10 @@ struct do_module_cleanup
CORE_ADDR out_value_addr;
/* Copy from struct compile_module. */
- struct munmap_list *munmap_list_head;
+ struct munmap_list *munmap_list_head = nullptr;
/* objfile_name of our objfile. */
- char objfile_name_string[1];
+ char *objfile_name_string = nullptr;
};
/* Cleanup everything after the inferior function dummy frame gets
@@ -96,13 +107,11 @@ do_module_cleanup (void *arg, int registers_valid)
/* Delete the .c file. */
unlink (data->source_file);
- xfree (data->source_file);
-
- delete data->munmap_list_head;
/* Delete the .o file. */
unlink (data->objfile_name_string);
- xfree (data);
+
+ delete data;
}
/* Create a copy of FUNC_TYPE that is independent of OBJFILE. */
@@ -132,11 +141,10 @@ compile_object_run (struct compile_module *module)
CORE_ADDR regs_addr = module->regs_addr;
struct objfile *objfile = module->objfile;
- data = (struct do_module_cleanup *) xmalloc (sizeof (*data)
- + strlen (objfile_name_s));
+ data = new struct do_module_cleanup;
data->executedp = &executed;
data->source_file = xstrdup (module->source_file);
- strcpy (data->objfile_name_string, objfile_name_s);
+ 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;