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