/* Target-vector operations for controlling windows child processes, for GDB.
- Copyright (C) 1995-2019 Free Software Foundation, Inc.
+ Copyright (C) 1995-2020 Free Software Foundation, Inc.
Contributed by Cygnus Solutions, A Red Hat Company.
#include "inf-child.h"
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/pathstuff.h"
+#include "gdbsupport/gdb_wait.h"
#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
WaitForDebugEvent */
static HANDLE current_process_handle; /* Currently executing process */
static windows_thread_info *current_thread; /* Info on currently selected thread */
+static EXCEPTION_RECORD siginfo_er; /* Contents of $_siginfo */
/* Counts of things. */
static int exception_count = 0;
bool get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
const char *thread_name (struct thread_info *) override;
+
+ int get_windows_debug_event (int pid, struct target_waitstatus *ourstatus);
};
static windows_nat_target the_windows_nat_target;
the main thread silently (in reality, this thread is really
more of a process to the user than a thread). */
if (main_thread_p)
- add_thread_silent (ptid);
+ add_thread_silent (&the_windows_nat_target, ptid);
else
- add_thread (ptid);
+ add_thread (&the_windows_nat_target, ptid);
/* Set the debug registers for the new thread if they are used. */
if (debug_registers_used)
target_pid_to_str (ptid).c_str (),
(unsigned) exit_code);
- delete_thread (find_thread_ptid (ptid));
+ delete_thread (find_thread_ptid (&the_windows_nat_target, ptid));
for (th = &thread_head;
th->next != NULL && th->next->id != id;
struct lm_info_windows : public lm_info_base
{
LPVOID load_addr = 0;
+ CORE_ADDR text_offset = 0;
};
static struct so_list solib_start, *solib_end;
static void
windows_clear_solib (void)
{
- solib_start.next = NULL;
+ struct so_list *so;
+
+ for (so = solib_start.next; so; so = solib_start.next)
+ {
+ solib_start.next = so->next;
+ windows_free_so (so);
+ }
+
solib_end = &solib_start;
}
DWORD code = rec->ExceptionCode;
handle_exception_result result = HANDLE_EXCEPTION_HANDLED;
+ memcpy (&siginfo_er, rec, sizeof siginfo_er);
+
ourstatus->kind = TARGET_WAITKIND_STOPPED;
/* Record the context of the current thread. */
/* Get the next event from the child. Returns a non-zero thread id if the event
requires handling by WFI (or whatever). */
-static int
-get_windows_debug_event (struct target_ops *ops,
- int pid, struct target_waitstatus *ourstatus)
+
+int
+windows_nat_target::get_windows_debug_event (int pid,
+ struct target_waitstatus *ourstatus)
{
BOOL debug_event;
DWORD continue_status, event_code;
"CREATE_THREAD_DEBUG_EVENT"));
if (saw_create != 1)
{
- struct inferior *inf;
- inf = find_inferior_pid (current_event.dwProcessId);
+ inferior *inf = find_inferior_pid (this, current_event.dwProcessId);
if (!saw_create && inf->attach_flag)
{
/* Kludge around a Windows bug where first event is a create
windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
current_event.dwThreadId),
0, true /* main_thread_p */);
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ DWORD exit_status = current_event.u.ExitProcess.dwExitCode;
+ /* If the exit status looks like a fatal exception, but we
+ don't recognize the exception's code, make the original
+ exit status value available, to avoid losing
+ information. */
+ int exit_signal
+ = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1;
+ if (exit_signal == -1)
+ {
+ ourstatus->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = exit_status;
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = gdb_signal_from_host (exit_signal);
+ }
thread_id = current_event.dwThreadId;
}
break;
the user tries to resume the execution in the inferior.
This is a classic race that we should try to fix one day. */
SetConsoleCtrlHandler (&ctrl_c_handler, TRUE);
- retval = get_windows_debug_event (this, pid, ourstatus);
+ retval = get_windows_debug_event (pid, ourstatus);
SetConsoleCtrlHandler (&ctrl_c_handler, FALSE);
if (retval)
if (from_tty)
{
- char *exec_file = (char *) get_exec_file (0);
+ const char *exec_file = get_exec_file (0);
if (exec_file)
printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
redirect_inferior_handles (allargs, allargs_copy,
&fd_inp, &fd_out, &fd_err);
if (errno)
- warning (_("Error in redirection: %s."), strerror (errno));
+ warning (_("Error in redirection: %s."), safe_strerror (errno));
else
errno = e;
allargs_len = strlen (allargs_copy);
CHECK (CloseHandle (current_process_handle));
open_process_used = 0;
}
+ siginfo_er.ExceptionCode = 0;
inf_child_target::mourn_inferior ();
}
windows_xfer_shared_library (so->so_name, (CORE_ADDR)
(uintptr_t) li->load_addr,
+ &li->text_offset,
target_gdbarch (), &obstack);
}
obstack_grow_str0 (&obstack, "</library-list>\n");
return len != 0 ? TARGET_XFER_OK : TARGET_XFER_EOF;
}
+/* Helper for windows_nat_target::xfer_partial that handles signal info. */
+
+static enum target_xfer_status
+windows_xfer_siginfo (gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
+{
+ if (siginfo_er.ExceptionCode == 0)
+ return TARGET_XFER_E_IO;
+
+ if (readbuf == nullptr)
+ return TARGET_XFER_E_IO;
+
+ if (offset > sizeof (siginfo_er))
+ return TARGET_XFER_E_IO;
+
+ if (offset + len > sizeof (siginfo_er))
+ len = sizeof (siginfo_er) - offset;
+
+ memcpy (readbuf, (char *) &siginfo_er + offset, len);
+ *xfered_len = len;
+
+ return TARGET_XFER_OK;
+}
+
enum target_xfer_status
windows_nat_target::xfer_partial (enum target_object object,
const char *annex, gdb_byte *readbuf,
return windows_xfer_shared_libraries (this, object, annex, readbuf,
writebuf, offset, len, xfered_len);
+ case TARGET_OBJECT_SIGNAL_INFO:
+ return windows_xfer_siginfo (readbuf, offset, len, xfered_len);
+
default:
if (beneath () == NULL)
{
}
+void _initialize_windows_nat ();
void
-_initialize_windows_nat (void)
+_initialize_windows_nat ()
{
x86_dr_low.set_control = cygwin_set_dr7;
x86_dr_low.set_addr = cygwin_set_dr;
return WaitForSingleObject (thread_rec (tid, FALSE)->h, 0) != WAIT_OBJECT_0;
}
+void _initialize_check_for_gdb_ini ();
void
-_initialize_check_for_gdb_ini (void)
+_initialize_check_for_gdb_ini ()
{
char *homedir;
if (inhibit_gdbinit)
/* Load any functions which may not be available in ancient versions
of Windows. */
+void _initialize_loadable ();
void
-_initialize_loadable (void)
+_initialize_loadable ()
{
HMODULE hm = NULL;