public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* representing C++ constructors in GDB's symbol tables
@ 2004-09-17 22:46 Jim Blandy
  2004-09-18  0:14 ` Daniel Jacobowitz
  2004-09-18  0:18 ` David Carlton
  0 siblings, 2 replies; 5+ messages in thread
From: Jim Blandy @ 2004-09-17 22:46 UTC (permalink / raw)
  To: gdb


There are currently several problems I see in the way we represent C++
constructors in GDB's symbol table.

First, for a class named "X", we put three (or possibly four) entries
in VAR_DOMAIN all named "X": the typedef, and two (or possibly three)
constructors.  This makes it (cough) difficult to look up the one you
need.

It occured to me that perhaps constructors should not be in the
VAR_DOMAIN.  You can't use them by name in expressions: you have to
say "new X(...)", never "X(...)".  You can't call them directly.  You
can't take their addresses: "&X::X(int)" is not valid C++.  The only
reason they really have names at all is to let you define them outside
the class.

Creating a new CONSTRUCTORS_DOMAIN would give you something reasonable
to pass when handling a "new" expression.  And there's nothing wrong
with adding a C++-specific domain; domains were created to distinguish
the different roles identifiers might play in a particular language:
witness STRUCT_DOMAIN vs VAR_DOMAIN for C.

Then there's the question of duplicate copies of the constructors
themselves.  The code at the moment wants to distinguish them by their
physical (linker) names, but I gather one of the main thrusts of David
and Daniel's work was to move away from the internal use of mangled
names for this kind of thing.  Domains are the wrong tool there; the
presence of multiple constructor copies is an ABI-specific thing.
I don't have an answer to that that sounds good yet. 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: representing C++ constructors in GDB's symbol tables
  2004-09-17 22:46 representing C++ constructors in GDB's symbol tables Jim Blandy
@ 2004-09-18  0:14 ` Daniel Jacobowitz
  2004-09-18  0:18 ` David Carlton
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2004-09-18  0:14 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb

On Fri, Sep 17, 2004 at 05:45:40PM -0500, Jim Blandy wrote:
> 
> There are currently several problems I see in the way we represent C++
> constructors in GDB's symbol table.
> 
> First, for a class named "X", we put three (or possibly four) entries
> in VAR_DOMAIN all named "X": the typedef, and two (or possibly three)
> constructors.  This makes it (cough) difficult to look up the one you
> need.
> 
> It occured to me that perhaps constructors should not be in the
> VAR_DOMAIN.  You can't use them by name in expressions: you have to
> say "new X(...)", never "X(...)".  You can't call them directly.  You
> can't take their addresses: "&X::X(int)" is not valid C++.  The only
> reason they really have names at all is to let you define them outside
> the class.
> 
> Creating a new CONSTRUCTORS_DOMAIN would give you something reasonable
> to pass when handling a "new" expression.  And there's nothing wrong
> with adding a C++-specific domain; domains were created to distinguish
> the different roles identifiers might play in a particular language:
> witness STRUCT_DOMAIN vs VAR_DOMAIN for C.

I prefer fixing the names of the constructors in the symbol table (or
un-flattening the symbol table); I think that would obsolete this.

> Then there's the question of duplicate copies of the constructors
> themselves.  The code at the moment wants to distinguish them by their
> physical (linker) names, but I gather one of the main thrusts of David
> and Daniel's work was to move away from the internal use of mangled
> names for this kind of thing.  Domains are the wrong tool there; the
> presence of multiple constructor copies is an ABI-specific thing.
> I don't have an answer to that that sounds good yet. 

We only need to have textual names that distinguish these things for
the user interface.  Internally, they can just be different pointers;
that means we have to keep track of them from the types rather than
storing names in the types and abusing lookup_symbol.

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: representing C++ constructors in GDB's symbol tables
  2004-09-17 22:46 representing C++ constructors in GDB's symbol tables Jim Blandy
  2004-09-18  0:14 ` Daniel Jacobowitz
@ 2004-09-18  0:18 ` David Carlton
  2004-09-18  2:29   ` Michael Chastain
  1 sibling, 1 reply; 5+ messages in thread
From: David Carlton @ 2004-09-18  0:18 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb

On Fri, 17 Sep 2004 17:45:40 -0500, Jim Blandy <jimb@redhat.com> said:

> It occured to me that perhaps constructors should not be in the
> VAR_DOMAIN.

This sounds plausible, though I'm not entirely convinced, but for what
it's worth this next claim of yours isn't really true:

> You can't use them by name in expressions: you have to say "new
> X(...)", never "X(...)".

You can use "X(...)" to create a temporary object of type X.  E.g. the
following program works fine.

  #include <iostream>

  class Printer {
    public:
      void print() const {
          std::cout << "print!\n";
      }
  };

  int main() {
      Printer().print();

      return 0;
  }

Having said that, a constructor really is a different beast from an
ordinary function call.  And I don't think that having GDB support

  (gdb) print Printer().print()

should be high on your list of priorities.

David Carlton
david.carlton@sun.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: representing C++ constructors in GDB's symbol tables
  2004-09-18  0:18 ` David Carlton
@ 2004-09-18  2:29   ` Michael Chastain
  2004-09-20 16:36     ` David Carlton
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Chastain @ 2004-09-18  2:29 UTC (permalink / raw)
  To: jimb, david.carlton; +Cc: gdb

David Carlton <david.carlton@sun.com> wrote:
> You can use "X(...)" to create a temporary object of type X.

Sure.  And of course:

  X my_x = X();

Also remember destructors.  A C++ program can explicitly call
a destructor.  Sigh.

> Having said that, a constructor really is a different beast from an
> ordinary function call.  And I don't think that having GDB support
>
>   (gdb) print Printer().print()
>
> should be high on your list of priorities.

Yeah.  I would be comfortable if gdb said "forget about it,
I don't call a ctor directly" (and the same for dtor).

Then in 2006 someone else can come along and fix that limitation,
watching out for the big trap that the ABI for constructors and
destructors can be *different* than for normal functions,
with hidden magic parameters.

Michael

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: representing C++ constructors in GDB's symbol tables
  2004-09-18  2:29   ` Michael Chastain
@ 2004-09-20 16:36     ` David Carlton
  0 siblings, 0 replies; 5+ messages in thread
From: David Carlton @ 2004-09-20 16:36 UTC (permalink / raw)
  To: Michael Chastain; +Cc: jimb, David.Carlton, gdb

On Fri, 17 Sep 2004 22:29:31 -0400, Michael Chastain <mec.gnu@mindspring.com> said:
> David Carlton <david.carlton@sun.com> wrote:

>> You can use "X(...)" to create a temporary object of type X.

> Sure.  And of course:

>   X my_x = X();

(But not "X my_x();", the C++ geek in me feels compelled to point
out. :-) )

David Carlton
david.carlton@sun.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-09-20 16:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-17 22:46 representing C++ constructors in GDB's symbol tables Jim Blandy
2004-09-18  0:14 ` Daniel Jacobowitz
2004-09-18  0:18 ` David Carlton
2004-09-18  2:29   ` Michael Chastain
2004-09-20 16:36     ` David Carlton

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).