From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 80480 invoked by alias); 9 Mar 2016 14:32:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 80465 invoked by uid 89); 9 Mar 2016 14:32:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=AWL,BAYES_20,KAM_LAZY_DOMAIN_SECURITY,KAM_STOCKGEN,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=375, Hx-spam-relays-external:192.55.52.120, H*RU:mga04.intel.com, Hx-spam-relays-external:mga04.intel.com X-HELO: mga04.intel.com Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Mar 2016 14:32:13 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP; 09 Mar 2016 06:32:11 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 09 Mar 2016 06:32:11 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u29EW9uO013174; Wed, 9 Mar 2016 14:32:09 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id u29EW9ml023214; Wed, 9 Mar 2016 15:32:09 +0100 Received: (from wtedesch@localhost) by ulvlx001.iul.intel.com with œ id u29EW9tv023210; Wed, 9 Mar 2016 15:32:09 +0100 From: Walfred Tedeschi To: palves@redhat.com, brobecker@adacore.com Cc: gdb-patches@sourceware.org, Walfred Tedeschi Subject: [PATCH v1] Fix of default lookup for "this" symbol. Date: Wed, 09 Mar 2016 14:32:00 -0000 Message-Id: <1457533925-22168-1-git-send-email-walfred.tedeschi@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00128.txt.bz2 Using the default lookup for the symbol "this" might lead to segmentation fault in GDB. Some languages, e.g. Fortran, use as default lookup routine the C++ routines. For those languages "this" can be the instance of a class or even the definition of a class. When an instance of a class having the name "this" is evaluated in GDB a segmentation fault was observed. As example of the issue take into consideration the Fortran code: type foo real :: a type(bar) :: x character*7 :: b end type foo type(foo) :: this Issue appears when evaluating the variable "this" in GDB. Within the language definition structure there is a field that represents the name of the special symbol used for the C++ "this" for the language being described. The fix presented here takes into account the aforementioned field. In the case the aforementioned field is NULL "this" is not represented in the language described and the lookup should return a null_block_symbol. 2016-03-09 Walfred Tedeschi gdb/ChangeLog: * cp_lookup_bare_symbol (cp_lookup_bare_symbol): Add check for the name_of_this in order to return a null symbol when looking up for "this". gdb/testsuite/ChangeLog: * gdb.fortran/derived-types.exp (result_line, result_line_2): New variables. (print this%a, print this%b, print this): New tests. * gdb.fortran/derived-types.f90 (this): New object and initialization. --- gdb/cp-namespace.c | 7 ++++++ gdb/testsuite/gdb.fortran/derived-type.exp | 35 ++++++++++++++++++++++++++++-- gdb/testsuite/gdb.fortran/derived-type.f90 | 7 +++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 72002d6..b9d7dbe 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -210,6 +210,13 @@ cp_lookup_bare_symbol (const struct language_defn *langdef, if (lang_this.symbol == NULL) return null_block_symbol; + /* This whole routine is also the default path for several languages. + In some languages "this" is not a special symbol, + i.e. LA_NAME_OF_THIS is NULL. + For those cases we should return a null_block_symbol. */ + if (langdef != NULL && langdef->la_name_of_this == NULL) + return null_block_symbol; + type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (lang_this.symbol))); /* If TYPE_NAME is NULL, abandon trying to find this symbol. This can happen for lambda functions compiled with clang++, diff --git a/gdb/testsuite/gdb.fortran/derived-type.exp b/gdb/testsuite/gdb.fortran/derived-type.exp index f650352..acccf3b 100644 --- a/gdb/testsuite/gdb.fortran/derived-type.exp +++ b/gdb/testsuite/gdb.fortran/derived-type.exp @@ -74,14 +74,45 @@ gdb_test_multiple $test $test { gdb_test "print q%x%c" "\\$\[0-9\]+ = 1" gdb_test "print q%x%d" "\\$\[0-9\]+ = 2\\.375" +set result_line "= \\( a = 3.125, x = \\( c = 1, d = 2\\.375 \\),\ +b = 'abcdefg' \\)\r\n$gdb_prompt $" + +# Used in case compiler generates an array of characters. +set result_line_2 " = \\( a = 3.125, x = \\( 1, 2\\.375 \\),\ +b = \\('abcdefg'\\) \\)\r\n$gdb_prompt $" + set test "print q" gdb_test_multiple $test $test { - -re "\\$\[0-9\]+ = \\( a = 3.125, x = \\( c = 1, d = 2\\.375 \\), b = 'abcdefg' \\)\r\n$gdb_prompt $" { + -re $result_line { pass $test } - -re "\\$\[0-9\]+ = \\( a = 3.125, x = \\( 1, 2\\.375 \\), b = \\('abcdefg'\\) \\)\r\n$gdb_prompt $" { + -re $result_line_2 { # Compiler should produce string, not an array of characters. setup_xfail "*-*-*" fail $test } } + +gdb_test "print this%a" " = 3\\.125" + +set test "print this%b" +gdb_test_multiple $test $test { + -re " = 'abcdefg'\r\n$gdb_prompt $" { + pass $test + } + -re $result_line_2 { + setup_xfail "*-*-*" + fail $test + } +} + +set test "print this" +gdb_test_multiple $test $test { + -re $result_line { + pass $test + } + -re $result_line_2 { + setup_xfail "*-*-*" + fail $test + } +} diff --git a/gdb/testsuite/gdb.fortran/derived-type.f90 b/gdb/testsuite/gdb.fortran/derived-type.f90 index 2cb2339..aad1553 100644 --- a/gdb/testsuite/gdb.fortran/derived-type.f90 +++ b/gdb/testsuite/gdb.fortran/derived-type.f90 @@ -29,12 +29,17 @@ program main end type foo type(foo) :: q type(bar) :: p + type(foo) :: this p = bar(1, 2.375) q%a = 3.125 q%b = "abcdefg" q%x%c = 1 q%x%d = 2.375 - print *,p,q + this%a = 3.125 + this%b = "abcdefg" + this%x%c = 1 + this%x%d = 2.375 + print *,p,q,this end program main -- 2.1.4