DDD arrrrgh!

Consider the following code:

case 1:
{
char pathname[MAX_PATH];

strcpy(pathname, “/tmp”);

if (test) {
printf(pathname);
}
}
break;

Suppose I put a breakpoint on strcpy() and I ask to display pathname.
Fine!

Now I execute the source line step by step. test is true, when I enter
inside the if, pathname disappear !?!

If I ask again to display pathname : graph display pathname, gdb answer:

No symbol “pathname” in current context.

printf(pathname) is ok off course.

any idea?

Better now!

Suppose you have an else block code. Inside the else, pathname is
displayed. Magic no?

Alain.

That’s strange…I’ve had similar problems with variables near the end
of a program disappearing. Is this code the last reference to pathname?
If it is, and you have optimization turned on, it could be that the
compiler is doing something funky. Like I said, I had some code where
I wanted to examine the state of a structure just before the program
exited and it wasn’t appearing until I turned optimization off.

(Forgive me if this is obvious. Unlike me, I’m sure most people are
clever enough to remember to turn off optimization when debugging. :stuck_out_tongue:)

Kris


Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

Consider the following code:

case 1:
{
char pathname[MAX_PATH];

strcpy(pathname, “/tmp”);

if (test) {
printf(pathname);
}
}
break;

Suppose I put a breakpoint on strcpy() and I ask to display pathname.
Fine!

Now I execute the source line step by step. test is true, when I enter
inside the if, pathname disappear !?!

If I ask again to display pathname : graph display pathname, gdb answer:

No symbol “pathname” in current context.

printf(pathname) is ok off course.

any idea?

Better now!

Suppose you have an else block code. Inside the else, pathname is
displayed. Magic no?

Alain.


Kris Warkentin
kewarken@qnx.com
(613)591-0836 x9368
“You’re bound to be unhappy if you optimize everything” - Donald Knuth

Kris Eric Warkentin a écrit :

That’s strange…I’ve had similar problems with variables near the end
of a program disappearing. Is this code the last reference to pathname?

What do you mean exactly?

If it is, and you have optimization turned on, it could be that the
compiler is doing something funky. Like I said, I had some code where
I wanted to examine the state of a structure just before the program
exited and it wasn’t appearing until I turned optimization off.

(Forgive me if this is obvious. Unlike me, I’m sure most people are
clever enough to remember to turn off optimization when debugging. > :stuck_out_tongue:> )

Not so obvious in fact!
The problem is that I use recursive makefiles (which use qcc as it’s advised
in the doc :astonished:). Strange almost everybody wants to use gcc) and the -O option
is turned on even to generate the debug version (you see that it’s not so
obvious !).
How can I turn off this option?

thanks,
Alain.

If you’re using the up to date RTP makefiles (/usr/include/mk) then doing
‘make OPTIMIZE_TYPE=NONE’ will do the trick. I’m not entirely sure but some
variables may get optimized out of existence once they’re no longer
referenced.

cheers,

Kris

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

Kris Eric Warkentin a crit :

That’s strange…I’ve had similar problems with variables near the end
of a program disappearing. Is this code the last reference to pathname?

What do you mean exactly?


If it is, and you have optimization turned on, it could be that the
compiler is doing something funky. Like I said, I had some code where
I wanted to examine the state of a structure just before the program
exited and it wasn’t appearing until I turned optimization off.

(Forgive me if this is obvious. Unlike me, I’m sure most people are
clever enough to remember to turn off optimization when debugging. > :stuck_out_tongue:> )

Not so obvious in fact!
The problem is that I use recursive makefiles (which use qcc as it’s advised
in the doc > :astonished:> ). Strange almost everybody wants to use gcc) and the -O option
is turned on even to generate the debug version (you see that it’s not so
obvious !).
How can I turn off this option?

thanks,
Alain.


Kris Warkentin
kewarken@qnx.com
(613)591-0836 x9368
“You’re bound to be unhappy if you optimize everything” - Donald Knuth