Make to_traceframe_info return a unique_ptr

Since this target method returns an allocated object, return a
unique_ptr.  It allows getting rid a some cleanups here and there.

I had to shuffle the includes around.  First, target.h now needs to
include tracepoint.h, to get the definition of traceframe_info_up.
However, the definition of enum trace_find_type was later in target, so
I had to move it to tracepoint.h, so that the declaration of tfind_1
could know about it.  I then had to remove the include of target.h from
tracepoint.h, which caused a circular dependency (it was probably
included to get enum trace_find_type in the first place anyway).

Regression tested on the buildbot.

gdb/ChangeLog:

	* target.h: Include tracepoint.h.
	(enum trace_find_type): Move to tracepoint.h.
	(struct target_ops) <to_traceframe_info>: Return a unique ptr.
	* tracepoint.h: Don't include target.h
	(enum trace_find_type): Move from target.h.
	(parse_traceframe_info): Return a unique ptr.
	* tracepoint.c (current_traceframe_info): Change type to unique
	ptr.
	(free_traceframe_info): Remove.
	(clear_traceframe_info): Don't manually free
	current_traceframe_info.
	(free_result): Remove.
	(parse_traceframe_info): Return a unique ptr.
	(get_traceframe_info): Adjust to unique ptr.
	* ctf.c (ctf_traceframe_info): Return a unique ptr.
	* remote.c (remote_traceframe_info): Return a unique ptr.
	* tracefile-tfile.c (tfile_traceframe_info): Return a unique
	ptr.
	* target-debug.h (target_debug_print_traceframe_info_up): New
	macro.
	* target-delegates.c: Regenerate.
This commit is contained in:
Simon Marchi 2017-10-14 08:47:44 -04:00 committed by Simon Marchi
parent 4cdd21a8d3
commit 2098b39391
9 changed files with 63 additions and 63 deletions

View File

@ -1,3 +1,27 @@
2017-10-14 Simon Marchi <simon.marchi@polymtl.ca>
* target.h: Include tracepoint.h.
(enum trace_find_type): Move to tracepoint.h.
(struct target_ops) <to_traceframe_info>: Return a unique ptr.
* tracepoint.h: Don't include target.h
(enum trace_find_type): Move from target.h.
(parse_traceframe_info): Return a unique ptr.
* tracepoint.c (current_traceframe_info): Change type to unique
ptr.
(free_traceframe_info): Remove.
(clear_traceframe_info): Don't manually free
current_traceframe_info.
(free_result): Remove.
(parse_traceframe_info): Return a unique ptr.
(get_traceframe_info): Adjust to unique ptr.
* ctf.c (ctf_traceframe_info): Return a unique ptr.
* remote.c (remote_traceframe_info): Return a unique ptr.
* tracefile-tfile.c (tfile_traceframe_info): Return a unique
ptr.
* target-debug.h (target_debug_print_traceframe_info_up): New
macro.
* target-delegates.c: Regenerate.
2017-10-14 Simon Marchi <simon.marchi@polymtl.ca>
* memrange.h (struct mem_range): Add constructors.

View File

@ -1635,10 +1635,10 @@ ctf_trace_find (struct target_ops *self, enum trace_find_type type, int num,
frame, extract memory range information, and return them in
traceframe_info. */
static struct traceframe_info *
static traceframe_info_up
ctf_traceframe_info (struct target_ops *self)
{
traceframe_info *info = new traceframe_info;
traceframe_info_up info (new traceframe_info);
const char *name;
struct bt_iter_pos *pos;

View File

@ -13061,7 +13061,7 @@ remote_set_circular_trace_buffer (struct target_ops *self, int val)
error (_("Bogus reply from target: %s"), reply);
}
static struct traceframe_info *
static traceframe_info_up
remote_traceframe_info (struct target_ops *self)
{
char *text;
@ -13070,10 +13070,9 @@ remote_traceframe_info (struct target_ops *self)
TARGET_OBJECT_TRACEFRAME_INFO, NULL);
if (text != NULL)
{
struct traceframe_info *info;
struct cleanup *back_to = make_cleanup (xfree, text);
traceframe_info_up info = parse_traceframe_info (text);
info = parse_traceframe_info (text);
do_cleanups (back_to);
return info;
}

View File

@ -164,6 +164,8 @@
target_debug_do_print (plongest (X))
#define target_debug_print_gdb_disassembly_flags(X) \
target_debug_do_print (plongest (X))
#define target_debug_print_traceframe_info_up(X) \
target_debug_do_print (host_address_to_string (X.get ()))
static void
target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)

View File

@ -3357,29 +3357,29 @@ debug_static_tracepoint_markers_by_strid (struct target_ops *self, const char *a
return result;
}
static struct traceframe_info *
static traceframe_info_up
delegate_traceframe_info (struct target_ops *self)
{
self = self->beneath;
return self->to_traceframe_info (self);
}
static struct traceframe_info *
static traceframe_info_up
tdefault_traceframe_info (struct target_ops *self)
{
tcomplain ();
}
static struct traceframe_info *
static traceframe_info_up
debug_traceframe_info (struct target_ops *self)
{
struct traceframe_info * result;
traceframe_info_up result;
fprintf_unfiltered (gdb_stdlog, "-> %s->to_traceframe_info (...)\n", debug_target.to_shortname);
result = debug_target.to_traceframe_info (&debug_target);
fprintf_unfiltered (gdb_stdlog, "<- %s->to_traceframe_info (", debug_target.to_shortname);
target_debug_print_struct_target_ops_p (&debug_target);
fputs_unfiltered (") = ", gdb_stdlog);
target_debug_print_struct_traceframe_info_p (result);
target_debug_print_traceframe_info_up (result);
fputs_unfiltered ("\n", gdb_stdlog);
return result;
}

