diff options
author | Zejun Wu <watashi@fb.com> | 2018-12-11 13:18:03 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-12-11 13:18:15 -0500 |
commit | 0136906c9e69b02cd1ffe2704fa5d737d8c4cfaf (patch) | |
tree | fadb44152e6ef39ec28a0a95169b417b982ae2d8 /rts | |
parent | 0ff5ecfbc543d80d1668fec460df90b98d563898 (diff) | |
download | haskell-0136906c9e69b02cd1ffe2704fa5d737d8c4cfaf.tar.gz |
Fix uninformative hp2ps error when the cmdline contains double quotes
Reapply D5346 with fix incompatible shell quoting in tests. It seems
like `$'string'` is not recognized under all test environments, so let's
avoid it in tests.
Test Plan:
```
hp2ps: "T15904".hp, line 2: integer must follow identifier
```
use new ghc and hp2ps to profile a simple program.
Reviewers: simonmar, bgamari, erikd, tdammers
Reviewed By: bgamari
Subscribers: tdammers, carter, rwbarton
GHC Trac Issues: #15904
Differential Revision: https://phabricator.haskell.org/D5388
Diffstat (limited to 'rts')
-rw-r--r-- | rts/ProfHeap.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c index de3d2b6aa5..517702f241 100644 --- a/rts/ProfHeap.c +++ b/rts/ProfHeap.c @@ -361,6 +361,18 @@ void endProfiling( void ) #endif /* !PROFILING */ static void +printEscapedString(const char* string) +{ + for (const char* p = string; *p != '\0'; ++p) { + if (*p == '\"') { + // Escape every " as "" + fputc('"', hp_file); + } + fputc(*p, hp_file); + } +} + +static void printSample(bool beginSample, StgDouble sampleValue) { fprintf(hp_file, "%s %f\n", @@ -428,16 +440,18 @@ initHeapProfiling(void) initEra( &censuses[era] ); /* initProfilingLogFile(); */ - fprintf(hp_file, "JOB \"%s", prog_name); + fprintf(hp_file, "JOB \""); + printEscapedString(prog_name); #if defined(PROFILING) - { - int count; - for(count = 1; count < prog_argc; count++) - fprintf(hp_file, " %s", prog_argv[count]); - fprintf(hp_file, " +RTS"); - for(count = 0; count < rts_argc; count++) - fprintf(hp_file, " %s", rts_argv[count]); + for (int i = 1; i < prog_argc; ++i) { + fputc(' ', hp_file); + printEscapedString(prog_argv[i]); + } + fprintf(hp_file, " +RTS"); + for (int i = 0; i < rts_argc; ++i) { + fputc(' ', hp_file); + printEscapedString(rts_argv[i]); } #endif /* PROFILING */ |