1 //===-- WindowsMiniDump.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This function is separated out from ObjectFilePECOFF.cpp to name avoid name
11 // collisions with WinAPI preprocessor macros.
13 #include "WindowsMiniDump.h"
14 #include "lldb/Host/FileSpec.h"
15 #include "llvm/Support/ConvertUTF.h"
18 #include "lldb/Host/windows/windows.h"
19 #include <dbghelp.h> // for MiniDumpWriteDump
22 namespace lldb_private {
24 bool SaveMiniDump(const lldb::ProcessSP &process_sp,
25 const lldb_private::FileSpec &outfile,
26 lldb_private::Error &error) {
30 HANDLE process_handle = ::OpenProcess(
31 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_sp->GetID());
32 const std::string file_name = outfile.GetCString();
33 std::wstring wide_name;
34 wide_name.resize(file_name.size() + 1);
35 char *result_ptr = reinterpret_cast<char *>(&wide_name[0]);
36 const llvm::UTF8 *error_ptr = nullptr;
37 if (!llvm::ConvertUTF8toWide(sizeof(wchar_t), file_name, result_ptr,
39 error.SetErrorString("cannot convert file name");
43 ::CreateFileW(wide_name.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL,
44 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
46 ::MiniDumpWriteDump(process_handle, process_sp->GetID(), file_handle,
47 MiniDumpWithFullMemoryInfo, NULL, NULL, NULL);
48 ::CloseHandle(file_handle);
49 ::CloseHandle(process_handle);
51 error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
59 } // namesapce lldb_private