On Friday 11 of April 2014, Eric Christopher wrote:
> On Fri, Apr 4, 2014 at 9:07 AM, Lubos Lunak <l.lu...@centrum.cz> wrote:
> > On Friday 04 of April 2014, David Blaikie wrote:
> >> Oops, re-add cfe-commits.
> >>
> >> On Fri, Apr 4, 2014 at 8:34 AM, David Blaikie <dblai...@gmail.com> wrote:
> >> > On Fri, Apr 4, 2014 at 8:24 AM, Lubos Lunak <l.lu...@centrum.cz> wrote:
> >> >> changing DW_AT_GNU_dwo_name explicitly after the build, but that
> >> >> seems needlessly complex given that this seems to be exactly what the
> >> >> option does. I don't see why I would be allowed to override any
> >> >> option except for this one.
> >> >
> >> > -Xclang and the underlying driver arguments aren't really a
> >> > stable/guaranteed interface. I'd be more inclined to accept this
> >> > change if it were just for some debugging, but since it sounds like
> >> > you want to rely on it, it's good for us to understand the goal and
> >> > perhaps suggest or provide the best way of achieving it long-term.
> >
> >  It's stable/guaranteed enough for me, and I'd rather have a clean
> > solution that maybe breaks one day than something hackish the whole time.
>
> I'm guessing you mean that the actual output file name differs? I.e.
> some sort of temporary cached file ala ccache that doesn't have the
> same name as the file that you've just compiled?

 Yes. Something like

 clang -c -g -gsplit-dwarf a.cpp

 may end up actually becoming something along the lines of

 clang -c -x c - -g -gsplit-dwarf -o /tmp/fhqtewdsg.o

> The directory ends up 
> being the same here (or can be set with, as you surmised
> -fdebug-compilation-dir).
>
> If so, I don't mind an option to set here necessarily, but would like
> to see it plumbed through and not rely on Xclang options.

 Like this?

-- 
 Lubos Lunak
From 5f6da37c00e66931dc3867d9b5c8af30c803e12a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <l.lu...@centrum.cz>
Date: Fri, 4 Apr 2014 09:12:59 +0200
Subject: [PATCH] -fdebug-compilation-dir and -fsplit-dwarf-file also in the
 driver

This allows overriding the normal values in special cases as such
distributed build systems performing the compilation in a chroot
where the expected locations do not exist.
---
 include/clang/Driver/CC1Options.td  |  4 ----
 include/clang/Driver/Options.td     |  6 ++++++
 lib/Driver/Tools.cpp                | 32 ++++++++++++++++++++------------
 lib/Frontend/CompilerInvocation.cpp |  2 +-
 test/CodeGen/split-debug-filename.c |  7 +++++--
 test/Driver/debug.c                 |  4 ++++
 test/Driver/split-debug.c           |  8 +++++++-
 7 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index e84a20b..3f85c00 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -128,8 +128,6 @@ def disable_llvm_verifier : Flag<["-"], "disable-llvm-verifier">,
   HelpText<"Don't run the LLVM IR verifier pass">;
 def disable_red_zone : Flag<["-"], "disable-red-zone">,
   HelpText<"Do not emit code that uses the red zone.">;
-def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
-  HelpText<"The compilation directory to embed in the debug info.">;
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
 def dwarf_column_info : Flag<["-"], "dwarf-column-info">,
@@ -405,8 +403,6 @@ def fsjlj_exceptions : Flag<["-"], "fsjlj-exceptions">,
   HelpText<"Use SjLj style exceptions">;
 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_wchar : Flag<["-"], "fno-wchar">,
   HelpText<"Disable C++ builtin type wchar_t">;
 def fconstant_string_class : Separate<["-"], "fconstant-string-class">,
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 8d2e368..1477f3d 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -910,6 +910,12 @@ def fdebug_types_section: Flag <["-"], "fdebug-types-section">, Group<f_Group>,
   Flags<[CC1Option]>, HelpText<"Place debug types in their own section (ELF Only)">;
 def fno_debug_types_section: Flag<["-"], "fno-debug-types-section">, Group<f_Group>,
   Flags<[CC1Option]>;
