/thirdparty/breakpad/client/windows/crash_generation/minidump_generator.h

http://github.com/tomahawk-player/tomahawk · C Header · 135 lines · 55 code · 23 blank · 57 comment · 0 complexity · e1bdb2d9cf24a81ff52865ac1d353d2d MD5 · raw file

  1. // Copyright (c) 2008, 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. #ifndef CLIENT_WINDOWS_CRASH_GENERATION_MINIDUMP_GENERATOR_H_
  30. #define CLIENT_WINDOWS_CRASH_GENERATION_MINIDUMP_GENERATOR_H_
  31. #include <windows.h>
  32. #include <dbghelp.h>
  33. #include <list>
  34. #include "google_breakpad/common/minidump_format.h"
  35. namespace google_breakpad {
  36. // Abstraction for various objects and operations needed to generate
  37. // minidump on Windows. This abstraction is useful to hide all the gory
  38. // details for minidump generation and provide a clean interface to
  39. // the clients to generate minidumps.
  40. class MinidumpGenerator {
  41. public:
  42. // Creates an instance with the given dump path.
  43. explicit MinidumpGenerator(const std::wstring& dump_path);
  44. ~MinidumpGenerator();
  45. // Writes the minidump with the given parameters. Stores the
  46. // dump file path in the dump_path parameter if dump generation
  47. // succeeds.
  48. bool WriteMinidump(HANDLE process_handle,
  49. DWORD process_id,
  50. DWORD thread_id,
  51. DWORD requesting_thread_id,
  52. EXCEPTION_POINTERS* exception_pointers,
  53. MDRawAssertionInfo* assert_info,
  54. MINIDUMP_TYPE dump_type,
  55. bool is_client_pointers,
  56. std::wstring* dump_path);
  57. // Writes the minidump with the given parameters. Stores the dump file
  58. // path in the dump_path (and full_dump_path) parameter if dump
  59. // generation succeeds. full_dump_path and dump_path can be NULL.
  60. bool WriteMinidump(HANDLE process_handle,
  61. DWORD process_id,
  62. DWORD thread_id,
  63. DWORD requesting_thread_id,
  64. EXCEPTION_POINTERS* exception_pointers,
  65. MDRawAssertionInfo* assert_info,
  66. MINIDUMP_TYPE dump_type,
  67. bool is_client_pointers,
  68. std::wstring* dump_path,
  69. std::wstring* full_dump_path);
  70. private:
  71. // Function pointer type for MiniDumpWriteDump, which is looked up
  72. // dynamically.
  73. typedef BOOL (WINAPI* MiniDumpWriteDumpType)(
  74. HANDLE hProcess,
  75. DWORD ProcessId,
  76. HANDLE hFile,
  77. MINIDUMP_TYPE DumpType,
  78. CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
  79. CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
  80. CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
  81. // Function pointer type for UuidCreate, which is looked up dynamically.
  82. typedef RPC_STATUS (RPC_ENTRY* UuidCreateType)(UUID* Uuid);
  83. // Loads the appropriate DLL lazily in a thread safe way.
  84. HMODULE GetDbghelpModule();
  85. // Loads the appropriate DLL and gets a pointer to the MiniDumpWriteDump
  86. // function lazily and in a thread-safe manner.
  87. MiniDumpWriteDumpType GetWriteDump();
  88. // Loads the appropriate DLL lazily in a thread safe way.
  89. HMODULE GetRpcrt4Module();
  90. // Loads the appropriate DLL and gets a pointer to the UuidCreate
  91. // function lazily and in a thread-safe manner.
  92. UuidCreateType GetCreateUuid();
  93. // Returns the path for the file to write dump to.
  94. bool GenerateDumpFilePath(std::wstring* file_path);
  95. // Handle to dynamically loaded DbgHelp.dll.
  96. HMODULE dbghelp_module_;
  97. // Pointer to the MiniDumpWriteDump function.
  98. MiniDumpWriteDumpType write_dump_;
  99. // Handle to dynamically loaded rpcrt4.dll.
  100. HMODULE rpcrt4_module_;
  101. // Pointer to the UuidCreate function.
  102. UuidCreateType create_uuid_;
  103. // Folder path to store dump files.
  104. std::wstring dump_path_;
  105. // Critical section to sychronize action of loading modules dynamically.
  106. CRITICAL_SECTION module_load_sync_;
  107. // Critical section to synchronize action of dynamically getting function
  108. // addresses from modules.
  109. CRITICAL_SECTION get_proc_address_sync_;
  110. };
  111. } // namespace google_breakpad
  112. #endif // CLIENT_WINDOWS_CRASH_GENERATION_MINIDUMP_GENERATOR_H_