Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > gdb & C++ Problem

gdb & C++ Problem
Thread Tools
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Dec 11, 2002, 03:33 PM
 
The problem that I'm having is that gdb doesn't seem to know what a 'char' is if I overload the '<<' operator but nothing uses the overloaded code. Here's the code I'm using, compiled with 'g++ -g -o Tester main.cpp'
Code:
#include <iostream> std::ostream& operator<< (std::ostream& s, const int& x) { std::cout << "I have been called" << std::endl; return s; } int main (int argc, const char * argv[]) { const char *kMyString = "Hello, world!"; std::cout << kMyString << std::endl; return 0; }
When I run this in gdb and break on the line that outputs kMyString, I get the following when I try to display the string's contents:
Code:
(gdb) p kMyString $1 = <incomplete type>
If I remove the operator-overload method, resulting in the following code, everything works fine. Here's the good code:
Code:
#include <iostream> int main (int argc, const char * argv[]) { const char *kMyString = "Hello, world!"; std::cout << kMyString << std::endl; return 0; } --------------- (gdb) p kMyString $1 = (<invalid type code 7> *) 0x297ac "Hello, world!"
This seems to be a bug in g++ and/or gdb. The overloaded method is never called, and should be dead-stripped. But even if it's not, it has nothing to do with whether or not the 'char' type is defined.

By the way, using the bad code, I also get the following strangeness in gdb:
Code:
(gdb) p (char)'a' Invalid cast.
Can anyone offer any insight? This problem makes debugging impossible. Oh, and I've tested this on multiple machines running 10.2.2.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:57 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2