public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types.
  2013-12-11 12:35 [PATCH v2 0/2] enable ptype/whatis for fortran types/modules Keven Boell
  2013-12-11 12:35 ` [PATCH v2 2/2] fortran: enable ptype/whatis for modules Keven Boell
@ 2013-12-11 12:35 ` Keven Boell
  2013-12-11 16:52   ` Doug Evans
  1 sibling, 1 reply; 9+ messages in thread
From: Keven Boell @ 2013-12-11 12:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: keven.boell, sanimir.agovic

	(gdb) ptype type
	old> No symbol "type" in current context.
	new> type = Type type
	     integer(kind=4) :: t_i
	     End Type type

2013-11-19  Sanimir Agovic  <sanimir.agovic@intel.com>
            Keven Boell  <keven.boell@intel.com>

	* f-exp.y (yylex): Add domain array to enable lookup
	in multiple domains. Loop over lookup domains and try
	to find requested symbol. Add STRUCT_DOMAIN to lookup
	domains to be able to query for user defined types.

testsuite/
	* gdb.fortran/type.f90: New file.
	* gdb.fortran/whatis_type.f90: New file.

Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/f-exp.y                               |   33 ++++++++++++--------
 gdb/testsuite/gdb.fortran/type.f90        |   28 +++++++++++++++++
 gdb/testsuite/gdb.fortran/whatis_type.exp |   48 +++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 12 deletions(-)
 create mode 100644 gdb/testsuite/gdb.fortran/type.f90
 create mode 100644 gdb/testsuite/gdb.fortran/whatis_type.exp

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 567cd00..a7e59df 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1175,21 +1175,30 @@ yylex (void)
     char *tmp = copy_name (yylval.sval);
     struct symbol *sym;
     struct field_of_this_result is_a_field_of_this;
+    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
+    int i;
     int hextype;
-    
-    /* Initialize this in case we *don't* use it in this call; that
-       way we can refer to it unconditionally below.  */
-    memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
-
-    sym = lookup_symbol (tmp, expression_context_block,
-			 VAR_DOMAIN,
-			 parse_language->la_language == language_cplus
-			 ? &is_a_field_of_this : NULL);
-    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+
+    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
       {
-	yylval.tsym.type = SYMBOL_TYPE (sym);
-	return TYPENAME;
+	/* Initialize this in case we *don't* use it in this call; that
+	   way we can refer to it unconditionally below.  */
+	memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
+
+	sym = lookup_symbol (tmp, expression_context_block,
+			     lookup_domains[i],
+			     parse_language->la_language == language_cplus
+			     ? &is_a_field_of_this : NULL);
+	if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+	  {
+	    yylval.tsym.type = SYMBOL_TYPE (sym);
+	    return TYPENAME;
+	  }
+
+	if (sym)
+	  break;
       }
+
     yylval.tsym.type
       = language_lookup_primitive_type_by_name (parse_language,
 						parse_gdbarch, tmp);
diff --git a/gdb/testsuite/gdb.fortran/type.f90 b/gdb/testsuite/gdb.fortran/type.f90
new file mode 100644
index 0000000..e0c699e
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/type.f90
@@ -0,0 +1,28 @@
+! Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+program type
+  implicit none
+
+  type :: t1
+    integer :: t1_i
+    real    :: t1_r
+  end type t1
+
+  type (t1) :: t1v
+
+  t1v%t1_i = 42
+  t1v%t1_r = 42.24    ! bp1
+end program type
diff --git a/gdb/testsuite/gdb.fortran/whatis_type.exp b/gdb/testsuite/gdb.fortran/whatis_type.exp
new file mode 100644
index 0000000..5a90b40
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/whatis_type.exp
@@ -0,0 +1,48 @@
+# Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+if { [skip_fortran_tests] } { continue }
+
+standard_testfile type.f90
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} \
+                          ${srcfile} {debug f90}] } {
+    return -1
+}
+
+if ![runto MAIN__] {
+    perror "Couldn't run to MAIN__"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "bp1"]
+gdb_continue_to_breakpoint "bp1"
+
+set t1_i "integer\\\(kind=4\\\) :: t1_i"
+set t1_r "real\\\(kind=4\\\) :: t1_r"
+
+gdb_test "whatis t1" \
+  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
+  "whatis t1"
+gdb_test "whatis t1v" \
+  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
+  "whatis t1v"
+
+gdb_test "ptype t1" \
+  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
+  "ptype t1"
+gdb_test "ptype t1v" \
+  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
+  "ptype t1"
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 0/2] enable ptype/whatis for fortran types/modules
@ 2013-12-11 12:35 Keven Boell
  2013-12-11 12:35 ` [PATCH v2 2/2] fortran: enable ptype/whatis for modules Keven Boell
  2013-12-11 12:35 ` [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types Keven Boell
  0 siblings, 2 replies; 9+ messages in thread
From: Keven Boell @ 2013-12-11 12:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: keven.boell, sanimir.agovic

This patch series enables ptype/whatis for fortran
user defined types and modules.

Recognize fortran user defined types:
	(gdb) ptype type
	old> No symbol "type" in current context.
	new> type = Type type
	     integer(kind=4) :: t_i
	     End Type type

Recognize fortran modules:
	(gdb) ptype modname
	old> No symbol "modname" in current context.
	new> type = module modname


Keven Boell (1):
  fortran: enable ptype/whatis for modules.

Sanimir Agovic (1):
  fortran: enable ptype/whatis for user defined types.

 gdb/cp-namespace.c                        |    1 +
 gdb/dwarf2read.c                          |   20 ++++++++++++
 gdb/f-exp.y                               |   34 ++++++++++++--------
 gdb/symtab.h                              |    4 +++
 gdb/testsuite/gdb.fortran/module.exp      |   13 ++++++--
 gdb/testsuite/gdb.fortran/module.f90      |   12 ++++++++
 gdb/testsuite/gdb.fortran/type.f90        |   28 +++++++++++++++++
 gdb/testsuite/gdb.fortran/whatis_type.exp |   48 +++++++++++++++++++++++++++++
 8 files changed, 145 insertions(+), 15 deletions(-)
 create mode 100644 gdb/testsuite/gdb.fortran/type.f90
 create mode 100644 gdb/testsuite/gdb.fortran/whatis_type.exp

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 2/2] fortran: enable ptype/whatis for modules.
  2013-12-11 12:35 [PATCH v2 0/2] enable ptype/whatis for fortran types/modules Keven Boell
@ 2013-12-11 12:35 ` Keven Boell
  2013-12-11 17:07   ` Doug Evans
  2013-12-11 12:35 ` [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types Keven Boell
  1 sibling, 1 reply; 9+ messages in thread
From: Keven Boell @ 2013-12-11 12:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: keven.boell, sanimir.agovic

Added new domain MODULE_DOMAIN for fortran modules to avoid
issues with sharing namespaces (e.g. when a variable currently
in scope has the same name as a module).

	(gdb) ptype modname
	old> No symbol "modname" in current context.
	new> type = module modname

This fixes PR 15209 and also addresses the issue
with sharing namespaces:
https://sourceware.org/ml/gdb-patches/2013-02/msg00643.html

2013-11-19  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

	* cp-namespace.c (cp_lookup_nested_symbol): Enable
	nested lookups for fortran modules.
	* dwarf2read.c (read_module): Add fortran module to
	the symbol table.
	(add_partial_symbol, add_partial_module): Add fortran
	module to the partial symbol table.
	(new_symbol_full): Create full symbol for fortran module.
	* f-exp.y (yylex): Add new module domain to be parsed.
	* symtab.h: New domain for fortran modules.

testsuite/

	* gdb.fortran/module.exp: Completion matches fortran module
	names as well. ptype/whatis on modules return a proper type.
	Add new check for having the correct scope.

Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/cp-namespace.c                   |    1 +
 gdb/dwarf2read.c                     |   20 ++++++++++++++++++++
 gdb/f-exp.y                          |    3 ++-
 gdb/symtab.h                         |    4 ++++
 gdb/testsuite/gdb.fortran/module.exp |   13 ++++++++++---
 gdb/testsuite/gdb.fortran/module.f90 |   12 ++++++++++++
 6 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 36134c0..06d8c76 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -784,6 +784,7 @@ cp_lookup_nested_symbol (struct type *parent_type,
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_NAMESPACE:
     case TYPE_CODE_UNION:
+    case TYPE_CODE_MODULE:
       {
 	/* NOTE: carlton/2003-11-10: We don't treat C++ class members
 	   of classes like, say, data or function members.  Instead,
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1c7dfc5..8d07f86 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6801,6 +6801,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 			   &objfile->global_psymbols,
 			   0, (CORE_ADDR) 0, cu->language, objfile);
       break;
+    case DW_TAG_module:
+      add_psymbol_to_list (actual_name, strlen (actual_name),
+			   built_actual_name != NULL,
+			   MODULE_DOMAIN, LOC_TYPEDEF,
+			   &objfile->global_psymbols,
+			   0, (CORE_ADDR) 0, cu->language, objfile);
+      break;
     case DW_TAG_class_type:
     case DW_TAG_interface_type:
     case DW_TAG_structure_type:
@@ -6871,6 +6878,10 @@ static void
 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
 		    CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
 {
+  /* Add a symbol for the namespace.  */
+
+  add_partial_symbol (pdi, cu);
+
   /* Now scan partial symbols in that module.  */
 
   if (pdi->has_children)
@@ -13660,6 +13671,10 @@ static void
 read_module (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct die_info *child_die = die->child;
+  struct type *type;
+
+  type = read_type_die (die, cu);
+  new_symbol (die, type, cu);
 
   while (child_die && child_die->tag)
     {
@@ -17690,6 +17705,11 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
 	  list_to_add = &global_symbols;
 	  break;
+	case DW_TAG_module:
+	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
+	  SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
+	  list_to_add = &global_symbols;
+	  break;
 	case DW_TAG_common_block:
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
 	  SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index a7e59df..efddf1f 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1175,7 +1175,8 @@ yylex (void)
     char *tmp = copy_name (yylval.sval);
     struct symbol *sym;
     struct field_of_this_result is_a_field_of_this;
-    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
+    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN,
+      MODULE_DOMAIN};
     int i;
     int hextype;
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 7cc6667..cca6a76 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -418,6 +418,10 @@ typedef enum domain_enum_tag
 
   STRUCT_DOMAIN,
 
+  /* MODULE_DOMAIN is used in Fortran to hold module type names.  */
+
+  MODULE_DOMAIN,
+
   /* LABEL_DOMAIN may be used for names of labels (for gotos).  */
 
   LABEL_DOMAIN,
diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
index 6a2b87d..8f5f1b7 100644
--- a/gdb/testsuite/gdb.fortran/module.exp
+++ b/gdb/testsuite/gdb.fortran/module.exp
@@ -43,6 +43,13 @@ gdb_breakpoint [gdb_get_line_number "i-is-2"]
 gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
 gdb_test "print var_i" " = 2" "print var_i value 2"
 
+gdb_breakpoint [gdb_get_line_number "i-is-3"]
+gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
+# Ensure that the scope is correctly resolved.
+gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
+gdb_test "p mod2" " = 3" "print mod2"
+gdb_test "p mod1" " = 3" "print mod1"
+
 gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
 gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
 gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
@@ -54,7 +61,7 @@ gdb_test "print var_x" " = 30" "print var_x value 30"
 gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
 gdb_test "print var_z" " = 31" "print var_x value 31"
 
-gdb_test "ptype modmany" {No symbol "modmany" in current context.}
+gdb_test "ptype modmany" "type = module modmany"
 
 proc complete {expr list} {
     set cmd "complete p $expr"
@@ -62,8 +69,8 @@ proc complete {expr list} {
     gdb_test $cmd $expect "complete $expr"
 }
 set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
-complete "modm" $modmany_list
-complete "modmany" $modmany_list
+complete "modm" "modmany $modmany_list"
+complete "modmany" "modmany $modmany_list"
 complete "modmany::" $modmany_list
 complete "modmany::var" $modmany_list
 
diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
index ada7262..d10b1fb 100644
--- a/gdb/testsuite/gdb.fortran/module.f90
+++ b/gdb/testsuite/gdb.fortran/module.f90
@@ -23,6 +23,12 @@ module mod2
         integer :: var_i = 2
 end module mod2
 
+module mod3
+        integer :: mod2 = 3
+        integer :: mod1 = 3
+        integer :: var_i = 3
+end module mod3
+
 module modmany
         integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
 end module modmany
@@ -43,6 +49,11 @@ end module moduse
         var_i = var_i                         ! i-is-2
         end
 
+        subroutine sub3
+        USE mod3
+        var_i = var_i                         ! i-is-3
+        END
+
         program module
 
         use modmany, only: var_b, var_d => var_c, var_i
@@ -50,6 +61,7 @@ end module moduse
 
         call sub1
         call sub2
+        call sub3
 
         if (var_b .ne. 11) call abort
         if (var_d .ne. 12) call abort
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types.
  2013-12-11 12:35 ` [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types Keven Boell
@ 2013-12-11 16:52   ` Doug Evans
  2013-12-12 13:04     ` Keven Boell
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2013-12-11 16:52 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches, Sanimir Agovic

On Wed, Dec 11, 2013 at 4:35 AM, Keven Boell <keven.boell@intel.com> wrote:
>         (gdb) ptype type
>         old> No symbol "type" in current context.
>         new> type = Type type
>              integer(kind=4) :: t_i
>              End Type type
>
> 2013-11-19  Sanimir Agovic  <sanimir.agovic@intel.com>
>             Keven Boell  <keven.boell@intel.com>
>
>         * f-exp.y (yylex): Add domain array to enable lookup
>         in multiple domains. Loop over lookup domains and try
>         to find requested symbol. Add STRUCT_DOMAIN to lookup
>         domains to be able to query for user defined types.
>
> testsuite/
>         * gdb.fortran/type.f90: New file.
>         * gdb.fortran/whatis_type.f90: New file.
>
> Signed-off-by: Keven Boell <keven.boell@intel.com>
> ---
>  gdb/f-exp.y                               |   33 ++++++++++++--------
>  gdb/testsuite/gdb.fortran/type.f90        |   28 +++++++++++++++++
>  gdb/testsuite/gdb.fortran/whatis_type.exp |   48 +++++++++++++++++++++++++++++
>  3 files changed, 97 insertions(+), 12 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.fortran/type.f90
>  create mode 100644 gdb/testsuite/gdb.fortran/whatis_type.exp
>
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index 567cd00..a7e59df 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -1175,21 +1175,30 @@ yylex (void)
>      char *tmp = copy_name (yylval.sval);
>      struct symbol *sym;
>      struct field_of_this_result is_a_field_of_this;
> +    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
> +    int i;
>      int hextype;
> -
> -    /* Initialize this in case we *don't* use it in this call; that
> -       way we can refer to it unconditionally below.  */
> -    memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
> -
> -    sym = lookup_symbol (tmp, expression_context_block,
> -                        VAR_DOMAIN,
> -                        parse_language->la_language == language_cplus
> -                        ? &is_a_field_of_this : NULL);
> -    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
> +
> +    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
>        {
> -       yylval.tsym.type = SYMBOL_TYPE (sym);
> -       return TYPENAME;
> +       /* Initialize this in case we *don't* use it in this call; that
> +          way we can refer to it unconditionally below.  */
> +       memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
> +
> +       sym = lookup_symbol (tmp, expression_context_block,
> +                            lookup_domains[i],
> +                            parse_language->la_language == language_cplus
> +                            ? &is_a_field_of_this : NULL);
> +       if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
> +         {
> +           yylval.tsym.type = SYMBOL_TYPE (sym);
> +           return TYPENAME;
> +         }
> +
> +       if (sym)
> +         break;
>        }
> +
>      yylval.tsym.type
>        = language_lookup_primitive_type_by_name (parse_language,
>                                                 parse_gdbarch, tmp);

I don't have any comments on this part of the patch,
Looks ok but I if there's a fortran-specific issue here I wouldn't know it. :-)

> diff --git a/gdb/testsuite/gdb.fortran/type.f90 b/gdb/testsuite/gdb.fortran/type.f90
> new file mode 100644
> index 0000000..e0c699e
> --- /dev/null
> +++ b/gdb/testsuite/gdb.fortran/type.f90
> @@ -0,0 +1,28 @@
> +! Copyright 2013 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 <http://www.gnu.org/licenses/>.
> +
> +program type
> +  implicit none
> +
> +  type :: t1
> +    integer :: t1_i
> +    real    :: t1_r
> +  end type t1
> +
> +  type (t1) :: t1v
> +
> +  t1v%t1_i = 42
> +  t1v%t1_r = 42.24    ! bp1
> +end program type
> diff --git a/gdb/testsuite/gdb.fortran/whatis_type.exp b/gdb/testsuite/gdb.fortran/whatis_type.exp
> new file mode 100644
> index 0000000..5a90b40
> --- /dev/null
> +++ b/gdb/testsuite/gdb.fortran/whatis_type.exp
> @@ -0,0 +1,48 @@
> +# Copyright 2013 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 <http://www.gnu.org/licenses/>.
> +
> +if { [skip_fortran_tests] } { continue }
> +
> +standard_testfile type.f90
> +
> +if { [prepare_for_testing ${testfile}.exp ${testfile} \
> +                          ${srcfile} {debug f90}] } {
> +    return -1
> +}
> +
> +if ![runto MAIN__] {
> +    perror "Couldn't run to MAIN__"
> +    continue
> +}

I never liked calling perror for this particular failure.
grepping, I see it's still used a lot though I'll bet that's all
cut-n-paste (and presumably you're just going with the flow here as
well).
For new patches I'd like to just use fail here (that's what runto will
do internally if asked).

> +
> +gdb_breakpoint [gdb_get_line_number "bp1"]
> +gdb_continue_to_breakpoint "bp1"
> +
> +set t1_i "integer\\\(kind=4\\\) :: t1_i"
> +set t1_r "real\\\(kind=4\\\) :: t1_r"
> +
> +gdb_test "whatis t1" \
> +  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
> +  "whatis t1"
> +gdb_test "whatis t1v" \
> +  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
> +  "whatis t1v"
> +
> +gdb_test "ptype t1" \
> +  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
> +  "ptype t1"
> +gdb_test "ptype t1v" \
> +  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
> +  "ptype t1"

Typo: "ptype t1v"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] fortran: enable ptype/whatis for modules.
  2013-12-11 12:35 ` [PATCH v2 2/2] fortran: enable ptype/whatis for modules Keven Boell
@ 2013-12-11 17:07   ` Doug Evans
  2013-12-12 13:04     ` Keven Boell
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2013-12-11 17:07 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches, Sanimir Agovic

On Wed, Dec 11, 2013 at 4:35 AM, Keven Boell <keven.boell@intel.com> wrote:
> Added new domain MODULE_DOMAIN for fortran modules to avoid
> issues with sharing namespaces (e.g. when a variable currently
> in scope has the same name as a module).
>
>         (gdb) ptype modname
>         old> No symbol "modname" in current context.
>         new> type = module modname
>
> This fixes PR 15209 and also addresses the issue
> with sharing namespaces:
> https://sourceware.org/ml/gdb-patches/2013-02/msg00643.html
>
> 2013-11-19  Keven Boell  <keven.boell@intel.com>
>             Sanimir Agovic  <sanimir.agovic@intel.com>
>
>         * cp-namespace.c (cp_lookup_nested_symbol): Enable
>         nested lookups for fortran modules.
>         * dwarf2read.c (read_module): Add fortran module to
>         the symbol table.
>         (add_partial_symbol, add_partial_module): Add fortran
>         module to the partial symbol table.
>         (new_symbol_full): Create full symbol for fortran module.
>         * f-exp.y (yylex): Add new module domain to be parsed.
>         * symtab.h: New domain for fortran modules.
>
> testsuite/
>
>         * gdb.fortran/module.exp: Completion matches fortran module
>         names as well. ptype/whatis on modules return a proper type.
>         Add new check for having the correct scope.
>
> Signed-off-by: Keven Boell <keven.boell@intel.com>
> ---
>  gdb/cp-namespace.c                   |    1 +
>  gdb/dwarf2read.c                     |   20 ++++++++++++++++++++
>  gdb/f-exp.y                          |    3 ++-
>  gdb/symtab.h                         |    4 ++++
>  gdb/testsuite/gdb.fortran/module.exp |   13 ++++++++++---
>  gdb/testsuite/gdb.fortran/module.f90 |   12 ++++++++++++
>  6 files changed, 49 insertions(+), 4 deletions(-)
>
> diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
> index 36134c0..06d8c76 100644
> --- a/gdb/cp-namespace.c
> +++ b/gdb/cp-namespace.c
> @@ -784,6 +784,7 @@ cp_lookup_nested_symbol (struct type *parent_type,
>      case TYPE_CODE_STRUCT:
>      case TYPE_CODE_NAMESPACE:
>      case TYPE_CODE_UNION:
> +    case TYPE_CODE_MODULE:

My gut reaction is to shudder and hope we can assert fail for this
case instead. :-)
[having to handle non-c++ stuff in cp-anything.c seems odd at first glance]
The comment for this function says it's only called when parent_type
is a c++ class or namespace.
How do we get here for a module?
[And if we can legitimately get here, a comment explaining "why things
are the way they are" is required (i.e. explain why we have to handle
TYPE_CODE_MODULE here).
I say that a lot, I know.  But it really helps me when I'm in the code later.]

>        {
>         /* NOTE: carlton/2003-11-10: We don't treat C++ class members
>            of classes like, say, data or function members.  Instead,
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 1c7dfc5..8d07f86 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -6801,6 +6801,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
>                            &objfile->global_psymbols,
>                            0, (CORE_ADDR) 0, cu->language, objfile);
>        break;
> +    case DW_TAG_module:
> +      add_psymbol_to_list (actual_name, strlen (actual_name),
> +                          built_actual_name != NULL,
> +                          MODULE_DOMAIN, LOC_TYPEDEF,
> +                          &objfile->global_psymbols,
> +                          0, (CORE_ADDR) 0, cu->language, objfile);
> +      break;
>      case DW_TAG_class_type:
>      case DW_TAG_interface_type:
>      case DW_TAG_structure_type:
> @@ -6871,6 +6878,10 @@ static void
>  add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
>                     CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
>  {
> +  /* Add a symbol for the namespace.  */
> +
> +  add_partial_symbol (pdi, cu);
> +
>    /* Now scan partial symbols in that module.  */
>
>    if (pdi->has_children)
> @@ -13660,6 +13671,10 @@ static void
>  read_module (struct die_info *die, struct dwarf2_cu *cu)
>  {
>    struct die_info *child_die = die->child;
> +  struct type *type;
> +
> +  type = read_type_die (die, cu);
> +  new_symbol (die, type, cu);
>
>    while (child_die && child_die->tag)
>      {
> @@ -17690,6 +17705,11 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
>           SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
>           list_to_add = &global_symbols;
>           break;
> +       case DW_TAG_module:
> +         SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
> +         SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
> +         list_to_add = &global_symbols;
> +         break;
>         case DW_TAG_common_block:
>           SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
>           SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index a7e59df..efddf1f 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -1175,7 +1175,8 @@ yylex (void)
>      char *tmp = copy_name (yylval.sval);
>      struct symbol *sym;
>      struct field_of_this_result is_a_field_of_this;
> -    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
> +    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN,
> +      MODULE_DOMAIN};

I'm sure there's a rule that says this needs to be formatted
differently, though I'm not sure of the details.
Maybe begin a new line at the {, and put } on a line by itself?

>      int i;
>      int hextype;
>
> diff --git a/gdb/symtab.h b/gdb/symtab.h
> index 7cc6667..cca6a76 100644
> --- a/gdb/symtab.h
> +++ b/gdb/symtab.h
> @@ -418,6 +418,10 @@ typedef enum domain_enum_tag
>
>    STRUCT_DOMAIN,
>
> +  /* MODULE_DOMAIN is used in Fortran to hold module type names.  */
> +
> +  MODULE_DOMAIN,
> +
>    /* LABEL_DOMAIN may be used for names of labels (for gotos).  */
>
>    LABEL_DOMAIN,
> diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
> index 6a2b87d..8f5f1b7 100644
> --- a/gdb/testsuite/gdb.fortran/module.exp
> +++ b/gdb/testsuite/gdb.fortran/module.exp
> @@ -43,6 +43,13 @@ gdb_breakpoint [gdb_get_line_number "i-is-2"]
>  gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
>  gdb_test "print var_i" " = 2" "print var_i value 2"
>
> +gdb_breakpoint [gdb_get_line_number "i-is-3"]
> +gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
> +# Ensure that the scope is correctly resolved.
> +gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
> +gdb_test "p mod2" " = 3" "print mod2"
> +gdb_test "p mod1" " = 3" "print mod1"
> +
>  gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
>  gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
>  gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
> @@ -54,7 +61,7 @@ gdb_test "print var_x" " = 30" "print var_x value 30"
>  gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
>  gdb_test "print var_z" " = 31" "print var_x value 31"
>
> -gdb_test "ptype modmany" {No symbol "modmany" in current context.}
> +gdb_test "ptype modmany" "type = module modmany"
>
>  proc complete {expr list} {
>      set cmd "complete p $expr"
> @@ -62,8 +69,8 @@ proc complete {expr list} {
>      gdb_test $cmd $expect "complete $expr"
>  }
>  set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
> -complete "modm" $modmany_list
> -complete "modmany" $modmany_list
> +complete "modm" "modmany $modmany_list"
> +complete "modmany" "modmany $modmany_list"
>  complete "modmany::" $modmany_list
>  complete "modmany::var" $modmany_list
>
> diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
> index ada7262..d10b1fb 100644
> --- a/gdb/testsuite/gdb.fortran/module.f90
> +++ b/gdb/testsuite/gdb.fortran/module.f90
> @@ -23,6 +23,12 @@ module mod2
>          integer :: var_i = 2
>  end module mod2
>
> +module mod3
> +        integer :: mod2 = 3
> +        integer :: mod1 = 3
> +        integer :: var_i = 3
> +end module mod3
> +
>  module modmany
>          integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
>  end module modmany
> @@ -43,6 +49,11 @@ end module moduse
>          var_i = var_i                         ! i-is-2
>          end
>
> +        subroutine sub3
> +        USE mod3
> +        var_i = var_i                         ! i-is-3
> +        END
> +
>          program module
>
>          use modmany, only: var_b, var_d => var_c, var_i
> @@ -50,6 +61,7 @@ end module moduse
>
>          call sub1
>          call sub2
> +        call sub3
>
>          if (var_b .ne. 11) call abort
>          if (var_d .ne. 12) call abort
> --
> 1.7.9.5
>


The rest seems ok to me.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types.
  2013-12-11 16:52   ` Doug Evans
@ 2013-12-12 13:04     ` Keven Boell
  2013-12-16 17:10       ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Keven Boell @ 2013-12-12 13:04 UTC (permalink / raw)
  To: Doug Evans, Keven Boell; +Cc: gdb-patches, Sanimir Agovic

Thank you for the review. Please see my comments below.

On 11.12.2013 17:52, Doug Evans wrote:
> On Wed, Dec 11, 2013 at 4:35 AM, Keven Boell <keven.boell@intel.com> wrote:
>>         (gdb) ptype type
>>         old> No symbol "type" in current context.
>>         new> type = Type type
>>              integer(kind=4) :: t_i
>>              End Type type
>>
>> 2013-11-19  Sanimir Agovic  <sanimir.agovic@intel.com>
>>             Keven Boell  <keven.boell@intel.com>
>>
>>         * f-exp.y (yylex): Add domain array to enable lookup
>>         in multiple domains. Loop over lookup domains and try
>>         to find requested symbol. Add STRUCT_DOMAIN to lookup
>>         domains to be able to query for user defined types.
>>
>> testsuite/
>>         * gdb.fortran/type.f90: New file.
>>         * gdb.fortran/whatis_type.f90: New file.
>>
>> Signed-off-by: Keven Boell <keven.boell@intel.com>
>> ---
>>  gdb/f-exp.y                               |   33 ++++++++++++--------
>>  gdb/testsuite/gdb.fortran/type.f90        |   28 +++++++++++++++++
>>  gdb/testsuite/gdb.fortran/whatis_type.exp |   48 +++++++++++++++++++++++++++++
>>  3 files changed, 97 insertions(+), 12 deletions(-)
>>  create mode 100644 gdb/testsuite/gdb.fortran/type.f90
>>  create mode 100644 gdb/testsuite/gdb.fortran/whatis_type.exp
>>
>> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
>> index 567cd00..a7e59df 100644
>> --- a/gdb/f-exp.y
>> +++ b/gdb/f-exp.y
>> @@ -1175,21 +1175,30 @@ yylex (void)
>>      char *tmp = copy_name (yylval.sval);
>>      struct symbol *sym;
>>      struct field_of_this_result is_a_field_of_this;
>> +    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
>> +    int i;
>>      int hextype;
>> -
>> -    /* Initialize this in case we *don't* use it in this call; that
>> -       way we can refer to it unconditionally below.  */
>> -    memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
>> -
>> -    sym = lookup_symbol (tmp, expression_context_block,
>> -                        VAR_DOMAIN,
>> -                        parse_language->la_language == language_cplus
>> -                        ? &is_a_field_of_this : NULL);
>> -    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
>> +
>> +    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
>>        {
>> -       yylval.tsym.type = SYMBOL_TYPE (sym);
>> -       return TYPENAME;
>> +       /* Initialize this in case we *don't* use it in this call; that
>> +          way we can refer to it unconditionally below.  */
>> +       memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
>> +
>> +       sym = lookup_symbol (tmp, expression_context_block,
>> +                            lookup_domains[i],
>> +                            parse_language->la_language == language_cplus
>> +                            ? &is_a_field_of_this : NULL);
>> +       if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
>> +         {
>> +           yylval.tsym.type = SYMBOL_TYPE (sym);
>> +           return TYPENAME;
>> +         }
>> +
>> +       if (sym)
>> +         break;
>>        }
>> +
>>      yylval.tsym.type
>>        = language_lookup_primitive_type_by_name (parse_language,
>>                                                 parse_gdbarch, tmp);
> 
> I don't have any comments on this part of the patch,
> Looks ok but I if there's a fortran-specific issue here I wouldn't know it. :-)
> 
>> diff --git a/gdb/testsuite/gdb.fortran/type.f90 b/gdb/testsuite/gdb.fortran/type.f90
>> new file mode 100644
>> index 0000000..e0c699e
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.fortran/type.f90
>> @@ -0,0 +1,28 @@
>> +! Copyright 2013 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 <http://www.gnu.org/licenses/>.
>> +
>> +program type
>> +  implicit none
>> +
>> +  type :: t1
>> +    integer :: t1_i
>> +    real    :: t1_r
>> +  end type t1
>> +
>> +  type (t1) :: t1v
>> +
>> +  t1v%t1_i = 42
>> +  t1v%t1_r = 42.24    ! bp1
>> +end program type
>> diff --git a/gdb/testsuite/gdb.fortran/whatis_type.exp b/gdb/testsuite/gdb.fortran/whatis_type.exp
>> new file mode 100644
>> index 0000000..5a90b40
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.fortran/whatis_type.exp
>> @@ -0,0 +1,48 @@
>> +# Copyright 2013 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 <http://www.gnu.org/licenses/>.
>> +
>> +if { [skip_fortran_tests] } { continue }
>> +
>> +standard_testfile type.f90
>> +
>> +if { [prepare_for_testing ${testfile}.exp ${testfile} \
>> +                          ${srcfile} {debug f90}] } {
>> +    return -1
>> +}
>> +
>> +if ![runto MAIN__] {
>> +    perror "Couldn't run to MAIN__"
>> +    continue
>> +}
> 
> I never liked calling perror for this particular failure.
> grepping, I see it's still used a lot though I'll bet that's all
> cut-n-paste (and presumably you're just going with the flow here as
> well).
> For new patches I'd like to just use fail here (that's what runto will
> do internally if asked).
> 

Indeed, I used another test as template :-)
Changed it to call fail with an appropriate message. I've attached the updated patch below.

>> +
>> +gdb_breakpoint [gdb_get_line_number "bp1"]
>> +gdb_continue_to_breakpoint "bp1"
>> +
>> +set t1_i "integer\\\(kind=4\\\) :: t1_i"
>> +set t1_r "real\\\(kind=4\\\) :: t1_r"
>> +
>> +gdb_test "whatis t1" \
>> +  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
>> +  "whatis t1"
>> +gdb_test "whatis t1v" \
>> +  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
>> +  "whatis t1v"
>> +
>> +gdb_test "ptype t1" \
>> +  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
>> +  "ptype t1"
>> +gdb_test "ptype t1v" \
>> +  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
>> +  "ptype t1"
> 
> Typo: "ptype t1v"
> 

Fixed.


Updated patch:

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 567cd00..a7e59df 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1175,21 +1175,30 @@ yylex (void)
     char *tmp = copy_name (yylval.sval);
     struct symbol *sym;
     struct field_of_this_result is_a_field_of_this;
+    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
+    int i;
     int hextype;
-    
-    /* Initialize this in case we *don't* use it in this call; that
-       way we can refer to it unconditionally below.  */
-    memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
-
-    sym = lookup_symbol (tmp, expression_context_block,
-			 VAR_DOMAIN,
-			 parse_language->la_language == language_cplus
-			 ? &is_a_field_of_this : NULL);
-    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+
+    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
       {
-	yylval.tsym.type = SYMBOL_TYPE (sym);
-	return TYPENAME;
+	/* Initialize this in case we *don't* use it in this call; that
+	   way we can refer to it unconditionally below.  */
+	memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
+
+	sym = lookup_symbol (tmp, expression_context_block,
+			     lookup_domains[i],
+			     parse_language->la_language == language_cplus
+			     ? &is_a_field_of_this : NULL);
+	if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+	  {
+	    yylval.tsym.type = SYMBOL_TYPE (sym);
+	    return TYPENAME;
+	  }
+
+	if (sym)
+	  break;
       }
+
     yylval.tsym.type
       = language_lookup_primitive_type_by_name (parse_language,
 						parse_gdbarch, tmp);
diff --git a/gdb/testsuite/gdb.fortran/type.f90 b/gdb/testsuite/gdb.fortran/type.f90
new file mode 100644
index 0000000..e0c699e
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/type.f90
@@ -0,0 +1,28 @@
+! Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+program type
+  implicit none
+
+  type :: t1
+    integer :: t1_i
+    real    :: t1_r
+  end type t1
+
+  type (t1) :: t1v
+
+  t1v%t1_i = 42
+  t1v%t1_r = 42.24    ! bp1
+end program type
diff --git a/gdb/testsuite/gdb.fortran/whatis_type.exp b/gdb/testsuite/gdb.fortran/whatis_type.exp
new file mode 100644
index 0000000..9d6151f
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/whatis_type.exp
@@ -0,0 +1,48 @@
+# Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+if { [skip_fortran_tests] } { continue }
+
+standard_testfile type.f90
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} \
+                          ${srcfile} {debug f90}] } {
+    return -1
+}
+
+if ![runto MAIN__] {
+    fail "run to MAIN__"
+    return
+}
+
+gdb_breakpoint [gdb_get_line_number "bp1"]
+gdb_continue_to_breakpoint "bp1"
+
+set t1_i "integer\\\(kind=4\\\) :: t1_i"
+set t1_r "real\\\(kind=4\\\) :: t1_r"
+
+gdb_test "whatis t1" \
+  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
+  "whatis t1"
+gdb_test "whatis t1v" \
+  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
+  "whatis t1v"
+
+gdb_test "ptype t1" \
+  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
+  "ptype t1"
+gdb_test "ptype t1v" \
+  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
+  "ptype t1v"
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] fortran: enable ptype/whatis for modules.
  2013-12-11 17:07   ` Doug Evans
@ 2013-12-12 13:04     ` Keven Boell
  2013-12-16 17:14       ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Keven Boell @ 2013-12-12 13:04 UTC (permalink / raw)
  To: Doug Evans, Keven Boell; +Cc: gdb-patches, Sanimir Agovic

On 11.12.2013 18:07, Doug Evans wrote:
> On Wed, Dec 11, 2013 at 4:35 AM, Keven Boell <keven.boell@intel.com> wrote:
>> Added new domain MODULE_DOMAIN for fortran modules to avoid
>> issues with sharing namespaces (e.g. when a variable currently
>> in scope has the same name as a module).
>>
>>         (gdb) ptype modname
>>         old> No symbol "modname" in current context.
>>         new> type = module modname
>>
>> This fixes PR 15209 and also addresses the issue
>> with sharing namespaces:
>> https://sourceware.org/ml/gdb-patches/2013-02/msg00643.html
>>
>> 2013-11-19  Keven Boell  <keven.boell@intel.com>
>>             Sanimir Agovic  <sanimir.agovic@intel.com>
>>
>>         * cp-namespace.c (cp_lookup_nested_symbol): Enable
>>         nested lookups for fortran modules.
>>         * dwarf2read.c (read_module): Add fortran module to
>>         the symbol table.
>>         (add_partial_symbol, add_partial_module): Add fortran
>>         module to the partial symbol table.
>>         (new_symbol_full): Create full symbol for fortran module.
>>         * f-exp.y (yylex): Add new module domain to be parsed.
>>         * symtab.h: New domain for fortran modules.
>>
>> testsuite/
>>
>>         * gdb.fortran/module.exp: Completion matches fortran module
>>         names as well. ptype/whatis on modules return a proper type.
>>         Add new check for having the correct scope.
>>
>> Signed-off-by: Keven Boell <keven.boell@intel.com>
>> ---
>>  gdb/cp-namespace.c                   |    1 +
>>  gdb/dwarf2read.c                     |   20 ++++++++++++++++++++
>>  gdb/f-exp.y                          |    3 ++-
>>  gdb/symtab.h                         |    4 ++++
>>  gdb/testsuite/gdb.fortran/module.exp |   13 ++++++++++---
>>  gdb/testsuite/gdb.fortran/module.f90 |   12 ++++++++++++
>>  6 files changed, 49 insertions(+), 4 deletions(-)
>>
>> diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
>> index 36134c0..06d8c76 100644
>> --- a/gdb/cp-namespace.c
>> +++ b/gdb/cp-namespace.c
>> @@ -784,6 +784,7 @@ cp_lookup_nested_symbol (struct type *parent_type,
>>      case TYPE_CODE_STRUCT:
>>      case TYPE_CODE_NAMESPACE:
>>      case TYPE_CODE_UNION:
>> +    case TYPE_CODE_MODULE:
> 
> My gut reaction is to shudder and hope we can assert fail for this
> case instead. :-)
> [having to handle non-c++ stuff in cp-anything.c seems odd at first glance]
> The comment for this function says it's only called when parent_type
> is a c++ class or namespace.
> How do we get here for a module?
> [And if we can legitimately get here, a comment explaining "why things
> are the way they are" is required (i.e. explain why we have to handle
> TYPE_CODE_MODULE here).
> I say that a lot, I know.  But it really helps me when I'm in the code later.]
> 

GDB gets there via f-exp.y with a call to lookup_symbol. Actually GDB takes
the C++ code path for looking up non-local symbols in this case by calling
the function pointer la_lookup_symbol_nonlocal, which points to the C++ specific
code (cp_lookup_symbol_nonlocal) and ends up at this location.
I see that this might be confusing and added a comment describing this behavior.

>>        {
>>         /* NOTE: carlton/2003-11-10: We don't treat C++ class members
>>            of classes like, say, data or function members.  Instead,
>> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
>> index 1c7dfc5..8d07f86 100644
>> --- a/gdb/dwarf2read.c
>> +++ b/gdb/dwarf2read.c
>> @@ -6801,6 +6801,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
>>                            &objfile->global_psymbols,
>>                            0, (CORE_ADDR) 0, cu->language, objfile);
>>        break;
>> +    case DW_TAG_module:
>> +      add_psymbol_to_list (actual_name, strlen (actual_name),
>> +                          built_actual_name != NULL,
>> +                          MODULE_DOMAIN, LOC_TYPEDEF,
>> +                          &objfile->global_psymbols,
>> +                          0, (CORE_ADDR) 0, cu->language, objfile);
>> +      break;
>>      case DW_TAG_class_type:
>>      case DW_TAG_interface_type:
>>      case DW_TAG_structure_type:
>> @@ -6871,6 +6878,10 @@ static void
>>  add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
>>                     CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
>>  {
>> +  /* Add a symbol for the namespace.  */
>> +
>> +  add_partial_symbol (pdi, cu);
>> +
>>    /* Now scan partial symbols in that module.  */
>>
>>    if (pdi->has_children)
>> @@ -13660,6 +13671,10 @@ static void
>>  read_module (struct die_info *die, struct dwarf2_cu *cu)
>>  {
>>    struct die_info *child_die = die->child;
>> +  struct type *type;
>> +
>> +  type = read_type_die (die, cu);
>> +  new_symbol (die, type, cu);
>>
>>    while (child_die && child_die->tag)
>>      {
>> @@ -17690,6 +17705,11 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
>>           SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
>>           list_to_add = &global_symbols;
>>           break;
>> +       case DW_TAG_module:
>> +         SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
>> +         SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
>> +         list_to_add = &global_symbols;
>> +         break;
>>         case DW_TAG_common_block:
>>           SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
>>           SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
>> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
>> index a7e59df..efddf1f 100644
>> --- a/gdb/f-exp.y
>> +++ b/gdb/f-exp.y
>> @@ -1175,7 +1175,8 @@ yylex (void)
>>      char *tmp = copy_name (yylval.sval);
>>      struct symbol *sym;
>>      struct field_of_this_result is_a_field_of_this;
>> -    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
>> +    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN,
>> +      MODULE_DOMAIN};
> 
> I'm sure there's a rule that says this needs to be formatted
> differently, though I'm not sure of the details.
> Maybe begin a new line at the {, and put } on a line by itself?
> 

I had a look how this is done elsewhere in the code and noticed that there are several styles. I changed it to the most common one.

>>      int i;
>>      int hextype;
>>
>> diff --git a/gdb/symtab.h b/gdb/symtab.h
>> index 7cc6667..cca6a76 100644
>> --- a/gdb/symtab.h
>> +++ b/gdb/symtab.h
>> @@ -418,6 +418,10 @@ typedef enum domain_enum_tag
>>
>>    STRUCT_DOMAIN,
>>
>> +  /* MODULE_DOMAIN is used in Fortran to hold module type names.  */
>> +
>> +  MODULE_DOMAIN,
>> +
>>    /* LABEL_DOMAIN may be used for names of labels (for gotos).  */
>>
>>    LABEL_DOMAIN,
>> diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
>> index 6a2b87d..8f5f1b7 100644
>> --- a/gdb/testsuite/gdb.fortran/module.exp
>> +++ b/gdb/testsuite/gdb.fortran/module.exp
>> @@ -43,6 +43,13 @@ gdb_breakpoint [gdb_get_line_number "i-is-2"]
>>  gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
>>  gdb_test "print var_i" " = 2" "print var_i value 2"
>>
>> +gdb_breakpoint [gdb_get_line_number "i-is-3"]
>> +gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
>> +# Ensure that the scope is correctly resolved.
>> +gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
>> +gdb_test "p mod2" " = 3" "print mod2"
>> +gdb_test "p mod1" " = 3" "print mod1"
>> +
>>  gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
>>  gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
>>  gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
>> @@ -54,7 +61,7 @@ gdb_test "print var_x" " = 30" "print var_x value 30"
>>  gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
>>  gdb_test "print var_z" " = 31" "print var_x value 31"
>>
>> -gdb_test "ptype modmany" {No symbol "modmany" in current context.}
>> +gdb_test "ptype modmany" "type = module modmany"
>>
>>  proc complete {expr list} {
>>      set cmd "complete p $expr"
>> @@ -62,8 +69,8 @@ proc complete {expr list} {
>>      gdb_test $cmd $expect "complete $expr"
>>  }
>>  set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
>> -complete "modm" $modmany_list
>> -complete "modmany" $modmany_list
>> +complete "modm" "modmany $modmany_list"
>> +complete "modmany" "modmany $modmany_list"
>>  complete "modmany::" $modmany_list
>>  complete "modmany::var" $modmany_list
>>
>> diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
>> index ada7262..d10b1fb 100644
>> --- a/gdb/testsuite/gdb.fortran/module.f90
>> +++ b/gdb/testsuite/gdb.fortran/module.f90
>> @@ -23,6 +23,12 @@ module mod2
>>          integer :: var_i = 2
>>  end module mod2
>>
>> +module mod3
>> +        integer :: mod2 = 3
>> +        integer :: mod1 = 3
>> +        integer :: var_i = 3
>> +end module mod3
>> +
>>  module modmany
>>          integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
>>  end module modmany
>> @@ -43,6 +49,11 @@ end module moduse
>>          var_i = var_i                         ! i-is-2
>>          end
>>
>> +        subroutine sub3
>> +        USE mod3
>> +        var_i = var_i                         ! i-is-3
>> +        END
>> +
>>          program module
>>
>>          use modmany, only: var_b, var_d => var_c, var_i
>> @@ -50,6 +61,7 @@ end module moduse
>>
>>          call sub1
>>          call sub2
>> +        call sub3
>>
>>          if (var_b .ne. 11) call abort
>>          if (var_d .ne. 12) call abort
>> --
>> 1.7.9.5
>>
> 
> 
> The rest seems ok to me.
> 

The updated patch:

diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 36134c0..e666c3e 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -784,6 +784,10 @@ cp_lookup_nested_symbol (struct type *parent_type,
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_NAMESPACE:
     case TYPE_CODE_UNION:
+    /* NOTE: Handle modules here as well, because Fortran is re-using the C++
+       specific code to lookup nested symbols in modules, by calling the
+       function pointer la_lookup_symbol_nonlocal, which ends up here.  */
+    case TYPE_CODE_MODULE:
       {
 	/* NOTE: carlton/2003-11-10: We don't treat C++ class members
 	   of classes like, say, data or function members.  Instead,
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1c7dfc5..8d07f86 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6801,6 +6801,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 			   &objfile->global_psymbols,
 			   0, (CORE_ADDR) 0, cu->language, objfile);
       break;
+    case DW_TAG_module:
+      add_psymbol_to_list (actual_name, strlen (actual_name),
+			   built_actual_name != NULL,
+			   MODULE_DOMAIN, LOC_TYPEDEF,
+			   &objfile->global_psymbols,
+			   0, (CORE_ADDR) 0, cu->language, objfile);
+      break;
     case DW_TAG_class_type:
     case DW_TAG_interface_type:
     case DW_TAG_structure_type:
@@ -6871,6 +6878,10 @@ static void
 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
 		    CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
 {
+  /* Add a symbol for the namespace.  */
+
+  add_partial_symbol (pdi, cu);
+
   /* Now scan partial symbols in that module.  */
 
   if (pdi->has_children)
@@ -13660,6 +13671,10 @@ static void
 read_module (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct die_info *child_die = die->child;
+  struct type *type;
+
+  type = read_type_die (die, cu);
+  new_symbol (die, type, cu);
 
   while (child_die && child_die->tag)
     {
@@ -17690,6 +17705,11 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
 	  list_to_add = &global_symbols;
 	  break;
+	case DW_TAG_module:
+	  SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
+	  SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
+	  list_to_add = &global_symbols;
+	  break;
 	case DW_TAG_common_block:
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
 	  SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index a7e59df..e97a6dd 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1175,7 +1175,12 @@ yylex (void)
     char *tmp = copy_name (yylval.sval);
     struct symbol *sym;
     struct field_of_this_result is_a_field_of_this;
-    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
+    enum domain_enum_tag lookup_domains[] =
+    {
+      STRUCT_DOMAIN,
+      VAR_DOMAIN,
+      MODULE_DOMAIN
+    };
     int i;
     int hextype;
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 7cc6667..cca6a76 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -418,6 +418,10 @@ typedef enum domain_enum_tag
 
   STRUCT_DOMAIN,
 
+  /* MODULE_DOMAIN is used in Fortran to hold module type names.  */
+
+  MODULE_DOMAIN,
+
   /* LABEL_DOMAIN may be used for names of labels (for gotos).  */
 
   LABEL_DOMAIN,
diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
index 6a2b87d..8f5f1b7 100644
--- a/gdb/testsuite/gdb.fortran/module.exp
+++ b/gdb/testsuite/gdb.fortran/module.exp
@@ -43,6 +43,13 @@ gdb_breakpoint [gdb_get_line_number "i-is-2"]
 gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
 gdb_test "print var_i" " = 2" "print var_i value 2"
 
+gdb_breakpoint [gdb_get_line_number "i-is-3"]
+gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
+# Ensure that the scope is correctly resolved.
+gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
+gdb_test "p mod2" " = 3" "print mod2"
+gdb_test "p mod1" " = 3" "print mod1"
+
 gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
 gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
 gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
@@ -54,7 +61,7 @@ gdb_test "print var_x" " = 30" "print var_x value 30"
 gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
 gdb_test "print var_z" " = 31" "print var_x value 31"
 
-gdb_test "ptype modmany" {No symbol "modmany" in current context.}
+gdb_test "ptype modmany" "type = module modmany"
 
 proc complete {expr list} {
     set cmd "complete p $expr"
@@ -62,8 +69,8 @@ proc complete {expr list} {
     gdb_test $cmd $expect "complete $expr"
 }
 set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
-complete "modm" $modmany_list
-complete "modmany" $modmany_list
+complete "modm" "modmany $modmany_list"
+complete "modmany" "modmany $modmany_list"
 complete "modmany::" $modmany_list
 complete "modmany::var" $modmany_list
 
diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
index ada7262..d10b1fb 100644
--- a/gdb/testsuite/gdb.fortran/module.f90
+++ b/gdb/testsuite/gdb.fortran/module.f90
@@ -23,6 +23,12 @@ module mod2
         integer :: var_i = 2
 end module mod2
 
+module mod3
+        integer :: mod2 = 3
+        integer :: mod1 = 3
+        integer :: var_i = 3
+end module mod3
+
 module modmany
         integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
 end module modmany
@@ -43,6 +49,11 @@ end module moduse
         var_i = var_i                         ! i-is-2
         end
 
+        subroutine sub3
+        USE mod3
+        var_i = var_i                         ! i-is-3
+        END
+
         program module
 
         use modmany, only: var_b, var_d => var_c, var_i
@@ -50,6 +61,7 @@ end module moduse
 
         call sub1
         call sub2
+        call sub3
 
         if (var_b .ne. 11) call abort
         if (var_d .ne. 12) call abort
-- 
1.7.9.5



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types.
  2013-12-12 13:04     ` Keven Boell
@ 2013-12-16 17:10       ` Doug Evans
  0 siblings, 0 replies; 9+ messages in thread
From: Doug Evans @ 2013-12-16 17:10 UTC (permalink / raw)
  To: Keven Boell; +Cc: Keven Boell, gdb-patches, Sanimir Agovic

On Thu, Dec 12, 2013 at 5:04 AM, Keven Boell
<keven.boell@linux.intel.com> wrote:
> Updated patch:
>
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index 567cd00..a7e59df 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -1175,21 +1175,30 @@ yylex (void)
>      char *tmp = copy_name (yylval.sval);
>      struct symbol *sym;
>      struct field_of_this_result is_a_field_of_this;
> +    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
> +    int i;
>      int hextype;
> -
> -    /* Initialize this in case we *don't* use it in this call; that
> -       way we can refer to it unconditionally below.  */
> -    memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
> -
> -    sym = lookup_symbol (tmp, expression_context_block,
> -                        VAR_DOMAIN,
> -                        parse_language->la_language == language_cplus
> -                        ? &is_a_field_of_this : NULL);
> -    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
> +
> +    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
>        {
> -       yylval.tsym.type = SYMBOL_TYPE (sym);
> -       return TYPENAME;
> +       /* Initialize this in case we *don't* use it in this call; that
> +          way we can refer to it unconditionally below.  */
> +       memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
> +
> +       sym = lookup_symbol (tmp, expression_context_block,
> +                            lookup_domains[i],
> +                            parse_language->la_language == language_cplus
> +                            ? &is_a_field_of_this : NULL);
> +       if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
> +         {
> +           yylval.tsym.type = SYMBOL_TYPE (sym);
> +           return TYPENAME;
> +         }
> +
> +       if (sym)
> +         break;
>        }
> +
>      yylval.tsym.type
>        = language_lookup_primitive_type_by_name (parse_language,
>                                                 parse_gdbarch, tmp);
> diff --git a/gdb/testsuite/gdb.fortran/type.f90 b/gdb/testsuite/gdb.fortran/type.f90
> new file mode 100644
> index 0000000..e0c699e
> --- /dev/null
> +++ b/gdb/testsuite/gdb.fortran/type.f90
> @@ -0,0 +1,28 @@
> +! Copyright 2013 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 <http://www.gnu.org/licenses/>.
> +
> +program type
> +  implicit none
> +
> +  type :: t1
> +    integer :: t1_i
> +    real    :: t1_r
> +  end type t1
> +
> +  type (t1) :: t1v
> +
> +  t1v%t1_i = 42
> +  t1v%t1_r = 42.24    ! bp1
> +end program type
> diff --git a/gdb/testsuite/gdb.fortran/whatis_type.exp b/gdb/testsuite/gdb.fortran/whatis_type.exp
> new file mode 100644
> index 0000000..9d6151f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.fortran/whatis_type.exp
> @@ -0,0 +1,48 @@
> +# Copyright 2013 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 <http://www.gnu.org/licenses/>.
> +
> +if { [skip_fortran_tests] } { continue }
> +
> +standard_testfile type.f90
> +
> +if { [prepare_for_testing ${testfile}.exp ${testfile} \
> +                          ${srcfile} {debug f90}] } {
> +    return -1
> +}
> +
> +if ![runto MAIN__] {
> +    fail "run to MAIN__"
> +    return
> +}
> +
> +gdb_breakpoint [gdb_get_line_number "bp1"]
> +gdb_continue_to_breakpoint "bp1"
> +
> +set t1_i "integer\\\(kind=4\\\) :: t1_i"
> +set t1_r "real\\\(kind=4\\\) :: t1_r"
> +
> +gdb_test "whatis t1" \
> +  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
> +  "whatis t1"
> +gdb_test "whatis t1v" \
> +  "type = Type t1\r\n${t1_i}\r\n${t1_r}\r\nEnd Type t1" \
> +  "whatis t1v"
> +
> +gdb_test "ptype t1" \
> +  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
> +  "ptype t1"
> +gdb_test "ptype t1v" \
> +  "type = Type t1\r\n    ${t1_i}\r\n    ${t1_r}\r\nEnd Type t1" \
> +  "ptype t1v"
> --

Looks ok to me.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] fortran: enable ptype/whatis for modules.
  2013-12-12 13:04     ` Keven Boell
@ 2013-12-16 17:14       ` Doug Evans
  0 siblings, 0 replies; 9+ messages in thread
From: Doug Evans @ 2013-12-16 17:14 UTC (permalink / raw)
  To: Keven Boell; +Cc: Keven Boell, gdb-patches, Sanimir Agovic

On Thu, Dec 12, 2013 at 5:04 AM, Keven Boell
<keven.boell@linux.intel.com> wrote:
> The updated patch:
>
> diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
> index 36134c0..e666c3e 100644
> --- a/gdb/cp-namespace.c
> +++ b/gdb/cp-namespace.c
> @@ -784,6 +784,10 @@ cp_lookup_nested_symbol (struct type *parent_type,
>      case TYPE_CODE_STRUCT:
>      case TYPE_CODE_NAMESPACE:
>      case TYPE_CODE_UNION:
> +    /* NOTE: Handle modules here as well, because Fortran is re-using the C++
> +       specific code to lookup nested symbols in modules, by calling the
> +       function pointer la_lookup_symbol_nonlocal, which ends up here.  */
> +    case TYPE_CODE_MODULE:
>        {
>         /* NOTE: carlton/2003-11-10: We don't treat C++ class members
>            of classes like, say, data or function members.  Instead,
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 1c7dfc5..8d07f86 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -6801,6 +6801,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
>                            &objfile->global_psymbols,
>                            0, (CORE_ADDR) 0, cu->language, objfile);
>        break;
> +    case DW_TAG_module:
> +      add_psymbol_to_list (actual_name, strlen (actual_name),
> +                          built_actual_name != NULL,
> +                          MODULE_DOMAIN, LOC_TYPEDEF,
> +                          &objfile->global_psymbols,
> +                          0, (CORE_ADDR) 0, cu->language, objfile);
> +      break;
>      case DW_TAG_class_type:
>      case DW_TAG_interface_type:
>      case DW_TAG_structure_type:
> @@ -6871,6 +6878,10 @@ static void
>  add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
>                     CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
>  {
> +  /* Add a symbol for the namespace.  */
> +
> +  add_partial_symbol (pdi, cu);
> +
>    /* Now scan partial symbols in that module.  */
>
>    if (pdi->has_children)
> @@ -13660,6 +13671,10 @@ static void
>  read_module (struct die_info *die, struct dwarf2_cu *cu)
>  {
>    struct die_info *child_die = die->child;
> +  struct type *type;
> +
> +  type = read_type_die (die, cu);
> +  new_symbol (die, type, cu);
>
>    while (child_die && child_die->tag)
>      {
> @@ -17690,6 +17705,11 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
>           SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
>           list_to_add = &global_symbols;
>           break;
> +       case DW_TAG_module:
> +         SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
> +         SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
> +         list_to_add = &global_symbols;
> +         break;
>         case DW_TAG_common_block:
>           SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
>           SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index a7e59df..e97a6dd 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -1175,7 +1175,12 @@ yylex (void)
>      char *tmp = copy_name (yylval.sval);
>      struct symbol *sym;
>      struct field_of_this_result is_a_field_of_this;
> -    enum domain_enum_tag lookup_domains[] = {STRUCT_DOMAIN, VAR_DOMAIN};
> +    enum domain_enum_tag lookup_domains[] =
> +    {
> +      STRUCT_DOMAIN,
> +      VAR_DOMAIN,
> +      MODULE_DOMAIN
> +    };
>      int i;
>      int hextype;
>
> diff --git a/gdb/symtab.h b/gdb/symtab.h
> index 7cc6667..cca6a76 100644
> --- a/gdb/symtab.h
> +++ b/gdb/symtab.h
> @@ -418,6 +418,10 @@ typedef enum domain_enum_tag
>
>    STRUCT_DOMAIN,
>
> +  /* MODULE_DOMAIN is used in Fortran to hold module type names.  */
> +
> +  MODULE_DOMAIN,
> +
>    /* LABEL_DOMAIN may be used for names of labels (for gotos).  */
>
>    LABEL_DOMAIN,
> diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
> index 6a2b87d..8f5f1b7 100644
> --- a/gdb/testsuite/gdb.fortran/module.exp
> +++ b/gdb/testsuite/gdb.fortran/module.exp
> @@ -43,6 +43,13 @@ gdb_breakpoint [gdb_get_line_number "i-is-2"]
>  gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
>  gdb_test "print var_i" " = 2" "print var_i value 2"
>
> +gdb_breakpoint [gdb_get_line_number "i-is-3"]
> +gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
> +# Ensure that the scope is correctly resolved.
> +gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
> +gdb_test "p mod2" " = 3" "print mod2"
> +gdb_test "p mod1" " = 3" "print mod1"
> +
>  gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
>  gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
>  gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
> @@ -54,7 +61,7 @@ gdb_test "print var_x" " = 30" "print var_x value 30"
>  gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
>  gdb_test "print var_z" " = 31" "print var_x value 31"
>
> -gdb_test "ptype modmany" {No symbol "modmany" in current context.}
> +gdb_test "ptype modmany" "type = module modmany"
>
>  proc complete {expr list} {
>      set cmd "complete p $expr"
> @@ -62,8 +69,8 @@ proc complete {expr list} {
>      gdb_test $cmd $expect "complete $expr"
>  }
>  set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
> -complete "modm" $modmany_list
> -complete "modmany" $modmany_list
> +complete "modm" "modmany $modmany_list"
> +complete "modmany" "modmany $modmany_list"
>  complete "modmany::" $modmany_list
>  complete "modmany::var" $modmany_list
>
> diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
> index ada7262..d10b1fb 100644
> --- a/gdb/testsuite/gdb.fortran/module.f90
> +++ b/gdb/testsuite/gdb.fortran/module.f90
> @@ -23,6 +23,12 @@ module mod2
>          integer :: var_i = 2
>  end module mod2
>
> +module mod3
> +        integer :: mod2 = 3
> +        integer :: mod1 = 3
> +        integer :: var_i = 3
> +end module mod3
> +
>  module modmany
>          integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
>  end module modmany
> @@ -43,6 +49,11 @@ end module moduse
>          var_i = var_i                         ! i-is-2
>          end
>
> +        subroutine sub3
> +        USE mod3
> +        var_i = var_i                         ! i-is-3
> +        END
> +
>          program module
>
>          use modmany, only: var_b, var_d => var_c, var_i
> @@ -50,6 +61,7 @@ end module moduse
>
>          call sub1
>          call sub2
> +        call sub3
>
>          if (var_b .ne. 11) call abort
>          if (var_d .ne. 12) call abort
> --

Looks ok to me.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-12-16 17:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-11 12:35 [PATCH v2 0/2] enable ptype/whatis for fortran types/modules Keven Boell
2013-12-11 12:35 ` [PATCH v2 2/2] fortran: enable ptype/whatis for modules Keven Boell
2013-12-11 17:07   ` Doug Evans
2013-12-12 13:04     ` Keven Boell
2013-12-16 17:14       ` Doug Evans
2013-12-11 12:35 ` [PATCH v2 1/2] fortran: enable ptype/whatis for user defined types Keven Boell
2013-12-11 16:52   ` Doug Evans
2013-12-12 13:04     ` Keven Boell
2013-12-16 17:10       ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).