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