aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-28 22:45:25 +0000
committerChris Lattner <sabre@nondot.org>2003-10-28 22:45:25 +0000
commitd09bef4d46224d4f8283033ed79903c7a7d01111 (patch)
treed1f712804678a33d878d7fe6c970795081111c24
parentc0204e0b730c8aea661d6ff0fd504f45959e51e2 (diff)
Actually save and pass in argument information
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9564 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--runtime/libprofile/CommonProfiling.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/runtime/libprofile/CommonProfiling.c b/runtime/libprofile/CommonProfiling.c
index e5cfbe3b78..b88ea9cf8b 100644
--- a/runtime/libprofile/CommonProfiling.c
+++ b/runtime/libprofile/CommonProfiling.c
@@ -19,24 +19,31 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
-static int SavedArgc = 0;
-static const char **SavedArgv = 0;
+static char *SavedArgs = 0;
+static unsigned SavedArgsLength = 0;
/* save_arguments - Save argc and argv as passed into the program for the file
* we output.
*/
void save_arguments(int argc, const char **argv) {
- if (SavedArgv) return; /* This can be called multiple times */
+ unsigned Length, i;
+ if (SavedArgs || !argv) return; /* This can be called multiple times */
- /* FIXME: this should copy the arguments out of argv into a string of our own,
- * because the program might modify the arguments!
- */
- SavedArgc = argc;
- SavedArgv = argv;
-}
+ for (Length = 0, i = 0; i != (unsigned)argc; ++i)
+ Length += strlen(argv[i])+1;
+ SavedArgs = (char*)malloc(Length);
+ for (Length = 0, i = 0; i != (unsigned)argc; ++i) {
+ unsigned Len = strlen(argv[i]);
+ memcpy(SavedArgs+Length, argv[i], Len);
+ Length += Len;
+ SavedArgs[Length++] = ' ';
+ }
+ SavedArgsLength = Length;
+}
/* write_profiling_data - Write a raw block of profiling counters out to the
@@ -62,16 +69,14 @@ void write_profiling_data(enum ProfilingType PT, unsigned *Start,
/* Output the command line arguments to the file. */
{
- const char *Args = "";
int PTy = Arguments;
- int ArgLength = strlen(Args);
int Zeros = 0;
write(OutFile, &PTy, sizeof(int));
- write(OutFile, &ArgLength, sizeof(int));
- write(OutFile, Args, ArgLength);
+ write(OutFile, &SavedArgsLength, sizeof(unsigned));
+ write(OutFile, SavedArgs, SavedArgsLength);
/* Pad out to a multiple of four bytes */
- if (ArgLength & 3)
- write(OutFile, &Zeros, 4-(ArgLength&3));
+ if (SavedArgsLength & 3)
+ write(OutFile, &Zeros, 4-(SavedArgsLength&3));
}
}