in rts/RtsFlags.c [618:731]
void setupRtsFlags (int *argc, char *argv[], RtsConfig rts_config)
{
uint32_t mode;
uint32_t total_arg;
uint32_t arg, rts_argc0;
rtsConfig = rts_config;
setProgName (argv);
total_arg = *argc;
arg = 1;
if (*argc > 1) { *argc = 1; };
rts_argc = 0;
rts_argv_size = total_arg + 1;
rts_argv = stgMallocBytes(rts_argv_size * sizeof (char *), "setupRtsFlags");
rts_argc0 = rts_argc;
// process arguments from the -with-rtsopts compile-time flag first
// (arguments from the GHCRTS environment variable and the command
// line override these).
{
if (rtsConfig.rts_opts != NULL) {
splitRtsFlags(rtsConfig.rts_opts);
// opts from rts_opts are always enabled:
procRtsOpts(rts_argc0, RtsOptsAll);
rts_argc0 = rts_argc;
}
}
// process arguments from the GHCRTS environment variable next
// (arguments from the command line override these).
// If we ignore all non-builtin rtsOpts we skip these.
if(rtsConfig.rts_opts_enabled != RtsOptsIgnoreAll)
{
char *ghc_rts = getenv("GHCRTS");
if (ghc_rts != NULL) {
if (rtsConfig.rts_opts_enabled == RtsOptsNone) {
errorRtsOptsDisabled(
"Warning: Ignoring GHCRTS variable as RTS options are disabled.\n %s");
// We don't actually exit, just warn
} else {
splitRtsFlags(ghc_rts);
procRtsOpts(rts_argc0, rtsConfig.rts_opts_enabled);
rts_argc0 = rts_argc;
}
}
}
// If we ignore all commandline rtsOpts we skip processing of argv by
// the RTS completely
if(!(rtsConfig.rts_opts_enabled == RtsOptsIgnoreAll ||
rtsConfig.rts_opts_enabled == RtsOptsIgnore)
)
{
// Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
// argv[0] must be PGM argument -- leave in argv
//
for (mode = PGM; arg < total_arg; arg++) {
// The '--RTS' argument disables all future
// +RTS ... -RTS processing.
if (strequal("--RTS", argv[arg])) {
arg++;
break;
}
// The '--' argument is passed through to the program, but
// disables all further +RTS ... -RTS processing.
else if (strequal("--", argv[arg])) {
break;
}
else if (strequal("+RTS", argv[arg])) {
mode = RTS;
}
else if (strequal("-RTS", argv[arg])) {
mode = PGM;
}
else if (mode == RTS) {
appendRtsArg(copyArg(argv[arg]));
}
else {
argv[(*argc)++] = argv[arg];
}
}
}
// process remaining program arguments
for (; arg < total_arg; arg++) {
argv[(*argc)++] = argv[arg];
}
argv[*argc] = (char *) 0;
procRtsOpts(rts_argc0, rtsConfig.rts_opts_enabled);
appendRtsArg((char *)0);
rts_argc--; // appendRtsArg will have bumped it for the NULL (#7227)
normaliseRtsOpts();
setProgArgv(*argc, argv);
if (RtsFlags.GcFlags.statsFile != NULL) {
initStatsFile (RtsFlags.GcFlags.statsFile);
}
#if defined(TICKY_TICKY)
if (RtsFlags.TickyFlags.tickyFile != NULL) {
initStatsFile (RtsFlags.TickyFlags.tickyFile);
}
#endif
}