From patchwork Tue Mar 28 16:06:36 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: 67037 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 7023E3858032 for ; Tue, 28 Mar 2023 16:06:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 9EAA33858C50 for ; Tue, 28 Mar 2023 16:06:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EAA33858C50 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-x52b.google.com with SMTP id w9so51898886edc.3 for ; Tue, 28 Mar 2023 09:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680019598; 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=0O9F26hqLE/kDmRrr3qSKpUASBbFFsRmpXYW0Pnobuk=; b=bjSW58sfDKOo5o+Kb2GNDz0s6T1gaBXoCIi5z4ioU5QbEUqiydyVhtuNG3nzOzg3uJ vf0JOWxSYy/8qSf7hUCFD5c7kKu34KKwh8solrJLD6RdjbSLp/lsIIx80e+4A+OnPBot 2PW2IasAC2W0UN470Z/nW3QO7c4qYtWCJiYVL/FKdv5FIrX0OUv+ElMFIS2qjR8u5geN QbK6XKn6uB56WfK8E9G42ZOSKhIJE0QpY8FWYorofxx2A7RSFJmhDO648pXnIJqSl8Jy AQWFzlCmkteY4kyTSVQQsug5aENxuSxOszUs8NrwnsvhxzSu4iZ/G36RCC0Vv/n2Aqix YTDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680019598; 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=0O9F26hqLE/kDmRrr3qSKpUASBbFFsRmpXYW0Pnobuk=; b=qf/kdrDkZ94ApEMqrWxZO3amLGpBCavJruQCysi/5W7qyCXa2an2Zuntc3uDseFPX2 rMvZf33BcF+xek2uNL//0d0vdfxwq4G99DDc2KSz5e8OZTAi7+VnzqVCnjlIuZWtURZR DV6o6PzyFUT9ypBM/9nBS6af0d+1YVRw+Gk5V95gaDsUgbNujS1R6iojWBK6moy0hmzO q3nXPzm7eyTW3EiVKxqVz+lrZuhMaPhDX+V/18RxrAQpkLZhWs94R9GLiSC+oGWnTcDd r1EvjX9cVH5ylIe6QkjR1HZ/JXXxbA8eIFySYOU8y/iEhwbhObrWqTYYhwYUVbyUQWpQ FFFg== X-Gm-Message-State: AAQBX9eDnFcZcweitOUWu87nWclgWl1/G+EXYxp/TzIR6Q+mmpNJGTEs 7bg/wv83e6Q5KPZP+Dok16iI/0xb/BTb7oYPfys= X-Google-Smtp-Source: AKy350YIY38bAZ4gCBsnp1HoT+DMyA8K09BLWiy+ZLJQz0P2km/diAGYrs/QTrjo0n452pM9PgjpAA== X-Received: by 2002:a17:907:1628:b0:88f:8a5:b4cd with SMTP id hb40-20020a170907162800b0088f08a5b4cdmr22110794ejc.1.1680019598428; Tue, 28 Mar 2023 09:06:38 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id xf13-20020a17090731cd00b0093e5baadfe6sm5864850ejb.204.2023.03.28.09.06.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2023 09:06:38 -0700 (PDT) Date: Tue, 28 Mar 2023 17:06:36 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Richard Bunt Subject: [PATCH 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) FAIL: gdb.fortran/backtrace.exp: bt 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 --- 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 Tue Mar 28 16:06:50 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: 67038 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 0A7163857C45 for ; Tue, 28 Mar 2023 16:07:12 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 76D6B3857C48 for ; Tue, 28 Mar 2023 16:06:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76D6B3857C48 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-x534.google.com with SMTP id eg48so51738416edb.13 for ; Tue, 28 Mar 2023 09:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680019612; 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=kotq9u9vELCuF0XZ2OQY4/RajseNHGyFTb6oYJ7FDXs=; b=FT7QfzFnu6waftgBiUa7dolCkKATHyPHhXVZ8q8vtKEMitO8bv1xko3EgF+n0gik8H K8+LmKoRG4mpFAnpU2deklNdPFvb+dTi4/1VT1EL64F41olVI3VJTKBQ9lR5ngaAL8mT UJdFD0mN+cFmvhCjCnuwJPi7Vaq+qa8IAZ0GmQ1CqPNuGpqpbwHaukXkQeX7kR16lf1Q xdGtS3rP9qPNGAZFsaU2qaTe9MkV73qVwqQ49jbDBAfnrbQ2QQSPNmwOkoyUxGFhTPLD 25Pdz6bPu/P4PO6XQDw5N87Qq2BDwOvynCcN+sIOcb8Apk3Sh4uOE3nXU9K40ZgmGW4l SJoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680019612; 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=kotq9u9vELCuF0XZ2OQY4/RajseNHGyFTb6oYJ7FDXs=; b=6j+8tdCMRUC9QudxHuyhBSY8/Z4VTqD3RXXGjHuPmYbytd8Gs9HqXUntH+21vu2LrS 3Q2sNFzVqQwTTxR/CQVB9RH40yKRvGT/UjmrfwMiKrblwCfMG2Hj/+QxTFKC5wON6OD7 bLB7sOiufN1dxWJETyjiz+3bhuUNiTXxihyo7JdLR4WjNJlKHFINqppiz2TAXLYi5mhf Y2WCGN2PahojvOL01P+VNR1YGd3+muCDCdTQ1NlxLYoz5+aPdzC0uMShFdBPqLDJNAI4 IQXhT/P1iUxTejTI29tJw+YFH9/r1EW1CnnCx2rTguafxqnRUb3xJQrRhJduGphNatPy bryw== X-Gm-Message-State: AAQBX9eHontFIpORNKwIrdU3n7Cj2ayeRlxfcpnDAe8K/XNr/9s08eG9 Mmb6zSDO3Uou10tzGBHPB3296aoMKjSYM70/rgE= X-Google-Smtp-Source: AKy350YNIN6jZP2mZt46PcJTFGKTfoTzudn4mTyk0UyZUMOdpWHCTyKIhdNvmErFizpz7zuWuMiVzw== X-Received: by 2002:a17:906:6816:b0:92f:abff:b4cc with SMTP id k22-20020a170906681600b0092fabffb4ccmr15756337ejr.77.1680019612435; Tue, 28 Mar 2023 09:06:52 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id l11-20020a1709066b8b00b00939faf4be97sm10421999ejr.215.2023.03.28.09.06.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2023 09:06:52 -0700 (PDT) Date: Tue, 28 Mar 2023 17:06:50 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Richard Bunt Subject: [PATCH 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. --- gdb/dwarf2/read.c | 19 ++++++++++++++++++- 1 file changed, 18 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,18 @@ inherit_abstract_dies (struct die_info * compute_delayed_physnames (origin_cu); } +/* Return TRUE if the given DIE is the program's "main". */ + +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 +10096,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 ()); @@ -16141,6 +16153,11 @@ cooked_indexer::scan_attributes (dwarf2_ *flags |= IS_MAIN; break; + 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 Tue Mar 28 16:07:17 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: 67039 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 D5EEE38582A1 for ; Tue, 28 Mar 2023 16:07:35 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id AFF203858D39 for ; Tue, 28 Mar 2023 16:07:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFF203858D39 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-x52c.google.com with SMTP id b20so51902133edd.1 for ; Tue, 28 Mar 2023 09:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680019639; 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=rVmrGZ1DNFMXjqTO7WbDJNzogH50t8Cu/Ym+ZfzCzqE=; b=Zbemf1FlvhIV/ZVdboA/ua5AF1w7rhBE6vYxlkGq90kETekLYLSt65q2GrUasblO8F aMVhtCMVqhRKZvtRQyk++Sm3iHMDsOyIFwsqje5vk0n6PsXpXMjEe1hxroGvm53l9BAn PR/f6wnnJALgdYsixtV3iTcs9CRLywh6V/AZl4SMA7yNGwPv2epeTGxHLQaZCEFlUIrH 2oCTSxW+eR6Z4Rg9q2wGxIYu1XUSkvNaP61ZfM/63UH+7ngEg/W3qdVk9odUGMrk8fFs FBfMriY+QmJPWY2RI3d/Gc09CL/+2raZfrxIFfQUaJHCdcjyx3j6YeOq0qMhkhVM4k05 ZC2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680019639; 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=rVmrGZ1DNFMXjqTO7WbDJNzogH50t8Cu/Ym+ZfzCzqE=; b=55/lE56XzYTuKEP5MjHZLWh9+sbhVOijfL0smW/wl+BKuWM/G7axhhKQActGzBrYJT kexLCZIIm4y9VEmhWix64KToVWXDseFfO/qvDRQ3EzgJ++zj7TuAizLwg58/s4nG8Q/S gejYAnPzr+4XGnM1TH5HkyyJoB5HhWU1haemfD2xTpOVuWoyTuZcJc0qOXpjm4oGkBgE tpAh2fB/Yqp5YKfE5gmcSb0Aad5zICfT/zlkhIL/631b++m7vt/cNcQSkbUNXUMtPSC8 eJrPqeay5Gf36SpMhNsTQcQsHdc8Q5cbpHJlHoYcW9YrB0e9qIs3tnBLJ4NIXlsd6FGw qQvA== X-Gm-Message-State: AAQBX9fkhec6r/W/t0bzWmnbVv9LCDl/TCkAZJPq8p/S70q/iILeNM1a k1uDYyRkpdz8RDX/ApPsViYx9O3pMx5qoMMIaaU= X-Google-Smtp-Source: AKy350aU0YxhvF+f/D4OQoep1g1yWAFSRf3mxukZDxzBPtNRQ16TH76J7R1uQxS5abQq0HIh9XP4vw== X-Received: by 2002:a17:906:8392:b0:92c:5f1:8288 with SMTP id p18-20020a170906839200b0092c05f18288mr17630316ejx.13.1680019639354; Tue, 28 Mar 2023 09:07:19 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id v2-20020a1709064e8200b008d9ddd2da88sm15421966eju.6.2023.03.28.09.07.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2023 09:07:18 -0700 (PDT) Date: Tue, 28 Mar 2023 17:07:17 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Richard Bunt Subject: [PATCH 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 --- gdb/symtab.c | 11 ++++++++ gdb/testsuite/gdb.fortran/info-main.exp | 42 ++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/info-main.f90 | 19 ++++++++++++++ 3 files changed, 72 insertions(+) gdb-richard-info-main-command.diff 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