Commit | Line | Data |
---|---|---|
ce3a066d | 1 | /* Target operations for the remote server for GDB. |
4c38e0a4 | 2 | Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 |
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 | ||
6a271cae PA |
25 | struct emit_ops; |
26 | ||
bd99dc85 PA |
27 | /* Ways to "resume" a thread. */ |
28 | ||
29 | enum resume_kind | |
30 | { | |
31 | /* Thread should continue. */ | |
32 | resume_continue, | |
33 | ||
34 | /* Thread should single-step. */ | |
35 | resume_step, | |
36 | ||
37 | /* Thread should be stopped. */ | |
38 | resume_stop | |
39 | }; | |
40 | ||
2bd7c093 PA |
41 | /* This structure describes how to resume a particular thread (or all |
42 | threads) based on the client's request. If thread is -1, then this | |
43 | entry applies to all threads. These are passed around as an | |
44 | array. */ | |
64386c31 DJ |
45 | |
46 | struct thread_resume | |
47 | { | |
95954743 | 48 | ptid_t thread; |
64386c31 | 49 | |
bd99dc85 PA |
50 | /* How to "resume". */ |
51 | enum resume_kind kind; | |
64386c31 | 52 | |
bd99dc85 PA |
53 | /* If non-zero, send this signal when we resume, or to stop the |
54 | thread. If stopping a thread, and this is 0, the target should | |
55 | stop the thread however it best decides to (e.g., SIGSTOP on | |
30d50328 JK |
56 | linux; SuspendThread on win32). This is a host signal value (not |
57 | enum target_signal). */ | |
64386c31 DJ |
58 | int sig; |
59 | }; | |
60 | ||
5b1c542e PA |
61 | /* Generally, what has the program done? */ |
62 | enum target_waitkind | |
63 | { | |
64 | /* The program has exited. The exit status is in | |
65 | value.integer. */ | |
66 | TARGET_WAITKIND_EXITED, | |
67 | ||
68 | /* The program has stopped with a signal. Which signal is in | |
69 | value.sig. */ | |
70 | TARGET_WAITKIND_STOPPED, | |
71 | ||
72 | /* The program has terminated with a signal. Which signal is in | |
73 | value.sig. */ | |
74 | TARGET_WAITKIND_SIGNALLED, | |
75 | ||
76 | /* The program is letting us know that it dynamically loaded | |
77 | something. */ | |
78 | TARGET_WAITKIND_LOADED, | |
79 | ||
80 | /* The program has exec'ed a new executable file. The new file's | |
81 | pathname is pointed to by value.execd_pathname. */ | |
82 | TARGET_WAITKIND_EXECD, | |
83 | ||
84 | /* Nothing of interest to GDB happened, but we stopped anyway. */ | |
85 | TARGET_WAITKIND_SPURIOUS, | |
86 | ||
87 | /* An event has occurred, but we should wait again. In this case, | |
88 | we want to go back to the event loop and wait there for another | |
89 | event from the inferior. */ | |
90 | TARGET_WAITKIND_IGNORE | |
91 | }; | |
92 | ||
93 | struct target_waitstatus | |
94 | { | |
95 | enum target_waitkind kind; | |
96 | ||
97 | /* Forked child pid, execd pathname, exit status or signal number. */ | |
98 | union | |
99 | { | |
100 | int integer; | |
101 | enum target_signal sig; | |
95954743 | 102 | ptid_t related_pid; |
5b1c542e PA |
103 | char *execd_pathname; |
104 | } | |
105 | value; | |
106 | }; | |
107 | ||
bd99dc85 PA |
108 | /* Options that can be passed to target_ops->wait. */ |
109 | ||
110 | #define TARGET_WNOHANG 1 | |
111 | ||
ce3a066d DJ |
112 | struct target_ops |
113 | { | |
114 | /* Start a new process. | |
115 | ||
116 | PROGRAM is a path to the program to execute. | |
117 | ARGS is a standard NULL-terminated array of arguments, | |
118 | to be passed to the inferior as ``argv''. | |
119 | ||
a9fa9f7d | 120 | Returns the new PID on success, -1 on failure. Registers the new |
ce3a066d DJ |
121 | process with the process list. */ |
122 | ||
123 | int (*create_inferior) (char *program, char **args); | |
124 | ||
125 | /* Attach to a running process. | |
126 | ||
127 | PID is the process ID to attach to, specified by the user | |
1d5315fe PA |
128 | or a higher layer. |
129 | ||
130 | Returns -1 if attaching is unsupported, 0 on success, and calls | |
131 | error() otherwise. */ | |
ce3a066d | 132 | |
a1928bad | 133 | int (*attach) (unsigned long pid); |
ce3a066d | 134 | |
95954743 | 135 | /* Kill inferior PID. Return -1 on failure, and 0 on success. */ |
ce3a066d | 136 | |
95954743 | 137 | int (*kill) (int pid); |
ce3a066d | 138 | |
95954743 PA |
139 | /* Detach from inferior PID. Return -1 on failure, and 0 on |
140 | success. */ | |
6ad8ae5c | 141 | |
95954743 | 142 | int (*detach) (int pid); |
444d6139 | 143 | |
8336d594 PA |
144 | /* The inferior process has died. Do what is right. */ |
145 | ||
146 | void (*mourn) (struct process_info *proc); | |
147 | ||
95954743 PA |
148 | /* Wait for inferior PID to exit. */ |
149 | void (*join) (int pid); | |
6ad8ae5c | 150 | |
ce3a066d DJ |
151 | /* Return 1 iff the thread with process ID PID is alive. */ |
152 | ||
95954743 | 153 | int (*thread_alive) (ptid_t pid); |
ce3a066d | 154 | |
64386c31 | 155 | /* Resume the inferior process. */ |
ce3a066d | 156 | |
2bd7c093 | 157 | void (*resume) (struct thread_resume *resume_info, size_t n); |
ce3a066d | 158 | |
5b1c542e | 159 | /* Wait for the inferior process or thread to change state. Store |
95954743 PA |
160 | status through argument pointer STATUS. |
161 | ||
162 | PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to | |
163 | wait for any thread of process pid to do something. Return ptid | |
164 | of child, or -1 in case of error; store status through argument | |
165 | pointer STATUS. OPTIONS is a bit set of options defined as | |
166 | TARGET_W* above. If options contains TARGET_WNOHANG and there's | |
167 | no child stop to report, return is | |
168 | null_ptid/TARGET_WAITKIND_IGNORE. */ | |
ce3a066d | 169 | |
95954743 | 170 | ptid_t (*wait) (ptid_t ptid, struct target_waitstatus *status, int options); |
ce3a066d DJ |
171 | |
172 | /* Fetch registers from the inferior process. | |
173 | ||
174 | If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */ | |
175 | ||
442ea881 | 176 | void (*fetch_registers) (struct regcache *regcache, int regno); |
aa691b87 | 177 | |
ce3a066d DJ |
178 | /* Store registers to the inferior process. |
179 | ||
180 | If REGNO is -1, store all registers; otherwise, store at least REGNO. */ | |
181 | ||
442ea881 | 182 | void (*store_registers) (struct regcache *regcache, int regno); |
ce3a066d | 183 | |
611cb4a5 DJ |
184 | /* Read memory from the inferior process. This should generally be |
185 | called through read_inferior_memory, which handles breakpoint shadowing. | |
ce3a066d | 186 | |
c3e735a6 DJ |
187 | Read LEN bytes at MEMADDR into a buffer at MYADDR. |
188 | ||
189 | Returns 0 on success and errno on failure. */ | |
ce3a066d | 190 | |
f450004a | 191 | int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len); |
ce3a066d | 192 | |
611cb4a5 DJ |
193 | /* Write memory to the inferior process. This should generally be |
194 | called through write_inferior_memory, which handles breakpoint shadowing. | |
ce3a066d DJ |
195 | |
196 | Write LEN bytes from the buffer at MYADDR to MEMADDR. | |
197 | ||
198 | Returns 0 on success and errno on failure. */ | |
199 | ||
f450004a DJ |
200 | int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr, |
201 | int len); | |
2f2893d9 DJ |
202 | |
203 | /* Query GDB for the values of any symbols we're interested in. | |
204 | This function is called whenever we receive a "qSymbols::" | |
205 | query, which corresponds to every time more symbols (might) | |
611cb4a5 DJ |
206 | become available. NULL if we aren't interested in any |
207 | symbols. */ | |
2f2893d9 DJ |
208 | |
209 | void (*look_up_symbols) (void); | |
e5379b03 | 210 | |
ef57601b PA |
211 | /* Send an interrupt request to the inferior process, |
212 | however is appropriate. */ | |
213 | ||
214 | void (*request_interrupt) (void); | |
aa691b87 RM |
215 | |
216 | /* Read auxiliary vector data from the inferior process. | |
217 | ||
218 | Read LEN bytes at OFFSET into a buffer at MYADDR. */ | |
219 | ||
f450004a DJ |
220 | int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr, |
221 | unsigned int len); | |
e013ee27 | 222 | |
d993e290 | 223 | /* Insert and remove a break or watchpoint. |
1b3f6016 | 224 | Returns 0 on success, -1 on failure and 1 on unsupported. |
e013ee27 | 225 | The type is coded as follows: |
c6314022 AR |
226 | '0' - software-breakpoint |
227 | '1' - hardware-breakpoint | |
228 | '2' - write watchpoint | |
229 | '3' - read watchpoint | |
230 | '4' - access watchpoint */ | |
e013ee27 | 231 | |
d993e290 PA |
232 | int (*insert_point) (char type, CORE_ADDR addr, int len); |
233 | int (*remove_point) (char type, CORE_ADDR addr, int len); | |
e013ee27 OF |
234 | |
235 | /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */ | |
236 | ||
237 | int (*stopped_by_watchpoint) (void); | |
238 | ||
1b3f6016 | 239 | /* Returns the address associated with the watchpoint that hit, if any; |
e013ee27 OF |
240 | returns 0 otherwise. */ |
241 | ||
242 | CORE_ADDR (*stopped_data_address) (void); | |
243 | ||
52fb6437 NS |
244 | /* Reports the text, data offsets of the executable. This is |
245 | needed for uclinux where the executable is relocated during load | |
246 | time. */ | |
1b3f6016 | 247 | |
52fb6437 | 248 | int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data); |
dae5f5cf DJ |
249 | |
250 | /* Fetch the address associated with a specific thread local storage | |
251 | area, determined by the specified THREAD, OFFSET, and LOAD_MODULE. | |
252 | Stores it in *ADDRESS and returns zero on success; otherwise returns | |
253 | an error code. A return value of -1 means this system does not | |
254 | support the operation. */ | |
255 | ||
256 | int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset, | |
257 | CORE_ADDR load_module, CORE_ADDR *address); | |
23181151 | 258 | |
0e7f50da UW |
259 | /* Read/Write from/to spufs using qXfer packets. */ |
260 | int (*qxfer_spu) (const char *annex, unsigned char *readbuf, | |
261 | unsigned const char *writebuf, CORE_ADDR offset, int len); | |
59a016f0 PA |
262 | |
263 | /* Fill BUF with an hostio error packet representing the last hostio | |
264 | error. */ | |
265 | void (*hostio_last_error) (char *buf); | |
07e059b5 VP |
266 | |
267 | /* Read/Write OS data using qXfer packets. */ | |
268 | int (*qxfer_osdata) (const char *annex, unsigned char *readbuf, | |
1b3f6016 | 269 | unsigned const char *writebuf, CORE_ADDR offset, |
07e059b5 | 270 | int len); |
4aa995e1 PA |
271 | |
272 | /* Read/Write extra signal info. */ | |
273 | int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf, | |
274 | unsigned const char *writebuf, | |
275 | CORE_ADDR offset, int len); | |
bd99dc85 PA |
276 | |
277 | int (*supports_non_stop) (void); | |
278 | ||
279 | /* Enables async target events. Returns the previous enable | |
280 | state. */ | |
281 | int (*async) (int enable); | |
282 | ||
283 | /* Switch to non-stop (1) or all-stop (0) mode. Return 0 on | |
284 | success, -1 otherwise. */ | |
285 | int (*start_non_stop) (int); | |
cf8fd78b PA |
286 | |
287 | /* Returns true if the target supports multi-process debugging. */ | |
288 | int (*supports_multi_process) (void); | |
cdbfd419 PP |
289 | |
290 | /* If not NULL, target-specific routine to process monitor command. | |
291 | Returns 1 if handled, or 0 to perform default processing. */ | |
292 | int (*handle_monitor_command) (char *); | |
dc146f7c VP |
293 | |
294 | /* Returns the core given a thread, or -1 if not known. */ | |
295 | int (*core_of_thread) (ptid_t); | |
1570b33e L |
296 | |
297 | /* Target specific qSupported support. */ | |
298 | void (*process_qsupported) (const char *); | |
219f2f23 PA |
299 | |
300 | /* Return 1 if the target supports tracepoints, 0 (or leave the | |
301 | callback NULL) otherwise. */ | |
302 | int (*supports_tracepoints) (void); | |
303 | ||
304 | /* Read PC from REGCACHE. */ | |
305 | CORE_ADDR (*read_pc) (struct regcache *regcache); | |
306 | ||
307 | /* Write PC to REGCACHE. */ | |
308 | void (*write_pc) (struct regcache *regcache, CORE_ADDR pc); | |
8336d594 PA |
309 | |
310 | /* Return true if THREAD is known to be stopped now. */ | |
311 | int (*thread_stopped) (struct thread_info *thread); | |
312 | ||
711e434b PM |
313 | /* Read Thread Information Block address. */ |
314 | int (*get_tib_address) (ptid_t ptid, CORE_ADDR *address); | |
7984d532 PA |
315 | |
316 | /* Pause all threads. If FREEZE, arrange for any resume attempt be | |
317 | be ignored until an unpause_all call unfreezes threads again. | |
318 | There can be nested calls to pause_all, so a freeze counter | |
319 | should be maintained. */ | |
320 | void (*pause_all) (int freeze); | |
321 | ||
322 | /* Unpause all threads. Threads that hadn't been resumed by the | |
323 | client should be left stopped. Basically a pause/unpause call | |
324 | pair should not end up resuming threads that were stopped before | |
325 | the pause call. */ | |
326 | void (*unpause_all) (int unfreeze); | |
327 | ||
328 | /* Cancel all pending breakpoints hits in all threads. */ | |
329 | void (*cancel_breakpoints) (void); | |
fa593d66 PA |
330 | |
331 | /* Stabilize all threads. That is, force them out of jump pads. */ | |
332 | void (*stabilize_threads) (void); | |
333 | ||
334 | /* Install a fast tracepoint jump pad. TPOINT is the address of the | |
335 | tracepoint internal object as used by the IPA agent. TPADDR is | |
336 | the address of tracepoint. COLLECTOR is address of the function | |
337 | the jump pad redirects to. LOCKADDR is the address of the jump | |
338 | pad lock object. ORIG_SIZE is the size in bytes of the | |
339 | instruction at TPADDR. JUMP_ENTRY points to the address of the | |
340 | jump pad entry, and on return holds the address past the end of | |
341 | the created jump pad. JJUMP_PAD_INSN is a buffer containing a | |
342 | copy of the instruction at TPADDR. ADJUST_INSN_ADDR and | |
343 | ADJUST_INSN_ADDR_END are output parameters that return the | |
344 | address range where the instruction at TPADDR was relocated | |
345 | to. */ | |
346 | int (*install_fast_tracepoint_jump_pad) (CORE_ADDR tpoint, CORE_ADDR tpaddr, | |
347 | CORE_ADDR collector, | |
348 | CORE_ADDR lockaddr, | |
349 | ULONGEST orig_size, | |
350 | CORE_ADDR *jump_entry, | |
351 | unsigned char *jjump_pad_insn, | |
352 | ULONGEST *jjump_pad_insn_size, | |
353 | CORE_ADDR *adjusted_insn_addr, | |
354 | CORE_ADDR *adjusted_insn_addr_end); | |
6a271cae PA |
355 | |
356 | /* Return the bytecode operations vector for the current inferior. | |
357 | Returns NULL if bytecode compilation is not supported. */ | |
358 | struct emit_ops *(*emit_ops) (void); | |
ce3a066d DJ |
359 | }; |
360 | ||
361 | extern struct target_ops *the_target; | |
362 | ||
363 | void set_target_ops (struct target_ops *); | |
364 | ||
365 | #define create_inferior(program, args) \ | |
366 | (*the_target->create_inferior) (program, args) | |
367 | ||
368 | #define myattach(pid) \ | |
369 | (*the_target->attach) (pid) | |
370 | ||
95954743 PA |
371 | #define kill_inferior(pid) \ |
372 | (*the_target->kill) (pid) | |
ce3a066d | 373 | |
95954743 PA |
374 | #define detach_inferior(pid) \ |
375 | (*the_target->detach) (pid) | |
6ad8ae5c | 376 | |
8336d594 PA |
377 | #define mourn_inferior(PROC) \ |
378 | (*the_target->mourn) (PROC) | |
379 | ||
ce3a066d DJ |
380 | #define mythread_alive(pid) \ |
381 | (*the_target->thread_alive) (pid) | |
382 | ||
442ea881 PA |
383 | #define fetch_inferior_registers(regcache, regno) \ |
384 | (*the_target->fetch_registers) (regcache, regno) | |
ce3a066d | 385 | |
442ea881 PA |
386 | #define store_inferior_registers(regcache, regno) \ |
387 | (*the_target->store_registers) (regcache, regno) | |
ce3a066d | 388 | |
95954743 PA |
389 | #define join_inferior(pid) \ |
390 | (*the_target->join) (pid) | |
444d6139 | 391 | |
bd99dc85 PA |
392 | #define target_supports_non_stop() \ |
393 | (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0) | |
394 | ||
395 | #define target_async(enable) \ | |
396 | (the_target->async ? (*the_target->async) (enable) : 0) | |
397 | ||
cf8fd78b PA |
398 | #define target_supports_multi_process() \ |
399 | (the_target->supports_multi_process ? \ | |
400 | (*the_target->supports_multi_process) () : 0) | |
401 | ||
8336d594 PA |
402 | #define target_process_qsupported(query) \ |
403 | do \ | |
404 | { \ | |
405 | if (the_target->process_qsupported) \ | |
406 | the_target->process_qsupported (query); \ | |
407 | } while (0) | |
1570b33e | 408 | |
219f2f23 PA |
409 | #define target_supports_tracepoints() \ |
410 | (the_target->supports_tracepoints \ | |
411 | ? (*the_target->supports_tracepoints) () : 0) | |
412 | ||
fa593d66 PA |
413 | #define target_supports_fast_tracepoints() \ |
414 | (the_target->install_fast_tracepoint_jump_pad != NULL) | |
415 | ||
8336d594 PA |
416 | #define thread_stopped(thread) \ |
417 | (*the_target->thread_stopped) (thread) | |
418 | ||
7984d532 PA |
419 | #define pause_all(freeze) \ |
420 | do \ | |
421 | { \ | |
422 | if (the_target->pause_all) \ | |
423 | (*the_target->pause_all) (freeze); \ | |
424 | } while (0) | |
425 | ||
426 | #define unpause_all(unfreeze) \ | |
427 | do \ | |
428 | { \ | |
429 | if (the_target->unpause_all) \ | |
430 | (*the_target->unpause_all) (unfreeze); \ | |
431 | } while (0) | |
432 | ||
433 | #define cancel_breakpoints() \ | |
434 | do \ | |
435 | { \ | |
436 | if (the_target->cancel_breakpoints) \ | |
437 | (*the_target->cancel_breakpoints) (); \ | |
8336d594 PA |
438 | } while (0) |
439 | ||
fa593d66 PA |
440 | #define stabilize_threads() \ |
441 | do \ | |
442 | { \ | |
443 | if (the_target->stabilize_threads) \ | |
444 | (*the_target->stabilize_threads) (); \ | |
445 | } while (0) | |
446 | ||
447 | #define install_fast_tracepoint_jump_pad(tpoint, tpaddr, \ | |
448 | collector, lockaddr, \ | |
449 | orig_size, \ | |
450 | jump_entry, jjump_pad_insn, \ | |
451 | jjump_pad_insn_size, \ | |
452 | adjusted_insn_addr, \ | |
453 | adjusted_insn_addr_end) \ | |
454 | (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr, \ | |
455 | collector,lockaddr, \ | |
456 | orig_size, jump_entry, \ | |
457 | jjump_pad_insn, \ | |
458 | jjump_pad_insn_size, \ | |
459 | adjusted_insn_addr, \ | |
460 | adjusted_insn_addr_end) | |
461 | ||
6a271cae PA |
462 | #define target_emit_ops() \ |
463 | (the_target->emit_ops ? (*the_target->emit_ops) () : NULL) | |
464 | ||
bd99dc85 PA |
465 | /* Start non-stop mode, returns 0 on success, -1 on failure. */ |
466 | ||
467 | int start_non_stop (int nonstop); | |
468 | ||
95954743 PA |
469 | ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options, |
470 | int connected_wait); | |
0d62e5e8 | 471 | |
f450004a | 472 | int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len); |
ce3a066d | 473 | |
f450004a DJ |
474 | int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr, |
475 | int len); | |
0d62e5e8 DJ |
476 | |
477 | void set_desired_inferior (int id); | |
ce3a066d | 478 | |
95954743 PA |
479 | const char *target_pid_to_str (ptid_t); |
480 | ||
8336d594 PA |
481 | const char *target_waitstatus_to_string (const struct target_waitstatus *); |
482 | ||
ce3a066d | 483 | #endif /* TARGET_H */ |