public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* c++/2294: gdb can't call or print a const function that uses virtual inheritance
@ 2007-08-02 20:58 jlevine
  0 siblings, 0 replies; only message in thread
From: jlevine @ 2007-08-02 20:58 UTC (permalink / raw)
  To: gdb-gnats; +Cc: dan


>Number:         2294
>Category:       c++
>Synopsis:       gdb can't call or print a const function that uses virtual inheritance
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 02 20:58:01 UTC 2007
>Closed-Date:
>Last-Modified:
>Originator:     Joshua Levine
>Release:        gdb 6.6
>Organization:
>Environment:
32bit ee3_0 using gnu g++ 3.2.3 and 4.1.1
gdb 6.6
>Description:
Having a virtual const function in a class that is inherited from a base class using virtual inheritance causes a "Cannot access memory at address 0x0" error when doing a 'print' on that function from the gdb console.  Taking out the virtual keyword from the inheritance of the base class solves the problem, or just removing the const from the function also fixes it.

The problem seems to be from the call_function_by_hand() function in gdb/infcall.c, near the start of the function.  You'll see the following two lines that were added in 6.6:

    if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
      ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
      
This replaces ftype with the target type if the function is a pointer, and eventually this leads to a xfer_partial memory read that has a NULL obj->beneath, and the memory read returns a -1.  I wasn't able to track down why the virtual inheritance causes this bad memory read.  As a temp work around, I have commented out the two lines of code and this fixes the problem.  Please see the test case below to reproduce the error.

I haven't tested this test case in 64bit mode, but my early tests showed the problem wasn't there if you compiled with 64bit and used a 64bit gdb.
>How-To-Repeat:
Compile with the following testcase and run the following commands at the gdb prompt:
(gdb) break main
(gdb) start
(gdb) next
(gdb) print o.do_print()

-------- test case ------------------------
class interface { };
 
class Obj : 
virtual // comment out this line and it works
public interface
{
public:
  virtual const char* do_print() const { return "Obj3"; }
};
 
int main(int argc, char** argv) {
  Obj o;
  return 0;
}
>Fix:
See description
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-08-02 20:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-02 20:58 c++/2294: gdb can't call or print a const function that uses virtual inheritance jlevine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).