Home | History | Annotate | Download | only in testdata
      1 // Copyright (c) 2009, Google Inc.
      2 // All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 //     * Redistributions of source code must retain the above copyright
      9 // notice, this list of conditions and the following disclaimer.
     10 //     * Redistributions in binary form must reproduce the above
     11 // copyright notice, this list of conditions and the following disclaimer
     12 // in the documentation and/or other materials provided with the
     13 // distribution.
     14 //     * Neither the name of Google Inc. nor the names of its
     15 // contributors may be used to endorse or promote products derived from
     16 // this software without specific prior written permission.
     17 //
     18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 // Breakpad test application for Linux. When run, it generates one on-demand
     31 // minidump and then crashes, which should generate an on-crash minidump.
     32 // dump_syms can be used to extract symbol information for use in processing.
     33 
     34 // To build:
     35 // g++ -g -o linux_test_app -I ../../ -L../../client/linux linux_test_app.cc \
     36 //   -lbreakpad
     37 // Add -m32 to build a 32-bit executable, or -m64 for a 64-bit one
     38 // (assuming your environment supports it). Replace -g with -gstabs+ to
     39 // generate an executable with STABS symbols (needs -m32), or -gdwarf-2 for one
     40 // with DWARF symbols (32- or 64-bit)
     41 
     42 #include <stdio.h>
     43 #include <sys/types.h>
     44 #include <unistd.h>
     45 
     46 #include <string>
     47 
     48 #include "client/linux/handler/exception_handler.h"
     49 #include "third_party/lss/linux_syscall_support.h"
     50 
     51 namespace {
     52 
     53 // google_breakpad::MinidumpCallback to invoke after minidump generation.
     54 static bool callback(const char *dump_path, const char *id,
     55                      void *context,
     56                      bool succeeded) {
     57   if (succeeded) {
     58     printf("dump guid is %s\n", id);
     59   } else {
     60     printf("dump failed\n");
     61   }
     62   fflush(stdout);
     63 
     64   return succeeded;
     65 }
     66 
     67 static void CrashFunction() {
     68   int *i = reinterpret_cast<int*>(0x45);
     69   *i = 5;  // crash!
     70 }
     71 
     72 }  // namespace
     73 
     74 int main(int argc, char **argv) {
     75   google_breakpad::ExceptionHandler eh(".", NULL, callback, NULL, true);
     76   if (!eh.WriteMinidump()) {
     77     printf("Failed to generate on-demand minidump\n");
     78   }
     79   CrashFunction();
     80   printf("did not crash?\n");
     81   return 0;
     82 }
     83