| 1 | /* Internal interfaces for the Win32 specific target code for gdbserver. |
| 2 | Copyright (C) 2007-2020 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 | |
| 25 | struct target_desc; |
| 26 | |
| 27 | /* The inferior's target description. This is a global because the |
| 28 | Windows ports support neither bi-arch nor multi-process. */ |
| 29 | extern const struct target_desc *win32_tdesc; |
| 30 | #ifdef __x86_64__ |
| 31 | extern const struct target_desc *wow64_win32_tdesc; |
| 32 | |
| 33 | extern bool wow64_process; |
| 34 | |
| 35 | typedef BOOL (WINAPI *winapi_Wow64GetThreadContext) (HANDLE, PWOW64_CONTEXT); |
| 36 | extern winapi_Wow64GetThreadContext win32_Wow64GetThreadContext; |
| 37 | #endif |
| 38 | |
| 39 | struct win32_target_ops |
| 40 | { |
| 41 | /* Architecture-specific setup. */ |
| 42 | void (*arch_setup) (void); |
| 43 | |
| 44 | /* The number of target registers. */ |
| 45 | int (*num_regs) (void); |
| 46 | |
| 47 | /* Perform initializations on startup. */ |
| 48 | void (*initial_stuff) (void); |
| 49 | |
| 50 | /* Fetch the context from the inferior. */ |
| 51 | void (*get_thread_context) (windows_nat::windows_thread_info *th); |
| 52 | |
| 53 | /* Called just before resuming the thread. */ |
| 54 | void (*prepare_to_resume) (windows_nat::windows_thread_info *th); |
| 55 | |
| 56 | /* Called when a thread was added. */ |
| 57 | void (*thread_added) (windows_nat::windows_thread_info *th); |
| 58 | |
| 59 | /* Fetch register from gdbserver regcache data. */ |
| 60 | void (*fetch_inferior_register) (struct regcache *regcache, |
| 61 | windows_nat::windows_thread_info *th, |
| 62 | int r); |
| 63 | |
| 64 | /* Store a new register value into the thread context of TH. */ |
| 65 | void (*store_inferior_register) (struct regcache *regcache, |
| 66 | windows_nat::windows_thread_info *th, |
| 67 | int r); |
| 68 | |
| 69 | void (*single_step) (windows_nat::windows_thread_info *th); |
| 70 | |
| 71 | const unsigned char *breakpoint; |
| 72 | int breakpoint_len; |
| 73 | |
| 74 | /* Amount by which to decrement the PC after a breakpoint is |
| 75 | hit. */ |
| 76 | int decr_pc_after_break; |
| 77 | |
| 78 | /* Get the PC register from REGCACHE. */ |
| 79 | CORE_ADDR (*get_pc) (struct regcache *regcache); |
| 80 | /* Set the PC register in REGCACHE. */ |
| 81 | void (*set_pc) (struct regcache *regcache, CORE_ADDR newpc); |
| 82 | |
| 83 | /* Breakpoint/Watchpoint related functions. See target.h for comments. */ |
| 84 | int (*supports_z_point_type) (char z_type); |
| 85 | int (*insert_point) (enum raw_bkpt_type type, CORE_ADDR addr, |
| 86 | int size, struct raw_breakpoint *bp); |
| 87 | int (*remove_point) (enum raw_bkpt_type type, CORE_ADDR addr, |
| 88 | int size, struct raw_breakpoint *bp); |
| 89 | int (*stopped_by_watchpoint) (void); |
| 90 | CORE_ADDR (*stopped_data_address) (void); |
| 91 | }; |
| 92 | |
| 93 | extern struct win32_target_ops the_low_target; |
| 94 | |
| 95 | /* Target ops definitions for a Win32 target. */ |
| 96 | |
| 97 | class win32_process_target : public process_stratum_target |
| 98 | { |
| 99 | public: |
| 100 | |
| 101 | int create_inferior (const char *program, |
| 102 | const std::vector<char *> &program_args) override; |
| 103 | |
| 104 | int attach (unsigned long pid) override; |
| 105 | |
| 106 | int kill (process_info *proc) override; |
| 107 | |
| 108 | int detach (process_info *proc) override; |
| 109 | |
| 110 | void mourn (process_info *proc) override; |
| 111 | |
| 112 | void join (int pid) override; |
| 113 | |
| 114 | bool thread_alive (ptid_t pid) override; |
| 115 | |
| 116 | void resume (thread_resume *resume_info, size_t n) override; |
| 117 | |
| 118 | ptid_t wait (ptid_t ptid, target_waitstatus *status, |
| 119 | int options) override; |
| 120 | |
| 121 | void fetch_registers (regcache *regcache, int regno) override; |
| 122 | |
| 123 | void store_registers (regcache *regcache, int regno) override; |
| 124 | |
| 125 | int read_memory (CORE_ADDR memaddr, unsigned char *myaddr, |
| 126 | int len) override; |
| 127 | |
| 128 | int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, |
| 129 | int len) override; |
| 130 | |
| 131 | void request_interrupt () override; |
| 132 | |
| 133 | bool supports_z_point_type (char z_type) override; |
| 134 | |
| 135 | int insert_point (enum raw_bkpt_type type, CORE_ADDR addr, |
| 136 | int size, raw_breakpoint *bp) override; |
| 137 | |
| 138 | int remove_point (enum raw_bkpt_type type, CORE_ADDR addr, |
| 139 | int size, raw_breakpoint *bp) override; |
| 140 | |
| 141 | bool supports_hardware_single_step () override; |
| 142 | |
| 143 | bool stopped_by_watchpoint () override; |
| 144 | |
| 145 | CORE_ADDR stopped_data_address () override; |
| 146 | |
| 147 | #ifdef _WIN32_WCE |
| 148 | void hostio_last_error (char *buf) override; |
| 149 | #endif |
| 150 | |
| 151 | bool supports_qxfer_siginfo () override; |
| 152 | |
| 153 | int qxfer_siginfo (const char *annex, unsigned char *readbuf, |
| 154 | unsigned const char *writebuf, |
| 155 | CORE_ADDR offset, int len) override; |
| 156 | |
| 157 | bool supports_get_tib_address () override; |
| 158 | |
| 159 | int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override; |
| 160 | |
| 161 | const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override; |
| 162 | |
| 163 | CORE_ADDR read_pc (regcache *regcache) override; |
| 164 | |
| 165 | void write_pc (regcache *regcache, CORE_ADDR pc) override; |
| 166 | |
| 167 | bool stopped_by_sw_breakpoint () override; |
| 168 | |
| 169 | bool supports_stopped_by_sw_breakpoint () override; |
| 170 | }; |
| 171 | |
| 172 | /* Retrieve the context for this thread, if not already retrieved. */ |
| 173 | extern void win32_require_context (windows_nat::windows_thread_info *th); |
| 174 | |
| 175 | /* Map the Windows error number in ERROR to a locale-dependent error |
| 176 | message string and return a pointer to it. Typically, the values |
| 177 | for ERROR come from GetLastError. |
| 178 | |
| 179 | The string pointed to shall not be modified by the application, |
| 180 | but may be overwritten by a subsequent call to strwinerror |
| 181 | |
| 182 | The strwinerror function does not change the current setting |
| 183 | of GetLastError. */ |
| 184 | extern char * strwinerror (DWORD error); |
| 185 | |
| 186 | #endif /* GDBSERVER_WIN32_LOW_H */ |