[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

Sourabh Singh Tomar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 30 05:19:31 PST 2019


SouraVX added a comment.

In D70696#1764043 <https://reviews.llvm.org/D70696#1764043>, @yonghong-song wrote:

> If I remove `!D->isUsed()`, I should be able to generate the debuginfo for `global_var` and eventually in dwarf in your above case.
>  What exactly your use case here for these unused external variables?


I simplified that test case, too much. Obiviously, for a real situation, that global variable must be defined possibly in some different file, which eventually got linked to final executable. Consider this for a moment -
`cat extern.c`

  int global_var = 2;

`cat main.c`

  extern int global_var;
  int main(){
   int local = global_var;
  }

Now for above, clang produce debug info for `gloabal_var` in `extern.c` fine, Not in `main.c` for Declaration of `gloabl_var`. Eventually when producing final binary{a.out}, linker will merge debug_info section of {extern.c and main.c} and we end up with debugging entry in `a.out` , consequently debugger is also seems to be happy with it.

But I think, it would be nice to have a declaration debug entry for `global_var` in file{main.o) debugging information contribution. Because it's using this global variable{declared extern}. like in present case!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70696/new/

https://reviews.llvm.org/D70696





More information about the cfe-commits mailing list