From patchwork Wed Mar 1 15:18:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65843 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 B57263858D3C for ; Wed, 1 Mar 2023 15:19:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B57263858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677683976; bh=x9jbd9PJfv45cpocMjVmqy9jHVz4dxXgZrnaDfhWQBw=; 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=BvANP60FNWgxpGkjGYID+uwmm75peaGl1xYI8SG+nf47pvXM/sl/tXmMPAskUAgm5 T68uJGp+FiSo4DluMnDdP66hS7F54qotqHqieOcDPAYaU3uwvZSX42AS5FhjM6HIsc ka1/0ENlJ1SyyLvqCg9t0IwYsEqfwpoy8naZ7mIQ= 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 04B5D3858D3C for ; Wed, 1 Mar 2023 15:18:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04B5D3858D3C Received: by mail-il1-x136.google.com with SMTP id g9so925439ila.8 for ; Wed, 01 Mar 2023 07:18:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677683924; 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=x9jbd9PJfv45cpocMjVmqy9jHVz4dxXgZrnaDfhWQBw=; b=i2wqbQP5FkZOPZnOtyYbk6drSkPKmytEST1gf/V2LC+MHW/HExUKkqYvHMAsGGJRaH gaAoU2Nxkns+hiyUHDTBe9J1XGvMGIZ1YAx1GwXSVbgi77FW1WcYadDpqvb4eTkHH/o5 lzYcGTZp9J0bPKK4jY29Fo+zLOY5Y/39pNt6QrbCl3Sdtv/NkGYDaNkXKgS89dz6ps4B tgHl4xgDB5wRwktvQLPJlDUv5dl8fD4eSzahUQr+wi/LFb4cX/3E6F6RRbqbnBr1NWT2 GtxScxiHlPD3p3elemO/5/hn8bfx/hWcaDXH6vR3nEbFrndTir6mgpVhriJm2ygjhLGm smzg== X-Gm-Message-State: AO0yUKUZkV/XheW2CpjkqoTdwCTNvwmEUDJ0Pe5ENYJMkLIjQZ+lI4XW M237Mn2kO23/Q5aTsPC216cWxd6MHVYpKUao X-Google-Smtp-Source: AK7set/Hn4rN3ZVQk/F9nZrqe+Xu+mYnvS7Fh3bv7HGrANZlC1KESZuXGzASznyBrATbF+EXtiqc3Q== X-Received: by 2002:a05:6e02:1b89:b0:315:7911:748a with SMTP id h9-20020a056e021b8900b003157911748amr15480298ili.1.1677683924238; Wed, 01 Mar 2023 07:18:44 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id p10-20020a02b38a000000b003c4f96913c1sm3974241jan.105.2023.03.01.07.18.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 07:18:43 -0800 (PST) Date: Wed, 01 Mar 2023 08:18:42 -0700 Subject: [PATCH 1/2] Make gdb property batons type-safe MIME-Version: 1.0 Message-Id: <20230301-submit-baton-stuff-v1-1-567d536a8245@adacore.com> References: <20230301-submit-baton-stuff-v1-0-567d536a8245@adacore.com> In-Reply-To: <20230301-submit-baton-stuff-v1-0-567d536a8245@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 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.29 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" gdbtypes treats dynamic property batons as 'void *', but in actuality the only users all use dwarf2_property_baton. This patch changes this code to be type-safe. If a new type is needed here, it seems like that too could be done in a type-safe way. --- gdb/dwarf2/loc.c | 12 ++++-------- gdb/gdbtypes.h | 11 ++++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 4727651027b..bf582bcfeff 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1649,8 +1649,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, { case PROP_LOCEXPR: { - const struct dwarf2_property_baton *baton - = (const struct dwarf2_property_baton *) prop->baton (); + const struct dwarf2_property_baton *baton = prop->baton (); gdb_assert (baton->property_type != NULL); bool is_reference = baton->locexpr.is_reference; @@ -1692,8 +1691,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, case PROP_LOCLIST: { - struct dwarf2_property_baton *baton - = (struct dwarf2_property_baton *) prop->baton (); + struct dwarf2_property_baton *baton = prop->baton (); CORE_ADDR pc; const gdb_byte *data; struct value *val; @@ -1724,8 +1722,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, case PROP_ADDR_OFFSET: { - struct dwarf2_property_baton *baton - = (struct dwarf2_property_baton *) prop->baton (); + struct dwarf2_property_baton *baton = prop->baton (); const struct property_addr_info *pinfo; struct value *val; @@ -1775,8 +1772,7 @@ dwarf2_compile_property_to_c (string_file *stream, CORE_ADDR pc, struct symbol *sym) { - struct dwarf2_property_baton *baton - = (struct dwarf2_property_baton *) prop->baton (); + struct dwarf2_property_baton *baton = prop->baton (); const gdb_byte *data; size_t size; dwarf2_per_cu_data *per_cu; diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index c2253310666..701a64d457a 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -64,6 +64,7 @@ struct value_print_options; struct language_defn; struct dwarf2_per_cu_data; struct dwarf2_per_objfile; +struct dwarf2_property_baton; /* Some macros for char-based bitfields. */ @@ -289,7 +290,7 @@ union dynamic_prop_data /* Storage for dynamic property. */ - void *baton; + dwarf2_property_baton *baton; /* Storage of variant parts for a type. A type with variant parts has all its fields "linearized" -- stored in a single field @@ -339,7 +340,7 @@ struct dynamic_prop m_data.const_val = const_val; } - void *baton () const + dwarf2_property_baton *baton () const { gdb_assert (m_kind == PROP_LOCEXPR || m_kind == PROP_LOCLIST @@ -348,19 +349,19 @@ struct dynamic_prop return m_data.baton; } - void set_locexpr (void *baton) + void set_locexpr (dwarf2_property_baton *baton) { m_kind = PROP_LOCEXPR; m_data.baton = baton; } - void set_loclist (void *baton) + void set_loclist (dwarf2_property_baton *baton) { m_kind = PROP_LOCLIST; m_data.baton = baton; } - void set_addr_offset (void *baton) + void set_addr_offset (dwarf2_property_baton *baton) { m_kind = PROP_ADDR_OFFSET; m_data.baton = baton; From patchwork Wed Mar 1 15:18:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65842 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 B771F385841C for ; Wed, 1 Mar 2023 15:19:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B771F385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677683951; bh=LNRLXbyYMWVJiMLzZWwRM635xSfccEZzAzrkJIv2dks=; 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=PKmogkb4SjM0YaBdmfAgXqasLBuYBHqlmVmEYXYJdMB3/HPjD9cL2Qnlqriuv6QOt Qx2e3MGbS1AomZ2AVMIosHANPbYsAulBiIns9qciE2TxUj64D5lqXFqnKVaVvnYVod 8HidabSp3Vtincek7jZEaD2qqFumBbtu3FAdciXQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id BDE9F3858CDB for ; Wed, 1 Mar 2023 15:18:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDE9F3858CDB Received: by mail-il1-x12b.google.com with SMTP id y14so6426494ilv.4 for ; Wed, 01 Mar 2023 07:18:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677683925; 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=LNRLXbyYMWVJiMLzZWwRM635xSfccEZzAzrkJIv2dks=; b=dOUeH/1m8bQ1/XIL/JFcefcYfOWWAWhPBGhH9BzEI85/aW3aKUBhC4q++XGTA6H/NV DBd6zHn3NsgMxuo6JuCyDNBOnJxsRl7qubmxwWSIlnreDD4oWlnlymTnQH5lCE2HziU/ l0SuaUJ8vJFr53AFt3A4hFXyWQqdEIkAQb+5BHH3OwuZOTgJsG5DcmMJ68IJtN1cAcDo tDGebasFvz03c2cUSKc/VV81lfPCeKXf330jf0vtpgAAqlBOnUDE73l/jJxt9lUkPKhQ PUL6NCDH/NTmWJM6FhiLES2WLjwVfSpZtQ0lqle3NfSTVclab7Si59lfNneSqPI/gY75 NzuQ== X-Gm-Message-State: AO0yUKXeb1o1HHRZEIbER9x2K7YkIQ67IrSjBLnSk9adtN/vb64Z8Qgf efkwTPp/x9MGvRLlsCiRbD2RUXDiDadmptAT X-Google-Smtp-Source: AK7set/MoiZjzxox6YhMejW0o0v15Ymz+qzWu1kXnuTJb9ZvaHPPM2i4++568/aMn9avs5SrUORLoQ== X-Received: by 2002:a05:6e02:152c:b0:310:e816:8c8c with SMTP id i12-20020a056e02152c00b00310e8168c8cmr6747558ilu.3.1677683924911; Wed, 01 Mar 2023 07:18:44 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id p10-20020a02b38a000000b003c4f96913c1sm3974241jan.105.2023.03.01.07.18.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 07:18:44 -0800 (PST) Date: Wed, 01 Mar 2023 08:18:43 -0700 Subject: [PATCH 2/2] Use const for dwarf2_property_baton MIME-Version: 1.0 Message-Id: <20230301-submit-baton-stuff-v1-2-567d536a8245@adacore.com> References: <20230301-submit-baton-stuff-v1-0-567d536a8245@adacore.com> In-Reply-To: <20230301-submit-baton-stuff-v1-0-567d536a8245@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 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.29 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" Once a baton is stored in a struct type, it doesn't make sense to modify it. This patch constifies the API. --- gdb/dwarf2/loc.c | 8 ++++---- gdb/dwarf2/loc.h | 2 +- gdb/gdbtypes.h | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index bf582bcfeff..914e016f085 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -347,7 +347,7 @@ decode_debug_loc_dwo_addresses (dwarf2_per_cu_data *per_cu, can be more than one in the list. */ const gdb_byte * -dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, +dwarf2_find_location_expression (const dwarf2_loclist_baton *baton, size_t *locexpr_length, CORE_ADDR pc) { dwarf2_per_objfile *per_objfile = baton->per_objfile; @@ -1691,7 +1691,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, case PROP_LOCLIST: { - struct dwarf2_property_baton *baton = prop->baton (); + const dwarf2_property_baton *baton = prop->baton (); CORE_ADDR pc; const gdb_byte *data; struct value *val; @@ -1722,7 +1722,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, case PROP_ADDR_OFFSET: { - struct dwarf2_property_baton *baton = prop->baton (); + const dwarf2_property_baton *baton = prop->baton (); const struct property_addr_info *pinfo; struct value *val; @@ -1772,7 +1772,7 @@ dwarf2_compile_property_to_c (string_file *stream, CORE_ADDR pc, struct symbol *sym) { - struct dwarf2_property_baton *baton = prop->baton (); + const dwarf2_property_baton *baton = prop->baton (); const gdb_byte *data; size_t size; dwarf2_per_cu_data *per_cu; diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index 37925f48497..ad60177e93c 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -37,7 +37,7 @@ extern unsigned int entry_values_debug; /* Find a particular location expression from a location list. */ const gdb_byte *dwarf2_find_location_expression - (struct dwarf2_loclist_baton *baton, + (const dwarf2_loclist_baton *baton, size_t *locexpr_length, CORE_ADDR pc); diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 701a64d457a..c4889a4a05b 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -290,7 +290,7 @@ union dynamic_prop_data /* Storage for dynamic property. */ - dwarf2_property_baton *baton; + const dwarf2_property_baton *baton; /* Storage of variant parts for a type. A type with variant parts has all its fields "linearized" -- stored in a single field @@ -340,7 +340,7 @@ struct dynamic_prop m_data.const_val = const_val; } - dwarf2_property_baton *baton () const + const dwarf2_property_baton *baton () const { gdb_assert (m_kind == PROP_LOCEXPR || m_kind == PROP_LOCLIST @@ -349,19 +349,19 @@ struct dynamic_prop return m_data.baton; } - void set_locexpr (dwarf2_property_baton *baton) + void set_locexpr (const dwarf2_property_baton *baton) { m_kind = PROP_LOCEXPR; m_data.baton = baton; } - void set_loclist (dwarf2_property_baton *baton) + void set_loclist (const dwarf2_property_baton *baton) { m_kind = PROP_LOCLIST; m_data.baton = baton; } - void set_addr_offset (dwarf2_property_baton *baton) + void set_addr_offset (const dwarf2_property_baton *baton) { m_kind = PROP_ADDR_OFFSET; m_data.baton = baton;