llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.58k stars 11.81k forks source link

[DEBUGINFO] Add DILabel Functions to LLVM-C #112799

Open tf2spi opened 1 day ago

tf2spi commented 1 day ago

Hello LLVM Team,

This is my first issue request in LLVM, so apologies if I've misspoken or acted poorly for any reason.

I'm currently using the LLVM-C bindings in a PR for Odin Lang and a really nice API in LLVM that's unfortunately missing in the C bindings is llvm::DIBuilder::createLabel and llvm::DIBuilder::insertLabel which are helpful when outputting debug info for various labels in Odin. There's even the LLVMDILabelMetadataKind kind but no way to actually make a DILabel from the C API as far as I'm aware.

For UNIX-like platforms, I was still able to link to the C++ function directly and use the C references which are wrappers around the C++ types. However, we have a build of the LLVM C DLL for Windows in the repo which does not export the C++ functions so it's not feasible right now to output debug info for labels on Windows.

In both cases, it would be more ideal if these were exported as C functions that we could then use in Odin. Programming languages with labels and whose compilers are written in C, whether now or in the future, would likely appreciate this as well.

llvmbot commented 1 day ago

@llvm/issue-subscribers-debuginfo

Author: None (tf2spi)

Hello LLVM Team, This is my first issue request in LLVM, so apologies if I've misspoken or acted poorly for any reason. I'm currently using the LLVM-C bindings in a [PR for Odin Lang](https://github.com/odin-lang/Odin/pull/4385) and a really nice API in LLVM that's unfortunately missing in the C bindings is [llvm::DIBuilder::createLabel](https://llvm.org/doxygen/DIBuilder_8cpp_source.html#l00830) and [llvm::DIBuilder::insertLabel](https://llvm.org/doxygen/DIBuilder_8cpp_source.html#l01013) which are helpful when outputting debug info for various labels in Odin. There's even the [LLVMDILabelMetadataKind](https://llvm.org/doxygen/llvm-c_2DebugInfo_8h_source.html#l00187) kind but no way to actually make a DILabel from the C API as far as I'm aware. For UNIX-like platforms, I was still able to link to the C++ function directly and use the C references which are wrappers around the C++ types. However, we have a build of the LLVM C DLL for Windows in the repo which does not export the C++ functions so it's not feasible right now to output debug info for labels on Windows. In both cases, it would be more ideal if these were exported as C functions that we could then use in Odin. Programming languages with labels and whose compilers are written in C, whether now or in the future, would likely appreciate this as well.
dwblaikie commented 1 day ago

This is a fine bug, thanks for filing it!

Though it's probably not something high on anyone's list to fix, unfortunately - and possibly to move it forward it'd be best if you could provide a pull request for the desired functionality - it's probably not too hard to plumb through, if it's already in DIBuilder?

tf2spi commented 1 day ago

Looking at how the C bindings work, I also suspect that it wouldn't be too hard to plumb. The hardest part would be getting familiar with the project but it's probably a worthwhile investment in any case. Thanks for the quick reply!

tf2spi commented 1 day ago

These are a general list of DIBuilder functions that also don't have C bindings that I found from eyeballing. I'm not sure where these should be documented or if documenting these cases would be desirable right now.

llvm::DIBuilder::createEnumerator
  - APSInt
llvm::DIBuilder::createStringType
llvm::DIBuilder::createPtrAuthQualifiedType
llvm::DIBuilder::createTemplateAlias
llvm::DIBuilder::createFriend
llvm::DIBuilder::createVariantMemberType
llvm::DIBuilder::createVariantPart
llvm::DIBuilder::createTemplateTypeParameter
llvm::DIBuilder::createTemplateValueParameter
llvm::DIBuilder::createTemplateTemplateParameter
  - TemplateTempleateParameterMetadataKind?
llvm::DIBuilder::createTemplateParameterPack
llvm::DIBuilder::createSetType
llvm::DIBuilder::retainType
llvm::DIBuilder::createUnspecifiedParameter
llvm::DIBuilder::getOrCreateMacroArray
llvm::DIBuilder::getOrCreateGenericSubrange
llvm::DIBuilder::createTempFunctionFwdDecl
llvm::DIBuilder::createMethod
llvm::DIBuilder::createCommonBlock
llvm::DIBuilder::replaceVTableHolder
llvm::DIBuilder::replaceArrays
llvm::DIBuilder::replaceTemporary