繁体   English   中英

C ++:LLDB + Python-如何在python脚本中打印std :: string

[英]c++: LLDB + Python - how to print a std::string in the python script

我正在尝试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()?

Jim在上面的正确位置发送了我-对我有用的最终代码是:

e = lldb.SBError()
frame.GetThread().GetProcess().ReadCStringFromMemory(frame.E‌​valuateExpression("b‌​uffer.c_str()").GetV‌​alueAsUnsigned(), 0xffffff, e) 

您需要SBValue中的摘要。 这一页:

http://lldb.llvm.org/varformats.html

详细描述摘要。 SBValue.GetSummary调用将执行您想要的操作。

每当lldb需要从实际但无用的值转换为用户友好的值时,它都会通过汇总机制来完成此操作。 例如,对于一个char *,0x12345是实际值,但您确实想看到“ C字符串的内容从0x12345开始”。 GetValue将显示0x12345,GetSummary字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM