r180628 - [driver] Implement the -fdebug-compilation-dir in a way that is compatible with

Chad Rosier mcrosier at apple.com
Fri Apr 26 14:49:32 PDT 2013


For the record, this commit has caused the gdb.base/fullname.exp test to unexpectedly pass two of the xfailed tests.
The xfail was removed in r180640.
 
On Apr 26, 2013, at 1:49 PM, Chad Rosier <mcrosier at apple.com> wrote:

> Author: mcrosier
> Date: Fri Apr 26 15:49:50 2013
> New Revision: 180628
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=180628&view=rev
> Log:
> [driver] Implement the -fdebug-compilation-dir in a way that is compatible with
> gcc.  No test case included as I'm having problems finding a test case where
> the inode/dev don't match.
> 
> Modified:
>    cfe/trunk/lib/Driver/Tools.cpp
>    cfe/trunk/test/Driver/debug-comp-dir.S
>    cfe/trunk/test/Driver/debug.c
> 
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=180628&r1=180627&r2=180628&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Fri Apr 26 15:49:50 2013
> @@ -7,6 +7,9 @@
> //
> //===----------------------------------------------------------------------===//
> 
> +#include <sys/param.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> #include "Tools.h"
> #include "InputInfo.h"
> #include "SanitizerArgs.h"
> @@ -1776,14 +1779,24 @@ static bool shouldUseLeafFramePointer(co
> /// If the PWD environment variable is set, add a CC1 option to specify the
> /// debug compilation directory.
> static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
> -  if (const char *pwd = ::getenv("PWD")) {
> -    // GCC also verifies that stat(pwd) and stat(".") have the same inode
> -    // number. Not doing those because stats are slow, but we could.
> -    if (llvm::sys::path::is_absolute(pwd)) {
> -      std::string CompDir = pwd;
> -      CmdArgs.push_back("-fdebug-compilation-dir");
> -      CmdArgs.push_back(Args.MakeArgString(CompDir));
> -    }
> +  struct stat StatPWDBuf, StatDotBuf;
> +
> +  const char *pwd;
> +  if ((pwd = ::getenv("PWD")) != 0 &&
> +      llvm::sys::path::is_absolute(pwd) &&
> +      stat(pwd, &StatPWDBuf) == 0 &&
> +      stat(".", &StatDotBuf) == 0 &&
> +      StatPWDBuf.st_ino == StatDotBuf.st_ino &&
> +      StatPWDBuf.st_dev == StatDotBuf.st_dev) {
> +    CmdArgs.push_back("-fdebug-compilation-dir");
> +    CmdArgs.push_back(Args.MakeArgString(pwd));
> +    return;
> +  }
> +  // Fall back to using getcwd.
> +  char cwd[MAXPATHLEN];
> +  if (pwd && ::getcwd(cwd, MAXPATHLEN)) {
> +    CmdArgs.push_back("-fdebug-compilation-dir");
> +    CmdArgs.push_back(Args.MakeArgString(cwd));
>   }
> }
> 
> 
> Modified: cfe/trunk/test/Driver/debug-comp-dir.S
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug-comp-dir.S?rev=180628&r1=180627&r2=180628&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/debug-comp-dir.S (original)
> +++ cfe/trunk/test/Driver/debug-comp-dir.S Fri Apr 26 15:49:50 2013
> @@ -1,9 +1,6 @@
> // RUN: cd %S && %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-PWD %s
> // CHECK-PWD: {{"-fdebug-compilation-dir" ".*Driver.*"}}
> 
> -// RUN: env PWD=/foo %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-FOO %s
> -// CHECK-FOO: {{"-fdebug-compilation-dir" ".*foo"}}
> -
> // "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different
> // path to the same directory (try a symlink).
> 
> 
> Modified: cfe/trunk/test/Driver/debug.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug.c?rev=180628&r1=180627&r2=180628&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/debug.c (original)
> +++ cfe/trunk/test/Driver/debug.c Fri Apr 26 15:49:50 2013
> @@ -1,9 +1,6 @@
> // RUN: cd %S && %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-PWD %s
> // CHECK-PWD: {{"-fdebug-compilation-dir" ".*Driver.*"}}
> 
> -// RUN: env PWD=/foo %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-FOO %s
> -// CHECK-FOO: {{"-fdebug-compilation-dir" ".*foo"}}
> -
> // "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different
> // path to the same directory (try a symlink).
> 
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130426/fc1ac501/attachment.html>


More information about the cfe-commits mailing list