File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include " nix/cmd/command.hh"
2+
3+ using namespace nix ;
4+
5+ struct CmdCrash : Command
6+ {
7+ std::string type;
8+
9+ CmdCrash ()
10+ {
11+ expectArg (" type" , &type);
12+ }
13+
14+ Category category () override
15+ {
16+ return catUndocumented;
17+ }
18+
19+ std::string description () override
20+ {
21+ return " crash the program to test crash reporting" ;
22+ }
23+
24+ void run () override
25+ {
26+ if (type == " segfault" ) {
27+ printError (" Triggering a segfault..." );
28+ volatile int * p = nullptr ;
29+ *p = 123 ;
30+ }
31+
32+ else if (type == " assert" ) {
33+ printError (" Triggering an assertion failure..." );
34+ assert (false && " This is an assertion failure" );
35+ }
36+
37+ else if (type == " logic-error" ) {
38+ printError (" Triggering a C++ logic error..." );
39+ std::bitset<4 >{" 012" };
40+ }
41+
42+ else {
43+ throw Error (" unknown crash type '%s'" , type);
44+ }
45+ }
46+ };
47+
48+ static auto rCrash = registerCommand<CmdCrash>(" crash" );
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ nix_sources = [ config_priv_h ] + files(
6868 ' config.cc' ,
6969 ' copy.cc' ,
7070 ' crash-handler.cc' ,
71+ ' crash.cc' ,
7172 ' derivation-add.cc' ,
7273 ' derivation-show.cc' ,
7374 ' derivation.cc' ,
You can’t perform that action at this time.
0 commit comments