Split out the command handling for split debug info, we're going
authorEric Christopher <echristo@gmail.com>
Fri, 22 Feb 2013 20:12:52 +0000 (20:12 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 22 Feb 2013 20:12:52 +0000 (20:12 +0000)
to want to propagate some information through the module into
the back end and so need to pass it through to codegen.

Also make the methods file static so we can use them in other places.

llvm-svn: 175916

clang/include/clang/Driver/CC1Options.td
clang/lib/Driver/Tools.cpp
clang/lib/Driver/Tools.h
clang/test/Driver/split-debug.c

index 5e7a551..d1b21fd 100644 (file)
@@ -379,6 +379,8 @@ def fhidden_weak_vtables : Flag<["-"], "fhidden-weak-vtables">,
   HelpText<"Generate weak vtables and RTTI with hidden visibility">;
 def main_file_name : Separate<["-"], "main-file-name">,
   HelpText<"Main file name to use for debug info">;
+def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
+  HelpText<"File name to use for split dwarf debug info output">;
 def fno_signed_char : Flag<["-"], "fno-signed-char">,
   HelpText<"Char is unsigned">;
 def fno_wchar : Flag<["-"], "fno-wchar">,
index 6ba77c2..445ae53 100644 (file)
@@ -1705,11 +1705,27 @@ static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
   }
 }
 
-void Clang::SplitDebugInfo(Compilation &C, const JobAction &JA,
-                           const ArgList &Args,
-                           const InputInfoList &Inputs,
-                           const InputInfo &Output,
-                           const char *LinkingOutput) const {
+static const char *SplitDebugName(const ArgList &Args,
+                                  const InputInfoList &Inputs) {
+  Arg *FinalOutput = Args.getLastArg(options::OPT_o);
+  if (FinalOutput && Args.hasArg(options::OPT_c)) {
+    SmallString<128> T(FinalOutput->getValue());
+    llvm::sys::path::replace_extension(T, "dwo");
+    return Args.MakeArgString(T);
+  } else {
+    // Use the compilation dir.
+    SmallString<128> T(Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
+    SmallString<128> F(llvm::sys::path::stem(Inputs[0].getBaseInput()));
+    llvm::sys::path::replace_extension(F, "dwo");
+    T += F;
+    return Args.MakeArgString(F);
+  }
+}
+
+static void SplitDebugInfo(const ToolChain &TC, Compilation &C,
+                           const Tool &T, const JobAction &JA,
+                           const ArgList &Args, const InputInfo &Output,
+                           const char *OutFile) {
   ArgStringList ExtractArgs;
   ExtractArgs.push_back("--extract-dwo");
 
@@ -1719,31 +1735,16 @@ void Clang::SplitDebugInfo(Compilation &C, const JobAction &JA,
   // Grabbing the output of the earlier compile step.
   StripArgs.push_back(Output.getFilename());
   ExtractArgs.push_back(Output.getFilename());
-
-  // Add an output for the extract.
-  Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
-  const char *OutFile;
-  if (FinalOutput && C.getArgs().hasArg(options::OPT_c)) {
-    SmallString<128> T(FinalOutput->getValue());
-    llvm::sys::path::replace_extension(T, "dwo");
-    OutFile = Args.MakeArgString(T);
-  } else {
-    // Use the compilation dir.
-    SmallString<128> T(Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
-    T += llvm::sys::path::stem(Inputs[0].getBaseInput());
-    llvm::sys::path::replace_extension(T, "dwo");
-    OutFile = Args.MakeArgString(T);
-  }
   ExtractArgs.push_back(OutFile);
 
   const char *Exec =
-    Args.MakeArgString(getToolChain().GetProgramPath("objcopy"));
+    Args.MakeArgString(TC.GetProgramPath("objcopy"));
 
   // First extract the dwo sections.
-  C.addCommand(new Command(JA, *this, Exec, ExtractArgs));
+  C.addCommand(new Command(JA, T, Exec, ExtractArgs));
 
   // Then remove them from the original .o file.
-  C.addCommand(new Command(JA, *this, Exec, StripArgs));
+  C.addCommand(new Command(JA, T, Exec, StripArgs));
 }
 
 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
@@ -3264,15 +3265,25 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Args.MakeArgString(Flags.str()));
   }
 
-  // Finally add the command to the compilation.
+  // Add the split debug info name to the command lines here so we
+  // can propagate it to the backend.
+  bool SplitDwarf = Args.hasArg(options::OPT_gsplit_dwarf) &&
+    (getToolChain().getTriple().getOS() == llvm::Triple::Linux) &&
+    isa<AssembleJobAction>(JA);
+  const char *SplitDwarfOut;
+  if (SplitDwarf) {
+    CmdArgs.push_back("-split-dwarf-file");
+    SplitDwarfOut = SplitDebugName(Args, Inputs);
+    CmdArgs.push_back(SplitDwarfOut);
+  }
+
+  // Finally add the compile command to the compilation.
   C.addCommand(new Command(JA, *this, Exec, CmdArgs));
 
   // Handle the debug info splitting at object creation time.
   // TODO: Currently only works on linux with newer objcopy.
-  if (Args.hasArg(options::OPT_gsplit_dwarf) &&
-      getToolChain().getTriple().getOS() == llvm::Triple::Linux &&
-      isa<AssembleJobAction>(JA))
-    SplitDebugInfo(C, JA, Args, Inputs, Output, LinkingOutput);
+  if (SplitDwarf)
+    SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDwarfOut);
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
     if (Args.hasArg(options::OPT_fomit_frame_pointer))
index 2d7f8b0..f4aebd8 100644 (file)
@@ -54,10 +54,6 @@ namespace tools {
     void AddSparcTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
     void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
     void AddHexagonTargetArgs (const ArgList &Args, ArgStringList &CmdArgs) const;
-    void SplitDebugInfo(Compilation &C, const JobAction &JA,
-                        const ArgList &Args, const InputInfoList &Inputs,
-                        const InputInfo &Output,
-                        const char *LinkingOutput) const;
 
     enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
 
index 5c77e6e..d8a9fe8 100644 (file)
@@ -18,3 +18,8 @@
 // RUN: FileCheck -check-prefix=CHECK-BAD < %t %s
 //
 // CHECK-BAD-NOT: "Bad.dwo"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
+//
+// CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"