This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gdb/1643: gdb


>Number:         1643
>Category:       gdb
>Synopsis:       gdb
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          test-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 13 15:38:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     diegoandresalvarez@gmx.net
>Release:        unknown-1.0
>Organization:
>Environment:

>Description:
gnu.gdb.bug, gnu.gcc.help, gnu.gcc, comp.lang.c

Dear all,

Is there a bug in gdb?

I am compiling the following code with

gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

gcc -Wall -g -c x.c
gcc -Wall -g x.o -o x -lm

The next program runs perfectly, but if I see an internal view with gdb, I obtain that the vector suma in function norm_inf() 

gdb x

(gdb) whatis suma
type = double [2]

but, as can we see easily it is double [4]

So, where is the problem?

How can I obtain the correct size of suma?

Thanks,

Diego Andres


#include <stdio.h>
#include <math.h>

double findmax(double *x, const int n) {
   double maximo = x[0];
   int i;
   for (i=1; i<n; i++) {
      if (x[i] > maximo) maximo = x[i];
   }
   return maximo;
};

double norm_inf(double *A, const int nf, const int nc) {
// NORM(X,inf) is the infinity norm of X, the largest row sum = max(sum(abs(X'))).
   double suma[nc];
   int i, j;
   
   for(i=0;i<nf;i++) {
      suma[i] = 0.0;
      for(j=0;j<nc;j++) suma[i] += fabs(A[i*nc + j]);
   }
      
   return findmax(suma, nc);
}

int main() {
   double x[] = {
     5,     4,     3,     4,
    -3,     3,    -1,     2,
     1,     0,     1,    -3,
     0,    -5,     3,    -1};
     
   printf("Norm Inf = %g\n",norm_inf(x, 4, 4));
   
   return 0;
}


[daa@cl1-c810 Desktop]$ gcc -Wall -g -c x.c

[daa@cl1-c810 Desktop]$ gcc -Wall -g x.o -o x -lm

[daa@cl1-c810 Desktop]$ gdb x

GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 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-gnu"...
(gdb) break norm_inf
Breakpoint 1 at 0x80483de: file x.c, line 19.
(gdb) l
22         for(i=0;i<nf;i++) {
23            suma[i] = 0.0;
24            for(j=0;j<nc;j++) suma[i] += fabs(A[i*nc + j]);
25         }
26
27         return findmax(suma, nc);
28      }
29
30      int main() {
31         double x[] = {
(gdb) break 27
Breakpoint 2 at 0x8048472: file x.c, line 27.
(gdb) r
Starting program: /home/daa/Desktop/x

Breakpoint 1, norm_inf (A=0xbfffda90, nf=4, nc=4) at x.c:19
19         double suma[nc];
(gdb) c
Continuing.

Breakpoint 2, norm_inf (A=0xbfffda90, nf=4, nc=4) at x.c:27
27         return findmax(suma, nc);
(gdb) print suma
$1 = {-1.9907996654489004, 8.4879831658373518e-314}
(gdb) whatis suma
type = double [2]


>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]