1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
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.
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.
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/>. */
24 #include "target-common.h"
27 struct btrace_target_info
;
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
39 /* How to "resume". */
40 enum resume_kind kind
;
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
49 /* Range to single step within. Valid only iff KIND is resume_step.
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
55 CORE_ADDR step_range_start
; /* Inclusive */
56 CORE_ADDR step_range_end
; /* Exclusive */
61 /* Start a new process.
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''.
67 Returns the new PID on success, -1 on failure. Registers the new
68 process with the process list. */
70 int (*create_inferior
) (char *program
, char **args
);
72 /* Attach to a running process.
74 PID is the process ID to attach to, specified by the user
77 Returns -1 if attaching is unsupported, 0 on success, and calls
80 int (*attach
) (unsigned long pid
);
82 /* Kill inferior PID. Return -1 on failure, and 0 on success. */
84 int (*kill
) (int pid
);
86 /* Detach from inferior PID. Return -1 on failure, and 0 on
89 int (*detach
) (int pid
);
91 /* The inferior process has died. Do what is right. */
93 void (*mourn
) (struct process_info
*proc
);
95 /* Wait for inferior PID to exit. */
96 void (*join
) (int pid
);
98 /* Return 1 iff the thread with process ID PID is alive. */
100 int (*thread_alive
) (ptid_t pid
);
102 /* Resume the inferior process. */
104 void (*resume
) (struct thread_resume
*resume_info
, size_t n
);
106 /* Wait for the inferior process or thread to change state. Store
107 status through argument pointer STATUS.
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. */
117 ptid_t (*wait
) (ptid_t ptid
, struct target_waitstatus
*status
, int options
);
119 /* Fetch registers from the inferior process.
121 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
123 void (*fetch_registers
) (struct regcache
*regcache
, int regno
);
125 /* Store registers to the inferior process.
127 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
129 void (*store_registers
) (struct regcache
*regcache
, int regno
);
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.
135 This should generally only be called from client facing routines,
136 such as gdb_read_memory/gdb_write_memory, or the insert_point
139 Like `read_memory' and `write_memory' below, returns 0 on success
140 and errno on failure. */
142 int (*prepare_to_access_memory
) (void);
144 /* Undo the effects of prepare_to_access_memory. */
146 void (*done_accessing_memory
) (void);
148 /* Read memory from the inferior process. This should generally be
149 called through read_inferior_memory, which handles breakpoint shadowing.
151 Read LEN bytes at MEMADDR into a buffer at MYADDR.
153 Returns 0 on success and errno on failure. */
155 int (*read_memory
) (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
);
157 /* Write memory to the inferior process. This should generally be
158 called through write_inferior_memory, which handles breakpoint shadowing.
160 Write LEN bytes from the buffer at MYADDR to MEMADDR.
162 Returns 0 on success and errno on failure. */
164 int (*write_memory
) (CORE_ADDR memaddr
, const unsigned char *myaddr
,
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
173 void (*look_up_symbols
) (void);
175 /* Send an interrupt request to the inferior process,
176 however is appropriate. */
178 void (*request_interrupt
) (void);
180 /* Read auxiliary vector data from the inferior process.
182 Read LEN bytes at OFFSET into a buffer at MYADDR. */
184 int (*read_auxv
) (CORE_ADDR offset
, unsigned char *myaddr
,
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 */
196 int (*insert_point
) (char type
, CORE_ADDR addr
, int len
);
197 int (*remove_point
) (char type
, CORE_ADDR addr
, int len
);
199 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */
201 int (*stopped_by_watchpoint
) (void);
203 /* Returns the address associated with the watchpoint that hit, if any;
204 returns 0 otherwise. */
206 CORE_ADDR (*stopped_data_address
) (void);
208 /* Reports the text, data offsets of the executable. This is
209 needed for uclinux where the executable is relocated during load
212 int (*read_offsets
) (CORE_ADDR
*text
, CORE_ADDR
*data
);
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. */
220 int (*get_tls_address
) (struct thread_info
*thread
, CORE_ADDR offset
,
221 CORE_ADDR load_module
, CORE_ADDR
*address
);
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
);
227 /* Fill BUF with an hostio error packet representing the last hostio
229 void (*hostio_last_error
) (char *buf
);
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
,
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
);
241 int (*supports_non_stop
) (void);
243 /* Enables async target events. Returns the previous enable
245 int (*async
) (int enable
);
247 /* Switch to non-stop (1) or all-stop (0) mode. Return 0 on
248 success, -1 otherwise. */
249 int (*start_non_stop
) (int);
251 /* Returns true if the target supports multi-process debugging. */
252 int (*supports_multi_process
) (void);
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 *);
258 /* Returns the core given a thread, or -1 if not known. */
259 int (*core_of_thread
) (ptid_t
);
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
);
265 /* Target specific qSupported support. */
266 void (*process_qsupported
) (const char *);
268 /* Return 1 if the target supports tracepoints, 0 (or leave the
269 callback NULL) otherwise. */
270 int (*supports_tracepoints
) (void);
272 /* Read PC from REGCACHE. */
273 CORE_ADDR (*read_pc
) (struct regcache
*regcache
);
275 /* Write PC to REGCACHE. */
276 void (*write_pc
) (struct regcache
*regcache
, CORE_ADDR pc
);
278 /* Return true if THREAD is known to be stopped now. */
279 int (*thread_stopped
) (struct thread_info
*thread
);
281 /* Read Thread Information Block address. */
282 int (*get_tib_address
) (ptid_t ptid
, CORE_ADDR
*address
);
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
);
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
294 void (*unpause_all
) (int unfreeze
);
296 /* Cancel all pending breakpoints hits in all threads. */
297 void (*cancel_breakpoints
) (void);
299 /* Stabilize all threads. That is, force them out of jump pads. */
300 void (*stabilize_threads
) (void);
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
317 int (*install_fast_tracepoint_jump_pad
) (CORE_ADDR tpoint
, CORE_ADDR tpaddr
,
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
,
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);
334 /* Returns true if the target supports disabling randomization. */
335 int (*supports_disable_randomization
) (void);
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);
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
);
346 /* Return true if target supports debugging agent. */
347 int (*supports_agent
) (void);
349 /* Check whether the target supports branch tracing. */
350 int (*supports_btrace
) (void);
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
);
356 /* Disable branch tracing. */
357 int (*disable_btrace
) (struct btrace_target_info
*tinfo
);
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
);
363 /* Return true if target supports range stepping. */
364 int (*supports_range_stepping
) (void);
367 extern struct target_ops
*the_target
;
369 void set_target_ops (struct target_ops
*);
371 #define create_inferior(program, args) \
372 (*the_target->create_inferior) (program, args)
374 #define myattach(pid) \
375 (*the_target->attach) (pid)
377 int kill_inferior (int);
379 #define detach_inferior(pid) \
380 (*the_target->detach) (pid)
382 #define mourn_inferior(PROC) \
383 (*the_target->mourn) (PROC)
385 #define mythread_alive(pid) \
386 (*the_target->thread_alive) (pid)
388 #define fetch_inferior_registers(regcache, regno) \
389 (*the_target->fetch_registers) (regcache, regno)
391 #define store_inferior_registers(regcache, regno) \
392 (*the_target->store_registers) (regcache, regno)
394 #define join_inferior(pid) \
395 (*the_target->join) (pid)
397 #define target_supports_non_stop() \
398 (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
400 #define target_async(enable) \
401 (the_target->async ? (*the_target->async) (enable) : 0)
403 #define target_supports_multi_process() \
404 (the_target->supports_multi_process ? \
405 (*the_target->supports_multi_process) () : 0)
407 #define target_process_qsupported(query) \
410 if (the_target->process_qsupported) \
411 the_target->process_qsupported (query); \
414 #define target_supports_tracepoints() \
415 (the_target->supports_tracepoints \
416 ? (*the_target->supports_tracepoints) () : 0)
418 #define target_supports_fast_tracepoints() \
419 (the_target->install_fast_tracepoint_jump_pad != NULL)
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)
425 #define thread_stopped(thread) \
426 (*the_target->thread_stopped) (thread)
428 #define pause_all(freeze) \
431 if (the_target->pause_all) \
432 (*the_target->pause_all) (freeze); \
435 #define unpause_all(unfreeze) \
438 if (the_target->unpause_all) \
439 (*the_target->unpause_all) (unfreeze); \
442 #define cancel_breakpoints() \
445 if (the_target->cancel_breakpoints) \
446 (*the_target->cancel_breakpoints) (); \
449 #define stabilize_threads() \
452 if (the_target->stabilize_threads) \
453 (*the_target->stabilize_threads) (); \
456 #define install_fast_tracepoint_jump_pad(tpoint, tpaddr, \
457 collector, lockaddr, \
460 trampoline, trampoline_size, \
462 jjump_pad_insn_size, \
463 adjusted_insn_addr, \
464 adjusted_insn_addr_end, \
466 (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr, \
467 collector,lockaddr, \
468 orig_size, jump_entry, \
472 jjump_pad_insn_size, \
473 adjusted_insn_addr, \
474 adjusted_insn_addr_end, \
477 #define target_emit_ops() \
478 (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)
480 #define target_supports_disable_randomization() \
481 (the_target->supports_disable_randomization ? \
482 (*the_target->supports_disable_randomization) () : 0)
484 #define target_supports_agent() \
485 (the_target->supports_agent ? \
486 (*the_target->supports_agent) () : 0)
488 #define target_supports_btrace() \
489 (the_target->supports_btrace ? (*the_target->supports_btrace) () : 0)
491 #define target_enable_btrace(ptid) \
492 (*the_target->enable_btrace) (ptid)
494 #define target_disable_btrace(tinfo) \
495 (*the_target->disable_btrace) (tinfo)
497 #define target_read_btrace(tinfo, buffer, type) \
498 (*the_target->read_btrace) (tinfo, buffer, type)
500 #define target_supports_range_stepping() \
501 (the_target->supports_range_stepping ? \
502 (*the_target->supports_range_stepping) () : 0)
504 /* Start non-stop mode, returns 0 on success, -1 on failure. */
506 int start_non_stop (int nonstop
);
508 ptid_t
mywait (ptid_t ptid
, struct target_waitstatus
*ourstatus
, int options
,
511 #define prepare_to_access_memory() \
512 (the_target->prepare_to_access_memory \
513 ? (*the_target->prepare_to_access_memory) () \
516 #define done_accessing_memory() \
519 if (the_target->done_accessing_memory) \
520 (*the_target->done_accessing_memory) (); \
523 #define target_core_of_thread(ptid) \
524 (the_target->core_of_thread ? (*the_target->core_of_thread) (ptid) \
527 int read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
);
529 int write_inferior_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
,
532 void set_desired_inferior (int id
);
534 const char *target_pid_to_str (ptid_t
);
536 #endif /* TARGET_H */