1 /* Target operations for the remote server for GDB. 2 Copyright (C) 2002, 2003, 2004, 2005 3 Free Software Foundation, Inc. 4 5 Contributed by MontaVista Software. 6 7 This file is part of GDB. 8 It has been modified to integrate it in valgrind 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 Boston, MA 02110-1301, USA. */ 24 25 #ifndef TARGET_H 26 #define TARGET_H 27 28 /* This structure describes how to resume a particular thread (or 29 all threads) based on the client's request. If thread is -1, then 30 this entry applies to all threads. These are generally passed around 31 as an array, and terminated by a thread == -1 entry. */ 32 33 struct thread_resume 34 { 35 unsigned long thread; 36 37 /* If non-zero, leave this thread stopped. */ 38 int leave_stopped; 39 40 /* If non-zero, we want to single-step. */ 41 int step; 42 43 /* If non-zero, send this signal when we resume. */ 44 int sig; 45 }; 46 47 struct target_ops 48 { 49 /* Return 1 iff the thread with process ID PID is alive. */ 50 51 int (*thread_alive) (unsigned long pid); 52 53 /* Resume the inferior process. */ 54 55 void (*resume) (struct thread_resume *resume_info); 56 57 /* Wait for the inferior process to change state. 58 59 STATUS will be filled in with a response code to send to GDB. 60 61 Returns the signal which caused the process to stop, in the 62 remote protocol numbering (e.g. TARGET_SIGNAL_STOP), or the 63 exit code as an integer if *STATUS is 'W'. */ 64 65 unsigned char (*wait) (char *status); 66 67 /* Fetch registers from the inferior process. 68 69 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */ 70 71 void (*fetch_registers) (int regno); 72 73 /* Store registers to the inferior process. 74 75 If REGNO is -1, store all registers; otherwise, store at least REGNO. */ 76 77 void (*store_registers) (int regno); 78 79 /* Read memory from the inferior process. This should generally be 80 called through read_inferior_memory, which handles breakpoint shadowing. 81 82 Read LEN bytes at MEMADDR into a buffer at MYADDR. 83 84 Returns 0 on success and errno on failure. */ 85 86 int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len); 87 88 /* Write memory to the inferior process. This should generally be 89 called through write_inferior_memory, which handles breakpoint shadowing. 90 91 Write LEN bytes from the buffer at MYADDR to MEMADDR. 92 93 Returns 0 on success and errno on failure. */ 94 95 int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr, 96 int len); 97 98 /* Send a signal to the inferior process, however is appropriate. */ 99 void (*send_signal) (int); 100 101 /* Returns the name of the xml target description file. 102 returns NULL if no xml target description available. */ 103 char* (*target_xml)(void); 104 105 /* Same but describes also the shadow registers. */ 106 char* (*shadow_target_xml)(void); 107 108 /* Insert and remove a hardware watchpoint. 109 Returns 0 on success, -1 on failure and 1 on unsupported. 110 The type is coded as follows: 111 2 = write watchpoint 112 3 = read watchpoint 113 4 = access watchpoint 114 */ 115 116 int (*insert_watchpoint) (char type, CORE_ADDR addr, int len); 117 int (*remove_watchpoint) (char type, CORE_ADDR addr, int len); 118 119 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */ 120 121 int (*stopped_by_watchpoint) (void); 122 123 /* Returns the address associated with the watchpoint that hit, if any; 124 returns 0 otherwise. */ 125 126 CORE_ADDR (*stopped_data_address) (void); 127 128 }; 129 130 extern struct target_ops *the_target; 131 132 void set_target_ops (struct target_ops *); 133 134 #define detach_inferior() \ 135 (*the_target->detach) () 136 137 #define mythread_alive(pid) \ 138 (*the_target->thread_alive) (pid) 139 140 #define fetch_inferior_registers(regno) \ 141 (*the_target->fetch_registers) (regno) 142 143 #define store_inferior_registers(regno) \ 144 (*the_target->store_registers) (regno) 145 146 #define mywait(statusp) \ 147 (*the_target->wait) (statusp) 148 149 int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len); 150 151 int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr, 152 int len); 153 154 void set_desired_inferior (int id); 155 156 /* like memcpy but first check if content of destination and source 157 differs. If no difference, no copy is done, *mod set to False. 158 If different; copy is done, *mod set to True. */ 159 extern void* VG_(dmemcpy) ( void *d, const void *s, SizeT sz, Bool *mod ); 160 161 typedef 162 enum { 163 valgrind_to_gdbserver, 164 gdbserver_to_valgrind} transfer_direction; 165 166 // According to dir, calls VG_(dmemcpy) 167 // to copy data from/to valgrind to/from gdbserver. 168 // If the transferred data differs from what is currently stored, 169 // sets *mod to True otherwise set *mod to False. 170 extern void VG_(transfer) (void *valgrind, 171 void *gdbserver, 172 transfer_direction dir, 173 SizeT sz, 174 Bool *mod); 175 176 #endif /* TARGET_H */ 177