Is it possible... when the debugger is stopped at a breakpoint, to modify the value of a std::string variable without resorting to hacks like tweaking the memory image of the current buffer?
e.g. something like "set var mystring="hello world"
?
Use the set variable (gdb) and the assign (dbx) commands to change the value associated with a variable, memory address, or expression that is accessible according to the scope and visibility rules of the language. The expression can be any expression that is valid in the current context.
The ptype [ARG] command will print the type. Show activity on this post. This question may be related: vtable in polymorphic class of C++ using gdb: (gdb) help set print object Set printing of object's derived type based on vtable info.
The following registers are mentioned in the article: ESP (points to the top of the stack) EBP (is used as a reference when accessing local variables and arguments of the function) EIP (points to the address of the next instruction)
Try this (tested and works for me):
call mystring.assign("hello world")
The key is that instead of modifying memory directly, you call the object's functions to change its state. It so happens that std::basic_string
has a member function called assign
which does the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With