Topic: A Debugging Question.

I am trying to debug an old (but still used) Fortran 77 fixed format program.  When I click "Step Into" (or press F9), the pointer jumps to the "Program Sites" (Sites is the name of the program) record.  I then have to click "Step Into" again to return to the next line in the program.  I don't believe this happens when I'm debugging free-format programs.  Is this typical of fixed-format or ????

Any help appreciated.

Don

Re: A Debugging Question.

Don,

There can be some oddities surrounding the startup code of Fortran programs, generally speaking.  I see this behavior on occasion with free-format Fortran as well.  When the debugger starts up, it pauses at the "main" program unit. Usually the underlying debugger correctly flags your program unit as the proper start point.  However, under some circumstances, it mistakes a procedure called "main" that you didn't write; it's actually part of the Fortran startup code (and is referring to the C "main" procedure in the underlying Fortran startup code).  It will still report the proper file, so you end up with it occasionally doing what you describe as the debugger actually enters the proper Fortran procedure.

It's an odd behavior that I've looked into before.  I obviously don't have a good fix or a handle on the circumstances that lead to the behavior.

Jeff Armstrong
Approximatrix, LLC

Re: A Debugging Question.

I've noticed it only jumps to the top in the main program. The real concern is the amount of time it takes to process a single step.  It can take up to 30 seconds per step.

On an other matter now.  This same program is now generating a SIGSEGV segmentation fault that I didn't get before.  I looked for a solution and the only one I found was a compiler option of "-heap-arrays", but it doesn't seem to be a gfortran compile option.  Do you have any suggestions?

Re: A Debugging Question.

Do you have "Enable Runtime Diagnostics" turned on?

It is best to disable this when you are debugging as it can cause the current line to "Jump about".

The SIGSEGV error is probably a bug in your coding. Try using the option -fbacktrace and debugging -g  to find out where it is occurring.

-heap-arrays is an Intel (ifort) compiler option for putting automatic arrays on the heap instead of the stack. Gfortran doesn't have this option because it always puts automatic arrays on the heap (not the stack).

See:

http://jblevins.org/log/segfault

--
David

Re: A Debugging Question.

Don Hazlewood wrote:

I've noticed it only jumps to the top in the main program. The real concern is the amount of time it takes to process a single step.  It can take up to 30 seconds per step.

Don,

Do you happen to have a large number of local variables?  Asking the debugger to look for changes can take a long time if there are an enormous number of variables.  I have programs, though, that have on the order of 100 or so in a single unit, and they don't exhibit this behavior.  It could be made worse, though, if you've expanded a lot of arrays (because each array member will need to be updated.

I can't really comment on why it would take so long without actually trying out a problematic code sample.  There is a reasonable chance there is a bug that is causing the delay.

Jeff Armstrong
Approximatrix, LLC

Re: A Debugging Question.

Don Hazlewood wrote:

This same program is now generating a SIGSEGV segmentation fault that I didn't get before.  I looked for a solution and the only one I found was a compiler option of "-heap-arrays", but it doesn't seem to be a gfortran compile option.  Do you have any suggestions?

Don,  I too have been (and still am) plagued with a SIGSEGV error when using the debugger, which I get ONLY from inside the debugger.

I am fairly sure it is a DBG fault, so not something that Jeff can solve.  It has brought my project development to a complete standstill while I wait in hope for a solution in a DBG UPDATE.

I've 'touched' the topic thread on this, to bring it to the top of the current list (just below this topic) in case you want to have a quick look.  See especially page 2 of the thread.
---
John

Re: A Debugging Question.

Hi David, John and Jeff.

Jeff, there is an enormous number of variables, both local and Common. And the slow down only occurs in the main program - subroutines zip right on through.

John, I feel your pain.....  I haven't tried to run it outside the debugger -- I'll give that a try and see what happens there.

David, I just compiled with the -backtrace option.  Will try running it in a bit.

I also want to express how much I appreciate all the support you guys give - not just to me but to everyone with a problem.  Thanks!!!

Re: A Debugging Question.

Don,

The development version now contains some speed improvements to the debugger's processing of variable updates.  It should be substantially faster in most cases.  On my test program, I notice a 2x to 5x speedup (estimated, of course) stepping in a relatively complicated and variable-rich procedure.  Your speed improvement could theoretically be significantly better after the program starts up and the variables panel is populated.

Jeff Armstrong
Approximatrix, LLC

Re: A Debugging Question.

Tried running the program outside the debugger and still get the SIGSEGV error.  I can track it right up to a statement "ierr = 0" and that's when I get the error.  Unfortunately, there is no way to go around this point in the program, so I'm stuck.  If anyone has a brilliant idea (or even just an idea), I'd sure be grateful to hear it.

Don

10 (edited by JohnWasilewski 2015-01-22 22:30:56)

Re: A Debugging Question.

SIGSEGV fault is a program development killer.
I long to see the back of it.

Just some random thoughts.  I'm sure you'll have considered far more than these already . . ...

Are the error conditions which might arise capable of being found by explicit tests for each one (such as non-existent files, files already in use, and so forth)?  You could then omit the "ierr=0" part of the offending statement.

Alternatively, is there anything strange lurking at the end of any previous lines, possibly off-screen to the right, which might be triggering the trip, quite misleadingly, on the "ierr=0" line?
---
J.

Re: A Debugging Question.

I've deleted, re-entered, re-named, moved its location, all to no avail.  I renamed it "kerr = 0" thinking that "ierr" might be a system reserved word - didn't help.  So I moved where it was being set - still didn't help.  The variable is brought into the program as an argument to a subroutine, with the intent of OUT.  Changed it to InOut - no help.

I guess what's bothering me the most is the fact that this program compiled and ran under the old Compaq Fortran.  That also brings up another question -- is there an equivalent to Compaq's DFLIB and KERNAL32 packages? They had some good file handling routines.

Re: A Debugging Question.

Don,

If you're comfortable with doing so, you can email the source code to me, and I can have a look/try to run it on my end.  I can't explain why you're seeing the SIGSEGV from your description.

With respect to DFLIB and KERNEL32, both are unlikely to make an appearance in Simply Fortran.  DFLIB is pretty big, there would at least be a chance to port it.  However, it is rather unlikely, especially because many of its more commonly used features are superseded by Fortran 2003 and 2008 intrinsics.  KERNEL32 was part of Digital's/Compaq's/HP's port of the Windows API directly to Fortran.  It is only one of a set of libraries (along with USER32, GDI32, COMCTL32...) that are part of the port.  Approximatrix has no plans to provide access to the Windows API from Fortran directly, especially because it gets a bit messy if you try to do so in a standards-compliant manner (Digital/Compaq/HP took some liberties with how Windows pointers are sized and assumed 32-bit, for example).

Jeff Armstrong
Approximatrix, LLC

Re: A Debugging Question.

And John, I haven't forgotten about your SIGSEGV issue.  I'll give it another go tomorrow morning looking for a way around it.

Jeff Armstrong
Approximatrix, LLC

14 (edited by JohnWasilewski 2015-01-22 23:26:38)

Re: A Debugging Question.

Don,

Have you tried initialising variables right at the start of the program - even those which should not need initialising yet?
I don't know if doing so would have this effect but my thought is that, as SIGSEGV faults appear to be something to do with accidentally trying to use memory which the executable does not own, this might force the compiler to allocate memory to variables from the very outset?
---
John

Re: A Debugging Question.

Thanks for the offer, Jeff.  I have a couple more things I think may be causing it.  I'm finding that arrays passed to subroutines are not transferring correctly (which means I've goofed somewhere in transporting from Compaq to Simply Fortran).  I'll get back to you as soon as I find out what's happening.

