bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

declaring and defining virtual function in header file


From: Henning Moll
Subject: declaring and defining virtual function in header file
Date: Sat, 16 Dec 2000 17:27:47 +0100
User-agent: KNode/0.3.2

Hi!

I think i found a very strange problem/bug:

(using 
-gdb version 4.16, 418 and to 5.0 configured for 'i586-pc-linux-gnu' and  
solaris
- gcc version 2.95.2 19991024 (release)
)

i wonder if it is an bug of gdb or gcc. (Or maybe it isn't a bug???)

Here's an example: (The very important part is in Class.h)
use the following commands on the files enclosed at the end of this mail:

c++ -O2 lib.cpp -c
c++ -g -c cctest.cpp 
c++ -o ttt cctest.o lib.o

Execute binary 'ttt'. The output looks like this:
| 0x80485e0
| 0x8048660
| this is function no_problem
| this is function problem



now start gdb ('gdb ttt')
use the 'info line *' command on both of the addresses. The output looks 
like 
this:

| (gdb) info line * 0x80485e0
| Line 6 of "cctest.cpp" starts at address 0x80485e0 <no_problem__Fv>
|    and ends at 0x80485e6 <no_problem__Fv+6>.



Everything's fine with this information

| (gdb) info line * 0x8048660
| Line 23 of "cctest.cpp" starts at address 0x8048652 <main+66>
|    and ends at 0x80486c0 <__tf4Test>.  



Oops: There is wrong line,file and symbol name information for the second 
address. 
try to step into the function 'problem'. 

without the keyword 'virtual' or/and without the function body of 
Test::cctest() everything's fine! What's wrong?

Best regards
Henning Moll

Here're the files:

---snip: cctest.cpp---
#include <stdio.h>
#include "Class.h"
#include "lib.h"

void no_problem()
{
         printf("this is function no_problem\n");
         return;
}

int main()
{
         printf("0x%x\n", &no_problem);  
         printf("0x%x\n", &problem);     


         /* try to step into these functions. no chance for func problem() 
*/

         no_problem();
         problem();

         return 0;
}; //why does gdb show this line, when stepping into function 'problem' ????
---snip---

---snip: lib.cpp---
#include <stdio.h>

void problem()
{
         printf("this is function problem\n");
         return;
};
---snip----

---snip: lib.h ---
void problem();
---snip----

---snip: Class.h---
class Test {
public:
  virtual void cctest(){}; /* note: cctest is virtual AND has a function 
body 
!!!! That's a very important point ! */
};
---snip----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]