簡體   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