How do you call operator<<(std::ostream &os, const ClassX &x) from inside gdb ?
In other words, how do you print an object in gdb ?
call std::cout<<x or call operator<<(std::cout, x) don’t seems to work for me!
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only way I found was this:
Since
std::coutwasn’t visible to gdb for some reason, I had to resort to creating my own like this:You haven’t stated any reasons for wanting to do this but won’t
print yourvariablebe easier?If this is an absolute must you could have a
Printmethod in your class and call that fromoperator<<and then call thePrintmethod on your object from gdb.Do take note that stdout is probably buffered in gdb so you won’t be seeing any output unless you redirect it somehow.
See this discussion from gdb’s mailing archive regarding this issue.