Bug 29937 - Stepping Fortran(77) code always jumps back to subroutine header
Summary: Stepping Fortran(77) code always jumps back to subroutine header
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.2
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-23 12:36 UTC by André Malcher
Modified: 2022-12-23 16:01 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description André Malcher 2022-12-23 12:36:18 UTC
I have a rather large code base (proprietary) including F77, C and C++ code.
The F77 parts are compiled with gfortran 11.2.0.

Compiling with debugging symbols and running the application with gdb works fine so far, but for the Fortran part there is the following annoyance:

For every `next` step in gdb, the debugger jumps to the corresponding subroutine header and I need to enter `next` again to go the the actual next line/statement. Consider the following snippet from a gdb session:

```
843	      DELTA = TIME - TOLD
(gdb) n
97	      SUBROUTINE THE_SUBROUTINE_HEADER
(gdb) n
844	      DELOLD(1) = DELTA
(gdb) n
845	      CALL COMCOF
(gdb) n
97	      SUBROUTINE THE_SUBROUTINE_HEADER
(gdb) n
854	      IF (ITL5 .NE. 0 .AND.
(gdb) n
97	      SUBROUTINE THE_SUBROUTINE_HEADER
(gdb) n
854	      IF (ITL5 .NE. 0 .AND.
```

I hope the point is clear. While I just want to step line by line through the code, I always have a superfluous step to `SUBROUTINE THE_SUBROUTINE_HEADER`, as also evident when looking at the line numbers. 

A few remarks:

* Interestingly, for logical operators, it looks like for every operand I have these additional calls (i.e. if I have something like `IF (A .AND. B .AND. C)`, gdb will jump to the subroutine header three times).

* The problem doesn't show up with the `advance` command, i.e. if I type `advance 900` to advance to line 900 in the example above, gdb will happily fast forward to the given location.

* FWIW, this also happens when I run the debugger from an IDE (that is, using GDB/MI)

* The C and C++ code is not affected, there gdb works like expected (in the same session).

* A related question was posted on StackOverflow, but no replies have been posted so far: https://stackoverflow.com/questions/23744141/ddd-execution-line-jumps-to-subroutine-top-continuation-line-fortran-77

Unfortunately I am not able to reproduce this bug in a small test program. 

Last but not least, things I have tried in the original program:
* Try with gdb 10.1 and 11.1 (the latter has its own set of problems, e.g. stepping takes ages to complete)
* Delete/remove everything from my ~/.gdbinit
* remove all flags except for `-g -O0`
* try with `-g3`
but to no avail.

Let me know in case you need further information or want me to test something, I'll be happy to help.
Comment 1 Tom Tromey 2022-12-23 16:01:33 UTC
> For every `next` step in gdb, the debugger jumps to the corresponding subroutine
> header and I need to enter `next` again to go the the actual next line/statement.

Normally this kind of thing turns out to be a problem in the debuginfo,
and not in gdb.

Sometimes you can see this by using "disassemble/s" on the
function in question.  Otherwise, where I would normally start is
by examining the line table with "readelf -wL".