简体   繁体   English

lldb 脚本:如何从文字地址获取 lldb.SBValue

[英]lldb script: How to get lldb.SBValue from literal address

Given a memory address, I would like to print it's content from a lldb script.给定一个 memory 地址,我想从 lldb 脚本打印它的内容。

I tried different approaches to get a SBValue given an address but none of them worked for me, namely我尝试了不同的方法来获取给定地址的 SBValue,但它们都不适合我,即

buffer = lldb.SBData()
buffer.CreateDataFromCString(lldb.eByteOrderBig, 10, "0x00007fffe45e3000")

but when I go to query the object nothing it shown.但是当我 go 查询 object 时没有显示。

I also tried to assign the address to a convenience variable in lldb and then use FindVariable(), but the variable is empty我还尝试将地址分配给lldb中的便利变量,然后使用FindVariable(),但该变量为空

expr auto $buffer =  function_returning_address();
>>> buffer = lldb.frame.FindVariable("$buffer")

but here again the variable has no name, type etc. I also tried with SBValue.SetValueFromCString()但是这里的变量又没有名称、类型等。我也尝试使用 SBValue.SetValueFromCString()

>>> buffer.SetValueFromCString("0x00007fffe45e3000", error)
False
>>> print error
error: Could not get value: No value

I didn't find much documentation on Google and I'm just starting out with lldb scripts, any suggestion is appreciated.我在 Google 上没有找到太多文档,而且我刚开始使用 lldb 脚本,欢迎提出任何建议。

Thanks.谢谢。

There are two ways to do this.有两种方法可以做到这一点。 If you want the raw data, you can ask your SBProcess to read memory as a Python byte array using SBProcess.ReadMemory.如果您想要原始数据,您可以要求您的 SBProcess 使用 SBProcess.ReadMemory 将 memory 作为 Python 字节数组读取。 If you want to present the data at that address as an instance of some type, you can use SBTarget.CreateValueFromAddress.如果您想将该地址处的数据显示为某种类型的实例,您可以使用 SBTarget.CreateValueFromAddress。 To find the type to pass into this, use SBTarget.FindFirstType...要找到传递给它的类型,请使用 SBTarget.FindFirstType...

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

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