Getting actual value of local variables in llvm

旧城冷巷雨未停 提交于 2019-12-07 11:45:21

问题


If I have this example:

int a=0, b=0;

a and b are local variables and make any modifications in their values, such as:

a++;
b++;

I need to get the value in this line code during running MCJIT.

I mean by value not Value class, but the actual integer or any type value.


回答1:


You need to return the value from a JITed LLVM function in order to retrieve it from the code invoking MCJIT.

Check out this Kaleidoscope example.

The relevant code is in 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());
  }
}



回答2:


Put a break point after execution of the statement where you want to check the value. In the console (lldb) po <variable name>.

Although I guess watch point is more suitable for your requirement, add a watch point for the variable like, watchpoint set variable <variable key path>.



来源:https://stackoverflow.com/questions/44874575/getting-actual-value-of-local-variables-in-llvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!