You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从指针类型字符串创建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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 21:10:20