/* Target-vector operations for controlling windows child processes, for GDB.
- Copyright (C) 1995-2017 Free Software Foundation, Inc.
+ Copyright (C) 1995-2018 Free Software Foundation, Inc.
Contributed by Cygnus Solutions, A Red Hat Company.
#include <sys/cygwin.h>
#include <cygwin/version.h>
#endif
+#include <algorithm>
#include "buildsym.h"
#include "filenames.h"
#include "x86-nat.h"
#include "complaints.h"
#include "inf-child.h"
+#include "gdb_tilde_expand.h"
#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
#define DEBUG_MEM(x) if (debug_memory) printf_unfiltered x
#define DEBUG_EXCEPT(x) if (debug_exceptions) printf_unfiltered x
-static void windows_interrupt (struct target_ops *self, ptid_t);
+static void windows_interrupt (struct target_ops *self);
static int windows_thread_alive (struct target_ops *, ptid_t);
static void windows_kill_inferior (struct target_ops *);
windows_thread_info *th, int r)
{
char *context_offset = ((char *) &th->context) + mappings[r];
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
long l;
((char *) &th->context) + mappings[r]);
else
{
- for (r = 0; r < gdbarch_num_regs (get_regcache_arch (regcache)); r++)
+ for (r = 0; r < gdbarch_num_regs (regcache->arch ()); r++)
do_windows_store_inferior_registers (regcache, th, r);
}
}
{
char *name;
int from_tty;
- struct section_addr_info *addrs;
+ section_addr_info *addrs;
int mainline;
int flags;
struct ui_file *err, *out;
};
/* Maintain a linked list of "so" information. */
-struct lm_info
+struct lm_info_windows : public lm_info_base
{
- LPVOID load_addr;
+ LPVOID load_addr = 0;
};
static struct so_list solib_start, *solib_end;
}
#endif
so = XCNEW (struct so_list);
- so->lm_info = XNEW (struct lm_info);
- so->lm_info->load_addr = load_addr;
+ lm_info_windows *li = new lm_info_windows;
+ so->lm_info = li;
+ li->load_addr = load_addr;
strcpy (so->so_original_name, name);
#ifndef __CYGWIN__
strcpy (so->so_name, buf);
do_initial_windows_stuff and windows_add_all_dlls for more info
on how we handle DLL loading during that phase). */
-static int
-handle_load_dll (void *dummy)
+static void
+handle_load_dll ()
{
LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll;
char *dll_name;
dll_name = get_image_name (current_process_handle,
event->lpImageName, event->fUnicode);
if (!dll_name)
- return 1;
+ return;
solib_end->next = windows_make_so (dll_name, event->lpBaseOfDll);
solib_end = solib_end->next;
- DEBUG_EVENTS (("gdb: Loading dll \"%s\" at %s.\n", solib_end->so_name,
- host_address_to_string (solib_end->lm_info->load_addr)));
+ lm_info_windows *li = (lm_info_windows *) solib_end->lm_info;
- return 1;
+ DEBUG_EVENTS (("gdb: Loading dll \"%s\" at %s.\n", solib_end->so_name,
+ host_address_to_string (li->load_addr)));
}
static void
windows_free_so (struct so_list *so)
{
- if (so->lm_info)
- xfree (so->lm_info);
+ lm_info_windows *li = (lm_info_windows *) so->lm_info;
+
+ delete li;
xfree (so);
}
do_initial_windows_stuff and windows_add_all_dlls for more info
on how we handle DLL loading during that phase). */
-static int
-handle_unload_dll (void *dummy)
+static void
+handle_unload_dll ()
{
LPVOID lpBaseOfDll = current_event.u.UnloadDll.lpBaseOfDll;
struct so_list *so;
for (so = &solib_start; so->next != NULL; so = so->next)
- if (so->next->lm_info->load_addr == lpBaseOfDll)
- {
- struct so_list *sodel = so->next;
+ {
+ lm_info_windows *li_next = (lm_info_windows *) so->next->lm_info;
- so->next = sodel->next;
- if (!so->next)
- solib_end = so;
- DEBUG_EVENTS (("gdb: Unloading dll \"%s\".\n", sodel->so_name));
+ if (li_next->load_addr == lpBaseOfDll)
+ {
+ struct so_list *sodel = so->next;
- windows_free_so (sodel);
- return 1;
- }
+ so->next = sodel->next;
+ if (!so->next)
+ solib_end = so;
+ DEBUG_EVENTS (("gdb: Unloading dll \"%s\".\n", sodel->so_name));
+
+ windows_free_so (sodel);
+ return;
+ }
+ }
/* We did not find any DLL that was previously loaded at this address,
so register a complaint. We do not report an error, because we have
32bit and 64bit worlds). */
complaint (&symfile_complaints, _("dll starting at %s not found."),
host_address_to_string (lpBaseOfDll));
+}
- return 0;
+/* Call FUNC wrapped in a TRY/CATCH that swallows all GDB
+ exceptions. */
+
+static void
+catch_errors (void (*func) ())
+{
+ TRY
+ {
+ func ();
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ exception_print (gdb_stderr, ex);
+ }
+ END_CATCH
}
/* Clear list of loaded DLLs. */
}
static void
-signal_event_command (char *args, int from_tty)
+signal_event_command (const char *args, int from_tty)
{
uintptr_t event_id = 0;
char *endargs = NULL;
static int
handle_output_debug_string (struct target_waitstatus *ourstatus)
{
- char *s = NULL;
+ gdb::unique_xmalloc_ptr<char> s;
int retval = 0;
if (!target_read_string
((CORE_ADDR) (uintptr_t) current_event.u.DebugString.lpDebugStringData,
- &s, 1024, 0)
- || !s || !*s)
+ &s, 1024, 0)
+ || !s || !*(s.get ()))
/* nothing to do */;
- else if (!startswith (s, _CYGWIN_SIGNAL_STRING))
+ else if (!startswith (s.get (), _CYGWIN_SIGNAL_STRING))
{
#ifdef __CYGWIN__
- if (!startswith (s, "cYg"))
+ if (!startswith (s.get (), "cYg"))
#endif
{
- char *p = strchr (s, '\0');
+ char *p = strchr (s.get (), '\0');
- if (p > s && *--p == '\n')
+ if (p > s.get () && *--p == '\n')
*p = '\0';
- warning (("%s"), s);
+ warning (("%s"), s.get ());
}
}
#ifdef __CYGWIN__
to be stored at the given address in the inferior. Tell gdb
to treat this like a real signal. */
char *p;
- int sig = strtol (s + sizeof (_CYGWIN_SIGNAL_STRING) - 1, &p, 0);
+ int sig = strtol (s.get () + sizeof (_CYGWIN_SIGNAL_STRING) - 1, &p, 0);
gdb_signal gotasig = gdb_signal_from_host (sig);
ourstatus->value.sig = gotasig;
}
#endif
- if (s)
- xfree (s);
return retval;
}
}
static void
-display_selectors (char * args, int from_tty)
+display_selectors (const char * args, int from_tty)
{
if (!current_thread)
{
if (named_thread != NULL)
{
int thread_name_len;
- char *thread_name;
+ gdb::unique_xmalloc_ptr<char> thread_name;
thread_name_len = target_read_string (thread_name_target,
&thread_name, 1025, NULL);
if (thread_name_len > 0)
{
- thread_name[thread_name_len - 1] = '\0';
+ thread_name.get ()[thread_name_len - 1] = '\0';
xfree (named_thread->name);
- named_thread->name = thread_name;
+ named_thread->name = thread_name.release ();
}
- else
- xfree (thread_name);
}
ourstatus->value.sig = GDB_SIGNAL_TRAP;
result = HANDLE_EXCEPTION_IGNORED;
{
/* Single step by setting t bit. */
struct regcache *regcache = get_current_regcache ();
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
windows_fetch_inferior_registers (ops, regcache,
gdbarch_ps_regnum (gdbarch));
th->context.EFlags |= FLAG_TRACE_BIT;
"EXIT_PROCESS_DEBUG_EVENT"));
if (!windows_initialization_done)
{
- target_terminal_ours ();
+ target_terminal::ours ();
target_mourn_inferior (inferior_ptid);
error (_("During startup program exited with code 0x%x."),
(unsigned int) current_event.u.ExitProcess.dwExitCode);
CloseHandle (current_event.u.LoadDll.hFile);
if (saw_create != 1 || ! windows_initialization_done)
break;
- catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);
+ catch_errors (handle_load_dll);
ourstatus->kind = TARGET_WAITKIND_LOADED;
ourstatus->value.integer = 0;
thread_id = main_thread_id;
"UNLOAD_DLL_DEBUG_EVENT"));
if (saw_create != 1 || ! windows_initialization_done)
break;
- catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);
+ catch_errors (handle_unload_dll);
ourstatus->kind = TARGET_WAITKIND_LOADED;
ourstatus->value.integer = 0;
thread_id = main_thread_id;
{
int pid = -1;
- target_terminal_ours ();
+ target_terminal::ours ();
/* We loop when we get a non-standard exception rather than return
with a SPURIOUS because resume can try and step or modify things,
current thread until we report an event out of windows_wait. */
inferior_ptid = pid_to_ptid (pid);
- target_terminal_init ();
- target_terminal_inferior ();
+ target_terminal::init ();
+ target_terminal::inferior ();
windows_initialization_done = 0;
}
do_initial_windows_stuff (ops, pid, 1);
- target_terminal_ours ();
+ target_terminal::ours ();
}
static void
-windows_detach (struct target_ops *ops, const char *args, int from_tty)
+windows_detach (struct target_ops *ops, inferior *inf, int from_tty)
{
int detached = 1;
#ifdef __CYGWIN__
cygwin_buf_t real_path[__PMAX];
cygwin_buf_t shell[__PMAX]; /* Path to shell */
+ cygwin_buf_t infcwd[__PMAX];
const char *sh;
cygwin_buf_t *toexec;
cygwin_buf_t *cygallargs;
if (!exec_file)
error (_("No executable specified, use `target exec'."));
+ const char *inferior_cwd = get_inferior_cwd ();
+ std::string expanded_infcwd;
+ if (inferior_cwd != NULL)
+ {
+ expanded_infcwd = gdb_tilde_expand (inferior_cwd);
+ /* Mirror slashes on inferior's cwd. */
+ std::replace (expanded_infcwd.begin (), expanded_infcwd.end (),
+ '/', '\\');
+ inferior_cwd = expanded_infcwd.c_str ();
+ }
+
memset (&si, 0, sizeof (si));
si.cb = sizeof (si);
flags |= DEBUG_PROCESS;
}
+ if (inferior_cwd != NULL
+ && cygwin_conv_path (CCP_POSIX_TO_WIN_W, inferior_cwd,
+ infcwd, strlen (inferior_cwd)) < 0)
+ error (_("Error converting inferior cwd: %d"), errno);
+
#ifdef __USEWIDE
args = (cygwin_buf_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2)
* sizeof (wchar_t));
TRUE, /* inherit handles */
flags, /* start flags */
w32_env, /* environment */
- NULL, /* current directory */
+ inferior_cwd != NULL ? infcwd : NULL, /* current
+ directory */
&si,
&pi);
if (w32_env)
TRUE, /* inherit handles */
flags, /* start flags */
w32env, /* environment */
- NULL, /* current directory */
+ inferior_cwd, /* current directory */
&si,
&pi);
if (tty != INVALID_HANDLE_VALUE)
^C on the controlling terminal. */
static void
-windows_interrupt (struct target_ops *self, ptid_t ptid)
+windows_interrupt (struct target_ops *self)
{
DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n"));
CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, current_event.dwProcessId));
obstack_init (&obstack);
obstack_grow_str (&obstack, "<library-list>\n");
for (so = solib_start.next; so; so = so->next)
- windows_xfer_shared_library (so->so_name, (CORE_ADDR)
- (uintptr_t) so->lm_info->load_addr,
- target_gdbarch (), &obstack);
+ {
+ lm_info_windows *li = (lm_info_windows *) so->lm_info;
+
+ windows_xfer_shared_library (so->so_name, (CORE_ADDR)
+ (uintptr_t) li->load_addr,
+ target_gdbarch (), &obstack);
+ }
obstack_grow_str0 (&obstack, "</library-list>\n");
buf = (const char *) obstack_finish (&obstack);
return t;
}
-/* -Wmissing-prototypes */
-extern initialize_file_ftype _initialize_windows_nat;
-
void
_initialize_windows_nat (void)
{
? FALSE : TRUE;
}
-/* -Wmissing-prototypes */
-extern initialize_file_ftype _initialize_check_for_gdb_ini;
-
void
_initialize_check_for_gdb_ini (void)
{
return size;
}
-/* -Wmissing-prototypes */
-extern initialize_file_ftype _initialize_loadable;
-
/* Load any functions which may not be available in ancient versions
of Windows. */