explorer: Handle /select arguments correctly with the new winefile
[wine] / programs / winedbg / tgt_minidump.c
1 /*
2  * Wine debugger - minidump handling
3  *
4  * Copyright 2005 Eric Pouech
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23
24 #include "config.h"
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdarg.h>
30
31 #include "debugger.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "tlhelp32.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
38
39 void minidump_write(const char* file, const EXCEPTION_RECORD* rec)
40 {
41     HANDLE                              hFile;
42     MINIDUMP_EXCEPTION_INFORMATION      mei;
43     EXCEPTION_POINTERS                  ep;
44     DWORD                               wine_opt;
45
46     hFile = CreateFile(file, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
47                        FILE_ATTRIBUTE_NORMAL, NULL);
48
49     if (hFile == INVALID_HANDLE_VALUE) return;
50
51     if (rec)
52     {
53         mei.ThreadId = dbg_curr_thread->tid;
54         mei.ExceptionPointers = &ep;
55         ep.ExceptionRecord = (EXCEPTION_RECORD*)rec;
56         ep.ContextRecord = &dbg_context;
57         mei.ClientPointers = FALSE;
58     }
59     /* this is a wine specific options to return also ELF modules in the
60      * dumping
61      */
62     SymSetOptions((wine_opt = SymGetOptions()) | 0x40000000);
63     MiniDumpWriteDump(dbg_curr_process->handle, dbg_curr_process->pid,
64                       hFile, MiniDumpNormal/*|MiniDumpWithDataSegs*/,
65                       rec ? &mei : NULL, NULL, NULL);
66     SymSetOptions(wine_opt);
67     CloseHandle(hFile);
68 }