X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fwindows-nat.c;h=8fedf9e60a36dd0eba5364568a24eeae92c6ea2e;hb=ec56be1b4dc25ec39c32ceab997747ad651c9d22;hp=ec014b3e91116851bf4f0f03aa97d687ab4d564c;hpb=33605d39628625079897972b9ecfa8d082000e67;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index ec014b3e91..8fedf9e60a 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -48,7 +48,6 @@ #include "objfiles.h" #include "gdb_obstack.h" #include "gdb_string.h" -#include "gdb_stdint.h" #include "gdbthread.h" #include "gdbcmd.h" #include @@ -106,7 +105,7 @@ static int debug_registers_used; #define DEBUG_MEM(x) if (debug_memory) printf_unfiltered x #define DEBUG_EXCEPT(x) if (debug_exceptions) printf_unfiltered x -static void win32_stop (void); +static void win32_stop (ptid_t); static int win32_win32_thread_alive (ptid_t); static void win32_kill_inferior (void); @@ -359,6 +358,8 @@ static void do_win32_fetch_inferior_registers (struct regcache *regcache, int r) { char *context_offset = ((char *) ¤t_thread->context) + mappings[r]; + struct gdbarch *gdbarch = get_regcache_arch (regcache); + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); long l; if (!current_thread) @@ -397,14 +398,12 @@ do_win32_fetch_inferior_registers (struct regcache *regcache, int r) current_thread->reload_context = 0; } -#define I387_ST0_REGNUM I386_ST0_REGNUM - - if (r == I387_FISEG_REGNUM) + if (r == I387_FISEG_REGNUM (tdep)) { l = *((long *) context_offset) & 0xffff; regcache_raw_supply (regcache, r, (char *) &l); } - else if (r == I387_FOP_REGNUM) + else if (r == I387_FOP_REGNUM (tdep)) { l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1); regcache_raw_supply (regcache, r, (char *) &l); @@ -413,11 +412,9 @@ do_win32_fetch_inferior_registers (struct regcache *regcache, int r) regcache_raw_supply (regcache, r, context_offset); else { - for (r = 0; r < gdbarch_num_regs (get_regcache_arch (regcache)); r++) + for (r = 0; r < gdbarch_num_regs (gdbarch); r++) do_win32_fetch_inferior_registers (regcache, r); } - -#undef I387_ST0_REGNUM } static void @@ -558,8 +555,6 @@ static int safe_symbol_file_add_stub (void *argv) { #define p ((struct safe_symbol_file_add_args *) argv) - struct so_list *so = &solib_start; - p->ret = symbol_file_add (p->name, p->from_tty, p->addrs, p->mainline, p->flags); return !!p->ret; #undef p @@ -656,7 +651,7 @@ win32_make_so (const char *name, DWORD load_addr) asection *text = NULL; CORE_ADDR text_vma; - abfd = bfd_openr (name, "pei-i386"); + abfd = bfd_openr (so->so_name, "pei-i386"); if (!abfd) return so; @@ -749,6 +744,9 @@ handle_load_dll (void *dummy) solib_end->next = win32_make_so (dll_name, (DWORD) event->lpBaseOfDll); solib_end = solib_end->next; + DEBUG_EVENTS (("gdb: Loading dll \"%s\" at 0x%lx.\n", solib_end->so_name, + (DWORD) solib_end->lm_info->load_addr)); + return 1; } @@ -773,6 +771,8 @@ handle_unload_dll (void *dummy) so->next = sodel->next; if (!so->next) solib_end = so; + DEBUG_EVENTS (("gdb: Unloading dll \"%s\".\n", sodel->so_name)); + win32_free_so (sodel); solib_add (NULL, 0, NULL, auto_solib_add); return 1; @@ -1302,7 +1302,7 @@ get_win32_debug_event (int pid, struct target_waitstatus *ourstatus) /* Kludge around a Windows bug where first event is a create thread event. Caused when attached process does not have a main thread. */ - retval = ourstatus->value.related_pid = fake_create_process (); + retval = fake_create_process (); if (retval) saw_create++; } @@ -1311,10 +1311,6 @@ get_win32_debug_event (int pid, struct target_waitstatus *ourstatus) /* Record the existence of this thread */ th = win32_add_thread (current_event.dwThreadId, current_event.u.CreateThread.hThread); - if (info_verbose) - printf_unfiltered ("[New %s]\n", - target_pid_to_str ( - pid_to_ptid (current_event.dwThreadId))); retval = current_event.dwThreadId; break; @@ -1346,7 +1342,7 @@ get_win32_debug_event (int pid, struct target_waitstatus *ourstatus) /* Add the main thread */ th = win32_add_thread (main_thread_id, current_event.u.CreateProcessInfo.hThread); - retval = ourstatus->value.related_pid = current_event.dwThreadId; + retval = current_event.dwThreadId; break; case EXIT_PROCESS_DEBUG_EVENT: @@ -1464,7 +1460,25 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus) while (1) { - int retval = get_win32_debug_event (pid, ourstatus); + int retval; + + /* Ignore CTRL+C signals while waiting for a debug event. + FIXME: brobecker/2008-05-20: When the user presses CTRL+C while + the inferior is running, both the inferior and GDB receive the + associated signal. If the inferior receives the signal first + and the delay until GDB receives that signal is sufficiently long, + GDB can sometimes receive the SIGINT after we have unblocked + the CTRL+C handler. This would lead to the debugger to stop + prematurely while handling the new-thread event that comes + with the handling of the SIGINT inside the inferior, and then + stop again immediately when the user tries to resume the execution + in the inferior. This is a classic race, and it would be nice + to find a better solution to that problem. But in the meantime, + the current approach already greatly mitigate this issue. */ + SetConsoleCtrlHandler (NULL, TRUE); + retval = get_win32_debug_event (pid, ourstatus); + SetConsoleCtrlHandler (NULL, FALSE); + if (retval) return pid_to_ptid (retval); else @@ -1508,15 +1522,18 @@ do_initial_win32_stuff (DWORD pid) terminal_init_inferior_with_pgrp (pid); target_terminal_inferior (); + stop_soon = STOP_QUIETLY; while (1) { stop_after_trap = 1; - wait_for_inferior (); + wait_for_inferior (0); if (stop_signal != TARGET_SIGNAL_TRAP) resume (0, stop_signal); else break; } + + stop_soon = NO_STOP_QUIETLY; stop_after_trap = 0; return; } @@ -1880,6 +1897,9 @@ win32_create_inferior (char *exec_file, char *allargs, char **in_env, error (_("Error creating process %s, (error %d)."), exec_file, (unsigned) GetLastError ()); + CloseHandle (pi.hThread); + CloseHandle (pi.hProcess); + if (useshell && shell[0] != '\0') saw_create = -1; else @@ -1908,7 +1928,7 @@ win32_mourn_inferior (void) ^C on the controlling terminal. */ static void -win32_stop (void) +win32_stop (ptid_t ptid) { DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n")); CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, current_event.dwProcessId)); @@ -1991,7 +2011,7 @@ win32_pid_to_str (ptid_t ptid) if ((DWORD) pid == current_event.dwProcessId) sprintf (buf, "process %d", pid); else - sprintf (buf, "thread %ld.0x%x", current_event.dwProcessId, pid); + sprintf (buf, "Thread %ld.0x%x", current_event.dwProcessId, pid); return buf; } @@ -2038,7 +2058,7 @@ win32_xfer_partial (struct target_ops *ops, enum target_object object, case TARGET_OBJECT_MEMORY: if (readbuf) return (*ops->deprecated_xfer_memory) (offset, readbuf, - len, 0/*write*/, NULL, ops); + len, 0/*read*/, NULL, ops); if (writebuf) return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf, len, 1/*write*/, NULL, ops); @@ -2065,6 +2085,7 @@ init_win32_ops (void) win32_ops.to_open = win32_open; win32_ops.to_close = win32_close; win32_ops.to_attach = win32_attach; + win32_ops.to_attach_no_wait = 1; win32_ops.to_detach = win32_detach; win32_ops.to_resume = win32_resume; win32_ops.to_wait = win32_wait;