1 // Copyright 2009 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 // Breakpad test application for Linux. When run, it generates one on-demand
30 // minidump and then crashes, which should generate an on-crash minidump.
31 // dump_syms can be used to extract symbol information for use in processing.
32
33 // To build:
34 // g++ -g -o linux_test_app -I ../../ -L../../client/linux linux_test_app.cc \
35 // -lbreakpad
36 // Add -m32 to build a 32-bit executable, or -m64 for a 64-bit one
37 // (assuming your environment supports it). Replace -g with -gstabs+ to
38 // generate an executable with STABS symbols (needs -m32), or -gdwarf-2 for one
39 // with DWARF symbols (32- or 64-bit)
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h> // Must come first
43 #endif
44
45 #include <stdio.h>
46 #include <sys/types.h>
47 #include <unistd.h>
48
49 #include <string>
50
51 #include "client/linux/handler/exception_handler.h"
52 #include "third_party/lss/linux_syscall_support.h"
53
54 namespace {
55
56 // google_breakpad::MinidumpCallback to invoke after minidump generation.
callback(const char * dump_path,const char * id,void * context,bool succeeded)57 static bool callback(const char* dump_path, const char* id,
58 void* context,
59 bool succeeded) {
60 if (succeeded) {
61 printf("dump guid is %s\n", id);
62 } else {
63 printf("dump failed\n");
64 }
65 fflush(stdout);
66
67 return succeeded;
68 }
69
CrashFunction()70 static void CrashFunction() {
71 int* i = reinterpret_cast<int*>(0x45);
72 *i = 5; // crash!
73 }
74
75 } // namespace
76
main(int argc,char ** argv)77 int main(int argc, char** argv) {
78 google_breakpad::ExceptionHandler eh(".", NULL, callback, NULL, true);
79 if (!eh.WriteMinidump()) {
80 printf("Failed to generate on-demand minidump\n");
81 }
82 CrashFunction();
83 printf("did not crash?\n");
84 return 0;
85 }
86