/* Low level interface to Windows debugging, for gdbserver.
- Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Contributed by Leo Zayas. Based on "win32-nat.c" from GDB.
/* Add a thread to the thread list. */
static win32_thread_info *
-child_add_thread (DWORD pid, DWORD tid, HANDLE h)
+child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
{
win32_thread_info *th;
ptid_t ptid = ptid_build (pid, tid, 0);
th = xcalloc (1, sizeof (*th));
th->tid = tid;
th->h = h;
+ th->thread_local_base = (CORE_ADDR) (uintptr_t) tlb;
add_thread (ptid, th);
set_inferior_regcache_data ((struct thread_info *)
int write, struct target_ops *target)
{
SIZE_T done;
- long addr = (long) memaddr;
+ uintptr_t addr = (uintptr_t) memaddr;
if (write)
{
/* Fetch register(s) from the current thread context. */
static void
-child_fetch_inferior_registers (int r)
+child_fetch_inferior_registers (struct regcache *regcache, int r)
{
int regno;
win32_thread_info *th = thread_rec (current_inferior_ptid (), TRUE);
if (r == -1 || r > NUM_REGS)
- child_fetch_inferior_registers (NUM_REGS);
+ child_fetch_inferior_registers (regcache, NUM_REGS);
else
for (regno = 0; regno < r; regno++)
- (*the_low_target.fetch_inferior_register) (th, regno);
+ (*the_low_target.fetch_inferior_register) (regcache, th, regno);
}
/* Store a new register value into the current thread context. We don't
change the program's context until later, when we resume it. */
static void
-child_store_inferior_registers (int r)
+child_store_inferior_registers (struct regcache *regcache, int r)
{
int regno;
win32_thread_info *th = thread_rec (current_inferior_ptid (), TRUE);
if (r == -1 || r == 0 || r > NUM_REGS)
- child_store_inferior_registers (NUM_REGS);
+ child_store_inferior_registers (regcache, NUM_REGS);
else
for (regno = 0; regno < r; regno++)
- (*the_low_target.store_inferior_register) (th, regno);
+ (*the_low_target.store_inferior_register) (regcache, th, regno);
}
/* Map the Windows error number in ERROR to a locale-dependent error
return 0;
}
+static void
+win32_mourn (struct process_info *process)
+{
+ remove_process (process);
+}
+
/* Wait for inferiors to end. */
static void
win32_join (int pid)
char *address_ptr;
int len = 0;
char b[2];
- DWORD done;
+ SIZE_T done;
/* Attempt to read the name of the dll that was detected.
This is documented to work only when actively debugging
}
static int
-psapi_get_dll_name (DWORD BaseAddress, char *dll_name_ret)
+psapi_get_dll_name (LPVOID BaseAddress, char *dll_name_ret)
{
DWORD len;
MODULEINFO mi;
(int) err, strwinerror (err));
}
- if ((DWORD) (mi.lpBaseOfDll) == BaseAddress)
+ if (mi.lpBaseOfDll == BaseAddress)
{
len = (*win32_GetModuleFileNameExA) (current_process_handle,
DllHandle[i],
}
static int
-toolhelp_get_dll_name (DWORD BaseAddress, char *dll_name_ret)
+toolhelp_get_dll_name (LPVOID BaseAddress, char *dll_name_ret)
{
HANDLE snapshot_module;
MODULEENTRY32 modEntry = { sizeof (MODULEENTRY32) };
/* Ignore the first module, which is the exe. */
if (win32_Module32First (snapshot_module, &modEntry))
while (win32_Module32Next (snapshot_module, &modEntry))
- if ((DWORD) modEntry.modBaseAddr == BaseAddress)
+ if (modEntry.modBaseAddr == BaseAddress)
{
#ifdef UNICODE
wcstombs (dll_name_ret, modEntry.szExePath, MAX_PATH + 1);
LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll;
char dll_buf[MAX_PATH + 1];
char *dll_name = NULL;
- DWORD load_addr;
+ CORE_ADDR load_addr;
dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
/* Windows does not report the image name of the dlls in the debug
event on attaches. We resort to iterating over the list of
loaded dlls looking for a match by image base. */
- if (!psapi_get_dll_name ((DWORD) event->lpBaseOfDll, dll_buf))
+ if (!psapi_get_dll_name (event->lpBaseOfDll, dll_buf))
{
if (!server_waiting)
/* On some versions of Windows and Windows CE, we can't create
toolhelp snapshots while the inferior is stopped in a
LOAD_DLL_DEBUG_EVENT due to a dll load, but we can while
Windows is reporting the already loaded dlls. */
- toolhelp_get_dll_name ((DWORD) event->lpBaseOfDll, dll_buf);
+ toolhelp_get_dll_name (event->lpBaseOfDll, dll_buf);
}
dll_name = dll_buf;
the offset from 0 of the first byte in an image - because
of the file header and the section alignment. */
- load_addr = (DWORD) event->lpBaseOfDll + 0x1000;
+ load_addr = (CORE_ADDR) (uintptr_t) event->lpBaseOfDll + 0x1000;
win32_add_one_solib (dll_name, load_addr);
}
handle_unload_dll (void)
{
CORE_ADDR load_addr =
- (CORE_ADDR) (DWORD) current_event.u.UnloadDll.lpBaseOfDll;
+ (CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll;
load_addr += 0x1000;
unloaded_dll (NULL, load_addr);
}
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
return;
}
- OUTMSG2 (("gdbserver: unknown target exception 0x%08lx at 0x%08lx",
+ OUTMSG2 (("gdbserver: unknown target exception 0x%08lx at 0x%s",
current_event.u.Exception.ExceptionRecord.ExceptionCode,
- (DWORD) current_event.u.Exception.ExceptionRecord.
- ExceptionAddress));
+ phex_nz ((uintptr_t) current_event.u.Exception.ExceptionRecord.
+ ExceptionAddress, sizeof (uintptr_t))));
ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
break;
}
/* Record the existence of this thread. */
child_add_thread (current_event.dwProcessId,
current_event.dwThreadId,
- current_event.u.CreateThread.hThread);
+ current_event.u.CreateThread.hThread,
+ current_event.u.CreateThread.lpThreadLocalBase);
break;
case EXIT_THREAD_DEBUG_EVENT:
/* Add the main thread. */
child_add_thread (current_event.dwProcessId,
main_thread_id,
- current_event.u.CreateProcessInfo.hThread);
+ current_event.u.CreateProcessInfo.hThread,
+ current_event.u.CreateProcessInfo.lpThreadLocalBase);
ourstatus->value.related_pid = debug_event_ptid (¤t_event);
#ifdef _WIN32_WCE
static ptid_t
win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
- struct process_info *process;
+ struct regcache *regcache;
while (1)
{
case TARGET_WAITKIND_EXITED:
OUTMSG2 (("Child exited with retcode = %x\n",
ourstatus->value.integer));
-
- process = find_process_pid (current_process_id);
- remove_process (process);
win32_clear_inferiors ();
return pid_to_ptid (current_event.dwProcessId);
case TARGET_WAITKIND_STOPPED:
OUTMSG2 (("Child Stopped with signal = %d \n",
ourstatus->value.sig));
- child_fetch_inferior_registers (-1);
+ regcache = get_thread_regcache (current_inferior, 1);
+ child_fetch_inferior_registers (regcache, -1);
if (ourstatus->kind == TARGET_WAITKIND_LOADED
&& !server_waiting)
/* Fetch registers from the inferior process.
If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
static void
-win32_fetch_inferior_registers (int regno)
+win32_fetch_inferior_registers (struct regcache *regcache, int regno)
{
- child_fetch_inferior_registers (regno);
+ child_fetch_inferior_registers (regcache, regno);
}
/* Store registers to the inferior process.
If REGNO is -1, store all registers; otherwise, store at least REGNO. */
static void
-win32_store_inferior_registers (int regno)
+win32_store_inferior_registers (struct regcache *regcache, int regno)
{
- child_store_inferior_registers (regno);
+ child_store_inferior_registers (regcache, regno);
}
/* Read memory from the inferior process. This should generally be
}
#endif
+/* Write Windows OS Thread Information Block address. */
+
+static int
+win32_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
+{
+ win32_thread_info *th;
+ th = thread_rec (ptid, 0);
+ if (th == NULL)
+ return 0;
+ if (addr != NULL)
+ *addr = th->thread_local_base;
+ return 1;
+}
+
static struct target_ops win32_target_ops = {
win32_create_inferior,
win32_attach,
win32_kill,
win32_detach,
+ win32_mourn,
win32_join,
win32_thread_alive,
win32_resume,
win32_store_inferior_registers,
win32_read_inferior_memory,
win32_write_inferior_memory,
- NULL,
+ NULL, /* lookup_symbols */
win32_request_interrupt,
- NULL,
+ NULL, /* read_auxv */
win32_insert_point,
win32_remove_point,
win32_stopped_by_watchpoint,
win32_stopped_data_address,
- NULL,
- NULL,
- NULL,
+ NULL, /* read_offsets */
+ NULL, /* get_tls_address */
+ NULL, /* qxfer_spu */
#ifdef _WIN32_WCE
wince_hostio_last_error,
#else
hostio_last_error_from_errno,
#endif
+ NULL, /* qxfer_osdata */
+ NULL, /* qxfer_siginfo */
+ NULL, /* supports_non_stop */
+ NULL, /* async */
+ NULL, /* start_non_stop */
+ NULL, /* supports_multi_process */
+ NULL, /* handle_monitor_command */
+ NULL, /* core_of_thread */
+ NULL, /* process_qsupported */
+ NULL, /* supports_tracepoints */
+ NULL, /* read_pc */
+ NULL, /* write_pc */
+ NULL, /* thread_stopped */
+ NULL, /* pause_all */
+ win32_get_tib_address,
};
/* Initialize the Win32 backend. */