d2d1: Remove unused D3D10 interfaces.
[wine.git] / programs / winedbg / winedbg.c
blob5e433bbb699a51c74991cf96926d04901300f045
1 /* Wine internal debugger
2 * Interface to Windows debugger API
3 * Copyright 2000-2004 Eric Pouech
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "debugger.h"
28 #include "winternl.h"
29 #include "wine/exception.h"
31 #include "wine/debug.h"
33 /* TODO list:
35 * - minidump
36 * + ensure that all commands work as expected in minidump reload function
37 * (and re-enable parser usage)
38 * - CPU adherence
39 * + we always assume the stack grows as on i386 (i.e. downwards)
40 * - UI
41 * + re-enable the limited output (depth of structure printing and number of
42 * lines)
43 * + make the output as close as possible to what gdb does
44 * - symbol management:
45 * + symbol table loading is broken
46 * + in symbol_get_lvalue, we don't do any scoping (as C does) between local and
47 * global vars (we may need this to force some display for example). A solution
48 * would be always to return arrays with: local vars, global vars, thunks
49 * - type management:
50 * + some bits of internal types are missing (like type casts and the address
51 * operator)
52 * + the type for an enum's value is always inferred as int (winedbg & dbghelp)
53 * + most of the code implies that sizeof(void*) = sizeof(int)
54 * + all computations should be made on long long
55 * o expr computations are in int:s
56 * o bitfield size is on a 4-bytes
57 * - execution:
58 * + set a better fix for gdb (proxy mode) than the step-mode hack
59 * + implement function call in debuggee
60 * + trampoline management is broken when getting 16 <=> 32 thunk destination
61 * address
62 * + thunking of delayed imports doesn't work as expected (ie, when stepping,
63 * it currently stops at first insn with line number during the library
64 * loading). We should identify this (__wine_delay_import) and set a
65 * breakpoint instead of single stepping the library loading.
66 * + it's wrong to copy thread->step_over_bp into process->bp[0] (when
67 * we have a multi-thread debuggee). complete fix must include storing all
68 * thread's step-over bp in process-wide bp array, and not to handle bp
69 * when we have the wrong thread running into that bp
70 * + code in CREATE_PROCESS debug event doesn't work on Windows, as we cannot
71 * get the name of the main module this way. We should rewrite all this code
72 * and store in struct dbg_process as early as possible (before process
73 * creation or attachment), the name of the main module
74 * - global:
75 * + define a better way to enable the wine extensions (either DBG SDK function
76 * in dbghelp, or TLS variable, or environment variable or ...)
77 * + audit all files to ensure that we check all potential return values from
78 * every function call to catch the errors
79 * + BTW check also whether the exception mechanism is the best way to return
80 * errors (or find a proper fix for MinGW port)
83 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
85 struct dbg_process* dbg_curr_process = NULL;
86 struct dbg_thread* dbg_curr_thread = NULL;
87 DWORD_PTR dbg_curr_tid = 0;
88 DWORD_PTR dbg_curr_pid = 0;
89 dbg_ctx_t dbg_context;
90 BOOL dbg_interactiveP = FALSE;
91 HANDLE dbg_houtput = 0;
93 static struct list dbg_process_list = LIST_INIT(dbg_process_list);
95 struct dbg_internal_var dbg_internal_vars[DBG_IV_LAST];
97 static void dbg_outputA(const char* buffer, int len)
99 static char line_buff[4096];
100 static unsigned int line_pos;
102 DWORD w, i;
104 while (len > 0)
106 unsigned int count = min( len, sizeof(line_buff) - line_pos );
107 memcpy( line_buff + line_pos, buffer, count );
108 buffer += count;
109 len -= count;
110 line_pos += count;
111 for (i = line_pos; i > 0; i--) if (line_buff[i-1] == '\n') break;
112 if (!i) /* no newline found */
114 if (len > 0) i = line_pos; /* buffer is full, flush anyway */
115 else break;
117 WriteFile(dbg_houtput, line_buff, i, &w, NULL);
118 memmove( line_buff, line_buff + i, line_pos - i );
119 line_pos -= i;
123 const char* dbg_W2A(const WCHAR* buffer, unsigned len)
125 static unsigned ansilen;
126 static char* ansi;
127 unsigned newlen;
129 newlen = WideCharToMultiByte(CP_ACP, 0, buffer, len, NULL, 0, NULL, NULL);
130 if (newlen > ansilen)
132 static char* newansi;
133 if (ansi)
134 newansi = HeapReAlloc(GetProcessHeap(), 0, ansi, newlen);
135 else
136 newansi = HeapAlloc(GetProcessHeap(), 0, newlen);
137 if (!newansi) return NULL;
138 ansilen = newlen;
139 ansi = newansi;
141 WideCharToMultiByte(CP_ACP, 0, buffer, len, ansi, newlen, NULL, NULL);
142 return ansi;
145 void dbg_outputW(const WCHAR* buffer, int len)
147 const char* ansi = dbg_W2A(buffer, len);
148 if (ansi) dbg_outputA(ansi, strlen(ansi));
149 /* FIXME: should CP_ACP be GetConsoleCP()? */
152 int dbg_printf(const char* format, ...)
154 static char buf[4*1024];
155 va_list valist;
156 int len;
158 va_start(valist, format);
159 len = vsnprintf(buf, sizeof(buf), format, valist);
160 va_end(valist);
162 if (len <= -1 || len >= sizeof(buf))
164 len = sizeof(buf) - 1;
165 buf[len] = 0;
166 buf[len - 1] = buf[len - 2] = buf[len - 3] = '.';
168 dbg_outputA(buf, len);
169 return len;
172 static unsigned dbg_load_internal_vars(void)
174 HKEY hkey;
175 DWORD type = REG_DWORD;
176 DWORD val;
177 DWORD count = sizeof(val);
178 int i;
179 struct dbg_internal_var* div = dbg_internal_vars;
181 /* initializes internal vars table */
182 #define INTERNAL_VAR(_var,_val,_ref,_tid) \
183 div->val = _val; div->name = #_var; div->pval = _ref; \
184 div->typeid = _tid; div++;
185 #include "intvar.h"
186 #undef INTERNAL_VAR
188 /* @@ Wine registry key: HKCU\Software\Wine\WineDbg */
189 if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey))
191 WINE_ERR("Cannot create WineDbg key in registry\n");
192 return FALSE;
195 for (i = 0; i < DBG_IV_LAST; i++)
197 if (!dbg_internal_vars[i].pval)
199 if (!RegQueryValueExA(hkey, dbg_internal_vars[i].name, 0,
200 &type, (LPBYTE)&val, &count))
201 dbg_internal_vars[i].val = val;
202 dbg_internal_vars[i].pval = &dbg_internal_vars[i].val;
205 RegCloseKey(hkey);
207 return TRUE;
210 static unsigned dbg_save_internal_vars(void)
212 HKEY hkey;
213 int i;
215 /* @@ Wine registry key: HKCU\Software\Wine\WineDbg */
216 if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey))
218 WINE_ERR("Cannot create WineDbg key in registry\n");
219 return FALSE;
222 for (i = 0; i < DBG_IV_LAST; i++)
224 /* FIXME: type should be inferred from basic type -if any- of intvar */
225 if (dbg_internal_vars[i].pval == &dbg_internal_vars[i].val)
227 DWORD val = dbg_internal_vars[i].val;
228 RegSetValueExA(hkey, dbg_internal_vars[i].name, 0, REG_DWORD, (BYTE *)&val, sizeof(val));
231 RegCloseKey(hkey);
232 return TRUE;
235 const struct dbg_internal_var* dbg_get_internal_var(const char* name)
237 const struct dbg_internal_var* div;
239 for (div = &dbg_internal_vars[DBG_IV_LAST - 1]; div >= dbg_internal_vars; div--)
241 if (!strcmp(div->name, name)) return div;
243 for (div = dbg_curr_process->be_cpu->context_vars; div->name; div++)
245 if (!strcasecmp(div->name, name))
247 struct dbg_internal_var* ret = (void*)lexeme_alloc_size(sizeof(*ret));
248 /* relocate register's field against current context */
249 *ret = *div;
250 ret->pval = (DWORD_PTR*)((char*)&dbg_context + (DWORD_PTR)div->pval);
251 return ret;
255 return NULL;
258 unsigned dbg_num_processes(void)
260 return list_count(&dbg_process_list);
263 struct dbg_process* dbg_get_process(DWORD pid)
265 struct dbg_process* p;
267 LIST_FOR_EACH_ENTRY(p, &dbg_process_list, struct dbg_process, entry)
268 if (p->pid == pid) return p;
269 return NULL;
272 struct dbg_process* dbg_get_process_h(HANDLE h)
274 struct dbg_process* p;
276 LIST_FOR_EACH_ENTRY(p, &dbg_process_list, struct dbg_process, entry)
277 if (p->handle == h) return p;
278 return NULL;
281 #ifdef __i386__
282 extern struct backend_cpu be_i386;
283 #elif defined(__x86_64__)
284 extern struct backend_cpu be_i386;
285 extern struct backend_cpu be_x86_64;
286 #elif defined(__arm__) && !defined(__ARMEB__)
287 extern struct backend_cpu be_arm;
288 #elif defined(__aarch64__) && !defined(__AARCH64EB__)
289 extern struct backend_cpu be_arm64;
290 #else
291 # error CPU unknown
292 #endif
294 struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid, HANDLE h)
296 struct dbg_process* p;
297 BOOL wow64;
299 if ((p = dbg_get_process(pid)))
300 return p;
302 if (!h)
303 h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
305 if (!(p = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dbg_process)))) return NULL;
306 p->handle = h;
307 p->pid = pid;
308 p->process_io = pio;
309 p->pio_data = NULL;
310 p->imageName = NULL;
311 list_init(&p->threads);
312 p->event_on_first_exception = NULL;
313 p->active_debuggee = FALSE;
314 p->next_bp = 1; /* breakpoint 0 is reserved for step-over */
315 memset(p->bp, 0, sizeof(p->bp));
316 p->delayed_bp = NULL;
317 p->num_delayed_bp = 0;
318 p->source_ofiles = NULL;
319 p->search_path = NULL;
320 p->source_current_file[0] = '\0';
321 p->source_start_line = -1;
322 p->source_end_line = -1;
324 list_add_head(&dbg_process_list, &p->entry);
326 IsWow64Process(h, &wow64);
328 #ifdef __i386__
329 p->be_cpu = &be_i386;
330 #elif defined(__x86_64__)
331 p->be_cpu = wow64 ? &be_i386 : &be_x86_64;
332 #elif defined(__arm__) && !defined(__ARMEB__)
333 p->be_cpu = &be_arm;
334 #elif defined(__aarch64__) && !defined(__AARCH64EB__)
335 p->be_cpu = &be_arm64;
336 #else
337 # error CPU unknown
338 #endif
339 return p;
342 void dbg_set_process_name(struct dbg_process* p, const WCHAR* imageName)
344 assert(p->imageName == NULL);
345 if (imageName)
347 WCHAR* tmp = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(imageName) + 1) * sizeof(WCHAR));
348 if (tmp) p->imageName = lstrcpyW(tmp, imageName);
352 void dbg_del_process(struct dbg_process* p)
354 struct dbg_thread* t;
355 struct dbg_thread* t2;
356 int i;
358 LIST_FOR_EACH_ENTRY_SAFE(t, t2, &p->threads, struct dbg_thread, entry)
359 dbg_del_thread(t);
361 for (i = 0; i < p->num_delayed_bp; i++)
362 if (p->delayed_bp[i].is_symbol)
363 HeapFree(GetProcessHeap(), 0, p->delayed_bp[i].u.symbol.name);
365 HeapFree(GetProcessHeap(), 0, p->delayed_bp);
366 source_nuke_path(p);
367 source_free_files(p);
368 list_remove(&p->entry);
369 if (p == dbg_curr_process) dbg_curr_process = NULL;
370 if (p->event_on_first_exception) CloseHandle(p->event_on_first_exception);
371 HeapFree(GetProcessHeap(), 0, (char*)p->imageName);
372 HeapFree(GetProcessHeap(), 0, p);
375 /******************************************************************
376 * dbg_init
378 * Initializes the dbghelp library, and also sets the application directory
379 * as a place holder for symbol searches.
381 BOOL dbg_init(HANDLE hProc, const WCHAR* in, BOOL invade)
383 BOOL ret;
385 ret = SymInitialize(hProc, NULL, invade);
386 if (ret && in)
388 const WCHAR* last;
390 for (last = in + lstrlenW(in) - 1; last >= in; last--)
392 if (*last == '/' || *last == '\\')
394 WCHAR* tmp;
395 tmp = HeapAlloc(GetProcessHeap(), 0, (1024 + 1 + (last - in) + 1) * sizeof(WCHAR));
396 if (tmp && SymGetSearchPathW(hProc, tmp, 1024))
398 WCHAR* x = tmp + lstrlenW(tmp);
400 *x++ = ';';
401 memcpy(x, in, (last - in) * sizeof(WCHAR));
402 x[last - in] = '\0';
403 ret = SymSetSearchPathW(hProc, tmp);
405 else ret = FALSE;
406 HeapFree(GetProcessHeap(), 0, tmp);
407 break;
411 return ret;
414 struct mod_loader_info
416 HANDLE handle;
417 IMAGEHLP_MODULE64* imh_mod;
420 static BOOL CALLBACK mod_loader_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
422 struct mod_loader_info* mli = ctx;
424 if (!strcmp(mod_name, "<wine-loader>"))
426 if (SymGetModuleInfo64(mli->handle, base, mli->imh_mod))
427 return FALSE; /* stop enum */
429 return TRUE;
432 BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE64* imh_mod)
434 struct mod_loader_info mli;
435 BOOL opt;
437 /* this will resynchronize builtin dbghelp's internal ELF module list */
438 SymLoadModule(hProcess, 0, 0, 0, 0, 0);
439 mli.handle = hProcess;
440 mli.imh_mod = imh_mod;
441 imh_mod->SizeOfStruct = sizeof(*imh_mod);
442 imh_mod->BaseOfImage = 0;
443 /* this is a wine specific options to return also ELF modules in the
444 * enumeration
446 opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
447 SymEnumerateModules64(hProcess, mod_loader_cb, &mli);
448 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
450 return imh_mod->BaseOfImage != 0;
453 BOOL dbg_load_module(HANDLE hProc, HANDLE hFile, const WCHAR* name, DWORD_PTR base, DWORD size)
455 BOOL ret = SymLoadModuleExW(hProc, NULL, name, NULL, base, size, NULL, 0);
456 if (ret)
458 IMAGEHLP_MODULEW64 ihm;
459 ihm.SizeOfStruct = sizeof(ihm);
460 if (SymGetModuleInfoW64(hProc, base, &ihm) && (ihm.PdbUnmatched || ihm.DbgUnmatched))
461 dbg_printf("Loaded unmatched debug information for %s\n", wine_dbgstr_w(name));
463 return ret;
466 struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid)
468 struct dbg_thread* t;
470 if (!p) return NULL;
471 LIST_FOR_EACH_ENTRY(t, &p->threads, struct dbg_thread, entry)
472 if (t->tid == tid) return t;
473 return NULL;
476 struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid,
477 HANDLE h, void* teb)
479 struct dbg_thread* t = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dbg_thread));
481 if (!t)
482 return NULL;
484 t->handle = h;
485 t->tid = tid;
486 t->teb = teb;
487 t->process = p;
488 t->exec_mode = dbg_exec_cont;
489 t->exec_count = 0;
490 t->step_over_bp.enabled = FALSE;
491 t->step_over_bp.refcount = 0;
492 t->stopped_xpoint = -1;
493 t->in_exception = FALSE;
494 t->frames = NULL;
495 t->num_frames = 0;
496 t->curr_frame = -1;
497 t->addr_mode = AddrModeFlat;
498 t->suspended = FALSE;
500 snprintf(t->name, sizeof(t->name), "%04x", tid);
502 list_add_head(&p->threads, &t->entry);
504 return t;
507 void dbg_del_thread(struct dbg_thread* t)
509 HeapFree(GetProcessHeap(), 0, t->frames);
510 list_remove(&t->entry);
511 if (t == dbg_curr_thread) dbg_curr_thread = NULL;
512 HeapFree(GetProcessHeap(), 0, t);
515 void dbg_set_option(const char* option, const char* val)
517 if (!strcasecmp(option, "module_load_mismatched"))
519 DWORD opt = SymGetOptions();
520 if (!val)
521 dbg_printf("Option: module_load_mismatched %s\n", opt & SYMOPT_LOAD_ANYTHING ? "true" : "false");
522 else if (!strcasecmp(val, "true")) opt |= SYMOPT_LOAD_ANYTHING;
523 else if (!strcasecmp(val, "false")) opt &= ~SYMOPT_LOAD_ANYTHING;
524 else
526 dbg_printf("Syntax: module_load_mismatched [true|false]\n");
527 return;
529 SymSetOptions(opt);
531 else if (!strcasecmp(option, "symbol_picker"))
533 if (!val)
534 dbg_printf("Option: symbol_picker %s\n",
535 symbol_current_picker == symbol_picker_interactive ? "interactive" : "scoped");
536 else if (!strcasecmp(val, "interactive"))
537 symbol_current_picker = symbol_picker_interactive;
538 else if (!strcasecmp(val, "scoped"))
539 symbol_current_picker = symbol_picker_scoped;
540 else
542 dbg_printf("Syntax: symbol_picker [interactive|scoped]\n");
543 return;
546 else dbg_printf("Unknown option '%s'\n", option);
549 BOOL dbg_interrupt_debuggee(void)
551 struct dbg_process* p;
552 if (list_empty(&dbg_process_list)) return FALSE;
553 /* FIXME: since we likely have a single process, signal the first process
554 * in list
556 p = LIST_ENTRY(list_head(&dbg_process_list), struct dbg_process, entry);
557 if (list_next(&dbg_process_list, &p->entry)) dbg_printf("Ctrl-C: only stopping the first process\n");
558 else dbg_printf("Ctrl-C: stopping debuggee\n");
559 if (p->event_on_first_exception)
561 SetEvent(p->event_on_first_exception);
562 CloseHandle(p->event_on_first_exception);
563 p->event_on_first_exception = NULL;
565 return DebugBreakProcess(p->handle);
568 static BOOL WINAPI ctrl_c_handler(DWORD dwCtrlType)
570 if (dwCtrlType == CTRL_C_EVENT)
572 return dbg_interrupt_debuggee();
574 return FALSE;
577 void dbg_init_console(void)
579 /* set the output handle */
580 dbg_houtput = GetStdHandle(STD_OUTPUT_HANDLE);
582 /* set our control-C handler */
583 SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
585 /* set our own title */
586 SetConsoleTitleA("Wine Debugger");
589 static int dbg_winedbg_usage(BOOL advanced)
591 if (advanced)
593 dbg_printf("Usage:\n"
594 " winedbg <cmdline> launch process <cmdline> (as if you were starting\n"
595 " it with wine) and run WineDbg on it\n"
596 " winedbg <num> attach to running process of wpid <num> and run\n"
597 " WineDbg on it\n"
598 " winedbg --gdb <cmdline> launch process <cmdline> (as if you were starting\n"
599 " wine) and run gdb (proxied) on it\n"
600 " winedbg --gdb <num> attach to running process of wpid <num> and run\n"
601 " gdb (proxied) on it\n"
602 " winedbg <file.mdmp> reload the minidump <file.mdmp> into memory and run\n"
603 " WineDbg on it\n"
604 " winedbg --help prints advanced options\n");
606 else
607 dbg_printf("Usage:\n\twinedbg [ [ --gdb ] [ <prog-name> [ <prog-args> ] | <num> | <file.mdmp> | --help ]\n");
608 return 0;
611 void dbg_start_interactive(HANDLE hFile)
613 struct dbg_process* p;
614 struct dbg_process* p2;
616 if (dbg_curr_process)
618 dbg_printf("WineDbg starting on pid %04lx\n", dbg_curr_pid);
619 if (dbg_curr_process->active_debuggee) dbg_active_wait_for_first_exception();
622 dbg_interactiveP = TRUE;
623 parser_handle(hFile);
625 LIST_FOR_EACH_ENTRY_SAFE(p, p2, &dbg_process_list, struct dbg_process, entry)
626 p->process_io->close_process(p, FALSE);
628 dbg_save_internal_vars();
631 static LONG CALLBACK top_filter( EXCEPTION_POINTERS *ptr )
633 dbg_printf( "winedbg: Internal crash at %p\n", ptr->ExceptionRecord->ExceptionAddress );
634 return EXCEPTION_EXECUTE_HANDLER;
637 static void restart_if_wow64(void)
639 BOOL is_wow64;
641 if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
643 static const WCHAR winedbgW[] = {'\\','w','i','n','e','d','b','g','.','e','x','e',0};
644 STARTUPINFOW si;
645 PROCESS_INFORMATION pi;
646 WCHAR filename[MAX_PATH];
647 void *redir;
648 DWORD exit_code;
650 memset( &si, 0, sizeof(si) );
651 si.cb = sizeof(si);
652 GetSystemDirectoryW( filename, MAX_PATH );
653 lstrcatW( filename, winedbgW );
655 Wow64DisableWow64FsRedirection( &redir );
656 if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
658 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
659 SetConsoleCtrlHandler( NULL, TRUE ); /* Ignore ^C */
660 WaitForSingleObject( pi.hProcess, INFINITE );
661 GetExitCodeProcess( pi.hProcess, &exit_code );
662 ExitProcess( exit_code );
664 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
665 Wow64RevertWow64FsRedirection( redir );
669 int main(int argc, char** argv)
671 int retv = 0;
672 HANDLE hFile = INVALID_HANDLE_VALUE;
673 enum dbg_start ds;
675 /* Initialize the output */
676 dbg_houtput = GetStdHandle(STD_OUTPUT_HANDLE);
678 SetUnhandledExceptionFilter( top_filter );
680 /* Initialize internal vars */
681 if (!dbg_load_internal_vars()) return -1;
683 /* as we don't care about exec name */
684 argc--; argv++;
686 if (argc && !strcmp(argv[0], "--help"))
687 return dbg_winedbg_usage(TRUE);
689 if (argc && !strcmp(argv[0], "--gdb"))
691 restart_if_wow64();
692 retv = gdb_main(argc, argv);
693 if (retv == -1) dbg_winedbg_usage(FALSE);
694 return retv;
696 dbg_init_console();
698 SymSetOptions((SymGetOptions() & ~(SYMOPT_UNDNAME)) |
699 SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS | SYMOPT_AUTO_PUBLICS);
701 if (argc && !strcmp(argv[0], "--auto"))
703 switch (dbg_active_auto(argc, argv))
705 case start_ok: return 0;
706 case start_error_parse: return dbg_winedbg_usage(FALSE);
707 case start_error_init: return -1;
710 if (argc && !strcmp(argv[0], "--minidump"))
712 switch (dbg_active_minidump(argc, argv))
714 case start_ok: return 0;
715 case start_error_parse: return dbg_winedbg_usage(FALSE);
716 case start_error_init: return -1;
719 /* parse options */
720 while (argc > 0 && argv[0][0] == '-')
722 if (!strcmp(argv[0], "--command"))
724 argc--; argv++;
725 hFile = parser_generate_command_file(argv[0], NULL);
726 if (hFile == INVALID_HANDLE_VALUE)
728 dbg_printf("Couldn't open temp file (%u)\n", GetLastError());
729 return 1;
731 argc--; argv++;
732 continue;
734 if (!strcmp(argv[0], "--file"))
736 argc--; argv++;
737 hFile = CreateFileA(argv[0], GENERIC_READ|DELETE, 0,
738 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
739 if (hFile == INVALID_HANDLE_VALUE)
741 dbg_printf("Couldn't open file %s (%u)\n", argv[0], GetLastError());
742 return 1;
744 argc--; argv++;
745 continue;
747 if (!strcmp(argv[0], "--"))
749 argc--; argv++;
750 break;
752 return dbg_winedbg_usage(FALSE);
754 if (!argc) ds = start_ok;
755 else if ((ds = dbg_active_attach(argc, argv)) == start_error_parse &&
756 (ds = minidump_reload(argc, argv)) == start_error_parse)
757 ds = dbg_active_launch(argc, argv);
758 switch (ds)
760 case start_ok: break;
761 case start_error_parse: return dbg_winedbg_usage(FALSE);
762 case start_error_init: return -1;
765 restart_if_wow64();
767 dbg_start_interactive(hFile);
769 return 0;