Setting an std::string variable value from gdb?

╄→гoц情女王★ 提交于 2019-12-04 16:14:51

问题


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"

?


回答1:


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.



来源:https://stackoverflow.com/questions/2502314/setting-an-stdstring-variable-value-from-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!