]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gdbserver/target.h
Decouple target code from remote protocol.
[thirdparty/binutils-gdb.git] / gdb / gdbserver / target.h
1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
3 Free Software Foundation, Inc.
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #ifndef TARGET_H
23 #define TARGET_H
24
25 /* This structure describes how to resume a particular thread (or all
26 threads) based on the client's request. If thread is -1, then this
27 entry applies to all threads. These are passed around as an
28 array. */
29
30 struct thread_resume
31 {
32 unsigned long thread;
33
34 /* If non-zero, we want to single-step. */
35 int step;
36
37 /* If non-zero, send this signal when we resume. */
38 int sig;
39 };
40
41 /* Generally, what has the program done? */
42 enum target_waitkind
43 {
44 /* The program has exited. The exit status is in
45 value.integer. */
46 TARGET_WAITKIND_EXITED,
47
48 /* The program has stopped with a signal. Which signal is in
49 value.sig. */
50 TARGET_WAITKIND_STOPPED,
51
52 /* The program has terminated with a signal. Which signal is in
53 value.sig. */
54 TARGET_WAITKIND_SIGNALLED,
55
56 /* The program is letting us know that it dynamically loaded
57 something. */
58 TARGET_WAITKIND_LOADED,
59
60 /* The program has exec'ed a new executable file. The new file's
61 pathname is pointed to by value.execd_pathname. */
62 TARGET_WAITKIND_EXECD,
63
64 /* Nothing of interest to GDB happened, but we stopped anyway. */
65 TARGET_WAITKIND_SPURIOUS,
66
67 /* An event has occurred, but we should wait again. In this case,
68 we want to go back to the event loop and wait there for another
69 event from the inferior. */
70 TARGET_WAITKIND_IGNORE
71 };
72
73 struct target_waitstatus
74 {
75 enum target_waitkind kind;
76
77 /* Forked child pid, execd pathname, exit status or signal number. */
78 union
79 {
80 int integer;
81 enum target_signal sig;
82 unsigned long related_pid;
83 char *execd_pathname;
84 }
85 value;
86 };
87
88 struct target_ops
89 {
90 /* Start a new process.
91
92 PROGRAM is a path to the program to execute.
93 ARGS is a standard NULL-terminated array of arguments,
94 to be passed to the inferior as ``argv''.
95
96 Returns the new PID on success, -1 on failure. Registers the new
97 process with the process list. */
98
99 int (*create_inferior) (char *program, char **args);
100
101 /* Attach to a running process.
102
103 PID is the process ID to attach to, specified by the user
104 or a higher layer.
105
106 Returns -1 if attaching is unsupported, 0 on success, and calls
107 error() otherwise. */
108
109 int (*attach) (unsigned long pid);
110
111 /* Kill all inferiors. */
112
113 void (*kill) (void);
114
115 /* Detach from all inferiors.
116 Return -1 on failure, and 0 on success. */
117
118 int (*detach) (void);
119
120 /* Wait for inferiors to end. */
121
122 void (*join) (void);
123
124 /* Return 1 iff the thread with process ID PID is alive. */
125
126 int (*thread_alive) (unsigned long pid);
127
128 /* Resume the inferior process. */
129
130 void (*resume) (struct thread_resume *resume_info, size_t n);
131
132 /* Wait for the inferior process or thread to change state. Store
133 status through argument pointer STATUS. */
134
135 unsigned long (*wait) (struct target_waitstatus *status);
136
137 /* Fetch registers from the inferior process.
138
139 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
140
141 void (*fetch_registers) (int regno);
142
143 /* Store registers to the inferior process.
144
145 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
146
147 void (*store_registers) (int regno);
148
149 /* Read memory from the inferior process. This should generally be
150 called through read_inferior_memory, which handles breakpoint shadowing.
151
152 Read LEN bytes at MEMADDR into a buffer at MYADDR.
153
154 Returns 0 on success and errno on failure. */
155
156 int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
157
158 /* Write memory to the inferior process. This should generally be
159 called through write_inferior_memory, which handles breakpoint shadowing.
160
161 Write LEN bytes from the buffer at MYADDR to MEMADDR.
162
163 Returns 0 on success and errno on failure. */
164
165 int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
166 int len);
167
168 /* Query GDB for the values of any symbols we're interested in.
169 This function is called whenever we receive a "qSymbols::"
170 query, which corresponds to every time more symbols (might)
171 become available. NULL if we aren't interested in any
172 symbols. */
173
174 void (*look_up_symbols) (void);
175
176 /* Send an interrupt request to the inferior process,
177 however is appropriate. */
178
179 void (*request_interrupt) (void);
180
181 /* Read auxiliary vector data from the inferior process.
182
183 Read LEN bytes at OFFSET into a buffer at MYADDR. */
184
185 int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
186 unsigned int len);
187
188 /* Insert and remove a hardware watchpoint.
189 Returns 0 on success, -1 on failure and 1 on unsupported.
190 The type is coded as follows:
191 2 = write watchpoint
192 3 = read watchpoint
193 4 = access watchpoint
194 */
195
196 int (*insert_watchpoint) (char type, CORE_ADDR addr, int len);
197 int (*remove_watchpoint) (char type, CORE_ADDR addr, int len);
198
199 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */
200
201 int (*stopped_by_watchpoint) (void);
202
203 /* Returns the address associated with the watchpoint that hit, if any;
204 returns 0 otherwise. */
205
206 CORE_ADDR (*stopped_data_address) (void);
207
208 /* Reports the text, data offsets of the executable. This is
209 needed for uclinux where the executable is relocated during load
210 time. */
211
212 int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data);
213
214 /* Fetch the address associated with a specific thread local storage
215 area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
216 Stores it in *ADDRESS and returns zero on success; otherwise returns
217 an error code. A return value of -1 means this system does not
218 support the operation. */
219
220 int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset,
221 CORE_ADDR load_module, CORE_ADDR *address);
222
223 /* Read/Write from/to spufs using qXfer packets. */
224 int (*qxfer_spu) (const char *annex, unsigned char *readbuf,
225 unsigned const char *writebuf, CORE_ADDR offset, int len);
226
227 /* Fill BUF with an hostio error packet representing the last hostio
228 error. */
229 void (*hostio_last_error) (char *buf);
230
231 /* Read/Write OS data using qXfer packets. */
232 int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
233 unsigned const char *writebuf, CORE_ADDR offset,
234 int len);
235
236 /* Read/Write extra signal info. */
237 int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf,
238 unsigned const char *writebuf,
239 CORE_ADDR offset, int len);
240 };
241
242 extern struct target_ops *the_target;
243
244 void set_target_ops (struct target_ops *);
245
246 #define create_inferior(program, args) \
247 (*the_target->create_inferior) (program, args)
248
249 #define myattach(pid) \
250 (*the_target->attach) (pid)
251
252 #define kill_inferior() \
253 (*the_target->kill) ()
254
255 #define detach_inferior() \
256 (*the_target->detach) ()
257
258 #define mythread_alive(pid) \
259 (*the_target->thread_alive) (pid)
260
261 #define fetch_inferior_registers(regno) \
262 (*the_target->fetch_registers) (regno)
263
264 #define store_inferior_registers(regno) \
265 (*the_target->store_registers) (regno)
266
267 #define join_inferior() \
268 (*the_target->join) ()
269
270 unsigned long mywait (struct target_waitstatus *ourstatus, int connected_wait);
271
272 int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
273
274 int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
275 int len);
276
277 void set_desired_inferior (int id);
278
279 #endif /* TARGET_H */