我正在尝试LLDB + python,以便更好地将json字符串打印到文件中。对于给定的std::string变量(称为缓冲区),我已经在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是实际值,但您确实希望看到“C字符串的内容从0x12345开始”。 GetValue将显示0x12345,GetSummary字符串。

关于c++ - C++:LLDB + Python-如何在python脚本中打印std::string,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39401848/

10-13 08:05
查看更多