From patchwork Fri Sep 15 18:36:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 76164 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 160833858C60 for ; Fri, 15 Sep 2023 18:37:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 160833858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694803074; bh=LLhYDs3+nIsSTAO7blRs4ykDx2M0WqCTGjNUYide9zk=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Er1lxNxstSb2Eknxq8rOrjeYoibbGcocDIT7IkauegsAWYqfStMyy3rnnhJjlWyZs zoO7Gzud3KZ3l8KIYWypSBMJiwpz6fKwNGaL0wek3fYWUofZgaE4M0YNAaF9bIaz9K aky3lnBqYv/PSbzm4vUN32UIYov+J427dJvb5KLY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by sourceware.org (Postfix) with ESMTPS id 7440A3858C60 for ; Fri, 15 Sep 2023 18:36:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7440A3858C60 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5738cb00eebso1448225eaf.2 for ; Fri, 15 Sep 2023 11:36:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694802964; x=1695407764; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LLhYDs3+nIsSTAO7blRs4ykDx2M0WqCTGjNUYide9zk=; b=pFLeYzM23XmHqfmdWAg6vBKYc/lS01apWuev0P+I1WxzR3iwS87SU6zx2+e4fJVa0r IS6Nw4LOrUo0+sS4BEkYDFHnL0HV7sCSxQwIFbTn/iBewg5xa+kT/XUowXpbZEjQUFDB Jsj4OKfM51/lqXKF7D8VHw6Boo8w6lHDJuaA/HydWyYm2ggZPDaFdT3VOVVVpgkRSHjh xB5TxXKYw5NzT85Qe4uor78jPjLV/p+G4Mio0l/X9jPyVmJYdXr6tov6QEXdEAjtFgdk CniDgdUtVxq2UI2Eoc1/JkGrwqVKUI48A0LdLTw20tM7JA3l/y4sXnu5tjEgldujXx+p jZug== X-Gm-Message-State: AOJu0Yy6SSB/Ehu11nKW0iga0H0QfEYOkp9JVh7cji9PK1lVegovXj9h e0KnYA/HCCT+s84Kcmwzh4WmZWF58jyQ686yLAlmCQ== X-Google-Smtp-Source: AGHT+IEHGQFcO/uaVl7sWYILce02IKd0dhLnyp0IV1jrkysSrO2UI9/Vq7gfYKzsXXAO+iwkGghtAw== X-Received: by 2002:a05:6870:414e:b0:1d0:cbc7:1c92 with SMTP id r14-20020a056870414e00b001d0cbc71c92mr2648988oad.28.1694802963638; Fri, 15 Sep 2023 11:36:03 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id w25-20020a02cf99000000b0042b0a6d899fsm1235997jar.60.2023.09.15.11.36.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 11:36:03 -0700 (PDT) Date: Fri, 15 Sep 2023 12:36:01 -0600 Subject: [PATCH 1/4] Use gdb::checked_static_cast for watchpoints MIME-Version: 1.0 Message-Id: <20230915-watchpoint-casts-v1-1-a4ff35c9644e@adacore.com> References: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> In-Reply-To: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This replaces some casts to 'watchpoint *' with checked_static_cast. In one spot, an unnecessary block is also removed. --- gdb/breakpoint.c | 298 +++++++++++++++++++++++---------------------- gdb/guile/scm-breakpoint.c | 2 +- gdb/python/py-breakpoint.c | 2 +- 3 files changed, 153 insertions(+), 149 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c429af455ff..c0d86f38c73 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5249,7 +5249,7 @@ watchpoint_check (bpstat *bs) /* BS is built from an existing struct breakpoint. */ gdb_assert (bs->breakpoint_at != NULL); - b = (struct watchpoint *) bs->breakpoint_at; + b = gdb::checked_static_cast (bs->breakpoint_at); /* If this is a local watchpoint, we only want to check if the watchpoint frame is in scope if the current thread is the thread @@ -5410,158 +5410,155 @@ bpstat_check_watchpoint (bpstat *bs) /* BS is built for existing struct breakpoint. */ bl = bs->bp_location_at.get (); gdb_assert (bl != NULL); - b = (struct watchpoint *) bs->breakpoint_at; - gdb_assert (b != NULL); - - { - bool must_check_value = false; - - if (b->type == bp_watchpoint) - /* For a software watchpoint, we must always check the - watched value. */ - must_check_value = true; - else if (b->watchpoint_triggered == watch_triggered_yes) - /* We have a hardware watchpoint (read, write, or access) - and the target earlier reported an address watched by - this watchpoint. */ - must_check_value = true; - else if (b->watchpoint_triggered == watch_triggered_unknown - && b->type == bp_hardware_watchpoint) - /* We were stopped by a hardware watchpoint, but the target could - not report the data address. We must check the watchpoint's - value. Access and read watchpoints are out of luck; without - a data address, we can't figure it out. */ - must_check_value = true; + b = gdb::checked_static_cast (bs->breakpoint_at); + + bool must_check_value = false; + + if (b->type == bp_watchpoint) + /* For a software watchpoint, we must always check the + watched value. */ + must_check_value = true; + else if (b->watchpoint_triggered == watch_triggered_yes) + /* We have a hardware watchpoint (read, write, or access) + and the target earlier reported an address watched by + this watchpoint. */ + must_check_value = true; + else if (b->watchpoint_triggered == watch_triggered_unknown + && b->type == bp_hardware_watchpoint) + /* We were stopped by a hardware watchpoint, but the target could + not report the data address. We must check the watchpoint's + value. Access and read watchpoints are out of luck; without + a data address, we can't figure it out. */ + must_check_value = true; + + if (must_check_value) + { + wp_check_result e; - if (must_check_value) + try + { + e = watchpoint_check (bs); + } + catch (const gdb_exception_error &ex) { - wp_check_result e; + exception_fprintf (gdb_stderr, ex, + "Error evaluating expression " + "for watchpoint %d\n", + b->number); - try - { - e = watchpoint_check (bs); - } - catch (const gdb_exception_error &ex) + SWITCH_THRU_ALL_UIS () { - exception_fprintf (gdb_stderr, ex, - "Error evaluating expression " - "for watchpoint %d\n", - b->number); - - SWITCH_THRU_ALL_UIS () - { - gdb_printf (_("Watchpoint %d deleted.\n"), - b->number); - } - watchpoint_del_at_next_stop (b); - e = WP_DELETED; + gdb_printf (_("Watchpoint %d deleted.\n"), + b->number); } + watchpoint_del_at_next_stop (b); + e = WP_DELETED; + } - switch (e) + switch (e) + { + case WP_DELETED: + /* We've already printed what needs to be printed. */ + bs->print_it = print_it_done; + /* Stop. */ + break; + case WP_IGNORE: + bs->print_it = print_it_noop; + bs->stop = false; + break; + case WP_VALUE_CHANGED: + if (b->type == bp_read_watchpoint) { - case WP_DELETED: - /* We've already printed what needs to be printed. */ - bs->print_it = print_it_done; - /* Stop. */ - break; - case WP_IGNORE: - bs->print_it = print_it_noop; - bs->stop = false; - break; - case WP_VALUE_CHANGED: - if (b->type == bp_read_watchpoint) + /* There are two cases to consider here: + + 1. We're watching the triggered memory for reads. + In that case, trust the target, and always report + the watchpoint hit to the user. Even though + reads don't cause value changes, the value may + have changed since the last time it was read, and + since we're not trapping writes, we will not see + those, and as such we should ignore our notion of + old value. + + 2. We're watching the triggered memory for both + reads and writes. There are two ways this may + happen: + + 2.1. This is a target that can't break on data + reads only, but can break on accesses (reads or + writes), such as e.g., x86. We detect this case + at the time we try to insert read watchpoints. + + 2.2. Otherwise, the target supports read + watchpoints, but, the user set an access or write + watchpoint watching the same memory as this read + watchpoint. + + If we're watching memory writes as well as reads, + ignore watchpoint hits when we find that the + value hasn't changed, as reads don't cause + changes. This still gives false positives when + the program writes the same value to memory as + what there was already in memory (we will confuse + it for a read), but it's much better than + nothing. */ + + int other_write_watchpoint = 0; + + if (bl->watchpoint_type == hw_read) { - /* There are two cases to consider here: - - 1. We're watching the triggered memory for reads. - In that case, trust the target, and always report - the watchpoint hit to the user. Even though - reads don't cause value changes, the value may - have changed since the last time it was read, and - since we're not trapping writes, we will not see - those, and as such we should ignore our notion of - old value. - - 2. We're watching the triggered memory for both - reads and writes. There are two ways this may - happen: - - 2.1. This is a target that can't break on data - reads only, but can break on accesses (reads or - writes), such as e.g., x86. We detect this case - at the time we try to insert read watchpoints. - - 2.2. Otherwise, the target supports read - watchpoints, but, the user set an access or write - watchpoint watching the same memory as this read - watchpoint. - - If we're watching memory writes as well as reads, - ignore watchpoint hits when we find that the - value hasn't changed, as reads don't cause - changes. This still gives false positives when - the program writes the same value to memory as - what there was already in memory (we will confuse - it for a read), but it's much better than - nothing. */ - - int other_write_watchpoint = 0; - - if (bl->watchpoint_type == hw_read) - { - for (breakpoint &other_b : all_breakpoints ()) - if (other_b.type == bp_hardware_watchpoint - || other_b.type == bp_access_watchpoint) + for (breakpoint &other_b : all_breakpoints ()) + if (other_b.type == bp_hardware_watchpoint + || other_b.type == bp_access_watchpoint) + { + watchpoint &other_w = + gdb::checked_static_cast (other_b); + + if (other_w.watchpoint_triggered + == watch_triggered_yes) { - watchpoint &other_w = - gdb::checked_static_cast (other_b); - - if (other_w.watchpoint_triggered - == watch_triggered_yes) - { - other_write_watchpoint = 1; - break; - } + other_write_watchpoint = 1; + break; } - } - - if (other_write_watchpoint - || bl->watchpoint_type == hw_access) - { - /* We're watching the same memory for writes, - and the value changed since the last time we - updated it, so this trap must be for a write. - Ignore it. */ - bs->print_it = print_it_noop; - bs->stop = false; - } + } } - break; - case WP_VALUE_NOT_CHANGED: - if (b->type == bp_hardware_watchpoint - || b->type == bp_watchpoint) + + if (other_write_watchpoint + || bl->watchpoint_type == hw_access) { - /* Don't stop: write watchpoints shouldn't fire if - the value hasn't changed. */ + /* We're watching the same memory for writes, + and the value changed since the last time we + updated it, so this trap must be for a write. + Ignore it. */ bs->print_it = print_it_noop; bs->stop = false; } - /* Stop. */ - break; - default: - /* Can't happen. */ - break; } + break; + case WP_VALUE_NOT_CHANGED: + if (b->type == bp_hardware_watchpoint + || b->type == bp_watchpoint) + { + /* Don't stop: write watchpoints shouldn't fire if + the value hasn't changed. */ + bs->print_it = print_it_noop; + bs->stop = false; + } + /* Stop. */ + break; + default: + /* Can't happen. */ + break; } - else /* !must_check_value */ - { - /* This is a case where some watchpoint(s) triggered, but - not at the address of this watchpoint, or else no - watchpoint triggered after all. So don't print - anything for this watchpoint. */ - bs->print_it = print_it_noop; - bs->stop = false; - } + } + else /* !must_check_value */ + { + /* This is a case where some watchpoint(s) triggered, but + not at the address of this watchpoint, or else no + watchpoint triggered after all. So don't print + anything for this watchpoint. */ + bs->print_it = print_it_noop; + bs->stop = false; } } @@ -5625,7 +5622,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) if (is_watchpoint (b)) { - struct watchpoint *w = (struct watchpoint *) b; + struct watchpoint *w = gdb::checked_static_cast (b); cond = w->cond_exp.get (); } @@ -5644,7 +5641,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) scoped_value_mark mark; if (is_watchpoint (b)) - w = (struct watchpoint *) b; + w = gdb::checked_static_cast (b); else w = NULL; @@ -5794,7 +5791,8 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, iteration. */ if (b.type == bp_watchpoint_scope && b.related_breakpoint != &b) { - struct watchpoint *w = (struct watchpoint *) b.related_breakpoint; + struct watchpoint *w + = gdb::checked_static_cast (b.related_breakpoint); w->watchpoint_triggered = watch_triggered_yes; } @@ -5918,7 +5916,8 @@ bpstat_stop_status (const address_space *aspace, && bs->breakpoint_at && is_hardware_watchpoint (bs->breakpoint_at)) { - struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; + struct watchpoint *w + = gdb::checked_static_cast (bs->breakpoint_at); update_watchpoint (w, false /* don't reparse. */); need_remove_insert = 1; @@ -6568,7 +6567,8 @@ print_one_breakpoint_location (struct breakpoint *b, { if (is_watchpoint (b)) { - struct watchpoint *w = (struct watchpoint *) b; + struct watchpoint *w + = gdb::checked_static_cast (b); /* Field 4, the address, is omitted (which makes the columns not line up too nicely with the headers, but the effect @@ -6828,7 +6828,8 @@ print_one_breakpoint_location (struct breakpoint *b, { if (is_watchpoint (b)) { - struct watchpoint *w = (struct watchpoint *) b; + struct watchpoint *w + = gdb::checked_static_cast (b); uiout->field_string ("original-location", w->exp_string.get ()); } @@ -7257,8 +7258,10 @@ static bool watchpoint_locations_match (const struct bp_location *loc1, const struct bp_location *loc2) { - struct watchpoint *w1 = (struct watchpoint *) loc1->owner; - struct watchpoint *w2 = (struct watchpoint *) loc2->owner; + struct watchpoint *w1 + = gdb::checked_static_cast (loc1->owner); + struct watchpoint *w2 + = gdb::checked_static_cast (loc2->owner); /* Both of them must exist. */ gdb_assert (w1 != NULL); @@ -12604,9 +12607,9 @@ delete_breakpoint (struct breakpoint *bpt) struct watchpoint *w; if (bpt->type == bp_watchpoint_scope) - w = (struct watchpoint *) bpt->related_breakpoint; + w = gdb::checked_static_cast (bpt->related_breakpoint); else if (bpt->related_breakpoint->type == bp_watchpoint_scope) - w = (struct watchpoint *) bpt; + w = gdb::checked_static_cast (bpt); else w = NULL; if (w != NULL) @@ -13770,7 +13773,8 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, try { - struct watchpoint *w = (struct watchpoint *) bpt; + struct watchpoint *w + = gdb::checked_static_cast (bpt); orig_enable_state = bpt->enable_state; bpt->enable_state = bp_enabled; diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index 59254646bcc..541e1037a5e 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -895,7 +895,7 @@ gdbscm_breakpoint_expression (SCM self) if (!is_watchpoint (bp_smob->bp)) return SCM_BOOL_F; - wp = (struct watchpoint *) bp_smob->bp; + wp = gdb::checked_static_cast (bp_smob->bp); const char *str = wp->exp_string.get (); if (! str) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index cb064515690..c6d23b65768 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -556,7 +556,7 @@ bppy_get_expression (PyObject *self, void *closure) if (!is_watchpoint (obj->bp)) Py_RETURN_NONE; - wp = (struct watchpoint *) obj->bp; + wp = gdb::checked_static_cast (obj->bp); str = wp->exp_string.get (); if (! str) From patchwork Fri Sep 15 18:36:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 76163 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 654333858C54 for ; Fri, 15 Sep 2023 18:37:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 654333858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694803046; bh=wASJ7aGH54NMzJic2FGjyGLCF86YY4m+hCyrDwM03f0=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EsaIwpiieP/TSYR+l94R5RjbmlBD/D6Fn7zcz24gjOr7TWJUXj4fcKHUonOgP2SBv a8kg0jQYyfT+JRIWmeqXafWoEu0WI0lFkV+R82dQPfGCZiMqaY4djAeSvP8IsFN3da qoCKT5PsF5KhQ7tMe5tXvi6b/nFvanXYYY493N1I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 543293858C00 for ; Fri, 15 Sep 2023 18:36:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 543293858C00 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-34f6c725d94so7780395ab.0 for ; Fri, 15 Sep 2023 11:36:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694802964; x=1695407764; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wASJ7aGH54NMzJic2FGjyGLCF86YY4m+hCyrDwM03f0=; b=r53veFha8fyZuVDfDfOJpre+m9c0/zRkuv5QE+goA5OiZShOmeUjaRBF6eOmHCQ670 0ue1NMit325lybUv/b4oRo/OWlO2wzfawgXNBUnAGL9ycOq9NCPwo502JTLXrw1+GD7t Tgp/Y1hcX16/aemKZc4+GVoW1jnDIMUO6nA1uWvEJQ+ZNEteRVoWnwhvDvr5CvlOwNwx iUhQVhMlz7CuhfUNnDruIW0CMxn/snhobgXNQIDW1R+Abu9/HPB2rI7peJhvP9dFUEIe kKn2STLn8eJII+0rTPKjnSOU0fX504K/vfH3nmua041BncEmeISI8SmS4jy6C/uZz5Cr 1FJQ== X-Gm-Message-State: AOJu0Yz2KhCyDWNA4Ojv7nJVA8cZprahh3YzAtmlMxZMy/vYf/jfcxf9 qQWZkcSKUCp3ZZRvtBOdTwHQY75knqk2ZW/zdpK1Uw== X-Google-Smtp-Source: AGHT+IHw7srPC5x4WVXts4bL+r/PVodPKoB3a16wXDg7z/342ra3aGeykfKKqGTD6Wx0vgnavQaDvA== X-Received: by 2002:a05:6e02:13e9:b0:34c:d0d6:512f with SMTP id w9-20020a056e0213e900b0034cd0d6512fmr2725816ilj.7.1694802964408; Fri, 15 Sep 2023 11:36:04 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id w25-20020a02cf99000000b0042b0a6d899fsm1235997jar.60.2023.09.15.11.36.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 11:36:03 -0700 (PDT) Date: Fri, 15 Sep 2023 12:36:02 -0600 Subject: [PATCH 2/4] Use gdb::checked_static_cast for tracepoints MIME-Version: 1.0 Message-Id: <20230915-watchpoint-casts-v1-2-a4ff35c9644e@adacore.com> References: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> In-Reply-To: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This replaces some casts to 'tracepoint *' with checked_static_cast. Some functions are changed to accept a 'tracepoint *' now, for better type safety. --- gdb/breakpoint.c | 33 +++++++++++++++++++-------------- gdb/mi/mi-cmd-break.c | 10 +++++++--- gdb/remote.c | 11 +++++------ gdb/target-debug.h | 2 ++ gdb/target-delegates.c | 16 ++++++++-------- gdb/target.c | 2 +- gdb/target.h | 4 ++-- gdb/tracefile-tfile.c | 4 ++-- gdb/tracepoint.c | 28 +++++++++++++++++----------- gdb/tracepoint.h | 4 ++-- 10 files changed, 65 insertions(+), 49 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c0d86f38c73..134ad76ce9a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1433,7 +1433,7 @@ validate_commands_for_breakpoint (struct breakpoint *b, { if (is_tracepoint (b)) { - struct tracepoint *t = (struct tracepoint *) b; + struct tracepoint *t = gdb::checked_static_cast (b); struct command_line *c; struct command_line *while_stepping = 0; @@ -1471,7 +1471,7 @@ validate_commands_for_breakpoint (struct breakpoint *b, while_stepping = c; } - validate_actionline (c->line, b); + validate_actionline (c->line, t); } if (while_stepping) { @@ -1645,7 +1645,9 @@ commands_command_1 (const char *arg, int from_tty, auto do_validate = [=] (const char *line) { - validate_actionline (line, b); + struct tracepoint *t + = gdb::checked_static_cast (b); + validate_actionline (line, t); }; gdb::function_view validator; if (is_tracepoint (b)) @@ -6762,7 +6764,7 @@ print_one_breakpoint_location (struct breakpoint *b, if (!part_of_multiple && is_tracepoint (b)) { - struct tracepoint *tp = (struct tracepoint *) b; + struct tracepoint *tp = gdb::checked_static_cast (b); if (tp->traceframe_usage) { @@ -6794,7 +6796,7 @@ print_one_breakpoint_location (struct breakpoint *b, if (is_tracepoint (b)) { - struct tracepoint *t = (struct tracepoint *) b; + struct tracepoint *t = gdb::checked_static_cast (b); if (!part_of_multiple && t->pass_count) { @@ -12811,9 +12813,8 @@ ambiguous_names_p (const bp_location_range &locs) precisely because it confuses tools). */ static struct symtab_and_line -update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) +update_static_tracepoint (struct tracepoint *tp, struct symtab_and_line sal) { - struct tracepoint *tp = (struct tracepoint *) b; struct static_tracepoint_marker marker; CORE_ADDR pc; @@ -12825,7 +12826,7 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) { if (tp->static_trace_marker_id != marker.str_id) warning (_("static tracepoint %d changed probed marker from %s to %s"), - b->number, tp->static_trace_marker_id.c_str (), + tp->number, tp->static_trace_marker_id.c_str (), marker.str_id.c_str ()); tp->static_trace_marker_id = std::move (marker.str_id); @@ -12856,7 +12857,7 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) warning (_("marker for static tracepoint %d (%s) not " "found at previous line number"), - b->number, tp->static_trace_marker_id.c_str ()); + tp->number, tp->static_trace_marker_id.c_str ()); symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); sym = find_pc_sect_function (tpmarker->address, NULL); @@ -12882,17 +12883,17 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) uiout->field_signed ("line", sal2.line); uiout->text ("\n"); - b->first_loc ().line_number = sal2.line; - b->first_loc ().symtab = sym != NULL ? sal2.symtab : NULL; + tp->first_loc ().line_number = sal2.line; + tp->first_loc ().symtab = sym != NULL ? sal2.symtab : NULL; std::unique_ptr els (new explicit_location_spec ()); els->source_filename = xstrdup (symtab_to_filename_for_display (sal2.symtab)); - els->line_offset.offset = b->first_loc ().line_number; + els->line_offset.offset = tp->first_loc ().line_number; els->line_offset.sign = LINE_OFFSET_NONE; - b->locspec = std::move (els); + tp->locspec = std::move (els); /* Might be nice to check if function changed, and warn if so. */ @@ -13153,7 +13154,11 @@ code_breakpoint::location_spec_to_sals (location_spec *locspec, } if (type == bp_static_tracepoint) - sals[0] = update_static_tracepoint (this, sals[0]); + { + struct tracepoint *t + = gdb::checked_static_cast (this); + sals[0] = update_static_tracepoint (t, sals[0]); + } *found = 1; } diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 975bc1c5dde..2294ea3723b 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -585,11 +585,15 @@ mi_cmd_break_commands (const char *command, const char *const *argv, int argc) }; if (is_tracepoint (b)) - break_command = read_command_lines_1 (reader, 1, - [=] (const char *line) + { + struct tracepoint *t + = gdb::checked_static_cast (b); + break_command = read_command_lines_1 (reader, 1, + [=] (const char *line) { - validate_actionline (line, b); + validate_actionline (line, t); }); + } else break_command = read_command_lines_1 (reader, 1, 0); diff --git a/gdb/remote.c b/gdb/remote.c index ba81c5b0b6f..38b4145be30 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -911,7 +911,7 @@ class remote_target : public process_stratum_target int get_trace_status (struct trace_status *ts) override; - void get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp) + void get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) override; void trace_stop () override; @@ -13256,7 +13256,7 @@ remote_target::download_tracepoint (struct bp_location *loc) std::vector stepping_actions; char *pkt; struct breakpoint *b = loc->owner; - struct tracepoint *t = (struct tracepoint *) b; + struct tracepoint *t = gdb::checked_static_cast (b); struct remote_state *rs = get_remote_state (); int ret; const char *err_msg = _("Tracepoint packet too large for target."); @@ -13675,12 +13675,11 @@ remote_target::get_trace_status (struct trace_status *ts) } void -remote_target::get_tracepoint_status (struct breakpoint *bp, +remote_target::get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) { struct remote_state *rs = get_remote_state (); char *reply; - struct tracepoint *tp = (struct tracepoint *) bp; size_t size = get_remote_packet_size (); if (tp) @@ -13700,7 +13699,7 @@ remote_target::get_tracepoint_status (struct breakpoint *bp, if (reply && *reply) { if (*reply == 'V') - parse_tracepoint_status (reply + 1, bp, utp); + parse_tracepoint_status (reply + 1, tp, utp); } } } @@ -13715,7 +13714,7 @@ remote_target::get_tracepoint_status (struct breakpoint *bp, if (reply && *reply) { if (*reply == 'V') - parse_tracepoint_status (reply + 1, bp, utp); + parse_tracepoint_status (reply + 1, tp, utp); } } } diff --git a/gdb/target-debug.h b/gdb/target-debug.h index a028d2ba5f4..2eccc7840d6 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -126,6 +126,8 @@ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_breakpoint_p(X) \ target_debug_do_print (host_address_to_string (X)) +#define target_debug_print_struct_tracepoint_p(X) \ + target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_uploaded_tp_p(X) \ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_uploaded_tp_pp(X) \ diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 8b066249624..909f2725035 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -143,7 +143,7 @@ struct dummy_target : public target_ops void trace_set_readonly_regions () override; void trace_start () override; int get_trace_status (struct trace_status *arg0) override; - void get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) override; + void get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) override; void trace_stop () override; int trace_find (enum trace_find_type arg0, int arg1, CORE_ADDR arg2, CORE_ADDR arg3, int *arg4) override; bool get_trace_state_variable_value (int arg0, LONGEST *arg1) override; @@ -318,7 +318,7 @@ struct debug_target : public target_ops void trace_set_readonly_regions () override; void trace_start () override; int get_trace_status (struct trace_status *arg0) override; - void get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) override; + void get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) override; void trace_stop () override; int trace_find (enum trace_find_type arg0, int arg1, CORE_ADDR arg2, CORE_ADDR arg3, int *arg4) override; bool get_trace_state_variable_value (int arg0, LONGEST *arg1) override; @@ -3216,24 +3216,24 @@ debug_target::get_trace_status (struct trace_status *arg0) } void -target_ops::get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) +target_ops::get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) { this->beneath ()->get_tracepoint_status (arg0, arg1); } void -dummy_target::get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) +dummy_target::get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) { tcomplain (); } void -debug_target::get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) +debug_target::get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) { gdb_printf (gdb_stdlog, "-> %s->get_tracepoint_status (...)\n", this->beneath ()->shortname ()); this->beneath ()->get_tracepoint_status (arg0, arg1); gdb_printf (gdb_stdlog, "<- %s->get_tracepoint_status (", this->beneath ()->shortname ()); - target_debug_print_struct_breakpoint_p (arg0); + target_debug_print_struct_tracepoint_p (arg0); gdb_puts (", ", gdb_stdlog); target_debug_print_struct_uploaded_tp_p (arg1); gdb_puts (")\n", gdb_stdlog); @@ -4553,9 +4553,9 @@ dummy_target::fetch_x86_xsave_layout () x86_xsave_layout debug_target::fetch_x86_xsave_layout () { - x86_xsave_layout result; gdb_printf (gdb_stdlog, "-> %s->fetch_x86_xsave_layout (...)\n", this->beneath ()->shortname ()); - result = this->beneath ()->fetch_x86_xsave_layout (); + x86_xsave_layout result + = this->beneath ()->fetch_x86_xsave_layout (); gdb_printf (gdb_stdlog, "<- %s->fetch_x86_xsave_layout (", this->beneath ()->shortname ()); gdb_puts (") = ", gdb_stdlog); target_debug_print_x86_xsave_layout (result); diff --git a/gdb/target.c b/gdb/target.c index 68d7fe2bb56..8cb4fa1736d 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -667,7 +667,7 @@ target_get_trace_status (trace_status *ts) } void -target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp) +target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp) { return current_inferior ()->top_target ()->get_tracepoint_status (tp, utp); } diff --git a/gdb/target.h b/gdb/target.h index aa07075f9f2..18388a32d19 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1043,7 +1043,7 @@ struct target_ops virtual int get_trace_status (struct trace_status *ts) TARGET_DEFAULT_RETURN (-1); - virtual void get_tracepoint_status (struct breakpoint *tp, + virtual void get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) TARGET_DEFAULT_NORETURN (tcomplain ()); @@ -2255,7 +2255,7 @@ extern void target_trace_set_readonly_regions (); extern int target_get_trace_status (trace_status *ts); -extern void target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp); +extern void target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp); extern void target_trace_stop (); diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 3440f375021..1158a8beeb2 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -67,7 +67,7 @@ class tfile_target final : public tracefile_target bool get_trace_state_variable_value (int tsv, LONGEST *val) override; traceframe_info_up traceframe_info () override; - void get_tracepoint_status (struct breakpoint *tp, + void get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) override; }; @@ -633,7 +633,7 @@ tfile_target::files_info () } void -tfile_target::get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp) +tfile_target::get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) { /* Other bits of trace status were collected as part of opening the trace files, so nothing to do here. */ diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 205380476b3..9cec91f0fd4 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -157,7 +157,7 @@ static std::string trace_stop_notes; struct collection_list; -static counted_command_line all_tracepoint_actions (struct breakpoint *); +static counted_command_line all_tracepoint_actions (struct tracepoint *); static struct trace_status trace_status; @@ -626,12 +626,11 @@ finalize_tracepoint_aexpr (struct agent_expr *aexpr) /* worker function */ void -validate_actionline (const char *line, struct breakpoint *b) +validate_actionline (const char *line, struct tracepoint *t) { struct cmd_list_element *c; const char *tmp_p; const char *p; - struct tracepoint *t = (struct tracepoint *) b; /* If EOF is typed, *line is NULL. */ if (line == NULL) @@ -1479,7 +1478,9 @@ encode_actions (struct bp_location *tloc, gdbarch_virtual_frame_pointer (tloc->gdbarch, tloc->address, &frame_reg, &frame_offset); - counted_command_line actions = all_tracepoint_actions (tloc->owner); + struct tracepoint *t + = gdb::checked_static_cast (tloc->owner); + counted_command_line actions = all_tracepoint_actions (t); encode_actions_1 (actions.get (), tloc, frame_reg, frame_offset, tracepoint_list, stepping_list); encode_actions_1 (breakpoint_commands (tloc->owner), tloc, @@ -1884,8 +1885,12 @@ tstatus_command (const char *args, int from_tty) (long int) (ts->stop_time % 1000000)); /* Now report any per-tracepoint status available. */ - for (breakpoint &t : all_tracepoints ()) - target_get_tracepoint_status (&t, NULL); + for (breakpoint &b : all_tracepoints ()) + { + struct tracepoint *t + = gdb::checked_static_cast (&b); + target_get_tracepoint_status (t, nullptr); + } } /* Report the trace status to uiout, in a way suitable for MI, and not @@ -2751,7 +2756,7 @@ get_traceframe_location (int *stepping_frame_p) /* Return the default collect actions of a tracepoint T. */ static counted_command_line -all_tracepoint_actions (struct breakpoint *t) +all_tracepoint_actions (struct tracepoint *t) { counted_command_line actions (nullptr, command_lines_deleter ()); @@ -2794,7 +2799,9 @@ tdump_command (const char *args, int from_tty) select_frame (get_current_frame ()); - counted_command_line actions = all_tracepoint_actions (loc->owner); + struct tracepoint *t + = gdb::checked_static_cast (loc->owner); + counted_command_line actions = all_tracepoint_actions (t); trace_dump_actions (actions.get (), 0, stepping_frame, from_tty); trace_dump_actions (breakpoint_commands (loc->owner), 0, stepping_frame, @@ -3059,7 +3066,7 @@ merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps) /* Mark this location as already inserted. */ loc->inserted = 1; - t = (struct tracepoint *) loc->owner; + t = gdb::checked_static_cast (loc->owner); gdb_printf (_("Assuming tracepoint %d is same " "as target's tracepoint %d at %s.\n"), loc->owner->number, utp->number, @@ -3368,11 +3375,10 @@ Status line: '%s'\n"), p, line); } void -parse_tracepoint_status (const char *p, struct breakpoint *bp, +parse_tracepoint_status (const char *p, struct tracepoint *tp, struct uploaded_tp *utp) { ULONGEST uval; - struct tracepoint *tp = (struct tracepoint *) bp; p = unpack_varlen_hex (p, &uval); if (tp) diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index a637d6b71d3..60b51390002 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -354,7 +354,7 @@ extern void encode_actions_rsp (struct bp_location *tloc, std::vector *tdp_actions, std::vector *stepping_actions); -extern void validate_actionline (const char *, struct breakpoint *); +extern void validate_actionline (const char *, struct tracepoint *); extern void validate_trace_state_variable_name (const char *name); extern struct trace_state_variable *find_trace_state_variable (const char *name); @@ -369,7 +369,7 @@ extern int encode_source_string (int num, ULONGEST addr, extern void parse_trace_status (const char *line, struct trace_status *ts); -extern void parse_tracepoint_status (const char *p, struct breakpoint *tp, +extern void parse_tracepoint_status (const char *p, struct tracepoint *tp, struct uploaded_tp *utp); extern void parse_tracepoint_definition (const char *line, From patchwork Fri Sep 15 18:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 76162 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B01D53857027 for ; Fri, 15 Sep 2023 18:36:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B01D53857027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694803018; bh=GMiClm+YCY+fVF92WLK8h38JuyCVmuJhghKRaRlZMkE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=H8fwHb/mk2z5qtj1G/WK3/BxwQ7Y7ImAhtMfzysSCxmGpvdfapJbRhOKCsvId8xE/ ShoX0KbbZLj9iYPi7JKeFjL5n/yCYtw4MTdIPaZd9XPMflgEgDZh1PRTD0eWFWlNkx 4GsfULdSgQSaVoIlyHSNkf7NNitFQWkdqWXjSbi8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id ED8A73858C2B for ; Fri, 15 Sep 2023 18:36:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED8A73858C2B Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-79545e141c7so64422039f.0 for ; Fri, 15 Sep 2023 11:36:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694802965; x=1695407765; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GMiClm+YCY+fVF92WLK8h38JuyCVmuJhghKRaRlZMkE=; b=OFR5OJFQQSFPNvy5Uwk+Jij15CgH3/jGiG0DgMP12HaAhMQ/9p1Ae+W7LflvppkUh8 OB0fyei1hlxRaxBA4RWwqbgpNkyAYyepVu4I5wyRCnRJmZPEgCYZi6T1TRxgqasBqOuO D/uHSgRdvibXZo2O5+v62Z6qMrn4ijQCMpoeR6vMtNFzhnI99vULqXJ+5f386o+xbDGr 6u9nkLVZIcbtL+ecSzdHzUyj30laik9iB5xMULK2q+90o6We8DeimIJq5yEDbFHOn+OB UmUKzwwtKZ9uxZGc0jYuwGyKAMCHM4vymUSD16DqRXWKpW96ttYogUJRDbReHssp7OjW hwKA== X-Gm-Message-State: AOJu0YxzDM6YpBa5xRfXMgXGbvZrzDz14WBXsBAjWehlxELmEpQa229h 7x2CW0ucEL5uiq4SF8DHsWuD4afq85KYLtlP7uFMsw== X-Google-Smtp-Source: AGHT+IGEcoRvEqJF04Nh/lQ0Epwp/1ztnPFLinqXRIB+nSzNpKmodCEIvBkDdIQgsKGLuOYMS1HqYw== X-Received: by 2002:a6b:e71a:0:b0:792:82f8:73fe with SMTP id b26-20020a6be71a000000b0079282f873femr2766181ioh.3.1694802965210; Fri, 15 Sep 2023 11:36:05 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id w25-20020a02cf99000000b0042b0a6d899fsm1235997jar.60.2023.09.15.11.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 11:36:04 -0700 (PDT) Date: Fri, 15 Sep 2023 12:36:03 -0600 Subject: [PATCH 3/4] Use gdb::checked_static_cast for code_breakpoint MIME-Version: 1.0 Message-Id: <20230915-watchpoint-casts-v1-3-a4ff35c9644e@adacore.com> References: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> In-Reply-To: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This replaces some casts to 'code_breakpoint *' with checked_static_cast. --- gdb/breakpoint.c | 6 ++++-- gdb/elfread.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 134ad76ce9a..5d87b17a58d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6174,10 +6174,12 @@ bpstat_run_callbacks (bpstat *bs_head) handle_jit_event (bs->bp_location_at->address); break; case bp_gnu_ifunc_resolver: - gnu_ifunc_resolver_stop ((code_breakpoint *) b); + gnu_ifunc_resolver_stop + (gdb::checked_static_cast (b)); break; case bp_gnu_ifunc_resolver_return: - gnu_ifunc_resolver_return_stop ((code_breakpoint *) b); + gnu_ifunc_resolver_return_stop + (gdb::checked_static_cast (b)); break; } } diff --git a/gdb/elfread.c b/gdb/elfread.c index 55e3e47ceca..8704b52f35b 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1033,7 +1033,7 @@ elf_gnu_ifunc_resolver_return_stop (code_breakpoint *b) "gnu-indirect-function breakpoint type %d"), (int) b->type); } - b = (code_breakpoint *) b_next; + b = gdb::checked_static_cast (b_next); } gdb_assert (b->type == bp_gnu_ifunc_resolver); gdb_assert (b->has_single_location ()); From patchwork Fri Sep 15 18:36:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 76161 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2BD03858C33 for ; Fri, 15 Sep 2023 18:36:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2BD03858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694802990; bh=+glESpznIMCc7o704EobzYrO6pnGGG2Op2QNydhiD/s=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xDeI/opf+ncbY3k+ABxuSiRFgUDXrsVY0eIdJDJx4aRg4unATUy4VVfA135o/Cd1I 2/Xv9IWc7cPVpg11UURROmHwa59ij2aQHN0pFGy39afpV6HFDu774aJB9BmlScFvmP +BEWuYqvfUeRZ70RvVC7OrgJCFpoyPCuJ9j7J9KI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 83AD33858C3A for ; Fri, 15 Sep 2023 18:36:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83AD33858C3A Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-34fcbb4a097so1569645ab.1 for ; Fri, 15 Sep 2023 11:36:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694802966; x=1695407766; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+glESpznIMCc7o704EobzYrO6pnGGG2Op2QNydhiD/s=; b=lwv83IQJBRJ1zUZ0YdsT09NISK3kHe76NF7cEQrfhGb+/u1pPz2gHoAZisD3EooIyb OfwakFxUz0FS1XeBtA1FXixjJdANOeQroDAMn52rxqQFfikVZUeCBpBK1tZ3R5HwD1ra hcnyAYEaDpdWQKISaku7KdBJ2dy6BKxZHuUWE4vudmXP1/BMd5cDWiZccYjaYGY4tCPt wxz5w2Wha1nx0+MRr3FvZd++kbgc7Ex6g7FyeA84dEe9XAcmXBoHcsWnN1RAsS5+a4c8 O8eDtCeLpBNTphat7gwNCbpMUisbh/VJP1wK8msgDIHTChE/PZiGLnVa7rkRkdcQfDCf arjg== X-Gm-Message-State: AOJu0YwW1ZidiSLzGVmYUCvnAn0l8OCsyx0vFJOZVG4bEGeot+Ix2xUL oZDG3P7kUhnREck+SDfboLF6b89wzIV/GihWq08pRQ== X-Google-Smtp-Source: AGHT+IGKfJITDGG4yd/omtAxYcM39zW+FEoJT2hXJSXJCYLnoNtOA8b8D32jDGpQLAZLuIf8jga2sw== X-Received: by 2002:a05:6e02:de2:b0:34f:41ba:7c98 with SMTP id m2-20020a056e020de200b0034f41ba7c98mr2885231ilj.12.1694802965837; Fri, 15 Sep 2023 11:36:05 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id w25-20020a02cf99000000b0042b0a6d899fsm1235997jar.60.2023.09.15.11.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 11:36:05 -0700 (PDT) Date: Fri, 15 Sep 2023 12:36:04 -0600 Subject: [PATCH 4/4] Use gdb::checked_static_cast for catchpoints MIME-Version: 1.0 Message-Id: <20230915-watchpoint-casts-v1-4-a4ff35c9644e@adacore.com> References: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> In-Reply-To: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This replaces some casts to various kinds of catchpoint with checked_static_cast. --- gdb/ada-lang.c | 3 ++- gdb/break-catch-sig.c | 8 +++++--- gdb/break-catch-syscall.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 2496c099f19..b1de58cce6f 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12203,7 +12203,8 @@ ada_catchpoint::allocate_location () bool ada_catchpoint::should_stop_exception (const struct bp_location *bl) const { - struct ada_catchpoint *c = (struct ada_catchpoint *) bl->owner; + struct ada_catchpoint *c + = gdb::checked_static_cast (bl->owner); const struct ada_catchpoint_location *ada_loc = (const struct ada_catchpoint_location *) bl; bool stop; diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c index 10c8b81f8e8..cc4f525e3a3 100644 --- a/gdb/break-catch-sig.c +++ b/gdb/break-catch-sig.c @@ -103,7 +103,8 @@ signal_to_name_or_int (enum gdb_signal sig) int signal_catchpoint::insert_location (struct bp_location *bl) { - struct signal_catchpoint *c = (struct signal_catchpoint *) bl->owner; + struct signal_catchpoint *c + = gdb::checked_static_cast (bl->owner); if (!c->signals_to_be_caught.empty ()) { @@ -130,7 +131,8 @@ int signal_catchpoint::remove_location (struct bp_location *bl, enum remove_bp_reason reason) { - struct signal_catchpoint *c = (struct signal_catchpoint *) bl->owner; + struct signal_catchpoint *c + = gdb::checked_static_cast (bl->owner); if (!c->signals_to_be_caught.empty ()) { @@ -166,7 +168,7 @@ signal_catchpoint::breakpoint_hit (const struct bp_location *bl, const target_waitstatus &ws) { const struct signal_catchpoint *c - = (const struct signal_catchpoint *) bl->owner; + = gdb::checked_static_cast (bl->owner); gdb_signal signal_number; if (ws.kind () != TARGET_WAITKIND_STOPPED) diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 9abf8183984..313ac44562c 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -480,10 +480,10 @@ catch_syscall_enabled (void) static bool catching_syscall_number_1 (struct breakpoint *b, int syscall_number) { - if (is_syscall_catchpoint_enabled (b)) { - struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; + struct syscall_catchpoint *c + = gdb::checked_static_cast (b); if (!c->syscalls_to_be_caught.empty ()) {