Hi, people.
I think I found a bug in gdb, and want to know if it is a known bug
and if there is any patch for it.
The version of my gdb is:
GNU gdb 4.17
Copyright 1998 Free Software Foundation, Inc.
<skip>
This GDB was configured as "sparc-sun-solaris2.5.1".
Following is the bug situation:
The language is C.
Let 'a' is a variable of which the type is 'foo_type'.
'foo_type' is a name of type defined by following typedef statement.
> typedef double footype;
In gdb, when you print the value of 'a' itself, the result is
correctly shown as double floating point value.
But once 'a' is refered in an arithmetic formula, the value of 'a' is
not evaluated correctly. It is always evaluated as an integer.
Let me show you an example.
> :::::::::::::::::::: main.c start
> #include <stdio.h>
> #include <stdlib.h>
>
> typedef double DOUBLE64;
> typedef float FLOAT32;
>
> int
> main()
> {
> DOUBLE64 a;
> double b;
> FLOAT32 c;
> float d;
>
> a = 1.1;
> b = 2.2;
> c = 3.3;
> d = 4.4;
>
> /* break here */
> printf("%g %g %g %g\n", a, b, c, d);
>
> exit(0);
> return 0;
> }
>
> :::::::::::::::::::: main.c end
Set break point and try "print x" for each variable.
The result may be like this.
> (gdb) p a
> $1 = 1.10000000000000001
> (gdb) p b
> $2 = 2.20000000000000002
> (gdb) p c
> $3 = 4.4000001
> (gdb) p d
> $4 = 8.80000019
It is correct.
Then, try "print x+1" for each variable.
This time, the result may be like this.
> (gdb) p a+1
> $17 = 2
> (gdb) p b+1
> $18 = 3.2000000000000002
> (gdb) p c+1
> $19 = 5
> (gdb) p d+1
> $20 = 9.8000001907348633
> (gdb)
As you can see, both the substituted types 'a' and 'c' are evaluated
as integers and the digits right to the floating points ignored.
This bug is very annoying when you just want to test some formulas
for floating point variables without rewriting, recompiling and
rerunning the program.
As the result is OK when the value itself is printed, I guess it is a
bug in processing parsing fomulas.
I hope you can help me by some patches.
Tak.