From patchwork Thu Jul 13 02:19:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 21568 Received: (qmail 71715 invoked by alias); 13 Jul 2017 02:19:39 -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 71395 invoked by uid 89); 13 Jul 2017 02:19:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 02:19:36 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27BDF8123E for ; Thu, 13 Jul 2017 02:19:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27BDF8123E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 27BDF8123E Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A429A60E37 for ; Thu, 13 Jul 2017 02:19:34 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 03/13] Make ptype/whatis print function name of functions with no debug info too Date: Thu, 13 Jul 2017 03:19:20 +0100 Message-Id: <1499912370-1842-4-git-send-email-palves@redhat.com> In-Reply-To: <1499912370-1842-1-git-send-email-palves@redhat.com> References: <1499912370-1842-1-git-send-email-palves@redhat.com> The patch to make GDB stop assuming functions return int left GDB with an inconsistency. While with normal expression evaluation the "unknown return type" error shows the name of the function that misses debug info: (gdb) p getenv ("PATH") 'getenv' has unknown return type; cast the call to its declared return type ^^^^^^ which is handy in more complicated expressions, "ptype" does not: (gdb) ptype getenv ("PATH") function has unknown return type; cast the call to its declared return type ^^^^^^^^ This commit builds on the new OP_VAR_MSYM_VALUE to fix it, by making OP_FUNCALL extract the function name from the symbol stored in OP_VAR_VALUE/OP_VAR_MSYM_VALUE. We now get the same error in "print" vs "ptype": (gdb) ptype getenv() 'getenv' has unknown return type; cast the call to its declared return type (gdb) p getenv() 'getenv' has unknown return type; cast the call to its declared return type gdb/ChangeLog: yyyy-dd-yy Pedro Alves * eval.c (evaluate_subexp_standard): : Extract function name from symbol/minsym and pass it to error_call_unknown_return_type. gdb/testsuite/ChangeLog: yyyy-dd-yy Pedro Alves * gdb.base/nodebug.exp: Test that ptype's error about functions with unknown return type includes the function name too. --- gdb/eval.c | 14 +++++++++++++- gdb/testsuite/gdb.base/nodebug.exp | 12 ++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index 457e280..0e77f0a 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -716,6 +716,7 @@ evaluate_subexp_standard (struct type *expect_type, int save_pos1; struct symbol *function = NULL; char *function_name = NULL; + const char *var_func_name = NULL; pc = (*pos)++; op = exp->elts[pc].opcode; @@ -1545,6 +1546,17 @@ evaluate_subexp_standard (struct type *expect_type, } else { + if (op == OP_VAR_MSYM_VALUE) + { + symbol *sym = exp->elts[*pos + 2].symbol; + var_func_name = SYMBOL_PRINT_NAME (sym); + } + else if (op == OP_VAR_VALUE) + { + minimal_symbol *msym = exp->elts[*pos + 2].msymbol; + var_func_name = MSYMBOL_PRINT_NAME (msym); + } + argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside); type = value_type (argvec[0]); if (type && TYPE_CODE (type) == TYPE_CODE_PTR) @@ -1761,7 +1773,7 @@ evaluate_subexp_standard (struct type *expect_type, return_type = expect_type; if (return_type == NULL) - error_call_unknown_return_type (NULL); + error_call_unknown_return_type (var_func_name); return allocate_value (return_type); } diff --git a/gdb/testsuite/gdb.base/nodebug.exp b/gdb/testsuite/gdb.base/nodebug.exp index 25dbf63..e7a6774 100644 --- a/gdb/testsuite/gdb.base/nodebug.exp +++ b/gdb/testsuite/gdb.base/nodebug.exp @@ -165,14 +165,10 @@ if [runto inner] then { # This test is not as obscure as it might look. `p getenv ("TERM")' # is a real-world example, at least on many systems. - - gdb_test {p/c array_index("abcdef",2)} \ - "'array_index' has unknown return type; cast the call to its declared return type" - gdb_test {ptype array_index("abcdef",2)} \ - "function has unknown return type; cast the call to its declared return type" - gdb_test {whatis array_index("abcdef",2)} \ - "function has unknown return type; cast the call to its declared return type" - + foreach cmd {"p/c" "ptype" "whatis"} { + gdb_test "$cmd array_index(\"abcdef\",2)" \ + "'array_index' has unknown return type; cast the call to its declared return type" + } if [target_info exists gdb,cannot_call_functions] { unsupported "p/c (int) array_index(\"abcdef\",2)" } else {