r175916 - Split out the command handling for split debug info, we're going

Eric Christopher echristo at gmail.com
Fri Feb 22 12:12:53 PST 2013


Author: echristo
Date: Fri Feb 22 14:12:52 2013
New Revision: 175916

URL: http://llvm.org/viewvc/llvm-project?rev=175916&view=rev
Log:
Split out the command handling for split debug info, we're going
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.

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

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=175916&r1=175915&r2=175916&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Feb 22 14:12:52 2013
@@ -379,6 +379,8 @@ def fhidden_weak_vtables : Flag<["-"], "
   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">,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=175916&r1=175915&r2=175916&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Feb 22 14:12:52 2013
@@ -1705,11 +1705,27 @@ static void addDebugCompDirArg(const Arg
   }
 }
 
-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 &
   // 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,
     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))

Modified: cfe/trunk/lib/Driver/Tools.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=175916&r1=175915&r2=175916&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Fri Feb 22 14:12:52 2013
@@ -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 };
 

Modified: cfe/trunk/test/Driver/split-debug.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/split-debug.c?rev=175916&r1=175915&r2=175916&view=diff
==============================================================================
--- cfe/trunk/test/Driver/split-debug.c (original)
+++ cfe/trunk/test/Driver/split-debug.c Fri Feb 22 14:12:52 2013
@@ -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"





More information about the cfe-commits mailing list