From patchwork Sun Sep 10 14:22:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 22792 Received: (qmail 30774 invoked by alias); 10 Sep 2017 14:23:16 -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 30651 invoked by uid 89); 10 Sep 2017 14:23:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy= X-HELO: sessmg22.ericsson.net Received: from sessmg22.ericsson.net (HELO sessmg22.ericsson.net) (193.180.251.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Sep 2017 14:23:13 +0000 Received: from ESESSHC023.ericsson.se (Unknown_Domain [153.88.183.87]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id F3.23.20899.ECA45B95; Sun, 10 Sep 2017 16:23:10 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.87) with Microsoft SMTP Server (TLS) id 14.3.352.0; Sun, 10 Sep 2017 16:23:09 +0200 Received: from elxacz23q12.localdomain (95.204.106.138) by AMSPR07MB310.eurprd07.prod.outlook.com (2a01:111:e400:802f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.4; Sun, 10 Sep 2017 14:23:08 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 2/2] Make collect_probes return an std::vector Date: Sun, 10 Sep 2017 16:22:57 +0200 Message-ID: <1505053377-10061-2-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1505053377-10061-1-git-send-email-simon.marchi@ericsson.com> References: <1505053377-10061-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-ClientProxiedBy: HE1PR0301CA0008.eurprd03.prod.outlook.com (2603:10a6:3:76::18) To AMSPR07MB310.eurprd07.prod.outlook.com (2a01:111:e400:802f::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fc35fe1f-db05-4850-fb07-08d4f85775b3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AMSPR07MB310; X-Microsoft-Exchange-Diagnostics: 1; AMSPR07MB310; 3:GxaL1uZbQwQJD+EWFYbNliEs8qpVr2BbSEmXoZ/OAm1SOVA5FmpteAUs6ipoMJmDHkA8n3In2w5gXjw28+8JgLzTk8bB4BL9I6NjvuACfOgPMagDMCDYtMk0gqX6NR6XdJaUDqeTQw3HEuceSRi94y3U0U7wM4qoSzKo5YFvpnwx7QHk7JsXyRM9tNNLyd1tIG1qrTatoBTvM+WDwvj9im4RweLBnd2PCOaGVH8wZVHH0yQor37g3eqe6gywIkB/; 25:hnbxWne7FlCtEki793yNQT1eismgRrigK1ZfS2FLfTes5SrbQFrxEvwU1sG5prFskUzmIGA6UJj5f53T7T0MaFnSIkI62rwWo3IZT7baSvpE68j6KZ3OdQ8U5WzAZX628DI/T84jbjkqtddPKSNW53aWOY6IwbuczfA8LY7gnSjIgkRaGO7pCJh3xz2hHhmLLYTEjbXm9QC645nWubk6E4kBifSA8E4GvgOHwr2oq7fh0CLsM0yxQZ/AO9MPez+ept8ADMBKsglFyuxsjj1NW0yklHT5zRfXw11o5JSndhGHf1md2tBw8ewZFpBd88mFliPRsLGN7LhCi65qiLi7ig==; 31:QHi20/FEYduQ931ldyz0KjehkVy0XhVVsPzPqaqlkCBquoabyxOeBWfq+cGXxhWNcWcKuhGNk77p6nOF10vaur9VJ+r5hojkt5oqaohJkUXNHipj0qEHjWW/WmLbl0u0kDWhM+OM01z+xu7QpTBLUzsUZ4X/ZgYf5LlZHYDAC/Qd/GLssQ0GDIlpZ4WYSK/SMz1TNKPtXpK+lHCN/CmUnwsdjAV/bWeD4XLfueh43Ng= X-MS-TrafficTypeDiagnostic: AMSPR07MB310: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; X-Microsoft-Exchange-Diagnostics: 1; AMSPR07MB310; 20:T+2TqVN5xJ0sH6zqPL9HlGvbp3CO8qlnNgWs2iL+JpGLAfD6vfLsDe2Sa9sefDgvHEEXudIdSdym/zR2fC/tAWObwYmiNrY2J9yX2O3Gq75fX6vI5QroOJA+lvRky0bdF8N86PIGTFlgUeYeG8XN5gwCwfuDOZ4M4+r0CtOrQyPOutSL5PSc6nIgiDQYnZpY12XsglQ0/Sfx2jyFkAVgYUVb4bt9kaJwWCv1wu/5hG7FxzHsuq9qtj9ykeZM2EvT5g6bkBK0t/WnbzxOhuYsYYZm9+aTrzDKk+VRmeExgPoluZVNvgi1AMPqM76yDFSgjTzLoblGSMpA7sOTPBxPogAnIxghtNHIqyKBWTvhfpXtKzw1DCH2+iYfoHUVc66gGUxp+ykkd71los0P+FnQVe3kAaBM1CrNR6XmZ5qwbZ4gauJlaGUJdJKSoPkQfd+Y926Ui1jalvbGC662yQwgBjGKNunNQyJkPVsaLQCNhvtfjNYEueCnEL0DQKSw6Zf5; 4:PA1AUVloskgI/DvirkEslEsRmuA2TJhBYjY/6Hb+nzDgCQxVYYPBXSpZ64Iqon8kpXvmTzZoTGKhiuV1HOo+w3M1B3gbQ9w5qbdOVzl9drVvl6k4je0jUOKU31hR6Q/AFLHtU86ZgBg+GIB/NQtV2l86Oc7eRGmz+qnFH4HF3mkRutqc1ZA2wy8m8f3x/udSS0yL+ddC+wQgu2XtHJAumP5I4aZOy2YS/5khotS310tDeflUCn9LSyovJxBSbqGu X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6041248)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AMSPR07MB310; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AMSPR07MB310; X-Forefront-PRVS: 04267075BD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(199003)(54534003)(189002)(2950100002)(2351001)(101416001)(4326008)(33646002)(2361001)(106356001)(6916009)(107886003)(110136004)(105586002)(6512007)(66066001)(53936002)(47776003)(2906002)(7350300001)(86362001)(6666003)(189998001)(42186005)(6486002)(6506006)(305945005)(36756003)(7736002)(76176999)(25786009)(50986999)(81166006)(48376002)(81156014)(5003940100001)(97736004)(50226002)(5660300001)(8676002)(68736007)(6116002)(50466002)(478600001)(3846002); DIR:OUT; SFP:1101; SCL:1; SRVR:AMSPR07MB310; H:elxacz23q12.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AMSPR07MB310; 23:wNohoJJkhzhcmbuvm/P+ZjMQiz03SZ3jMUfZLU4GX+?= =?us-ascii?Q?FH+oDH1LSuvSLvpAGdvm092b5Rpiv64TTC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JZfWYoKjrKlfz3IxJ8OtYbtEqtmN1H+IMiAxmTBL851cRKEr4H5kndjTWOlIkgMbA4NBt2ls= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2017 14:23:08.3842 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMSPR07MB310 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes Change collect_probes so it returns an std::vector instead of a VEC(bound_probe_s). This allows removing some cleanups. It also seems like enable_probes_command and disable_probes_command were not freeing that vector. The comparison function compare_probes needs to be updated to return a bool indicating whether the first parameter is "less than" the second parameter. I defined two constructors to bound_probe. The default constructor is needed, for example, so the instance in struct bp_location can be constructed without parameters. The constructor with parameters is useful so we can use emplace_back and pass the values directly. The s390 builder on the buildbot shows a weird failure that I can't explain: ../../binutils-gdb/gdb/elfread.c: In function void probe_key_free(bfd*, void*): ../../binutils-gdb/gdb/elfread.c:1346:8: error: types may not be defined in a for-range-declaration [-Werror] for (struct probe *probe : *probes) ^~~~~~ I guess it's a bug with that specific version< of the compiler, since no other gcc gives me that error. It is using: g++ (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) Any idea about this problem? gdb/ChangeLog: * probe.h (struct bound_probe): Define constructors. * probe.c (bound_probe_s): Remove typedef. (DEF_VEC_O (bound_probe_s)): Remove VEC. (collect_probes): Change return type to std::vector, remove cleanup. (compare_probes): Return bool, change parameter type. Change semantic to "less than". (gen_ui_out_table_header_info): Change parameter to std::vector and update. (exists_probe_with_pops): Likewise. (info_probes_for_ops): Update to std::vector change. (enable_probes_command): Likewise. (disable_probes_command): Likewise. --- gdb/probe.c | 147 ++++++++++++++++++++++++------------------------------------ gdb/probe.h | 19 +++++--- 2 files changed, 72 insertions(+), 94 deletions(-) diff --git a/gdb/probe.c b/gdb/probe.c index 2d68437..384ea9d 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -38,11 +38,6 @@ #include #include "common/gdb_optional.h" -typedef struct bound_probe bound_probe_s; -DEF_VEC_O (bound_probe_s); - - - /* A helper for parse_probes that decodes a probe specification in SEARCH_PSPACE. It appends matching SALs to RESULT. */ @@ -267,17 +262,14 @@ find_probe_by_pc (CORE_ADDR pc) If POPS is not NULL, only probes of this certain probe_ops will match. Each argument is a regexp, or NULL, which matches anything. */ -static VEC (bound_probe_s) * +static std::vector collect_probes (char *objname, char *provider, char *probe_name, const struct probe_ops *pops) { struct objfile *objfile; - VEC (bound_probe_s) *result = NULL; - struct cleanup *cleanup; + std::vector result; gdb::optional obj_pat, prov_pat, probe_pat; - cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result); - if (provider != NULL) prov_pat.emplace (provider, REG_NOSUB, _("Invalid provider regexp")); if (probe_name != NULL) @@ -301,8 +293,6 @@ collect_probes (char *objname, char *provider, char *probe_name, for (struct probe *probe : probes) { - struct bound_probe bound; - if (pops != NULL && probe->pops != pops) continue; @@ -314,46 +304,39 @@ collect_probes (char *objname, char *provider, char *probe_name, && probe_pat->exec (probe->name, 0, NULL, 0) != 0) continue; - bound.objfile = objfile; - bound.probe = probe; - VEC_safe_push (bound_probe_s, result, &bound); + result.emplace_back (probe, objfile); } } - discard_cleanups (cleanup); return result; } /* A qsort comparison function for bound_probe_s objects. */ -static int -compare_probes (const void *a, const void *b) +static bool +compare_probes (const bound_probe &a, const bound_probe &b) { - const struct bound_probe *pa = (const struct bound_probe *) a; - const struct bound_probe *pb = (const struct bound_probe *) b; int v; - v = strcmp (pa->probe->provider, pb->probe->provider); - if (v) - return v; + v = strcmp (a.probe->provider, b.probe->provider); + if (v != 0) + return v < 0; - v = strcmp (pa->probe->name, pb->probe->name); - if (v) - return v; + v = strcmp (a.probe->name, b.probe->name); + if (v != 0) + return v < 0; - if (pa->probe->address < pb->probe->address) - return -1; - if (pa->probe->address > pb->probe->address) - return 1; + if (a.probe->address != b.probe->address) + return a.probe->address < b.probe->address; - return strcmp (objfile_name (pa->objfile), objfile_name (pb->objfile)); + return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0; } /* Helper function that generate entries in the ui_out table being crafted by `info_probes_for_ops'. */ static void -gen_ui_out_table_header_info (VEC (bound_probe_s) *probes, +gen_ui_out_table_header_info (const std::vector &probes, const struct probe_ops *p) { /* `headings' refers to the names of the columns when printing `info @@ -382,11 +365,9 @@ gen_ui_out_table_header_info (VEC (bound_probe_s) *probes, VEC_iterate (info_probe_column_s, headings, ix, column); ++ix) { - struct bound_probe *probe; - int jx; size_t size_max = strlen (column->print_name); - for (jx = 0; VEC_iterate (bound_probe_s, probes, jx, probe); ++jx) + for (const bound_probe &probe : probes) { /* `probe_fields' refers to the values of each new field that this probe will display. */ @@ -395,11 +376,11 @@ gen_ui_out_table_header_info (VEC (bound_probe_s) *probes, const char *val; int kx; - if (probe->probe->pops != p) + if (probe.probe->pops != p) continue; c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields); - p->gen_info_probes_table_values (probe->probe, &probe_fields); + p->gen_info_probes_table_values (probe.probe, &probe_fields); gdb_assert (VEC_length (const_char_ptr, probe_fields) == headings_size); @@ -526,14 +507,14 @@ get_number_extra_fields (const struct probe_ops *pops) featuring the given POPS. It returns 0 otherwise. */ static int -exists_probe_with_pops (VEC (bound_probe_s) *probes, +exists_probe_with_pops (const std::vector &probes, const struct probe_ops *pops) { struct bound_probe *probe; int ix; - for (ix = 0; VEC_iterate (bound_probe_s, probes, ix, probe); ++ix) - if (probe->probe->pops == pops) + for (const bound_probe &probe : probes) + if (probe.probe->pops == pops) return 1; return 0; @@ -565,15 +546,13 @@ info_probes_for_ops (const char *arg, int from_tty, { char *provider, *probe_name = NULL, *objname = NULL; struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); - VEC (bound_probe_s) *probes; - int i, any_found; + int any_found; int ui_out_extra_fields = 0; size_t size_addr; size_t size_name = strlen ("Name"); size_t size_objname = strlen ("Object"); size_t size_provider = strlen ("Provider"); size_t size_type = strlen ("Type"); - struct bound_probe *probe; struct gdbarch *gdbarch = get_current_arch (); parse_probe_linespec (arg, &provider, &probe_name, &objname); @@ -581,8 +560,8 @@ info_probes_for_ops (const char *arg, int from_tty, make_cleanup (xfree, probe_name); make_cleanup (xfree, objname); - probes = collect_probes (objname, provider, probe_name, pops); - make_cleanup (VEC_cleanup (probe_p), &probes); + std::vector probes + = collect_probes (objname, provider, probe_name, pops); if (pops == NULL) { @@ -609,27 +588,23 @@ info_probes_for_ops (const char *arg, int from_tty, { ui_out_emit_table table_emitter (current_uiout, 5 + ui_out_extra_fields, - VEC_length (bound_probe_s, probes), - "StaticProbes"); + probes.size (), "StaticProbes"); - if (!VEC_empty (bound_probe_s, probes)) - qsort (VEC_address (bound_probe_s, probes), - VEC_length (bound_probe_s, probes), - sizeof (bound_probe_s), compare_probes); + std::sort (probes.begin (), probes.end (), compare_probes); /* What's the size of an address in our architecture? */ size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10; /* Determining the maximum size of each field (`type', `provider', `name' and `objname'). */ - for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i) + for (const bound_probe &probe : probes) { - const char *probe_type = probe->probe->pops->type_name (probe->probe); + const char *probe_type = probe.probe->pops->type_name (probe.probe); size_type = std::max (strlen (probe_type), size_type); - size_name = std::max (strlen (probe->probe->name), size_name); - size_provider = std::max (strlen (probe->probe->provider), size_provider); - size_objname = std::max (strlen (objfile_name (probe->objfile)), + size_name = std::max (strlen (probe.probe->name), size_name); + size_provider = std::max (strlen (probe.probe->provider), size_provider); + size_objname = std::max (strlen (objfile_name (probe.objfile)), size_objname); } @@ -657,18 +632,18 @@ info_probes_for_ops (const char *arg, int from_tty, current_uiout->table_header (size_objname, ui_left, "object", _("Object")); current_uiout->table_body (); - for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i) + for (const bound_probe &probe : probes) { - const char *probe_type = probe->probe->pops->type_name (probe->probe); + const char *probe_type = probe.probe->pops->type_name (probe.probe); ui_out_emit_tuple tuple_emitter (current_uiout, "probe"); current_uiout->field_string ("type",probe_type); - current_uiout->field_string ("provider", probe->probe->provider); - current_uiout->field_string ("name", probe->probe->name); - current_uiout->field_core_addr ( - "addr", probe->probe->arch, - get_probe_address (probe->probe, probe->objfile)); + current_uiout->field_string ("provider", probe.probe->provider); + current_uiout->field_string ("name", probe.probe->name); + current_uiout->field_core_addr ("addr", probe.probe->arch, + get_probe_address (probe.probe, + probe.objfile)); if (pops == NULL) { @@ -677,20 +652,20 @@ info_probes_for_ops (const char *arg, int from_tty, for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) - if (probe->probe->pops == po) - print_ui_out_info (probe->probe); + if (probe.probe->pops == po) + print_ui_out_info (probe.probe); else if (exists_probe_with_pops (probes, po)) print_ui_out_not_applicables (po); } else - print_ui_out_info (probe->probe); + print_ui_out_info (probe.probe); current_uiout->field_string ("object", - objfile_name (probe->objfile)); + objfile_name (probe.objfile)); current_uiout->text ("\n"); } - any_found = !VEC_empty (bound_probe_s, probes); + any_found = !probes.empty (); } do_cleanups (cleanup); @@ -713,17 +688,15 @@ enable_probes_command (char *arg, int from_tty) { char *provider, *probe_name = NULL, *objname = NULL; struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); - VEC (bound_probe_s) *probes; - struct bound_probe *probe; - int i; parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname); make_cleanup (xfree, provider); make_cleanup (xfree, probe_name); make_cleanup (xfree, objname); - probes = collect_probes (objname, provider, probe_name, NULL); - if (VEC_empty (bound_probe_s, probes)) + std::vector probes + = collect_probes (objname, provider, probe_name, NULL); + if (probes.empty ()) { current_uiout->message (_("No probes matched.\n")); do_cleanups (cleanup); @@ -732,19 +705,19 @@ enable_probes_command (char *arg, int from_tty) /* Enable the selected probes, provided their backends support the notion of enabling a probe. */ - for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i) + for (const bound_probe &probe: probes) { - const struct probe_ops *pops = probe->probe->pops; + const struct probe_ops *pops = probe.probe->pops; if (pops->enable_probe != NULL) { - pops->enable_probe (probe->probe); + pops->enable_probe (probe.probe); current_uiout->message (_("Probe %s:%s enabled.\n"), - probe->probe->provider, probe->probe->name); + probe.probe->provider, probe.probe->name); } else current_uiout->message (_("Probe %s:%s cannot be enabled.\n"), - probe->probe->provider, probe->probe->name); + probe.probe->provider, probe.probe->name); } do_cleanups (cleanup); @@ -757,17 +730,15 @@ disable_probes_command (char *arg, int from_tty) { char *provider, *probe_name = NULL, *objname = NULL; struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); - VEC (bound_probe_s) *probes; - struct bound_probe *probe; - int i; parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname); make_cleanup (xfree, provider); make_cleanup (xfree, probe_name); make_cleanup (xfree, objname); - probes = collect_probes (objname, provider, probe_name, NULL /* pops */); - if (VEC_empty (bound_probe_s, probes)) + std::vector probes + = collect_probes (objname, provider, probe_name, NULL /* pops */); + if (probes.empty ()) { current_uiout->message (_("No probes matched.\n")); do_cleanups (cleanup); @@ -776,19 +747,19 @@ disable_probes_command (char *arg, int from_tty) /* Disable the selected probes, provided their backends support the notion of enabling a probe. */ - for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i) + for (const bound_probe &probe : probes) { - const struct probe_ops *pops = probe->probe->pops; + const struct probe_ops *pops = probe.probe->pops; if (pops->disable_probe != NULL) { - pops->disable_probe (probe->probe); + pops->disable_probe (probe.probe); current_uiout->message (_("Probe %s:%s disabled.\n"), - probe->probe->provider, probe->probe->name); + probe.probe->provider, probe.probe->name); } else current_uiout->message (_("Probe %s:%s cannot be disabled.\n"), - probe->probe->provider, probe->probe->name); + probe.probe->provider, probe.probe->name); } do_cleanups (cleanup); diff --git a/gdb/probe.h b/gdb/probe.h index 61e3031..75e9a5c 100644 --- a/gdb/probe.h +++ b/gdb/probe.h @@ -214,15 +214,22 @@ struct probe their point of use. */ struct bound_probe - { - /* The probe. */ +{ + bound_probe () + {} - struct probe *probe; + bound_probe (struct probe *probe_, struct objfile *objfile_) + : probe (probe_), objfile (objfile_) + {} - /* The objfile in which the probe originated. */ + /* The probe. */ - struct objfile *objfile; - }; + struct probe *probe = NULL; + + /* The objfile in which the probe originated. */ + + struct objfile *objfile = NULL; +}; /* A helper for linespec that decodes a probe specification. It returns a std::vector object and updates LOC or