xref: /netbsd-src/external/gpl3/gdb/dist/gdbserver/win32-low.h (revision 13ed34fa5696ce1ff8e9519eeb5619eee4331db8)
18dffb485Schristos /* Internal interfaces for the Win32 specific target code for gdbserver.
2*13ed34faSchristos    Copyright (C) 2007-2024 Free Software Foundation, Inc.
38dffb485Schristos 
48dffb485Schristos    This file is part of GDB.
58dffb485Schristos 
68dffb485Schristos    This program is free software; you can redistribute it and/or modify
78dffb485Schristos    it under the terms of the GNU General Public License as published by
88dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
98dffb485Schristos    (at your option) any later version.
108dffb485Schristos 
118dffb485Schristos    This program is distributed in the hope that it will be useful,
128dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
138dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
148dffb485Schristos    GNU General Public License for more details.
158dffb485Schristos 
168dffb485Schristos    You should have received a copy of the GNU General Public License
178dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
188dffb485Schristos 
198dffb485Schristos #ifndef GDBSERVER_WIN32_LOW_H
208dffb485Schristos #define GDBSERVER_WIN32_LOW_H
218dffb485Schristos 
228dffb485Schristos #include <windows.h>
238dffb485Schristos #include "nat/windows-nat.h"
248dffb485Schristos 
258dffb485Schristos struct target_desc;
268dffb485Schristos 
278dffb485Schristos /* The inferior's target description.  This is a global because the
288dffb485Schristos    Windows ports support neither bi-arch nor multi-process.  */
298dffb485Schristos extern const struct target_desc *win32_tdesc;
308dffb485Schristos #ifdef __x86_64__
318dffb485Schristos extern const struct target_desc *wow64_win32_tdesc;
328dffb485Schristos #endif
338dffb485Schristos 
348dffb485Schristos struct win32_target_ops
358dffb485Schristos {
368dffb485Schristos   /* Architecture-specific setup.  */
378dffb485Schristos   void (*arch_setup) (void);
388dffb485Schristos 
398dffb485Schristos   /* The number of target registers.  */
408dffb485Schristos   int (*num_regs) (void);
418dffb485Schristos 
428dffb485Schristos   /* Perform initializations on startup.  */
438dffb485Schristos   void (*initial_stuff) (void);
448dffb485Schristos 
458dffb485Schristos   /* Fetch the context from the inferior.  */
468dffb485Schristos   void (*get_thread_context) (windows_nat::windows_thread_info *th);
478dffb485Schristos 
488dffb485Schristos   /* Called just before resuming the thread.  */
498dffb485Schristos   void (*prepare_to_resume) (windows_nat::windows_thread_info *th);
508dffb485Schristos 
518dffb485Schristos   /* Called when a thread was added.  */
528dffb485Schristos   void (*thread_added) (windows_nat::windows_thread_info *th);
538dffb485Schristos 
548dffb485Schristos   /* Fetch register from gdbserver regcache data.  */
558dffb485Schristos   void (*fetch_inferior_register) (struct regcache *regcache,
568dffb485Schristos 				   windows_nat::windows_thread_info *th,
578dffb485Schristos 				   int r);
588dffb485Schristos 
598dffb485Schristos   /* Store a new register value into the thread context of TH.  */
608dffb485Schristos   void (*store_inferior_register) (struct regcache *regcache,
618dffb485Schristos 				   windows_nat::windows_thread_info *th,
628dffb485Schristos 				   int r);
638dffb485Schristos 
648dffb485Schristos   void (*single_step) (windows_nat::windows_thread_info *th);
658dffb485Schristos 
668dffb485Schristos   const unsigned char *breakpoint;
678dffb485Schristos   int breakpoint_len;
688dffb485Schristos 
698dffb485Schristos   /* Amount by which to decrement the PC after a breakpoint is
708dffb485Schristos      hit.  */
718dffb485Schristos   int decr_pc_after_break;
728dffb485Schristos 
738dffb485Schristos   /* Get the PC register from REGCACHE.  */
748dffb485Schristos   CORE_ADDR (*get_pc) (struct regcache *regcache);
758dffb485Schristos   /* Set the PC register in REGCACHE.  */
768dffb485Schristos   void (*set_pc) (struct regcache *regcache, CORE_ADDR newpc);
778dffb485Schristos 
788dffb485Schristos   /* Breakpoint/Watchpoint related functions.  See target.h for comments.  */
798dffb485Schristos   int (*supports_z_point_type) (char z_type);
808dffb485Schristos   int (*insert_point) (enum raw_bkpt_type type, CORE_ADDR addr,
818dffb485Schristos 		       int size, struct raw_breakpoint *bp);
828dffb485Schristos   int (*remove_point) (enum raw_bkpt_type type, CORE_ADDR addr,
838dffb485Schristos 		       int size, struct raw_breakpoint *bp);
848dffb485Schristos   int (*stopped_by_watchpoint) (void);
858dffb485Schristos   CORE_ADDR (*stopped_data_address) (void);
868dffb485Schristos };
878dffb485Schristos 
888dffb485Schristos extern struct win32_target_ops the_low_target;
898dffb485Schristos 
908dffb485Schristos /* Target ops definitions for a Win32 target.  */
918dffb485Schristos 
928dffb485Schristos class win32_process_target : public process_stratum_target
938dffb485Schristos {
948dffb485Schristos public:
958dffb485Schristos 
968dffb485Schristos   int create_inferior (const char *program,
978dffb485Schristos 		       const std::vector<char *> &program_args) override;
988dffb485Schristos 
998dffb485Schristos   int attach (unsigned long pid) override;
1008dffb485Schristos 
1018dffb485Schristos   int kill (process_info *proc) override;
1028dffb485Schristos 
1038dffb485Schristos   int detach (process_info *proc) override;
1048dffb485Schristos 
1058dffb485Schristos   void mourn (process_info *proc) override;
1068dffb485Schristos 
1078dffb485Schristos   void join (int pid) override;
1088dffb485Schristos 
1098dffb485Schristos   bool thread_alive (ptid_t pid) override;
1108dffb485Schristos 
1118dffb485Schristos   void resume (thread_resume *resume_info, size_t n) override;
1128dffb485Schristos 
1138dffb485Schristos   ptid_t wait (ptid_t ptid, target_waitstatus *status,
1144b169a6bSchristos 	       target_wait_flags options) override;
1158dffb485Schristos 
1168dffb485Schristos   void fetch_registers (regcache *regcache, int regno) override;
1178dffb485Schristos 
1188dffb485Schristos   void store_registers (regcache *regcache, int regno) override;
1198dffb485Schristos 
1208dffb485Schristos   int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
1218dffb485Schristos 		   int len) override;
1228dffb485Schristos 
1238dffb485Schristos   int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
1248dffb485Schristos 		    int len) override;
1258dffb485Schristos 
1268dffb485Schristos   void request_interrupt () override;
1278dffb485Schristos 
1288dffb485Schristos   bool supports_z_point_type (char z_type) override;
1298dffb485Schristos 
1308dffb485Schristos   int insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
1318dffb485Schristos 		    int size, raw_breakpoint *bp) override;
1328dffb485Schristos 
1338dffb485Schristos   int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
1348dffb485Schristos 		    int size, raw_breakpoint *bp) override;
1358dffb485Schristos 
1368dffb485Schristos   bool supports_hardware_single_step () override;
1378dffb485Schristos 
1388dffb485Schristos   bool stopped_by_watchpoint () override;
1398dffb485Schristos 
1408dffb485Schristos   CORE_ADDR stopped_data_address () override;
1418dffb485Schristos 
1428dffb485Schristos   bool supports_qxfer_siginfo () override;
1438dffb485Schristos 
1448dffb485Schristos   int qxfer_siginfo (const char *annex, unsigned char *readbuf,
1458dffb485Schristos 		     unsigned const char *writebuf,
1468dffb485Schristos 		     CORE_ADDR offset, int len) override;
1478dffb485Schristos 
1488dffb485Schristos   bool supports_get_tib_address () override;
1498dffb485Schristos 
1508dffb485Schristos   int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
1518dffb485Schristos 
1528dffb485Schristos   const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
1538dffb485Schristos 
1548dffb485Schristos   CORE_ADDR read_pc (regcache *regcache) override;
1558dffb485Schristos 
1568dffb485Schristos   void write_pc (regcache *regcache, CORE_ADDR pc) override;
1578dffb485Schristos 
1588dffb485Schristos   bool stopped_by_sw_breakpoint () override;
1598dffb485Schristos 
1608dffb485Schristos   bool supports_stopped_by_sw_breakpoint () override;
1614b169a6bSchristos 
1624b169a6bSchristos   const char *thread_name (ptid_t thread) override;
1634b169a6bSchristos 
1644b169a6bSchristos   bool supports_pid_to_exec_file () override
1654b169a6bSchristos   { return true; }
1664b169a6bSchristos 
1674b169a6bSchristos   const char *pid_to_exec_file (int pid) override;
1684b169a6bSchristos 
1694b169a6bSchristos   bool supports_disable_randomization () override
1704b169a6bSchristos   {
1714b169a6bSchristos     return windows_nat::disable_randomization_available ();
1724b169a6bSchristos   }
1738dffb485Schristos };
1748dffb485Schristos 
1754b169a6bSchristos struct gdbserver_windows_process : public windows_nat::windows_process_info
1764b169a6bSchristos {
1774b169a6bSchristos   windows_nat::windows_thread_info *thread_rec
1784b169a6bSchristos        (ptid_t ptid,
1794b169a6bSchristos 	windows_nat::thread_disposition_type disposition) override;
1804b169a6bSchristos   int handle_output_debug_string (struct target_waitstatus *ourstatus) override;
1814b169a6bSchristos   void handle_load_dll (const char *dll_name, LPVOID base) override;
1824b169a6bSchristos   void handle_unload_dll () override;
1834b169a6bSchristos   bool handle_access_violation (const EXCEPTION_RECORD *rec) override;
1844b169a6bSchristos 
1854b169a6bSchristos   int attaching = 0;
1864b169a6bSchristos 
1874b169a6bSchristos   /* A status that hasn't been reported to the core yet, and so
1884b169a6bSchristos      win32_wait should return it next, instead of fetching the next
1894b169a6bSchristos      debug event off the win32 API.  */
1904b169a6bSchristos   struct target_waitstatus cached_status;
1914b169a6bSchristos 
1924b169a6bSchristos   /* Non zero if an interrupt request is to be satisfied by suspending
1934b169a6bSchristos      all threads.  */
1944b169a6bSchristos   int soft_interrupt_requested = 0;
1954b169a6bSchristos 
1964b169a6bSchristos   /* Non zero if the inferior is stopped in a simulated breakpoint done
1974b169a6bSchristos      by suspending all the threads.  */
1984b169a6bSchristos   int faked_breakpoint = 0;
1994b169a6bSchristos 
2004b169a6bSchristos   /* True if current_process_handle needs to be closed.  */
2014b169a6bSchristos   bool open_process_used = false;
2024b169a6bSchristos 
2034b169a6bSchristos   /* Zero during the child initialization phase, and nonzero
2044b169a6bSchristos      otherwise.  */
2054b169a6bSchristos   int child_initialization_done = 0;
2064b169a6bSchristos };
2074b169a6bSchristos 
2084b169a6bSchristos /* The sole Windows process.  */
2094b169a6bSchristos extern gdbserver_windows_process windows_process;
2104b169a6bSchristos 
2118dffb485Schristos /* Retrieve the context for this thread, if not already retrieved.  */
2128dffb485Schristos extern void win32_require_context (windows_nat::windows_thread_info *th);
2138dffb485Schristos 
2148dffb485Schristos #endif /* GDBSERVER_WIN32_LOW_H */
215