aprantl created this revision.
aprantl added reviewers: dblaikie, echristo.
aprantl added a subscriber: cfe-commits.
aprantl set the repository for this revision to rL LLVM.

This patch adds a -gmodules option to the driver and a -dwarf-ext-refs to cc1 
to enable the use of external type references in the debug info (a.k.a. module 
debugging).

The driver expands -gmodules to "-g -fmodule-format=obj -dwarf-ext-refs" and 
passes that to cc1.
Most options that start with -g (e.g., -gdwarf-2) also turn on -g, and module 
requires object-container-wrapped modules, "-dwarf-ext-refs" been the actual 
low-level option for turning on external type references.

Rationale for the choice of names (and this is really all there is to review in 
this patch):
"-gmodules": is meant to pair nicely with "-fmodules"
"-dwarf-ext-refs": Fits into the naming scheme of similar options like 
"-dwarf-column-info" and "-dwarf-debug-flags". Spelling out the option 
"-dwarf-external-type-references" seemed to be overkill.

All this does at the moment is set a flag codegenopts. Having this flag in 
place is a prerequisite for emitting debug info into modules: The debug info 
for a module needs to use external type references for types defined in (other) 
modules or we would violate the minimal deserialization requirements (cf. 
test/PCH/check-deserializations.cpp).

Repository:
  rL LLVM

http://reviews.llvm.org/D11958

Files:
  docs/CommandGuide/clang.rst
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===================================================================
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -77,6 +77,9 @@
 //
 // RUN: %clang -### -g %s 2>&1 | FileCheck -check-prefix=CI %s
 //
+// RUN: %clang -### -gmodules %s 2>&1 \
+// RUN:        | FileCheck -check-prefix=GEXTREFS %s
+//
 // G: "-cc1"
 // G: "-g"
 //
@@ -126,3 +129,5 @@
 // CI: "-dwarf-column-info"
 //
 // NOCI-NOT: "-dwarf-column-info"
+//
+// GEXTREFS: "-g" "-dwarf-ext-refs" "-fmodule-format=obj"
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -424,6 +424,7 @@
     Opts.DwarfVersion = 3;
   else if (Args.hasArg(OPT_gdwarf_4))
     Opts.DwarfVersion = 4;
+  Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
 
   if (const Arg *A =
           Args.getLastArg(OPT_emit_llvm_uselists, OPT_no_emit_llvm_uselists))
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3702,6 +3702,12 @@
     CmdArgs.push_back("-dwarf-column-info");
 
   // FIXME: Move backend command line options to the module.
+  if (Args.hasArg(options::OPT_gmodules)) {
+    CmdArgs.push_back("-g");
+    CmdArgs.push_back("-dwarf-ext-refs");
+    CmdArgs.push_back("-fmodule-format=obj");
+  }
+
   // -gsplit-dwarf should turn on -g and enable the backend dwarf
   // splitting and extraction.
   // FIXME: Currently only works on Linux.
Index: lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===================================================================
--- lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -64,6 +64,7 @@
     // ThreadModel, but the backend expects them to be nonempty.
     CodeGenOpts.CodeModel = "default";
     CodeGenOpts.ThreadModel = "single";
+    CodeGenOpts.DebugTypeExtRefs = true;
     CodeGenOpts.setDebugInfo(CodeGenOptions::FullDebugInfo);
     CodeGenOpts.SplitDwarfFile = OutputFileName;
   }
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -52,6 +52,7 @@
   friend class SaveAndRestoreLocation;
   CodeGenModule &CGM;
   const CodeGenOptions::DebugInfoKind DebugKind;
+  bool DebugTypeExtRefs;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   SourceLocation CurLoc;
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -45,6 +45,7 @@
 
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
     : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
+      DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
       DBuilder(CGM.getModule()) {
   CreateCompileUnit();
 }
Index: include/clang/Frontend/CodeGenOptions.def
===================================================================
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -161,6 +161,9 @@
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
                                   ///< in debug info.
 
+CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain
+                                   ///< external references to a PCH or module.
+
 CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.
 
 /// The user specified number of registers to be used for integral arguments,
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1133,6 +1133,9 @@
 def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group<g_flags_Group>;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>;
 def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group<g_flags_Group>;
+def gmodules : Flag <["-"], "gmodules">, Group<f_Group>,
+  HelpText<"Generate debug info with external references to clang modules"
+           " or precompiled headers">;
 def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
   HelpText<"Display available options">;
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -166,6 +166,9 @@
   HelpText<"Emit newer GNU style pubnames">;
 def arange_sections : Flag<["-"], "arange_sections">,
   HelpText<"Emit DWARF .debug_arange sections">;
+def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">,
+  HelpText<"Generate debug info with external references to clang modules"
+           " or precompiled headers">;
 def fforbid_guard_variables : Flag<["-"], "fforbid-guard-variables">,
   HelpText<"Emit an error if a C++ static local initializer would need a guard variable">;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,
Index: docs/CommandGuide/clang.rst
===================================================================
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -257,6 +257,13 @@
 
   Generate debug information.  Note that Clang debug information works best at -O0.
 
+.. option:: -gmodules
+
+  Generate debug information that contains external references to
+  types defined in clang modules or precompiled headers instead of
+  emitting redundant debug type information into every object file.
+  This option implies `-fmodule-format=obj`.
+  
 .. option:: -fstandalone-debug -fno-standalone-debug
 
   Clang supports a number of optimizations to reduce the size of debug
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to