0

While debugging a C++ program in Eclipse, I need to change the value of a string. But when I am about to do it, I see this and I cannot change it: (here's the link to the image, I don't have enough reputation yet) https://i.stack.imgur.com/G8gxu.png

What should I try? Thank you.

Awacate
  • 125
  • 2
  • 10

1 Answers1

0

A std::string is actually not very simple behind the scenes. It has to manage a buffer of memory that your text is stored in. If you want the string to have a different (possibly much longer) value, then the std::string may have to deallocate the old buffer, allocate a new buffer of sufficient size and finally copy over the values, while keeping track of all the related information (e.g. its old and new size).

And then there's also small string optimization.

It's not trivial for a debugger to do these changes (without breaking the std::string in question). Some debuggers that understand the underlying compiler well (e.g. if you're working in Visual Studio) may be able to do this, but it's not a simple thing for a debugger to do.

Therefore, I would not be surprised if Eclipse's debugger does not allow changing string values at runtime. You might be able to change individual characters, but especially adding characters (or replacing with a longer string) might be beyond its capabilities.

Disclaimer: It's of course possible that there is a way or a workaround, such as this one for gdb. I don't use Eclipse so I can't tell you, but if there is no way to do it then the above is essentially the reason for that.

Max Langhof
  • 23,383
  • 5
  • 39
  • 72