Bug 8724 - Cannot call operator<<(ostream&, MyClass&) from gdb
Summary: Cannot call operator<<(ostream&, MyClass&) from gdb
Status: ASSIGNED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 16106
  Show dependency treegraph
 
Reported: 2004-04-23 12:48 UTC by salman.khilji
Modified: 2023-12-17 18:06 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments
deleteme.cpp (191 bytes, application/octet-stream)
, salman.khilji
Details

Note You need to log in before you can comment on or make changes to this bug.
Description salman.khilji 2004-04-23 12:48:00 UTC
[Converted from Gnats 1619]

I have a class which defines an operator<< so that it can be dumped to cout or cerr.  I cannot call this function from gdb.  I have searched the bug database and while this problem has been reported before and some solutions were presented, none of them worked using gdb 6.0, gcc 2.95.3


class MyClass
{
public:
  int     mInteger;
  double  mDouble;
};
 
ostream & operator<< (ostream & s, const MyClass & o)
{
  s << o.mInteger << " " << o.mDouble << endl;
  return s;
}

Release:
6.0

Environment:
Linux, gcc 2.95.3

How-To-Repeat:
Put a breakpoint on the attached file @ line 22.  Then try to call the operator<< function defined on line 12.

compile with g++ -g -o test deleteme.cpp
Comment 1 salman.khilji 2004-04-23 12:48:00 UTC
Fix:
Don't know.
Comment 2 Hannes Domani 2023-12-16 18:04:29 UTC
Calling operator<< works just fine for me since at least gdb-8.1:

(gdb) p operator<< (cout, obj)
$1 = (std::ostream &) @0x13f2e3980: <incomplete type>
Comment 3 Tom Tromey 2023-12-17 16:00:54 UTC
How about "p cout << obj" ?
Comment 4 Hannes Domani 2023-12-17 18:06:55 UTC
(In reply to Tom Tromey from comment #3)
> How about "p cout << obj" ?

Right, forgot to test the obvious, that works for me since gdb-8.2.1:
```
(gdb) p cout << obj
1 4.57307e-318
$1 = (std::ostream &) @0x13fa33980: <incomplete type>
```