From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: text/plain; charset=US-ASCII 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 List-Id: 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