]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix of default lookup for "this" symbol.
authorWalfred Tedeschi <walfred.tedeschi@intel.com>
Thu, 7 Jul 2016 15:33:05 +0000 (17:33 +0200)
committerWalfred Tedeschi <walfred.tedeschi@intel.com>
Thu, 7 Jul 2016 15:33:05 +0000 (17:33 +0200)
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.

Tests: Performed tests with gfortran and ifort.

Reviewed:
https://sourceware.org/ml/gdb-patches/2016-04/msg00068.html

After the commited patch:
https://sourceware.org/ml/gdb-patches/2016-06/msg00364.html
Patch can be applied.

2016-06-16  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

* cp-namespace.c (cp_lookup_bare_symbol): Use language passed as
parameter to look for the symbol "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/ChangeLog
gdb/cp-namespace.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/derived-type.exp
gdb/testsuite/gdb.fortran/derived-type.f90

index 6a9ebbddfec2222609a5f00efa9943058f24825b..2d3e5ed71f8a731cadfd0d3fc911365989928252 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-07  Walfred Tedeschi  <walfred.tedeschi@intel.com>
+
+       * cp-namespace.c (cp_lookup_bare_symbol): Use language passed as
+       parameter to look for the symbol "this".
+
+
 2016-07-06  John Baldwin  <jhb@FreeBSD.org>
 
        * h8300-tdep.c (h8300_print_register): Remove extraneous parentheses.
index 016a42f5883a298febb6d2f1eb001ec722549e1c..f34e383bd3089c721c6793f4fac7700cba389b9f 100644 (file)
@@ -206,10 +206,13 @@ cp_lookup_bare_symbol (const struct language_defn *langdef,
       struct block_symbol lang_this;
       struct type *type;
 
-      lang_this = lookup_language_this (language_def (language_cplus), block);
+      if (langdef != NULL)
+       lang_this = lookup_language_this (langdef, block);
+
       if (lang_this.symbol == 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++,
index b0e6c2a2efd8aa8380d0fd644d617c92f825f283..b6f21d766c430d87dc2b6057858fff878cc416d4 100644 (file)
@@ -1,3 +1,11 @@
+2016-07-07  Walfred Tedeschi  <walfred.tedeschi@intel.com>
+
+       * 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.
+
 2016-07-06  Simon Marchi  <simon.marchi@ericsson.com>
 
        * gdb.ada/arraydim.exp: Remove extra directory level in build
index 32431bc8ba848ea8abb19d4be0038756155aa64b..278185068d9f31d49124a4cb4b3b626fdf90bc22 100644 (file)
@@ -73,14 +73,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
+    }
+}
index 2cb2339c811db578bba83f681fde56493f4a653a..aad15532798a7d262e909b102a6779b61382f238 100644 (file)
@@ -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