[llvm-dev] [llvm][debug][jit] llvm-project debug jit-ed code (original) (raw)
Stefan Gränitz via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 17 03:32:53 PDT 2021
- Previous message: [llvm-dev] (no subject)
- Next message: [llvm-dev] Experimenting with opt -Os/-Oz
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello Alex, I am adding llvm-dev (cc) as other people might have similar questions.
If I understand correctly, debugging works with lli if you follow the instructions from https://www.llvm.org/docs/DebuggingJITedCode.html That's a good first step, because now the only question is what's the difference between lli and your code in main.cpp.
From what you describe I don't see an obvious problem. You say debugging main.cpp itself works fine. Here's a few things you can try to narrow down the problem:
- Set a breakpoint in the constructor of MCJIT and make sure RegisterJITEventListener() is called.
- Set a breakpoint in GDBJITRegistrationListener::notifyObjectLoaded() and check that the call to getObjectForDebug() returns a non-null result.
- Enable logging for the JIT interface in LLDB and check that you get output like this:
(lldb) b my_func Breakpoint 1: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. (lldb) log enable lldb jit (lldb) run JITLoaderGDB::SetJITBreakpoint looking for JIT register hook JITLoaderGDB::SetJITBreakpoint setting JIT breakpoint Process 46448 launched: '/path/to/main' (x86_64) JITLoaderGDB::JITDebugBreakpointHit hit JIT breakpoint JITLoaderGDB::ReadJITDescriptorImpl registering JIT entry at 0x10e019830 (2872 bytes) 1 location added to breakpoint 1
Does that help?
Best Stefan
On 17/03/2021 09:21, Alex wrote:
Hello
My name is Alex Fedchenko. I try work with JIT-ed code. As I see you work with llvm-project. Could you help me with debugging IR-code. Now I try is use combination with llvm::Module/ llvm::ExecutionEngine/ llvm::Function successful. But I want debugging this code. I can debug code from main.cpp , but I do not know how I can debug code from my.ll file. I try explain what I can do ... I have file "my.c" with function "int myfunc(int v)" I created file my.ll use command "clang -g -c -S -emit-llvm my.c" 1) If I write simple main.c file like: extern int myfunc(int v); int main() { for( int i = 0; i < 10; i++) {_ _int n = -1;_ _n = myfunc( i );_ _}_ _return 0;_ _}_ _And create mail.ll use command "clang -g -c -S -emit-llvm main.c"_ _Then I linked my.ll and mail.ll use command "llvm-link my.ll main.ll_ _-o all.ll"_ _After that I can debugging myfunc using gdb or lldb-12_ _(instruction here: https://www.llvm.org/docs/DebuggingJITedCode.html_ _<https://www.llvm.org/docs/DebuggingJITedCode.html>) It is work fine (about debug process). BUT 2) When I write main.cpp file, where I use llvm::Module/ llvm::ExecutionEngine/ llvm::Function like: int main(int argc, char const *argv[]) { ... std::uniqueptrllvm::Module mod = llvm::parseIRFile( "my.ll", error, context ); llvm::ExecutionEngine *executionEngine = llvm::EngineBuilder( std::move( mod )).create(); ... llvm::Function *f = executionEngine->FindFunctionNamed(llvm::StringRef("myfunc")); ... llvm::GenericValue res = executionEngine->runFunction( f, arg ); ... I CAN NOT DUBUD myfunc :( I build main.cpp : "clang++ -g main.cpp -O0 -o main" I can debug main.cpp using gdb or lldb, but I can not set breakpoint in myfunc and debug myfunc :( ("./main" - work fine) Could you help me? Maybe you have any ideas how we can debug function what was load from Module and called over ExecutionEngine? Maybe you know any person who can help me? Or may be exist another way where we can called function from ll-file and debugged it from another running application (in debug mode). Thank you for your response Best regards Alex F.
-- https://flowcrypt.com/pub/stefan.graenitz@gmail.com
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210317/24747896/attachment.html>
- Previous message: [llvm-dev] (no subject)
- Next message: [llvm-dev] Experimenting with opt -Os/-Oz
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]