1 // Copyright 2008 Google Inc. All Rights Reserved.
2 // Author: satorux@google.com (Satoru Takabayashi)
4 // This is a helper binary for testing signalhandler.cc. The actual test
5 // is done in signalhandler_unittest.sh.
14 #include "glog/logging.h"
16 using namespace GOOGLE_NAMESPACE;
18 void* DieInThread(void*) {
19 fprintf(stderr, "0x%lx is dying\n", pthread_self());
20 // Use volatile to prevent from these to be optimized away.
22 volatile int b = 1 / a;
25 void WriteToStdout(const char* data, int size) {
26 write(STDOUT_FILENO, data, size);
29 int main(int argc, char **argv) {
30 #if defined(HAVE_STACKTRACE) && defined(HAVE_SYMBOLIZE)
31 InitGoogleLogging(argv[0]);
32 #ifdef HAVE_LIB_GFLAGS
33 ParseCommandLineFlags(&argc, &argv, true);
35 InstallFailureSignalHandler();
36 const std::string command = argc > 1 ? argv[1] : "none";
37 if (command == "segv") {
38 // We'll check if this is outputted.
39 LOG(INFO) << "create the log file";
40 LOG(INFO) << "a message before segv";
41 // We assume 0xDEAD is not writable.
42 int *a = (int*)0xDEAD;
44 } else if (command == "loop") {
45 fprintf(stderr, "looping\n");
47 } else if (command == "die_in_thread") {
49 pthread_create(&thread, NULL, &DieInThread, NULL);
50 pthread_join(thread, NULL);
51 } else if (command == "dump_to_stdout") {
52 InstallFailureWriter(WriteToStdout);
55 // Tell the shell script