¿Cómo se modifica aquí el valor de esta variable?

OK, I have this benchmark from SPLASH2 which I am using to test a tool which I have created. The benchmark has the following struct.

typedef struct _interact {
    struct _interact *next ;          /* Next entry of the list */
    Element *destination ;            /* Partner of the interaction */
    float   formfactor_out ;          /* Form factor from this patch  */
    float   formfactor_err ;            /* Error of FF */
    float   area_ratio ;          /* Area(this) / Area(dest) */
    float   visibility ;          /* Visibility (0 - 1.0) */
} Interaction ;

Looking into the code, I found that area_ratio is never used. However, in the end, I see that the value of area_ratio is not 0, as it is in the beginning. So I placed a watchpoint on this variable, and surprisingly gdb pointed me to a code which modifies visibilidad (the variable just below the area_ratio).

Now my question is why is this happening. How come area_ratio is modified by modifing visibilidad. What are the possibilties? Any clue? I'm really puzzled. Note that I'm testing my program on a 64-bit machine. Maybe 64 bit has to do something with it, but I don't know!

El código es algo como esto:

/* Create links and finish the job */
inter = get_interaction(process_id) ;
*inter = i12 ;
inter->visibility = VISIBILITY_UNDEF ; // <---- This is what gdb is pointing to

preguntado el 08 de noviembre de 11 a las 13:11

It's conceivable that you've taken a pointer to an Interaction, and somehow subtracted sizeof(float) bytes from it. That would require what I'll call "pointer trickery" -- e.g. casting to char* for the subtraction. So if there's any such trickery with Interaction pointers, check it carefully. -

1 Respuestas

Ah I got it! Actually what is happening is that i12 is a local variable, which is not initialized to 0 and when we perform *inter = i12;,la area_ratio of i12 está asignado a *inter y desde i12's area_ratio is random and not necessarily 0, that value of area_ratio está asignado a *inter.

And by the way, now I've realized that gdb shows the line number of the one below the intended line, so its not pointing to the line inter->visibility = VISIBILITY_UNDEF, but the line *inter = i12;

respondido 08 nov., 11:17

GDB doesn't show "line number one below intended". Rather, GDB stops immediately after the instruction which modified the address being watched, i.e. on the next instruction. The next instruction could belong to the same line, the next line, 10 lines later, or 100 lines earlier, depending on the code and how it was built. - Ruso empleado

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.