From 1f45808ead357e8a81dec16b9802a6c369e08426 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 8 Nov 2016 15:26:43 +0000 Subject: 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 * 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 and . (struct memrange): Add constructors. (struct collection_list): Now a class. (class collection_list) : New methods. : Rename to ... : ... this. : Delete fields. : New field. : Delete fields. : New field. : Rename to ... : ... this. Now a bool. : Rename to ... : ... this. Now a std::vector. : Rename to ... : ... this. Now a std::vector. (encode_actions_and_make_cleanup): Delete declaration. (encode_actions): New declaration. --- gdb/tracepoint.h | 72 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 16 deletions(-) (limited to 'gdb/tracepoint.h') diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index 8985394..d3571b1 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -24,6 +24,9 @@ #include "memrange.h" #include "gdb_vecs.h" +#include +#include + /* 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 { +public: + collection_list (); + ~collection_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 &wholly_collected () + { return m_wholly_collected; } + + const std::vector &computed () + { return m_computed; } + +private: /* room for up to 256 regs */ - unsigned char regs_mask[32]; - long listsize; - long next_memrange; - struct memrange *list; + unsigned char m_regs_mask[32]; + + std::vector m_memranges; - /* size of array pointed to by expr_list elt. */ - long aexpr_listsize; - long next_aexpr_elt; - struct agent_expr **aexpr_list; + /* Vector owns pointers. */ + std::vector 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 m_wholly_collected; /* A set of computed expressions. */ - VEC(char_ptr) *computed; + std::vector 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); -- cgit v1.1