View File

@ -76,6 +76,7 @@ struct inferior;
#include "record.h"
#include "command.h"
#include "disasm.h"
#include "tracepoint.h"
#include "break-common.h" /* For enum target_hw_bp_type. */
@ -235,18 +236,6 @@ enum target_xfer_status
extern const char *
target_xfer_status_to_string (enum target_xfer_status status);
/* Enumeration of the kinds of traceframe searches that a target may
be able to perform. */
enum trace_find_type
{
tfind_number,
tfind_pc,
tfind_tp,
tfind_range,
tfind_outside,
};
typedef struct static_tracepoint_marker *static_tracepoint_marker_p;
DEF_VEC_P(static_tracepoint_marker_p);
@ -1116,8 +1105,8 @@ struct target_ops
traceframe's contents. This method should not cache data;
higher layers take care of caching, invalidating, and
re-fetching when necessary. */
struct traceframe_info *(*to_traceframe_info) (struct target_ops *)
TARGET_DEFAULT_NORETURN (tcomplain ());
traceframe_info_up (*to_traceframe_info) (struct target_ops *)
TARGET_DEFAULT_NORETURN (tcomplain ());
/* Ask the target to use or not to use agent according to USE. Return 1
successful, 0 otherwise. */

View File

@ -1088,12 +1088,13 @@ build_traceframe_info (char blocktype, void *data)
return 0;
}
static struct traceframe_info *
static traceframe_info_up
tfile_traceframe_info (struct target_ops *self)
{
traceframe_info *info = new traceframe_info;
traceframe_info_up info (new traceframe_info);
traceframe_walk_blocks (build_traceframe_info, 0, info.get ());
traceframe_walk_blocks (build_traceframe_info, 0, info);
return info;
}

View File

@ -133,7 +133,7 @@ static int tracepoint_number;
yet attempted to fetch it, or if the target does not support
fetching this object, or if we're not inspecting a traceframe
presently. */
static struct traceframe_info *current_traceframe_info;
static traceframe_info_up current_traceframe_info;
/* Tracing command lists. */
static struct cmd_list_element *tfindlist;
@ -191,21 +191,12 @@ current_trace_status (void)
return &trace_status;
}
/* Destroy INFO. */
static void
free_traceframe_info (struct traceframe_info *info)
{
delete info;
}
/* Free and clear the traceframe info cache of the current
traceframe. */
static void
clear_traceframe_info (void)
{
free_traceframe_info (current_traceframe_info);
current_traceframe_info = NULL;
}
@ -4020,16 +4011,6 @@ traceframe_info_start_tvar (struct gdb_xml_parser *parser,
info->tvars.push_back (id);
}
/* Discard the constructed trace frame info (if an error occurs). */
static void
free_result (void *p)
{
struct traceframe_info *result = (struct traceframe_info *) p;
free_traceframe_info (result);
}
/* The allowed elements and attributes for an XML memory map. */
static const struct gdb_xml_attribute memory_attributes[] = {
@ -4061,25 +4042,16 @@ static const struct gdb_xml_element traceframe_info_elements[] = {
/* Parse a traceframe-info XML document. */
struct traceframe_info *
traceframe_info_up
parse_traceframe_info (const char *tframe_info)
{
traceframe_info *result = new traceframe_info;
struct cleanup *back_to;
back_to = make_cleanup (free_result, result);
traceframe_info_up result (new traceframe_info);
if (gdb_xml_parse_quick (_("trace frame info"),
"traceframe-info.dtd", traceframe_info_elements,
tframe_info, result) == 0)
{
/* Parsed successfully, keep the result. */
discard_cleanups (back_to);
tframe_info, result.get ()) == 0)
return result;
return result;
}
do_cleanups (back_to);
return NULL;
}
@ -4095,7 +4067,7 @@ get_traceframe_info (void)
if (current_traceframe_info == NULL)
current_traceframe_info = target_traceframe_info ();
return current_traceframe_info;
return current_traceframe_info.get ();
}
/* If the target supports the query, return in RESULT the set of

View File

@ -20,7 +20,6 @@
#define TRACEPOINT_H 1
#include "breakpoint.h"
#include "target.h"
#include "memrange.h"
#include "gdb_vecs.h"
@ -38,6 +37,8 @@ struct traceframe_info
std::vector<int> tvars;
};
typedef std::unique_ptr<traceframe_info> traceframe_info_up;
/* A trace state variable is a value managed by a target being
traced. A trace state variable (or tsv for short) can be accessed
and assigned to by tracepoint actions and conditionals, but is not
@ -376,6 +377,18 @@ extern void trace_status_mi (int on_stop);
extern void tvariables_info_1 (void);
extern void save_trace_state_variables (struct ui_file *fp);
/* Enumeration of the kinds of traceframe searches that a target may
be able to perform. */
enum trace_find_type
{
tfind_number,
tfind_pc,
tfind_tp,
tfind_range,
tfind_outside,
};
extern void tfind_1 (enum trace_find_type type, int num,
CORE_ADDR addr1, CORE_ADDR addr2,
int from_tty);
@ -385,7 +398,7 @@ extern void trace_save_tfile (const char *filename,
extern void trace_save_ctf (const char *dirname,
int target_does_save);
extern struct traceframe_info *parse_traceframe_info (const char *tframe_info);
extern traceframe_info_up parse_traceframe_info (const char *tframe_info);
extern int traceframe_available_memory (VEC(mem_range_s) **result,
CORE_ADDR memaddr, ULONGEST len);