From patchwork Wed Jul 19 20:32:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 21694 Received: (qmail 19461 invoked by alias); 19 Jul 2017 20:54:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19410 invoked by uid 89); 19 Jul 2017 20:54:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-22.5 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, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy=readily X-HELO: gproxy4.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Jul 2017 20:54:00 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id DFC4C177BAC for ; Wed, 19 Jul 2017 14:32:33 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id mkYW1v0162f2jeq01kYZVT; Wed, 19 Jul 2017 14:32:33 -0600 X-Authority-Analysis: v=2.2 cv=UM2tJGXy c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=G3gG6ho9WtcA:10 a=zstS-IiYAAAA:8 a=PMDf129cQ9M9K2jXu1wA:9 a=qXwPyjxP7Nrbhx6B:21 a=zqssYzrhVeD8n_6e:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-29-39-24.hlrn.qwest.net ([174.29.39.24]:39320 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dXve2-004HUQ-Nr; Wed, 19 Jul 2017 14:32:30 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 4/4] Use std::vector in struct catch_syscall_inferior_data Date: Wed, 19 Jul 2017 14:32:25 -0600 Message-Id: <20170719203225.6714-5-tom@tromey.com> In-Reply-To: <20170719203225.6714-1-tom@tromey.com> References: <20170719203225.6714-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dXve2-004HUQ-Nr X-Source-Sender: 174-29-39-24.hlrn.qwest.net (bapiya.Home) [174.29.39.24]:39320 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes struct catch_syscall_inferior_data to use a std::vector rather than a VEC. It also changes it to be allocated with new and destroyed with delete. 2017-07-18 Tom Tromey * break-catch-syscall.c (struct catch_syscall_inferior_data) : Now a std::vector. (get_catch_syscall_inferior_data): Use "new". (catch_syscall_inferior_data_cleanup): Use "delete". (insert_catch_syscall, remove_catch_syscall) (clear_syscall_counts): Update. --- gdb/ChangeLog | 9 +++++++++ gdb/break-catch-syscall.c | 47 ++++++++++++++++------------------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fb953ed..4372853 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2017-07-18 Tom Tromey + + * break-catch-syscall.c (struct catch_syscall_inferior_data) + : Now a std::vector. + (get_catch_syscall_inferior_data): Use "new". + (catch_syscall_inferior_data_cleanup): Use "delete". + (insert_catch_syscall, remove_catch_syscall) + (clear_syscall_counts): Update. + 2017-07-17 Tom Tromey * break-catch-syscall.c (syscall_catchpoint) diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index ff0cb69..3df358b 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -54,14 +54,14 @@ struct catch_syscall_inferior_data int any_syscall_count; /* Count of each system call. */ - VEC(int) *syscalls_counts; + std::vector syscalls_counts; /* This counts all syscall catch requests, so we can readily determine if any catching is necessary. */ int total_syscalls_count; }; -static struct catch_syscall_inferior_data* +static struct catch_syscall_inferior_data * get_catch_syscall_inferior_data (struct inferior *inf) { struct catch_syscall_inferior_data *inf_data; @@ -70,7 +70,7 @@ get_catch_syscall_inferior_data (struct inferior *inf) inferior_data (inf, catch_syscall_inferior_data)); if (inf_data == NULL) { - inf_data = XCNEW (struct catch_syscall_inferior_data); + inf_data = new struct catch_syscall_inferior_data (); set_inferior_data (inf, catch_syscall_inferior_data, inf_data); } @@ -80,7 +80,9 @@ get_catch_syscall_inferior_data (struct inferior *inf) static void catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) { - xfree (arg); + struct catch_syscall_inferior_data *inf_data + = (struct catch_syscall_inferior_data *) arg; + delete inf_data; } @@ -104,31 +106,17 @@ insert_catch_syscall (struct bp_location *bl) { int elem; - if (iter >= VEC_length (int, inf_data->syscalls_counts)) - { - int old_size = VEC_length (int, inf_data->syscalls_counts); - uintptr_t vec_addr_offset - = old_size * ((uintptr_t) sizeof (int)); - uintptr_t vec_addr; - VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); - vec_addr = ((uintptr_t) VEC_address (int, - inf_data->syscalls_counts) - + vec_addr_offset); - memset ((void *) vec_addr, 0, - (iter + 1 - old_size) * sizeof (int)); - } - elem = VEC_index (int, inf_data->syscalls_counts, iter); - VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); + if (iter >= inf_data->syscalls_counts.size ()) + inf_data->syscalls_counts.resize (iter + 1); + ++inf_data->syscalls_counts[iter]; } } return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), inf_data->total_syscalls_count != 0, inf_data->any_syscall_count, - VEC_length (int, - inf_data->syscalls_counts), - VEC_address (int, - inf_data->syscalls_counts)); + inf_data->syscalls_counts.size (), + inf_data->syscalls_counts.data ()); } /* Implement the "remove" breakpoint_ops method for syscall @@ -150,21 +138,18 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason) for (int iter : c->syscalls_to_be_caught) { int elem; - if (iter >= VEC_length (int, inf_data->syscalls_counts)) + if (iter >= inf_data->syscalls_counts.size ()) /* Shouldn't happen. */ continue; - elem = VEC_index (int, inf_data->syscalls_counts, iter); - VEC_replace (int, inf_data->syscalls_counts, iter, --elem); + --inf_data->syscalls_counts[iter]; } } return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), inf_data->total_syscalls_count != 0, inf_data->any_syscall_count, - VEC_length (int, - inf_data->syscalls_counts), - VEC_address (int, - inf_data->syscalls_counts)); + inf_data->syscalls_counts.size (), + inf_data->syscalls_counts.data ()); } /* Implement the "breakpoint_hit" breakpoint_ops method for syscall @@ -628,7 +613,7 @@ clear_syscall_counts (struct inferior *inf) inf_data->total_syscalls_count = 0; inf_data->any_syscall_count = 0; - VEC_free (int, inf_data->syscalls_counts); + inf_data->syscalls_counts.clear (); } static void