I’m having trouble creating an std::string (or any C++ object, I guess) in GDB. I tried lots of variations to the following and none of them seem to work:
(gdb) p std::string("hello")
A syntax error in expression, near `"hello")'.
Is there a way to do it?
(I’m surprised I couldn’t find anything about this on the Web. I’m starting to think if my GDB is buggy or I’m doing something very wrong.)
You should be able to construct a new std::string within the GDB. You want to allocate space on the heap to hold the std::string object, invoke the default constructor, and assign your string value. Here is an example: