Re: [RFC/RFA] gdb.cp/classes.exp: Don't try to print local variable out of scope

Corinna Vinschen
2004-03-09T15:40:30Z

Hi Michael,

On Mar 9 10:11, Michael Elizabeth Chastain wrote:
> That is: is a local variable required to exist at the closing brace of a
> function?
>
> I think your answer is "no, it's not required to exist, therefore the
> gdb test suite should change". My answer is "reluctantly, no,
> it's not required to exist"; I don't think the famous gcc -O0
> debug info clause covers this case. I'm curious what drow and
> carlton and other people have to say.

basically this problem is similar to the "having the same variable
defined twice in a function" problem:

1 void foo ()
2 {
3 int i = 1;
4 {
5 int i = 2;
6 bar(i);
7 }
8 bar (i);
9 }

Is line 7 still in the scope of the inner definition of variable `i'?
Which `i' should be printed at that point?

> void foo ()
> {
> int i;
> i = 1;
> bar (i);
> }
>
> (gdb) break bar
> (gdb) run
> (gdb) finish
> (gdb) print i
>
> Is it okay for gcc to emit debug info that "i" is out of scope here?

IMHO yes. Keep in mind that it's a *local* variable. It's practically
dead at this point. $pc sits already in the epilogue which destroys the
variable anyway. Just one `stepi' would perhaps *really* destroy the
variable and GDB might print some entirely confused value.

> cv> I'd suggest to change the testsuite case to add another line to the
> cv> function enums1(), so that it's sure to be still in the scope of the
> cv> local variable obj_with_enum.
>
> misc.cc is used by three *.exp files so I do not want to touch it
> at all, so I am dis-approving your patch. I will write a patch to
> remove the "gdb_test next" in test_enums instead.

I tested the whole gdb.cp testsuite on linux-x-sh with and without the
patch and the only difference in the testsuite output where the tests
directly affected by this change:

7c7,10
< (gdb) KFAIL: gdb.cp/classes.exp: ptype obj_with_enum (PRMS: gdb/57)
---
> (gdb) FAIL: gdb.cp/classes.exp: print obj_with_enum (2)
> (gdb) FAIL: gdb.cp/classes.exp: print obj_with_enum.priv_enum
> (gdb) FAIL: gdb.cp/classes.exp: ptype obj_with_enum.priv_enum
> (gdb) FAIL: gdb.cp/classes.exp: ptype obj_with_enum

Corinna

--
Corinna Vinschen
Cygwin Developer
Red Hat, Inc.