Don

Re: A Debugging Question.

Okay, I'm pretty sure the problem centers around the way Compac and gFortran handle structures. I re-wrote a part of the program to make it compatible with gFortran and it got rid of the SIGSEGV error.

And on to another question: (quit sighing, Jeff)  In Fortran IV, you could put a backslash (\) at the end of a format statement to tell the printer not to issue a carriage return/line feed.  In other words, don't advance the printer.  gFortran doesn't like this.  I was told that you could enter 'advance=no' in place of the backslash to kill the CR/LF.  Unfortunately, all it does is print "advance=no" followed by a CR/LF.  Is there an equivalent to the backslash? 

Also, is there a good, general purpose Programmer's Guide that covers the basic fortran commands - not compiler options, etc. that would be helpful to me? 

Don

Re: A Debugging Question.

ADVANCE="NO" works for me, Don.
Have you checked the exact syntax.

Re: A Debugging Question.

Thanks, John.  No - I haven't been able to find just a basic programmer's guide to gfortran.  Everything I look at seem to be oriented to command line options, etc.  If you know where to find one, I'd really appreciate it.

Re: A Debugging Question.

Okay, I tried ADVANCE="NO" as follows:

   85 Format (11x,i4,1x,2f8.0,f7.2,f8.3,f11.2,f10.2,f8.3,ADVANCE="NO")

and I get Error: Positive width required in format specifier D at (1).   Any suggestions????

Don

20 (edited by davidb 2015-01-24 11:02:48)

Re: A Debugging Question.

The use of Advance goes in the read or write statement, not the format statement

Example of non-advancing IO:

character(len=20) :: name
write(*, 10, advance='no') 'Enter your name: '
read(*, 10) name
write(*, 10, advance='no') 'Hello '
write(*, 10, advance= 'no') name
write(*, 10) ", how are you?"
10 Format (A)
--
David

21 (edited by davidb 2015-01-24 11:11:35)

Re: A Debugging Question.

Don Hazlewood wrote:

If you know where to find one, I'd really appreciate it.

Have a look at books 4, 5, 6 and 8 on this list for books specifically about Fortran 95.

The other books are mostly Fortran 77, which are also worth having for reference.

http://www.linuxlinks.com/article/20140 … Part2.html

--
David

Re: A Debugging Question.

Sorry not to have replied sooner but I'm pleased to see others have given excellent help.
For fortran manuals and references, search the web, not for 'GFortran', because that will just find references on the compiler extensions, compile-time switches and options etc, but for 'Fortran 95', 'Fortran 98', 'Fortran 2003', etc, where you'll find Fortran language references.
---
John

Re: A Debugging Question.

Thanks to David and John.  Really helpful information that has my program up and running!  Also, those books were just what I was looking for.  Thanks, again

Don