2017-07-02 41 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()); 
    } 
}