g77/gdb and complex numbers.

craig@jcb-sc.com craig@jcb-sc.com
Sat Jul 31 23:33:00 GMT 1999


[bug-gdb: In case this hasn't already been reported, gdb 4.18 doesn't
print Fortran complex numbers correctly, as shown below.  Another rare
case of a g77/gdb problem that seems to be a gdb problem (most of them
are g77 problems, or at least mostly so).]

>	Yesterday, I posted to comp.lang.fortran a query about how the
>g77/gdb duo treat complex numbers. Basically, I cannot inspect complex
>number arrays (or single complex variables). Also, in this sort of test
>programs, I cannot redirect my output to the console. print* -statements
>print fine on gdb, but when executed from the pront, I just get a clean
>prompt again. This is the test program:

>(gdb) p carr
>$1 = (Invalid F77 type code 3 in symbol table.
>(gdb) p carr(1)
>$2 = Invalid F77 type code 3 in symbol table.

I believe those diagnostics are due to the g77 option `-femulate-complex'
being the default in EGCS versions 1.0 and 1.1.

In the soon-to-be-released EGCS 1.2, which has been renamed GCC 2.95,
`-fno-emulate-complex' is now the default, as we believe the remaining
back-end bugs affecting "native" complex types have been fixed.

The good news is, this should cause gdb to recognize COMPLEX numbers.

The bad news is, it seems gdb doesn't print them correctly -- it prints
the real value twice, instead of the real value then the imaginary value.

Enclosed below is a gdb session that shows this.

>	Also, why with this short program, and running it in the console, I
>get no output whatsoever?

I don't know what "running it in the console" means in this context --
it works fine for me, running it from my shell (bash), on my Redhat Linux
5.2 system.

        tq vm, (burley)


Current directory is ~/gnu/play/
GNU gdb 4.18
Copyright 1998 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-linux-gnu"...
(gdb) break 18
Breakpoint 1 at 0x804c074: file ../../../../egcs-19990629/libf2c/libF77/main.c, line 18.
(gdb) delete 1
(gdb) break complex.f:18
Breakpoint 2 at 0x8048d50: file complex.f, line 18.
(gdb) r
Starting program: /home3/craig/gnu/play/a.out 

Breakpoint 2, MAIN__ () at complex.f:28
Current language:  auto; currently fortran
(gdb) c
Continuing.
 Press a key

Program received signal SIGINT, Interrupt.
0x400926f4 in read () from /lib/libc.so.6
(gdb) b complex.f:39
Breakpoint 3 at 0x8048eff: file complex.f, line 39.
(gdb) c
Continuing.
k
 Values of carr
 Complex Value   Real Part   Imaginary Part
0.0000 9.0000   .0000E+00       0.9000E+01
1.0000 8.0000   .1000E+01       0.8000E+01
2.0000 7.0000   .2000E+01       0.7000E+01
3.0000 6.0000   .3000E+01       0.6000E+01
4.0000 5.0000   .4000E+01       0.5000E+01
5.0000 4.0000   .5000E+01       0.4000E+01
6.0000 3.0000   .6000E+01       0.3000E+01
7.0000 2.0000   .7000E+01       0.2000E+01
8.0000 1.0000   .8000E+01       0.1000E+01
9.0000 0.0000   .9000E+01       0.0000E+00

Breakpoint 3, MAIN__ () at complex.f:39
(gdb) p carr
$1 = ((0,0), (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9))
(gdb) p drpart
$2 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
(gdb) p dimag
$3 = (9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
(gdb) set lang c
Warning: the current language does not match this frame.
(gdb) p carr
$4 = {Invalid C/C++ type code 20 in symbol table.
(gdb) set lang default
Unknown language `default'.
(gdb) set lang
The currently understood settings are:

local or auto    Automatic setting based on source file
c                Use the C language
c++              Use the C++ language
asm              Use the Asm language
chill            Use the Chill language
fortran          Use the Fortran language
java             Use the Java language
modula-2         Use the Modula-2 language
scheme           Use the Scheme language
(gdb) set lang auto
(gdb) p carr
$5 = ((0,0), (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9))
(gdb) p carr(1)
$6 = (0,0)
(gdb) p imag(carr(1))
No symbol "imag" in current context.
(gdb) p aimag(carr(1))
No symbol "aimag" in current context.
(gdb) set lang c
(gdb) p &carr[0]
$7 = (complex *) 0xbffffc58
(gdb) p *$
$8 = Invalid C/C++ type code 20 in symbol table.
(gdb) p (float *) $7
$9 = (float *) 0xbffffc58
(gdb) p $9[0]
$10 = 0
(gdb) p $9[1]
$11 = 9
(gdb) p $9[2]
$12 = 1
(gdb) p $9[3]
$13 = 8
(gdb) p $9[4]
$14 = 2
(gdb) p $9[5]
$15 = 7
(gdb) quit
The program is running.  Exit anyway? (y or n) y

Debugger finished



More information about the Gcc-bugs mailing list