2017-07-02 81 views
3

如果我有这样的例子:获取局部变量的实际值LLVM

int a=0, b=0; 

a和b是局部变量,进行任何修改它们的值,如:

a++; 
b++; 

我需要在运行MCJIT期间获取此行代码中的值。

我的意思是价值不是Value类,但实际的整数或任何类型的值。

+0

你会请举一个例子对这个“我需要在运行MCJIT期间获得该行代码中的值”解释多一点 – Saranjith

回答

-1

在执行要检查值的语句后输入一个断点。在控制台(lldb) po <variable name>

虽然我认为观察点更适合您的要求,请为变量添加一个观察点,如watchpoint set variable <variable key path>

+1

我需要根据运行时的值对IR进行一些修改 –

0

您需要从JITed LLVM函数返回值,以便从调用MCJIT的代码中检索该值。

看看这个Kaleidoscope example

相关的代码是在HandleTopLevelExpression():

if (FunctionAST *F = ParseTopLevelExpr()) { 
    if (Function *LF = F->Codegen()) { 
    // JIT the function, returning a function pointer. 
    void *FPtr = TheHelper->getPointerToFunction(LF); 

    // Cast it to the right type (takes no arguments, returns a double) so we 
    // can call it as a native function. 
    double (*FP)() = (double (*)())(intptr_t)FPtr; 
    fprintf(stderr, "Evaluated to %f\n", FP()); 
    } 
}