从gdb设置std :: string变量值? [英] Setting an std::string variable value from gdb?

查看:753
本文介绍了从gdb设置std :: string变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当调试器在断点处停止时,是否有可能修改std :: string变量的值而无需借助诸如调整当前缓冲区的内存映像之类的黑客手段?

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?

例如类似于"set var mystring ="hello world"

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

?

推荐答案

尝试一下(经过测试,对我有用):

Try this (tested and works for me):

call mystring.assign("hello world")

关键是您可以直接调用对象的函数来更改其状态,而不是直接修改内存.碰巧std::basic_string有一个称为assign的成员函数来完成这项工作.

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.

这篇关于从gdb设置std :: string变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