LLDB API:如何调用存储在SBValue中的对象的方法

LLDB API : How to call a method of object stored in SBValue

本文关键字:存储 SBValue 对象 方法 调用 API 何调用 LLDB      更新时间:2023-10-16

>我有一个类型为 sc_time 的值,它有方法

inline double sc_time::to_double() const  

我可以从调试器调用此方法以获取返回值吗?可能吗?

// lldb::SBValue cur_time
cout << "IsInScope: " << cur_time.IsInScope() << endl;
cout << "Name: " << cur_time.GetName() << endl;
cout << "Type Name: " << cur_time.GetType().GetName() << endl;

返回

IsInScope: 1
Name: m_curr_time
Type Name: sc_core::sc_time

我试过了

cur_time.CreateValueFromExpression("retval", "to_double()")
cur_time.CreateValueFromExpression("retval", "m_curr_time.to_double()")
cur_time.CreateValueFromExpression("retval", "this->to_double()")

没有一个工作

class sc_time
{
public:
    double to_double() const { return 123.456; // mock }
};

~/.lldbinit中加载配置文件:

command script import ~/.lldbcfg/print_sc_time.py                                                                                                           

用于打印sc_time类实例的配置文件: $HOME/.lldbcfg/print_sc_time.py

def print_sc_time(valobj, internal_dict):
    res = str(valobj.EvaluateExpression("to_double()").GetValue())
    return res
def __lldb_init_module(debugger, internal_dict):
    debugger.HandleCommand('type summary add -P sc_time -F {:s}.print_sc_time'.format(__name__))