Author Topic: Debugging fortran  (Read 21749 times)

JoachimB

  • Guest
Debugging fortran
« on: May 09, 2006, 09:51:59 pm »
For some obscured reason, I'm working on a project where I'm trying to get an old fortran program to come to live again. Now I'm using codeblocks and the GCC (G77). The program actually runs and I can debug it in codeblocks. There is one problem though; The debugger (gdb) knows where in the code in it is and breakpoints works. It also knows the path to the source file but, -and here it comes, the IDE does not point out which line it is on. (Actually, I'm using the IDE to set the breakpoint so that direction is working)

My output looks like below;

Selecting target: Debug
Compiling: done
Adding source dir: C:\Projects\Tiny\fello\
Adding source dir: C:\Projects\Tiny\fello\
Adding file: bin\Debug\fello.exe
Starting debugger: done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 5.2.1
At C:/Projects/Tiny/fello/tiny.f:4   :lol:
 

The small program I used here looks like this

      PROGRAM TINY 
      CHARACTER ODOR*2
      WRITE(UNIT=*,FMT=*)'Hello world'
      WRITE(UNIT=*,FMT=*)'Hello hello'   :P
      READ (UNIT=*,FMT=995) ODOR
      WRITE(UNIT=*,FMT=*)'Good bye'
995 FORMAT(A2)
      END

The compiler output looks like

-------------- Build: Debug in fello ---------------
mingw32-g++.exe -Wall -g  -I- -I. -IC:\MingW\include  -c tiny.f -o obj\Debug\tiny.o
mingw32-g++.exe -LC:\MinGW\lib  -o bin\Debug\fello.exe obj\Debug\tiny.o    ..\..\..\SW_Dev\f2c\libf2c\Libf2c.a
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings
 
The source file is in the same directory as the cbp file and it is a straight wizard generated console application where I only have added the libf2, removed the main.cpp file and finally added the tiny.f file which is recognized as an other file by the Ide. I have manually marked the tiny.f for compiling and linking.

-Any suggestions on how to get the IDE to point out where the program stopped due to the breakpoint? If someone points me in the right direction I might be able to find a solution in the code (Probably I'm saying to much now)

Joachim

Impressive piece of work, Code::Blocks!

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Debugging fortran
« Reply #1 on: May 09, 2006, 10:07:31 pm »
You should enable the debugger's debug log (in debugger options) and paste its output here.
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Debugging fortran
« Reply #2 on: May 09, 2006, 10:14:37 pm »
Hmmm... It works for me (see the screenshot).
I wonder why you compile your program with G++ instead of G77... Did you find:
http://wiki.codeblocks.org/index.php?title=Installing_Fortran_Compiler
With regards, Morten.

[attachment deleted by admin]
« Last Edit: May 09, 2006, 10:17:07 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

JoachimB

  • Guest
Re: Debugging fortran
« Reply #3 on: May 09, 2006, 10:33:05 pm »
I did set "Display debugger´s log and got;

-------------------------------------------
Command-line: c:\dev-cpp\bin\gdb.exe -nx -fullname  -args bin/Debug/fello.exe
Working dir : C:\Projects\Tiny\fello\
> set prompt (gdb)
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) (gdb)
> set confirm off
(gdb)
> set width 0
(gdb)
> set height 0
(gdb)
> set breakpoint pending on
No symbol "breakpoint" in current context.
(gdb)
> set print asm-demangle on
(gdb)
> set new-console on
(gdb)
> set disassembly-flavor intel
(gdb)
> directory C:/Projects/Tiny/fello/
(gdb)
> delete breakpoints
(gdb)
> break tiny.f:4
Breakpoint 1 at 0x40131b: file tiny.f, line 4.
(gdb)
> run
Breakpoint 1, MAIN__ () at tiny.f:4
C:/Projects/Tiny/fello/tiny.f:4:84:beg:0x40131b
Current language:  auto; currently fortran
(gdb)
--------------------------------------------

and

-----------------------------------------------------------------------------
[21:35:58.919]: Initialize EditColorSet .....
[21:35:58.939]: Loading lexer_angelscript.xml
[21:35:59.009]: Loading lexer_batch.xml
[21:35:59.029]: Loading lexer_cg.xml
[21:35:59.560]: Loading lexer_cpp.xml
[21:35:59.630]: Loading lexer_css.xml
[21:35:59.720]: Loading lexer_d.xml
[21:35:59.830]: Loading lexer_diff.xml
[21:35:59.860]: Loading lexer_f77.xml
[21:35:59.910]: Loading lexer_glsl.xml
[21:36:00.060]: Loading lexer_gm.xml
[21:36:00.090]: Loading lexer_hitasm.xml
[21:36:00.131]: Loading lexer_lua.xml
[21:36:00.161]: Loading lexer_masm.xml
[21:36:00.441]: Loading lexer_matlab.xml
[21:36:01.963]: Loading lexer_nsis.xml
[21:36:02.464]: Loading lexer_OgreCompositor.xml
[21:36:02.494]: Loading lexer_OgreMaterial.xml
[21:36:02.514]: Loading lexer_prg.xml
[21:36:02.604]: Loading lexer_python.xml
[21:36:02.995]: Loading lexer_rc.xml
[21:36:03.045]: Loading lexer_xml.xml
[21:36:03.095]: Initialize EditColorSet: done.
[21:36:03.465]: Loading toolbar...
[21:36:03.746]: AStylePlugin: loaded
[21:36:03.786]: Autosave: loaded
[21:36:04.126]: CBProfiler: loaded
[21:36:04.687]: ClassWizard: loaded
[21:36:04.777]: Concurrent threads for pool set to 1
[21:36:04.927]: CodeCompletion: loaded
[21:36:05.088]: CodeStatistics: loaded
[21:36:05.568]: Added compiler "GNU GCC Compiler"
[21:36:05.568]: Added compiler "Microsoft Visual C++ Toolkit 2003"
[21:36:05.568]: Added compiler "Borland C++ Compiler 5.5"
[21:36:05.568]: Added compiler "Digital Mars Compiler"
[21:36:05.568]: Added compiler "OpenWatcom (W32) Compiler"
[21:36:05.568]: Added compiler "Intel C/C++ Compiler"
[21:36:05.568]: Added compiler "SDCC Compiler"
[21:36:05.568]: Added compiler "GNU GDC Compiler"
[21:36:05.568]: Added compiler "Digital Mars D Compiler"
[21:36:05.568]: Added compiler "GNU ARM GCC Compiler"
[21:36:05.578]: Added compiler "f2c"
[21:36:05.578]: Compiler: loaded
[21:36:05.598]: copystrings: loaded
[21:36:06.279]: Debugger: loaded
[21:36:06.700]: FilesExtensionHandler: loaded
[21:36:07.191]: DevPakUpdater: loaded
[21:36:07.211]: DragScroll: loaded
[21:36:07.321]: Source Exporter: loaded
[21:36:07.481]: HelpPlugin: loaded
[21:36:07.671]: cbKeyBinder: loaded
[21:36:08.152]: PluginWizard: loaded
[21:36:08.212]: Wizard: loaded
[21:36:08.693]: ToDoList: loaded
[21:36:08.763]: wxSmith: loaded
[21:36:08.763]: wxSmithMime: loaded
[21:36:08.833]: wxSmithWizard: loaded
[21:36:08.853]: WindowsXPLookNFeel: loaded
[21:36:08.863]: Source code formatter (AStyle) plugin loaded
[21:36:09.654]: Autosave plugin loaded
[21:36:09.654]: Code profiler plugin loaded
[21:36:09.654]: Class wizard plugin loaded
[21:36:11.046]: Code completion plugin loaded
[21:36:11.046]: Code Statistics plugin loaded
[21:36:11.287]: Compiler plugin loaded
[21:36:11.287]: Copy Strings to clipboard plugin loaded
[21:36:11.777]: Debugger plugin loaded
[21:36:11.777]: Files extension handler plugin loaded
[21:36:11.787]: Dev-C++ DevPak updater/installer plugin loaded
[21:36:11.787]: DragScroll plugin loaded
[21:36:11.787]: Source Exporter plugin loaded
[21:36:11.787]: Help plugin plugin loaded
[21:36:11.787]: Keyboard shortcuts plugin loaded
[21:36:11.787]: Plugin wizard plugin loaded
[21:36:12.348]: Project wizard added for 'Console application wizard'
[21:36:12.348]: Generic wizard plugin loaded
[21:36:12.769]: Project wizard added for 'Irrlicht project wizard'
[21:36:12.939]: Project wizard added for 'Ogre project wizard'
[21:36:13.049]: Project wizard added for 'wxWidgets application wizard'
[21:36:13.169]: Project wizard added for 'D application wizard'
[21:36:13.179]: To-Do List plugin loaded
[21:36:14.571]: wxSmith plugin loaded
[21:36:14.571]: wxSmith - MIME plugin plugin loaded
[21:36:14.571]: wxSmith - Project Wizard plugin plugin loaded
[21:36:14.571]: Windows XP Look'n'Feel plugin loaded
[21:36:14.942]: Initializing plugins...
[21:36:14.972]: Running startup script
[21:37:13.266]: Loading project file...
[21:37:13.296]: Parsing project file...
[21:37:13.296]: Loading target Debug
[21:37:13.296]: Loading target Release
[21:37:13.296]: Loading project files...
[21:37:13.296]: 2 files loaded
[21:37:13.296]: Done loading project in 30ms
[21:37:13.296]: Project's base path: C:\Projects\Tiny\fello\
[21:37:13.306]: Project's common toplevel path: C:\Projects\Tiny\fello\
[21:37:13.326]: project data set for C:\Projects\Tiny\fello\tiny.f
[21:37:13.326]: Top Editor: C:\Projects\Tiny\fello\tiny.f
[21:37:13.336]: Add project fello in parsing queue
[21:37:40.976]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:37:40.976]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:37:40.976]: Scanned 0 files for #includes, cache used 1, cache updated 0
[21:37:40.976]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:37:40.976]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:37:40.986]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:37:40.986]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:29.798]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:29.808]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:29.808]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:29.808]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:32.532]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:32.532]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:32.542]: Scanned 0 files for #includes, cache used 0, cache updated 0
[21:40:32.542]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 1, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:10:22.837]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:11.187]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:11.197]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:11.197]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:11.208]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.136]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.457]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.457]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.457]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:24.457]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 1, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:16:31.146]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 1, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 0, cache updated 0
[22:18:21.495]: Scanned 0 files for #includes, cache used 0, cache updated 0
-----------------------------------------------------------------------------

I also right now tried using the g77 compiler according to the advice in the other reply. (Thanks) It did not help though. Still the same. Missing that little arrow

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Debugging fortran
« Reply #4 on: May 09, 2006, 10:55:18 pm »
mandrav: I think he is right. Why it works for me is because I'm usually mixing Fortran and C/C++ programs together using the G2C library. Thus the source is converted into C and than translated. So debugging works for me on a "C" level. If I compile a "pure" (native) Fortran application is doesn't work for me, too... I never tried that before... :oops:
With regards, Morten.

Edit: I guess the important part of JoachimB's output is:
Code
> break tiny.f:4
Breakpoint 1 at 0x40131b: file tiny.f, line 4.
(gdb)
> run
Breakpoint 1, MAIN__ () at tiny.f:4
C:/Projects/Tiny/fello/tiny.f:4:84:beg:0x40131b
Current language:  auto; currently fortran
(gdb)
« Last Edit: May 09, 2006, 10:58:01 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

JoachimB

  • Guest
Re: Debugging fortran
« Reply #5 on: May 09, 2006, 11:07:54 pm »
How do you mean, a mixed fortran / c++ project?
Earlier, I used to use f2c and converted to c files which I made a project of. Then I could debug the c-code of course. But from your screenshot, it looks like you are debugging the fortran code itself. -What does your project look like? After installing G77 according to your wiki page, I have the following build log

-------------- Build: Debug in Fello2 ---------------
g77.exe -Wall -g  -I- -I. -IC:\MingW\include  -c main.f -o obj\Debug\main.o
g77.exe -LC:\MinGW\lib  -o bin\Debug\Fello2.exe obj\Debug\main.o   -lg2c -lstdc++ 
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings



Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Debugging fortran
« Reply #6 on: May 09, 2006, 11:16:10 pm »
How do you mean, a mixed fortran / c++ project?
Nope, you are completely right. I have used my Fortran template and just adjusted the main.f file in it. Thus I did not have a "native" Fortran application for the screenshot. Just forget about that post of mine. Sorry.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Debugging fortran
« Reply #7 on: May 09, 2006, 11:26:52 pm »
> set prompt (gdb)
GNU gdb 5.2.1

Hello,

You should use GDB 6.3 and not 5.2.1.

Best wishes,
Michael

JoachimB

  • Guest
Re: Debugging fortran
« Reply #8 on: May 10, 2006, 12:53:28 am »
Thanks Mikael, I tried but it makes no difference

