Bug 22424 - gdb.lookup_type fails for Fortran
Summary: gdb.lookup_type fails for Fortran
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.0.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-12 15:52 UTC by zed.three
Modified: 2021-02-22 10:34 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Include Fortran veto on symbol_matches_domain (225 bytes, patch)
2020-02-26 13:14 UTC, Simon Braß
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zed.three 2017-11-12 15:52:14 UTC
`gdb.lookup_type` from the Python API doesn't work for Fortran.

In the following Fortran program (compiled with gfortran 7.2.1): 

    program mvce
      implicit none

      type :: my_type
         integer :: my_int
      end type my_type

      type(my_type) :: foo

      foo%my_int = 4
      print*, foo%my_int
    end program mvce

gives:

    (gdb) py gdb.lookup_type(str(gdb.parse_and_eval("foo").type))
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    gdb.error: No type named Type my_type.
    Error while executing Python code.

Possibly related is that `info types` also doesn't work for Fortran, although `info types <type>` does:

    (gdb) info types
    All defined types:

    File ../../../gcc/fortran/libgfortran.h:
    Language not supported.
    (gdb) info types my_type
    All types matching regular expression "my_type":

    File mvce.f90:
    Type my_type;
Comment 1 Christian Biesinger 2019-08-02 00:23:33 UTC
I wonder if this is the same cause as PR21763, in which case this would be an easy fix (add fortan to the switch in symbol_matches_domain)
Comment 2 Simon Braß 2020-02-26 13:14:04 UTC
Created attachment 12325 [details]
Include Fortran veto on symbol_matches_domain

I've bumped into this problem today.

I tried looking up the solution from bug 21763:
In symtab.c's symbol_matches_domain, it seems that symbol_domain and domain do not match (d'uh) for the derived type lookup.

I've then looked up the definition of my derived type in the dwarf output of gfortran, and found that the derived is tagged as DW_TAG_structure_type (would go into STRUCT_DOMAIN), not as DW_TAG_typedef (would go into VAR_DOMAIN), as one could maybe expect?

The information about the type should then be searched in STRUCT_DOMAIN and not in VAR_DOMAIN, or not?

Adding an exception for language_fortran in symtab.c's symbol_matches_domain seems to resolve the problem (however, I did not run the testsuite).
Comment 3 Simon Braß 2021-02-22 10:34:50 UTC
(In reply to Simon Braß from comment #2)
> Created attachment 12325 [details]
> Include Fortran veto on symbol_matches_domain
> 
> I've bumped into this problem today.
> 
> I tried looking up the solution from bug 21763:
> In symtab.c's symbol_matches_domain, it seems that symbol_domain and domain
> do not match (d'uh) for the derived type lookup.
> 
> I've then looked up the definition of my derived type in the dwarf output of
> gfortran, and found that the derived is tagged as DW_TAG_structure_type
> (would go into STRUCT_DOMAIN), not as DW_TAG_typedef (would go into
> VAR_DOMAIN), as one could maybe expect?
> 
> The information about the type should then be searched in STRUCT_DOMAIN and
> not in VAR_DOMAIN, or not?
> 
> Adding an exception for language_fortran in symtab.c's symbol_matches_domain
> seems to resolve the problem (however, I did not run the testsuite).

Is there any progress regarding this bug? E.g. general progress on the Fortran support?