+def fsplit_dwarf_file : Separate<["-"], "fsplit-dwarf-file">, Group<f_Group>,
+  Flags<[CC1Option]>,
+  HelpText<"File name to use for split dwarf debug info">;
+def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">, Group<f_Group>,
+  Flags<[CC1Option]>,
+  HelpText<"The compilation directory to embed in the debug info.">;
 def g_Flag : Flag<["-"], "g">, Group<g_Group>,
   HelpText<"Generate source level debug information">, Flags<[CC1Option]>;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group<g_Group>,
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 94d13b2..2267d15 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2087,6 +2087,11 @@ static bool shouldUseLeafFramePointer(const ArgList &Args,
 
 /// Add a CC1 option to specify the debug compilation directory.
 static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
+  if (Arg *A = Args.getLastArg(options::OPT_fdebug_compilation_dir)) {
+    CmdArgs.push_back("-fdebug-compilation-dir");
+    CmdArgs.push_back(A->getValue());
+    return;
+  }
   SmallString<128> cwd;
   if (!llvm::sys::fs::current_path(cwd)) {
     CmdArgs.push_back("-fdebug-compilation-dir");
@@ -3982,6 +3987,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
 
+  // 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().isOSLinux() &&
+    (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA));
+  const char *SplitDwarfOut;
+  if (SplitDwarf) {
+    CmdArgs.push_back("-fsplit-dwarf-file");
+    if (Arg *A = Args.getLastArg(options::OPT_fsplit_dwarf_file))
+      SplitDwarfOut = Args.MakeArgString(A->getValue());
+    else
+      SplitDwarfOut = SplitDebugName(Args, Inputs);
+    CmdArgs.push_back(SplitDwarfOut);
+  }
+
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
   Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
@@ -4040,18 +4060,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Args.MakeArgString(Flags.str()));
   }
 
-  // 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().isOSLinux() &&
-    (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(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.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
       Output.getType() == types::TY_Object &&
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 9321f89..3fb2eb6 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -336,7 +336,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
       Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo);
   }
   Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info);
-  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_fsplit_dwarf_file);
   if (Args.hasArg(OPT_gdwarf_2))
     Opts.DwarfVersion = 2;
   else if (Args.hasArg(OPT_gdwarf_3))
diff --git a/test/CodeGen/split-debug-filename.c b/test/CodeGen/split-debug-filename.c
index 63970a8..7561fed 100644
--- a/test/CodeGen/split-debug-filename.c
+++ b/test/CodeGen/split-debug-filename.c
@@ -1,7 +1,10 @@
-// RUN: %clang -target x86_64-linux-gnu -gsplit-dwarf -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -gsplit-dwarf -S -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-NOOPTION %s
+// RUN: %clang -target x86_64-linux-gnu -gsplit-dwarf -fsplit-dwarf-file /path/debug.dwo -S -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-OPTION %s
 int main (void) {
   return 0;
 }
 
 // Testing to ensure that the dwo name gets output into the compile unit.
-// CHECK: split-debug-filename.dwo
+// CHECK-NOOPTION: split-debug-filename.dwo
+// CHECK-OPTION: /path/debug.dwo
+// CHECK-NOOPTION-NOT: split-debug-filename.dwo
diff --git a/test/Driver/debug.c b/test/Driver/debug.c
index daf895c..c2e60e4 100644
--- a/test/Driver/debug.c
+++ b/test/Driver/debug.c
@@ -1,4 +1,5 @@
 // RUN: cd %S && %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-PWD %s
+// RUN: %clang -### -g -fdebug-compilation-dir /somewhere/ %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPTION %s
 // CHECK-PWD: {{"-fdebug-compilation-dir" ".*Driver.*"}}
 
 // "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different
@@ -6,3 +7,6 @@
 
 // This depends on host's behavior how $PWD would be set.
 // REQUIRES: shell
+
+// CHECK-OPTION: {{"-fdebug-compilation-dir" "/somewhere/"}}
+// CHECK-OPTION-NOT: {{"-fdebug-compilation-dir" ".*Driver.*"}}
diff --git a/test/Driver/split-debug.c b/test/Driver/split-debug.c
index 792abbd..b0734b3 100644
--- a/test/Driver/split-debug.c
+++ b/test/Driver/split-debug.c
@@ -22,7 +22,13 @@
 // 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"
+// CHECK-OPTION: "-fsplit-dwarf-file" "split-debug.dwo"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -fsplit-dwarf-file madeup.dwo -c -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OPTION-FILE < %t %s
+//
+// CHECK-OPTION-FILE: "-fsplit-dwarf-file" "madeup.dwo"
+// CHECK-OPTION-FILE-NOT: "-fsplit-dwarf-file" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ASM < %t %s
-- 
1.8.4.5

_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to