Decouple target code from remote protocol.
[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
2bd7c093
PA
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. */
64386c31
DJ
29
30struct thread_resume
31{
a1928bad 32 unsigned long thread;
64386c31 33
64386c31
DJ
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
5b1c542e
PA
41/* Generally, what has the program done? */
42enum 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
73struct 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
ce3a066d
DJ
88struct 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
a9fa9f7d 96 Returns the new PID on success, -1 on failure. Registers the new
ce3a066d
DJ
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
1d5315fe
PA
104 or a higher layer.
105
106 Returns -1 if attaching is unsupported, 0 on success, and calls
107 error() otherwise. */
ce3a066d 108
a1928bad 109 int (*attach) (unsigned long pid);
ce3a066d
DJ
110
111 /* Kill all inferiors. */
112
113 void (*kill) (void);
114
444d6139
PA
115 /* Detach from all inferiors.
116 Return -1 on failure, and 0 on success. */
6ad8ae5c 117
444d6139
PA
118 int (*detach) (void);
119
120 /* Wait for inferiors to end. */
121
122 void (*join) (void);
6ad8ae5c 123
ce3a066d
DJ
124 /* Return 1 iff the thread with process ID PID is alive. */
125
a1928bad 126 int (*thread_alive) (unsigned long pid);
ce3a066d 127
64386c31 128 /* Resume the inferior process. */
ce3a066d 129
2bd7c093 130 void (*resume) (struct thread_resume *resume_info, size_t n);
ce3a066d 131
5b1c542e
PA
132 /* Wait for the inferior process or thread to change state. Store
133 status through argument pointer STATUS. */
ce3a066d 134
5b1c542e 135 unsigned long (*wait) (struct target_waitstatus *status);
ce3a066d
DJ
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);
aa691b87 142
ce3a066d
DJ
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
611cb4a5
DJ
149 /* Read memory from the inferior process. This should generally be
150 called through read_inferior_memory, which handles breakpoint shadowing.
ce3a066d 151
c3e735a6
DJ
152 Read LEN bytes at MEMADDR into a buffer at MYADDR.
153
154 Returns 0 on success and errno on failure. */
ce3a066d 155
f450004a 156 int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
ce3a066d 157
611cb4a5
DJ
158 /* Write memory to the inferior process. This should generally be
159 called through write_inferior_memory, which handles breakpoint shadowing.
ce3a066d
DJ
160
161 Write LEN bytes from the buffer at MYADDR to MEMADDR.
162
163 Returns 0 on success and errno on failure. */
164
f450004a
DJ
165 int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
166 int len);
2f2893d9
DJ
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)
611cb4a5
DJ
171 become available. NULL if we aren't interested in any
172 symbols. */
2f2893d9
DJ
173
174 void (*look_up_symbols) (void);
e5379b03 175
ef57601b
PA
176 /* Send an interrupt request to the inferior process,
177 however is appropriate. */
178
179 void (*request_interrupt) (void);
aa691b87
RM
180
181 /* Read auxiliary vector data from the inferior process.
182
183 Read LEN bytes at OFFSET into a buffer at MYADDR. */
184
f450004a
DJ
185 int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
186 unsigned int len);
e013ee27
OF
187
188 /* Insert and remove a hardware watchpoint.
1b3f6016 189 Returns 0 on success, -1 on failure and 1 on unsupported.
e013ee27
OF
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
1b3f6016 203 /* Returns the address associated with the watchpoint that hit, if any;
e013ee27
OF
204 returns 0 otherwise. */
205
206 CORE_ADDR (*stopped_data_address) (void);
207
52fb6437
NS
208 /* Reports the text, data offsets of the executable. This is
209 needed for uclinux where the executable is relocated during load
210 time. */
1b3f6016 211
52fb6437 212 int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data);
dae5f5cf
DJ
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);
23181151 222
0e7f50da
UW
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);
59a016f0
PA
226
227 /* Fill BUF with an hostio error packet representing the last hostio
228 error. */
229 void (*hostio_last_error) (char *buf);
07e059b5
VP
230
231 /* Read/Write OS data using qXfer packets. */
232 int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
1b3f6016 233 unsigned const char *writebuf, CORE_ADDR offset,
07e059b5 234 int len);
4aa995e1
PA
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);
ce3a066d
DJ
240};
241
242extern struct target_ops *the_target;
243
244void 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
6ad8ae5c
DJ
255#define detach_inferior() \
256 (*the_target->detach) ()
257
ce3a066d
DJ
258#define mythread_alive(pid) \
259 (*the_target->thread_alive) (pid)
260
ce3a066d
DJ
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
444d6139
PA
267#define join_inferior() \
268 (*the_target->join) ()
269
5b1c542e 270unsigned long mywait (struct target_waitstatus *ourstatus, int connected_wait);
0d62e5e8 271
f450004a 272int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
ce3a066d 273
f450004a
DJ
274int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
275 int len);
0d62e5e8
DJ
276
277void set_desired_inferior (int id);
ce3a066d
DJ
278
279#endif /* TARGET_H */
This page took 0.526339 seconds and 4 git commands to generate.