0

How can I check that -g flag (debug info enable) was set, from my llvm pass that I am writing? I am just trying to see if there is a way to get the command-line options through my pass, including -g.

Kyriakos
  • 757
  • 8
  • 23

1 Answers1

1

When Clang generates LLVM IR, it does not directly record which command-line options were used. However you can easily check whether debug info was enabled by checking for the presence of said debug info.

The simplest approach I can think of is checking for the presence of the !llvm.dbg.cu named metadata node:

bool wasCompiledWithDebugInfo(const Module& M) {
  return M.getNamedMetadata("llvm.dbg.cu") != NULL;
}

That should work for most cases There's one catch - a single Module might actually be composed of multiple compile units linked together, some compiled with debug info and some not. If you don't care about that, then you got your answer.

If you do care, you need to be more specific of what you are really trying to achieve. For instance, if you care about whether a specific function was compiled with debug information, then you should check that function directly (by searching for the DISubprogram metadata describing it) instead of asking about compile units.

Community
  • 1
  • 1
Oak
  • 26,231
  • 8
  • 93
  • 152
  • Thank you Oak! This is what I was thinking. I was just trying to see if there is a way to get the command-line options through my pass, including -g. Its nice because you also point me to one of my older answers in stack overflow :) – Kyriakos Feb 12 '14 at 10:31