我想从一个字符串创建一个SBType
,目标是使用SBType
来计算指针类型,这是当前代码:
# `typ` is a string representing a C type (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
Find function pointer SBType in LLDB when DWARF info contains only typedef提出了类似的问题,但没有解决方案。
编辑:link @atl shared提示我使用EvaluateExpression
来转换表达式。下面是一个更新的示例:
# `typ` is a string representing a C type (int, int32_t, char*).
typ_sbtype : lldb.SBType = target.FindFirstType (typ)
if not typ_sbtype.IsValid ():
# Try to cast 0 as an expression to obtain the type.
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))
1条答案
按热度按时间kknvjkwl1#
这一系列命令可能会有所帮助,其思想来自这些lldb注解