From patchwork Wed Mar 29 19:10:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 67097 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 A519D3858413 for ; Wed, 29 Mar 2023 19:11:17 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 2DA53385802F for ; Wed, 29 Mar 2023 19:11:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DA53385802F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ed1-x52d.google.com with SMTP id cn12so67476464edb.4 for ; Wed, 29 Mar 2023 12:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680117061; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=yEflwrg7e92BsfGjVeEuGOduKwF/kEFxrOxoq+0LNRM=; b=CnXsPe4YcpMBGsNvDMCNBMOfR3bKb7A48zAhylsESDqfKKS6Nnwab5ZDdCWeLhyQZ0 98YLUk45fXXEj4lmn+7Zy5Qd1vuUnSVf8qVkSZ7qEUeqVvetaKjQu23Wb6wtwSSVUorg OPA9hztQgCv/DQqmlBmKy98Er1u/ZYpory9CpfQIJCmZeH+MMdep1fgZQCdHyDWYl2S7 pIf9IaDgsgjo6yxJsV6QdUHQGFjrT+K+2TVJ4x1J0vO2E+vVVx3mMwxWDDIUcnPiq/pf ZiBDQ57sV5ut4hsXYtdE+e7GB0Gq7DmZ5+cZoF55/odCuzvOSQJCiU+QDMy05xVYZ5OY tP9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680117061; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yEflwrg7e92BsfGjVeEuGOduKwF/kEFxrOxoq+0LNRM=; b=b6j7s4Er5k7eKLTXvzSQWTRVQ7Uo754bCgDemQN7h7GIFcJH+DoXZ4Kn6rh42iFsil gIA5T1seqZ0nDhxL4xKOnikUCPtv8CE0lfZf4floHbkyY3cPZPpjU0y7U1zdQhFUkx5B VFgsKoteTfb2FHlnsz4zFiJcgS09VUP0TMSUHXZsnopUK0HmPg2hMK9mu5uJ09kcehWu 1yWdkcA4RmliHhfgdGIwrxysMox0Cjqqlin/AlCyPMazS0JawUzOwO98FtZlAEhgezqa TXKE8pmc8e18HI7rTRGeAJnMilYy6urZnfeRWD+uoFjRocBycYM4JoblIrD8FO8jGx9/ DC1A== X-Gm-Message-State: AAQBX9etkdvPaPJKntmUOKlC+ISpZts8Djnqi3A/3N75Daujfd5VYB4y RAem3Kpq2lKujy2soR8hgy8Bfxdvhl3KOUa+1pA= X-Google-Smtp-Source: AKy350aaJ7K03PFYWtt9VIhvM3/T1DdaVk6MsztXH1EmfDVRc0rCLsR4s1Q7rTfQvop5iLfBPVSlLQ== X-Received: by 2002:a17:906:395:b0:93b:6da8:539a with SMTP id b21-20020a170906039500b0093b6da8539amr20407978eja.18.1680117060834; Wed, 29 Mar 2023 12:11:00 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id a11-20020a17090680cb00b00930d22474dbsm16852752ejx.97.2023.03.29.12.10.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2023 12:11:00 -0700 (PDT) Date: Wed, 29 Mar 2023 20:10:58 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Tom Tromey , Richard Bunt Subject: [PATCH v3 1/3] GDB: Favor full symbol main name for backtrace stop In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Richard Bunt In the case where a Fortran program has a program name of "main" and there is also a minimal symbol called main, such as with programs built with GCC version 4.4.7 or below, the backtrace will erroneously stop at the minimal symbol rather than the user specified main, e.g.: (gdb) bt #0 bar () at .../gdb/testsuite/gdb.fortran/backtrace.f90:17 #1 0x0000000000402556 in foo () at .../gdb/testsuite/gdb.fortran/backtrace.f90:21 #2 0x0000000000402575 in main () at .../gdb/testsuite/gdb.fortran/backtrace.f90:31 #3 0x00000000004025aa in main () (gdb) This patch fixes this issue by increasing the precedence of the full symbol when the language of the current frame is Fortran. Newer versions of GCC transform the program name to "MAIN__" in this case, avoiding the problem. Co-Authored-By: Maciej W. Rozycki --- No changes from v2. Changes from v1: - Remove testsuite status mistakenly copied to the change description. --- gdb/frame.c | 25 ++++++++++++--------- gdb/testsuite/gdb.fortran/backtrace.exp | 38 ++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/backtrace.f90 | 32 ++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 10 deletions(-) gdb-richard-favour-full-symbol-main-name-for-backtrace-stop.diff Index: src/gdb/frame.c =================================================================== --- src.orig/gdb/frame.c +++ src/gdb/frame.c @@ -2542,29 +2542,34 @@ inside_main_func (frame_info_ptr this_fr bound_minimal_symbol msymbol = lookup_minimal_symbol (name, NULL, current_program_space->symfile_object_file); - if (msymbol.minsym == nullptr) + + if (msymbol.minsym != nullptr) + sym_addr = msymbol.value_address (); + + /* Favor a full symbol in Fortran, for the case where the Fortran main + is also called "main". */ + if (msymbol.minsym == nullptr + || get_frame_language (this_frame) == language_fortran) { /* In some language (for example Fortran) there will be no minimal symbol with the name of the main function. In this case we should search the full symbols to see if we can find a match. */ struct block_symbol bs = lookup_symbol (name, NULL, VAR_DOMAIN, 0); - if (bs.symbol == nullptr) - return false; /* We might have found some unrelated symbol. For example, the Rust compiler can emit both a subprogram and a namespace with the same name in the same scope; and due to how gdb's symbol tables currently work, we can't request the one we'd prefer. */ - if (bs.symbol->aclass () != LOC_BLOCK) + if (bs.symbol != nullptr && bs.symbol->aclass () == LOC_BLOCK) + { + const struct block *block = bs.symbol->value_block (); + gdb_assert (block != nullptr); + sym_addr = block->start (); + } + else if (msymbol.minsym == nullptr) return false; - - const struct block *block = bs.symbol->value_block (); - gdb_assert (block != nullptr); - sym_addr = block->start (); } - else - sym_addr = msymbol.value_address (); /* Convert any function descriptor addresses into the actual function code address. */ Index: src/gdb/testsuite/gdb.fortran/backtrace.exp =================================================================== --- /dev/null +++ src/gdb/testsuite/gdb.fortran/backtrace.exp @@ -0,0 +1,38 @@ +# 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 . + +require allow_fortran_tests + +load_lib fortran.exp + +standard_testfile .f90 + +if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}]} { + return -1 +} + +if {![fortran_runto_main]} { + perror "Could not run to main." + return +} + +gdb_breakpoint [gdb_get_line_number "Break here"] +gdb_continue_to_breakpoint "continue to bar" + +gdb_test "bt" \ + [multi_line \ + "#0\[ \t\]*bar \\(\\) at \[^\r\n\]+" \ + "#1\[ \t\]*$hex in foo \\(\\) at \[^\r\n\]+" \ + "#2\[ \t\]*$hex in \(?:MAIN__\|main\) \\(\\) at \[^\r\n\]+" ] Index: src/gdb/testsuite/gdb.fortran/backtrace.f90 =================================================================== --- /dev/null +++ src/gdb/testsuite/gdb.fortran/backtrace.f90 @@ -0,0 +1,32 @@ +! 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 . + +subroutine bar () + return ! Break here +end subroutine bar + +subroutine foo () + call bar () +end subroutine foo + +program main + interface + subroutine bar () + end subroutine bar + subroutine foo () + end subroutine foo + end interface + call foo () +end program main From patchwork Wed Mar 29 19:11:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 67098 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 E91E138582BD for ; Wed, 29 Mar 2023 19:11:29 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 528A93857C48 for ; Wed, 29 Mar 2023 19:11:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 528A93857C48 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ed1-x52f.google.com with SMTP id h8so67450931ede.8 for ; Wed, 29 Mar 2023 12:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680117075; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OWRT5RLypHWWsyQ8WHEUesj6PcALkHBNFHNkr6yYIis=; b=AGP1M5lXtTw9BixQyu9RIT5MYTuEq/HZsEzuuzRt8IkAT+UwdnGoh/nmlQK19zZ8Dn WEH5qGigLPH7cI7JEUShDOfmvJUHlEw9eDkPsnjyQAUkaGu6lXRLhCmjID+gGNiLZblJ pjdCwrejw8SN58fDY5vhOOjlOWZ9XLCzIZ9wYz26LHMwLbs47qu8juU1hqshKfBS6FKY 2WZzErq4zNS7fJKvUZPl08hk74ACdrzq2Z0Ef9e0nG2csHEjQQn4Pdr7a66BxEf7J/BO a0ln+b1VV0Sf1fn8ScxqY6WWgt2/+GXrvEm2d0mw4OdypaEi7YpbDmCTi66W7g9fzjni X7pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680117075; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OWRT5RLypHWWsyQ8WHEUesj6PcALkHBNFHNkr6yYIis=; b=vn4OiheVLeoSdL+28U5iig6nY7KOSnwDF/cgI8I4tKO712RwQAg4pfaf/wdfiPpXSZ MxcgCspLvo9QVGORDOMAKd89/9ClV1mEPz6R0iyOjBaWj+87WPRHGospO468sTo4yoed wqwYfY7GXStCJyu9M/WUserlb/xJ4F10WIZtfChkJLPmMet1n0jeUfQrQZ/28mSuuq0R NQl6uMjc6/97ZveplfGx66Lba0Ri/dxsjqfiAx4MYghmsLFB6ZJfy9UoMcKd+uSZFjQo vsMIH+ddGP650X6iUi3H84nQ48d22mdfPPpCSwyp6dzrWQG/tY1BrLdXXNY/iEIg+UdN d8Ow== X-Gm-Message-State: AAQBX9dNI10sAsRBjDMa43mQHRrRpPumiIejnQeXtsRRMvrF0qPy7O24 jmhpUYi6e0j9SP+ZBsv3ZkpJEP1+0ey/rBKrYes= X-Google-Smtp-Source: AKy350aSyISmQFg7MTSctamxgpwpLKbJNynOH/5uHBOeARBGUI6s6TgPgkcn7PWdmmS6dwK1aS6Prg== X-Received: by 2002:a17:906:3592:b0:934:8043:ebf8 with SMTP id o18-20020a170906359200b009348043ebf8mr20652078ejb.26.1680117075171; Wed, 29 Mar 2023 12:11:15 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id 21-20020a508755000000b004fc920655basm17490003edv.54.2023.03.29.12.11.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2023 12:11:14 -0700 (PDT) Date: Wed, 29 Mar 2023 20:11:13 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Tom Tromey , Richard Bunt Subject: [PATCH v3 2/3] GDB: Bring back the handling of DW_CC_program In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Fix a functional regression and restore the handling of DW_CC_program code of DW_AT_calling_convention attribute for determining the name of the starting function of the program where the DW_AT_main_subprogram attribute has not been provided, such as with Fortran code compiled with GCC versions 4.5.4 and below, or where DWARF version 3 or below has been requested. Without it "main" is considered the starting function. Cf. GCC PR fortran/43414. Original code was removed with commit 6209cde4ddb8 ("Delete DWARF psymtab code"), and then an update to complement commit 81873cc81eff ("[gdb/symtab] Support DW_AT_main_subprogram with -readnow.") has also been included here. --- NB this was discovered with and is covered by the test case included with 3/3; it has been verified to trigger with GCC 4.4.7 and will likely also with other configurations. Changes from v2: - Add inline documentation for the history of DW_AT_main_subprogram and DW_AT_calling_convention == DW_CC_program DWARF attributes. No change from v1. --- gdb/dwarf2/read.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) gdb-main-name-dw-cc-program.diff Index: src/gdb/dwarf2/read.c =================================================================== --- src.orig/gdb/dwarf2/read.c +++ src/gdb/dwarf2/read.c @@ -9994,6 +9994,22 @@ inherit_abstract_dies (struct die_info * compute_delayed_physnames (origin_cu); } +/* Return TRUE if the given DIE is the program's "main". DWARF 4 has + defined a dedicated DW_AT_main_subprogram attribute to indicate the + starting function of the program, however with older versions the + DW_CC_program value of the DW_AT_calling_convention attribute was + used instead as the only means available. We handle both variants. */ + +static bool +dwarf2_func_is_main_p (struct die_info *die, struct dwarf2_cu *cu) +{ + if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu)) + return true; + struct attribute *attr = dwarf2_attr (die, DW_AT_calling_convention, cu); + return (attr != nullptr + && attr->constant_value (DW_CC_normal) == DW_CC_program); +} + static void read_func_scope (struct die_info *die, struct dwarf2_cu *cu) { @@ -10084,7 +10100,7 @@ read_func_scope (struct die_info *die, s newobj = cu->get_builder ()->push_context (0, lowpc); newobj->name = new_symbol (die, read_type_die (die, cu), cu, templ_func); - if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu)) + if (dwarf2_func_is_main_p (die, cu)) set_objfile_main_name (objfile, newobj->name->linkage_name (), cu->lang ()); @@ -16136,11 +16152,21 @@ cooked_indexer::scan_attributes (dwarf2_ *linkage_name = attr.as_string (); break; + /* DWARF 4 has defined a dedicated DW_AT_main_subprogram + attribute to indicate the starting function of the program... */ case DW_AT_main_subprogram: if (attr.as_boolean ()) *flags |= IS_MAIN; break; + /* ... however with older versions the DW_CC_program value of + the DW_AT_calling_convention attribute was used instead as + the only means available. We handle both variants then. */ + case DW_AT_calling_convention: + if (attr.constant_value (DW_CC_normal) == DW_CC_program) + *flags |= IS_MAIN; + break; + case DW_AT_declaration: is_declaration = attr.as_boolean (); break; From patchwork Wed Mar 29 19:11:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 67099 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 E708D3858025 for ; Wed, 29 Mar 2023 19:11:49 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 57DFD3858004 for ; Wed, 29 Mar 2023 19:11:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57DFD3858004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ed1-x536.google.com with SMTP id r11so67472151edd.5 for ; Wed, 29 Mar 2023 12:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680117093; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jWZI279ghoVvUGogREUzBPcxJ8x1/77NwtMw2Jvh2Yk=; b=PbvskRkI0s6TxNT72OWNdVoJ9pVFiNXfNviQzwKv79Y/phGK8hhx29EBhPnaie/H/p hf56hgeHEQ/aUmA2SYzOFpZgGhhp0x6XDLk/hhaB2ew1gg+Pr026NXH+U+6HaSQF0MNb MpFz8WQ8zEKux2n0xUegut5lOYINS7oOgi5aTp88FqrzU+PUX9a6RRwzeAx6HWD6pDz/ EDvQfKf8rIxUQ5VgfkB95XnhXYdizyoPRDv2fIPvp6wdOCFewcQKHvZGdW5SKMqDNidC ulIU23rZWTNN7zW2AuZeQkaa2l+xnDCULLGnd3+HW7WbcQdNajwCJRYq5IocSCWQrURc tR+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680117093; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jWZI279ghoVvUGogREUzBPcxJ8x1/77NwtMw2Jvh2Yk=; b=208k9gXubtrujL0w0lmVwAv2ZY1iz776xNaAORz5YUdTyQlBFZXWe8vCfEZoSea4Jj 9DLp1s7oDEoAe0wu6peOt6Vin3vfvFj79C+4S22gMEMU3ZzTre6SYFXx+3J9p8mdvvQ3 UGl9O9RjFGiH/VG1ulUhmQRS97ckVLBDMDjzLk5Tl+5G/s2El3LhMOnAQvgRb/YbSr48 ObwvSnX10kHNSqZgFJHuDRsmIkMf0ODz6i9eQmwppnrTdmr9jd+IxYE4B4SvUil3ewhz +jGmhJZKkeoDRCZ1BPhc8dxvPxzLul/WVEfe906S1plicLvHXqP0PL6Z6acU1+QzM1Bw bHhQ== X-Gm-Message-State: AAQBX9cu1nm/E2KRDVCMB3Hd8CfZD9aKAWJVUsZrgwlQISc7aSzbExl0 xWjWrZk/1v3xYE19KvtxENl9SyxdAjeKNR5rjDY= X-Google-Smtp-Source: AKy350bY7B/mQdB2XozyxZM+pwff+eeQep2ONVErlLNANhbOBixB3KcqBJd23UCkRGlPMFz+1x/odA== X-Received: by 2002:aa7:c703:0:b0:4fa:b302:84d4 with SMTP id i3-20020aa7c703000000b004fab30284d4mr20660594edq.13.1680117093058; Wed, 29 Mar 2023 12:11:33 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id r17-20020a50aad1000000b005024459f431sm4028100edc.70.2023.03.29.12.11.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2023 12:11:32 -0700 (PDT) Date: Wed, 29 Mar 2023 20:11:31 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Tom Tromey , Richard Bunt Subject: [PATCH v3 3/3] GDB: Add `info main' command In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Richard Bunt Allow consumers of GDB to extract the name of the main method. This is most useful for Fortran programs which have a variable main method. Used by both MAP and DDT e.g. it is used to detect the presence of debug information. Co-Authored-By: Maciej W. Rozycki --- No change from v2. Changes from v1: - Add documentation pieces. --- gdb/NEWS | 3 ++ gdb/doc/gdb.texinfo | 6 ++++ gdb/symtab.c | 11 ++++++++ gdb/testsuite/gdb.fortran/info-main.exp | 42 ++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/info-main.f90 | 19 ++++++++++++++ 5 files changed, 81 insertions(+) gdb-richard-info-main-command.diff Index: src/gdb/NEWS =================================================================== --- src.orig/gdb/NEWS +++ src/gdb/NEWS @@ -83,6 +83,9 @@ show always-read-ctf When off, CTF is only read if DWARF is not present. When on, CTF is read regardless of whether DWARF is present. Off by default. +info main + Get main symbol to identify entry point into program. + * New convenience function "$_shell", to execute a shell command and return the result. This lets you run shell commands in expressions. Some examples: Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo +++ src/gdb/doc/gdb.texinfo @@ -20162,6 +20162,12 @@ The optional flag @samp{-q}, which stand printing header information and messages explaining why no functions or variables have been printed. +@kindex info main +@item info main +Print the name of the starting function of the program. This serves +primarily Fortran programs, which have a user-supplied name for the +main subroutine. + @kindex info classes @cindex Objective-C, classes and selectors @item info classes Index: src/gdb/symtab.c =================================================================== --- src.orig/gdb/symtab.c +++ src/gdb/symtab.c @@ -5282,6 +5282,14 @@ info_modules_command (const char *args, from_tty); } +/* Implement the 'info main' command. */ + +static void +info_main_command (const char *args, int from_tty) +{ + gdb_printf ("%s\n", main_name ()); +} + static void rbreak_command (const char *regexp, int from_tty) { @@ -6873,6 +6881,9 @@ Options:\n\ _("All module names, or those matching REGEXP.")); set_cmd_completer_handle_brkchars (c, info_types_command_completer); + add_info ("main", info_main_command, + _("Get main symbol to identify entry point into program.")); + add_basic_prefix_cmd ("module", class_info, _("\ Print information about modules."), &info_module_cmdlist, 0, &infolist); Index: src/gdb/testsuite/gdb.fortran/info-main.exp =================================================================== --- /dev/null +++ src/gdb/testsuite/gdb.fortran/info-main.exp @@ -0,0 +1,42 @@ +# 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 . + +require allow_fortran_tests + +load_lib fortran.exp + +standard_testfile .f90 + +set old_gdbflags $GDBFLAGS +set GDBFLAGS [string map {"-readnow" ""} "$GDBFLAGS"] + +if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}]} { + return -1 +} + +gdb_test "info main" "simple" "info main prior to start" + +if ![fortran_runto_main] { + untested "could not run to main" + return -1 +} + +gdb_test "info main" "simple" "info main post start" + +set GDBFLAGS "$GDBFLAGS -readnow" +clean_restart $testfile +gdb_test "info main" "simple" "info main with readnow" + +set GDBFLAGS $old_gdbflags Index: src/gdb/testsuite/gdb.fortran/info-main.f90 =================================================================== --- /dev/null +++ src/gdb/testsuite/gdb.fortran/info-main.f90 @@ -0,0 +1,19 @@ +! 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 . + +program simple + implicit none + print *, "Nothing." +end program simple