1 /* Target operations for the Valgrind remote server for GDB. 2 Copyright (C) 2002, 2003, 2004, 2005, 2012 3 Free Software Foundation, Inc. 4 Philippe Waroquiers. 5 6 Contributed by MontaVista Software. 7 8 This file is part of GDB. 9 It has been modified to integrate it in valgrind 10 11 This program is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation; either version 2 of the License, or 14 (at your option) any later version. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 Boston, MA 02110-1301, USA. */ 25 26 #ifndef TARGET_H 27 #define TARGET_H 28 29 /* This file defines the architecture independent Valgrind gdbserver 30 high level operations such as read memory, get/set registers, ... 31 32 These high level operations are called by the gdbserver 33 protocol implementation (e.g. typically server.c). 34 35 For some of these high level operations, target.c will call 36 low level operations dependent on the architecture. 37 38 For example, getting or setting the registers will work on a 39 register cache. The exact details of the registers (how much, 40 their size, etc) is not defined by target.c or the register cache. 41 42 Such architecture dependent information is defined by 43 valgrind_low.h/valgrind-low-xxxxx.c providing 'low level operations' 44 specific to the xxxxx architecture (for example, 45 valgrind-low-x86.c, valgrind-low-armc.c). */ 46 47 /* -------------------------------------------------------------------------- */ 48 /* ------------------------ Initialisation ---------------------------------- */ 49 /* -------------------------------------------------------------------------- */ 50 51 /* Initialize the Valgrind high target. This will in turn 52 initialise the low (architecture specific) target. */ 53 extern void valgrind_initialize_target(void); 54 55 /* initialize or re-initialize the register set of the low target. 56 if shadow_mode, then (re-)define the normal and valgrind shadow registers 57 else (re-)define only the normal registers. */ 58 extern void initialize_shadow_low (Bool shadow_mode); 59 60 /* Returns the name of the xml target description file. 61 returns NULL if no xml target description available. 62 if shadow_mode, then returns the xml target description 63 with the shadow registers 64 else returns the xml target description only for 65 the normal registers. */ 66 extern char* valgrind_target_xml (Bool shadow_mode); 67 68 69 /* -------------------------------------------------------------------------- */ 70 /* --------------------------- Execution control ---------------------------- */ 71 /* -------------------------------------------------------------------------- */ 72 73 /* This structure describes how to resume the execution. 74 Currently, there is no way to resume only a specific thread. */ 75 struct thread_resume 76 { 77 /* If non-zero, we want to single-step. */ 78 int step; 79 80 /* If non-zero, send this signal when we resume. */ 81 int sig; 82 }; 83 84 /* Prepare to Resume (i.e. restart) the guest. 85 The resume info indicates how the resume will be done. 86 In case GDB has changed the program counter, valgrind_resume 87 will also ensure that the execution will be resumed at this 88 new program counter. 89 The Resume is really only executed once the gdbserver 90 returns (giving back the control to Valgrind). */ 91 extern void valgrind_resume (struct thread_resume *resume_info); 92 93 /* When Valgrind gets the control, it will execute the guest 94 process till there is a reason to call the gdbserver 95 again (e.g. because a breakpoint is encountered or the 96 tool reports an error). 97 In such case, the executionof guest code stops, and the 98 control is given to gdbserver. Gdbserver will send a resume 99 reply packet to GDB. 100 101 valgrind_wait gets from Valgrind data structures the 102 information needed produce the resume reply for GDB: 103 a.o. OURSTATUS will be filled in with a response code to send to GDB. 104 105 Returns the signal which caused the process to stop, in the 106 remote protocol numbering (e.g. TARGET_SIGNAL_STOP), or the 107 exit code as an integer if *OURSTATUS is 'W'. */ 108 extern unsigned char valgrind_wait (char *outstatus); 109 110 /* When execution is stopped and gdbserver has control, more 111 info about the stop reason can be retrieved using the following 112 functions. */ 113 114 /* gets the addr at which a (possible) break must be ignored once. 115 If there is no such break to be ignored once, 0 is returned. 116 This is needed for the following case: 117 The user sets a break at address AAA. 118 The break is encountered. Then the user does stepi 119 (i.e. step one instruction). 120 In such a case, the already encountered break must be ignored 121 to ensure the stepi will advance by one instruction: a "break" 122 is implemented in valgrind by some helper code just after the 123 instruction mark at which the break is set. This helper code 124 verifies if either there is a break at the current PC 125 or if we are in stepping mode. If we are in stepping mode, 126 the already encountered break must be ignored once to advance 127 to the next instruction. 128 ??? need to check if this is *really* needed. */ 129 extern Addr valgrind_get_ignore_break_once(void); 130 131 /* When addr > 0, ensures the next resume reply packet informs 132 gdb about the encountered watchpoint. 133 valgrind_stopped_by_watchpoint() will return 1 till reset. 134 Use addr 0x0 to reset. */ 135 extern void VG_(set_watchpoint_stop_address) (Addr addr); 136 137 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */ 138 extern int valgrind_stopped_by_watchpoint (void); 139 140 /* Returns the address associated with the watchpoint that hit, if any; 141 returns 0 otherwise. */ 142 extern CORE_ADDR valgrind_stopped_data_address (void); 143 144 /* True if gdbserver is single stepping the valgrind process */ 145 extern Bool valgrind_single_stepping(void); 146 147 /* Set Valgrind in single stepping mode or not according to Bool. */ 148 extern void valgrind_set_single_stepping(Bool); 149 150 /* -------------------------------------------------------------------------- */ 151 /* ----------------- Examining/modifying data while stopped ----------------- */ 152 /* -------------------------------------------------------------------------- */ 153 154 /* Return 1 iff the thread with ID tid is alive. */ 155 extern int valgrind_thread_alive (unsigned long tid); 156 157 /* Allows to controls the thread (current_inferior) used for following 158 valgrind_(fetch|store)_registers calls. 159 If USE_GENERAL, 160 current_inferior is set to general_thread 161 else 162 current_inferior is set to step_thread or else cont_thread. 163 If the above gives no valid thread, then current_inferior is 164 set to the first valid thread. */ 165 extern void set_desired_inferior (int use_general); 166 167 /* Fetch registers from the current_inferior thread. 168 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */ 169 extern void valgrind_fetch_registers (int regno); 170 171 /* Store registers to the current_inferior thread. 172 If REGNO is -1, store all registers; otherwise, store at least REGNO. */ 173 extern void valgrind_store_registers (int regno); 174 175 176 177 /* Read memory from the inferior process. 178 Read LEN bytes at MEMADDR into a buffer at MYADDR. 179 Returns 0 on success and errno on failure. */ 180 extern int valgrind_read_memory (CORE_ADDR memaddr, 181 unsigned char *myaddr, int len); 182 183 /* Write memory to the inferior process. 184 Write LEN bytes from the buffer at MYADDR to MEMADDR. 185 Returns 0 on success and errno on failure. */ 186 extern int valgrind_write_memory (CORE_ADDR memaddr, 187 const unsigned char *myaddr, int len); 188 189 190 /* Insert and remove a hardware watchpoint. 191 Returns 0 on success, -1 on failure and 1 on unsupported. 192 The type is coded as follows: 193 2 = write watchpoint 194 3 = read watchpoint 195 4 = access watchpoint 196 */ 197 extern int valgrind_insert_watchpoint (char type, CORE_ADDR addr, int len); 198 extern int valgrind_remove_watchpoint (char type, CORE_ADDR addr, int len); 199 200 201 /* -------------------------------------------------------------------------- */ 202 /* ----------- Utils functions for low level arch specific files ------------ */ 203 /* -------------------------------------------------------------------------- */ 204 205 /* returns a pointer to the architecture state corresponding to 206 the provided register set: 0 => normal guest registers, 207 1 => shadow1 208 2 => shadow2 209 */ 210 extern VexGuestArchState* get_arch (int set, ThreadState* tst); 211 212 /* like memcpy but first check if content of destination and source 213 differs. If no difference, no copy is done, *mod set to False. 214 If different; copy is done, *mod set to True. */ 215 extern void* VG_(dmemcpy) ( void *d, const void *s, SizeT sz, Bool *mod ); 216 217 typedef 218 enum { 219 valgrind_to_gdbserver, 220 gdbserver_to_valgrind} transfer_direction; 221 222 // According to dir, calls VG_(dmemcpy) 223 // to copy data from/to valgrind to/from gdbserver. 224 // If the transferred data differs from what is currently stored, 225 // sets *mod to True otherwise set *mod to False. 226 extern void VG_(transfer) (void *valgrind, 227 void *gdbserver, 228 transfer_direction dir, 229 SizeT sz, 230 Bool *mod); 231 232 233 234 #endif /* TARGET_H */ 235