开发者

Setting an std::string variable value from gdb?

开发者 https://www.devze.com 2022-12-24 21:56 出处:网络
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 开发者_如何学JAVAthe current

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 开发者_如何学JAVAthe current buffer?

e.g. something like "set var mystring="hello world"

?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消