From patchwork Mon Mar 18 12:52:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31882 Received: (qmail 22131 invoked by alias); 18 Mar 2019 12:52:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 22012 invoked by uid 89); 18 Mar 2019 12:52:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f54.google.com Received: from mail-wm1-f54.google.com (HELO mail-wm1-f54.google.com) (209.85.128.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Mar 2019 12:52:33 +0000 Received: by mail-wm1-f54.google.com with SMTP id f65so12883906wma.2 for ; Mon, 18 Mar 2019 05:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=rG4P9J2w4Q6cvtbZRY2drXVcr1JHDZbpq0wL/q/RUFk=; b=N2H7ANK5rAp+Jigee9hpTqWcLITLsCQL20SHNMqolCs80cfqBH3+wlLDoGxssslJS5 9U/AmkP6soNh9mMqHfzNeVhHsAa2bva++8+3Qc3VC7oLjeLKO/O+JfsK5H1l4ckSkrQ0 ifTPA8FQa/35w0T6ZlsvF+SUc7XYnGu4XQRTqodx4D3IQYHgWbxiUVPpPVPzTRAAk3qc 4j1QFORLFQgkHsYipfjdCQN5oOksZwRA+WcCjNMtB9nkWDczYLRE+qyvQ/EMw4eLdhAX U/lraj7k933dhQYg5aKU5p2CtzyQwKREU12vgAI1T+VPWbzQH7eo+VUPEtI14SSDscIe QokQ== Return-Path: Received: from localhost (host86-142-70-198.range86-142.btcentralplus.com. [86.142.70.198]) by smtp.gmail.com with ESMTPSA id q2sm4162926wrm.52.2019.03.18.05.52.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 05:52:30 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Richard Bunt , Andrew Burgess Subject: [PATCH 2/8] gdb/fortran: Handle internal function calls Date: Mon, 18 Mar 2019 12:52:17 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes If an convenience function is defined in python (or guile), then currently this will not work in Fortran, instead the user is given this message: (gdb) set language fortran (gdb) p $myfunc (3) Cannot perform substring on this type Compare this to C: (gdb) set language c (gdb) p $myfunc (3) $1 = 1 After this patch we see the same behaviour in both C and Fortran. I've extended the test to check that all languages can call the convenience functions - only Fortran was broken. When calling convenience functions in Fortran we don't need to perform the same value preparation (passing by pointer) that we would for calling a native function - passing the real value is fine. gdb/ChangeLog: * eval.c (evaluate_subexp_standard): Handle internal functions during Fortran function call handling. gdb/testsuite/ChangeLog: * gdb.python/py-function.exp: Check calling helper function from all languages. * lib/gdb.exp (gdb_supported_languages): New proc. --- gdb/ChangeLog | 5 +++++ gdb/eval.c | 12 ++++++++---- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-function.exp | 8 +++++++- gdb/testsuite/lib/gdb.exp | 8 ++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 705bcaff49f..51863b21dc6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-03-18 Andrew Burgess + + * eval.c (evaluate_subexp_standard): Handle internal functions + during Fortran function call handling. + 2019-03-18 Andrew Burgess * NEWS: Mention new internal functions. diff --git a/gdb/eval.c b/gdb/eval.c index 0c0cf7f6ac7..085c00a7d65 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1979,6 +1979,7 @@ evaluate_subexp_standard (struct type *expect_type, case TYPE_CODE_PTR: case TYPE_CODE_FUNC: + case TYPE_CODE_INTERNAL_FUNCTION: /* It's a function call. */ /* Allocate arg vector, including space for the function to be called in argvec[0] and a terminating NULL. */ @@ -1996,10 +1997,13 @@ evaluate_subexp_standard (struct type *expect_type, results in malloc being called with a pointer to an integer followed by an attempt to malloc the arguments to malloc in target memory. Infinite recursion ensues. */ - bool is_artificial = - TYPE_FIELD_ARTIFICIAL (value_type (arg1), tem - 1); - argvec[tem] = fortran_argument_convert (argvec[tem], - is_artificial); + if (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC) + { + bool is_artificial = + TYPE_FIELD_ARTIFICIAL (value_type (arg1), tem - 1); + argvec[tem] = fortran_argument_convert (argvec[tem], + is_artificial); + } } argvec[tem] = 0; /* signal end of arglist */ if (noside == EVAL_SKIP) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b471f374271..6094d773163 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-03-18 Andrew Burgess + + * gdb.python/py-function.exp: Check calling helper function from + all languages. + * lib/gdb.exp (gdb_supported_languages): New proc. + 2019-03-18 Andrew Burgess * gdb.base/complex-parts.c: New file. diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp index 76cc57d81c9..01c326b5d0b 100644 --- a/gdb/testsuite/gdb.python/py-function.exp +++ b/gdb/testsuite/gdb.python/py-function.exp @@ -51,7 +51,13 @@ gdb_py_test_multiple "input value-returning convenience function" \ "Double ()" "" \ "end" "" -gdb_test "print \$double (1)" "= 2" "call value-returning function" +# Different languages can have different parsers, so lets check that +# internal functions are understood by every language. Place auto +# last in the list so we end up back in 'auto' language mode. +foreach lang [concat [gdb_supported_languages] auto] { + gdb_test_no_output "set language $lang" + gdb_test "print \$double (1)" "= 2" "call value-returning function, language = $lang" +} gdb_py_test_multiple "input int-returning function" \ "python" "" \ diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index f13f909c344..ad5f1857e1c 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6308,5 +6308,13 @@ proc cd { dir } { builtin_cd $dir } +# Return a list of all languages supported by GDB, suitable for use in +# 'set language NAME'. This doesn't include either the 'local' or +# 'auto' keywords. +proc gdb_supported_languages {} { + return [list c objective-c c++ d go fortran modula-2 asm pascal \ + opencl rust minimal ada] +} + # Always load compatibility stuff. load_lib future.exp