From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116925 invoked by alias); 12 Sep 2017 18:57:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 116792 invoked by uid 89); 12 Sep 2017 18:57:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 18:57:46 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 68C22176143 for ; Tue, 12 Sep 2017 12:57:45 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 8ixi1w00N2f2jeq01ixlse; Tue, 12 Sep 2017 12:57:45 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=4Qr6ZDGys_xgsNAJZ8MA:9 a=_4ZR1d0fLeCCcofM:21 a=ceZKAq5Sa3ueXafA:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:46142 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1drqNS-001eRR-BE; Tue, 12 Sep 2017 12:57:42 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 09/11] Use std::set in mi-main.c Date: Tue, 12 Sep 2017 18:57:00 -0000 Message-Id: <20170912185736.20436-10-tom@tromey.com> In-Reply-To: <20170912185736.20436-1-tom@tromey.com> References: <20170912185736.20436-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1drqNS-001eRR-BE X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:46142 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-09/txt/msg00348.txt.bz2 Change a couple of spots in mi-main.c to use std::set. This simplifies the code and removes some cleanups. ChangeLog 2017-09-12 Tom Tromey * mi/mi-main.c (struct print_one_inferior_data) : Now a 'std::set *'. (print_one_inferior): Update. (free_vector_of_ints): Remove. (list_available_thread_groups): Change "ids" to std::set. (mi_cmd_list_thread_groups): Update. (struct collect_cores_data) : Now a std::set. (collect_cores): Update. (unique): Remove. (print_one_inferior): Update. --- gdb/ChangeLog | 13 ++++++++++ gdb/mi/mi-main.c | 77 +++++++++++++------------------------------------------- 2 files changed, 31 insertions(+), 59 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6368f41..54928fc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,18 @@ 2017-09-12 Tom Tromey + * mi/mi-main.c (struct print_one_inferior_data) : Now a + 'std::set *'. + (print_one_inferior): Update. + (free_vector_of_ints): Remove. + (list_available_thread_groups): Change "ids" to std::set. + (mi_cmd_list_thread_groups): Update. + (struct collect_cores_data) : Now a std::set. + (collect_cores): Update. + (unique): Remove. + (print_one_inferior): Update. + +2017-09-12 Tom Tromey + * mi/mi-main.c (mi_execute_cli_command): Use unique_xmalloc_ptr. (mi_execute_async_cli_command): Likewise. (mi_cmd_trace_frame_collected): Use std::string. diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 0147fb9..3d73446 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -62,6 +62,8 @@ #include #include "progspace-and-thread.h" #include "common/rsp-low.h" +#include +#include enum { @@ -604,8 +606,7 @@ mi_cmd_thread_info (const char *command, char **argv, int argc) struct collect_cores_data { int pid; - - VEC (int) *cores; + std::set cores; }; static int @@ -618,27 +619,16 @@ collect_cores (struct thread_info *ti, void *xdata) int core = target_core_of_thread (ti->ptid); if (core != -1) - VEC_safe_push (int, data->cores, core); + data->cores.insert (core); } return 0; } -static int * -unique (int *b, int *e) -{ - int *d = b; - - while (++b != e) - if (*d != *b) - *++d = *b; - return ++d; -} - struct print_one_inferior_data { int recurse; - VEC (int) *inferiors; + const std::set *inferiors; }; static int @@ -648,10 +638,9 @@ print_one_inferior (struct inferior *inferior, void *xdata) = (struct print_one_inferior_data *) xdata; struct ui_out *uiout = current_uiout; - if (VEC_empty (int, top_data->inferiors) - || bsearch (&(inferior->pid), VEC_address (int, top_data->inferiors), - VEC_length (int, top_data->inferiors), sizeof (int), - compare_positive_ints)) + if (top_data->inferiors->empty () + || (top_data->inferiors->find (inferior->pid) + != top_data->inferiors->end ())) { struct collect_cores_data data; ui_out_emit_tuple tuple_emitter (uiout, NULL); @@ -670,28 +659,18 @@ print_one_inferior (struct inferior *inferior, void *xdata) inferior->pspace->pspace_exec_filename); } - data.cores = 0; if (inferior->pid != 0) { data.pid = inferior->pid; iterate_over_threads (collect_cores, &data); } - if (!VEC_empty (int, data.cores)) + if (!data.cores.empty ()) { - int *b, *e; ui_out_emit_list list_emitter (uiout, "cores"); - qsort (VEC_address (int, data.cores), - VEC_length (int, data.cores), sizeof (int), - compare_positive_ints); - - b = VEC_address (int, data.cores); - e = b + VEC_length (int, data.cores); - e = unique (b, e); - - for (; b != e; ++b) - uiout->field_int (NULL, *b); + for (int b : data.cores) + uiout->field_int (NULL, b); } if (top_data->recurse) @@ -717,14 +696,6 @@ output_cores (struct ui_out *uiout, const char *field_name, const char *xcores) } static void -free_vector_of_ints (void *xvector) -{ - VEC (int) **vector = (VEC (int) **) xvector; - - VEC_free (int, *vector); -} - -static void do_nothing (splay_tree_key k) { } @@ -755,7 +726,7 @@ free_splay_tree (void *xt) } static void -list_available_thread_groups (VEC (int) *ids, int recurse) +list_available_thread_groups (const std::set &ids, int recurse) { struct osdata *data; struct osdata_item *item; @@ -824,12 +795,9 @@ list_available_thread_groups (VEC (int) *ids, int recurse) /* At present, the target will return all available processes and if information about specific ones was required, we filter undesired processes here. */ - if (ids && bsearch (&pid_i, VEC_address (int, ids), - VEC_length (int, ids), - sizeof (int), compare_positive_ints) == NULL) + if (!ids.empty () && ids.find (pid_i) != ids.end ()) continue; - ui_out_emit_tuple tuple_emitter (uiout, NULL); uiout->field_fmt ("id", "%s", pid); @@ -875,10 +843,9 @@ void mi_cmd_list_thread_groups (const char *command, char **argv, int argc) { struct ui_out *uiout = current_uiout; - struct cleanup *back_to; int available = 0; int recurse = 0; - VEC (int) *ids = 0; + std::set ids; enum opt { @@ -930,23 +897,17 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc) if (*end != '\0') error (_("invalid syntax of group id '%s'"), argv[oind]); - VEC_safe_push (int, ids, inf); + ids.insert (inf); } - if (VEC_length (int, ids) > 1) - qsort (VEC_address (int, ids), - VEC_length (int, ids), - sizeof (int), compare_positive_ints); - - back_to = make_cleanup (free_vector_of_ints, &ids); if (available) { list_available_thread_groups (ids, recurse); } - else if (VEC_length (int, ids) == 1) + else if (ids.size () == 1) { /* Local thread groups, single id. */ - int id = *VEC_address (int, ids); + int id = *(ids.begin ()); struct inferior *inf = find_inferior_id (id); if (!inf) @@ -959,7 +920,7 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc) struct print_one_inferior_data data; data.recurse = recurse; - data.inferiors = ids; + data.inferiors = &ids; /* Local thread groups. Either no explicit ids -- and we print everything, or several explicit ids. In both cases, @@ -969,8 +930,6 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc) update_thread_list (); iterate_over_inferiors (print_one_inferior, &data); } - - do_cleanups (back_to); } void -- 2.9.4