From: Delcypher <delcypher@gmail.com>
To: gdb@sourceware.org
Subject: Accessing std::cout and std::cin from within gdb.
Date: Thu, 20 Oct 2011 17:24:00 -0000 [thread overview]
Message-ID: <CANNJ_ziCQSnYQ+WdXMA1fFD9cqXNFEGp3FaXG+AqiR-3n7gpMg@mail.gmail.com> (raw)
Hi I'm having problems accessing the cout and cin objects from within
gdb. If I take a simple example program:
#include <iostream>
using namespace std;
int main()
{
ostream& mockCout = cout;
istream& mockCin = cin;
cout << "&std::cout is " << &cout << endl;
cout << "&std::cin is " << &cin << endl;
cout << "&mockCin is " << &mockCin << endl;
cout << "&mockCout is " << &mockCout << endl;
return 0;
}
And build with `g++ -Wall -g test.cpp' and then run `gdb a.out'
(gdb) b main
Breakpoint 1 at 0x40087c: file test.cpp, line 6.
(gdb) run
Starting program: /home/dan/src/a.out
Breakpoint 1, main () at test.cpp:6
6 ostream& mockCout = cout;
(gdb) n
7 istream& mockCin = cin;
(gdb) n
9 cout << "&std::cout is " << &cout << endl;
(gdb) n
&std::cout is 0x6013a0
10 cout << "&std::cin is " << &cin << endl;
(gdb) n
&std::cin is 0x601280
12 cout << "&mockCin is " << &mockCin << endl;
(gdb) n
&mockCin is 0x601280
13 cout << "&mockCout is " << &mockCout << endl;
(gdb) n
&mockCout is 0x6013a0
14 return 0;
(gdb) p &cout
$1 = (std::ostream *) 0x7ffff7dc9d60
(gdb) p &cin
$2 = (std::istream *) 0x7ffff7dc9e80
(gdb) p &mockCout
$3 = (std::ostream *) 0x6013a0
(gdb) p &mockCin
$4 = (std::istream *) 0x601280
(gdb)
What I see is that gdb has the completely wrong address for the cin
and cout objects. My references have the right address though.
Consequently calling any of cin's or cout's methods fails but using my
references works fine (except for the error messages I see).
(gdb) call cout.good()
Cannot access memory at address 0xffffffffffffffe8
(gdb) call mockCout.good()
warning: RTTI symbol not found for class 'std::ostream'
warning: RTTI symbol not found for class 'std::ostream'
warning: RTTI symbol not found for class 'std::ostream'
warning: RTTI symbol not found for class 'std::ostream'
warning: RTTI symbol not found for class 'std::ostream'
$6 = true
(gdb)
I found an old post
(http://sourceware.org/ml/gdb/2006-08/msg00244.html ) from over 5
years ago that demonstrates this behaviour and shows another way to
access cout or cin. In my case I could run
(gdb) call ( (std::ostream) *(0x6013a0)).good()
Is this behaviour of not being able to access cout and cin a bug or
have I done something wrong?
If needed here is some version information.
OS: Arch Linux x86_64
g++ version: g++ (GCC) 4.6.1 20110819 (prerelease)
gdb version: GNU gdb (GDB) 7.3.1
Thanks,
Dan.
next reply other threads:[~2011-10-19 21:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-20 17:24 Delcypher [this message]
2011-10-21 0:47 ` Jan Kratochvil
2011-10-22 1:18 ` Delcypher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANNJ_ziCQSnYQ+WdXMA1fFD9cqXNFEGp3FaXG+AqiR-3n7gpMg@mail.gmail.com \
--to=delcypher@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).