Bug 53797 - Not able to print local variable while debugging at -O0
Summary: Not able to print local variable while debugging at -O0
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2012-06-28 11:33 UTC by Mohamed Shafi
Modified: 2021-08-10 01:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.0
Last reconfirmed: 2012-06-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mohamed Shafi 2012-06-28 11:33:03 UTC
I tried debugging the following function with arm,i686 and ppc C and C++ compiler.

void func (int);
int main ()
{
	func (20);
	return 0;
}

void func(int in)
{
     int a;
     in++;
     {
          int k, j;
    	  k = 10;
    	  j = k + 44;
    	  in = j + 1;
    	  a = in;
     }                  <------      Line 1
     a = in;
     a++;
}           <--------- Line 2


Invocation line :

g++ main.cpp -g3 -gdwarf-2 --save-temps -dA -o main.elf

When i try to print the value of 'a' when the execution reaches "line
2" i get the message "No symbol "a" in current context.". Here is the
gdb output:

(gdb) l
15                j = k + 44;
16                in = j + 1;
17                a = in;
18           }
19           a = in;
20           a++;
21      }
22
23      int main()
24      {
(gdb) s
21      }
(gdb) p a
No symbol "a" in current context.
(gdb) p in
$1 = 55
(gdb)

For the same program i am able to view the value of 'a' if i compile
this as a C program. This happens because DW_TAG_lexical_block which
is generated only for in C++ debug info marks the scope of variable
'a' between prologue and epilogue of the code. Since the epilogue is
not present in the scope, the variable cannot be viewed when the
control reaches the closing brace of the function.
Comment 1 Richard Biener 2012-06-28 11:58:22 UTC
Confirmed.  Works with the C frontend.  The difference is different location
info for the BLOCK:

-func (int in)
-[t.C : 9:1] {
+void func(int) (int in)
+[t.C : 20:6] {
   int a;
...
-  [t.C : 19:5] a = in;
-  [t.C : 20:4] a = a + 1;
+  [t.C : 19:9] a = in;
+  [t.C : 20:6] a = a + 1;
 }

for -C +C++.