diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:10:19 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:10:19 +0000 |
commit | 6de2c08bc400b4aca9fb46684e8bdb56eed9b09f (patch) | |
tree | 32b4679ab4b8f28e5228daafc65e9dc436935353 /runtime/libprofile/CommonProfiling.c | |
parent | 4dc93743c9d40c29c0a3bec2aae328cac0d289e8 (diff) | |
download | FreeBSD-src-6de2c08bc400b4aca9fb46684e8bdb56eed9b09f.zip FreeBSD-src-6de2c08bc400b4aca9fb46684e8bdb56eed9b09f.tar.gz |
Vendor import of llvm release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/llvm/branches/release_32@168974
Diffstat (limited to 'runtime/libprofile/CommonProfiling.c')
-rw-r--r-- | runtime/libprofile/CommonProfiling.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/runtime/libprofile/CommonProfiling.c b/runtime/libprofile/CommonProfiling.c index acc17ce..8f4119c 100644 --- a/runtime/libprofile/CommonProfiling.c +++ b/runtime/libprofile/CommonProfiling.c @@ -28,14 +28,35 @@ static char *SavedArgs = 0; static unsigned SavedArgsLength = 0; +static const char *SavedEnvVar = 0; static const char *OutputFilename = "llvmprof.out"; +/* check_environment_variable - Check to see if the LLVMPROF_OUTPUT environment + * variable is set. If it is then save it and set OutputFilename. + */ +static void check_environment_variable(void) { + const char *EnvVar; + if (SavedEnvVar) return; /* Guarantee that we can't leak memory. */ + + if ((EnvVar = getenv("LLVMPROF_OUTPUT")) != NULL) { + /* The string that getenv returns is allowed to be statically allocated, + * which means it may be changed by future calls to getenv, so copy it. + */ + SavedEnvVar = strdup(EnvVar); + OutputFilename = SavedEnvVar; + } +} + /* save_arguments - Save argc and argv as passed into the program for the file * we output. + * If either the LLVMPROF_OUTPUT environment variable or the -llvmprof-output + * command line argument are set then change OutputFilename to the provided + * value. The command line argument value overrides the environment variable. */ int save_arguments(int argc, const char **argv) { unsigned Length, i; + if (!SavedEnvVar && !SavedArgs) check_environment_variable(); if (SavedArgs || !argv) return argc; /* This can be called multiple times */ /* Check to see if there are any arguments passed into the program for the @@ -54,6 +75,7 @@ int save_arguments(int argc, const char **argv) { puts("-llvmprof-output requires a filename argument!"); else { OutputFilename = strdup(argv[1]); + if (SavedEnvVar) { free((void *)SavedEnvVar); SavedEnvVar = 0; } memmove((char**)&argv[1], &argv[2], (argc-1)*sizeof(char*)); --argc; } |