Non-stop mode support.
[deliverable/binutils-gdb.git] / gdb / gdbserver / target.h
CommitLineData
ce3a066d 1/* Target operations for the remote server for GDB.
0fb0cc75 2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
9b254dd1 3 Free Software Foundation, Inc.
ce3a066d
DJ
4
5 Contributed by MontaVista Software.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
ce3a066d
DJ
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ce3a066d
DJ
21
22#ifndef TARGET_H
23#define TARGET_H
24
bd99dc85
PA
25/* Ways to "resume" a thread. */
26
27enum resume_kind
28{
29 /* Thread should continue. */
30 resume_continue,
31
32 /* Thread should single-step. */
33 resume_step,
34
35 /* Thread should be stopped. */
36 resume_stop
37};
38
2bd7c093
PA
39/* This structure describes how to resume a particular thread (or all
40 threads) based on the client's request. If thread is -1, then this
41 entry applies to all threads. These are passed around as an
42 array. */
64386c31
DJ
43
44struct thread_resume
45{
a1928bad 46 unsigned long thread;
64386c31 47
bd99dc85
PA
48 /* How to "resume". */
49 enum resume_kind kind;
64386c31 50
bd99dc85
PA
51 /* If non-zero, send this signal when we resume, or to stop the
52 thread. If stopping a thread, and this is 0, the target should
53 stop the thread however it best decides to (e.g., SIGSTOP on
54 linux; SuspendThread on win32). */
64386c31
DJ
55 int sig;
56};
57
5b1c542e
PA
58/* Generally, what has the program done? */
59enum target_waitkind
60 {
61 /* The program has exited. The exit status is in
62 value.integer. */
63 TARGET_WAITKIND_EXITED,
64
65 /* The program has stopped with a signal. Which signal is in
66 value.sig. */
67 TARGET_WAITKIND_STOPPED,
68
69 /* The program has terminated with a signal. Which signal is in
70 value.sig. */
71 TARGET_WAITKIND_SIGNALLED,
72
73 /* The program is letting us know that it dynamically loaded
74 something. */
75 TARGET_WAITKIND_LOADED,
76
77 /* The program has exec'ed a new executable file. The new file's
78 pathname is pointed to by value.execd_pathname. */
79 TARGET_WAITKIND_EXECD,
80
81 /* Nothing of interest to GDB happened, but we stopped anyway. */
82 TARGET_WAITKIND_SPURIOUS,
83
84 /* An event has occurred, but we should wait again. In this case,
85 we want to go back to the event loop and wait there for another
86 event from the inferior. */
87 TARGET_WAITKIND_IGNORE
88 };
89
90struct target_waitstatus
91 {
92 enum target_waitkind kind;
93
94 /* Forked child pid, execd pathname, exit status or signal number. */
95 union
96 {
97 int integer;
98 enum target_signal sig;
99 unsigned long related_pid;
100 char *execd_pathname;
101 }
102 value;
103 };
104
bd99dc85
PA
105/* Options that can be passed to target_ops->wait. */
106
107#define TARGET_WNOHANG 1
108
ce3a066d
DJ
109struct target_ops
110{
111 /* Start a new process.
112
113 PROGRAM is a path to the program to execute.
114 ARGS is a standard NULL-terminated array of arguments,
115 to be passed to the inferior as ``argv''.
116
a9fa9f7d 117 Returns the new PID on success, -1 on failure. Registers the new
ce3a066d
DJ
118 process with the process list. */
119
120 int (*create_inferior) (char *program, char **args);
121
122 /* Attach to a running process.
123
124 PID is the process ID to attach to, specified by the user
1d5315fe
PA
125 or a higher layer.
126
127 Returns -1 if attaching is unsupported, 0 on success, and calls
128 error() otherwise. */
ce3a066d 129
a1928bad 130 int (*attach) (unsigned long pid);
ce3a066d
DJ
131
132 /* Kill all inferiors. */
133
134 void (*kill) (void);
135
444d6139
PA
136 /* Detach from all inferiors.
137 Return -1 on failure, and 0 on success. */
6ad8ae5c 138
444d6139
PA
139 int (*detach) (void);
140
141 /* Wait for inferiors to end. */
142
143 void (*join) (void);
6ad8ae5c 144
ce3a066d
DJ
145 /* Return 1 iff the thread with process ID PID is alive. */
146
a1928bad 147 int (*thread_alive) (unsigned long pid);
ce3a066d 148
64386c31 149 /* Resume the inferior process. */
ce3a066d 150
2bd7c093 151 void (*resume) (struct thread_resume *resume_info, size_t n);
ce3a066d 152
5b1c542e
PA
153 /* Wait for the inferior process or thread to change state. Store
154 status through argument pointer STATUS. */
ce3a066d 155
bd99dc85 156 unsigned long (*wait) (struct target_waitstatus *status, int options);
ce3a066d
DJ
157
158 /* Fetch registers from the inferior process.
159
160 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
161
162 void (*fetch_registers) (int regno);
aa691b87 163
ce3a066d
DJ
164 /* Store registers to the inferior process.
165
166 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
167
168 void (*store_registers) (int regno);
169
611cb4a5
DJ
170 /* Read memory from the inferior process. This should generally be
171 called through read_inferior_memory, which handles breakpoint shadowing.
ce3a066d 172
c3e735a6
DJ
173 Read LEN bytes at MEMADDR into a buffer at MYADDR.
174
175 Returns 0 on success and errno on failure. */
ce3a066d 176
f450004a 177 int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
ce3a066d 178
611cb4a5
DJ
179 /* Write memory to the inferior process. This should generally be
180 called through write_inferior_memory, which handles breakpoint shadowing.
ce3a066d
DJ
181
182 Write LEN bytes from the buffer at MYADDR to MEMADDR.
183
184 Returns 0 on success and errno on failure. */
185
f450004a
DJ
186 int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
187 int len);
2f2893d9
DJ
188
189 /* Query GDB for the values of any symbols we're interested in.
190 This function is called whenever we receive a "qSymbols::"
191 query, which corresponds to every time more symbols (might)
611cb4a5
DJ
192 become available. NULL if we aren't interested in any
193 symbols. */
2f2893d9
DJ
194
195 void (*look_up_symbols) (void);
e5379b03 196
ef57601b
PA
197 /* Send an interrupt request to the inferior process,
198 however is appropriate. */
199
200 void (*request_interrupt) (void);
aa691b87
RM
201
202 /* Read auxiliary vector data from the inferior process.
203
204 Read LEN bytes at OFFSET into a buffer at MYADDR. */
205
f450004a
DJ
206 int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
207 unsigned int len);
e013ee27
OF
208
209 /* Insert and remove a hardware watchpoint.
1b3f6016 210 Returns 0 on success, -1 on failure and 1 on unsupported.
e013ee27
OF
211 The type is coded as follows:
212 2 = write watchpoint
213 3 = read watchpoint
214 4 = access watchpoint
215 */
216
217 int (*insert_watchpoint) (char type, CORE_ADDR addr, int len);
218 int (*remove_watchpoint) (char type, CORE_ADDR addr, int len);
219
220 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */
221
222 int (*stopped_by_watchpoint) (void);
223
1b3f6016 224 /* Returns the address associated with the watchpoint that hit, if any;
e013ee27
OF
225 returns 0 otherwise. */
226
227 CORE_ADDR (*stopped_data_address) (void);
228
52fb6437
NS
229 /* Reports the text, data offsets of the executable. This is
230 needed for uclinux where the executable is relocated during load
231 time. */
1b3f6016 232
52fb6437 233 int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data);
dae5f5cf
DJ
234
235 /* Fetch the address associated with a specific thread local storage
236 area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
237 Stores it in *ADDRESS and returns zero on success; otherwise returns
238 an error code. A return value of -1 means this system does not
239 support the operation. */
240
241 int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset,
242 CORE_ADDR load_module, CORE_ADDR *address);
23181151 243
0e7f50da
UW
244 /* Read/Write from/to spufs using qXfer packets. */
245 int (*qxfer_spu) (const char *annex, unsigned char *readbuf,
246 unsigned const char *writebuf, CORE_ADDR offset, int len);
59a016f0
PA
247
248 /* Fill BUF with an hostio error packet representing the last hostio
249 error. */
250 void (*hostio_last_error) (char *buf);
07e059b5
VP
251
252 /* Read/Write OS data using qXfer packets. */
253 int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
1b3f6016 254 unsigned const char *writebuf, CORE_ADDR offset,
07e059b5 255 int len);
4aa995e1
PA
256
257 /* Read/Write extra signal info. */
258 int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf,
259 unsigned const char *writebuf,
260 CORE_ADDR offset, int len);
bd99dc85
PA
261
262 int (*supports_non_stop) (void);
263
264 /* Enables async target events. Returns the previous enable
265 state. */
266 int (*async) (int enable);
267
268 /* Switch to non-stop (1) or all-stop (0) mode. Return 0 on
269 success, -1 otherwise. */
270 int (*start_non_stop) (int);
ce3a066d
DJ
271};
272
273extern struct target_ops *the_target;
274
275void set_target_ops (struct target_ops *);
276
277#define create_inferior(program, args) \
278 (*the_target->create_inferior) (program, args)
279
280#define myattach(pid) \
281 (*the_target->attach) (pid)
282
283#define kill_inferior() \
284 (*the_target->kill) ()
285
6ad8ae5c
DJ
286#define detach_inferior() \
287 (*the_target->detach) ()
288
ce3a066d
DJ
289#define mythread_alive(pid) \
290 (*the_target->thread_alive) (pid)
291
ce3a066d
DJ
292#define fetch_inferior_registers(regno) \
293 (*the_target->fetch_registers) (regno)
294
295#define store_inferior_registers(regno) \
296 (*the_target->store_registers) (regno)
297
444d6139
PA
298#define join_inferior() \
299 (*the_target->join) ()
300
bd99dc85
PA
301#define target_supports_non_stop() \
302 (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
303
304#define target_async(enable) \
305 (the_target->async ? (*the_target->async) (enable) : 0)
306
307/* Start non-stop mode, returns 0 on success, -1 on failure. */
308
309int start_non_stop (int nonstop);
310
311unsigned long mywait (struct target_waitstatus *ourstatus, int options,
312 int connected_wait);
0d62e5e8 313
f450004a 314int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
ce3a066d 315
f450004a
DJ
316int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
317 int len);
0d62e5e8
DJ
318
319void set_desired_inferior (int id);
ce3a066d
DJ
320
321#endif /* TARGET_H */
This page took 0.490613 seconds and 4 git commands to generate.