1 // Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10 
11 int recbomb(int n);
12 void PrepareBelow(int argc, char *argv[]);
13 extern int DefeatTailOptimizationForCrasher();
DefeatTailOptimizationForBomb()14 int DefeatTailOptimizationForBomb() {
15   return 0;
16 }
17 
main(int argc,char * argv[])18 int main(int argc, char *argv[]) {
19   PrepareBelow(argc, argv);
20   return recbomb(16) + DefeatTailOptimizationForCrasher();
21 }
22 
23 // Prepare for doing the crash, but do it below main so that main's
24 // line numbers remain stable.
PrepareBelow(int argc,char * argv[])25 void PrepareBelow(int argc, char *argv[]) {
26   fprintf(stderr, "pid=%lld\n", static_cast<long long>(getpid()));
27   fflush(stderr);
28   if (argc == 2 && strcmp(argv[1], "--nocrash") == 0) {
29     fprintf(stderr, "Doing normal exit\n");
30     // Just exit with an error code if requested, to test that
31     // CrashDumper cleanup does not cause troubles.
32     exit(0);
33   }
34   fprintf(stderr, "Crashing as requested.\n");
35 }
36