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

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 9 16:52:36 PST 2019


dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

In D70696#1774931 <https://reviews.llvm.org/D70696#1774931>, @Jac1494 wrote:

> For some real life case like below we need debuginfo for declaration of global extern variable .
>
> $cat shlib.c
>  int var;
>  int test()
>  { return var++; }
>
> $cat test.c
>  extern int test();
>  extern int var;
>  int main()
>  { var++; printf("%d\n",test()); }
>
> If we debug above case with gdb it is not giving types of variable var.
>  Because of no variable DIE is there in executable.
>
> (gdb) b main
>  Breakpoint 1 at 0x40063c: file test.c, line 4.
>  (gdb) pt var
>  type = <data variable, no debug info>


Sounds like this is if you build shlib without debug info?

If you build shlib with debug info, it seems to be fine:

  $ clang-tot -shared -o libshlib.so shlib.c -fpic -g
  $ clang-tot test.c -lshlib -g -L.
  $ LD_LIBRARY_PATH=. gdb ./a.out
  (gdb) start
  Temporary breakpoint 1, main () at test.c:4
  4       { var++; printf("%d\n",test()); }
  (gdb) pt var
  type = int
  (gdb) 

This is the same as if the code were compiled statically & one test.c was compiled with debug info but shlib.c was compiled without debug info - the shared-library-ness doesn't change this situation.

-fstandalone-debug is the flag to use if parts of the program are built without debug info. Yes, that could be used to add global variable declaration to the DWARF & currently isn't - but I think that's a sufficiently nuanced/separate feature built on top of the work in this patch that it should be done separately, rather than trying to have all the design discussion for that in this code review.

This looks fine to me - I think a lot of the testing probably isn't testing "interesting" cases, but up to you.



================
Comment at: clang/test/CodeGen/debug-info-extern-basic.c:14-23
+extern int (*foo)(int);
+int test3() {
+  return foo(0);
+}
+
+int test4() {
+  extern int (*foo2)(int);
----------------
What do these tests add? What sort of bugs would be caught by these global function pointer tests that wouldn't be caught by the char tests above them?


================
Comment at: clang/test/CodeGen/debug-info-extern-duplicate.c:4-38
+extern char ch;
+extern char ch;
+int test() {
+  return ch;
+}
+
+extern char ch2;
----------------
Similarly - are these covering novel/distinct codepaths from the other tests? Are there codepaths that are different for multiple declarations?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696





More information about the llvm-commits mailing list