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.