PageRenderTime 20ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/thirdparty/breakpad/processor/testdata/linux_test_app.cc

http://github.com/tomahawk-player/tomahawk
C++ | 82 lines | 32 code | 11 blank | 39 comment | 3 complexity | a13f732f172ccb4ad929a9a5e64d0a6a MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  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. // 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. // To build:
  33. // g++ -g -o linux_test_app -I ../../ -L../../client/linux linux_test_app.cc \
  34. // -lbreakpad
  35. // Add -m32 to build a 32-bit executable, or -m64 for a 64-bit one
  36. // (assuming your environment supports it). Replace -g with -gstabs+ to
  37. // generate an executable with STABS symbols (needs -m32), or -gdwarf-2 for one
  38. // with DWARF symbols (32- or 64-bit)
  39. #include <stdio.h>
  40. #include <sys/types.h>
  41. #include <unistd.h>
  42. #include <string>
  43. #include "client/linux/handler/exception_handler.h"
  44. #include "third_party/lss/linux_syscall_support.h"
  45. namespace {
  46. // google_breakpad::MinidumpCallback to invoke after minidump generation.
  47. static bool callback(const char *dump_path, const char *id,
  48. void *context,
  49. bool succeeded) {
  50. if (succeeded) {
  51. printf("dump guid is %s\n", id);
  52. } else {
  53. printf("dump failed\n");
  54. }
  55. fflush(stdout);
  56. return succeeded;
  57. }
  58. static void CrashFunction() {
  59. int *i = reinterpret_cast<int*>(0x45);
  60. *i = 5; // crash!
  61. }
  62. } // namespace
  63. int main(int argc, char **argv) {
  64. google_breakpad::ExceptionHandler eh(".", NULL, callback, NULL, true);
  65. if (!eh.WriteMinidump()) {
  66. printf("Failed to generate on-demand minidump\n");
  67. }
  68. CrashFunction();
  69. printf("did not crash?\n");
  70. return 0;
  71. }