From patchwork Tue Mar 14 20:04:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66389 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 56AFE3858289 for ; Tue, 14 Mar 2023 20:05:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56AFE3858289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678824315; bh=s521qLDBAWU5AXb3A9jj0wTMwOWk3irppgcSF2KlU/A=; 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=km1q1Gg/ZR3BG4LHPvWYl8WmCz9n+ae+wcIA3nXUklp1MUT9dJbX5K0lJQg1GULZF 8GbXfro1iqygGZySz4T3sXKmdoZ1ueA98Vcg6S6SKBcPbOjktpx8CcFLyAWri1flwz pjQaudxnqPBGWEC65q2Tg9PDKlObLERxiGJGMPok= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 67E323858D39 for ; Tue, 14 Mar 2023 20:04:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67E323858D39 Received: by mail-io1-xd35.google.com with SMTP id v10so6916703iox.8 for ; Tue, 14 Mar 2023 13:04:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678824287; 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=s521qLDBAWU5AXb3A9jj0wTMwOWk3irppgcSF2KlU/A=; b=LJCwP9ZsdEtIh4p1Em2ucTNDZDAQi/ZYssfrNEe6GCNRkEOtyLR0EZPvYXTDUxX1jW qjeqO4UigTi/wFwG5/J0qsMMoD+IVygUXxQeeOio0VuHam4pUJ5vqP/ixYSve7XgO/v8 I/p5IQIJJSkop10++vpIpTiJCHPpTj2t3iKjXk3sFYaZ5vb5AURUkrEFcbGXuTC1KiKU 6rIvxqF4lRRDKDXCc6nPRn8u7hzvK/v4VEJdLKjNq/rJ9NahQzMHU/ifTWqNF9ByTj1D ouMnkzY+WmVaUUgeiAZxbZnkXNWufjNMlBNUzRjxBWuh5Rt3Zc2HH6GcxjfaRjLHoi56 Q8lg== X-Gm-Message-State: AO0yUKUgEbly+GP7hkXwJWdDAOFddIuzkC+iRinsIUcJzCCy2YrgDy1c 3814PQdFGqkDDbGDBCZXEpayaChKxok5UyqY3ew= X-Google-Smtp-Source: AK7set9UVl2QqLgmjGyAdntO6uhIZ0KoKl2S2aG1YbC9OTAuWs1lzLgM6qdLnnto86t8zlK1CTs8vg== X-Received: by 2002:a6b:e80d:0:b0:752:de20:b984 with SMTP id f13-20020a6be80d000000b00752de20b984mr918356ioh.8.1678824287598; Tue, 14 Mar 2023 13:04:47 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id m13-20020a056638224d00b003ee9720740esm1030257jas.153.2023.03.14.13.04.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:04:47 -0700 (PDT) Date: Tue, 14 Mar 2023 14:04:45 -0600 Subject: [PATCH 1/5] Introduce lookup_minimal_symbol_linkage MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v1-1-a235709f7e96@adacore.com> References: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.5 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" This introduces a new function, lookup_minimal_symbol_linkage, and refactors a couple other existing functions to call it. This function will be used in a subsequent patch. --- gdb/minsyms.c | 22 ++++++++++++++++++++++ gdb/minsyms.h | 8 ++++++++ gdb/symtab.c | 31 ++++++++----------------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 02e36cc6dd2..aed37978bb9 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -592,6 +592,28 @@ lookup_minimal_symbol_linkage (const char *name, struct objfile *objf) /* See minsyms.h. */ +struct bound_minimal_symbol +lookup_minimal_symbol_linkage (const char *name, bool only_main) +{ + for (objfile *objfile : current_program_space->objfiles ()) + { + if (objfile->separate_debug_objfile_backlink != nullptr) + continue; + + if (only_main && (objfile->flags & OBJF_MAINLINE) == 0) + continue; + + bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (name, + objfile); + if (minsym.minsym != nullptr) + return minsym; + } + + return {}; +} + +/* See minsyms.h. */ + struct bound_minimal_symbol lookup_minimal_symbol_text (const char *name, struct objfile *objf) { diff --git a/gdb/minsyms.h b/gdb/minsyms.h index e9081495eb1..40513b148ff 100644 --- a/gdb/minsyms.h +++ b/gdb/minsyms.h @@ -236,6 +236,14 @@ extern struct bound_minimal_symbol lookup_minimal_symbol_linkage (const char *name, struct objfile *objf) ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2); +/* A variant of lookup_minimal_symbol_linkage that iterates over all + objfiles. If ONLY_MAIN is true, then only an objfile with + OBJF_MAINLINE will be considered. */ + +extern struct bound_minimal_symbol lookup_minimal_symbol_linkage + (const char *name, bool only_main) + ATTRIBUTE_NONNULL (1); + /* Look through all the current minimal symbol tables and find the first minimal symbol that matches NAME and PC. If OBJF is non-NULL, limit the search to that objfile. Returns a pointer to the minimal diff --git a/gdb/symtab.c b/gdb/symtab.c index e11f9262a22..80395f99f24 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6475,17 +6475,10 @@ get_symbol_address (const struct symbol *sym) gdb_assert (sym->aclass () == LOC_STATIC); const char *linkage_name = sym->linkage_name (); - - for (objfile *objfile : current_program_space->objfiles ()) - { - if (objfile->separate_debug_objfile_backlink != nullptr) - continue; - - bound_minimal_symbol minsym - = lookup_minimal_symbol_linkage (linkage_name, objfile); - if (minsym.minsym != nullptr) - return minsym.value_address (); - } + bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (linkage_name, + false); + if (minsym.minsym != nullptr) + return minsym.value_address (); return sym->m_value.address; } @@ -6498,18 +6491,10 @@ get_msymbol_address (struct objfile *objf, const struct minimal_symbol *minsym) gdb_assert ((objf->flags & OBJF_MAINLINE) == 0); const char *linkage_name = minsym->linkage_name (); - - for (objfile *objfile : current_program_space->objfiles ()) - { - if (objfile->separate_debug_objfile_backlink == nullptr - && (objfile->flags & OBJF_MAINLINE) != 0) - { - bound_minimal_symbol found - = lookup_minimal_symbol_linkage (linkage_name, objfile); - if (found.minsym != nullptr) - return found.value_address (); - } - } + bound_minimal_symbol found = lookup_minimal_symbol_linkage (linkage_name, + true); + if (found.minsym != nullptr) + return found.value_address (); return (minsym->m_value.address + objf->section_offsets[minsym->section_index ()]); } From patchwork Tue Mar 14 20:04:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66392 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 458853858C30 for ; Tue, 14 Mar 2023 20:06:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 458853858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678824367; bh=/YriosOqMT4KogZXG2WZGU7XLzIa6K7FrbguxmXhNcE=; 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=lve3oknSK4gz5mSlZdb6bxT8B0nWCanilUotlPMBff2K0tzeZBOigvp3UhYfVQbov mD8hZi5yWp/cGtaTOWKZCu3TwQ6EP75rKOAmZR+sYdfKx5q7s8YgVnX0W8UsePGhbj zEf2HFk2J2p22A85zSnhzIQZKGKnIOg4/3VApynQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 2CD7A3858C5E for ; Tue, 14 Mar 2023 20:04:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CD7A3858C5E Received: by mail-io1-xd29.google.com with SMTP id v10so6916711iox.8 for ; Tue, 14 Mar 2023 13:04:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678824288; 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=/YriosOqMT4KogZXG2WZGU7XLzIa6K7FrbguxmXhNcE=; b=RiyEa+XrJ6cyEGSYyrQ8Ee6iaZau+casGUARzA0kXvUu33l/pzyYtG5+3wfEh3Twd6 6S9eJ7fMLNl+3LWhnG4chnWaa5wHNlGzg7qMrMevN+WJPodfe6zvCQj+pjkGLgPAZkku fDlcTpHpzFtFWkehKu0pqAEZ0lnrBicPlgJYVOSyeuseHVc+OHneaLO1f1h60I20PqiY 8RigOJt3aCM57woDqn4MMV/QOeO6gBiNXbGvKdk2ZSmILGAYqR5HuY3ChDe5MZw4txMp MC1CRstmZP4w+4NHKvhyU/sXmIJW9P/YmCpAF49saxSXymRRjdJX+bf014WEb4NHuh4t j43A== X-Gm-Message-State: AO0yUKXgkeIX5EhnIFRgTQD0EuV3+8/FFrfDrruHC3Va57qvG/Vs3duB +BAPkrQwy7boPAHaXPQbYTUBy3rAF4LXv4JWdE0= X-Google-Smtp-Source: AK7set/Lgi7nwHuZeps22vhGQd5y5qH3kNs0nG6QLOZgvUJl5PTXhE9AccP5TYDAzvYnhzBDjQWY9Q== X-Received: by 2002:a6b:f617:0:b0:74c:b8f9:651b with SMTP id n23-20020a6bf617000000b0074cb8f9651bmr10667193ioh.1.1678824288316; Tue, 14 Mar 2023 13:04:48 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id m13-20020a056638224d00b003ee9720740esm1030257jas.153.2023.03.14.13.04.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:04:47 -0700 (PDT) Date: Tue, 14 Mar 2023 14:04:46 -0600 Subject: [PATCH 2/5] Bump MAX_SYMBOL_IMPLS MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v1-2-a235709f7e96@adacore.com> References: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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" A subsequent patch will introduce more aclass registrations, causing the number to go over the current maximum. This bumps the number. Note that there's a separate static assert that ensures that this number doesn't get too large for the field size in the symbol. --- gdb/symtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 80395f99f24..57ba61c2c05 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6330,7 +6330,7 @@ static int next_aclass_value = LOC_FINAL_VALUE; /* The maximum number of "aclass" registrations we support. This is constant for convenience. */ -#define MAX_SYMBOL_IMPLS (LOC_FINAL_VALUE + 10) +#define MAX_SYMBOL_IMPLS (LOC_FINAL_VALUE + 11) /* The objects representing the various "aclass" values. The elements from 0 up to LOC_FINAL_VALUE-1 represent themselves, and subsequent From patchwork Tue Mar 14 20:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66391 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 BB4883858421 for ; Tue, 14 Mar 2023 20:05:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB4883858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678824339; bh=0L7VtPS/2rRDN9sHxeCEFeTZgh0aJe7BHhni+VPZJgo=; 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=UtpM2YXLPbPtQPwWppkNgXoKkT4Y4AGKO5vUUkrL0jIwPmlUJ5FFlW3NF5c+tqZ14 6p2kwLOpqLFJ05PB23GDGytFAA6BamWPymNkGt1VHU4jmvqGxpkWKqMjrw/lYDpbnZ 6K8kHy8zg6jg1mrUdbqVvQjCTHYduY30c2uw3dRY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id CCA473858C66 for ; Tue, 14 Mar 2023 20:04:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCA473858C66 Received: by mail-io1-xd2b.google.com with SMTP id b16so6902134iof.11 for ; Tue, 14 Mar 2023 13:04:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678824289; 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=0L7VtPS/2rRDN9sHxeCEFeTZgh0aJe7BHhni+VPZJgo=; b=5H0ZK3t/TxOgbFudst8aOPxmdTkAdrJVTWph23Yo37Bci0q+hQA4M8BxMRFek00fEO oN6bZ7+HIumE2dFDWot3LENypuqNtJxhqmN/jMNDPfUnxqcmEhHc1c5r7wywHIBDmpWX IPvHtPuyZE5m/MYJi/4W3gVdnIfuxm/w4cnIAG4CGRfQETsbC97+zqRCsnqwjlN8s3Sz tDtEq9flmqbIbQRl6jON4o7C0ojnYJiNORDMZRRH/OWFFlfGubxNskAkQ9TUTH7g9koD Sejm9DZLyWYeVXtiP1BoDZxITIOAvZ97W32ZLHwTvk3we758efUkinrDY3K/RId1mnp9 3LYA== X-Gm-Message-State: AO0yUKXaeKRjEBhoiSWs3UYJOurwLygxmeDLsfPWV6TrsAgQUqYZKckE /++sDSi2PG97gij3wtWNiG9k44LQ+xzQq2dZ07w= X-Google-Smtp-Source: AK7set9EjkQZNqrZsZwHOr6wuyAZYr9PSmK6rsHPZWlzNsdERtSbZVnp2M52YfZ7gEOYp33a/Mifnw== X-Received: by 2002:a5d:8594:0:b0:74c:b436:4a9e with SMTP id f20-20020a5d8594000000b0074cb4364a9emr24790263ioj.16.1678824289000; Tue, 14 Mar 2023 13:04:49 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id m13-20020a056638224d00b003ee9720740esm1030257jas.153.2023.03.14.13.04.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:04:48 -0700 (PDT) Date: Tue, 14 Mar 2023 14:04:47 -0600 Subject: [PATCH 3/5] Define symbol::value_block separately MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v1-3-a235709f7e96@adacore.com> References: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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" This moves the definition of symbol::value_block outside of the class. A subsequent patch will change this method to use SYMBOL_BLOCK_OPS, and it seemed simplest to move this method out-of-line, and cleaner to do this as a separate change. --- gdb/symtab.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gdb/symtab.h b/gdb/symtab.h index 005b64b5a08..0a42fd2380c 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1346,10 +1346,7 @@ struct symbol : public general_symbol_info, public allocate_on_obstack m_value.common_block = common_block; } - const block *value_block () const - { - return m_value.block; - } + const block *value_block () const; void set_value_block (const block *block) { @@ -1507,6 +1504,12 @@ struct block_symbol #define SYMBOL_REGISTER_OPS(symbol) ((symbol)->impl ().ops_register) #define SYMBOL_LOCATION_BATON(symbol) (symbol)->aux_value +inline const block * +symbol::value_block () const +{ + return m_value.block; +} + extern int register_symbol_computed_impl (enum address_class, const struct symbol_computed_ops *); From patchwork Tue Mar 14 20:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66390 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 58493385B530 for ; Tue, 14 Mar 2023 20:05:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58493385B530 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678824320; bh=f5c5w7V9UScwknM7yLt2TLNb4G39ZP3FWVMiPPQMJVo=; 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=SrGdE65tL6ET90J2UC7ziZbpbjbTtkxb6rw0nYVpYanwkfDQJzbNafnvV0COXDlxt 3R08d8Gbs8KIaZPMtUXVleBTbZxGpslR9uHxDzl8OwHCd81KkpPKWnAhdkZzSCsHoj jYIpb/4SdrZ0ZPkyY8VOtxLPS0K7j4kP5RbTgUE4= 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 6ECC03858C1F for ; Tue, 14 Mar 2023 20:04:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6ECC03858C1F Received: by mail-il1-x12b.google.com with SMTP id bp11so3841396ilb.3 for ; Tue, 14 Mar 2023 13:04:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678824289; 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=f5c5w7V9UScwknM7yLt2TLNb4G39ZP3FWVMiPPQMJVo=; b=sow75BW42tr97kfWiuoEOsXe3jLOgg/QpIubIKTiSrrYG8He815sLBbGOicdW0WxEn 5LcC1hlUqxL5zbpeMlKZJNnBTiEC8R+0B+LJvrOGAiAHlI2t4i/yCKQw3dujJFppGvT8 1ekqvYNc1tw57WclY7cJsWuCIzz8cFJOnI0PUTdnR/uRMnDah+eBUNaU9vONSa4Kkvhn NNs0n9Nt8Tjp3eQPuZsnQuu7KHftpgBCamiVU/5WQJ7TM7UM/OzoOjXImSkRyy6mt+eC J/Cq0qqLdd54vQ/OZfU2KzDT2RGgdQe8/X1feRymRaXdnx30vB7fDSv/w36zS/LgVrb4 AXXg== X-Gm-Message-State: AO0yUKUJ6fD2ZTb1cimJM/P2gI4Oash1K4j3+usUCwM9Zkx68zzq8Na4 20J7NaccnDlq/mF+7c10OpwwYOkP+PIxRSxjUig= X-Google-Smtp-Source: AK7set+CLpXG6/rn1MPeYOP5LyzS8CJlXsxaZCfISNHC78W32KDZgDPopw6UPG/X36f4Bt00q+fCCQ== X-Received: by 2002:a05:6e02:d46:b0:317:6ead:2e4e with SMTP id h6-20020a056e020d4600b003176ead2e4emr3131583ilj.5.1678824289611; Tue, 14 Mar 2023 13:04:49 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id m13-20020a056638224d00b003ee9720740esm1030257jas.153.2023.03.14.13.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:04:49 -0700 (PDT) Date: Tue, 14 Mar 2023 14:04:48 -0600 Subject: [PATCH 4/5] Introduce symbol_block_ops::get_block_value MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v1-4-a235709f7e96@adacore.com> References: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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" This adds a new callback to symbol_block_ops. This callback lets a LOC_BLOCK symbol implement its own function to find the underlying block. --- gdb/symtab.c | 3 ++- gdb/symtab.h | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 57ba61c2c05..237b3ff794f 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6391,7 +6391,8 @@ register_symbol_block_impl (enum address_class aclass, /* Sanity check OPS. */ gdb_assert (ops != NULL); - gdb_assert (ops->find_frame_base_location != NULL); + gdb_assert (ops->find_frame_base_location != nullptr + || ops->get_block_value != nullptr); return result; } diff --git a/gdb/symtab.h b/gdb/symtab.h index 0a42fd2380c..ea3cf395f26 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1149,6 +1149,12 @@ struct symbol_block_ops the corresponding DW_AT_frame_base attribute. */ CORE_ADDR (*get_frame_base) (struct symbol *framefunc, frame_info_ptr frame); + + /* Return the block for this function. So far, this is used to + implement function aliases. So, if this is set, then it's not + necessary to set the other functions in this structure; and vice + versa. */ + const block *(*get_block_value) (const struct symbol *sym); }; /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR. */ @@ -1507,6 +1513,9 @@ struct block_symbol inline const block * symbol::value_block () const { + if (SYMBOL_BLOCK_OPS (this) != nullptr + && SYMBOL_BLOCK_OPS (this)->get_block_value != nullptr) + return SYMBOL_BLOCK_OPS (this)->get_block_value (this); return m_value.block; } From patchwork Tue Mar 14 20:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66393 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 7DE803858414 for ; Tue, 14 Mar 2023 20:06:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7DE803858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678824395; bh=LgtCzEpO41R+22VHKlvwCiAK1EnheHfAYJDdiMB2wkY=; 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=VkxyIEBGQK7iBCxwd2HYk1TMIDMBWW+Pezwrky+Wkiz4rWOqrfjcqjPFIUzgQS220 xVN4qYjIXXbFbkSXtZsD4xrRHtR/YsLYsMaAkxgfrwYW3cQkqaibFZS1q8Pc8WIGH1 Nx5KlyklPd6D+ejZ09Ql2ZCwSmt9BxCtmreyjpGI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id BD0DD3858C2F for ; Tue, 14 Mar 2023 20:04:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD0DD3858C2F Received: by mail-io1-xd36.google.com with SMTP id v10so401259iol.9 for ; Tue, 14 Mar 2023 13:04:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678824290; 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=LgtCzEpO41R+22VHKlvwCiAK1EnheHfAYJDdiMB2wkY=; b=jGWu1CElkNZUX+yWOlYNECHiG7bkLzRJjwdgaPZsPVj662mqxWGWz4S2pjwa8RQT28 bs327ejxcWNsBTxjBcq16HOty/AMXLALbO8Vv03q8dbvBdefNTG5JnnlyBsK4VSyn4RY HkRF+V9Y0s5w05T51JCL9tos2rC2ktIz17Qi+X0+yaIcM0RxETGVChrl5/wAJBEi1Moh 82N46SZhOQvYThrCeoFbYhOh/9QozKnG2NZha9lRasJu8/J3rQlmFr0h4OGviBwh62av T84NfVxKSFwi/AA2S83kF/ydR81D9jgV+3IpcQ3NAEwGxtoWTutIz9ZVC1eSDSBjcTva 4QAQ== X-Gm-Message-State: AO0yUKWVZ7YHteilzfD6PQAzPi0mfLLglaMLU7A+EyGnBtcvvlUrWUsw POdCgMMLmKkkmQdbURn0gIwAKkLTlRX6SrZEoKs= X-Google-Smtp-Source: AK7set/c+v6zowHZpzNgb23Nj/ZD8Zj1YtZCUj27uP638v9lPsT5i4Ic3I94LHLiG07IEAkKc6f1Aw== X-Received: by 2002:a6b:6a1a:0:b0:704:b905:e652 with SMTP id x26-20020a6b6a1a000000b00704b905e652mr23783697iog.11.1678824290221; Tue, 14 Mar 2023 13:04:50 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id m13-20020a056638224d00b003ee9720740esm1030257jas.153.2023.03.14.13.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:04:49 -0700 (PDT) Date: Tue, 14 Mar 2023 14:04:49 -0600 Subject: [PATCH 5/5] Handle Ada Pragma Import and Pragma Export MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v1-5-a235709f7e96@adacore.com> References: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, 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" Ada can import C APIs and also export Ada constructs to C via Pragma Import and Pragma Export. This patch adds support for these to gdb, by arranging to either defer some aspects of a symbol to the underlying C symbol (for Import) or by introducing a second symbol (for Export). A somewhat tricky approach is needed, both because gdb doesn't generally handle symbol aliasing, and because Ada treats symbol names in an unusual way (as compared to the rest of gdb). --- gdb/Makefile.in | 1 + gdb/dwarf2/ada-imported.c | 122 +++++++++++++++++++++++++++++ gdb/dwarf2/loc.h | 2 + gdb/dwarf2/read.c | 128 +++++++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/complete.exp | 2 + gdb/testsuite/gdb.ada/complete/pck.ads | 4 +- gdb/testsuite/gdb.ada/import.exp | 58 ++++++++++++++ gdb/testsuite/gdb.ada/import/inc.c | 27 +++++++ gdb/testsuite/gdb.ada/import/pkg.adb | 28 +++++++ gdb/testsuite/gdb.ada/import/pkg.ads | 33 ++++++++ gdb/testsuite/gdb.ada/import/prog.adb | 31 ++++++++ gdb/testsuite/gdb.ada/info_auto_lang.exp | 10 ++- 12 files changed, 442 insertions(+), 4 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 40497541880..a8d665ef5a6 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1062,6 +1062,7 @@ COMMON_SFILES = \ dummy-frame.c \ dwarf2/abbrev.c \ dwarf2/abbrev-cache.c \ + dwarf2/ada-imported.c \ dwarf2/attribute.c \ dwarf2/comp-unit-head.c \ dwarf2/cooked-index.c \ diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c new file mode 100644 index 00000000000..d1d99be6923 --- /dev/null +++ b/gdb/dwarf2/ada-imported.c @@ -0,0 +1,122 @@ +/* Ada Pragma Import support. + + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" +#include "symtab.h" +#include "value.h" +#include "dwarf2/loc.h" + +/* Helper to get the imported symbol's real name. */ +static const char * +get_imported_name (const struct symbol *sym) +{ + return (const char *) SYMBOL_LOCATION_BATON (sym); +} + +/* Implement the read_variable method from symbol_computed_ops. */ + +static struct value * +ada_imported_read_variable (struct symbol *symbol, frame_info_ptr frame) +{ + const char *name = get_imported_name (symbol); + bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (name, false); + if (minsym.minsym == nullptr) + error (_("could not find imported name %s"), name); + return value_at (symbol->type (), minsym.value_address ()); +} + +/* Implement the read_variable method from symbol_computed_ops. */ + +static enum symbol_needs_kind +ada_imported_get_symbol_read_needs (struct symbol *symbol) +{ + return SYMBOL_NEEDS_NONE; +} + +/* Implement the describe_location method from + symbol_computed_ops. */ + +static void +ada_imported_describe_location (struct symbol *symbol, CORE_ADDR addr, + struct ui_file *stream) +{ + gdb_printf (stream, "an imported name for '%s'", + get_imported_name (symbol)); +} + +/* Implement the tracepoint_var_ref method from + symbol_computed_ops. */ + +static void +ada_imported_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, + struct axs_value *value) +{ + /* Probably could be done, but not needed right now. */ + error (_("not implemented: trace of imported Ada symbol")); +} + +/* Implement the generate_c_location method from + symbol_computed_ops. */ + +static void +ada_imported_generate_c_location (struct symbol *symbol, string_file *stream, + struct gdbarch *gdbarch, + std::vector ®isters_used, + CORE_ADDR pc, const char *result_name) +{ + /* Probably could be done, but not needed right now, and perhaps not + ever. */ + error (_("not implemented: compile translation of imported Ada symbol")); +} + +const struct symbol_computed_ops ada_imported_funcs = +{ + ada_imported_read_variable, + nullptr, + ada_imported_get_symbol_read_needs, + ada_imported_describe_location, + 0, + ada_imported_tracepoint_var_ref, + ada_imported_generate_c_location +}; + +/* Implement the get_block_value method from symbol_block_ops. */ + +static const block * +ada_alias_get_block_value (const struct symbol *sym) +{ + const char *name = get_imported_name (sym); + block_symbol real_symbol = lookup_global_symbol (name, nullptr, + VAR_DOMAIN); + if (real_symbol.symbol == nullptr) + error (_("could not find alias '%s' for function '%s'"), + name, sym->print_name ()); + if (real_symbol.symbol->aclass () != LOC_BLOCK) + error (_("alias '%s' for function '%s' is not a function"), + name, sym->print_name ()); + + return real_symbol.symbol->value_block (); +} + +const struct symbol_block_ops ada_function_alias_funcs = +{ + nullptr, + nullptr, + ada_alias_get_block_value +}; diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index ad60177e93c..1fec834787b 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -246,9 +246,11 @@ struct dwarf2_property_baton extern const struct symbol_computed_ops dwarf2_locexpr_funcs; extern const struct symbol_computed_ops dwarf2_loclist_funcs; +extern const struct symbol_computed_ops ada_imported_funcs; extern const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs; extern const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs; +extern const struct symbol_block_ops ada_function_alias_funcs; /* Determined tail calls for constructing virtual tail call frames. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 138537cfefd..a47f7f61b51 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -142,8 +142,10 @@ static const registry::key static int dwarf2_locexpr_index; static int dwarf2_loclist_index; +static int ada_imported_index; static int dwarf2_locexpr_block_index; static int dwarf2_loclist_block_index; +static int ada_block_index; /* Size of .debug_loclists section header for 32-bit DWARF format. */ #define LOCLIST_HEADER_SIZE32 12 @@ -1072,6 +1074,9 @@ static void queue_comp_unit (dwarf2_per_cu_data *per_cu, static void process_queue (dwarf2_per_objfile *per_objfile); +static bool is_ada_import_or_export (dwarf2_cu *cu, const char *name, + const char *linkagename); + /* Class, the destructor of which frees all allocated queue entries. This will only have work to do if an error was thrown while processing the dwarf. If no error was thrown then the queue entries should have all @@ -9993,6 +9998,31 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) compute_delayed_physnames (origin_cu); } +/* A helper to handle Ada's "Pragma Import" feature when it is applied + to a function. */ + +static bool +check_ada_pragma_import (struct die_info *die, struct dwarf2_cu *cu) +{ + /* A Pragma Import will have both a name and a linkage name. */ + const char *name = dwarf2_name (die, cu); + if (name == nullptr) + return false; + + const char *linkage_name = dw2_linkage_name (die, cu); + /* Disallow the special Ada symbols. */ + if (!is_ada_import_or_export (cu, name, linkage_name)) + return false; + + /* A Pragma Import will be a declaration, while a Pragma Export will + not be. */ + if (!die_is_declaration (die, cu)) + return false; + + new_symbol (die, read_type_die (die, cu), cu); + return true; +} + static void read_func_scope (struct die_info *die, struct dwarf2_cu *cu) { @@ -10039,6 +10069,14 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) return; } + if (check_ada_pragma_import (die, cu)) + { + /* We already made the symbol for the Pragma Import, and because + it is a declaration, we know it won't have any other + important information, so we can simply return. */ + return; + } + /* Ignore functions with missing or invalid low and high pc attributes. */ if (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, nullptr, nullptr) <= PC_BOUNDS_INVALID) @@ -18751,6 +18789,51 @@ var_decode_location (struct attribute *attr, struct symbol *sym, cu->has_loclist = true; } +/* A helper function to add an "export" symbol. The new symbol starts + as a clone of ORIG, but is modified to defer to the symbol named + ORIG_NAME. The original symbol uses the name given in the source + code, and the symbol that is created here uses the linkage name as + its name. See ada-imported.c. */ + +static void +add_ada_export_symbol (struct symbol *orig, const char *new_name, + const char *orig_name, struct dwarf2_cu *cu, + struct pending **list_to_add) +{ + struct symbol *copy + = new (&cu->per_objfile->objfile->objfile_obstack) symbol (*orig); + copy->set_linkage_name (new_name); + SYMBOL_LOCATION_BATON (copy) = (void *) orig_name; + copy->set_aclass_index (copy->aclass () == LOC_BLOCK + ? ada_block_index + : ada_imported_index); + add_symbol_to_list (copy, list_to_add); +} + +/* A helper function that decides if a given symbol is an Ada Pragma + Import or Pragma Export. */ + +static bool +is_ada_import_or_export (dwarf2_cu *cu, const char *name, + const char *linkagename) +{ + return (cu->lang () == language_ada + && linkagename != nullptr + && !streq (name, linkagename) + /* The following exclusions are necessary because symbols + with names or linkage names that match here will meet the + other criteria but are not in fact caused by Pragma + Import or Pragma Export, and applying the import/export + treatment to them will introduce problems. Some of these + checks only apply to functions, but it is simpler and + harmless to always do them all. */ + && !startswith (name, "__builtin") + && !startswith (linkagename, "___ghost_") + && !startswith (linkagename, "__gnat") + && !startswith (linkagename, "_ada_") + && !streq (linkagename, "adainit")); +} + /* Given a pointer to a DWARF information entry, figure out if we need to make a symbol table entry for it, and if so, create a new entry and return a pointer to it. @@ -18891,6 +18974,28 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, { list_to_add = cu->list_in_scope; } + + if (is_ada_import_or_export (cu, name, linkagename)) + { + /* This is either a Pragma Import or Export. They can + be distinguished by the declaration flag. */ + sym->set_linkage_name (name); + if (die_is_declaration (die, cu)) + { + /* For Import, create a symbol using the source + name, and have it refer to the linkage name. */ + SYMBOL_LOCATION_BATON (sym) = (void *) linkagename; + sym->set_aclass_index (ada_block_index); + } + else + { + /* For Export, create a symbol using the source + name, then create a second symbol that refers + back to it. */ + add_ada_export_symbol (sym, linkagename, name, cu, + list_to_add); + } + } break; case DW_TAG_inlined_subroutine: /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by @@ -18983,6 +19088,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, } else list_to_add = cu->list_in_scope; + + if (is_ada_import_or_export (cu, name, linkagename)) + { + /* This is a Pragma Export. A Pragma Import won't + be seen here, because it will not have a location + and so will be handled below. */ + add_ada_export_symbol (sym, name, linkagename, cu, + list_to_add); + } } else { @@ -19004,6 +19118,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, if (!suppress_add) list_to_add = cu->list_in_scope; } + else if (is_ada_import_or_export (cu, name, linkagename)) + { + /* This is a Pragma Import. A Pragma Export won't + be seen here, because it will have a location and + so will be handled above. */ + sym->set_linkage_name (name); + list_to_add = cu->list_in_scope; + SYMBOL_LOCATION_BATON (sym) = (void *) linkagename; + sym->set_aclass_index (ada_imported_index); + } else if (attr2 != nullptr && attr2->as_boolean () && dwarf2_attr (die, DW_AT_type, cu) != NULL) { @@ -21935,11 +22059,15 @@ the demangler."), &dwarf2_locexpr_funcs); dwarf2_loclist_index = register_symbol_computed_impl (LOC_COMPUTED, &dwarf2_loclist_funcs); + ada_imported_index = register_symbol_computed_impl (LOC_COMPUTED, + &ada_imported_funcs); dwarf2_locexpr_block_index = register_symbol_block_impl (LOC_BLOCK, &dwarf2_block_frame_base_locexpr_funcs); dwarf2_loclist_block_index = register_symbol_block_impl (LOC_BLOCK, &dwarf2_block_frame_base_loclist_funcs); + ada_block_index = register_symbol_block_impl (LOC_BLOCK, + &ada_function_alias_funcs); #if GDB_SELF_TEST selftests::register_test ("dw2_expand_symtabs_matching", diff --git a/gdb/testsuite/gdb.ada/complete.exp b/gdb/testsuite/gdb.ada/complete.exp index 57b65466012..9e9250545e9 100644 --- a/gdb/testsuite/gdb.ada/complete.exp +++ b/gdb/testsuite/gdb.ada/complete.exp @@ -160,6 +160,7 @@ test_gdb_complete "pck" \ "p pck.ambiguous_func" \ "p pck.external_identical_one" \ "p pck.inner.inside_variable" \ + "p pck.internal_capitalized" \ "p pck.local_identical_one" \ "p pck.local_identical_two" \ "p pck.my_global_variable" \ @@ -172,6 +173,7 @@ test_gdb_complete "pck." \ "p pck.ambiguous_func" \ "p pck.external_identical_one" \ "p pck.inner.inside_variable" \ + "p pck.internal_capitalized" \ "p pck.local_identical_one" \ "p pck.local_identical_two" \ "p pck.my_global_variable" \ diff --git a/gdb/testsuite/gdb.ada/complete/pck.ads b/gdb/testsuite/gdb.ada/complete/pck.ads index 77f89678fae..034c142d91d 100644 --- a/gdb/testsuite/gdb.ada/complete/pck.ads +++ b/gdb/testsuite/gdb.ada/complete/pck.ads @@ -17,8 +17,8 @@ package Pck is My_Global_Variable : Integer := 1; - Exported_Capitalized : Integer := 2; - pragma Export (C, Exported_Capitalized, "Exported_Capitalized"); + Internal_Capitalized : Integer := 2; + pragma Export (C, Internal_Capitalized, "Exported_Capitalized"); Local_Identical_One : Integer := 4; Local_Identical_Two : Integer := 8; diff --git a/gdb/testsuite/gdb.ada/import.exp b/gdb/testsuite/gdb.ada/import.exp new file mode 100644 index 00000000000..866b431aac5 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import.exp @@ -0,0 +1,58 @@ +# Copyright 2023 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile prog + +set cfile "inc" +set csrcfile ${srcdir}/${subdir}/${testdir}/${cfile}.c +set cobject [standard_output_file ${cfile}.o] + +if {[gdb_compile "${csrcfile}" "${cobject}" object debug] != ""} { + untested "could not compile C file" + return +} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \ + [list debug additional_flags=-largs \ + additional_flags=${cobject} additional_flags=-margs]] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "BREAK" ${testdir}/prog.adb] +runto "prog.adb:$bp_location" + +gdb_test "print ordinary_var" " = 78" + +gdb_test "print imported_var" " = 42" +gdb_test "print imported_var_ada" " = 42" +gdb_test "print local_imported_var" " = 42" +gdb_test "print pkg.imported_var_ada" " = 42" + +gdb_test "print pkg.exported_var_ada" " = 99" +gdb_test "print exported_var_ada" " = 99" + +gdb_breakpoint "pkg.imported_func_ada" message +gdb_breakpoint "imported_func" message +gdb_breakpoint "imported_func_ada" message + +gdb_breakpoint "local_imported_func" message +gdb_breakpoint "pkg.exported_func_ada" message +gdb_breakpoint "exported_func_ada" message +gdb_breakpoint "exported_func" message diff --git a/gdb/testsuite/gdb.ada/import/inc.c b/gdb/testsuite/gdb.ada/import/inc.c new file mode 100644 index 00000000000..c3a1ea18d55 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/inc.c @@ -0,0 +1,27 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +extern int exported_var; +extern int exported_func (void); + +int imported_var = 42; + +int +imported_func (void) +{ + return exported_var + exported_func (); +} diff --git a/gdb/testsuite/gdb.ada/import/pkg.adb b/gdb/testsuite/gdb.ada/import/pkg.adb new file mode 100644 index 00000000000..e4f1c1a88b7 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/pkg.adb @@ -0,0 +1,28 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +package body Pkg is + + function Exported_Func_Ada return Integer is + begin + return Imported_Var_Ada; + end Exported_Func_Ada; + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + +end Pkg; diff --git a/gdb/testsuite/gdb.ada/import/pkg.ads b/gdb/testsuite/gdb.ada/import/pkg.ads new file mode 100644 index 00000000000..5576d1b92d7 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/pkg.ads @@ -0,0 +1,33 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with System; +package Pkg is + + Imported_Var_Ada : Integer; + pragma Import (C, Imported_Var_Ada, "imported_var"); + + function Imported_Func_Ada return Integer; + pragma Import (C, Imported_Func_Ada, "imported_func"); + + Exported_Var_Ada : Integer := 99; + pragma Export (C, Exported_Var_Ada, "exported_var"); + + function Exported_Func_Ada return Integer; + pragma Export (C, Exported_Func_Ada, "exported_func"); + + procedure Do_Nothing (A : System.Address); + +end Pkg; diff --git a/gdb/testsuite/gdb.ada/import/prog.adb b/gdb/testsuite/gdb.ada/import/prog.adb new file mode 100644 index 00000000000..77f2073a633 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/prog.adb @@ -0,0 +1,31 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with Pkg; + +procedure Prog is + Ordinary_Var : Integer := 78; + + Local_Imported_Var : Integer; + pragma Import (C, Local_Imported_Var, "imported_var"); + + function Local_Imported_Func return Integer; + pragma Import (C, Local_Imported_Func, "imported_func"); +begin + Local_Imported_Var := Local_Imported_Func; -- BREAK + Pkg.Imported_Var_Ada := Pkg.Imported_Func_Ada; + Pkg.Do_Nothing (Pkg.Imported_Func_Ada'Address); + Pkg.Do_Nothing (Pkg.Exported_Func_Ada'Address); +end Prog; diff --git a/gdb/testsuite/gdb.ada/info_auto_lang.exp b/gdb/testsuite/gdb.ada/info_auto_lang.exp index 5202605b731..5134643c0ca 100644 --- a/gdb/testsuite/gdb.ada/info_auto_lang.exp +++ b/gdb/testsuite/gdb.ada/info_auto_lang.exp @@ -51,8 +51,14 @@ if {![runto "some_c.c:$bp_location"]} { set func_in_c(c_syntax) "${decimal}: void proc_in_c\\\(void\\\);" set func_in_c(ada_syntax) "${decimal}: procedure proc_in_c;" -set func_in_ada(c_syntax) "${decimal}: void proc_in_ada\\\(void\\\);" -set func_in_ada(ada_syntax) "${decimal}: procedure proc_in_ada;" +set func_in_ada(c_syntax) \ + [string cat \ + "${decimal}: void proc_in_ada\\\(void\\\);\r\n" \ + "${decimal}: void proc_in_ada.something_in_c\\\(void\\\);"] +set func_in_ada(ada_syntax) \ + [string cat \ + "${decimal}: procedure proc_in_ada;\r\n" \ + "${decimal}: procedure proc_in_ada.something_in_c;"] set type_in_c(c_syntax) "${decimal}: typedef struct {\\.\\.\\.} some_type_in_c;" set type_in_c(ada_syntax) [multi_line \