| 1 |
/* Internal interfaces for the Win32 specific target code for gdbserver. |
| 2 |
Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GDB. |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 18 |
|
| 19 |
#ifndef GDBSERVER_WIN32_LOW_H |
| 20 |
#define GDBSERVER_WIN32_LOW_H |
| 21 |
|
| 22 |
#include <windows.h> |
| 23 |
#include "nat/windows-nat.h" |
| 24 |
#include "gdbsupport/osabi.h" |
| 25 |
|
| 26 |
struct target_desc; |
| 27 |
|
| 28 |
/* The inferior's target description. This is a global because the |
| 29 |
Windows ports support neither bi-arch nor multi-process. */ |
| 30 |
extern const struct target_desc *win32_tdesc; |
| 31 |
#ifdef __x86_64__ |
| 32 |
extern const struct target_desc *wow64_win32_tdesc; |
| 33 |
#endif |
| 34 |
|
| 35 |
#ifdef __CYGWIN__ |
| 36 |
constexpr enum gdb_osabi WINDOWS_OSABI = GDB_OSABI_CYGWIN; |
| 37 |
#else |
| 38 |
constexpr enum gdb_osabi WINDOWS_OSABI = GDB_OSABI_WINDOWS; |
| 39 |
#endif |
| 40 |
|
| 41 |
struct win32_target_ops |
| 42 |
{ |
| 43 |
/* Architecture-specific setup. */ |
| 44 |
void (*arch_setup) (void); |
| 45 |
|
| 46 |
/* The number of target registers. */ |
| 47 |
int (*num_regs) (void); |
| 48 |
|
| 49 |
/* Perform initializations on startup. */ |
| 50 |
void (*initial_stuff) (void); |
| 51 |
|
| 52 |
/* Fetch the context from the inferior. */ |
| 53 |
void (*get_thread_context) (windows_nat::windows_thread_info *th); |
| 54 |
|
| 55 |
/* Called just before resuming the thread. */ |
| 56 |
void (*prepare_to_resume) (windows_nat::windows_thread_info *th); |
| 57 |
|
| 58 |
/* Called when a thread was added. */ |
| 59 |
void (*thread_added) (windows_nat::windows_thread_info *th); |
| 60 |
|
| 61 |
/* Fetch register from gdbserver regcache data. */ |
| 62 |
void (*fetch_inferior_register) (struct regcache *regcache, |
| 63 |
windows_nat::windows_thread_info *th, |
| 64 |
int r); |
| 65 |
|
| 66 |
/* Store a new register value into the thread context of TH. */ |
| 67 |
void (*store_inferior_register) (struct regcache *regcache, |
| 68 |
windows_nat::windows_thread_info *th, |
| 69 |
int r); |
| 70 |
|
| 71 |
void (*single_step) (windows_nat::windows_thread_info *th); |
| 72 |
|
| 73 |
const unsigned char *breakpoint; |
| 74 |
int breakpoint_len; |
| 75 |
|
| 76 |
/* Amount by which to decrement the PC after a breakpoint is |
| 77 |
hit. */ |
| 78 |
int decr_pc_after_break; |
| 79 |
|
| 80 |
/* Get the PC register from REGCACHE. */ |
| 81 |
CORE_ADDR (*get_pc) (struct regcache *regcache); |
| 82 |
/* Set the PC register in REGCACHE. */ |
| 83 |
void (*set_pc) (struct regcache *regcache, CORE_ADDR newpc); |
| 84 |
|
| 85 |
/* Breakpoint/Watchpoint related functions. See target.h for comments. */ |
| 86 |
int (*supports_z_point_type) (char z_type); |
| 87 |
int (*insert_point) (enum raw_bkpt_type type, CORE_ADDR addr, |
| 88 |
int size, struct raw_breakpoint *bp); |
| 89 |
int (*remove_point) (enum raw_bkpt_type type, CORE_ADDR addr, |
| 90 |
int size, struct raw_breakpoint *bp); |
| 91 |
int (*stopped_by_watchpoint) (void); |
| 92 |
CORE_ADDR (*stopped_data_address) (void); |
| 93 |
}; |
| 94 |
|
| 95 |
extern struct win32_target_ops the_low_target; |
| 96 |
|
| 97 |
/* Target ops definitions for a Win32 target. */ |
| 98 |
|
| 99 |
class win32_process_target : public process_stratum_target |
| 100 |
{ |
| 101 |
public: |
| 102 |
|
| 103 |
int create_inferior (const char *program, |
| 104 |
const std::string &program_args) override; |
| 105 |
|
| 106 |
int attach (unsigned long pid) override; |
| 107 |
|
| 108 |
int kill (process_info *proc) override; |
| 109 |
|
| 110 |
int detach (process_info *proc) override; |
| 111 |
|
| 112 |
void mourn (process_info *proc) override; |
| 113 |
|
| 114 |
void join (int pid) override; |
| 115 |
|
| 116 |
bool thread_alive (ptid_t pid) override; |
| 117 |
|
| 118 |
void resume (thread_resume *resume_info, size_t n) override; |
| 119 |
|
| 120 |
ptid_t wait (ptid_t ptid, target_waitstatus *status, |
| 121 |
target_wait_flags options) override; |
| 122 |
|
| 123 |
void fetch_registers (regcache *regcache, int regno) override; |
| 124 |
|
| 125 |
void store_registers (regcache *regcache, int regno) override; |
| 126 |
|
| 127 |
int read_memory (CORE_ADDR memaddr, unsigned char *myaddr, |
| 128 |
int len) override; |
| 129 |
|
| 130 |
int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, |
| 131 |
int len) override; |
| 132 |
|
| 133 |
void request_interrupt () override; |
| 134 |
|
| 135 |
bool supports_z_point_type (char z_type) override; |
| 136 |
|
| 137 |
int insert_point (enum raw_bkpt_type type, CORE_ADDR addr, |
| 138 |
int size, raw_breakpoint *bp) override; |
| 139 |
|
| 140 |
int remove_point (enum raw_bkpt_type type, CORE_ADDR addr, |
| 141 |
int size, raw_breakpoint *bp) override; |
| 142 |
|
| 143 |
bool supports_hardware_single_step () override; |
| 144 |
|
| 145 |
bool stopped_by_watchpoint () override; |
| 146 |
|
| 147 |
CORE_ADDR stopped_data_address () override; |
| 148 |
|
| 149 |
bool supports_qxfer_siginfo () override; |
| 150 |
|
| 151 |
int qxfer_siginfo (const char *annex, unsigned char *readbuf, |
| 152 |
unsigned const char *writebuf, |
| 153 |
CORE_ADDR offset, int len) override; |
| 154 |
|
| 155 |
bool supports_get_tib_address () override; |
| 156 |
|
| 157 |
int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override; |
| 158 |
|
| 159 |
const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override; |
| 160 |
|
| 161 |
CORE_ADDR read_pc (regcache *regcache) override; |
| 162 |
|
| 163 |
void write_pc (regcache *regcache, CORE_ADDR pc) override; |
| 164 |
|
| 165 |
bool stopped_by_sw_breakpoint () override; |
| 166 |
|
| 167 |
bool supports_stopped_by_sw_breakpoint () override; |
| 168 |
|
| 169 |
const char *thread_name (ptid_t thread) override; |
| 170 |
|
| 171 |
bool supports_pid_to_exec_file () override |
| 172 |
{ return true; } |
| 173 |
|
| 174 |
const char *pid_to_exec_file (int pid) override; |
| 175 |
|
| 176 |
bool supports_disable_randomization () override |
| 177 |
{ |
| 178 |
return windows_nat::disable_randomization_available (); |
| 179 |
} |
| 180 |
}; |
| 181 |
|
| 182 |
struct gdbserver_windows_process : public windows_nat::windows_process_info |
| 183 |
{ |
| 184 |
windows_nat::windows_thread_info *thread_rec |
| 185 |
(ptid_t ptid, |
| 186 |
windows_nat::thread_disposition_type disposition) override; |
| 187 |
int handle_output_debug_string (struct target_waitstatus *ourstatus) override; |
| 188 |
void handle_load_dll (const char *dll_name, LPVOID base) override; |
| 189 |
void handle_unload_dll () override; |
| 190 |
bool handle_access_violation (const EXCEPTION_RECORD *rec) override; |
| 191 |
|
| 192 |
int attaching = 0; |
| 193 |
|
| 194 |
/* A status that hasn't been reported to the core yet, and so |
| 195 |
win32_wait should return it next, instead of fetching the next |
| 196 |
debug event off the win32 API. */ |
| 197 |
struct target_waitstatus cached_status; |
| 198 |
|
| 199 |
/* Non zero if an interrupt request is to be satisfied by suspending |
| 200 |
all threads. */ |
| 201 |
int soft_interrupt_requested = 0; |
| 202 |
|
| 203 |
/* Non zero if the inferior is stopped in a simulated breakpoint done |
| 204 |
by suspending all the threads. */ |
| 205 |
int faked_breakpoint = 0; |
| 206 |
|
| 207 |
/* True if current_process_handle needs to be closed. */ |
| 208 |
bool open_process_used = false; |
| 209 |
|
| 210 |
/* Zero during the child initialization phase, and nonzero |
| 211 |
otherwise. */ |
| 212 |
int child_initialization_done = 0; |
| 213 |
}; |
| 214 |
|
| 215 |
/* The sole Windows process. */ |
| 216 |
extern gdbserver_windows_process windows_process; |
| 217 |
|
| 218 |
/* Retrieve the context for this thread, if not already retrieved. */ |
| 219 |
extern void win32_require_context (windows_nat::windows_thread_info *th); |
| 220 |
|
| 221 |
#endif /* GDBSERVER_WIN32_LOW_H */ |