diff options
author | Pedro Alves <palves@redhat.com> | 2018-05-11 19:10:14 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2018-05-11 19:12:21 +0100 |
commit | 1524450719d3867e10fc6a8dbc051b8dc7924898 (patch) | |
tree | 65e147c2934fb6b2eae72aaf309a71f032c3ea76 /gdb/target.h | |
parent | 451953fa440aa0ade02b652159155fae689483a3 (diff) | |
download | gdb-1524450719d3867e10fc6a8dbc051b8dc7924898.zip gdb-1524450719d3867e10fc6a8dbc051b8dc7924898.tar.gz gdb-1524450719d3867e10fc6a8dbc051b8dc7924898.tar.bz2 |
Heap-allocate core_target instances
This gets rid of the core_ops global, and replaces it with
heap-allocated core_target instances. In practice, there will only be
one such instance, though that will change further ahead as more
pieces of multi-target support are merged.
Notice that this replaces one heap-allocated object for another, the
number of allocations is the same. Specifically, currently we
heap-allocate the 'core_data' object, which holds the core's section
table. With this patch, that object is made a field of the
core_target class, and no longer allocated separately.
Note that this bit:
- /* Looks semi-reasonable. Toss the old core file and work on the
- new. */
-
- unpush_target (&core_ops);
does not need a replacement, because by the time we get here, the
target_preopen call at the top of core_target_open has already
unpushed any previous target.
gdb/ChangeLog:
2018-05-11 Pedro Alves <palves@redhat.com>
* corelow.c (core_target) <core_target>: No longer inline.
Initialize m_core_gdbarch, m_core_vec and build the section table
here.
<~core_target>: New.
<core_gdbarch, get_core_register_section>: New methods.
<m_core_section_table, m_core_vec, m_core_gdbarch>: New fields,
factored out from ...
<core_data, core_vec, core_gdbarch>: ... these deleted globals.
(core_ops): Delete.
(sniff_core_bfd): Add gdbarch parameter.
(core_close): Delete, merged into ...
(core_target::close): ... here. Delete self.
(core_close_cleanup): Delete.
(core_target_open): Allocate a core_target on the heap. Use a
unique_ptr instead of a cleanup. Bits moved into the core_target
ctor. Adjust to use core_target methods instead of globals.
(get_core_register_section): Rename to ...
(core_target::get_core_register_section): ... this and adjust.
(struct get_core_registers_cb_data): New.
(get_core_registers_cb): Use it. Use bool.
(core_target::fetch_registers, core_target::files_info)
(core_target::xfer_partial, core_target::read_description)
(core_target::pid_to, core_target::thread_name): Adjust to
reference class fields instead of globals.
* target.h (struct target_ops_deleter, target_ops_up): New.
Diffstat (limited to 'gdb/target.h')
-rw-r--r-- | gdb/target.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gdb/target.h b/gdb/target.h index b37702b..e2d1e61 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1243,6 +1243,20 @@ struct target_ops TARGET_DEFAULT_IGNORE (); }; +/* Deleter for std::unique_ptr. See comments in + target_ops::~target_ops and target_ops::close about heap-allocated + targets. */ +struct target_ops_deleter +{ + void operator() (target_ops *target) + { + target->close (); + } +}; + +/* A unique pointer for target_ops. */ +typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up; + /* Native target backends call this once at initialization time to inform the core about which is the target that can respond to "run" or "attach". Note: native targets are always singletons. */ |