From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/6] Use new/delete for do_module_cleanup
Date: Sun, 9 Aug 2020 07:52:54 -0600 [thread overview]
Message-ID: <20200809135258.8207-3-tom@tromey.com> (raw)
In-Reply-To: <20200809135258.8207-1-tom@tromey.com>
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-08-08 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.
---
gdb/ChangeLog | 8 ++++++++
gdb/compile/compile-object-run.c | 24 ++++++++++++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index a2f39900053..4a18655d488 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -32,6 +32,17 @@
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;
@@ -51,7 +62,7 @@ struct do_module_cleanup
struct munmap_list *munmap_list_head;
/* objfile_name of our objfile. */
- char objfile_name_string[1];
+ char *objfile_name_string;
};
/* 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;
}
/* Perform inferior call of MODULE. This function may throw an error.
@@ -122,11 +131,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;
--
2.17.2
next prev parent reply other threads:[~2020-08-09 13:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-09 13:52 [PATCH 0/6] Avoid manual memory management in gdb/compile/ Tom Tromey
2020-08-09 13:52 ` [PATCH 1/6] Remove some manual memory management from compile interface Tom Tromey
2020-08-09 22:34 ` Simon Marchi
2020-09-19 23:45 ` Tom Tromey
2020-09-19 23:52 ` Simon Marchi
2020-09-23 12:56 ` Tom Tromey
2020-08-09 13:52 ` Tom Tromey [this message]
2020-08-09 22:45 ` [PP?] [PATCH 2/6] Use new/delete for do_module_cleanup Simon Marchi
2020-09-23 13:36 ` Tom Tromey
2020-08-09 13:52 ` [PATCH 3/6] Introduce and use compile_module_up Tom Tromey
2020-08-09 13:52 ` [PATCH 4/6] Transfer module ownership to do_module_cleanup Tom Tromey
2020-08-10 0:48 ` [PP?] " Simon Marchi
2020-09-23 14:55 ` Tom Tromey
2020-08-09 13:52 ` [PATCH 5/6] Simplify compile_module cleanup Tom Tromey
2020-08-09 13:52 ` [PATCH 6/6] Avoid manual memory management of argv arrays in gdb/compile Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200809135258.8207-3-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox