gdb can view source files of programs written in C, but not those of F77 programs. Test: write helloworld.f, compile ("g77 -g ...") and try to view source in gdb. It works for helloworld.c but not the fortran version. gdb man page says "Fortran support will be added when a GNU Fortran compiler is ready." ... but I have a GNU Fortran compiler - g77! Versions installed are: egcs-1.1.2-12 egcs-c++-1.1.2-12 egcs-g77-1.1.2-12 gdb-4.17.0.11-6 xxgdb-1.12-10
This is an xxgdb bug; I had no trouble seeing the source in plain GDB but I was able to reproduce the problem by "xxgdb a.out" (with C it starts up with the source showing; with FORTRAN it says "No source file"). Here is the hello world program I used for the benefit of the FORTRAN-impaired: WRITE (*, FMT=9000) 1.5 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5)) END
At the time, g77 wasn't a GNU compiler - egcs was not a GNU project. Anyway, it doesn't seem to work now.
Still a problem...
Created attachment 20202 [details] Simple FORTRAN example file, for those unfamiliar with the language
(This bug isn't considered a xxgdb bug now, but a gdb bug) This is with a GDB snapshot from 2001-06-01: [teg@halden teg]$ cat hello.f PROGRAM hello print *,"Hello, world!" END [teg@halden teg]$ g77 -g hello.f -o hello [teg@halden teg]$ gdb hello GNU gdb Red Hat Linux 7.x (5.0rh-10) Copyright 2001 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 "i386-redhat-linux"... (gdb) list 1 init.c: No such file or directory. in init.c (gdb) b MAIN__ Breakpoint 1 at 0x8048e96: file hello.f, line 3. (gdb) l 1 in init.c (gdb) r Starting program: /home/devel/teg/hello Breakpoint 1, MAIN__ () at hello.f:3 3 print *,"Hello, world!" Current language: auto; currently fortran (gdb) l 1 PROGRAM hello 2 3 print *,"Hello, world!" 4 5 END (gdb) The program is running. Exit anyway? (y or n) y [teg@halden teg]$ If you know to break at MAIN__ it works, but "list" should work without having to do that.
Still a problem with gdb 5.1
The same problem can be reproduced with a C version of the Hello World program, or any C program for that matter. I have not tried a similar approach to setting the breakpoint but I agree with the above comment. This bug is a nucance especially for newbies (who'll think they are doing something wrong).
No, this doesn't happen with C programs. It's a problem specific to FORTRAN 77. Remember to build with "-g".
(just tested with gdb 5.2 - still no FORTRAN love).
Still a problem. More analysis: GDB doesn't know about the various languages' conventions for naming the main program. MAIN__ in fortran, main in C, etc. Gdb has a mechanism to figure out the name of main from STABS debug info. Such debug info has an N_MAIN directive that has value equal to the name of main. Once gdb knows the name of main, it can also figure out what the list command should default to displaying. (look at set_main_name()) For Dwarf2/3, the spec says: "If the semantics of the language of the compilation unit containing the subroutine entry distinguishes between ordinary subroutines and subroutines that can serve as the ``main program,'' that is, subroutines that cannot be called directly following the ordinary calling conventions, then the debugging information entry for such a subroutine may have a calling convention attribute whose value is the constant DW_CC_program. The DW_CC_program value is intended to support Fortran main programs. It is not intended as a way of finding the entry address for the program." however as of gcc-3.2 such directive is not emitted. I filed a PR in the FSF gnats database. The PR number is: gdb/822
Trivia fun-fact: this is one of _two_ remaining four-digit bugs (not counting bugzilla-bugs.) Is it still an issue in FC5? A quick web searched turned up a message with the phrase "The problems stated in GDB PR 822, GCC 10220 are all gone."
Red Hat Linux is no longer supported by Red Hat, Inc. If you are still running Red Hat Linux, you are strongly advised to upgrade to a current Fedora Core release or Red Hat Enterprise Linux or comparable. Some information on which option may be right for you is available at http://www.redhat.com/rhel/migrate/redhatlinux/. Red Hat apologizes that these issues have not been resolved yet. We do want to make sure that no important bugs slip through the cracks. Please check if this issue is still present in a current Fedora Core release. If so, please change the product and version to match, and check the box indicating that the requested information has been provided. Note that any bug still open against Red Hat Linux on will be closed as 'CANTFIX' on September 30, 2006. Thanks again for your help.
Red Hat Linux is no longer supported by Red Hat, Inc. If you are still running Red Hat Linux, you are strongly advised to upgrade to a current Fedora Core release or Red Hat Enterprise Linux or comparable. Some information on which option may be right for you is available at http://www.redhat.com/rhel/migrate/redhatlinux/. Closing as CANTFIX.