I am debugging a Fortran program with DDT, but the value of an allocatable character variable (character(len = :), allocatable :: s) appears to be empty until it is passed into a subroutine. Is there a way to show the value in DDT?
Hi,Is it possible for you to share a little code snippet here of the declaration and subroutine call?
If I run the following code in DDT, on line 16 the variable x(i)%s is an empty string, but on line 26 the variable 's' has the expected value.
type :: str_t character(:), allocatable :: s end type str_t
integer :: i type(str_t) :: x(2)
x(1)%s = 'item1' x(2)%s = 'another_item'
do i = 1, size(x) print *, str_len(x(i)%s) end do
function str_len(s) result(rv)
character(*), intent(in) :: s integer :: rv
rv = len(s)
end function str_len
end program try_string
I've tried this with both Intel and gfortran compilers.
Hi John,Apologies for the delayed response. I was able to recreate the issue in DDT and tried using both gdb 8 and gdb 10 both of which confirmed the issue. This has more to do with using derived types in fortran which DDT sometimes fails to monitor. A ticket has now been raised with the development team and I shall keep you posted on the quick progress ahead.Thank You for your patience.Suyash
Thank you for submitting to the development team. It will be very helpful if they can solve the problem.
Development team has successfully identified the root cause being associated with GDB patch-set and some planning is ongoing on the possible fixes. At this point, I can not commit a timeline or the vehicle for the fix, but I should be back with some news within some time again.
Thank You for your patience!
Hi John,We have looked into the root cause and it turns out that, for derived types in fortran, the deferred length string property is unavailable and instead there is another particular non-standard value available i.e. _in_derived_type_length. This value can be cast on a character pointer - char* - and accessed indirectly that way at-least when using gcc. (Image attached)
For standard data types in fortran, DW_AT_string_length value is available in general for gcc compilers but unfortunately not for the intel ones. So going ahead if gcc(gfortran) is your primary compiler of choice, there is a clear fix available ahead but not in case of an Intel compiler, which doesn't have the standard length value as mentioned above.Let me know if you're ok with this.
Thank you for the update. It's good to know there is a workaround for gfortran. Unfortunately, I am mainly using the Intel compiler. In the Intel implementation, the derived type seems to hold a pointer to a null terminated string. Is there a way to view that string using casting?
Hi John,Unfortunately for Intel the DW_AT_string_length field doesn't even exist which can only happen when Intel provides the DWARF information which would be a decision of the DWARF committee. Until then it will not be possible to useany kind of workaround to get the string.Sorry about that.RegardsSuyash