<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hello Alex, I am adding llvm-dev (cc) as other people might have
    similar questions.<br>
    <br>
    If I understand correctly, debugging works with lli if you follow
    the instructions from
    <a class="moz-txt-link-freetext" href="https://www.llvm.org/docs/DebuggingJITedCode.html">https://www.llvm.org/docs/DebuggingJITedCode.html</a> That's a good
    first step, because now the only question is what's the difference
    between lli and your code in main.cpp.<br>
    <br>
    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:<br>
    <br>
    * Set a breakpoint in the constructor of MCJIT and make sure
    RegisterJITEventListener() is called.<br>
    * Set a breakpoint in
    GDBJITRegistrationListener::notifyObjectLoaded() and check that the
    call to getObjectForDebug() returns a non-null result.<br>
    * Enable logging for the JIT interface in LLDB and check that you
    get output like this:<br>
    <br>
    (lldb) b my_func<br>
    Breakpoint 1: no locations (pending).<br>
    WARNING:  Unable to resolve breakpoint to any actual locations.<br>
    (lldb) log enable lldb jit<br>
    (lldb) run<br>
     JITLoaderGDB::SetJITBreakpoint looking for JIT register hook<br>
     JITLoaderGDB::SetJITBreakpoint setting JIT breakpoint<br>
    Process 46448 launched: '/path/to/main' (x86_64)<br>
     JITLoaderGDB::JITDebugBreakpointHit hit JIT breakpoint<br>
     JITLoaderGDB::ReadJITDescriptorImpl registering JIT entry at
    0x10e019830 (2872 bytes)<br>
    1 location added to breakpoint 1<br>
    <br>
    Does that help?<br>
    <br>
    Best<br>
    Stefan<br>
    <br>
    <div class="moz-cite-prefix">On 17/03/2021 09:21, Alex wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:1615969273.435424000.kuo84g3e@frv55.fwdcdn.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <span style="display:block;" class="xfm_28241686">Hello<br>
        <br>
        My name is Alex Fedchenko.<br>
        <br>
        I try work with JIT-ed code.<br>
        As I see you work with llvm-project.<br>
        Could you help me with debugging IR-code.<br>
        <br>
        Now I try is use combination with llvm::Module/
        llvm::ExecutionEngine/ llvm::Function successful.<br>
        But I want debugging this code.<br>
        I can debug code from main.cpp , but I do not know how I can
        debug code from my.ll file.<br>
        <br>
        I try explain what I can do ...<br>
        <br>
        I have file "my.c" with function "int my_func(int v)"<br>
        I created file my.ll use command "clang -g -c -S -emit-llvm
        my.c"<br>
        <br>
        1)<br>
        If I write simple main.c file like:<br>
        <br>
        extern int my_func(int v);<br>
        <br>
        int main() {<br>
            for( int i = 0; i < 10; i++) {<br>
                int n = -1;<br>
                n = my_func( i );<br>
            }<br>
        <br>
            return 0;<br>
        }<br>
        <br>
        And create mail.ll use command "clang -g -c -S -emit-llvm
        main.c"<br>
        Then I linked my.ll and mail.ll use command "llvm-link my.ll
        main.ll -o all.ll"<br>
        <br>
        After that I can debugging my_func using gdb or lldb-12<br>
        (instruction here:  <a
          href="https://www.llvm.org/docs/DebuggingJITedCode.html"
          target="_blank" rel="noreferrer noopener"
          moz-do-not-send="true">https://www.llvm.org/docs/DebuggingJITedCode.html</a>)<br>
        It is work fine (about debug process).<br>
        <br>
        BUT<br>
        2)<br>
        When I write main.cpp file, where I use llvm::Module/
        llvm::ExecutionEngine/ llvm::Function<br>
        like:<br>
        <br>
        int main(int argc, char const *argv[]) {<br>
            ...<br>
            std::unique_ptr<llvm::Module> mod = llvm::parseIRFile(
        "my.ll", error, context );<br>
            llvm::ExecutionEngine *executionEngine =
        llvm::EngineBuilder( std::move( mod )).create();<br>
            ...<br>
            llvm::Function *f =
        executionEngine->FindFunctionNamed(llvm::StringRef("my_func"));<br>
            ...<br>
            llvm::GenericValue res = executionEngine->runFunction( f,
        arg );<br>
            ...<br>
            <br>
        I CAN NOT DUBUD my_func :(<br>
        I build main.cpp : "clang++ -g main.cpp -O0 -o main"<br>
        I can debug main.cpp using gdb or lldb, but I can not set
        breakpoint in my_func and debug my_func :(<br>
        ("./main" - work fine)<br>
        <br>
        Could you help me?<br>
        Maybe you have any ideas how we can debug function what was load
        from Module and called over ExecutionEngine?<br>
        Maybe you know any person who can help me?<br>
        Or may be exist another way where we can called function from
        ll-file and debugged it from another running application (in
        debug mode).<br>
        <br>
        Thank you for your response<br>
        <br>
        Best regards<br>
        Alex F.</span>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="https://flowcrypt.com/pub/stefan.graenitz@gmail.com">https://flowcrypt.com/pub/stefan.graenitz@gmail.com</a></pre>
  </body>
</html>