c++: LLDB + Python -如何在Python脚本中打印std::字符串
c++: LLDB + Python - how to print a std::string in the python script
我正在尝试LLDB + python,以便更好地将json字符串打印到文件中。对于给定的std::string变量(称其为buffer),我在python断点脚本中尝试了以下操作,以便美观地打印到文件—所有操作都不成功:
json.dump(frame.FindVariable("buffer"), handle, indent=4)
# ^^^^ error that SBValue* is not serializable
json.dump(frame.FindVariable("buffer").GetValue(), handle, indent=4)
# ^^^^ emits null
json.dump(frame.EvaluateExpression("buffer.c_str()"), handle, indent=4)
# ^^^^ error that SBValue* is not serializable
json.dump(frame.EvaluateExpression("buffer.c_str()").GetValue(), handle, indent=4)
# ^^^^ prints an address...not useful
json.dump(frame.EvaluateExpression("buffer.c_str()").GetData(), handle, indent=4)
# ^^^^ error that SBValue* is not serializable
有谁知道有什么神奇的东西可以让我把std::string框架变量转换成python字符串传递给json.dump()吗?
您需要SBValue的摘要。这个页面:
http://lldb.llvm.org/varformats.html更详细地描述了摘要。SBValue。GetSummary调用会做你想做的。
任何时候lldb需要从实际但无用的值转换为用户友好的值,它都是通过摘要机制完成的。例如,对于char *, 0x12345是实际值,但您真正想看到的是"从0x12345开始的c字符串的内容"。GetValue将显示0x12345, GetSummary将显示字符串
Jim把我送到了正确的轨道上——最终对我有效的代码是:
e = lldb.SBError()
frame.GetThread().GetProcess().ReadCStringFromMemory(frame.EvaluateExpression("buffer.c_str()").GetValueAsUnsigned(), 0xffffff, e)
相关文章:
- 如何在c++中使用system()来运行包含空格的python脚本
- 如何将真正的字符串从python c-api转换为python脚本
- 在从Qt调用的Python脚本中导入OpenCV崩溃
- 使用 Main() 返回值作为 python 脚本的参数
- 如何制作启动 Python 脚本的 linux 后台进程(在 c 中)
- 从Raspberry Pi / Linux上的Python脚本运行和停止C++程序
- C++ Python 并不总是执行 Python 脚本
- 从C++调用 Python 脚本以持续流式传输数据
- 将数据从 c++ 文件连续发送到 Python 脚本以进行进一步处理
- 错误,在嵌入在C++程序中的 python 脚本中使用 matplotlib 时
- 在使用PyInstaller冻结Python脚本时包含一个C++可执行文件
- 使用 pipe() 和 fdopen() 将数据从 Python 脚本传递到 Windows 中的C++应用程序
- Python 脚本到 c .obj 文件
- 从 c++ 运行 python 脚本时出现问题
- C++ :从C++脚本内部触发存储在我机器上的 python 脚本
- 从 c++ 中运行 python 脚本,找不到模块
- 参数从 Python 脚本传递到 C++ 使用 boost-python
- 无法从Linux,C ++执行"my_script" python脚本"main(filename)"功能;pModule = PyImport_Import(pName);返回空值
- 如何在C ++(qt)代码中使用python脚本?(网页抓取方面)
- 将对象从 python 脚本传递给 c++