Apparent bug with dbx on SGI IRIX

From Higher Intellect Wiki
Jump to: navigation, search

I am using dbx version 7.3 MR 55458 on IRIX Release 6.5 IP27. I am programming in C++ and compiling using CC. I have noticed that the following code

unsigned short A, **B;
unsigned long X, Y;

/* memory allocation and filling array with values

 Code added for memory allocation and value assignment


A = B[Y][X];

results in the following

dbx> p B[Y][X], A
dbx> 910, 230

Note that I break and check the values just after the statement

A = B[Y][X];

but the value in B[Y][X] has not been assigned to A. Is there a bug in the way the values are assigned or in the way they are reported? Note also that

dbx> p (A==B[Y][X])
results in
dbx> 0

I would be grateful if anyone could tell me what is causing this problem.

Here is my complete compile command line.

CC -g -c ImageProcessing.cpp

I don't know if this would have any bearing on the problem but the problem is caused in a library file that is made as follows.

ar vr /usr/users/plikonen/lib/libImage.a ImageProcessing.o

The calling routine is compiled using the same arguments as the library files.


Here is a small example that shows things working properly:

(dbx) n
Process  3100 (t) stopped at [::main:28 ,0x10001348]
  28  B[Y][X] = 930;
(dbx) p B[Y][X], A
0 230 
(dbx) n
Process  3100 (t) stopped at [::main:30 ,0x1000137c]
  30  A = B[Y][X];
(dbx) p B[Y][X], A
930 230 
(dbx) n
Process  3100 (t) stopped at [::main:32 ,0x100013b0]
  32  printf("%d %d\n",A,B[Y][X]);
(dbx) !p
(!p = p B[Y][X], A)
930 930

Here is the test program:
proton 44% cat t.cxx
#include <stdio.h>
#include <strings.h>
#include <malloc.h>

unsigned short A, **B;
unsigned long X, Y;

#define LIMX  15
#define LIMY  20

int main()
        int A = 230;
        X = LIMX-5;
        Y = LIMY-5;

        B = (unsigned short **)malloc(LIMY*sizeof(*B) );

        B[Y] =  (unsigned short *)malloc(LIMX*sizeof(unsigned short));
        bzero(B[Y],LIMX*sizeof(unsigned short));
        B[Y][X] = 930;

        A = B[Y][X];
        printf("%d %d\n",A,B[Y][X]);
        return 0;

The compile command is: CC -g -n32 t.cxx -o t

All works exactly as it should as far as I can tell. You don't give a *complete* test case, so I supply one here. I don't recall you mentioning (in response to Walter Roberson's reply) for sure which ABI you compile for, so I guessed but made the -n32 explicit for clarity.

I tried it with 7.2.1 and (not yet released). IRIX 6.5.5 and IRIX 6.5.9 not on exactly the same releases as you did, but... this is very basic stuff.

I give the complete dbx script to make it clear dbx displays the source line *to be executed next*.

Note that the above command is incorrect. For C++ files to go into archives with 7.3, you should be using

   CC -ar /usr/users/plikonen/lib/libImage.a ImageProcessing.o

as is documented (but I don't recall just where ...).

For C or Fortran (f77 or f90) objects the ar command is fine. But C++ has all these special things like templates, constructors, etc etc, and plain ar(1) does not, in general, do the right things on C++ objects.

I have no reason to think this command error has any bearing on the original question, though.

Share your opinion