From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29466 invoked by alias); 19 Oct 2011 21:14:44 -0000 Received: (qmail 29450 invoked by uid 22791); 19 Oct 2011 21:14:42 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-bw0-f41.google.com (HELO mail-bw0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Oct 2011 21:14:26 +0000 Received: by bkbzu5 with SMTP id zu5so3074936bkb.0 for ; Wed, 19 Oct 2011 14:14:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.129.22 with SMTP id m22mr6166834bks.22.1319058864735; Wed, 19 Oct 2011 14:14:24 -0700 (PDT) Received: by 10.205.115.138 with HTTP; Wed, 19 Oct 2011 14:14:24 -0700 (PDT) Date: Thu, 20 Oct 2011 17:24:00 -0000 Message-ID: Subject: Accessing std::cout and std::cin from within gdb. From: Delcypher To: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-10/txt/msg00162.txt.bz2 Hi I'm having problems accessing the cout and cin objects from within gdb. If I take a simple example program: #include 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.