1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002-2014 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/target.h"
25 #include "target/resume.h"
26 #include "target/wait.h"
27 #include "target/waitstatus.h"
28 #include "mem-break.h"
31 struct btrace_target_info
;
35 /* This structure describes how to resume a particular thread (or all
36 threads) based on the client's request. If thread is -1, then this
37 entry applies to all threads. These are passed around as an
44 /* How to "resume". */
45 enum resume_kind kind
;
47 /* If non-zero, send this signal when we resume, or to stop the
48 thread. If stopping a thread, and this is 0, the target should
49 stop the thread however it best decides to (e.g., SIGSTOP on
50 linux; SuspendThread on win32). This is a host signal value (not
54 /* Range to single step within. Valid only iff KIND is resume_step.
56 Single-step once, and then continuing stepping as long as the
57 thread stops in this range. (If the range is empty
58 [STEP_RANGE_START == STEP_RANGE_END], then this is a single-step
60 CORE_ADDR step_range_start
; /* Inclusive */
61 CORE_ADDR step_range_end
; /* Exclusive */
66 /* Start a new process.
68 PROGRAM is a path to the program to execute.
69 ARGS is a standard NULL-terminated array of arguments,
70 to be passed to the inferior as ``argv''.
72 Returns the new PID on success, -1 on failure. Registers the new
73 process with the process list. */
75 int (*create_inferior
) (char *program
, char **args
);
77 /* Attach to a running process.
79 PID is the process ID to attach to, specified by the user
82 Returns -1 if attaching is unsupported, 0 on success, and calls
85 int (*attach
) (unsigned long pid
);
87 /* Kill inferior PID. Return -1 on failure, and 0 on success. */
89 int (*kill
) (int pid
);
91 /* Detach from inferior PID. Return -1 on failure, and 0 on
94 int (*detach
) (int pid
);
96 /* The inferior process has died. Do what is right. */
98 void (*mourn
) (struct process_info
*proc
);
100 /* Wait for inferior PID to exit. */
101 void (*join
) (int pid
);
103 /* Return 1 iff the thread with process ID PID is alive. */
105 int (*thread_alive
) (ptid_t pid
);
107 /* Resume the inferior process. */
109 void (*resume
) (struct thread_resume
*resume_info
, size_t n
);
111 /* Wait for the inferior process or thread to change state. Store
112 status through argument pointer STATUS.
114 PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to
115 wait for any thread of process pid to do something. Return ptid
116 of child, or -1 in case of error; store status through argument
117 pointer STATUS. OPTIONS is a bit set of options defined as
118 TARGET_W* above. If options contains TARGET_WNOHANG and there's
119 no child stop to report, return is
120 null_ptid/TARGET_WAITKIND_IGNORE. */
122 ptid_t (*wait
) (ptid_t ptid
, struct target_waitstatus
*status
, int options
);
124 /* Fetch registers from the inferior process.
126 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
128 void (*fetch_registers
) (struct regcache
*regcache
, int regno
);
130 /* Store registers to the inferior process.
132 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
134 void (*store_registers
) (struct regcache
*regcache
, int regno
);
136 /* Prepare to read or write memory from the inferior process.
137 Targets use this to do what is necessary to get the state of the
138 inferior such that it is possible to access memory.
140 This should generally only be called from client facing routines,
141 such as gdb_read_memory/gdb_write_memory, or the GDB breakpoint
144 Like `read_memory' and `write_memory' below, returns 0 on success
145 and errno on failure. */
147 int (*prepare_to_access_memory
) (void);
149 /* Undo the effects of prepare_to_access_memory. */
151 void (*done_accessing_memory
) (void);
153 /* Read memory from the inferior process. This should generally be
154 called through read_inferior_memory, which handles breakpoint shadowing.
156 Read LEN bytes at MEMADDR into a buffer at MYADDR.
158 Returns 0 on success and errno on failure. */
160 int (*read_memory
) (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
);
162 /* Write memory to the inferior process. This should generally be
163 called through write_inferior_memory, which handles breakpoint shadowing.
165 Write LEN bytes from the buffer at MYADDR to MEMADDR.
167 Returns 0 on success and errno on failure. */
169 int (*write_memory
) (CORE_ADDR memaddr
, const unsigned char *myaddr
,
172 /* Query GDB for the values of any symbols we're interested in.
173 This function is called whenever we receive a "qSymbols::"
174 query, which corresponds to every time more symbols (might)
175 become available. NULL if we aren't interested in any
178 void (*look_up_symbols
) (void);
180 /* Send an interrupt request to the inferior process,
181 however is appropriate. */
183 void (*request_interrupt
) (void);
185 /* Read auxiliary vector data from the inferior process.
187 Read LEN bytes at OFFSET into a buffer at MYADDR. */
189 int (*read_auxv
) (CORE_ADDR offset
, unsigned char *myaddr
,
192 /* Returns true if GDB Z breakpoint type TYPE is supported, false
193 otherwise. The type is coded as follows:
194 '0' - software-breakpoint
195 '1' - hardware-breakpoint
196 '2' - write watchpoint
197 '3' - read watchpoint
198 '4' - access watchpoint
200 int (*supports_z_point_type
) (char z_type
);
202 /* Insert and remove a break or watchpoint.
203 Returns 0 on success, -1 on failure and 1 on unsupported. */
205 int (*insert_point
) (enum raw_bkpt_type type
, CORE_ADDR addr
,
206 int size
, struct raw_breakpoint
*bp
);
207 int (*remove_point
) (enum raw_bkpt_type type
, CORE_ADDR addr
,
208 int size
, struct raw_breakpoint
*bp
);
210 /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */
212 int (*stopped_by_watchpoint
) (void);
214 /* Returns the address associated with the watchpoint that hit, if any;
215 returns 0 otherwise. */
217 CORE_ADDR (*stopped_data_address
) (void);
219 /* Reports the text, data offsets of the executable. This is
220 needed for uclinux where the executable is relocated during load
223 int (*read_offsets
) (CORE_ADDR
*text
, CORE_ADDR
*data
);
225 /* Fetch the address associated with a specific thread local storage
226 area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
227 Stores it in *ADDRESS and returns zero on success; otherwise returns
228 an error code. A return value of -1 means this system does not
229 support the operation. */
231 int (*get_tls_address
) (struct thread_info
*thread
, CORE_ADDR offset
,
232 CORE_ADDR load_module
, CORE_ADDR
*address
);
234 /* Read/Write from/to spufs using qXfer packets. */
235 int (*qxfer_spu
) (const char *annex
, unsigned char *readbuf
,
236 unsigned const char *writebuf
, CORE_ADDR offset
, int len
);
238 /* Fill BUF with an hostio error packet representing the last hostio
240 void (*hostio_last_error
) (char *buf
);
242 /* Read/Write OS data using qXfer packets. */
243 int (*qxfer_osdata
) (const char *annex
, unsigned char *readbuf
,
244 unsigned const char *writebuf
, CORE_ADDR offset
,
247 /* Read/Write extra signal info. */
248 int (*qxfer_siginfo
) (const char *annex
, unsigned char *readbuf
,
249 unsigned const char *writebuf
,
250 CORE_ADDR offset
, int len
);
252 int (*supports_non_stop
) (void);
254 /* Enables async target events. Returns the previous enable
256 int (*async
) (int enable
);
258 /* Switch to non-stop (1) or all-stop (0) mode. Return 0 on
259 success, -1 otherwise. */
260 int (*start_non_stop
) (int);
262 /* Returns true if the target supports multi-process debugging. */
263 int (*supports_multi_process
) (void);
265 /* If not NULL, target-specific routine to process monitor command.
266 Returns 1 if handled, or 0 to perform default processing. */
267 int (*handle_monitor_command
) (char *);
269 /* Returns the core given a thread, or -1 if not known. */
270 int (*core_of_thread
) (ptid_t
);
272 /* Read loadmaps. Read LEN bytes at OFFSET into a buffer at MYADDR. */
273 int (*read_loadmap
) (const char *annex
, CORE_ADDR offset
,
274 unsigned char *myaddr
, unsigned int len
);
276 /* Target specific qSupported support. */
277 void (*process_qsupported
) (const char *);
279 /* Return 1 if the target supports tracepoints, 0 (or leave the
280 callback NULL) otherwise. */
281 int (*supports_tracepoints
) (void);
283 /* Read PC from REGCACHE. */
284 CORE_ADDR (*read_pc
) (struct regcache
*regcache
);
286 /* Write PC to REGCACHE. */
287 void (*write_pc
) (struct regcache
*regcache
, CORE_ADDR pc
);
289 /* Return true if THREAD is known to be stopped now. */
290 int (*thread_stopped
) (struct thread_info
*thread
);
292 /* Read Thread Information Block address. */
293 int (*get_tib_address
) (ptid_t ptid
, CORE_ADDR
*address
);
295 /* Pause all threads. If FREEZE, arrange for any resume attempt to
296 be ignored until an unpause_all call unfreezes threads again.
297 There can be nested calls to pause_all, so a freeze counter
298 should be maintained. */
299 void (*pause_all
) (int freeze
);
301 /* Unpause all threads. Threads that hadn't been resumed by the
302 client should be left stopped. Basically a pause/unpause call
303 pair should not end up resuming threads that were stopped before
305 void (*unpause_all
) (int unfreeze
);
307 /* Cancel all pending breakpoints hits in all threads. */
308 void (*cancel_breakpoints
) (void);
310 /* Stabilize all threads. That is, force them out of jump pads. */
311 void (*stabilize_threads
) (void);
313 /* Install a fast tracepoint jump pad. TPOINT is the address of the
314 tracepoint internal object as used by the IPA agent. TPADDR is
315 the address of tracepoint. COLLECTOR is address of the function
316 the jump pad redirects to. LOCKADDR is the address of the jump
317 pad lock object. ORIG_SIZE is the size in bytes of the
318 instruction at TPADDR. JUMP_ENTRY points to the address of the
319 jump pad entry, and on return holds the address past the end of
320 the created jump pad. If a trampoline is created by the function,
321 then TRAMPOLINE and TRAMPOLINE_SIZE return the address and size of
322 the trampoline, else they remain unchanged. JJUMP_PAD_INSN is a
323 buffer containing a copy of the instruction at TPADDR.
324 ADJUST_INSN_ADDR and ADJUST_INSN_ADDR_END are output parameters that
325 return the address range where the instruction at TPADDR was relocated
326 to. If an error occurs, the ERR may be used to pass on an error
328 int (*install_fast_tracepoint_jump_pad
) (CORE_ADDR tpoint
, CORE_ADDR tpaddr
,
332 CORE_ADDR
*jump_entry
,
333 CORE_ADDR
*trampoline
,
334 ULONGEST
*trampoline_size
,
335 unsigned char *jjump_pad_insn
,
336 ULONGEST
*jjump_pad_insn_size
,
337 CORE_ADDR
*adjusted_insn_addr
,
338 CORE_ADDR
*adjusted_insn_addr_end
,
341 /* Return the bytecode operations vector for the current inferior.
342 Returns NULL if bytecode compilation is not supported. */
343 struct emit_ops
*(*emit_ops
) (void);
345 /* Returns true if the target supports disabling randomization. */
346 int (*supports_disable_randomization
) (void);
348 /* Return the minimum length of an instruction that can be safely overwritten
349 for use as a fast tracepoint. */
350 int (*get_min_fast_tracepoint_insn_len
) (void);
352 /* Read solib info on SVR4 platforms. */
353 int (*qxfer_libraries_svr4
) (const char *annex
, unsigned char *readbuf
,
354 unsigned const char *writebuf
,
355 CORE_ADDR offset
, int len
);
357 /* Return true if target supports debugging agent. */
358 int (*supports_agent
) (void);
360 /* Check whether the target supports branch tracing. */
361 int (*supports_btrace
) (struct target_ops
*);
363 /* Enable branch tracing for @ptid and allocate a branch trace target
364 information struct for reading and for disabling branch trace. */
365 struct btrace_target_info
*(*enable_btrace
) (ptid_t ptid
);
367 /* Disable branch tracing.
368 Returns zero on success, non-zero otherwise. */
369 int (*disable_btrace
) (struct btrace_target_info
*tinfo
);
371 /* Read branch trace data into buffer. We use an int to specify the type
372 to break a cyclic dependency.
373 Return 0 on success; print an error message into BUFFER and return -1,
375 int (*read_btrace
) (struct btrace_target_info
*, struct buffer
*, int type
);
377 /* Return true if target supports range stepping. */
378 int (*supports_range_stepping
) (void);
381 extern struct target_ops
*the_target
;
383 void set_target_ops (struct target_ops
*);
385 #define create_inferior(program, args) \
386 (*the_target->create_inferior) (program, args)
388 #define myattach(pid) \
389 (*the_target->attach) (pid)
391 int kill_inferior (int);
393 #define detach_inferior(pid) \
394 (*the_target->detach) (pid)
396 #define mourn_inferior(PROC) \
397 (*the_target->mourn) (PROC)
399 #define mythread_alive(pid) \
400 (*the_target->thread_alive) (pid)
402 #define fetch_inferior_registers(regcache, regno) \
403 (*the_target->fetch_registers) (regcache, regno)
405 #define store_inferior_registers(regcache, regno) \
406 (*the_target->store_registers) (regcache, regno)
408 #define join_inferior(pid) \
409 (*the_target->join) (pid)
411 #define target_supports_non_stop() \
412 (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
414 #define target_async(enable) \
415 (the_target->async ? (*the_target->async) (enable) : 0)
417 #define target_supports_multi_process() \
418 (the_target->supports_multi_process ? \
419 (*the_target->supports_multi_process) () : 0)
421 #define target_process_qsupported(query) \
424 if (the_target->process_qsupported) \
425 the_target->process_qsupported (query); \
428 #define target_supports_tracepoints() \
429 (the_target->supports_tracepoints \
430 ? (*the_target->supports_tracepoints) () : 0)
432 #define target_supports_fast_tracepoints() \
433 (the_target->install_fast_tracepoint_jump_pad != NULL)
435 #define target_get_min_fast_tracepoint_insn_len() \
436 (the_target->get_min_fast_tracepoint_insn_len \
437 ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)
439 #define thread_stopped(thread) \
440 (*the_target->thread_stopped) (thread)
442 #define pause_all(freeze) \
445 if (the_target->pause_all) \
446 (*the_target->pause_all) (freeze); \
449 #define unpause_all(unfreeze) \
452 if (the_target->unpause_all) \
453 (*the_target->unpause_all) (unfreeze); \
456 #define cancel_breakpoints() \
459 if (the_target->cancel_breakpoints) \
460 (*the_target->cancel_breakpoints) (); \
463 #define stabilize_threads() \
466 if (the_target->stabilize_threads) \
467 (*the_target->stabilize_threads) (); \
470 #define install_fast_tracepoint_jump_pad(tpoint, tpaddr, \
471 collector, lockaddr, \
474 trampoline, trampoline_size, \
476 jjump_pad_insn_size, \
477 adjusted_insn_addr, \
478 adjusted_insn_addr_end, \
480 (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr, \
481 collector,lockaddr, \
482 orig_size, jump_entry, \
486 jjump_pad_insn_size, \
487 adjusted_insn_addr, \
488 adjusted_insn_addr_end, \
491 #define target_emit_ops() \
492 (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)
494 #define target_supports_disable_randomization() \
495 (the_target->supports_disable_randomization ? \
496 (*the_target->supports_disable_randomization) () : 0)
498 #define target_supports_agent() \
499 (the_target->supports_agent ? \
500 (*the_target->supports_agent) () : 0)
502 #define target_supports_btrace() \
503 (the_target->supports_btrace \
504 ? (*the_target->supports_btrace) (the_target) : 0)
506 #define target_enable_btrace(ptid) \
507 (*the_target->enable_btrace) (ptid)
509 #define target_disable_btrace(tinfo) \
510 (*the_target->disable_btrace) (tinfo)
512 #define target_read_btrace(tinfo, buffer, type) \
513 (*the_target->read_btrace) (tinfo, buffer, type)
515 #define target_supports_range_stepping() \
516 (the_target->supports_range_stepping ? \
517 (*the_target->supports_range_stepping) () : 0)
519 /* Start non-stop mode, returns 0 on success, -1 on failure. */
521 int start_non_stop (int nonstop
);
523 ptid_t
mywait (ptid_t ptid
, struct target_waitstatus
*ourstatus
, int options
,
526 #define prepare_to_access_memory() \
527 (the_target->prepare_to_access_memory \
528 ? (*the_target->prepare_to_access_memory) () \
531 #define done_accessing_memory() \
534 if (the_target->done_accessing_memory) \
535 (*the_target->done_accessing_memory) (); \
538 #define target_core_of_thread(ptid) \
539 (the_target->core_of_thread ? (*the_target->core_of_thread) (ptid) \
542 int read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
);
544 int write_inferior_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
,
547 void set_desired_thread (int id
);
549 const char *target_pid_to_str (ptid_t
);
551 #endif /* TARGET_H */