C++, breakpoint set in ancestor's virtual method, for RVCT compiled elf-file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++, breakpoint set in ancestor's virtual method, for RVCT compiled elf-file



This bug was reported to the gdb bug list as #2434.

 

I set a breakpoint on a <class>::<method> (e.g. A::getValue), but the
breakpoint is set at the virtual method <baseclass>::<method> (e.g.
Base::getValue) that <class>::<method> is overriding. This happens when
I use a RVCT compiled elf file using dwarf2, but not with a gcc compiled
(elf/dwarf2) file. I am using gdb 6.7.1 linux/arm and RVCT 3.1.

 

 

> cat bug.cpp
#include <iostream>
using namespace std;

class Base {
public:
   Base() {}
   virtual ~Base() {}
   virtual int getValue(); // not virtual
};

class A : public Base {
public:
   A() : Base() {}
   ~A() {}
   int getValue();
};

int Base::getValue(){
   return 0;
}

int A::getValue(){
   return 100;
}

int main (int argc, char** argv) 
{
   A a;
   Base *object;
   object = &a; // object is now an A object

   int value = object->getValue();
   cout << "new value should be 100 is " << value << endl; 
}

//// END OF FILE

------------------------------------------------------------------------
-
RVCT compiled elf-file run in gdb sim
The breakpoint is not set on line 23 as it should be,
and thus the program does not stop on the breakpoint.
Note that the run is correct only the breakpoint is at the wrong place.
------------------------------------------------------------------------
-

> make -f build_rvct.mk clean
rm -f *.o *.elf
> make -f build_rvct.mk all
/ARM/RVCT/Programs/3.1/569/linux-pentium/armcpp -c -g -O0
-I/ARM/RVCT/Data/3.1/569/include/unix --dwarf2 bug.cpp -o bug.o
"bug.cpp", line 14: Warning:  #1300-D: ~A inherits implicit virtual
     ~A() {}
     ^
"bug.cpp", line 15: Warning:  #1300-D: getValue inherits implicit
virtual
     int getValue();
         ^
bug.cpp: 2 warnings, 0 errors
/ARM/RVCT/Programs/3.1/569/linux-pentium/armlink --libpath
/ARM/RVCT/Data/3.1/569/lib bug.o --info totals --elf -o bug.elf
<<<< info removed >>>>
Build completed
> /gdb_linux_arm_6.7.1/bin/arm-ose-gdb
GNU gdb 6.7.1
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
http://gnu.org/licenses/gpl.html> <http://gnu.org/licenses/gpl.html%3E> 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show
copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-ose".
(gdb) target sim
Connected to the simulator.
(gdb) load bug.elf
Loading section ER_RO, size 0xc0b8 vma 0x8000
Loading section ER_RW, size 0xa4 vma 0x140b8
Start address 0x8000
Transfer rate: 396000 bits in <1 sec.
(gdb) file bug.elf
Reading symbols from /homes/anders/bug.elf...done.
(gdb) break A::getValue
Breakpoint 1 at 0x8160: file bug.cpp, line 19.
(gdb) r
Starting program: /homes/anders/bug.elf 
new value should be 100 is 100

Program exited normally.
(gdb) quit

 

 

The same example works for a gcc compiled elf file.

If the breakpoint is set as 'A::getValue()' it is set correctly.

 

Best Regards 

Anders

 

---------------------------------
Anders Hessel Ph.D.
Tools / R&D

Enea Software AB
Skalholtsgatan 9,
Box 1033, SE-164 21 Kista, Sweden
Direct: +46850714441
Mobile: +46709714441
Anders.Hessel '@t' enea.com
www.enea.com
---------------------------------
Enea - Embedded for Leaders
---------------------------------