Clean up tracepoint.h/c:collection_list

Noticed we could do this while working on the expression_up change.

The main goal here was getting rid of the
encode_actions_and_make_cleanup / do_clear_collection_list cleanups.

While at it, uncrustify the code:

 - Make collection_list a C++ class, with data members private (and
   thus renamed m_...).

 - Make related functions be member methods.

 - Use std::vector instead of an open coding a vector implementation.

 - Use std::sort instead of qsort.

 - Rename the "list" member of collection_list, which is an incredibly
   obfuscating name.

 - Rename a couple other things here and there for clarify.

 - Use "bool" more.

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

	* mi/mi-main.c (print_variable_or_computed): Constify 'expression'
	parameter.
	(mi_cmd_trace_frame_collected): Call encode_actions instead of
	encode_actions_and_make_cleanup.  Adjust to use std::vector.
	* tracepoint.c (memrange_cmp): Delete.
	(memrange_comp): New.
	(memrange_sortmerge): Take a memrange vector as parameter instead
	of a collection_list.  Use std::sort instead of qsort.
	(add_register): Now a method of collection_list.  Adjust to m_
	prefix of data fields.
	(add_memrange): Now a method of collection_list.  Adjust to m_
	prefix of data fields.  Adjust to use std::vector.
	(collect_symbol): Now a method of collection_list.  Adjust to m_
	prefix of data fields.
	(do_collect_symbol): Adjust.  Call add_wholly_collected instead of
	accessing the vector directly.
	(collection_list::add_wholly_collected): New.
	(add_local_symbols): Now a method of collection_list.
	(add_static_trace_data): Now a method of collection_list.  Adjust
	to use bool.
	(clear_collection_list, do_clear_collection_list): Delete.
	(init_collection_list): Delete.
	(collection_list::collection_list): New.
	(collection_list::~collection_list): New.
	(stringify_collection_list): Rename to ...
	(collection_list::stringify): ... this and adjust to being a
	method of collection_list.  Adjust to use of std::vector.
	(append_exp): Now a method of collection_list.  Use
	ui_file_as_string.  Adjust to std::vector.
	(collection_list::finish): New.
	(encode_actions_1): Adjust.
	(encode_actions_and_make_cleanup): Rename to ...
	(encode_actions)... this.  No longer returns a cleanup.  No longer
	call init_collection_list nor install do_clear_collection_list
	cleanups.  Call collection_list::finish instead of
	memrange_sortmerge directly.
	(encode_actions_rsp): Adjust to call encode_actions instead of
	encode_actions_and_make_cleanup.  Adjust to method renames.
	(add_aexpr): Now a method of collection_list.
	* tracepoint.h: Include <vector> and <string>.
	(struct memrange): Add constructors.
	(struct collection_list): Now a class.
	(class collection_list) <collection_list, ~collection_list,
	add_wholly_collected, append_exp, add_aexpr, add_register,
	add_memrange, collect_symbol, add_local_symbols,
	add_static_trace_data, finish, stringify, wholly_collected, and
	computed>: New methods.
	<regs_mask>: Rename to ...
	<m_regs_mask>: ... this.
	<listsize, next_memrange, list>: Delete fields.
	<m_memranges>: New field.
	<aexpr_listsize, next_aexpr_elt, aexpr_list>: Delete fields.
	<m_aexprs>: New field.
	<strace_data>: Rename to ...
	<m_strace_data>: ... this.  Now a bool.
	<wholly_collected>: Rename to ...
	<m_wholly_collected>: ... this.  Now a std::vector<std::string>.
	<computed>: Rename to ...
	<m_computed>: ... this.  Now a std::vector<std::string>.
	(encode_actions_and_make_cleanup): Delete declaration.
	(encode_actions): New declaration.
This commit is contained in:
Pedro Alves 2016-11-08 15:26:43 +00:00
parent 8de00631b8
commit 1f45808ead
4 changed files with 303 additions and 264 deletions

View file

@ -24,6 +24,9 @@
#include "memrange.h"
#include "gdb_vecs.h"
#include <vector>
#include <string>
/* An object describing the contents of a traceframe. */
struct traceframe_info
@ -222,6 +225,13 @@ struct static_tracepoint_marker
struct memrange
{
memrange (int type_, bfd_signed_vma start_, bfd_signed_vma end_)
: type (type_), start (start_), end (end_)
{}
memrange ()
{}
/* memrange_absolute for absolute memory range, else basereg
number. */
int type;
@ -229,27 +239,58 @@ struct memrange
bfd_signed_vma end;
};
struct collection_list
class collection_list
{
/* room for up to 256 regs */
unsigned char regs_mask[32];
long listsize;
long next_memrange;
struct memrange *list;
public:
collection_list ();
~collection_list ();
/* size of array pointed to by expr_list elt. */
long aexpr_listsize;
long next_aexpr_elt;
struct agent_expr **aexpr_list;
void add_wholly_collected (const char *print_name);
void append_exp (struct expression *exp);
void add_aexpr (struct agent_expr *aexpr);
void add_register (unsigned int regno);
void add_memrange (int type, bfd_signed_vma base,
unsigned long len);
void collect_symbol (struct symbol *sym,
struct gdbarch *gdbarch,
long frame_regno, long frame_offset,
CORE_ADDR scope,
int trace_string);
void add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc,
long frame_regno, long frame_offset, int type,
int trace_string);
void add_static_trace_data ();
void finish ();
char **stringify ();
const std::vector<std::string> &wholly_collected ()
{ return m_wholly_collected; }
const std::vector<std::string> &computed ()
{ return m_computed; }
private:
/* room for up to 256 regs */
unsigned char m_regs_mask[32];
std::vector<memrange> m_memranges;
/* Vector owns pointers. */
std::vector<agent_expr *> m_aexprs;
/* True is the user requested a collection of "$_sdata", "static
tracepoint data". */
int strace_data;
bool m_strace_data;
/* A set of names of wholly collected objects. */
VEC(char_ptr) *wholly_collected;
std::vector<std::string> m_wholly_collected;
/* A set of computed expressions. */
VEC(char_ptr) *computed;
std::vector<std::string> m_computed;
};
extern void parse_static_tracepoint_marker_definition
@ -280,10 +321,9 @@ void free_actions (struct breakpoint *);
extern const char *decode_agent_options (const char *exp, int *trace_string);
extern struct cleanup *
encode_actions_and_make_cleanup (struct bp_location *tloc,
struct collection_list *tracepoint_list,
struct collection_list *stepping_list);
extern void encode_actions (struct bp_location *tloc,
struct collection_list *tracepoint_list,
struct collection_list *stepping_list);
extern void encode_actions_rsp (struct bp_location *tloc,
char ***tdp_actions, char ***stepping_actions);