* target.h (struct target_ops): Add
[binutils-gdb.git] / gdb / target.h
1 /* Interface between GDB and target environments, including files and processes
2
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 Free Software Foundation, Inc.
6
7 Contributed by Cygnus Support. Written by John Gilmore.
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23
24 #if !defined (TARGET_H)
25 #define TARGET_H
26
27 struct objfile;
28 struct ui_file;
29 struct mem_attrib;
30 struct target_ops;
31 struct bp_target_info;
32 struct regcache;
33
34 /* This include file defines the interface between the main part
35 of the debugger, and the part which is target-specific, or
36 specific to the communications interface between us and the
37 target.
38
39 A TARGET is an interface between the debugger and a particular
40 kind of file or process. Targets can be STACKED in STRATA,
41 so that more than one target can potentially respond to a request.
42 In particular, memory accesses will walk down the stack of targets
43 until they find a target that is interested in handling that particular
44 address. STRATA are artificial boundaries on the stack, within
45 which particular kinds of targets live. Strata exist so that
46 people don't get confused by pushing e.g. a process target and then
47 a file target, and wondering why they can't see the current values
48 of variables any more (the file target is handling them and they
49 never get to the process target). So when you push a file target,
50 it goes into the file stratum, which is always below the process
51 stratum. */
52
53 #include "bfd.h"
54 #include "symtab.h"
55 #include "dcache.h"
56 #include "memattr.h"
57 #include "vec.h"
58
59 enum strata
60 {
61 dummy_stratum, /* The lowest of the low */
62 file_stratum, /* Executable files, etc */
63 core_stratum, /* Core dump files */
64 process_stratum, /* Executing processes */
65 thread_stratum /* Executing threads */
66 };
67
68 enum thread_control_capabilities
69 {
70 tc_none = 0, /* Default: can't control thread execution. */
71 tc_schedlock = 1, /* Can lock the thread scheduler. */
72 tc_switch = 2 /* Can switch the running thread on demand. */
73 };
74
75 /* Stuff for target_wait. */
76
77 /* Generally, what has the program done? */
78 enum target_waitkind
79 {
80 /* The program has exited. The exit status is in value.integer. */
81 TARGET_WAITKIND_EXITED,
82
83 /* The program has stopped with a signal. Which signal is in
84 value.sig. */
85 TARGET_WAITKIND_STOPPED,
86
87 /* The program has terminated with a signal. Which signal is in
88 value.sig. */
89 TARGET_WAITKIND_SIGNALLED,
90
91 /* The program is letting us know that it dynamically loaded something
92 (e.g. it called load(2) on AIX). */
93 TARGET_WAITKIND_LOADED,
94
95 /* The program has forked. A "related" process' ID is in
96 value.related_pid. I.e., if the child forks, value.related_pid
97 is the parent's ID. */
98
99 TARGET_WAITKIND_FORKED,
100
101 /* The program has vforked. A "related" process's ID is in
102 value.related_pid. */
103
104 TARGET_WAITKIND_VFORKED,
105
106 /* The program has exec'ed a new executable file. The new file's
107 pathname is pointed to by value.execd_pathname. */
108
109 TARGET_WAITKIND_EXECD,
110
111 /* The program has entered or returned from a system call. On
112 HP-UX, this is used in the hardware watchpoint implementation.
113 The syscall's unique integer ID number is in value.syscall_id */
114
115 TARGET_WAITKIND_SYSCALL_ENTRY,
116 TARGET_WAITKIND_SYSCALL_RETURN,
117
118 /* Nothing happened, but we stopped anyway. This perhaps should be handled
119 within target_wait, but I'm not sure target_wait should be resuming the
120 inferior. */
121 TARGET_WAITKIND_SPURIOUS,
122
123 /* An event has occured, but we should wait again.
124 Remote_async_wait() returns this when there is an event
125 on the inferior, but the rest of the world is not interested in
126 it. The inferior has not stopped, but has just sent some output
127 to the console, for instance. In this case, we want to go back
128 to the event loop and wait there for another event from the
129 inferior, rather than being stuck in the remote_async_wait()
130 function. This way the event loop is responsive to other events,
131 like for instance the user typing. */
132 TARGET_WAITKIND_IGNORE
133 };
134
135 struct target_waitstatus
136 {
137 enum target_waitkind kind;
138
139 /* Forked child pid, execd pathname, exit status or signal number. */
140 union
141 {
142 int integer;
143 enum target_signal sig;
144 int related_pid;
145 char *execd_pathname;
146 int syscall_id;
147 }
148 value;
149 };
150
151 /* Possible types of events that the inferior handler will have to
152 deal with. */
153 enum inferior_event_type
154 {
155 /* There is a request to quit the inferior, abandon it. */
156 INF_QUIT_REQ,
157 /* Process a normal inferior event which will result in target_wait
158 being called. */
159 INF_REG_EVENT,
160 /* Deal with an error on the inferior. */
161 INF_ERROR,
162 /* We are called because a timer went off. */
163 INF_TIMER,
164 /* We are called to do stuff after the inferior stops. */
165 INF_EXEC_COMPLETE,
166 /* We are called to do some stuff after the inferior stops, but we
167 are expected to reenter the proceed() and
168 handle_inferior_event() functions. This is used only in case of
169 'step n' like commands. */
170 INF_EXEC_CONTINUE
171 };
172
173 /* Return the string for a signal. */
174 extern char *target_signal_to_string (enum target_signal);
175
176 /* Return the name (SIGHUP, etc.) for a signal. */
177 extern char *target_signal_to_name (enum target_signal);
178
179 /* Given a name (SIGHUP, etc.), return its signal. */
180 enum target_signal target_signal_from_name (char *);
181 \f
182 /* Target objects which can be transfered using target_read,
183 target_write, et cetera. */
184
185 enum target_object
186 {
187 /* AVR target specific transfer. See "avr-tdep.c" and "remote.c". */
188 TARGET_OBJECT_AVR,
189 /* SPU target specific transfer. See "spu-tdep.c". */
190 TARGET_OBJECT_SPU,
191 /* Transfer up-to LEN bytes of memory starting at OFFSET. */
192 TARGET_OBJECT_MEMORY,
193 /* Memory, avoiding GDB's data cache and trusting the executable.
194 Target implementations of to_xfer_partial never need to handle
195 this object, and most callers should not use it. */
196 TARGET_OBJECT_RAW_MEMORY,
197 /* Kernel Unwind Table. See "ia64-tdep.c". */
198 TARGET_OBJECT_UNWIND_TABLE,
199 /* Transfer auxilliary vector. */
200 TARGET_OBJECT_AUXV,
201 /* StackGhost cookie. See "sparc-tdep.c". */
202 TARGET_OBJECT_WCOOKIE,
203 /* Target memory map in XML format. */
204 TARGET_OBJECT_MEMORY_MAP,
205 /* Flash memory. This object can be used to write contents to
206 a previously erased flash memory. Using it without erasing
207 flash can have unexpected results. Addresses are physical
208 address on target, and not relative to flash start. */
209 TARGET_OBJECT_FLASH,
210 /* Available target-specific features, e.g. registers and coprocessors.
211 See "target-descriptions.c". ANNEX should never be empty. */
212 TARGET_OBJECT_AVAILABLE_FEATURES,
213 /* Currently loaded libraries, in XML format. */
214 TARGET_OBJECT_LIBRARIES
215 /* Possible future objects: TARGET_OBJECT_FILE, TARGET_OBJECT_PROC, ... */
216 };
217
218 /* Request that OPS transfer up to LEN 8-bit bytes of the target's
219 OBJECT. The OFFSET, for a seekable object, specifies the
220 starting point. The ANNEX can be used to provide additional
221 data-specific information to the target.
222
223 Return the number of bytes actually transfered, or -1 if the
224 transfer is not supported or otherwise fails. Return of a positive
225 value less than LEN indicates that no further transfer is possible.
226 Unlike the raw to_xfer_partial interface, callers of these
227 functions do not need to retry partial transfers. */
228
229 extern LONGEST target_read (struct target_ops *ops,
230 enum target_object object,
231 const char *annex, gdb_byte *buf,
232 ULONGEST offset, LONGEST len);
233
234 extern LONGEST target_write (struct target_ops *ops,
235 enum target_object object,
236 const char *annex, const gdb_byte *buf,
237 ULONGEST offset, LONGEST len);
238
239 /* Similar to target_write, except that it also calls PROGRESS with
240 the number of bytes written and the opaque BATON after every
241 successful partial write (and before the first write). This is
242 useful for progress reporting and user interaction while writing
243 data. To abort the transfer, the progress callback can throw an
244 exception. */
245
246 LONGEST target_write_with_progress (struct target_ops *ops,
247 enum target_object object,
248 const char *annex, const gdb_byte *buf,
249 ULONGEST offset, LONGEST len,
250 void (*progress) (ULONGEST, void *),
251 void *baton);
252
253 /* Wrapper to perform a full read of unknown size. OBJECT/ANNEX will
254 be read using OPS. The return value will be -1 if the transfer
255 fails or is not supported; 0 if the object is empty; or the length
256 of the object otherwise. If a positive value is returned, a
257 sufficiently large buffer will be allocated using xmalloc and
258 returned in *BUF_P containing the contents of the object.
259
260 This method should be used for objects sufficiently small to store
261 in a single xmalloc'd buffer, when no fixed bound on the object's
262 size is known in advance. Don't try to read TARGET_OBJECT_MEMORY
263 through this function. */
264
265 extern LONGEST target_read_alloc (struct target_ops *ops,
266 enum target_object object,
267 const char *annex, gdb_byte **buf_p);
268
269 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
270 returned as a string, allocated using xmalloc. If an error occurs
271 or the transfer is unsupported, NULL is returned. Empty objects
272 are returned as allocated but empty strings. A warning is issued
273 if the result contains any embedded NUL bytes. */
274
275 extern char *target_read_stralloc (struct target_ops *ops,
276 enum target_object object,
277 const char *annex);
278
279 /* Wrappers to target read/write that perform memory transfers. They
280 throw an error if the memory transfer fails.
281
282 NOTE: cagney/2003-10-23: The naming schema is lifted from
283 "frame.h". The parameter order is lifted from get_frame_memory,
284 which in turn lifted it from read_memory. */
285
286 extern void get_target_memory (struct target_ops *ops, CORE_ADDR addr,
287 gdb_byte *buf, LONGEST len);
288 extern ULONGEST get_target_memory_unsigned (struct target_ops *ops,
289 CORE_ADDR addr, int len);
290 \f
291
292 /* If certain kinds of activity happen, target_wait should perform
293 callbacks. */
294 /* Right now we just call (*TARGET_ACTIVITY_FUNCTION) if I/O is possible
295 on TARGET_ACTIVITY_FD. */
296 extern int target_activity_fd;
297 /* Returns zero to leave the inferior alone, one to interrupt it. */
298 extern int (*target_activity_function) (void);
299 \f
300 struct thread_info; /* fwd decl for parameter list below: */
301
302 struct target_ops
303 {
304 struct target_ops *beneath; /* To the target under this one. */
305 char *to_shortname; /* Name this target type */
306 char *to_longname; /* Name for printing */
307 char *to_doc; /* Documentation. Does not include trailing
308 newline, and starts with a one-line descrip-
309 tion (probably similar to to_longname). */
310 /* Per-target scratch pad. */
311 void *to_data;
312 /* The open routine takes the rest of the parameters from the
313 command, and (if successful) pushes a new target onto the
314 stack. Targets should supply this routine, if only to provide
315 an error message. */
316 void (*to_open) (char *, int);
317 /* Old targets with a static target vector provide "to_close".
318 New re-entrant targets provide "to_xclose" and that is expected
319 to xfree everything (including the "struct target_ops"). */
320 void (*to_xclose) (struct target_ops *targ, int quitting);
321 void (*to_close) (int);
322 void (*to_attach) (char *, int);
323 void (*to_post_attach) (int);
324 void (*to_detach) (char *, int);
325 void (*to_disconnect) (struct target_ops *, char *, int);
326 void (*to_resume) (ptid_t, int, enum target_signal);
327 ptid_t (*to_wait) (ptid_t, struct target_waitstatus *);
328 void (*to_fetch_registers) (struct regcache *, int);
329 void (*to_store_registers) (struct regcache *, int);
330 void (*to_prepare_to_store) (struct regcache *);
331
332 /* Transfer LEN bytes of memory between GDB address MYADDR and
333 target address MEMADDR. If WRITE, transfer them to the target, else
334 transfer them from the target. TARGET is the target from which we
335 get this function.
336
337 Return value, N, is one of the following:
338
339 0 means that we can't handle this. If errno has been set, it is the
340 error which prevented us from doing it (FIXME: What about bfd_error?).
341
342 positive (call it N) means that we have transferred N bytes
343 starting at MEMADDR. We might be able to handle more bytes
344 beyond this length, but no promises.
345
346 negative (call its absolute value N) means that we cannot
347 transfer right at MEMADDR, but we could transfer at least
348 something at MEMADDR + N.
349
350 NOTE: cagney/2004-10-01: This has been entirely superseeded by
351 to_xfer_partial and inferior inheritance. */
352
353 int (*deprecated_xfer_memory) (CORE_ADDR memaddr, gdb_byte *myaddr,
354 int len, int write,
355 struct mem_attrib *attrib,
356 struct target_ops *target);
357
358 void (*to_files_info) (struct target_ops *);
359 int (*to_insert_breakpoint) (struct bp_target_info *);
360 int (*to_remove_breakpoint) (struct bp_target_info *);
361 int (*to_can_use_hw_breakpoint) (int, int, int);
362 int (*to_insert_hw_breakpoint) (struct bp_target_info *);
363 int (*to_remove_hw_breakpoint) (struct bp_target_info *);
364 int (*to_remove_watchpoint) (CORE_ADDR, int, int);
365 int (*to_insert_watchpoint) (CORE_ADDR, int, int);
366 int (*to_stopped_by_watchpoint) (void);
367 int to_have_steppable_watchpoint;
368 int to_have_continuable_watchpoint;
369 int (*to_stopped_data_address) (struct target_ops *, CORE_ADDR *);
370 int (*to_watchpoint_addr_within_range) (struct target_ops *,
371 CORE_ADDR, CORE_ADDR, int);
372 int (*to_region_ok_for_hw_watchpoint) (CORE_ADDR, int);
373 void (*to_terminal_init) (void);
374 void (*to_terminal_inferior) (void);
375 void (*to_terminal_ours_for_output) (void);
376 void (*to_terminal_ours) (void);
377 void (*to_terminal_save_ours) (void);
378 void (*to_terminal_info) (char *, int);
379 void (*to_kill) (void);
380 void (*to_load) (char *, int);
381 int (*to_lookup_symbol) (char *, CORE_ADDR *);
382 void (*to_create_inferior) (char *, char *, char **, int);
383 void (*to_post_startup_inferior) (ptid_t);
384 void (*to_acknowledge_created_inferior) (int);
385 void (*to_insert_fork_catchpoint) (int);
386 int (*to_remove_fork_catchpoint) (int);
387 void (*to_insert_vfork_catchpoint) (int);
388 int (*to_remove_vfork_catchpoint) (int);
389 int (*to_follow_fork) (struct target_ops *, int);
390 void (*to_insert_exec_catchpoint) (int);
391 int (*to_remove_exec_catchpoint) (int);
392 int (*to_has_exited) (int, int, int *);
393 void (*to_mourn_inferior) (void);
394 int (*to_can_run) (void);
395 void (*to_notice_signals) (ptid_t ptid);
396 int (*to_thread_alive) (ptid_t ptid);
397 void (*to_find_new_threads) (void);
398 char *(*to_pid_to_str) (ptid_t);
399 char *(*to_extra_thread_info) (struct thread_info *);
400 void (*to_stop) (void);
401 void (*to_rcmd) (char *command, struct ui_file *output);
402 char *(*to_pid_to_exec_file) (int pid);
403 void (*to_log_command) (const char *);
404 enum strata to_stratum;
405 int to_has_all_memory;
406 int to_has_memory;
407 int to_has_stack;
408 int to_has_registers;
409 int to_has_execution;
410 int to_has_thread_control; /* control thread execution */
411 struct section_table
412 *to_sections;
413 struct section_table
414 *to_sections_end;
415 /* ASYNC target controls */
416 int (*to_can_async_p) (void);
417 int (*to_is_async_p) (void);
418 void (*to_async) (void (*) (enum inferior_event_type, void *), void *);
419 int (*to_async_mask) (int);
420 int (*to_find_memory_regions) (int (*) (CORE_ADDR,
421 unsigned long,
422 int, int, int,
423 void *),
424 void *);
425 char * (*to_make_corefile_notes) (bfd *, int *);
426
427 /* Return the thread-local address at OFFSET in the
428 thread-local storage for the thread PTID and the shared library
429 or executable file given by OBJFILE. If that block of
430 thread-local storage hasn't been allocated yet, this function
431 may return an error. */
432 CORE_ADDR (*to_get_thread_local_address) (ptid_t ptid,
433 CORE_ADDR load_module_addr,
434 CORE_ADDR offset);
435
436 /* Request that OPS transfer up to LEN 8-bit bytes of the target's
437 OBJECT. The OFFSET, for a seekable object, specifies the
438 starting point. The ANNEX can be used to provide additional
439 data-specific information to the target.
440
441 Return the number of bytes actually transfered, zero when no
442 further transfer is possible, and -1 when the transfer is not
443 supported. Return of a positive value smaller than LEN does
444 not indicate the end of the object, only the end of the
445 transfer; higher level code should continue transferring if
446 desired. This is handled in target.c.
447
448 The interface does not support a "retry" mechanism. Instead it
449 assumes that at least one byte will be transfered on each
450 successful call.
451
452 NOTE: cagney/2003-10-17: The current interface can lead to
453 fragmented transfers. Lower target levels should not implement
454 hacks, such as enlarging the transfer, in an attempt to
455 compensate for this. Instead, the target stack should be
456 extended so that it implements supply/collect methods and a
457 look-aside object cache. With that available, the lowest
458 target can safely and freely "push" data up the stack.
459
460 See target_read and target_write for more information. One,
461 and only one, of readbuf or writebuf must be non-NULL. */
462
463 LONGEST (*to_xfer_partial) (struct target_ops *ops,
464 enum target_object object, const char *annex,
465 gdb_byte *readbuf, const gdb_byte *writebuf,
466 ULONGEST offset, LONGEST len);
467
468 /* Returns the memory map for the target. A return value of NULL
469 means that no memory map is available. If a memory address
470 does not fall within any returned regions, it's assumed to be
471 RAM. The returned memory regions should not overlap.
472
473 The order of regions does not matter; target_memory_map will
474 sort regions by starting address. For that reason, this
475 function should not be called directly except via
476 target_memory_map.
477
478 This method should not cache data; if the memory map could
479 change unexpectedly, it should be invalidated, and higher
480 layers will re-fetch it. */
481 VEC(mem_region_s) *(*to_memory_map) (struct target_ops *);
482
483 /* Erases the region of flash memory starting at ADDRESS, of
484 length LENGTH.
485
486 Precondition: both ADDRESS and ADDRESS+LENGTH should be aligned
487 on flash block boundaries, as reported by 'to_memory_map'. */
488 void (*to_flash_erase) (struct target_ops *,
489 ULONGEST address, LONGEST length);
490
491 /* Finishes a flash memory write sequence. After this operation
492 all flash memory should be available for writing and the result
493 of reading from areas written by 'to_flash_write' should be
494 equal to what was written. */
495 void (*to_flash_done) (struct target_ops *);
496
497 /* Describe the architecture-specific features of this target.
498 Returns the description found, or NULL if no description
499 was available. */
500 const struct target_desc *(*to_read_description) (struct target_ops *ops);
501
502 int to_magic;
503 /* Need sub-structure for target machine related rather than comm related?
504 */
505 };
506
507 /* Magic number for checking ops size. If a struct doesn't end with this
508 number, somebody changed the declaration but didn't change all the
509 places that initialize one. */
510
511 #define OPS_MAGIC 3840
512
513 /* The ops structure for our "current" target process. This should
514 never be NULL. If there is no target, it points to the dummy_target. */
515
516 extern struct target_ops current_target;
517
518 /* Define easy words for doing these operations on our current target. */
519
520 #define target_shortname (current_target.to_shortname)
521 #define target_longname (current_target.to_longname)
522
523 /* Does whatever cleanup is required for a target that we are no
524 longer going to be calling. QUITTING indicates that GDB is exiting
525 and should not get hung on an error (otherwise it is important to
526 perform clean termination, even if it takes a while). This routine
527 is automatically always called when popping the target off the
528 target stack (to_beneath is undefined). Closing file descriptors
529 and freeing all memory allocated memory are typical things it
530 should do. */
531
532 void target_close (struct target_ops *targ, int quitting);
533
534 /* Attaches to a process on the target side. Arguments are as passed
535 to the `attach' command by the user. This routine can be called
536 when the target is not on the target-stack, if the target_can_run
537 routine returns 1; in that case, it must push itself onto the stack.
538 Upon exit, the target should be ready for normal operations, and
539 should be ready to deliver the status of the process immediately
540 (without waiting) to an upcoming target_wait call. */
541
542 #define target_attach(args, from_tty) \
543 (*current_target.to_attach) (args, from_tty)
544
545 /* The target_attach operation places a process under debugger control,
546 and stops the process.
547
548 This operation provides a target-specific hook that allows the
549 necessary bookkeeping to be performed after an attach completes. */
550 #define target_post_attach(pid) \
551 (*current_target.to_post_attach) (pid)
552
553 /* Takes a program previously attached to and detaches it.
554 The program may resume execution (some targets do, some don't) and will
555 no longer stop on signals, etc. We better not have left any breakpoints
556 in the program or it'll die when it hits one. ARGS is arguments
557 typed by the user (e.g. a signal to send the process). FROM_TTY
558 says whether to be verbose or not. */
559
560 extern void target_detach (char *, int);
561
562 /* Disconnect from the current target without resuming it (leaving it
563 waiting for a debugger). */
564
565 extern void target_disconnect (char *, int);
566
567 /* Resume execution of the target process PTID. STEP says whether to
568 single-step or to run free; SIGGNAL is the signal to be given to
569 the target, or TARGET_SIGNAL_0 for no signal. The caller may not
570 pass TARGET_SIGNAL_DEFAULT. */
571
572 #define target_resume(ptid, step, siggnal) \
573 do { \
574 dcache_invalidate(target_dcache); \
575 (*current_target.to_resume) (ptid, step, siggnal); \
576 } while (0)
577
578 /* Wait for process pid to do something. PTID = -1 to wait for any
579 pid to do something. Return pid of child, or -1 in case of error;
580 store status through argument pointer STATUS. Note that it is
581 _NOT_ OK to throw_exception() out of target_wait() without popping
582 the debugging target from the stack; GDB isn't prepared to get back
583 to the prompt with a debugging target but without the frame cache,
584 stop_pc, etc., set up. */
585
586 #define target_wait(ptid, status) \
587 (*current_target.to_wait) (ptid, status)
588
589 /* Fetch at least register REGNO, or all regs if regno == -1. No result. */
590
591 #define target_fetch_registers(regcache, regno) \
592 (*current_target.to_fetch_registers) (regcache, regno)
593
594 /* Store at least register REGNO, or all regs if REGNO == -1.
595 It can store as many registers as it wants to, so target_prepare_to_store
596 must have been previously called. Calls error() if there are problems. */
597
598 #define target_store_registers(regcache, regs) \
599 (*current_target.to_store_registers) (regcache, regs)
600
601 /* Get ready to modify the registers array. On machines which store
602 individual registers, this doesn't need to do anything. On machines
603 which store all the registers in one fell swoop, this makes sure
604 that REGISTERS contains all the registers from the program being
605 debugged. */
606
607 #define target_prepare_to_store(regcache) \
608 (*current_target.to_prepare_to_store) (regcache)
609
610 extern DCACHE *target_dcache;
611
612 extern int target_read_string (CORE_ADDR, char **, int, int *);
613
614 extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len);
615
616 extern int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
617 int len);
618
619 extern int xfer_memory (CORE_ADDR, gdb_byte *, int, int,
620 struct mem_attrib *, struct target_ops *);
621
622 /* Fetches the target's memory map. If one is found it is sorted
623 and returned, after some consistency checking. Otherwise, NULL
624 is returned. */
625 VEC(mem_region_s) *target_memory_map (void);
626
627 /* Erase the specified flash region. */
628 void target_flash_erase (ULONGEST address, LONGEST length);
629
630 /* Finish a sequence of flash operations. */
631 void target_flash_done (void);
632
633 /* Describes a request for a memory write operation. */
634 struct memory_write_request
635 {
636 /* Begining address that must be written. */
637 ULONGEST begin;
638 /* Past-the-end address. */
639 ULONGEST end;
640 /* The data to write. */
641 gdb_byte *data;
642 /* A callback baton for progress reporting for this request. */
643 void *baton;
644 };
645 typedef struct memory_write_request memory_write_request_s;
646 DEF_VEC_O(memory_write_request_s);
647
648 /* Enumeration specifying different flash preservation behaviour. */
649 enum flash_preserve_mode
650 {
651 flash_preserve,
652 flash_discard
653 };
654
655 /* Write several memory blocks at once. This version can be more
656 efficient than making several calls to target_write_memory, in
657 particular because it can optimize accesses to flash memory.
658
659 Moreover, this is currently the only memory access function in gdb
660 that supports writing to flash memory, and it should be used for
661 all cases where access to flash memory is desirable.
662
663 REQUESTS is the vector (see vec.h) of memory_write_request.
664 PRESERVE_FLASH_P indicates what to do with blocks which must be
665 erased, but not completely rewritten.
666 PROGRESS_CB is a function that will be periodically called to provide
667 feedback to user. It will be called with the baton corresponding
668 to the request currently being written. It may also be called
669 with a NULL baton, when preserved flash sectors are being rewritten.
670
671 The function returns 0 on success, and error otherwise. */
672 int target_write_memory_blocks (VEC(memory_write_request_s) *requests,
673 enum flash_preserve_mode preserve_flash_p,
674 void (*progress_cb) (ULONGEST, void *));
675
676 /* From infrun.c. */
677
678 extern int inferior_has_forked (int pid, int *child_pid);
679
680 extern int inferior_has_vforked (int pid, int *child_pid);
681
682 extern int inferior_has_execd (int pid, char **execd_pathname);
683
684 /* From exec.c */
685
686 extern void print_section_info (struct target_ops *, bfd *);
687
688 /* Print a line about the current target. */
689
690 #define target_files_info() \
691 (*current_target.to_files_info) (&current_target)
692
693 /* Insert a breakpoint at address BP_TGT->placed_address in the target
694 machine. Result is 0 for success, or an errno value. */
695
696 #define target_insert_breakpoint(bp_tgt) \
697 (*current_target.to_insert_breakpoint) (bp_tgt)
698
699 /* Remove a breakpoint at address BP_TGT->placed_address in the target
700 machine. Result is 0 for success, or an errno value. */
701
702 #define target_remove_breakpoint(bp_tgt) \
703 (*current_target.to_remove_breakpoint) (bp_tgt)
704
705 /* Initialize the terminal settings we record for the inferior,
706 before we actually run the inferior. */
707
708 #define target_terminal_init() \
709 (*current_target.to_terminal_init) ()
710
711 /* Put the inferior's terminal settings into effect.
712 This is preparation for starting or resuming the inferior. */
713
714 #define target_terminal_inferior() \
715 (*current_target.to_terminal_inferior) ()
716
717 /* Put some of our terminal settings into effect,
718 enough to get proper results from our output,
719 but do not change into or out of RAW mode
720 so that no input is discarded.
721
722 After doing this, either terminal_ours or terminal_inferior
723 should be called to get back to a normal state of affairs. */
724
725 #define target_terminal_ours_for_output() \
726 (*current_target.to_terminal_ours_for_output) ()
727
728 /* Put our terminal settings into effect.
729 First record the inferior's terminal settings
730 so they can be restored properly later. */
731
732 #define target_terminal_ours() \
733 (*current_target.to_terminal_ours) ()
734
735 /* Save our terminal settings.
736 This is called from TUI after entering or leaving the curses
737 mode. Since curses modifies our terminal this call is here
738 to take this change into account. */
739
740 #define target_terminal_save_ours() \
741 (*current_target.to_terminal_save_ours) ()
742
743 /* Print useful information about our terminal status, if such a thing
744 exists. */
745
746 #define target_terminal_info(arg, from_tty) \
747 (*current_target.to_terminal_info) (arg, from_tty)
748
749 /* Kill the inferior process. Make it go away. */
750
751 #define target_kill() \
752 (*current_target.to_kill) ()
753
754 /* Load an executable file into the target process. This is expected
755 to not only bring new code into the target process, but also to
756 update GDB's symbol tables to match.
757
758 ARG contains command-line arguments, to be broken down with
759 buildargv (). The first non-switch argument is the filename to
760 load, FILE; the second is a number (as parsed by strtoul (..., ...,
761 0)), which is an offset to apply to the load addresses of FILE's
762 sections. The target may define switches, or other non-switch
763 arguments, as it pleases. */
764
765 extern void target_load (char *arg, int from_tty);
766
767 /* Look up a symbol in the target's symbol table. NAME is the symbol
768 name. ADDRP is a CORE_ADDR * pointing to where the value of the
769 symbol should be returned. The result is 0 if successful, nonzero
770 if the symbol does not exist in the target environment. This
771 function should not call error() if communication with the target
772 is interrupted, since it is called from symbol reading, but should
773 return nonzero, possibly doing a complain(). */
774
775 #define target_lookup_symbol(name, addrp) \
776 (*current_target.to_lookup_symbol) (name, addrp)
777
778 /* Start an inferior process and set inferior_ptid to its pid.
779 EXEC_FILE is the file to run.
780 ALLARGS is a string containing the arguments to the program.
781 ENV is the environment vector to pass. Errors reported with error().
782 On VxWorks and various standalone systems, we ignore exec_file. */
783
784 #define target_create_inferior(exec_file, args, env, FROM_TTY) \
785 (*current_target.to_create_inferior) (exec_file, args, env, (FROM_TTY))
786
787
788 /* Some targets (such as ttrace-based HPUX) don't allow us to request
789 notification of inferior events such as fork and vork immediately
790 after the inferior is created. (This because of how gdb gets an
791 inferior created via invoking a shell to do it. In such a scenario,
792 if the shell init file has commands in it, the shell will fork and
793 exec for each of those commands, and we will see each such fork
794 event. Very bad.)
795
796 Such targets will supply an appropriate definition for this function. */
797
798 #define target_post_startup_inferior(ptid) \
799 (*current_target.to_post_startup_inferior) (ptid)
800
801 /* On some targets, the sequence of starting up an inferior requires
802 some synchronization between gdb and the new inferior process, PID. */
803
804 #define target_acknowledge_created_inferior(pid) \
805 (*current_target.to_acknowledge_created_inferior) (pid)
806
807 /* On some targets, we can catch an inferior fork or vfork event when
808 it occurs. These functions insert/remove an already-created
809 catchpoint for such events. */
810
811 #define target_insert_fork_catchpoint(pid) \
812 (*current_target.to_insert_fork_catchpoint) (pid)
813
814 #define target_remove_fork_catchpoint(pid) \
815 (*current_target.to_remove_fork_catchpoint) (pid)
816
817 #define target_insert_vfork_catchpoint(pid) \
818 (*current_target.to_insert_vfork_catchpoint) (pid)
819
820 #define target_remove_vfork_catchpoint(pid) \
821 (*current_target.to_remove_vfork_catchpoint) (pid)
822
823 /* If the inferior forks or vforks, this function will be called at
824 the next resume in order to perform any bookkeeping and fiddling
825 necessary to continue debugging either the parent or child, as
826 requested, and releasing the other. Information about the fork
827 or vfork event is available via get_last_target_status ().
828 This function returns 1 if the inferior should not be resumed
829 (i.e. there is another event pending). */
830
831 int target_follow_fork (int follow_child);
832
833 /* On some targets, we can catch an inferior exec event when it
834 occurs. These functions insert/remove an already-created
835 catchpoint for such events. */
836
837 #define target_insert_exec_catchpoint(pid) \
838 (*current_target.to_insert_exec_catchpoint) (pid)
839
840 #define target_remove_exec_catchpoint(pid) \
841 (*current_target.to_remove_exec_catchpoint) (pid)
842
843 /* Returns TRUE if PID has exited. And, also sets EXIT_STATUS to the
844 exit code of PID, if any. */
845
846 #define target_has_exited(pid,wait_status,exit_status) \
847 (*current_target.to_has_exited) (pid,wait_status,exit_status)
848
849 /* The debugger has completed a blocking wait() call. There is now
850 some process event that must be processed. This function should
851 be defined by those targets that require the debugger to perform
852 cleanup or internal state changes in response to the process event. */
853
854 /* The inferior process has died. Do what is right. */
855
856 #define target_mourn_inferior() \
857 (*current_target.to_mourn_inferior) ()
858
859 /* Does target have enough data to do a run or attach command? */
860
861 #define target_can_run(t) \
862 ((t)->to_can_run) ()
863
864 /* post process changes to signal handling in the inferior. */
865
866 #define target_notice_signals(ptid) \
867 (*current_target.to_notice_signals) (ptid)
868
869 /* Check to see if a thread is still alive. */
870
871 #define target_thread_alive(ptid) \
872 (*current_target.to_thread_alive) (ptid)
873
874 /* Query for new threads and add them to the thread list. */
875
876 #define target_find_new_threads() \
877 (*current_target.to_find_new_threads) ()
878
879 /* Make target stop in a continuable fashion. (For instance, under
880 Unix, this should act like SIGSTOP). This function is normally
881 used by GUIs to implement a stop button. */
882
883 #define target_stop current_target.to_stop
884
885 /* Send the specified COMMAND to the target's monitor
886 (shell,interpreter) for execution. The result of the query is
887 placed in OUTBUF. */
888
889 #define target_rcmd(command, outbuf) \
890 (*current_target.to_rcmd) (command, outbuf)
891
892
893 /* Does the target include all of memory, or only part of it? This
894 determines whether we look up the target chain for other parts of
895 memory if this target can't satisfy a request. */
896
897 #define target_has_all_memory \
898 (current_target.to_has_all_memory)
899
900 /* Does the target include memory? (Dummy targets don't.) */
901
902 #define target_has_memory \
903 (current_target.to_has_memory)
904
905 /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
906 we start a process.) */
907
908 #define target_has_stack \
909 (current_target.to_has_stack)
910
911 /* Does the target have registers? (Exec files don't.) */
912
913 #define target_has_registers \
914 (current_target.to_has_registers)
915
916 /* Does the target have execution? Can we make it jump (through
917 hoops), or pop its stack a few times? This means that the current
918 target is currently executing; for some targets, that's the same as
919 whether or not the target is capable of execution, but there are
920 also targets which can be current while not executing. In that
921 case this will become true after target_create_inferior or
922 target_attach. */
923
924 #define target_has_execution \
925 (current_target.to_has_execution)
926
927 /* Can the target support the debugger control of thread execution?
928 a) Can it lock the thread scheduler?
929 b) Can it switch the currently running thread? */
930
931 #define target_can_lock_scheduler \
932 (current_target.to_has_thread_control & tc_schedlock)
933
934 #define target_can_switch_threads \
935 (current_target.to_has_thread_control & tc_switch)
936
937 /* Can the target support asynchronous execution? */
938 #define target_can_async_p() (current_target.to_can_async_p ())
939
940 /* Is the target in asynchronous execution mode? */
941 #define target_is_async_p() (current_target.to_is_async_p ())
942
943 /* Put the target in async mode with the specified callback function. */
944 #define target_async(CALLBACK,CONTEXT) \
945 (current_target.to_async ((CALLBACK), (CONTEXT)))
946
947 /* This is to be used ONLY within call_function_by_hand(). It provides
948 a workaround, to have inferior function calls done in sychronous
949 mode, even though the target is asynchronous. After
950 target_async_mask(0) is called, calls to target_can_async_p() will
951 return FALSE , so that target_resume() will not try to start the
952 target asynchronously. After the inferior stops, we IMMEDIATELY
953 restore the previous nature of the target, by calling
954 target_async_mask(1). After that, target_can_async_p() will return
955 TRUE. ANY OTHER USE OF THIS FEATURE IS DEPRECATED.
956
957 FIXME ezannoni 1999-12-13: we won't need this once we move
958 the turning async on and off to the single execution commands,
959 from where it is done currently, in remote_resume(). */
960
961 #define target_async_mask(MASK) \
962 (current_target.to_async_mask (MASK))
963
964 /* Converts a process id to a string. Usually, the string just contains
965 `process xyz', but on some systems it may contain
966 `process xyz thread abc'. */
967
968 #undef target_pid_to_str
969 #define target_pid_to_str(PID) current_target.to_pid_to_str (PID)
970
971 #ifndef target_tid_to_str
972 #define target_tid_to_str(PID) \
973 target_pid_to_str (PID)
974 extern char *normal_pid_to_str (ptid_t ptid);
975 #endif
976
977 /* Return a short string describing extra information about PID,
978 e.g. "sleeping", "runnable", "running on LWP 3". Null return value
979 is okay. */
980
981 #define target_extra_thread_info(TP) \
982 (current_target.to_extra_thread_info (TP))
983
984 /* Attempts to find the pathname of the executable file
985 that was run to create a specified process.
986
987 The process PID must be stopped when this operation is used.
988
989 If the executable file cannot be determined, NULL is returned.
990
991 Else, a pointer to a character string containing the pathname
992 is returned. This string should be copied into a buffer by
993 the client if the string will not be immediately used, or if
994 it must persist. */
995
996 #define target_pid_to_exec_file(pid) \
997 (current_target.to_pid_to_exec_file) (pid)
998
999 /*
1000 * Iterator function for target memory regions.
1001 * Calls a callback function once for each memory region 'mapped'
1002 * in the child process. Defined as a simple macro rather than
1003 * as a function macro so that it can be tested for nullity.
1004 */
1005
1006 #define target_find_memory_regions(FUNC, DATA) \
1007 (current_target.to_find_memory_regions) (FUNC, DATA)
1008
1009 /*
1010 * Compose corefile .note section.
1011 */
1012
1013 #define target_make_corefile_notes(BFD, SIZE_P) \
1014 (current_target.to_make_corefile_notes) (BFD, SIZE_P)
1015
1016 /* Thread-local values. */
1017 #define target_get_thread_local_address \
1018 (current_target.to_get_thread_local_address)
1019 #define target_get_thread_local_address_p() \
1020 (target_get_thread_local_address != NULL)
1021
1022
1023 /* Hardware watchpoint interfaces. */
1024
1025 /* Returns non-zero if we were stopped by a hardware watchpoint (memory read or
1026 write). */
1027
1028 #ifndef STOPPED_BY_WATCHPOINT
1029 #define STOPPED_BY_WATCHPOINT(w) \
1030 (*current_target.to_stopped_by_watchpoint) ()
1031 #endif
1032
1033 /* Non-zero if we have steppable watchpoints */
1034
1035 #ifndef HAVE_STEPPABLE_WATCHPOINT
1036 #define HAVE_STEPPABLE_WATCHPOINT \
1037 (current_target.to_have_steppable_watchpoint)
1038 #endif
1039
1040 /* Non-zero if we have continuable watchpoints */
1041
1042 #ifndef HAVE_CONTINUABLE_WATCHPOINT
1043 #define HAVE_CONTINUABLE_WATCHPOINT \
1044 (current_target.to_have_continuable_watchpoint)
1045 #endif
1046
1047 /* Provide defaults for hardware watchpoint functions. */
1048
1049 /* If the *_hw_beakpoint functions have not been defined
1050 elsewhere use the definitions in the target vector. */
1051
1052 /* Returns non-zero if we can set a hardware watchpoint of type TYPE. TYPE is
1053 one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint, or
1054 bp_hardware_breakpoint. CNT is the number of such watchpoints used so far
1055 (including this one?). OTHERTYPE is who knows what... */
1056
1057 #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT
1058 #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) \
1059 (*current_target.to_can_use_hw_breakpoint) (TYPE, CNT, OTHERTYPE);
1060 #endif
1061
1062 #ifndef TARGET_REGION_OK_FOR_HW_WATCHPOINT
1063 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(addr, len) \
1064 (*current_target.to_region_ok_for_hw_watchpoint) (addr, len)
1065 #endif
1066
1067
1068 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes. TYPE is 0
1069 for write, 1 for read, and 2 for read/write accesses. Returns 0 for
1070 success, non-zero for failure. */
1071
1072 #ifndef target_insert_watchpoint
1073 #define target_insert_watchpoint(addr, len, type) \
1074 (*current_target.to_insert_watchpoint) (addr, len, type)
1075
1076 #define target_remove_watchpoint(addr, len, type) \
1077 (*current_target.to_remove_watchpoint) (addr, len, type)
1078 #endif
1079
1080 #ifndef target_insert_hw_breakpoint
1081 #define target_insert_hw_breakpoint(bp_tgt) \
1082 (*current_target.to_insert_hw_breakpoint) (bp_tgt)
1083
1084 #define target_remove_hw_breakpoint(bp_tgt) \
1085 (*current_target.to_remove_hw_breakpoint) (bp_tgt)
1086 #endif
1087
1088 extern int target_stopped_data_address_p (struct target_ops *);
1089
1090 #ifndef target_stopped_data_address
1091 #define target_stopped_data_address(target, x) \
1092 (*target.to_stopped_data_address) (target, x)
1093 #else
1094 /* Horrible hack to get around existing macros :-(. */
1095 #define target_stopped_data_address_p(CURRENT_TARGET) (1)
1096 #endif
1097
1098 #define target_watchpoint_addr_within_range(target, addr, start, length) \
1099 (*target.to_watchpoint_addr_within_range) (target, addr, start, length)
1100
1101 extern const struct target_desc *target_read_description (struct target_ops *);
1102
1103 /* Command logging facility. */
1104
1105 #define target_log_command(p) \
1106 do \
1107 if (current_target.to_log_command) \
1108 (*current_target.to_log_command) (p); \
1109 while (0)
1110
1111 /* Routines for maintenance of the target structures...
1112
1113 add_target: Add a target to the list of all possible targets.
1114
1115 push_target: Make this target the top of the stack of currently used
1116 targets, within its particular stratum of the stack. Result
1117 is 0 if now atop the stack, nonzero if not on top (maybe
1118 should warn user).
1119
1120 unpush_target: Remove this from the stack of currently used targets,
1121 no matter where it is on the list. Returns 0 if no
1122 change, 1 if removed from stack.
1123
1124 pop_target: Remove the top thing on the stack of current targets. */
1125
1126 extern void add_target (struct target_ops *);
1127
1128 extern int push_target (struct target_ops *);
1129
1130 extern int unpush_target (struct target_ops *);
1131
1132 extern void target_pre_inferior (int);
1133
1134 extern void target_preopen (int);
1135
1136 extern void pop_target (void);
1137
1138 extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
1139 CORE_ADDR offset);
1140
1141 /* Mark a pushed target as running or exited, for targets which do not
1142 automatically pop when not active. */
1143
1144 void target_mark_running (struct target_ops *);
1145
1146 void target_mark_exited (struct target_ops *);
1147
1148 /* Struct section_table maps address ranges to file sections. It is
1149 mostly used with BFD files, but can be used without (e.g. for handling
1150 raw disks, or files not in formats handled by BFD). */
1151
1152 struct section_table
1153 {
1154 CORE_ADDR addr; /* Lowest address in section */
1155 CORE_ADDR endaddr; /* 1+highest address in section */
1156
1157 struct bfd_section *the_bfd_section;
1158
1159 bfd *bfd; /* BFD file pointer */
1160 };
1161
1162 /* Return the "section" containing the specified address. */
1163 struct section_table *target_section_by_addr (struct target_ops *target,
1164 CORE_ADDR addr);
1165
1166
1167 /* From mem-break.c */
1168
1169 extern int memory_remove_breakpoint (struct bp_target_info *);
1170
1171 extern int memory_insert_breakpoint (struct bp_target_info *);
1172
1173 extern int default_memory_remove_breakpoint (struct gdbarch *, struct bp_target_info *);
1174
1175 extern int default_memory_insert_breakpoint (struct gdbarch *, struct bp_target_info *);
1176
1177
1178 /* From target.c */
1179
1180 extern void initialize_targets (void);
1181
1182 extern void noprocess (void);
1183
1184 extern void target_require_runnable (void);
1185
1186 extern void find_default_attach (char *, int);
1187
1188 extern void find_default_create_inferior (char *, char *, char **, int);
1189
1190 extern struct target_ops *find_run_target (void);
1191
1192 extern struct target_ops *find_core_target (void);
1193
1194 extern struct target_ops *find_target_beneath (struct target_ops *);
1195
1196 extern int target_resize_to_sections (struct target_ops *target,
1197 int num_added);
1198
1199 extern void remove_target_sections (bfd *abfd);
1200
1201 \f
1202 /* Stuff that should be shared among the various remote targets. */
1203
1204 /* Debugging level. 0 is off, and non-zero values mean to print some debug
1205 information (higher values, more information). */
1206 extern int remote_debug;
1207
1208 /* Speed in bits per second, or -1 which means don't mess with the speed. */
1209 extern int baud_rate;
1210 /* Timeout limit for response from target. */
1211 extern int remote_timeout;
1212
1213 \f
1214 /* Functions for helping to write a native target. */
1215
1216 /* This is for native targets which use a unix/POSIX-style waitstatus. */
1217 extern void store_waitstatus (struct target_waitstatus *, int);
1218
1219 /* Predicate to target_signal_to_host(). Return non-zero if the enum
1220 targ_signal SIGNO has an equivalent ``host'' representation. */
1221 /* FIXME: cagney/1999-11-22: The name below was chosen in preference
1222 to the shorter target_signal_p() because it is far less ambigious.
1223 In this context ``target_signal'' refers to GDB's internal
1224 representation of the target's set of signals while ``host signal''
1225 refers to the target operating system's signal. Confused? */
1226
1227 extern int target_signal_to_host_p (enum target_signal signo);
1228
1229 /* Convert between host signal numbers and enum target_signal's.
1230 target_signal_to_host() returns 0 and prints a warning() on GDB's
1231 console if SIGNO has no equivalent host representation. */
1232 /* FIXME: cagney/1999-11-22: Here ``host'' is used incorrectly, it is
1233 refering to the target operating system's signal numbering.
1234 Similarly, ``enum target_signal'' is named incorrectly, ``enum
1235 gdb_signal'' would probably be better as it is refering to GDB's
1236 internal representation of a target operating system's signal. */
1237
1238 extern enum target_signal target_signal_from_host (int);
1239 extern int target_signal_to_host (enum target_signal);
1240
1241 extern enum target_signal default_target_signal_from_host (struct gdbarch *,
1242 int);
1243 extern int default_target_signal_to_host (struct gdbarch *,
1244 enum target_signal);
1245
1246 /* Convert from a number used in a GDB command to an enum target_signal. */
1247 extern enum target_signal target_signal_from_command (int);
1248
1249 /* Any target can call this to switch to remote protocol (in remote.c). */
1250 extern void push_remote_target (char *name, int from_tty);
1251
1252 /* Set the show memory breakpoints mode to show, and installs a cleanup
1253 to restore it back to the current value. */
1254 extern struct cleanup *make_show_memory_breakpoints_cleanup (int show);
1255
1256 \f
1257 /* Imported from machine dependent code */
1258
1259 /* Blank target vector entries are initialized to target_ignore. */
1260 void target_ignore (void);
1261
1262 extern struct target_ops deprecated_child_ops;
1263
1264 #endif /* !defined (TARGET_H) */