d064b79ab5ab3608cc21ac54d66bfa2dba3ca1b2
[deliverable/binutils-gdb.git] / gdb / gdbserver / target.h
1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3
4 Contributed by MontaVista Software.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #ifndef TARGET_H
22 #define TARGET_H
23
24 #include "target-common.h"
25
26 struct emit_ops;
27 struct btrace_target_info;
28 struct buffer;
29
30 /* This structure describes how to resume a particular thread (or all
31 threads) based on the client's request. If thread is -1, then this
32 entry applies to all threads. These are passed around as an
33 array. */
34
35 struct thread_resume
36 {
37 ptid_t thread;
38
39 /* How to "resume". */
40 enum resume_kind kind;
41
42 /* If non-zero, send this signal when we resume, or to stop the
43 thread. If stopping a thread, and this is 0, the target should
44 stop the thread however it best decides to (e.g., SIGSTOP on
45 linux; SuspendThread on win32). This is a host signal value (not
46 enum gdb_signal). */
47 int sig;
48
49 /* Range to single step within. Valid only iff KIND is resume_step.
50
51 Single-step once, and then continuing stepping as long as the
52 thread stops in this range. (If the range is empty
53 [STEP_RANGE_START == STEP_RANGE_END], then this is a single-step
54 request.) */
55 CORE_ADDR step_range_start; /* Inclusive */
56 CORE_ADDR step_range_end; /* Exclusive */
57 };
58
59 struct target_ops
60 {
61 /* Start a new process.
62
63 PROGRAM is a path to the program to execute.
64 ARGS is a standard NULL-terminated array of arguments,
65 to be passed to the inferior as ``argv''.
66
67 Returns the new PID on success, -1 on failure. Registers the new
68 process with the process list. */
69
70 int (*create_inferior) (char *program, char **args);
71
72 /* Attach to a running process.
73
74 PID is the process ID to attach to, specified by the user
75 or a higher layer.
76
77 Returns -1 if attaching is unsupported, 0 on success, and calls
78 error() otherwise. */
79
80 int (*attach) (unsigned long pid);
81
82 /* Kill inferior PID. Return -1 on failure, and 0 on success. */
83
84 int (*kill) (int pid);
85
86 /* Detach from inferior PID. Return -1 on failure, and 0 on
87 success. */
88
89 int (*detach) (int pid);
90
91 /* The inferior process has died. Do what is right. */
92
93 void (*mourn) (struct process_info *proc);
94
95 /* Wait for inferior PID to exit. */
96 void (*join) (int pid);
97
98 /* Return 1 iff the thread with process ID PID is alive. */
99
100 int (*thread_alive) (ptid_t pid);
101
102 /* Resume the inferior process. */
103
104 void (*resume) (struct thread_resume *resume_info, size_t n);
105
106 /* Wait for the inferior process or thread to change state. Store
107 status through argument pointer STATUS.
108
109 PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to
110 wait for any thread of process pid to do something. Return ptid
111 of child, or -1 in case of error; store status through argument
112 pointer STATUS. OPTIONS is a bit set of options defined as
113 TARGET_W* above. If options contains TARGET_WNOHANG and there's
114 no child stop to report, return is
115 null_ptid/TARGET_WAITKIND_IGNORE. */
116
117 ptid_t (*wait) (ptid_t ptid, struct target_waitstatus *status, int options);
118
119 /* Fetch registers from the inferior process.
120
121 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
122
123 void (*fetch_registers) (struct regcache *regcache, int regno);
124
125 /* Store registers to the inferior process.
126
127 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
128
129 void (*store_registers) (struct regcache *regcache, int regno);
130
131 /* Prepare to read or write memory from the inferior process.
132 Targets use this to do what is necessary to get the state of the
133 inferior such that it is possible to access memory.
134
135 This should generally only be called from client facing routines,
136 such as gdb_read_memory/gdb_write_memory, or the insert_point
137 callbacks.
138
139 Like `read_memory' and `write_memory' below, returns 0 on success
140 and errno on failure. */
141
142 int (*prepare_to_access_memory) (void);
143
144 /* Undo the effects of prepare_to_access_memory. */
145
146 void (*done_accessing_memory) (void);
147
148 /* Read memory from the inferior process. This should generally be
149 called through read_inferior_memory, which handles breakpoint shadowing.
150
151 Read LEN bytes at MEMADDR into a buffer at MYADDR.
152
153 Returns 0 on success and errno on failure. */
154
155 int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
156
157 /* Write memory to the inferior process. This should generally be
158 called through write_inferior_memory, which handles breakpoint shadowing.
159
160 Write LEN bytes from the buffer at MYADDR to MEMADDR.
161
162 Returns 0 on success and errno on failure. */
163
164 int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
165 int len);
166
167 /* Query GDB for the values of any symbols we're interested in.
168 This function is called whenever we receive a "qSymbols::"
169 query, which corresponds to every time more symbols (might)
170 become available. NULL if we aren't interested in any
171 symbols. */
172
173 void (*look_up_symbols) (void);
174
175 /* Send an interrupt request to the inferior process,
176 however is appropriate. */
177
178 void (*request_interrupt) (void);
179
180 /* Read auxiliary vector data from the inferior process.
181
182 Read LEN bytes at OFFSET into a buffer at MYADDR. */
183
184 int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
185 unsigned int len);
186
187 /* Insert and remove a break or watchpoint.
188 Returns 0 on success, -1 on failure and 1 on unsupported.
189 The type is coded as follows:
190 '0' - software-breakpoint
191 '1' - hardware-breakpoint
192 '2' - write watchpoint
193 '3' - read watchpoint
194 '4' - access watchpoint */
195
196 int (*insert_point) (char type, CORE_ADDR addr, int len);
197 int (*remove_point) (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 int (*supports_non_stop) (void);
242
243 /* Enables async target events. Returns the previous enable
244 state. */
245 int (*async) (int enable);
246
247 /* Switch to non-stop (1) or all-stop (0) mode. Return 0 on
248 success, -1 otherwise. */
249 int (*start_non_stop) (int);
250
251 /* Returns true if the target supports multi-process debugging. */
252 int (*supports_multi_process) (void);
253
254 /* If not NULL, target-specific routine to process monitor command.
255 Returns 1 if handled, or 0 to perform default processing. */
256 int (*handle_monitor_command) (char *);
257
258 /* Returns the core given a thread, or -1 if not known. */
259 int (*core_of_thread) (ptid_t);
260
261 /* Read loadmaps. Read LEN bytes at OFFSET into a buffer at MYADDR. */
262 int (*read_loadmap) (const char *annex, CORE_ADDR offset,
263 unsigned char *myaddr, unsigned int len);
264
265 /* Target specific qSupported support. */
266 void (*process_qsupported) (const char *);
267
268 /* Return 1 if the target supports tracepoints, 0 (or leave the
269 callback NULL) otherwise. */
270 int (*supports_tracepoints) (void);
271
272 /* Read PC from REGCACHE. */
273 CORE_ADDR (*read_pc) (struct regcache *regcache);
274
275 /* Write PC to REGCACHE. */
276 void (*write_pc) (struct regcache *regcache, CORE_ADDR pc);
277
278 /* Return true if THREAD is known to be stopped now. */
279 int (*thread_stopped) (struct thread_info *thread);
280
281 /* Read Thread Information Block address. */
282 int (*get_tib_address) (ptid_t ptid, CORE_ADDR *address);
283
284 /* Pause all threads. If FREEZE, arrange for any resume attempt to
285 be ignored until an unpause_all call unfreezes threads again.
286 There can be nested calls to pause_all, so a freeze counter
287 should be maintained. */
288 void (*pause_all) (int freeze);
289
290 /* Unpause all threads. Threads that hadn't been resumed by the
291 client should be left stopped. Basically a pause/unpause call
292 pair should not end up resuming threads that were stopped before
293 the pause call. */
294 void (*unpause_all) (int unfreeze);
295
296 /* Cancel all pending breakpoints hits in all threads. */
297 void (*cancel_breakpoints) (void);
298
299 /* Stabilize all threads. That is, force them out of jump pads. */
300 void (*stabilize_threads) (void);
301
302 /* Install a fast tracepoint jump pad. TPOINT is the address of the
303 tracepoint internal object as used by the IPA agent. TPADDR is
304 the address of tracepoint. COLLECTOR is address of the function
305 the jump pad redirects to. LOCKADDR is the address of the jump
306 pad lock object. ORIG_SIZE is the size in bytes of the
307 instruction at TPADDR. JUMP_ENTRY points to the address of the
308 jump pad entry, and on return holds the address past the end of
309 the created jump pad. If a trampoline is created by the function,
310 then TRAMPOLINE and TRAMPOLINE_SIZE return the address and size of
311 the trampoline, else they remain unchanged. JJUMP_PAD_INSN is a
312 buffer containing a copy of the instruction at TPADDR.
313 ADJUST_INSN_ADDR and ADJUST_INSN_ADDR_END are output parameters that
314 return the address range where the instruction at TPADDR was relocated
315 to. If an error occurs, the ERR may be used to pass on an error
316 message. */
317 int (*install_fast_tracepoint_jump_pad) (CORE_ADDR tpoint, CORE_ADDR tpaddr,
318 CORE_ADDR collector,
319 CORE_ADDR lockaddr,
320 ULONGEST orig_size,
321 CORE_ADDR *jump_entry,
322 CORE_ADDR *trampoline,
323 ULONGEST *trampoline_size,
324 unsigned char *jjump_pad_insn,
325 ULONGEST *jjump_pad_insn_size,
326 CORE_ADDR *adjusted_insn_addr,
327 CORE_ADDR *adjusted_insn_addr_end,
328 char *err);
329
330 /* Return the bytecode operations vector for the current inferior.
331 Returns NULL if bytecode compilation is not supported. */
332 struct emit_ops *(*emit_ops) (void);
333
334 /* Returns true if the target supports disabling randomization. */
335 int (*supports_disable_randomization) (void);
336
337 /* Return the minimum length of an instruction that can be safely overwritten
338 for use as a fast tracepoint. */
339 int (*get_min_fast_tracepoint_insn_len) (void);
340
341 /* Read solib info on SVR4 platforms. */
342 int (*qxfer_libraries_svr4) (const char *annex, unsigned char *readbuf,
343 unsigned const char *writebuf,
344 CORE_ADDR offset, int len);
345
346 /* Return true if target supports debugging agent. */
347 int (*supports_agent) (void);
348
349 /* Check whether the target supports branch tracing. */
350 int (*supports_btrace) (void);
351
352 /* Enable branch tracing for @ptid and allocate a branch trace target
353 information struct for reading and for disabling branch trace. */
354 struct btrace_target_info *(*enable_btrace) (ptid_t ptid);
355
356 /* Disable branch tracing. */
357 int (*disable_btrace) (struct btrace_target_info *tinfo);
358
359 /* Read branch trace data into buffer. We use an int to specify the type
360 to break a cyclic dependency. */
361 void (*read_btrace) (struct btrace_target_info *, struct buffer *, int type);
362
363 /* Return true if target supports range stepping. */
364 int (*supports_range_stepping) (void);
365 };
366
367 extern struct target_ops *the_target;
368
369 void set_target_ops (struct target_ops *);
370
371 #define create_inferior(program, args) \
372 (*the_target->create_inferior) (program, args)
373
374 #define myattach(pid) \
375 (*the_target->attach) (pid)
376
377 int kill_inferior (int);
378
379 #define detach_inferior(pid) \
380 (*the_target->detach) (pid)
381
382 #define mourn_inferior(PROC) \
383 (*the_target->mourn) (PROC)
384
385 #define mythread_alive(pid) \
386 (*the_target->thread_alive) (pid)
387
388 #define fetch_inferior_registers(regcache, regno) \
389 (*the_target->fetch_registers) (regcache, regno)
390
391 #define store_inferior_registers(regcache, regno) \
392 (*the_target->store_registers) (regcache, regno)
393
394 #define join_inferior(pid) \
395 (*the_target->join) (pid)
396
397 #define target_supports_non_stop() \
398 (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
399
400 #define target_async(enable) \
401 (the_target->async ? (*the_target->async) (enable) : 0)
402
403 #define target_supports_multi_process() \
404 (the_target->supports_multi_process ? \
405 (*the_target->supports_multi_process) () : 0)
406
407 #define target_process_qsupported(query) \
408 do \
409 { \
410 if (the_target->process_qsupported) \
411 the_target->process_qsupported (query); \
412 } while (0)
413
414 #define target_supports_tracepoints() \
415 (the_target->supports_tracepoints \
416 ? (*the_target->supports_tracepoints) () : 0)
417
418 #define target_supports_fast_tracepoints() \
419 (the_target->install_fast_tracepoint_jump_pad != NULL)
420
421 #define target_get_min_fast_tracepoint_insn_len() \
422 (the_target->get_min_fast_tracepoint_insn_len \
423 ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)
424
425 #define thread_stopped(thread) \
426 (*the_target->thread_stopped) (thread)
427
428 #define pause_all(freeze) \
429 do \
430 { \
431 if (the_target->pause_all) \
432 (*the_target->pause_all) (freeze); \
433 } while (0)
434
435 #define unpause_all(unfreeze) \
436 do \
437 { \
438 if (the_target->unpause_all) \
439 (*the_target->unpause_all) (unfreeze); \
440 } while (0)
441
442 #define cancel_breakpoints() \
443 do \
444 { \
445 if (the_target->cancel_breakpoints) \
446 (*the_target->cancel_breakpoints) (); \
447 } while (0)
448
449 #define stabilize_threads() \
450 do \
451 { \
452 if (the_target->stabilize_threads) \
453 (*the_target->stabilize_threads) (); \
454 } while (0)
455
456 #define install_fast_tracepoint_jump_pad(tpoint, tpaddr, \
457 collector, lockaddr, \
458 orig_size, \
459 jump_entry, \
460 trampoline, trampoline_size, \
461 jjump_pad_insn, \
462 jjump_pad_insn_size, \
463 adjusted_insn_addr, \
464 adjusted_insn_addr_end, \
465 err) \
466 (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr, \
467 collector,lockaddr, \
468 orig_size, jump_entry, \
469 trampoline, \
470 trampoline_size, \
471 jjump_pad_insn, \
472 jjump_pad_insn_size, \
473 adjusted_insn_addr, \
474 adjusted_insn_addr_end, \
475 err)
476
477 #define target_emit_ops() \
478 (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)
479
480 #define target_supports_disable_randomization() \
481 (the_target->supports_disable_randomization ? \
482 (*the_target->supports_disable_randomization) () : 0)
483
484 #define target_supports_agent() \
485 (the_target->supports_agent ? \
486 (*the_target->supports_agent) () : 0)
487
488 #define target_supports_btrace() \
489 (the_target->supports_btrace ? (*the_target->supports_btrace) () : 0)
490
491 #define target_enable_btrace(ptid) \
492 (*the_target->enable_btrace) (ptid)
493
494 #define target_disable_btrace(tinfo) \
495 (*the_target->disable_btrace) (tinfo)
496
497 #define target_read_btrace(tinfo, buffer, type) \
498 (*the_target->read_btrace) (tinfo, buffer, type)
499
500 #define target_supports_range_stepping() \
501 (the_target->supports_range_stepping ? \
502 (*the_target->supports_range_stepping) () : 0)
503
504 /* Start non-stop mode, returns 0 on success, -1 on failure. */
505
506 int start_non_stop (int nonstop);
507
508 ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
509 int connected_wait);
510
511 #define prepare_to_access_memory() \
512 (the_target->prepare_to_access_memory \
513 ? (*the_target->prepare_to_access_memory) () \
514 : 0)
515
516 #define done_accessing_memory() \
517 do \
518 { \
519 if (the_target->done_accessing_memory) \
520 (*the_target->done_accessing_memory) (); \
521 } while (0)
522
523 #define target_core_of_thread(ptid) \
524 (the_target->core_of_thread ? (*the_target->core_of_thread) (ptid) \
525 : -1)
526
527 int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
528
529 int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
530 int len);
531
532 void set_desired_inferior (int id);
533
534 const char *target_pid_to_str (ptid_t);
535
536 #endif /* TARGET_H */
This page took 0.041095 seconds and 4 git commands to generate.