minidump_generator_test_helper.cc
1 // Copyright 2010 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 // minidump_generator_test_helper.cc: A helper program that 30 // minidump_generator_test.cc can launch to test certain things 31 // that require a separate executable. 32 33 #ifdef HAVE_CONFIG_H 34 #include <config.h> // Must come first 35 #endif 36 37 #include <unistd.h> 38 39 #include "client/mac/handler/exception_handler.h" 40 #include "common/mac/MachIPC.h" 41 42 using google_breakpad::MachPortSender; 43 using google_breakpad::MachReceiveMessage; 44 using google_breakpad::MachSendMessage; 45 using google_breakpad::ReceivePort; 46 47 int main(int argc, char** argv) { 48 if (argc < 2) 49 return 1; 50 51 if (strcmp(argv[1], "crash") != 0) { 52 const int kTimeoutMs = 2000; 53 // Send parent process the task and thread ports. 54 MachSendMessage child_message(0); 55 child_message.AddDescriptor(mach_task_self()); 56 child_message.AddDescriptor(mach_thread_self()); 57 58 MachPortSender child_sender(argv[1]); 59 if (child_sender.SendMessage(child_message, kTimeoutMs) != KERN_SUCCESS) { 60 fprintf(stderr, "Error sending message from child process!\n"); 61 exit(1); 62 } 63 64 // Loop forever. 65 while (true) { 66 sleep(100); 67 } 68 } else if (argc == 3 && strcmp(argv[1], "crash") == 0) { 69 // Instantiate an OOP exception handler 70 google_breakpad::ExceptionHandler eh("", NULL, NULL, NULL, true, argv[2]); 71 // and crash. 72 int *a = (int*)0x42; 73 *a = 1; 74 } 75 76 return 0; 77 }