Command-line: C:\MinGW\bin\gdb.exe -nx -fullname  -args bin/Debug/Fello2.exe
Working dir : C:\Projects\Tiny\Fello2\
> set prompt (gdb)
GNU gdb 6.3  :shock:
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) (gdb)
> set confirm off
(gdb)
> set width 0
(gdb)
> set height 0
(gdb)
> set breakpoint pending on
(gdb)
> set print asm-demangle on
(gdb)
> set new-console on
(gdb)
> set disassembly-flavor intel
(gdb)
> directory C:/Projects/Tiny/Fello2/
(gdb)
> delete breakpoints
(gdb)
> break main.f:4
Breakpoint 1 at 0x40131b: file main.f, line 4.
(gdb)
> run
Breakpoint 1, MAIN__ () at main.f:4
C:/Projects/Tiny/Fello2/main.f:4:84:beg:0x40131b  --It knows right :shock:
Current language:  auto; currently fortran
(gdb)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Debugging fortran
« Reply #9 on: May 10, 2006, 07:52:20 am »
Thanks Mikael, I tried but it makes no difference
It doesn't depend on the debugger's version. I guess it has to do with the parsing of the debugger's output. This is "optimised" for C/C++ code. If you have a hello world C++ application the output looks different:
Code
> break main.cpp:5
Breakpoint 1 at 0x401408: file main.cpp, line 5.
(gdb)
> run
Breakpoint 1, main () at main.cpp:5
C:/DOKUME~1/morten/Desktop/haha/main.cpp:5:38:beg:0x401408
(gdb)
...again in comparision, here is the fortran's output:
Code
> break main.f:4
Breakpoint 2 at 0x40131b: file main.f, line 4.
(gdb)
> run
Breakpoint 2, MAIN__ () at main.f:4
C:/DOKUME~1/morten/Desktop/huhu/main.f:4:81:beg:0x40131b
Current language:  auto; currently fortran
(gdb)
I've had a look at it already but fall asleep yesterday... ;-) Give me some time.
...or I'm sure mandrav knows - he wrote the debugger's parser.
With regards, Morten.
« Last Edit: May 10, 2006, 07:56:12 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Debugging fortran
« Reply #10 on: May 10, 2006, 09:09:35 am »
Quote
Code
At C:/Projects/Tiny/fello/tiny.f:4

This line in the debugger's log, shows that the breakpoint was actually seen by C::B (this is a C::B message). So, if there is no marker for the active line, it has to do with the editor. Either the debugger failed to access the cbEditor* holding the file or the editor's markers are not setup correctly.

Morten,

I don't know fortran neither I have it installed. So I 'm gonna need your help on this.
The problem must be inside DebuggerGDB::SyncEditor() (debuggergdb.cpp). Can you put a breakpoint in there and see what's going on when the breakpoint hits?

Hint of the day: did you know that you can examine previous frames (caller functions) by switching to them (right click on the backtrace and choose "switch")?
« Last Edit: May 10, 2006, 09:11:51 am by mandrav »
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Debugging fortran
« Reply #11 on: May 10, 2006, 09:54:33 am »
So I 'm gonna need your help on this.
...got it: The problem is indeed inside DebuggerGDB::SyncEditor. The issue lies in the following lines of code:
Code
    FileType ft = FileTypeOf(filename);
    if (ft == ftOther)
        return; // don't try to open unknown files
Since for a fortran (*.f) file type the "if" statement is true, DebuggerGDB::SyncEditor just returns and nothing happens.
I hope you have an idea what to do. I'm not sure whether it makes sense just to remove that "if" statement? ...or should we add another file type "ftFortran"?
With regards, Morten.
« Last Edit: May 10, 2006, 09:56:18 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Debugging fortran
« Reply #12 on: May 10, 2006, 10:03:15 am »
should we add another file type "ftFortran"?
...forget about that. I think just adding another FileFilter and modifying FileTypeOf() to include e.g. a new FileFilters::F_EXT should work I guess... Should I give it a try and propose a patch if that works?
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Debugging fortran
« Reply #13 on: May 10, 2006, 10:04:20 am »
Quote
should we add another file type "ftFortran"?

This sounds better. It will also solve the "manually check compile/link" when adding fortran files to the project.
I 'm on it...
Be patient!
This bug will be fixed soon...

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Debugging fortran
« Reply #14 on: May 10, 2006, 10:12:44 am »
Can you try this patch and see if it solves the problem?

[attachment deleted by admin]
Be patient!
This bug will be fixed soon...