~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/winedbg/tgt_minidump.c

Version: ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #define NONAMELESSUNION
 22 #define NONAMELESSSTRUCT
 23 
 24 #include "config.h"
 25 #include "wine/port.h"
 26 
 27 #include <stdlib.h>
 28 #include <stdio.h>
 29 #include <string.h>
 30 #include <stdarg.h>
 31 
 32 #include "debugger.h"
 33 #include "wingdi.h"
 34 #include "winuser.h"
 35 #include "tlhelp32.h"
 36 #include "wine/debug.h"
 37 #include "wine/exception.h"
 38 
 39 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
 40 
 41 static struct be_process_io be_process_minidump_io;
 42 
 43 /* we need this function on 32bit hosts to ensure we zero out the higher DWORD
 44  * stored in the minidump file (sometimes it's not cleared, or the conversion from
 45  * 32bit to 64bit wide integers is done as signed, which is wrong)
 46  * So we clamp on 32bit CPUs (as stored in minidump information) all addresses to
 47  * keep only the lower 32 bits.
 48  * FIXME: as of today, since we don't support a backend CPU which is different from
 49  * CPU this process is running on, casting to (DWORD_PTR) will do just fine.
 50  */
 51 static inline DWORD64  get_addr64(DWORD64 addr)
 52 {
 53     return (DWORD_PTR)addr;
 54 }
 55 
 56 void minidump_write(const char* file, const EXCEPTION_RECORD* rec)
 57 {
 58     HANDLE                              hFile;
 59     MINIDUMP_EXCEPTION_INFORMATION      mei;
 60     EXCEPTION_POINTERS                  ep;
 61 
 62     hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
 63                         FILE_ATTRIBUTE_NORMAL, NULL);
 64 
 65     if (hFile == INVALID_HANDLE_VALUE) return;
 66 
 67     if (rec)
 68     {
 69         mei.ThreadId = dbg_curr_thread->tid;
 70         mei.ExceptionPointers = &ep;
 71         ep.ExceptionRecord = (EXCEPTION_RECORD*)rec;
 72         ep.ContextRecord = &dbg_context;
 73         mei.ClientPointers = FALSE;
 74     }
 75     MiniDumpWriteDump(dbg_curr_process->handle, dbg_curr_process->pid,
 76                       hFile, MiniDumpNormal/*|MiniDumpWithDataSegs*/,
 77                       rec ? &mei : NULL, NULL, NULL);
 78     CloseHandle(hFile);
 79 }
 80 
 81 #define Wine_ElfModuleListStream        0xFFF0
 82 
 83 struct tgt_process_minidump_data
 84 {
 85     void*       mapping;
 86     HANDLE      hFile;
 87     HANDLE      hMap;
 88 };
 89 
 90 static inline struct tgt_process_minidump_data* private_data(struct dbg_process* pcs)
 91 {
 92     return pcs->pio_data;
 93 }
 94 
 95 static BOOL tgt_process_minidump_read(HANDLE hProcess, const void* addr,
 96                                       void* buffer, SIZE_T len, SIZE_T* rlen)
 97 {
 98     void*               stream;
 99 
100     if (!private_data(dbg_curr_process)->mapping) return FALSE;
101     if (MiniDumpReadDumpStream(private_data(dbg_curr_process)->mapping,
102                                MemoryListStream, NULL, &stream, NULL))
103     {
104         MINIDUMP_MEMORY_LIST*   mml = stream;
105         MINIDUMP_MEMORY_DESCRIPTOR* mmd = &mml->MemoryRanges[0];
106         int                     i, found = -1;
107         SIZE_T                  ilen, prev_len = 0;
108 
109         /* There's no reason that memory ranges inside a minidump do not overlap.
110          * So be smart when looking for a given memory range (either grab a
111          * range that covers the whole requested area, or if none, the range that
112          * has the largest overlap with requested area)
113          */
114         for (i = 0; i < mml->NumberOfMemoryRanges; i++, mmd++)
115         {
116             if (get_addr64(mmd->StartOfMemoryRange) <= (DWORD_PTR)addr &&
117                 (DWORD_PTR)addr < get_addr64(mmd->StartOfMemoryRange) + mmd->Memory.DataSize)
118             {
119                 ilen = min(len,
120                            get_addr64(mmd->StartOfMemoryRange) + mmd->Memory.DataSize - (DWORD_PTR)addr);
121                 if (ilen == len) /* whole range is matched */
122                 {
123                     found = i;
124                     prev_len = ilen;
125                     break;
126                 }
127                 if (found == -1 || ilen > prev_len) /* partial match, keep largest one */
128                 {
129                     found = i;
130                     prev_len = ilen;
131                 }
132             }
133         }
134         if (found != -1)
135         {
136             mmd = &mml->MemoryRanges[found];
137             memcpy(buffer,
138                    (char*)private_data(dbg_curr_process)->mapping + mmd->Memory.Rva + (DWORD_PTR)addr - get_addr64(mmd->StartOfMemoryRange),
139                    prev_len);
140             if (rlen) *rlen = prev_len;
141             return TRUE;
142         }
143     }
144     /* FIXME: this is a dirty hack to let the last frame in a bt to work
145      * However, we need to check who's to blame, this code or the current 
146      * dbghelp!StackWalk implementation
147      */
148     if ((DWORD_PTR)addr < 32)
149     {
150         memset(buffer, 0, len); 
151         if (rlen) *rlen = len;
152         return TRUE;
153     }
154     return FALSE;
155 }
156 
157 static BOOL tgt_process_minidump_write(HANDLE hProcess, void* addr,
158                                        const void* buffer, SIZE_T len, SIZE_T* wlen)
159 {
160     return FALSE;
161 }
162 
163 static BOOL CALLBACK validate_file(PCWSTR name, void* user)
164 {
165     return FALSE; /* get the first file we find !! */
166 }
167 
168 static BOOL is_pe_module_embedded(struct tgt_process_minidump_data* data,
169                                   MINIDUMP_MODULE* pe_mm)
170 {
171     MINIDUMP_MODULE_LIST*       mml;
172 
173     if (MiniDumpReadDumpStream(data->mapping, Wine_ElfModuleListStream, NULL,
174                                (void**)&mml, NULL))
175     {
176         MINIDUMP_MODULE*        mm;
177         unsigned                i;
178 
179         for (i = 0, mm = &mml->Modules[0]; i < mml->NumberOfModules; i++, mm++)
180         {
181             if (get_addr64(mm->BaseOfImage) <= get_addr64(pe_mm->BaseOfImage) &&
182                 get_addr64(mm->BaseOfImage) + mm->SizeOfImage >= get_addr64(pe_mm->BaseOfImage) + pe_mm->SizeOfImage)
183                 return TRUE;
184         }
185     }
186     return FALSE;
187 }
188 
189 static enum dbg_start minidump_do_reload(struct tgt_process_minidump_data* data)
190 {
191     void*                       stream;
192     DWORD                       pid = 1; /* by default */
193     HANDLE                      hProc = (HANDLE)0x900DBAAD;
194     int                         i;
195     MINIDUMP_MODULE_LIST*       mml;
196     MINIDUMP_MODULE*            mm;
197     MINIDUMP_STRING*            mds;
198     MINIDUMP_DIRECTORY*         dir;
199     WCHAR                       exec_name[1024];
200     WCHAR                       nameW[1024];
201     unsigned                    len;
202     static WCHAR                default_exec_name[] = {'<','m','i','n','i','d','u','m','p','-','e','x','e','c','>',0};
203 
204     /* fetch PID */
205     if (MiniDumpReadDumpStream(data->mapping, MiscInfoStream, NULL, &stream, NULL))
206     {
207         MINIDUMP_MISC_INFO* mmi = stream;
208         if (mmi->Flags1 & MINIDUMP_MISC1_PROCESS_ID)
209             pid = mmi->ProcessId;
210     }
211 
212     /* fetch executable name (it's normally the first one in module list) */
213     lstrcpyW(exec_name, default_exec_name);
214     if (MiniDumpReadDumpStream(data->mapping, ModuleListStream, NULL, &stream, NULL))
215     {
216         mml = stream;
217         if (mml->NumberOfModules)
218         {
219             WCHAR*      ptr;
220 
221             mm = &mml->Modules[0];
222             mds = (MINIDUMP_STRING*)((char*)data->mapping + mm->ModuleNameRva);
223             len = mds->Length / 2;
224             memcpy(exec_name, mds->Buffer, mds->Length);
225             exec_name[len] = 0;
226             for (ptr = exec_name + len - 1; ptr >= exec_name; ptr--)
227             {
228                 if (*ptr == '/' || *ptr == '\\')
229                 {
230                     memmove(exec_name, ptr + 1, (lstrlenW(ptr + 1) + 1) * sizeof(WCHAR));
231                     break;
232                 }
233             }
234         }
235     }
236 
237     if (MiniDumpReadDumpStream(data->mapping, SystemInfoStream, &dir, &stream, NULL))
238     {
239         MINIDUMP_SYSTEM_INFO*   msi = stream;
240         const char *str;
241         char tmp[128];
242 
243         dbg_printf("WineDbg starting on minidump on pid %04x\n", pid);
244         switch (msi->ProcessorArchitecture)
245         {
246         case PROCESSOR_ARCHITECTURE_UNKNOWN:
247             str = "Unknown";
248             break;
249         case PROCESSOR_ARCHITECTURE_INTEL:
250             strcpy(tmp, "Intel ");
251             switch (msi->ProcessorLevel)
252             {
253             case  3: str = "80386"; break;
254             case  4: str = "80486"; break;
255             case  5: str = "Pentium"; break;
256             case  6: str = "Pentium Pro/II or AMD Athlon"; break;
257             case 15: str = "Pentium 4 or AMD Athlon64"; break;
258             default: str = "???"; break;
259             }
260             strcat(tmp, str);
261             if (msi->ProcessorLevel == 3 || msi->ProcessorLevel == 4)
262             {
263                 if (HIBYTE(msi->ProcessorRevision) == 0xFF)
264                     sprintf(tmp + strlen(tmp), " (%c%d)",
265                             'A' + ((msi->ProcessorRevision>>4)&0xf)-0x0a,
266                             ((msi->ProcessorRevision&0xf)));
267                 else
268                     sprintf(tmp + strlen(tmp), " (%c%d)",
269                             'A' + HIBYTE(msi->ProcessorRevision),
270                             LOBYTE(msi->ProcessorRevision));
271             }
272             else sprintf(tmp + strlen(tmp), " (%d.%d)",
273                          HIBYTE(msi->ProcessorRevision),
274                          LOBYTE(msi->ProcessorRevision));
275             str = tmp;
276             break;
277         case PROCESSOR_ARCHITECTURE_MIPS:
278             str = "Mips";
279             break;
280         case PROCESSOR_ARCHITECTURE_ALPHA:
281             str = "Alpha";
282             break;
283         case PROCESSOR_ARCHITECTURE_PPC:
284             str = "PowerPC";
285             break;
286         case PROCESSOR_ARCHITECTURE_AMD64:
287             str = "X86_64";
288             break;
289         case PROCESSOR_ARCHITECTURE_ARM:
290             str = "ARM";
291             break;
292         default:
293             str = "???";
294             break;
295         }
296         dbg_printf("  %s was running on #%d %s CPU%s",
297                    dbg_W2A(exec_name, -1), msi->u.s.NumberOfProcessors, str,
298                    msi->u.s.NumberOfProcessors < 2 ? "" : "s");
299         switch (msi->MajorVersion)
300         {
301         case 3:
302             switch (msi->MinorVersion)
303             {
304             case 51: str = "NT 3.51"; break;
305             default: str = "3-????"; break;
306             }
307             break;
308         case 4:
309             switch (msi->MinorVersion)
310             {
311             case 0: str = (msi->PlatformId == VER_PLATFORM_WIN32_NT) ? "NT 4.0" : "95"; break;
312             case 10: str = "98"; break;
313             case 90: str = "ME"; break;
314             default: str = "5-????"; break;
315             }
316             break;
317         case 5:
318             switch (msi->MinorVersion)
319             {
320             case 0: str = "2000"; break;
321             case 1: str = "XP"; break;
322             case 2: str = "Server 2003"; break;
323             default: str = "5-????"; break;
324             }
325             break;
326         default: str = "???"; break;
327         }
328         dbg_printf(" on Windows %s (%u)\n", str, msi->BuildNumber);
329         /* FIXME CSD: msi->CSDVersionRva */
330 
331         if (sizeof(MINIDUMP_SYSTEM_INFO) + 4 > dir->Location.DataSize &&
332             msi->CSDVersionRva >= dir->Location.Rva + sizeof(MINIDUMP_SYSTEM_INFO) + 4)
333         {
334             const char*     code = (const char*)stream + sizeof(MINIDUMP_SYSTEM_INFO);
335             const DWORD*    wes;
336 
337             if (code[0] == 'W' && code[1] == 'I' && code[2] == 'N' && code[3] == 'E' &&
338                 *(wes = (const DWORD*)(code += 4)) >= 3)
339             {
340                 /* assume we have wine extensions */
341                 dbg_printf("    [on %s, on top of %s (%s)]\n",
342                            code + wes[1], code + wes[2], code + wes[3]);
343             }
344         }
345     }
346 
347     dbg_curr_process = dbg_add_process(&be_process_minidump_io, pid, hProc);
348     dbg_curr_pid = pid;
349     dbg_curr_process->pio_data = data;
350     dbg_set_process_name(dbg_curr_process, exec_name);
351 
352     dbg_init(hProc, NULL, FALSE);
353 
354     if (MiniDumpReadDumpStream(data->mapping, ThreadListStream, NULL, &stream, NULL))
355     {
356         MINIDUMP_THREAD_LIST*   mtl = stream;
357         ULONG                   i;
358 
359         for (i = 0; i < mtl->NumberOfThreads; i++)
360         {
361             dbg_add_thread(dbg_curr_process, mtl->Threads[i].ThreadId, NULL,
362                            (void*)(DWORD_PTR)get_addr64(mtl->Threads[i].Teb));
363         }
364     }
365     /* first load ELF modules, then do the PE ones */
366     if (MiniDumpReadDumpStream(data->mapping, Wine_ElfModuleListStream, NULL,
367                                &stream, NULL))
368     {
369         WCHAR   buffer[MAX_PATH];
370 
371         mml = stream;
372         for (i = 0, mm = &mml->Modules[0]; i < mml->NumberOfModules; i++, mm++)
373         {
374             mds = (MINIDUMP_STRING*)((char*)data->mapping + mm->ModuleNameRva);
375             memcpy(nameW, mds->Buffer, mds->Length);
376             nameW[mds->Length / sizeof(WCHAR)] = 0;
377             if (SymFindFileInPathW(hProc, NULL, nameW, (void*)(DWORD_PTR)mm->CheckSum,
378                                    0, 0, SSRVOPT_DWORD, buffer, validate_file, NULL))
379                 dbg_load_module(hProc, NULL, buffer, get_addr64(mm->BaseOfImage),
380                                  mm->SizeOfImage);
381             else
382                 SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
383                                  mm->SizeOfImage, NULL, SLMFLAG_VIRTUAL);
384         }
385     }
386     if (MiniDumpReadDumpStream(data->mapping, ModuleListStream, NULL, &stream, NULL))
387     {
388         WCHAR   buffer[MAX_PATH];
389 
390         mml = stream;
391         for (i = 0, mm = &mml->Modules[0]; i < mml->NumberOfModules; i++, mm++)
392         {
393             mds = (MINIDUMP_STRING*)((char*)data->mapping + mm->ModuleNameRva);
394             memcpy(nameW, mds->Buffer, mds->Length);
395             nameW[mds->Length / sizeof(WCHAR)] = 0;
396             if (SymFindFileInPathW(hProc, NULL, nameW, (void*)(DWORD_PTR)mm->TimeDateStamp,
397                                    mm->SizeOfImage, 0, SSRVOPT_DWORD, buffer, validate_file, NULL))
398                 dbg_load_module(hProc, NULL, buffer, get_addr64(mm->BaseOfImage),
399                                  mm->SizeOfImage);
400             else if (is_pe_module_embedded(data, mm))
401                 dbg_load_module(hProc, NULL, nameW, get_addr64(mm->BaseOfImage),
402                                  mm->SizeOfImage);
403             else
404                 SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
405                                  mm->SizeOfImage, NULL, SLMFLAG_VIRTUAL);
406         }
407     }
408     if (MiniDumpReadDumpStream(data->mapping, ExceptionStream, NULL, &stream, NULL))
409     {
410         MINIDUMP_EXCEPTION_STREAM*      mes = stream;
411 
412         if ((dbg_curr_thread = dbg_get_thread(dbg_curr_process, mes->ThreadId)))
413         {
414             ADDRESS64   addr;
415 
416             dbg_curr_tid = mes->ThreadId;
417             dbg_curr_thread->in_exception = TRUE;
418             dbg_curr_thread->excpt_record.ExceptionCode = mes->ExceptionRecord.ExceptionCode;
419             dbg_curr_thread->excpt_record.ExceptionFlags = mes->ExceptionRecord.ExceptionFlags;
420             dbg_curr_thread->excpt_record.ExceptionRecord = (void*)(DWORD_PTR)get_addr64(mes->ExceptionRecord.ExceptionRecord);
421             dbg_curr_thread->excpt_record.ExceptionAddress = (void*)(DWORD_PTR)get_addr64(mes->ExceptionRecord.ExceptionAddress);
422             dbg_curr_thread->excpt_record.NumberParameters = mes->ExceptionRecord.NumberParameters;
423             for (i = 0; i < dbg_curr_thread->excpt_record.NumberParameters; i++)
424             {
425                 dbg_curr_thread->excpt_record.ExceptionInformation[i] = mes->ExceptionRecord.ExceptionInformation[i];
426             }
427             memcpy(&dbg_context, (char*)data->mapping + mes->ThreadContext.Rva,
428                    min(sizeof(dbg_context), mes->ThreadContext.DataSize));
429             memory_get_current_pc(&addr);
430             stack_fetch_frames(&dbg_context);
431             be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0);
432             stack_info(-1);
433             be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context);
434             stack_backtrace(mes->ThreadId);
435             source_list_from_addr(&addr, 0);
436         }
437     }
438     return start_ok;
439 }
440 
441 static void cleanup(struct tgt_process_minidump_data* data)
442 {
443     if (data->mapping)                          UnmapViewOfFile(data->mapping);
444     if (data->hMap)                             CloseHandle(data->hMap);
445     if (data->hFile != INVALID_HANDLE_VALUE)    CloseHandle(data->hFile);
446     HeapFree(GetProcessHeap(), 0, data);
447 }
448 
449 static struct be_process_io be_process_minidump_io;
450 
451 enum dbg_start minidump_reload(int argc, char* argv[])
452 {
453     struct tgt_process_minidump_data*   data;
454     enum dbg_start                      ret = start_error_parse;
455 
456     /* try the form <myself> minidump-file */
457     if (argc != 1) return start_error_parse;
458     
459     WINE_TRACE("Processing Minidump file %s\n", argv[0]);
460 
461     data = HeapAlloc(GetProcessHeap(), 0, sizeof(struct tgt_process_minidump_data));
462     if (!data) return start_error_init;
463     data->mapping = NULL;
464     data->hMap    = NULL;
465     data->hFile   = INVALID_HANDLE_VALUE;
466 
467     if ((data->hFile = CreateFileA(argv[0], GENERIC_READ, FILE_SHARE_READ, NULL, 
468                                    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE &&
469         ((data->hMap = CreateFileMappingA(data->hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
470         ((data->mapping = MapViewOfFile(data->hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
471     {
472         __TRY
473         {
474             if (((MINIDUMP_HEADER*)data->mapping)->Signature == MINIDUMP_SIGNATURE)
475             {
476                 ret = minidump_do_reload(data);
477             }
478         }
479         __EXCEPT_PAGE_FAULT
480         {
481             dbg_printf("Unexpected fault while reading minidump %s\n", argv[0]);
482             dbg_curr_pid = 0;
483         }
484         __ENDTRY;
485     }
486     if (ret != start_ok) cleanup(data);
487     return ret;
488 }
489 
490 static BOOL tgt_process_minidump_close_process(struct dbg_process* pcs, BOOL kill)
491 {
492     struct tgt_process_minidump_data*    data = private_data(pcs);
493 
494     cleanup(data);
495     pcs->pio_data = NULL;
496     SymCleanup(pcs->handle);
497     dbg_del_process(pcs);
498     return TRUE;
499 }
500 
501 static BOOL tgt_process_minidump_get_selector(HANDLE hThread, DWORD sel, LDT_ENTRY* le)
502 {
503     /* so far, pretend all selectors are valid, and mapped to a 32bit flat address space */
504     memset(le, 0, sizeof(*le));
505     le->HighWord.Bits.Default_Big = 1;
506     return TRUE;
507 }
508 
509 static struct be_process_io be_process_minidump_io =
510 {
511     tgt_process_minidump_close_process,
512     tgt_process_minidump_read,
513     tgt_process_minidump_write,
514     tgt_process_minidump_get_selector,
515 };
516 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.