Hello All,
I’m trying to build a list of macros in a compilation unit using CU->getMacros().
I do not see the macros field in DICompileUnit output.
https://godbolt.org/z/b8cM1Yf7v
Please let me know what I’m missing.
Many Thanks.
Hello All,
I’m trying to build a list of macros in a compilation unit using CU->getMacros().
I do not see the macros field in DICompileUnit output.
https://godbolt.org/z/b8cM1Yf7v
Please let me know what I’m missing.
Many Thanks.
Add -fdebug-macro
Thanks David for the helpful information. Is there a way to filter the predefined macros such as clang, GNUC, etc.
I could not get the macros defined in my C code with the below code:
DIMacroNodeArray Macros = DICompUnit->getMacros();
for (auto *MN : Macros) {
if (auto *M = dyn_cast(MN)) {
outs()<< M->getName();
}
}
You could check where the macro is defined, I guess?
If it's in a DIMacroFile i guess it's not a compiler builtin. It might
still be from a system header, etc, if that matters to you - so then
you'd have to filter by the DIMacroFile's 'file' attribute.
Thanks a lot! It works.
Also there is no IR code generated for macros. Is there a way to relate llvm::value’s that refer to macros.
Many Thanks.
Thanks a lot! It works.
Also there is no IR code generated for macros. Is there a way to relate llvm::value's that refer to macros.
Not that I know of, no. If you're interested in doing source analysis
like this - you might want to use a Clang Tool rather than debug info:
https://clang.llvm.org/docs/LibTooling.html