FreeBSD Helgrind: turn off check for locks held on exit for FreeBSD 14.2
[valgrind.git] / coregrind / m_gdbserver / target.h
blob1309bba7a5d46bc4bd6bfbd600dd1a508da918ef
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.
6 Contributed by MontaVista Software.
8 This file is part of GDB.
9 It has been modified to integrate it in valgrind
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.
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.
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. */
26 #ifndef TARGET_H
27 #define TARGET_H
29 #include "pub_core_basics.h" // Addr
30 #include "server.h" // CORE_ADDR
32 /* This file defines the architecture independent Valgrind gdbserver
33 high level operations such as read memory, get/set registers, ...
35 These high level operations are called by the gdbserver
36 protocol implementation (e.g. typically server.c).
38 For some of these high level operations, target.c will call
39 low level operations dependent on the architecture.
41 For example, getting or setting the registers will work on a
42 register cache. The exact details of the registers (how much,
43 their size, etc) is not defined by target.c or the register cache.
45 Such architecture dependent information is defined by
46 valgrind_low.h/valgrind-low-xxxxx.c providing 'low level operations'
47 specific to the xxxxx architecture (for example,
48 valgrind-low-x86.c, valgrind-low-armc.c). */
50 /* -------------------------------------------------------------------------- */
51 /* ------------------------ Initialisation ---------------------------------- */
52 /* -------------------------------------------------------------------------- */
54 /* Initialize the Valgrind high target. This will in turn
55 initialise the low (architecture specific) target. */
56 extern void valgrind_initialize_target(void);
58 /* initialize or re-initialize the register set of the low target.
59 if shadow_mode, then (re-)define the normal and valgrind shadow registers
60 else (re-)define only the normal registers. */
61 extern void initialize_shadow_low (Bool shadow_mode);
63 /* Returns the name of the xml target description file.
64 returns NULL if no xml target description available.
65 if shadow_mode, then returns the xml target description
66 with the shadow registers
67 else returns the xml target description only for
68 the normal registers. */
69 extern const char* valgrind_target_xml (Bool shadow_mode);
72 /* -------------------------------------------------------------------------- */
73 /* --------------------------- Execution control ---------------------------- */
74 /* -------------------------------------------------------------------------- */
76 /* This structure describes how to resume the execution.
77 Currently, there is no way to resume only a specific thread. */
78 struct thread_resume
80 /* If non-zero, we want to single-step. */
81 int step;
83 /* If non-zero, send this signal when we resume. */
84 int sig;
87 /* Prepare to Resume (i.e. restart) the guest.
88 The resume info indicates how the resume will be done.
89 In case GDB has changed the program counter, valgrind_resume
90 will also ensure that the execution will be resumed at this
91 new program counter.
92 The Resume is really only executed once the gdbserver
93 returns (giving back the control to Valgrind). */
94 extern void valgrind_resume (struct thread_resume *resume_info);
96 /* When Valgrind gets the control, it will execute the guest
97 process till there is a reason to call the gdbserver
98 again (e.g. because a breakpoint is encountered or the
99 tool reports an error).
100 In such case, the executionof guest code stops, and the
101 control is given to gdbserver. Gdbserver will send a resume
102 reply packet to GDB.
104 valgrind_wait gets from Valgrind data structures the
105 information needed produce the resume reply for GDB:
106 a.o. OURSTATUS will be filled in with a response code to send to GDB.
108 Returns the signal which caused the process to stop, in the
109 remote protocol numbering (e.g. TARGET_SIGNAL_STOP), or the
110 exit code as an integer if *OURSTATUS is 'W'. */
111 extern unsigned char valgrind_wait (char *outstatus);
113 /* When execution is stopped and gdbserver has control, more
114 info about the stop reason can be retrieved using the following
115 functions. */
117 /* gets the addr at which a (possible) break must be ignored once.
118 If there is no such break to be ignored once, 0 is returned.
119 This is needed for the following case:
120 The user sets a break at address AAA.
121 The break is encountered. Then the user does stepi
122 (i.e. step one instruction).
123 In such a case, the already encountered break must be ignored
124 to ensure the stepi will advance by one instruction: a "break"
125 is implemented in valgrind by some helper code just after the
126 instruction mark at which the break is set. This helper code
127 verifies if either there is a break at the current PC
128 or if we are in stepping mode. If we are in stepping mode,
129 the already encountered break must be ignored once to advance
130 to the next instruction.
131 ??? need to check if this is *really* needed. */
132 extern Addr valgrind_get_ignore_break_once(void);
134 /* When addr > 0, ensures the next resume reply packet informs
135 gdb about the encountered watchpoint.
136 valgrind_stopped_by_watchpoint() will return 1 till reset.
137 Use addr 0x0 to reset. */
138 extern void VG_(set_watchpoint_stop_address) (Addr addr);
140 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */
141 extern int valgrind_stopped_by_watchpoint (void);
143 /* Returns the address associated with the watchpoint that hit, if any;
144 returns 0 otherwise. */
145 extern CORE_ADDR valgrind_stopped_data_address (void);
148 /* Inform GDB (if needed) that client is before (or after) syscall sysno.
149 sysno -1 is used to clear the fact that a syscall has been encountered. */
150 extern void gdbserver_syscall_encountered (Bool before, Int sysno);
152 /* >= 0 if valgrind stopped due to syscall, -1 if not stopped due to syscall. */
153 extern Int valgrind_stopped_by_syscall (void);
155 /* if valgrind_stopped_by_syscall() >= 0, tells if stopped before or after
156 syscall. */
157 extern Bool valgrind_stopped_before_syscall (void);
159 /* True if gdbserver is single stepping the valgrind process */
160 extern Bool valgrind_single_stepping (void);
162 /* Set Valgrind in single stepping mode or not according to Bool. */
163 extern void valgrind_set_single_stepping (Bool);
165 /* -------------------------------------------------------------------------- */
166 /* ----------------- Examining/modifying data while stopped ----------------- */
167 /* -------------------------------------------------------------------------- */
169 /* Return 1 iff the thread with ID tid is alive. */
170 extern int valgrind_thread_alive (unsigned long tid);
172 /* Allows to controls the thread (current_inferior) used for following
173 valgrind_(fetch|store)_registers calls.
174 If USE_GENERAL,
175 current_inferior is set to general_thread
176 else
177 current_inferior is set to step_thread or else cont_thread.
178 If the above gives no valid thread, then current_inferior is
179 set to the first valid thread. */
180 extern void set_desired_inferior (int use_general);
182 /* Fetch register regno from the current_inferior thread and put its value in buf. */
183 extern void valgrind_fetch_register (int regno, unsigned char *buf);
185 /* Store register REGNO value from BUF to the VEX valgrind state. */
186 extern void valgrind_store_register (int regno, const unsigned char *buf);
190 /* Read memory from the inferior process.
191 Read LEN bytes at MEMADDR into a buffer at MYADDR.
192 Returns 0 on success and errno on failure. */
193 extern int valgrind_read_memory (CORE_ADDR memaddr,
194 unsigned char *myaddr, int len);
196 /* Write memory to the inferior process.
197 Write LEN bytes from the buffer at MYADDR to MEMADDR.
198 Returns 0 on success and errno on failure. */
199 extern int valgrind_write_memory (CORE_ADDR memaddr,
200 const unsigned char *myaddr, int len);
203 /* Insert and remove a hardware watchpoint.
204 Returns 0 on success, -1 on failure and 1 on unsupported.
205 The type is coded as follows:
206 2 = write watchpoint
207 3 = read watchpoint
208 4 = access watchpoint
210 extern int valgrind_insert_watchpoint (char type, CORE_ADDR addr, int len);
211 extern int valgrind_remove_watchpoint (char type, CORE_ADDR addr, int len);
213 /* Get the address of a thread local variable.
214 'tst' is the thread for which thread local address is searched for.
215 'offset' is the offset of the variable in the tls data of the load
216 module identified by 'lm'.
217 'lm' is the link_map address of the loaded module : it is the address
218 of the data structure used by the dynamic linker to maintain various
219 information about a loaded object.
221 Returns True if the address of the variable could be found.
222 *tls_addr is then set to this address.
223 Returns False if tls support is not available for this arch, or
224 if an error occurred. *tls_addr is set to NULL. */
225 extern Bool valgrind_get_tls_addr (ThreadState *tst,
226 CORE_ADDR offset,
227 CORE_ADDR lm,
228 CORE_ADDR *tls_addr);
231 /* -------------------------------------------------------------------------- */
232 /* ----------- Utils functions for low level arch specific files ------------ */
233 /* -------------------------------------------------------------------------- */
236 /* returns a pointer to the architecture state corresponding to
237 the provided register set: 0 => normal guest registers,
238 1 => shadow1
239 2 => shadow2
241 extern VexGuestArchState* get_arch (int set, ThreadState* tst);
243 /* like memcpy but first check if content of destination and source
244 differs. If no difference, no copy is done, *mod set to False.
245 If different; copy is done, *mod set to True. */
246 extern void* VG_(dmemcpy) ( void *d, const void *s, SizeT sz, Bool *mod );
248 typedef
249 enum {
250 valgrind_to_gdbserver,
251 gdbserver_to_valgrind} transfer_direction;
253 // According to dir, calls VG_(dmemcpy)
254 // to copy data from/to valgrind to/from gdbserver.
255 // If the transferred data differs from what is currently stored,
256 // sets *mod to True otherwise set *mod to False.
257 extern void VG_(transfer) (void *valgrind,
258 void *gdbserver,
259 transfer_direction dir,
260 SizeT sz,
261 Bool *mod);
264 // True means gdbserver can access (internal) Valgrind memory.
265 // Otherwise, only the client memory can be accessed.
266 extern Bool hostvisibility;
268 #endif /* TARGET_H */