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