From patchwork Mon Apr 17 13:41:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67819 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 0A0C3385B526 for ; Mon, 17 Apr 2023 13:42:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A0C3385B526 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681738943; bh=GWlXGLfuvryAVMHe2Mh6SOJwZNGGZG/87ucfut56h+Y=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=f1MQhzHvOSVTncHrXEnj+FMj1Szrf54mdecitCeOO2KZTR1kY24IeGd6FINAaDJbN JsMe7WovonI8cmluoeUyXltm/y5pcv+OnyDfmsY5E/LKZAgBKFQBcDgQ34ASE9l6gD bDCmYcnEWUq0EGTqnpGalTtYa7+b8UUpELZRqR0E= 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 465E0385B514 for ; Mon, 17 Apr 2023 13:41:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 465E0385B514 Received: by mail-io1-xd34.google.com with SMTP id s6so1390176iow.11 for ; Mon, 17 Apr 2023 06:41:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681738916; x=1684330916; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GWlXGLfuvryAVMHe2Mh6SOJwZNGGZG/87ucfut56h+Y=; b=ceW/SZaL8ikLQ2aw/fTECjiIDMbJDEovXmNndbGmW3RHvXLe77EzTwD21eprx7nZEc +cozBHjSECZAnEOHKyA6k39EMc09r5Pkyxg1FTLFc1twWe4DcqvzCO8ZtevkJxitwslk Z/MclXD5jhsjusbyQet20OLf7R2WR2GMnO+D6iRzY+HMtfjd06YeTmWH2irdbI9tmXMP c0qcISAw4fGTI+Xji4MvAkve2sXviBFaNBw1fkbKcS6VJs7n1dQRrmreDFNrGj9hIjhU c+Qn8NlTAIxWQYNI5CoYDEx+oXIhSrrNj9L8h7qherr0B9J7vcKXgC+/YLIa+ajqbQNT i/jg== X-Gm-Message-State: AAQBX9fj7XEtHOBME+OEjywgtkF+/DKVDWFhnSyscf2SrYHaTj5kAb62 VXbUgvhkzfafx1rDviVfAaC9j9jI6DcLUNuGzafLqw== X-Google-Smtp-Source: AKy350bF0/9EFktJFbdD3cIAaknm9GNirO3RfbFMvKfirrBcWveAN9/kORC76IuJHD/Rt8F4IIlyBg== X-Received: by 2002:a6b:ec0c:0:b0:760:efd4:957e with SMTP id c12-20020a6bec0c000000b00760efd4957emr2742558ioh.3.1681738916611; Mon, 17 Apr 2023 06:41:56 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id g5-20020a6b6b05000000b00760b75a2760sm3129058ioc.41.2023.04.17.06.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 06:41:56 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix calling debuginfo-less functions in Ada Date: Mon, 17 Apr 2023 07:41:49 -0600 Message-Id: <20230417134149.511889-1-tromey@adacore.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 at AdaCore noticed that calling a function without debuginfo yields: (gdb) print plus_one(23) 'pck.plus_one' has unknown return type; cast the call to its declared return type However, this also happens if you follow the directions and add the cast. This patch fixes the problem and adds a regression test. --- gdb/ada-lang.c | 2 +- gdb/testsuite/gdb.ada/call-no-debug.exp | 45 ++++++++++++++++++++ gdb/testsuite/gdb.ada/call-no-debug/pck.adb | 21 +++++++++ gdb/testsuite/gdb.ada/call-no-debug/pck.ads | 18 ++++++++ gdb/testsuite/gdb.ada/call-no-debug/prog.adb | 22 ++++++++++ gdb/testsuite/lib/ada.exp | 4 +- 6 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/call-no-debug.exp create mode 100644 gdb/testsuite/gdb.ada/call-no-debug/pck.adb create mode 100644 gdb/testsuite/gdb.ada/call-no-debug/pck.ads create mode 100644 gdb/testsuite/gdb.ada/call-no-debug/prog.adb diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d2d7dca5c1e..2c77ae48bc5 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -11229,7 +11229,7 @@ ada_funcall_operation::evaluate (struct type *expect_type, error_call_unknown_return_type (NULL); return value::allocate (type->target_type ()); } - return call_function_by_hand (callee, NULL, argvec); + return call_function_by_hand (callee, expect_type, argvec); case TYPE_CODE_INTERNAL_FUNCTION: if (noside == EVAL_AVOID_SIDE_EFFECTS) /* We don't know anything about what the internal diff --git a/gdb/testsuite/gdb.ada/call-no-debug.exp b/gdb/testsuite/gdb.ada/call-no-debug.exp new file mode 100644 index 00000000000..422b83761d9 --- /dev/null +++ b/gdb/testsuite/gdb.ada/call-no-debug.exp @@ -0,0 +1,45 @@ +# 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 . + +# Test calling a function without debug info. + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile prog + +# Compile pck without debuginfo but prog with it. +if {[gdb_compile_ada $srcdir/$subdir/$testdir/pck.adb \ + [standard_output_file pck.o] object {}] != ""} { + return +} + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \ + {debug no-force}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/prog.adb] +runto "prog.adb:$bp_location" + +# Verify that the function was built without debuginfo. +gdb_test "print plus_one(23)" \ + "plus_one.* has unknown return type; cast the call to its declared return type" \ + "call function without debuginfo" +gdb_test "print integer (plus_one(23))" " = 24" \ + "use cast to call function without debuginfo" diff --git a/gdb/testsuite/gdb.ada/call-no-debug/pck.adb b/gdb/testsuite/gdb.ada/call-no-debug/pck.adb new file mode 100644 index 00000000000..fb74d6c464e --- /dev/null +++ b/gdb/testsuite/gdb.ada/call-no-debug/pck.adb @@ -0,0 +1,21 @@ +-- 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 Pck is + function Plus_One (A : Integer) return Integer is + begin + return A + 1; + end Plus_One; +end Pck; diff --git a/gdb/testsuite/gdb.ada/call-no-debug/pck.ads b/gdb/testsuite/gdb.ada/call-no-debug/pck.ads new file mode 100644 index 00000000000..7b353de765c --- /dev/null +++ b/gdb/testsuite/gdb.ada/call-no-debug/pck.ads @@ -0,0 +1,18 @@ +-- 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 Pck is + function Plus_One (A : Integer) return Integer; +end Pck; diff --git a/gdb/testsuite/gdb.ada/call-no-debug/prog.adb b/gdb/testsuite/gdb.ada/call-no-debug/prog.adb new file mode 100644 index 00000000000..27b7a7f02bf --- /dev/null +++ b/gdb/testsuite/gdb.ada/call-no-debug/prog.adb @@ -0,0 +1,22 @@ +-- 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 Pck; use Pck; + +procedure Prog is + X : Integer := Plus_One (23); +begin + null; -- STOP +end Prog; diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 4395f31ad94..211aa77e366 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -66,7 +66,9 @@ proc gdb_compile_ada_1 {source dest type options} { # and it avoids using a stray objfile file from a long-past # run, for instance. append options " ada" - append options " additional_flags=-f" + if {[lsearch -exact $options no-force] == -1} { + append options " additional_flags=-f" + } append options " additional_flags=-I$srcdir" set result [target_compile_ada_from_dir \