From patchwork Sat Oct 21 07:01:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 23745 Received: (qmail 108916 invoked by alias); 21 Oct 2017 07:01:54 -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 108722 invoked by uid 89); 21 Oct 2017 07:01:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=2114 X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 21 Oct 2017 07:01:51 +0000 X-ASG-Debug-ID: 1508569307-0c856e65d53809fc0001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id cf9dMjD1gK78fdwM (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Oct 2017 03:01:47 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-192.222.251.162.electronicbox.net [192.222.251.162]) by smtp.electronicbox.net (Postfix) with ESMTP id 59ADB441B21; Sat, 21 Oct 2017 03:01:43 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-192.222.251.162.electronicbox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/2] Get rid of VEC(probe_p) Date: Sat, 21 Oct 2017 03:01:34 -0400 X-ASG-Orig-Subj: [PATCH 2/2] Get rid of VEC(probe_p) Message-Id: <20171021070134.3962-2-simon.marchi@polymtl.ca> In-Reply-To: <20171021070134.3962-1-simon.marchi@polymtl.ca> References: <20171021070134.3962-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1508569307 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 10187 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.44080 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes From: Simon Marchi Replace the remaining usages of VEC(probe_p) with std::vector. Regtested on the buildbot. gdb/ChangeLog: * probe.h: Don't include gdb_vecs.h. (DEF_VEC_P (probe_p)): Remove. (find_probes_in_objfile): Return an std::vector. * probe.c (find_probes_in_objfile): Likewise. * breakpoint.c (breakpoint_objfile_data) : Change type to std::vector. : Likewise. (free_breakpoint_probes): Don't manually free vectors. (create_longjmp_master_breakpoint): Adjust. (create_exception_master_breakpoint): Adjust. * solib-svr4.c (svr4_create_probe_breakpoints): Change parameter type, adjust. (svr4_create_solib_event_breakpoints): Adjust. --- gdb/breakpoint.c | 64 ++++++++++++++++++++------------------------------------ gdb/probe.c | 8 +++---- gdb/probe.h | 14 +++---------- gdb/solib-svr4.c | 29 ++++++++----------------- 4 files changed, 39 insertions(+), 76 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 301d7aabff..246507a1f1 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -3191,8 +3191,9 @@ struct breakpoint_objfile_data /* True if we have looked for longjmp probes. */ int longjmp_searched = 0; - /* SystemTap probe points for longjmp (if any). */ - VEC (probe_p) *longjmp_probes = NULL; + /* SystemTap probe points for longjmp (if any). These are non-owning + references. */ + std::vector longjmp_probes; /* Minimal symbol for "std::terminate()" (if any). */ struct bound_minimal_symbol terminate_msym {}; @@ -3203,8 +3204,9 @@ struct breakpoint_objfile_data /* True if we have looked for exception probes. */ int exception_searched = 0; - /* SystemTap probe points for unwinding (if any). */ - VEC (probe_p) *exception_probes = NULL; + /* SystemTap probe points for unwinding (if any). These are non-owning + references. */ + std::vector exception_probes; }; static const struct objfile_data *breakpoint_objfile_key; @@ -3244,9 +3246,6 @@ free_breakpoint_objfile_data (struct objfile *obj, void *data) struct breakpoint_objfile_data *bp_objfile_data = (struct breakpoint_objfile_data *) data; - VEC_free (probe_p, bp_objfile_data->longjmp_probes); - VEC_free (probe_p, bp_objfile_data->exception_probes); - delete bp_objfile_data; } @@ -3328,43 +3327,35 @@ create_longjmp_master_breakpoint (void) if (!bp_objfile_data->longjmp_searched) { - VEC (probe_p) *ret; + std::vector ret + = find_probes_in_objfile (objfile, "libc", "longjmp"); - ret = find_probes_in_objfile (objfile, "libc", "longjmp"); - if (ret != NULL) + if (!ret.empty ()) { /* We are only interested in checking one element. */ - struct probe *p = VEC_index (probe_p, ret, 0); + probe *p = ret[0]; if (!can_evaluate_probe_arguments (p)) { /* We cannot use the probe interface here, because it does not know how to evaluate arguments. */ - VEC_free (probe_p, ret); - ret = NULL; + ret.clear (); } } bp_objfile_data->longjmp_probes = ret; bp_objfile_data->longjmp_searched = 1; } - if (bp_objfile_data->longjmp_probes != NULL) + if (!bp_objfile_data->longjmp_probes.empty ()) { - int i; - struct probe *probe; struct gdbarch *gdbarch = get_objfile_arch (objfile); - for (i = 0; - VEC_iterate (probe_p, - bp_objfile_data->longjmp_probes, - i, probe); - ++i) + for (probe *p : bp_objfile_data->longjmp_probes) { struct breakpoint *b; b = create_internal_breakpoint (gdbarch, - get_probe_address (probe, - objfile), + get_probe_address (p, objfile), bp_longjmp_master, &internal_breakpoint_ops); b->location = new_probe_location ("-probe-stap libc:longjmp"); @@ -3489,44 +3480,35 @@ create_exception_master_breakpoint (void) /* We prefer the SystemTap probe point if it exists. */ if (!bp_objfile_data->exception_searched) { - VEC (probe_p) *ret; - - ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); + std::vector ret + = find_probes_in_objfile (objfile, "libgcc", "unwind"); - if (ret != NULL) + if (!ret.empty ()) { /* We are only interested in checking one element. */ - struct probe *p = VEC_index (probe_p, ret, 0); + probe *p = ret[0]; if (!can_evaluate_probe_arguments (p)) { /* We cannot use the probe interface here, because it does not know how to evaluate arguments. */ - VEC_free (probe_p, ret); - ret = NULL; + ret.clear (); } } bp_objfile_data->exception_probes = ret; bp_objfile_data->exception_searched = 1; } - if (bp_objfile_data->exception_probes != NULL) + if (!bp_objfile_data->exception_probes.empty ()) { struct gdbarch *gdbarch = get_objfile_arch (objfile); - int i; - struct probe *probe; - - for (i = 0; - VEC_iterate (probe_p, - bp_objfile_data->exception_probes, - i, probe); - ++i) + + for (probe *p : bp_objfile_data->exception_probes) { struct breakpoint *b; b = create_internal_breakpoint (gdbarch, - get_probe_address (probe, - objfile), + get_probe_address (p, objfile), bp_exception_master, &internal_breakpoint_ops); b->location = new_probe_location ("-probe-stap libgcc:unwind"); diff --git a/gdb/probe.c b/gdb/probe.c index ba40959126..829f6d18d7 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -193,14 +193,14 @@ parse_probes (const struct event_location *location, /* See definition in probe.h. */ -VEC (probe_p) * +std::vector find_probes_in_objfile (struct objfile *objfile, const char *provider, const char *name) { - VEC (probe_p) *result = NULL; + std::vector result; if (!objfile->sf || !objfile->sf->sym_probe_fns) - return NULL; + return result; const std::vector &probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); @@ -212,7 +212,7 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider, if (strcmp (p->name, name) != 0) continue; - VEC_safe_push (probe_p, result, p); + result.push_back (p); } return result; diff --git a/gdb/probe.h b/gdb/probe.h index 1b3916602a..c44a308d9b 100644 --- a/gdb/probe.h +++ b/gdb/probe.h @@ -21,14 +21,6 @@ #define PROBE_H 1 struct event_location; - -#include "gdb_vecs.h" - -/* Definition of a vector of probes. */ - -typedef struct probe *probe_p; -DEF_VEC_P (probe_p); - struct linespec_result; /* Structure useful for passing the header names in the method @@ -257,9 +249,9 @@ extern struct bound_probe find_probe_by_pc (CORE_ADDR pc); VEC of all probes that were found. If no matching probe is found, return NULL. The caller must free the VEC. */ -extern VEC (probe_p) *find_probes_in_objfile (struct objfile *objfile, - const char *provider, - const char *name); +extern std::vector find_probes_in_objfile (struct objfile *objfile, + const char *provider, + const char *name); /* Generate a `info probes' command output for probe_ops represented by POPS. If POPS is NULL it considers any probes types. It is a helper diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index bf2577a433..5ec606de43 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2075,25 +2075,19 @@ svr4_update_solib_event_breakpoints (void) static void svr4_create_probe_breakpoints (struct gdbarch *gdbarch, - VEC (probe_p) **probes, + const std::vector *probes, struct objfile *objfile) { - int i; - - for (i = 0; i < NUM_PROBES; i++) + for (int i = 0; i < NUM_PROBES; i++) { enum probe_action action = probe_info[i].action; - struct probe *probe; - int ix; - for (ix = 0; - VEC_iterate (probe_p, probes[i], ix, probe); - ++ix) + for (probe *p : probes[i]) { - CORE_ADDR address = get_probe_address (probe, objfile); + CORE_ADDR address = get_probe_address (p, objfile); create_solib_event_breakpoint (gdbarch, address); - register_solib_event_probe (probe, address, action); + register_solib_event_probe (p, address, action); } } @@ -2125,13 +2119,11 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch, for (with_prefix = 0; with_prefix <= 1; with_prefix++) { - VEC (probe_p) *probes[NUM_PROBES]; + std::vector probes[NUM_PROBES]; int all_probes_found = 1; int checked_can_use_probe_arguments = 0; - int i; - memset (probes, 0, sizeof (probes)); - for (i = 0; i < NUM_PROBES; i++) + for (int i = 0; i < NUM_PROBES; i++) { const char *name = probe_info[i].name; struct probe *p; @@ -2158,7 +2150,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch, if (strcmp (name, "rtld_map_failed") == 0) continue; - if (VEC_empty (probe_p, probes[i])) + if (probes[i].empty ()) { all_probes_found = 0; break; @@ -2167,7 +2159,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch, /* Ensure probe arguments can be evaluated. */ if (!checked_can_use_probe_arguments) { - p = VEC_index (probe_p, probes[i], 0); + p = probes[i][0]; if (!can_evaluate_probe_arguments (p)) { all_probes_found = 0; @@ -2180,9 +2172,6 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch, if (all_probes_found) svr4_create_probe_breakpoints (gdbarch, probes, os->objfile); - for (i = 0; i < NUM_PROBES; i++) - VEC_free (probe_p, probes[i]); - if (all_probes_found) return; }