From patchwork Fri Apr 7 16:39:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67520 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 D67873856DE0 for ; Fri, 7 Apr 2023 16:40:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D67873856DE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885625; bh=1TOq/2DEuK1VgZgjB/lLT+gFTjHyFw74Qg3ipNoV2dY=; 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=Z0KiVRr6l8lOG3q6V0NCzJxGxhUJHdUd48hW2eavV3gNG7+B0QBfWYntnuGPVZAIi HUhmM6Qv0E0+HVZTcHv4b6F4xfwKtbLniP/DiENelQygtiXaFfy9omvngwhjyCJTOd Awqa5VSP/GX7Nlb8dy787aI1+KAyD/kqg/P9R5ag= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id BF8F63858D33 for ; Fri, 7 Apr 2023 16:39:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF8F63858D33 Received: by mail-il1-x134.google.com with SMTP id h14so21054512ilj.0 for ; Fri, 07 Apr 2023 09:39:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885596; x=1683477596; 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=1TOq/2DEuK1VgZgjB/lLT+gFTjHyFw74Qg3ipNoV2dY=; b=0XU0zUHC1YyKz4MBrUUX3a16icGgsshHvkBt0cfBCXCT07GoXexx/xpSa/6LrALH1h MhA2xwF0HnFKQfMverlVs31EzXAcYU829JXrVrXfbKVPCkxhfZeRhgeBAQt4g1nnV0hY bKRlsmW0wdrdMlgCAIO7PrT12d8QEulvEG2VFcLlHTPBjO2rda70STADWsRYzsAKN4MU FQ+wGSPlaGQs6DYfDfWNnPxypYDiyWywB5NMI9fkp9tOYGLMO0cExXk/Zrr5B4+8Nc78 EYpW4SbsSRnCZBrT1RFE0V1GCP4pbuuvZmzp48M7+AYOSzU43cpmUnWSDJ05E35WoY1D 1Qdg== X-Gm-Message-State: AAQBX9c/0jUGzawH5OYf97OYBgkVhb4SGHTN7I1FRSvCcGqvzx5S08an M11Dn+FWjXwoFhFa2AwzQRyJvXKRfHhRLicL8mdjFw== X-Google-Smtp-Source: AKy350YA8rkbdcAWSEpy6hLKlDk5+ilujt6IXNoCJwqflq7uVq4XhhbjEWYuumUQITyfpA1xI0DVOA== X-Received: by 2002:a92:c9cd:0:b0:316:b0b2:beff with SMTP id k13-20020a92c9cd000000b00316b0b2beffmr1832021ilq.4.1680885596017; Fri, 07 Apr 2023 09:39:56 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:55 -0700 (PDT) Date: Fri, 07 Apr 2023 10:39:54 -0600 Subject: [PATCH v2 1/8] Introduce lookup_minimal_symbol_linkage MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-1-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 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 3fa07f47b9f..8185e9cd727 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 59c276f01f3..f3a2474c796 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 9e9798676cb..9b0887c8d65 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6488,17 +6488,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; } @@ -6511,18 +6504,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 Fri Apr 7 16:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67519 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 056983858412 for ; Fri, 7 Apr 2023 16:40:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 056983858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885624; bh=7rPLgz7ZQNylSGCbZx0mHwVo9TP0+jcY3VXUTWhBEPg=; 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=uEoqA11AH1M/DYxlcZ4+hrg2s7BEhxysjb4355OvOUcZR5TB0VHbCqL+d9aNvkjz4 sjRUNbbGkAvtcR6wlw2qC35TA0FNJSf7Ra3AAZnVfYuhTjhoKvWObJrWdkd+M6JeMn JEpi8j8F3cXidQ/fzjPHaGho/zxWSRcZSrUyn8h8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 60EC13858D35 for ; Fri, 7 Apr 2023 16:39:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60EC13858D35 Received: by mail-il1-x12e.google.com with SMTP id u8so22415179ilb.2 for ; Fri, 07 Apr 2023 09:39:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885596; x=1683477596; 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=7rPLgz7ZQNylSGCbZx0mHwVo9TP0+jcY3VXUTWhBEPg=; b=l/88i4zVncxvCjw9y59oxHaf4Qed3eX4VvuCjq9emUMX5Zfp2dhhrWxCJaX2Ath2Fl fmd/E7ejEFe+NisWeAcaTb1dmTbC+CqyQiA53JguUxQQlAGungzzLaZb+xZTOejgBg6Y XBdQR2ZWxMnCgxA3+gGYm3sdGqIXn9M4l1gx+LIVcGiDXrQ3+6frfTaJwX8YpfgkMbxD xhO0Ab2XzFQRYL8Z5EssjH3Jc+UsN2g2F7x3kdCWzKEj4Jlcvi7Y5rJ0GygMHgNiPuxq 14YIKVSSeLMLoM8KClycKTyMTnB3A9KtsxMRnofZMzoR9BCWgmdlvcQVkdVW9r5qYkwJ fDsA== X-Gm-Message-State: AAQBX9f+eI7+XEylSJCIKEeLw+pNjsshYv1BGVO6SxkNf3DWjoUAUCcZ b492JcTUxi2Q0GS+XuudkfnHJbELTIKukyzuhITkWQ== X-Google-Smtp-Source: AKy350axvzeg7HwqR/Wf59NBa/xG30Aqu28OKtB11sFRANIhUDy46yqKBTQLZ75ZCJZdQkp9l2QSvg== X-Received: by 2002:a92:d906:0:b0:325:cf1a:34d0 with SMTP id s6-20020a92d906000000b00325cf1a34d0mr1941860iln.4.1680885596602; Fri, 07 Apr 2023 09:39:56 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:56 -0700 (PDT) Date: Fri, 07 Apr 2023 10:39:55 -0600 Subject: [PATCH v2 2/8] Bump MAX_SYMBOL_IMPLS MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-2-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.1 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 9b0887c8d65..b7b77818fbe 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6343,7 +6343,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 Fri Apr 7 16:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67524 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 25E57385771C for ; Fri, 7 Apr 2023 16:40:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25E57385771C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885656; bh=A6NESOMdLk6jlGAEBiuJ64Ol8ViI008RBkERGqlgFHQ=; 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=vos+ZDMgNR9x0xvdRuQD62YjPtX7OJmbi1FNJNF+khwWptmrwsFpcsxZO2etl+cmB qR5fj/K7UClZwonvAqz4bvXn3xUH1gLgLXv/8bnBPpruJBTENtEdcDXl7XChujd1ME xEcWlDfQ94kXLXK+fZ8JWXMlaTSWXRPtTHVYfjwc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 0EF1E3858CDA for ; Fri, 7 Apr 2023 16:39:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EF1E3858CDA Received: by mail-il1-x135.google.com with SMTP id h11so22407614ild.11 for ; Fri, 07 Apr 2023 09:39:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885597; x=1683477597; 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=A6NESOMdLk6jlGAEBiuJ64Ol8ViI008RBkERGqlgFHQ=; b=FfauOFBBYRKQvUVykB295QZlqQ57vbhRJdafg9dM+mTEy5asI27fjHxBPsQB1OHXD0 mPExFdPObr+aRXGpcdLCm4L+78wPLGQHiTw6HCNUrD3VHVmdt2vgbXKr9NGb0+NYUwmc oVE9mxcEH+9789UozrxtNjkapj3S6YY0btDLthwocLmvqHIkBHoCasYJV70cAwNukwoP Ju8QnTsEDNs6fl9dRjYs8Ci6UtQCH3aFyXMWD4vAuHIu+BZHIlNPSdLSMgH9Agcf6KFD yldGAsynWiLeet5fRbJekOjKBBF46QPHQJn+zGrigXjx5ZphSXP69xA6ZRTAYXLeNHG5 Eu5w== X-Gm-Message-State: AAQBX9flCheY+qgopBhxD3Wr3e9S2BzaLbuTpyz4WA0hBFjnRCalKF3F vQXEc3fNxwwWq66WGguhJdPYd5izIC7EVefeR31NRA== X-Google-Smtp-Source: AKy350bzzJ2chs4Sy+JfVu/XxTGOEEMHwqo5nBWcpZj6DxxZkgSJnbIsJqx34JM9mVyqzqJHttm9yQ== X-Received: by 2002:a92:c703:0:b0:326:4079:79b0 with SMTP id a3-20020a92c703000000b00326407979b0mr1775914ilp.9.1680885597252; Fri, 07 Apr 2023 09:39:57 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:56 -0700 (PDT) Date: Fri, 07 Apr 2023 10:39:56 -0600 Subject: [PATCH v2 3/8] Define symbol::value_block separately MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-3-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.1 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 404d0ab30a8..8d3f5610bd3 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1379,10 +1379,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) { @@ -1536,6 +1533,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 Fri Apr 7 16:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67522 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 B944E38555AE for ; Fri, 7 Apr 2023 16:40:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B944E38555AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885652; bh=JaK+wZAH1T/5WThjHTNFAIi14X8IxTArPcvcrt4iVHc=; 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=ICALY/wOAIsAC2+416T+F9NlWIB+xugUjFEeFlijszOm+nIDdw8pigJOYAdb+m1Qj 5OozsY7igUD4267pglh6gZlNr39udFjmOPjOj41R5DdINMJXDSxpN8K3S+mf/mnCap Kel6r4XoUxvNugzKm7KrneZb28fJks8zNeAbh1P0= 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 A281F3858C83 for ; Fri, 7 Apr 2023 16:39:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A281F3858C83 Received: by mail-io1-xd30.google.com with SMTP id o10so10743742iou.5 for ; Fri, 07 Apr 2023 09:39:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885598; x=1683477598; 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=JaK+wZAH1T/5WThjHTNFAIi14X8IxTArPcvcrt4iVHc=; b=kHojJF5u4wkSkR28ruI/K5Iioa5d3WMFKEfTKA0zB8H2rc0RZD6gccCdPZSqd55zQC dzyrgRfbNAK7hmccLmKu3qAplOcVwcH9qMYcBT9+xTNmAlKPzknJHmSmrruYkiWSUrwk D2/bUz+XFbA2YNvoo8QD6DXVUM5WWI3wuqrDLh99nHVEMIp063+FYfVnkx4Itq4h+zqw waTRV37W2pU/K+PyoAZ7Pxvj0eZi8RmDkZNE6MSTXM08usrd77fkG0dd2pzsbE8mDjwy XUJC8+rOU72RNAIZfCMVvYVJ53Fe6Y5Th/1EFv2lTRS2ILuPNrzYhFgZdErnWDrQsi5N yK2Q== X-Gm-Message-State: AAQBX9d6kD3GofjkpMa/PJ2JCoJte7UH6C2xppN8LbJiU+kJIxTQSzM0 FvrMdjreob7klC42PVAczRKQegdDc7kYhrDBWq7YBw== X-Google-Smtp-Source: AKy350YhT8VJEPUgqivw6euQyrF/s3okSRnkfuVJkfLHBX+evt60P8/SPV/rsqqdshddKtWV76xtww== X-Received: by 2002:a5e:c913:0:b0:758:a91a:aa82 with SMTP id z19-20020a5ec913000000b00758a91aaa82mr2464115iol.11.1680885597839; Fri, 07 Apr 2023 09:39:57 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:57 -0700 (PDT) Date: Fri, 07 Apr 2023 10:39:57 -0600 Subject: [PATCH v2 4/8] Introduce symbol_block_ops::get_block_value MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-4-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.2 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 b7b77818fbe..d940abbd4ed 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6404,7 +6404,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 8d3f5610bd3..d8e3c273f85 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1182,6 +1182,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. */ @@ -1536,6 +1542,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 Fri Apr 7 16:39:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67525 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 BD54A3855599 for ; Fri, 7 Apr 2023 16:41:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD54A3855599 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885668; bh=6l2Mlf4qzV9hqVFp0MCvuLMgdQTCYFR384jgMdhjNsY=; 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=DbUEvRYV+a0oKM8GAfZKG2ASvfFaLzqlXoTmJK1uOnvm/YWvu+EzIaFRnXN5mhFbC dBPhh4iXB5tow2r5epX/u52EDuu9kkWMfIHf4p3Mnss+6Zvt7S/LDdiGqH+d1npXqh jzIiZx5wpRbuAjv/dNRIG105TtLxByOAXR2e7u0I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 8A5543858C1F for ; Fri, 7 Apr 2023 16:39:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A5543858C1F Received: by mail-io1-xd34.google.com with SMTP id h187so17174897iof.7 for ; Fri, 07 Apr 2023 09:39:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885598; x=1683477598; 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=6l2Mlf4qzV9hqVFp0MCvuLMgdQTCYFR384jgMdhjNsY=; b=gCp3dpvWYK8tQDkuoZL7dXSGS8vwkuZFbG/QWN+YZKh/F2uySTg7vREkrNszfj78XD O69vpKbq5B1M7F9mwnxLKXFiSUkUAZuByi6zlPuYpiYa3XNMLImcfzLcvOMVIlPITZje arhMYrJqHmDtkLD7CA3vtMUgwi+6kA1aGxX63pSNUcHONCv4d9zdOGb1dS9uIDCuWG6D PnGkRqX8kYxmHYMPgANGYjLuyn5kGRi5Bk8R5jDvUTjkghyeJJDToAx8ALasYq/CVzVu RVpqmSf0TGUpmO59DbpyHYoSn1D2mG4kxgO9vX+URYo8pRsDGgSJGqgb9wz4h4mnHCUs VfqA== X-Gm-Message-State: AAQBX9dbBP17hKhg0N2exXAz0lhQthu9nsr1bVivUSGYu1mGJKrfbOkT vJYUK4Yrt3CC96GG0HYPyZk9dFbZ5Uw0dP9lcL5xRA== X-Google-Smtp-Source: AKy350YB9XmoJuaKpBpsc277zAGeba5B7odaA3WSg5dJlEG3EGuHkVR3XV2IumAmEya5nH8ifE6PSw== X-Received: by 2002:a5e:8414:0:b0:758:52ab:6250 with SMTP id h20-20020a5e8414000000b0075852ab6250mr2584438ioj.3.1680885598482; Fri, 07 Apr 2023 09:39:58 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:58 -0700 (PDT) Date: Fri, 07 Apr 2023 10:39:58 -0600 Subject: [PATCH v2 5/8] Handle Ada Pragma Import and Pragma Export MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-5-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.2 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 8f35b973f3e..7de0e9f2e20 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 @@ -10014,6 +10019,31 @@ dwarf2_func_is_main_p (struct die_info *die, struct dwarf2_cu *cu) && attr->constant_value (DW_CC_normal) == DW_CC_program); } +/* 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) { @@ -10060,6 +10090,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) @@ -18795,6 +18833,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. @@ -18935,6 +19018,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 @@ -19027,6 +19132,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 { @@ -19048,6 +19162,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) { @@ -21979,11 +22103,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 \ From patchwork Fri Apr 7 16:39:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67523 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 BA55E385414C for ; Fri, 7 Apr 2023 16:40:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA55E385414C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885654; bh=+fyQb92+OggT4pghlueBF0ZfjXQdbHhbRg5hkHHixAc=; 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=StvUInZpxwJqsa4LPqPrmIla45yqscJP/QxX7WoMXEqXxSznsPddTpfRQX9sAZ+6q E34QGz1QIDRVin3Gy9PdXmjY+HS1sS5R+5nkKlma8QX2JmLClB97Nv9s3mFNGhP6cK H3fl3y+ov2f5dZoRNedB3Ro+3A2Jr/gLk1EsUQYE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 653A73858C74 for ; Fri, 7 Apr 2023 16:39:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 653A73858C74 Received: by mail-il1-x12e.google.com with SMTP id u8so22415215ilb.2 for ; Fri, 07 Apr 2023 09:39:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885599; x=1683477599; 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=+fyQb92+OggT4pghlueBF0ZfjXQdbHhbRg5hkHHixAc=; b=u3ZxTJDwyLW7P1HH0TGUeI8VfKpIwsCO5pM7uewo996fOiFBMZx2jswu86kOwL1iTl 52ybE3ip7F15NYxVPueon2SS9BRkFZQsp+UEpeOwzSEmWvlhuUeLhoLeuAFo4ukqQRGg r905jfITloM8wVVGDhvUzoluwVcW84lKnxzNbsuUW+9639ROrE+3bkpmGO9rS/z2ebT0 /Zc+Wwzb0wgaaFLQiJ6IOYIgYE4pd8nJsLHpBxSrijm3Bpl92dKIRYAR3eSH53rPp2YB 5k0G8KSuGPXXrXbgUs2dq5RW5D4Wz4qwlM05KCGtq+qIEI6n8SBGlYi305Pg8xOUwers M94g== X-Gm-Message-State: AAQBX9fMWgQEUGJKMD5otj14+TstwPS+TxUtRzPQk7gKStL+tORTxXI6 hyCHzKaZV+QvzTpDOz/y81Zcy5/wDVMi2YIkjJ545Q== X-Google-Smtp-Source: AKy350ao+rYYiKK6wBTRjVHijTItpabNQuB/g4M08lf3bU0oRYyWQl2cXVJWn0hNeVLio2ZzMkvvAg== X-Received: by 2002:a92:90e:0:b0:328:59a9:23dc with SMTP id y14-20020a92090e000000b0032859a923dcmr1046474ilg.29.1680885599069; Fri, 07 Apr 2023 09:39:59 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:58 -0700 (PDT) Date: Fri, 07 Apr 2023 10:39:59 -0600 Subject: [PATCH v2 6/8] Use reference parameter in remove_extra_symbols MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-6-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 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" Changing ada-lang.c:remove_extra_symbols to take a reference parameter makes the code a bit easier to read, by replacing "(*syms)" with plain "syms". --- gdb/ada-lang.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d2d7dca5c1e..5d0ba5ac20b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5027,34 +5027,34 @@ symbols_are_identical_enums (const std::vector &syms) debugging symbols)). Modifies SYMS to squeeze out deleted entries. */ static void -remove_extra_symbols (std::vector *syms) +remove_extra_symbols (std::vector &syms) { int i, j; /* We should never be called with less than 2 symbols, as there cannot be any extra symbol in that case. But it's easy to handle, since we have nothing to do in that case. */ - if (syms->size () < 2) + if (syms.size () < 2) return; i = 0; - while (i < syms->size ()) + while (i < syms.size ()) { int remove_p = 0; /* If two symbols have the same name and one of them is a stub type, the get rid of the stub. */ - if ((*syms)[i].symbol->type ()->is_stub () - && (*syms)[i].symbol->linkage_name () != NULL) + if (syms[i].symbol->type ()->is_stub () + && syms[i].symbol->linkage_name () != NULL) { - for (j = 0; j < syms->size (); j++) + for (j = 0; j < syms.size (); j++) { if (j != i - && !(*syms)[j].symbol->type ()->is_stub () - && (*syms)[j].symbol->linkage_name () != NULL - && strcmp ((*syms)[i].symbol->linkage_name (), - (*syms)[j].symbol->linkage_name ()) == 0) + && !syms[j].symbol->type ()->is_stub () + && syms[j].symbol->linkage_name () != NULL + && strcmp (syms[i].symbol->linkage_name (), + syms[j].symbol->linkage_name ()) == 0) remove_p = 1; } } @@ -5062,26 +5062,26 @@ remove_extra_symbols (std::vector *syms) /* Two symbols with the same name, same class and same address should be identical. */ - else if ((*syms)[i].symbol->linkage_name () != NULL - && (*syms)[i].symbol->aclass () == LOC_STATIC - && is_nondebugging_type ((*syms)[i].symbol->type ())) + else if (syms[i].symbol->linkage_name () != NULL + && syms[i].symbol->aclass () == LOC_STATIC + && is_nondebugging_type (syms[i].symbol->type ())) { - for (j = 0; j < syms->size (); j += 1) + for (j = 0; j < syms.size (); j += 1) { if (i != j - && (*syms)[j].symbol->linkage_name () != NULL - && strcmp ((*syms)[i].symbol->linkage_name (), - (*syms)[j].symbol->linkage_name ()) == 0 - && ((*syms)[i].symbol->aclass () - == (*syms)[j].symbol->aclass ()) - && (*syms)[i].symbol->value_address () - == (*syms)[j].symbol->value_address ()) + && syms[j].symbol->linkage_name () != NULL + && strcmp (syms[i].symbol->linkage_name (), + syms[j].symbol->linkage_name ()) == 0 + && (syms[i].symbol->aclass () + == syms[j].symbol->aclass ()) + && syms[i].symbol->value_address () + == syms[j].symbol->value_address ()) remove_p = 1; } } if (remove_p) - syms->erase (syms->begin () + i); + syms.erase (syms.begin () + i); else i += 1; } @@ -5098,8 +5098,8 @@ remove_extra_symbols (std::vector *syms) to ask the user to disambiguate anyways. And if we have to present a multiple-choice menu, it's less confusing if the list isn't missing some choices that were identical and yet distinct. */ - if (symbols_are_identical_enums (*syms)) - syms->resize (1); + if (symbols_are_identical_enums (syms)) + syms.resize (1); } /* Given a type that corresponds to a renaming entity, use the type name @@ -5711,7 +5711,7 @@ ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name, ada_add_all_symbols (results, block, lookup_name, domain, full_search, &syms_from_global_search); - remove_extra_symbols (&results); + remove_extra_symbols (results); if (results.empty () && full_search && syms_from_global_search) cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL); From patchwork Fri Apr 7 16:40:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67526 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 C36E13856976 for ; Fri, 7 Apr 2023 16:41:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C36E13856976 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885680; bh=WeLL7zU3NMAdQt101VGDZxN7axTNVreSdKkx1zg8lOE=; 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=nGq8S9IYhP9eOxaYBIhwFmNVtaEOec9bYHp7I1+0fkxKlIChx6LKpuwxRi0XaJmwk axHwWZ7R4djaz1g0wm/fNdPCQjnR+t1qVWo0ga6EQbobE+C3AiMzjyUQIyTd7RtnWw ZoRCJoXbg9nwQ9rC3OLPjOxIqs4Y4ZYiCCLSf7PI= 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 74FBC3858404 for ; Fri, 7 Apr 2023 16:40:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74FBC3858404 Received: by mail-io1-xd29.google.com with SMTP id 82so5067928iou.2 for ; Fri, 07 Apr 2023 09:40:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885599; x=1683477599; 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=WeLL7zU3NMAdQt101VGDZxN7axTNVreSdKkx1zg8lOE=; b=XjVabR2IU8u5ttZRo8sR/xAMNQMs466qW+0cKAyEd7OEXSte0xxAMTHioXvn8Zkeqj /SOxQ9xDpnn7ReGC7sp5OSZ/6DBOY6W3HcRPychDitS84C8lmBJIHgt/wliNo4dcfYoT 6BJiqPc6Pq4bPn+xi4UJtYJotznw/konzPwC6wkJCbAAY8LiQqdtm+rNF8iAuxAjqyPb +44kW6/Z3mr28UE+X038Q/v3uJ3qQda4BAzuLn7V1eh/6zQumo8u0eNfLVadU7yP0EXr 05InB6ro0BSymR72zE+5TkDhrJu89GEq/WNXO9x21bX78qvF8PczxPmYzIAkMbXulpuX 7BXQ== X-Gm-Message-State: AAQBX9e8PRTJYbEn2mnPkgRMgvJ5Cjf4ja4ZPTGe3ieInVTweK7dB0Fm vNYh9ca5rH8KVMrNb0DlgNifk2YaZg+myiJOBoWYHg== X-Google-Smtp-Source: AKy350ai4T3lJLzsjJSTlnF57Xhy5FObbEyn+sMHCtbhXyjEZakmyVVMdnloSsxO1Vwo1VwpiZdVCw== X-Received: by 2002:a6b:f107:0:b0:759:8f29:2e81 with SMTP id e7-20020a6bf107000000b007598f292e81mr2623132iog.18.1680885599612; Fri, 07 Apr 2023 09:39:59 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:59 -0700 (PDT) Date: Fri, 07 Apr 2023 10:40:00 -0600 Subject: [PATCH v2 7/8] Use bool and early loop exit in remove_extra_symbols MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-7-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 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 changes remove_extra_symbols to use bool rather than int, and changes the nested loops to exit early when "remove_p" is set. --- gdb/ada-lang.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 5d0ba5ac20b..091faba3037 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5040,7 +5040,7 @@ remove_extra_symbols (std::vector &syms) i = 0; while (i < syms.size ()) { - int remove_p = 0; + bool remove_p = false; /* If two symbols have the same name and one of them is a stub type, the get rid of the stub. */ @@ -5048,14 +5048,14 @@ remove_extra_symbols (std::vector &syms) if (syms[i].symbol->type ()->is_stub () && syms[i].symbol->linkage_name () != NULL) { - for (j = 0; j < syms.size (); j++) + for (j = 0; !remove_p && j < syms.size (); j++) { if (j != i && !syms[j].symbol->type ()->is_stub () && syms[j].symbol->linkage_name () != NULL && strcmp (syms[i].symbol->linkage_name (), syms[j].symbol->linkage_name ()) == 0) - remove_p = 1; + remove_p = true; } } @@ -5066,7 +5066,7 @@ remove_extra_symbols (std::vector &syms) && syms[i].symbol->aclass () == LOC_STATIC && is_nondebugging_type (syms[i].symbol->type ())) { - for (j = 0; j < syms.size (); j += 1) + for (j = 0; !remove_p && j < syms.size (); j += 1) { if (i != j && syms[j].symbol->linkage_name () != NULL @@ -5076,7 +5076,7 @@ remove_extra_symbols (std::vector &syms) == syms[j].symbol->aclass ()) && syms[i].symbol->value_address () == syms[j].symbol->value_address ()) - remove_p = 1; + remove_p = true; } } From patchwork Fri Apr 7 16:40: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: 67521 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 628DD385B501 for ; Fri, 7 Apr 2023 16:40:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 628DD385B501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680885639; bh=z3K5gtZk22nfaB1TMSFZveYetpbNKe/BTBUBSVXzpFA=; 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=wySbw0ThlRs+CMO6rFGSRm0QAtpm0w8pVvWTyuUDHI5TNeEuK02/8R3jKYJxru5Fb bok+BmAlc6Hp9rYh0X0DMB9CC9cXsit5ssBt4R/V4HxEG3fNpk4pSUwFQS4FzBNjn4 8GPONNz7ZWjDB8kvBftowMpf0HxJv+QEU2OjpA0s= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 09AB1385842C for ; Fri, 7 Apr 2023 16:40:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09AB1385842C Received: by mail-il1-x12f.google.com with SMTP id v5so19857909ilj.4 for ; Fri, 07 Apr 2023 09:40:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680885600; x=1683477600; 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=z3K5gtZk22nfaB1TMSFZveYetpbNKe/BTBUBSVXzpFA=; b=Oz1xFkYJUEjjv0T7ENGAB/Xq90yavDWSA0XAhB9K7DPrraVqvofw7Wxl1/dACb0D2/ EQyjsRVtnSdP6eMSxNPrP/EUAdWIw9BZ+ZYHwj1gV3CVxcfChy/B6N9Kq+TVKGqMdacf ADqz17eQZ9ZSIgsZZIgxHBeUjNe/IalW1OnTz1iE0Wzki6wsOPkKe1NmTRU/OGARFNBY 8pS8sGPDqcgwwJzay5fbnNq7hEMxBtTZPaWMt6ad1eZHhKpC7GMb5KJEmXLmPMvZrxU7 148KwZ3pV6fBR0632KOOsw6SpMBuo020oVL/RU1hMwa6p1K2gK6O76F4xk8w/5J8RMKs B/zQ== X-Gm-Message-State: AAQBX9d4aVhWI6M2bFi419loJ3D+l1ArInFidGbdP0BFr+T4Q32hhSyU HHp8zcFt8CBc0sb3PeSvJONtrsTE2pH0g9xCnDztUA== X-Google-Smtp-Source: AKy350b0P/qKNij0pb3cMm5mwLKg1f5Q2BSltqdjfnGyoWRi2Ukkkq9NcFUsOb+ZPvSlIiX2PpegYg== X-Received: by 2002:a92:c88a:0:b0:322:f878:abcb with SMTP id w10-20020a92c88a000000b00322f878abcbmr2024371ilo.0.1680885600230; Fri, 07 Apr 2023 09:40:00 -0700 (PDT) Received: from localhost.localdomain (75-166-159-36.hlrn.qwest.net. [75.166.159.36]) by smtp.gmail.com with ESMTPSA id c62-20020a029644000000b00406431d0fb5sm1171452jai.72.2023.04.07.09.39.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 09:39:59 -0700 (PDT) Date: Fri, 07 Apr 2023 10:40:01 -0600 Subject: [PATCH v2 8/8] Fix regression due to Pragma Import series MIME-Version: 1.0 Message-Id: <20230314-submit-pragma-import-export-v2-8-dcff927191fb@adacore.com> References: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> In-Reply-To: <20230314-submit-pragma-import-export-v2-0-dcff927191fb@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 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" A co-worker here at AdaCore discovered that the Pragma Import series caused a rgression. When debugging gnat1, gdb started asking for overload resolution like: (gdb) call pp(n) Multiple matches for pp [0] cancel [1] pp (types.union_id) at ../../gcc/gcc/ada/treepr.adb:511 [2] treepr.pp (types.union_id) at ../../gcc/gcc/ada/treepr.adb:511 This worked before the series, and is strange anyway, because the matches refer to the same function. This patch adds a test case for this situation and fixes the bug by pruning identical functions in remove_extra_symbols. --- gdb/ada-lang.c | 14 ++++++++++++++ gdb/testsuite/gdb.ada/import.exp | 2 ++ gdb/testsuite/gdb.ada/import/pkg.adb | 7 +++++++ gdb/testsuite/gdb.ada/import/pkg.ads | 5 +++++ 4 files changed, 28 insertions(+) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 091faba3037..224850b7a69 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5080,6 +5080,20 @@ remove_extra_symbols (std::vector &syms) } } + /* Two functions with the same block are identical. */ + + else if (syms[i].symbol->aclass () == LOC_BLOCK) + { + for (j = 0; !remove_p && j < syms.size (); j += 1) + { + if (i != j + && syms[j].symbol->aclass () == LOC_BLOCK + && (syms[i].symbol->value_block () + == syms[j].symbol->value_block ())) + remove_p = true; + } + } + if (remove_p) syms.erase (syms.begin () + i); else diff --git a/gdb/testsuite/gdb.ada/import.exp b/gdb/testsuite/gdb.ada/import.exp index 866b431aac5..90cffa48e9c 100644 --- a/gdb/testsuite/gdb.ada/import.exp +++ b/gdb/testsuite/gdb.ada/import.exp @@ -56,3 +56,5 @@ gdb_breakpoint "local_imported_func" message gdb_breakpoint "pkg.exported_func_ada" message gdb_breakpoint "exported_func_ada" message gdb_breakpoint "exported_func" message + +gdb_test "print copy" " = 42" diff --git a/gdb/testsuite/gdb.ada/import/pkg.adb b/gdb/testsuite/gdb.ada/import/pkg.adb index e4f1c1a88b7..1c706188c69 100644 --- a/gdb/testsuite/gdb.ada/import/pkg.adb +++ b/gdb/testsuite/gdb.ada/import/pkg.adb @@ -20,6 +20,13 @@ package body Pkg is return Imported_Var_Ada; end Exported_Func_Ada; + function base return Integer is + begin + return Imported_Var_Ada; + end base; + + function copy return Integer renames base; + procedure Do_Nothing (A : System.Address) is begin null; diff --git a/gdb/testsuite/gdb.ada/import/pkg.ads b/gdb/testsuite/gdb.ada/import/pkg.ads index 5576d1b92d7..e30781a436e 100644 --- a/gdb/testsuite/gdb.ada/import/pkg.ads +++ b/gdb/testsuite/gdb.ada/import/pkg.ads @@ -28,6 +28,11 @@ package Pkg is function Exported_Func_Ada return Integer; pragma Export (C, Exported_Func_Ada, "exported_func"); + function base return Integer; + pragma Export (Ada, base); + function copy return Integer; + pragma Export (Ada, copy); + procedure Do_Nothing (A : System.Address); end Pkg;