Discussion:
Fortran Debug Step odd behavior on continuation lines
(too old to reply)
Tom Wade
2020-08-29 15:07:08 UTC
Permalink
Hi,

I've noticed the following odd behavior when single stepping through a
Fortran program with continuation lines. I've always worked around it,
as it never caused me any real problems, but I finally had the time to
put it down, so that someone might explain what I've been doing wrong
all these years.

Consider the following trivial program, compiled /debug/noopt and
launched with screen mode debugging.

─ SRC: module TEST
-scroll-source───────────────────────────────────────────────
-> 1: Program Test
2:
3: Implicit None
4: Integer i, j
5:
6: i = 0
7: j = 0
8: i = i +
9: & j +
10: & 5
11: Call Exit
12: End

If you STEP (or hit KP0), the Debugger steps through the program line by
line. First step goes to line 6, second to line 7 etc until it gets to
8. At 8, I would expect the Debugger to step to 11, as 9 & 10 are
continuation lines, effectively part of the same statement. Instead it
steps to 9. The really strange thing is the next step jumps back to 8.
The one after that goes to 9, the next one back to 8 again, and the next
one goes to 11 (skipping 9 & 10). The value of i only changes when it
arrives at 11.

Not a real problem, but I guess finally my curiosity got the better of
me. Anyone else seen or can understand this ?

OpenVMS Alpha 8.4
HP Fortran V8.2-104679
HP Fortran 77 V7.6-198 (/old_f77)
(but it's been around for as long as I remember, and that's quite a
while!).

Tom Wade
tom dot wade at tomwade got eu
Dave Froble
2020-08-29 15:26:13 UTC
Permalink
Post by Tom Wade
Hi,
I've noticed the following odd behavior when single stepping through a
Fortran program with continuation lines. I've always worked around it,
as it never caused me any real problems, but I finally had the time to
put it down, so that someone might explain what I've been doing wrong
all these years.
Consider the following trivial program, compiled /debug/noopt and
launched with screen mode debugging.
─ SRC: module TEST
-scroll-source───────────────────────────────────────────────
-> 1: Program Test
3: Implicit None
4: Integer i, j
6: i = 0
7: j = 0
8: i = i +
9: & j +
10: & 5
11: Call Exit
12: End
If you STEP (or hit KP0), the Debugger steps through the program line by
line. First step goes to line 6, second to line 7 etc until it gets to
8. At 8, I would expect the Debugger to step to 11, as 9 & 10 are
continuation lines, effectively part of the same statement. Instead it
steps to 9. The really strange thing is the next step jumps back to 8.
The one after that goes to 9, the next one back to 8 again, and the next
one goes to 11 (skipping 9 & 10). The value of i only changes when it
arrives at 11.
Not a real problem, but I guess finally my curiosity got the better of
me. Anyone else seen or can understand this ?
OpenVMS Alpha 8.4
HP Fortran V8.2-104679
HP Fortran 77 V7.6-198 (/old_f77)
(but it's been around for as long as I remember, and that's quite a
while!).
Tom Wade
tom dot wade at tomwade got eu
At the risk of John getting a good laugh ...

The way I learned it so many years ago is that when a compiler comes
upon a complex operation, it parses it and pushes each step onto a
stack, then pops each off the stack when processing.

So, your line 10 was last onto the stack, so the first popped off, then
line 9, and finally it completes the operation.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: ***@tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
abrsvc
2020-08-29 16:34:08 UTC
Permalink
Post by Dave Froble
Post by Tom Wade
Hi,
I've noticed the following odd behavior when single stepping through a
Fortran program with continuation lines. I've always worked around it,
as it never caused me any real problems, but I finally had the time to
put it down, so that someone might explain what I've been doing wrong
all these years.
Consider the following trivial program, compiled /debug/noopt and
launched with screen mode debugging.
─ SRC: module TEST
-scroll-source───────────────────────────────────────────────
-> 1: Program Test
3: Implicit None
4: Integer i, j
6: i = 0
7: j = 0
8: i = i +
9: & j +
10: & 5
11: Call Exit
12: End
If you STEP (or hit KP0), the Debugger steps through the program line by
line. First step goes to line 6, second to line 7 etc until it gets to
8. At 8, I would expect the Debugger to step to 11, as 9 & 10 are
continuation lines, effectively part of the same statement. Instead it
steps to 9. The really strange thing is the next step jumps back to 8.
The one after that goes to 9, the next one back to 8 again, and the next
one goes to 11 (skipping 9 & 10). The value of i only changes when it
arrives at 11.
Not a real problem, but I guess finally my curiosity got the better of
me. Anyone else seen or can understand this ?
OpenVMS Alpha 8.4
HP Fortran V8.2-104679
HP Fortran 77 V7.6-198 (/old_f77)
(but it's been around for as long as I remember, and that's quite a
while!).
Tom Wade
tom dot wade at tomwade got eu
At the risk of John getting a good laugh ...
The way I learned it so many years ago is that when a compiler comes
upon a complex operation, it parses it and pushes each step onto a
stack, then pops each off the stack when processing.
So, your line 10 was last onto the stack, so the first popped off, then
line 9, and finally it completes the operation.
--
David Froble Tel: 724-529-0450
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
I would compile the source again and request the machine code listing. Look carefully at the code generated as even with no-opt, there will be some folding of instructions "out of order" with the code lines. For example, loading registers with the values for the operation. That may trigger what appears to be random lines when stepping through the code. The debugger will try to tie the actual instruction to the source code line. Here with continuation lines, there are 3 "source" lines associated with the "real" source line which would be all of the continuation lines concatenated together.

I recall seeing this even more when stepping by instruction. The code would appear to bounce all over the place (as expected with Alpha instruction streams).

Dan
Stephen Hoffman
2020-08-29 17:19:04 UTC
Permalink
Post by Tom Wade
Not a real problem, but I guess finally my curiosity got the better of
me. Anyone else seen or can understand this ?
I suspect the compilers and the debugger necessarily conflate file
lines with source lines.

The debugger doesn't even seem to have a good way to show source lines,
from what can be inferred from its displays.

Integrating LLVM directly into the tooling can avoid some of this "fun"
as that can provide more code context, but that's a ways into the
future.
--
Pure Personal Opinion | HoffmanLabs LLC
Andrew Commons
2020-08-30 01:48:53 UTC
Permalink
On Sunday, August 30, 2020 at 12:37:12 AM UTC+9:30, Tom Wade wrote:

Maybe switch to INSTRUCTION display while you single step.

In VAX MACRO lines 8 and 9 could be a single ADDL instruction so inserting a breakpoint/trap in the middle is a tad difficult.

I suspect the debugger is trying to reconcile this sort of problem with a literal interpretation of source code line.
Loading...