PDA

View Full Version : gfortran and gdb problem



buttari
January 31st, 2008, 04:53 PM
Hi all,
I have a problem in using GDB on code generated by gfortran under Ubuntu Gutsy.
I compile a simple "hello world" program with -g and then run gdb on the resulting executable.
Now, if, in the gdb prompt I type "l" I get the correct listing for the program code:



1 program hello
2
3 write(*,*) 'hello world'
4 end program


At this point, this is what happens:



(gdb) break main
Breakpoint 1 at 0x804869e
(gdb) r
Starting program: /home/abuttari/Numerical/Junk/a.out

Breakpoint 1, 0x0804869e in main ()
(gdb) n
Single stepping until exit from function main,
which has no line number information.
hello world
0xb7d06050 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6


The same procedure on an executable generated by gcc from C code works perfect.
I have this same problem on another system running ubuntu gusty. I tried gfortran-4.1 and 4.2, I also recompiled GDB 6.7 myself (gutsy has 6.6).

Has anybody here had the same problem? and maybe also knows how to solve it?
If not I'm prepared to submit a bug in launchpad.

Thanks

alfredo

rufius
January 31st, 2008, 05:16 PM
I just tested this on my laptop running Gutsy.

Could not reproduce the error. Are you running on x86_64 or x86?

Output as follows:

program


program hello

write(*,*) 'hello world'
end program


console output


zbrown[~]$ gfortran -g test.f
zbrown[~]$ gdb a.out
GNU gdb 6.6-debian
Copyright (C) 2006 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 "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) r
Starting program: /home/zbrown/a.out
hello world

Program exited normally.
(gdb)


Hope that helps :)

buttari
January 31st, 2008, 05:27 PM
I just tested this on my laptop running Gutsy.

Could not reproduce the error. Are you running on x86_64 or x86?

Output as follows:

program


program hello

write(*,*) 'hello world'
end program


console output


zbrown[~]$ gfortran -g test.f
zbrown[~]$ gdb a.out
GNU gdb 6.6-debian
Copyright (C) 2006 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 "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) r
Starting program: /home/zbrown/a.out
hello world

Program exited normally.
(gdb)


Hope that helps :)

Rufius,
thanks for the quick reply. I am running on x86. However what you did is not the same sequence of steps I did. Try set a breakpoint in main, then run, and then next please. Here it is the sequence of gdb commands


(gdb) break main
(gdb) r
(gdb) n

What you did (i.e., simply running) works fine for me as well.
Thanks for the help

PS
if you are running on x86 you can maybe send me you executable...

alfredo

rufius
February 1st, 2008, 04:02 PM
Hmmm it appears that is a bug. Though I'm not sure if its Ubuntu specific or gfortran's issue. You might check around gfortran's and gdb's bug trackers for things like that.

Interesting. My mistake :)

buttari
February 1st, 2008, 04:05 PM
Hmmm it appears that is a bug. Though I'm not sure if its Ubuntu specific or gfortran's issue. You might check around gfortran's and gdb's bug trackers for things like that.

Interesting. My mistake :)

Rufius,
I found the same thing on many other systems (including fedora and debian with many combinations of gfortran and gdb versions).
if the breakpoint is set like this


(gdb) break hello.f90:2

then everything works.
Thanks

Alfredo

rufius
February 4th, 2008, 04:23 PM
Actually that makes sense... seeing as there was never a declaration of anything named "main" in those fortran programs unlike the C programs.

Its not a bug, its a mistake on yours & my part.

That makes more sense :).

pallukucchu
March 22nd, 2010, 09:16 PM
Fortran Program

hello_world.f

program hello_world
write(*,*) 'Hello World!'
end program

Terminal command:

gfortran hello_world.f

gfortran hello_world.f -o hello_world_out.txt

The output file doesnt show the any readable text.

Need suggestions.

pallukucchu
March 22nd, 2010, 09:19 PM
Problem Solved

gfortran hello_world.f -o hello
./hello

Cool!