@@ -1058,6 +1058,17 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
10581058 split (environment, tmpEnv);
10591059 }
10601060
1061+ // / Add libSegFault to the stack if provided.
1062+ if (varmap.count (" stacktrace-on-signal" ) && varmap[" stacktrace-on-signal" ].as <std::string>() != " none" ) {
1063+ char const * preload = getenv (" LD_PRELOAD" );
1064+ if (preload == nullptr ) {
1065+ tmpEnv.push_back (" LD_PRELOAD=libSegFault.so" );
1066+ } else {
1067+ tmpEnv.push_back (fmt::format (" LD_PRELOAD=\" {}:libSegFault.so\" " , preload));
1068+ }
1069+ tmpEnv.push_back (fmt::format (" SEGFAULT_SIGNALS=\" {}\" " , varmap[" stacktrace-on-signal" ].as <std::string>()));
1070+ }
1071+
10611072 // options can be grouped per processor spec, the group is entered by
10621073 // the option created from the actual processor spec name
10631074 // if specified, the following string is interpreted as a sequence
@@ -1074,6 +1085,7 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
10741085 realOdesc.add_options ()(" child-driver" , bpo::value<std::string>());
10751086 realOdesc.add_options ()(" rate" , bpo::value<std::string>());
10761087 realOdesc.add_options ()(" environment" , bpo::value<std::string>());
1088+ realOdesc.add_options ()(" stacktrace-on-signal" , bpo::value<std::string>());
10771089 realOdesc.add_options ()(" post-fork-command" , bpo::value<std::string>());
10781090 realOdesc.add_options ()(" shm-segment-size" , bpo::value<std::string>());
10791091 realOdesc.add_options ()(" shm-mlock-segment" , bpo::value<std::string>());
@@ -1199,6 +1211,8 @@ boost::program_options::options_description DeviceSpecHelpers::getForwardedDevic
11991211 (" shm-throw-bad-alloc" , bpo::value<std::string>()->default_value (" true" ), " throw if insufficient shm memory" ) //
12001212 (" shm-segment-id" , bpo::value<std::string>()->default_value (" 0" ), " shm segment id" ) //
12011213 (" environment" , bpo::value<std::string>(), " comma separated list of environment variables to set for the device" ) //
1214+ (" stacktrace-on-signal" , bpo::value<std::string>()->default_value (" none" ), //
1215+ " dump stacktrace on specified signal(s) (any of `all`, `segv`, `bus`, `ill`, `abrt`, `fpe`, `sys`.)" ) //
12021216 (" post-fork-command" , bpo::value<std::string>(), " post fork command to execute (e.g. numactl {pid}" ) //
12031217 (" session" , bpo::value<std::string>(), " unique label for the shared memory session" ) //
12041218 (" configuration,cfg" , bpo::value<std::string>(), " configuration connection string" ) //
0 commit comments