[Bug c/53793] New: [ARM] Debug info is wrong at optimization level -O1

2012-06-28 Thread shafitvm at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53793

 Bug #: 53793
   Summary: [ARM] Debug info is wrong at optimization level -O1
Classification: Unclassified
   Product: gcc
   Version: 4.6.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: shafi...@gmail.com


Compiler:

Arm linaro
Target: arm-none-eabi
Configured with:
/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/src/gcc/configure
--build=i686-linux-gnu --host=i686-pc-mingw32 --target=arm-none-eabi
--prefix=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/install-mingw
--enable-languages=c,c++ --disable-decimal-float --disable-libffi
--disable-libgomp --disable-libmudflap --disable-libquadmath
--disable-libssp --disable-libstdcxx-pch --disable-lto --disable-nls
--disable-shared --disable-threads --disable-tls --with-gnu-as
--with-gnu-ld --with-headers=yes --with-newlib
--with-sysroot=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/install-mingw/arm-none-eabi
--with-libiconv-prefix=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-gmp=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-mpfr=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-mpc=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-ppl=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-cloog=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-libelf=/home/rat031/arm_gcc_051612/gcc-arm-none-eabi-4_6-2012q1-20120316/build-mingw/host-libs/usr
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic
-lm' --with-pkgversion='GNU Tools for ARM Embedded Processors'
--with-extra-multilibs=armv6-m,armv7-m,armv7e-m,armv7-r
Thread model: single
gcc version 4.6.2 20120316 (release) [ARM/embedded-4_6-branch revision
185452] (GNU Tools for ARM Embedded Processors)


invocation line:
arm-none-eabi-gcc -Wl,-Map=output.map -mcpu=cortex-m0 -mthumb
-specs=rdimon.specs -lrdimon -lc -lrdimon test.c -g3 -gdwarf-2 -O1  -o
test.elf --save-temps -dA

Code:

void variables_local();

int main(void)
{
   variables_local();
   return 0;
}



void variables_local()
{
   volatile int SizeOfInt  = sizeof (int);
   volatile int lint = 1024;
   volatile float lfloat = 55.55f;
   volatile double ldouble = 222.222;
   volatile long llong = 123456789;
   volatile unsigned luint = 256;
   volatile char lchar = 'a';
   volatile char *lstring = "hello";
   volatile char mlarray[8] = "testing";
   return;
}

gdb output:

Breakpoint 1, main () at test.c:14
14  variables_local();
(gdb) s
variables_local () at test.c:22
22  volatile int SizeOfInt  = sizeof (int);
(gdb) s
23  volatile int lint = 1024;
(gdb) p SizeOfInt
$1 = 39211
(gdb) s
24  volatile float lfloat = 55.55f;
(gdb) p lint
$2 = 0
(gdb) s
25  volatile double ldouble = 222.222;
(gdb) p lfloat
$3 = 5.60519386e-045
(gdb) s
26  volatile long llong = 123456789;
(gdb) p ldouble
$4 = 518831996932.39624
(gdb) s
27  volatile unsigned luint = 256;
(gdb) p llong
$5 = 1080805146
(gdb) s
28  volatile char lchar = 'a';
(gdb) p luint
$6 = 2680059593
(gdb) s
30  volatile char mlarray[8] = "testing";
(gdb) p lchar
$7 = 97 'a'
(gdb) s
32  }
(gdb) p lchar
$8 = 159 'Y'
(gdb) p lint
$9 = 0
(gdb) p luint
$10 = 2680059593
(gdb)

Issue:

I think dwarf info generated doesn't take into account the push/pop instruction

variables_local:
.LFB1:
   .file 1 "../Sources/main.c"
   @ ../Sources/main.c:21
   .loc 1 21 0
   .cfi_startproc
   push{r4, lr}
.LCFI0:
   .cfi_def_cfa_offset 8
   .cfi_offset 4, -8
   .cfi_offset 14, -4
   @ basic block 2
   sub sp, sp, #16
.LCFI1:
   .cfi_def_cfa_offset 24
   @ ../Sources/main.c:22
   .loc 1 22 0
   mov r3, #4
   str r3, [sp, #12]
.LVL0:

I see that in prologue/epilogue push/pop instructions are directly emitted on
to output file using asm_print, rather than into the rtl steam. Hence the dwarf
info generation code is not aware of such instructions.


[Bug target/53793] [ARM] Debug info is wrong at optimization level -O1

2012-06-28 Thread shafitvm at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53793

--- Comment #2 from Mohamed Shafi  2012-06-28 
11:15:18 UTC ---
So this is fixed in 4.7 then. Any plan to back port this?


[Bug c++/53797] New: Not able to print local variable while debugging at -O0

2012-06-28 Thread shafitvm at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53797

 Bug #: 53797
   Summary: Not able to print local variable while debugging at
-O0
Classification: Unclassified
   Product: gcc
   Version: 4.6.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: shafi...@gmail.com


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
15j = k + 44;
16in = j + 1;
17a = 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.