如何从指针类型字符串创建LLDB的SBType对象?
问题:从字符串创建SBType并处理指针类型
我希望从字符串创建SBType对象,目标是利用该SBType计算指针类型。当前代码如下:
# `typ` 是代表C类型的字符串(如int、int32_t、char*)。 typ_sbtype : lldb.SBType = target.FindFirstType (typ) if not typ_sbtype.IsValid (): raise Exception ("type: {} is not valid".format(typ)) print (typ_sbtype.GetPointerType())
该代码对char有效,但对char*无效:
(lldb) target create "./a.out" Current executable set to '/home/kevin/code/python_toolkit/lldb_scripting/debugme2/a.out' (x86_64). (lldb) command script import print_ptrtype print_ptrtype has been imported. Try `print_ptrtype <type>`. (lldb) print_ptrtype "char" char * (lldb) print_ptrtype "char *" Traceback (most recent call last): File "/home/kevin/code/python_toolkit/lldb_scripting/debugme2/./print_ptrtype.py", line 13, in print_ptrtype raise Exception ("type: {} is not valid".format(typ)) Exception: type: char * is not valid
曾有类似问题但未得到解决。
编辑补充:可以使用EvaluateExpression来转换表达式,以下是更新后的示例代码:
# `typ` 是代表C类型的字符串(如int、int32_t、char*)。 typ_sbtype : lldb.SBType = target.FindFirstType (typ) if not typ_sbtype.IsValid (): # 尝试将0转换为对应表达式以获取类型。 ptr : lldb.SBValue = frame.EvaluateExpression("({}) 0".format(typ)) typ_sbtype : lldb.SBType = ptr.GetType() if not typ_sbtype.IsValid(): raise Exception ("type: {} is not valid".format(typ))
内容的提问来源于stack exchange,提问作者kevinAlbs
相关产品推荐
相关产品推荐

