Getting the actual value of local variables in llvm

If I have this example:

int a=0, b=0;

      

a and b are local variables and make any changes to their values, such as:

a++;
b++;

      

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

I don't mean the value of the Value

class, but the actual integer or any value of the type.

+3


source to share


2 answers


You need to return the value from the JITed LLVM function in order to extract it from the code that calls MCJIT.

Check out this example of a kaleidoscope .



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());
  }
}

      

0


source


Place a breakpoint after executing the statement where you want to check the value. In the console (lldb) po <variable name>

.



While I think a watchpoint is more appropriate for your requirement, add a watchpoint for the type variable watchpoint set variable <variable key path>

.

-1


source







All Articles