Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-c] Expose debug support for LLJIT in Orc C-API bindings #73257

Merged
merged 8 commits into from
Dec 11, 2023

Conversation

weliveindetail
Copy link
Contributor

Allow C-API users to debug their JITed code. The new API function LLVMOrcObjectLayerRegisterPluginJITLoaderGDB() adds the required plugin to provide GDB JIT Interface support. This initial patch covers the ELF use-case by installing the DebugObjectManagerPlugin. It should be easy to add support for other object formats later on.

Copy link
Contributor Author

@weliveindetail weliveindetail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few open questions

llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp Outdated Show resolved Hide resolved
llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp Outdated Show resolved Hide resolved
llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp Outdated Show resolved Hide resolved
Copy link
Contributor Author

@weliveindetail weliveindetail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short discussion on Discord suggested that it's better to add this for LLJIT specifically. So, here is the update.

@@ -39,7 +39,7 @@ Error enableDebuggerSupport(LLJIT &J) {
if (!Registrar)
return Registrar.takeError();
ObjLinkingLayer->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
ES, std::move(*Registrar), true, true));
ES, std::move(*Registrar), false, true));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the RequireDebugSections flag. Without this change the test won't pass, because the bitcode for the sum() example has no debug info.

This change may cause some overhead, but this shouldn't be a surprise in the context of debugging. And it may avoid headaches for users: Not remembering to generate debug info is a common problem for JITed code. With this change users get at least function names, like in release builds. Without it, the debugger has zero info.

Alternatively, we could expose it in the C-API and wire it up in the internal function here. See my second comment for details.

}
}

#if defined(_AIX) or not defined(__ELF__)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the test doesn't pass for MachO, because the sum() example has no debug info and it's a hard-coded requirement in the MachO plugin:
https://github.com/llvm/llvm-project/blob/0424546ed4a75708/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp#L401

@lhames For the reasons described above, it might be interesting to expose the RequireDebugSections flag in the C-API. What do you think? Would you wire it up in the MachO plugin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MachO plugin just bails out early if there's no debug info, right? I think that's reasonable behavior. Could we add some debug info to the test case? Hopefully the IR-level debug info is the same for both platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MachO plugin just bails out early if there's no debug info, right? I think that's reasonable behavior.

Not sure. I think it's confusing for users. People are used to have symbol names in non-debug builds, so they can at least set breakpoints on their functions. With the bail out behavior here they have nothing at all and it's not immediately obvious why. It's one of too many things that can go wrong in JITed code debugging.

Could we add some debug info to the test case? Hopefully the IR-level debug info is the same for both platforms?

Anyway, yes that's probably the best solution. I guess minimal debug info will be pretty portable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MachO plugin just bails out early if there's no debug info, right? I think that's reasonable behavior.

Not sure. I think it's confusing for users. People are used to have symbol names in non-debug builds, so they can at least set breakpoints on their functions. With the bail out behavior here they have nothing at all and it's not immediately obvious why. It's one of too many things that can go wrong in JITed code debugging.

Regarding that: I'm working on some lighter-weight symbolication solutions that we could use to enable breakpoints (and symbolicated backtraces) for JIT'd code, even in the case of a crashed executor. So hopefully this situation will be temporary. :)

@weliveindetail weliveindetail changed the title [llvm-c] Expose debug object registration in Orc C-API bindings [llvm-c] Expose debug support for LLJIT in Orc C-API bindings Nov 29, 2023
Copy link

github-actions bot commented Dec 8, 2023

:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks very much @weliveindetail!

llvm/include/llvm-c/LLJITUtils.h Outdated Show resolved Hide resolved
@weliveindetail weliveindetail merged commit 54397f9 into llvm:main Dec 11, 2023
3 of 4 checks passed
MaskRay added a commit that referenced this pull request Dec 11, 2023
MaskRay added a commit that referenced this pull request Dec 11, 2023
weliveindetail added a commit that referenced this pull request Dec 12, 2023
…o RuntimeDyld

Fix test failure reported from buildbot clang-s390x-linux-lnt after #73257
OrcCAPITest.cpp:562: Debugger support requires JITLink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants