Changes from the FSF for Hurd thread support.
[external/binutils.git] / gdb / target.h
1 /* Interface between GDB and target environments, including files and processes
2    Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3    Contributed by Cygnus Support.  Written by John Gilmore.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #if !defined (TARGET_H)
22 #define TARGET_H
23
24 /* This include file defines the interface between the main part
25    of the debugger, and the part which is target-specific, or
26    specific to the communications interface between us and the
27    target.
28
29    A TARGET is an interface between the debugger and a particular 
30    kind of file or process.  Targets can be STACKED in STRATA, 
31    so that more than one target can potentially respond to a request.
32    In particular, memory accesses will walk down the stack of targets
33    until they find a target that is interested in handling that particular
34    address.  STRATA are artificial boundaries on the stack, within
35    which particular kinds of targets live.  Strata exist so that
36    people don't get confused by pushing e.g. a process target and then
37    a file target, and wondering why they can't see the current values
38    of variables any more (the file target is handling them and they
39    never get to the process target).  So when you push a file target,
40    it goes into the file stratum, which is always below the process
41    stratum.  */
42
43 #include "bfd.h"
44
45 enum strata {
46         dummy_stratum,          /* The lowest of the low */
47         file_stratum,           /* Executable files, etc */
48         core_stratum,           /* Core dump files */
49         download_stratum,       /* Downloading of remote targets */
50         process_stratum         /* Executing processes */
51 };
52
53 /* Stuff for target_wait.  */
54
55 /* Generally, what has the program done?  */
56 enum target_waitkind {
57   /* The program has exited.  The exit status is in value.integer.  */
58   TARGET_WAITKIND_EXITED,
59
60   /* The program has stopped with a signal.  Which signal is in value.sig.  */
61   TARGET_WAITKIND_STOPPED,
62
63   /* The program has terminated with a signal.  Which signal is in
64      value.sig.  */
65   TARGET_WAITKIND_SIGNALLED,
66
67   /* The program is letting us know that it dynamically loaded something
68      (e.g. it called load(2) on AIX).  */
69   TARGET_WAITKIND_LOADED,
70
71   /* Nothing happened, but we stopped anyway.  This perhaps should be handled
72      within target_wait, but I'm not sure target_wait should be resuming the
73      inferior.  */
74   TARGET_WAITKIND_SPURIOUS
75   };
76
77 /* The numbering of these signals is chosen to match traditional unix
78    signals (insofar as various unices use the same numbers, anyway).
79    It is also the numbering of the GDB remote protocol.  Other remote
80    protocols, if they use a different numbering, should make sure to
81    translate appropriately.  */
82
83 /* This is based strongly on Unix/POSIX signals for several reasons:
84    (1) This set of signals represents a widely-accepted attempt to
85    represent events of this sort in a portable fashion, (2) we want a
86    signal to make it from wait to child_wait to the user intact, (3) many
87    remote protocols use a similar encoding.  However, it is
88    recognized that this set of signals has limitations (such as not
89    distinguishing between various kinds of SIGSEGV, or not
90    distinguishing hitting a breakpoint from finishing a single step).
91    So in the future we may get around this either by adding additional
92    signals for breakpoint, single-step, etc., or by adding signal
93    codes; the latter seems more in the spirit of what BSD, System V,
94    etc. are doing to address these issues.  */
95
96 /* For an explanation of what each signal means, see
97    target_signal_to_string.  */
98
99 enum target_signal {
100   /* Used some places (e.g. stop_signal) to record the concept that
101      there is no signal.  */
102   TARGET_SIGNAL_0 = 0,
103   TARGET_SIGNAL_FIRST = 0,
104   TARGET_SIGNAL_HUP = 1,
105   TARGET_SIGNAL_INT = 2,
106   TARGET_SIGNAL_QUIT = 3,
107   TARGET_SIGNAL_ILL = 4,
108   TARGET_SIGNAL_TRAP = 5,
109   TARGET_SIGNAL_ABRT = 6,
110   TARGET_SIGNAL_EMT = 7,
111   TARGET_SIGNAL_FPE = 8,
112   TARGET_SIGNAL_KILL = 9,
113   TARGET_SIGNAL_BUS = 10,
114   TARGET_SIGNAL_SEGV = 11,
115   TARGET_SIGNAL_SYS = 12,
116   TARGET_SIGNAL_PIPE = 13,
117   TARGET_SIGNAL_ALRM = 14,
118   TARGET_SIGNAL_TERM = 15,
119   TARGET_SIGNAL_URG = 16,
120   TARGET_SIGNAL_STOP = 17,
121   TARGET_SIGNAL_TSTP = 18,
122   TARGET_SIGNAL_CONT = 19,
123   TARGET_SIGNAL_CHLD = 20,
124   TARGET_SIGNAL_TTIN = 21,
125   TARGET_SIGNAL_TTOU = 22,
126   TARGET_SIGNAL_IO = 23,
127   TARGET_SIGNAL_XCPU = 24,
128   TARGET_SIGNAL_XFSZ = 25,
129   TARGET_SIGNAL_VTALRM = 26,
130   TARGET_SIGNAL_PROF = 27,
131   TARGET_SIGNAL_WINCH = 28,
132   TARGET_SIGNAL_LOST = 29,
133   TARGET_SIGNAL_USR1 = 30,
134   TARGET_SIGNAL_USR2 = 31,
135   TARGET_SIGNAL_PWR = 32,
136   /* Similar to SIGIO.  Perhaps they should have the same number.  */
137   TARGET_SIGNAL_POLL = 33,
138   TARGET_SIGNAL_WIND = 34,
139   TARGET_SIGNAL_PHONE = 35,
140   TARGET_SIGNAL_WAITING = 36,
141   TARGET_SIGNAL_LWP = 37,
142   TARGET_SIGNAL_DANGER = 38,
143   TARGET_SIGNAL_GRANT = 39,
144   TARGET_SIGNAL_RETRACT = 40,
145   TARGET_SIGNAL_MSG = 41,
146   TARGET_SIGNAL_SOUND = 42,
147   TARGET_SIGNAL_SAK = 43,
148   TARGET_SIGNAL_PRIO = 44,
149   TARGET_SIGNAL_REALTIME_33 = 45,
150   TARGET_SIGNAL_REALTIME_34 = 46,
151   TARGET_SIGNAL_REALTIME_35 = 47,
152   TARGET_SIGNAL_REALTIME_36 = 48,
153   TARGET_SIGNAL_REALTIME_37 = 49,
154   TARGET_SIGNAL_REALTIME_38 = 50,
155   TARGET_SIGNAL_REALTIME_39 = 51,
156   TARGET_SIGNAL_REALTIME_40 = 52,
157   TARGET_SIGNAL_REALTIME_41 = 53,
158   TARGET_SIGNAL_REALTIME_42 = 54,
159   TARGET_SIGNAL_REALTIME_43 = 55,
160   TARGET_SIGNAL_REALTIME_44 = 56,
161   TARGET_SIGNAL_REALTIME_45 = 57,
162   TARGET_SIGNAL_REALTIME_46 = 58,
163   TARGET_SIGNAL_REALTIME_47 = 59,
164   TARGET_SIGNAL_REALTIME_48 = 60,
165   TARGET_SIGNAL_REALTIME_49 = 61,
166   TARGET_SIGNAL_REALTIME_50 = 62,
167   TARGET_SIGNAL_REALTIME_51 = 63,
168   TARGET_SIGNAL_REALTIME_52 = 64,
169   TARGET_SIGNAL_REALTIME_53 = 65,
170   TARGET_SIGNAL_REALTIME_54 = 66,
171   TARGET_SIGNAL_REALTIME_55 = 67,
172   TARGET_SIGNAL_REALTIME_56 = 68,
173   TARGET_SIGNAL_REALTIME_57 = 69,
174   TARGET_SIGNAL_REALTIME_58 = 70,
175   TARGET_SIGNAL_REALTIME_59 = 71,
176   TARGET_SIGNAL_REALTIME_60 = 72,
177   TARGET_SIGNAL_REALTIME_61 = 73,
178   TARGET_SIGNAL_REALTIME_62 = 74,
179   TARGET_SIGNAL_REALTIME_63 = 75,
180
181   /* Mach exceptions */
182   TARGET_EXC_BAD_ACCESS = 76,
183   TARGET_EXC_BAD_INSTRUCTION = 77,
184   TARGET_EXC_ARITHMETIC = 78,
185   TARGET_EXC_EMULATION = 79,
186   TARGET_EXC_SOFTWARE = 80,
187   TARGET_EXC_BREAKPOINT = 81,
188
189   /* Some signal we don't know about.  */
190   TARGET_SIGNAL_UNKNOWN,
191
192   /* Use whatever signal we use when one is not specifically specified
193      (for passing to proceed and so on).  */
194   TARGET_SIGNAL_DEFAULT,
195
196   /* Last and unused enum value, for sizing arrays, etc.  */
197   TARGET_SIGNAL_LAST
198 };
199
200 struct target_waitstatus {
201   enum target_waitkind kind;
202
203   /* Exit status or signal number.  */
204   union {
205     int integer;
206     enum target_signal sig;
207   } value;
208 };
209
210 /* Return the string for a signal.  */
211 extern char *target_signal_to_string PARAMS ((enum target_signal));
212
213 /* Return the name (SIGHUP, etc.) for a signal.  */
214 extern char *target_signal_to_name PARAMS ((enum target_signal));
215
216 /* Given a name (SIGHUP, etc.), return its signal.  */
217 enum target_signal target_signal_from_name PARAMS ((char *));
218 \f
219 /* If certain kinds of activity happen, target_wait should perform
220    callbacks.  */
221 /* Right now we just call (*TARGET_ACTIVITY_FUNCTION) if I/O is possible
222    on TARGET_ACTIVITY_FD.   */
223 extern int target_activity_fd;
224 /* Returns zero to leave the inferior alone, one to interrupt it.  */
225 extern int (*target_activity_function) PARAMS ((void));
226 \f
227 struct target_ops
228 {
229   char         *to_shortname;   /* Name this target type */
230   char         *to_longname;    /* Name for printing */
231   char         *to_doc;         /* Documentation.  Does not include trailing
232                                    newline, and starts with a one-line descrip-
233                                    tion (probably similar to to_longname). */
234   void        (*to_open) PARAMS ((char *, int));
235   void        (*to_close) PARAMS ((int));
236   void        (*to_attach) PARAMS ((char *, int));
237   void        (*to_detach) PARAMS ((char *, int));
238   void        (*to_resume) PARAMS ((int, int, enum target_signal));
239   int         (*to_wait) PARAMS ((int, struct target_waitstatus *));
240   void        (*to_fetch_registers) PARAMS ((int));
241   void        (*to_store_registers) PARAMS ((int));
242   void        (*to_prepare_to_store) PARAMS ((void));
243
244   /* Transfer LEN bytes of memory between GDB address MYADDR and
245      target address MEMADDR.  If WRITE, transfer them to the target, else
246      transfer them from the target.  TARGET is the target from which we
247      get this function.
248
249      Return value, N, is one of the following:
250
251      0 means that we can't handle this.  If errno has been set, it is the
252      error which prevented us from doing it (FIXME: What about bfd_error?).
253
254      positive (call it N) means that we have transferred N bytes
255      starting at MEMADDR.  We might be able to handle more bytes
256      beyond this length, but no promises.
257
258      negative (call its absolute value N) means that we cannot
259      transfer right at MEMADDR, but we could transfer at least
260      something at MEMADDR + N.  */
261
262   int         (*to_xfer_memory) PARAMS ((CORE_ADDR memaddr, char *myaddr,
263                                          int len, int write,
264                                          struct target_ops * target));
265
266 #if 0
267   /* Enable this after 4.12.  */
268
269   /* Search target memory.  Start at STARTADDR and take LEN bytes of
270      target memory, and them with MASK, and compare to DATA.  If they
271      match, set *ADDR_FOUND to the address we found it at, store the data
272      we found at LEN bytes starting at DATA_FOUND, and return.  If
273      not, add INCREMENT to the search address and keep trying until
274      the search address is outside of the range [LORANGE,HIRANGE).
275
276      If we don't find anything, set *ADDR_FOUND to (CORE_ADDR)0 and return.  */
277   void (*to_search) PARAMS ((int len, char *data, char *mask,
278                              CORE_ADDR startaddr, int increment,
279                              CORE_ADDR lorange, CORE_ADDR hirange,
280                              CORE_ADDR *addr_found, char *data_found));
281
282 #define target_search(len, data, mask, startaddr, increment, lorange, hirange, addr_found, data_found)  \
283   (*current_target.to_search) (len, data, mask, startaddr, increment, \
284                                 lorange, hirange, addr_found, data_found)
285 #endif /* 0 */
286
287   void        (*to_files_info) PARAMS ((struct target_ops *));
288   int         (*to_insert_breakpoint) PARAMS ((CORE_ADDR, char *));
289   int         (*to_remove_breakpoint) PARAMS ((CORE_ADDR, char *));
290   void        (*to_terminal_init) PARAMS ((void));
291   void        (*to_terminal_inferior) PARAMS ((void));
292   void        (*to_terminal_ours_for_output) PARAMS ((void));
293   void        (*to_terminal_ours) PARAMS ((void));
294   void        (*to_terminal_info) PARAMS ((char *, int));
295   void        (*to_kill) PARAMS ((void));
296   void        (*to_load) PARAMS ((char *, int));
297   int         (*to_lookup_symbol) PARAMS ((char *, CORE_ADDR *));
298   void        (*to_create_inferior) PARAMS ((char *, char *, char **));
299   void        (*to_mourn_inferior) PARAMS ((void));
300   int         (*to_can_run) PARAMS ((void));
301   void        (*to_notice_signals) PARAMS ((int pid));
302   int         (*to_thread_alive) PARAMS ((int pid));
303   void        (*to_stop) PARAMS ((void));
304   enum strata   to_stratum;
305   struct target_ops
306                 *DONT_USE;      /* formerly to_next */
307   int           to_has_all_memory;
308   int           to_has_memory;
309   int           to_has_stack;
310   int           to_has_registers;
311   int           to_has_execution;
312   struct section_table
313                *to_sections;
314   struct section_table
315                *to_sections_end;
316   int           to_magic;
317   /* Need sub-structure for target machine related rather than comm related? */
318 };
319
320 /* Magic number for checking ops size.  If a struct doesn't end with this
321    number, somebody changed the declaration but didn't change all the
322    places that initialize one.  */
323
324 #define OPS_MAGIC       3840
325
326 /* The ops structure for our "current" target process.  This should
327    never be NULL.  If there is no target, it points to the dummy_target.  */
328
329 extern struct target_ops        current_target;
330
331 /* An item on the target stack.  */
332
333 struct target_stack_item
334 {
335   struct target_stack_item *next;
336   struct target_ops *target_ops;
337 };
338
339 /* The target stack.  */
340
341 extern struct target_stack_item *target_stack;
342
343 /* Define easy words for doing these operations on our current target.  */
344
345 #define target_shortname        (current_target.to_shortname)
346 #define target_longname         (current_target.to_longname)
347
348 /* The open routine takes the rest of the parameters from the command,
349    and (if successful) pushes a new target onto the stack.
350    Targets should supply this routine, if only to provide an error message.  */
351 #define target_open(name, from_tty)     \
352         (*current_target.to_open) (name, from_tty)
353
354 /* Does whatever cleanup is required for a target that we are no longer
355    going to be calling.  Argument says whether we are quitting gdb and
356    should not get hung in case of errors, or whether we want a clean
357    termination even if it takes a while.  This routine is automatically
358    always called just before a routine is popped off the target stack.
359    Closing file descriptors and freeing memory are typical things it should
360    do.  */
361
362 #define target_close(quitting)  \
363         (*current_target.to_close) (quitting)
364
365 /* Attaches to a process on the target side.  Arguments are as passed
366    to the `attach' command by the user.  This routine can be called
367    when the target is not on the target-stack, if the target_can_run
368    routine returns 1; in that case, it must push itself onto the stack.  
369    Upon exit, the target should be ready for normal operations, and
370    should be ready to deliver the status of the process immediately 
371    (without waiting) to an upcoming target_wait call.  */
372
373 #define target_attach(args, from_tty)   \
374         (*current_target.to_attach) (args, from_tty)
375
376 /* Takes a program previously attached to and detaches it.
377    The program may resume execution (some targets do, some don't) and will
378    no longer stop on signals, etc.  We better not have left any breakpoints
379    in the program or it'll die when it hits one.  ARGS is arguments
380    typed by the user (e.g. a signal to send the process).  FROM_TTY
381    says whether to be verbose or not.  */
382
383 extern void
384 target_detach PARAMS ((char *, int));
385
386 /* Resume execution of the target process PID.  STEP says whether to
387    single-step or to run free; SIGGNAL is the signal to be given to
388    the target, or TARGET_SIGNAL_0 for no signal.  The caller may not
389    pass TARGET_SIGNAL_DEFAULT.  */
390
391 #define target_resume(pid, step, siggnal)       \
392         (*current_target.to_resume) (pid, step, siggnal)
393
394 /* Wait for process pid to do something.  Pid = -1 to wait for any pid
395    to do something.  Return pid of child, or -1 in case of error;
396    store status through argument pointer STATUS.  Note that it is
397    *not* OK to return_to_top_level out of target_wait without popping
398    the debugging target from the stack; GDB isn't prepared to get back
399    to the prompt with a debugging target but without the frame cache,
400    stop_pc, etc., set up.  */
401
402 #define target_wait(pid, status)                \
403         (*current_target.to_wait) (pid, status)
404
405 /* Fetch register REGNO, or all regs if regno == -1.  No result.  */
406
407 #define target_fetch_registers(regno)   \
408         (*current_target.to_fetch_registers) (regno)
409
410 /* Store at least register REGNO, or all regs if REGNO == -1.
411    It can store as many registers as it wants to, so target_prepare_to_store
412    must have been previously called.  Calls error() if there are problems.  */
413
414 #define target_store_registers(regs)    \
415         (*current_target.to_store_registers) (regs)
416
417 /* Get ready to modify the registers array.  On machines which store
418    individual registers, this doesn't need to do anything.  On machines
419    which store all the registers in one fell swoop, this makes sure
420    that REGISTERS contains all the registers from the program being
421    debugged.  */
422
423 #define target_prepare_to_store()       \
424         (*current_target.to_prepare_to_store) ()
425
426 extern int target_read_string PARAMS ((CORE_ADDR, char **, int, int *));
427
428 extern int
429 target_read_memory PARAMS ((CORE_ADDR, char *, int));
430
431 extern int
432 target_read_memory_partial PARAMS ((CORE_ADDR, char *, int, int *));
433
434 extern int
435 target_write_memory PARAMS ((CORE_ADDR, char *, int));
436
437 extern int
438 xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
439
440 extern int
441 child_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
442
443 /* Transfer LEN bytes between target address MEMADDR and GDB address MYADDR.
444    Returns 0 for success, errno code for failure (which includes partial
445    transfers--if you want a more useful response to partial transfers, try
446    target_read_memory_partial).  */
447
448 extern int target_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
449                                        int len, int write));
450
451 /* From exec.c */
452
453 extern void
454 print_section_info PARAMS ((struct target_ops *, bfd *));
455
456 /* Print a line about the current target.  */
457
458 #define target_files_info()     \
459         (*current_target.to_files_info) (&current_target)
460
461 /* Insert a breakpoint at address ADDR in the target machine.
462    SAVE is a pointer to memory allocated for saving the
463    target contents.  It is guaranteed by the caller to be long enough
464    to save "sizeof BREAKPOINT" bytes.  Result is 0 for success, or
465    an errno value.  */
466
467 #define target_insert_breakpoint(addr, save)    \
468         (*current_target.to_insert_breakpoint) (addr, save)
469
470 /* Remove a breakpoint at address ADDR in the target machine.
471    SAVE is a pointer to the same save area 
472    that was previously passed to target_insert_breakpoint.  
473    Result is 0 for success, or an errno value.  */
474
475 #define target_remove_breakpoint(addr, save)    \
476         (*current_target.to_remove_breakpoint) (addr, save)
477
478 /* Initialize the terminal settings we record for the inferior,
479    before we actually run the inferior.  */
480
481 #define target_terminal_init() \
482         (*current_target.to_terminal_init) ()
483
484 /* Put the inferior's terminal settings into effect.
485    This is preparation for starting or resuming the inferior.  */
486
487 #define target_terminal_inferior() \
488         (*current_target.to_terminal_inferior) ()
489
490 /* Put some of our terminal settings into effect,
491    enough to get proper results from our output,
492    but do not change into or out of RAW mode
493    so that no input is discarded.
494
495    After doing this, either terminal_ours or terminal_inferior
496    should be called to get back to a normal state of affairs.  */
497
498 #define target_terminal_ours_for_output() \
499         (*current_target.to_terminal_ours_for_output) ()
500
501 /* Put our terminal settings into effect.
502    First record the inferior's terminal settings
503    so they can be restored properly later.  */
504
505 #define target_terminal_ours() \
506         (*current_target.to_terminal_ours) ()
507
508 /* Print useful information about our terminal status, if such a thing
509    exists.  */
510
511 #define target_terminal_info(arg, from_tty) \
512         (*current_target.to_terminal_info) (arg, from_tty)
513
514 /* Kill the inferior process.   Make it go away.  */
515
516 #define target_kill() \
517         (*current_target.to_kill) ()
518
519 /* Load an executable file into the target process.  This is expected to
520    not only bring new code into the target process, but also to update
521    GDB's symbol tables to match.  */
522
523 #define target_load(arg, from_tty) \
524         (*current_target.to_load) (arg, from_tty)
525
526 /* Look up a symbol in the target's symbol table.  NAME is the symbol
527    name.  ADDRP is a CORE_ADDR * pointing to where the value of the symbol
528    should be returned.  The result is 0 if successful, nonzero if the
529    symbol does not exist in the target environment.  This function should
530    not call error() if communication with the target is interrupted, since
531    it is called from symbol reading, but should return nonzero, possibly
532    doing a complain().  */
533
534 #define target_lookup_symbol(name, addrp)       \
535   (*current_target.to_lookup_symbol) (name, addrp)
536
537 /* Start an inferior process and set inferior_pid to its pid.
538    EXEC_FILE is the file to run.
539    ALLARGS is a string containing the arguments to the program.
540    ENV is the environment vector to pass.  Errors reported with error().
541    On VxWorks and various standalone systems, we ignore exec_file.  */
542  
543 #define target_create_inferior(exec_file, args, env)    \
544         (*current_target.to_create_inferior) (exec_file, args, env)
545
546 /* The inferior process has died.  Do what is right.  */
547
548 #define target_mourn_inferior() \
549         (*current_target.to_mourn_inferior) ()
550
551 /* Does target have enough data to do a run or attach command? */
552
553 #define target_can_run(t) \
554         ((t)->to_can_run) ()
555
556 /* post process changes to signal handling in the inferior.  */
557
558 #define target_notice_signals(pid) \
559         (*current_target.to_notice_signals) (pid)
560
561 /* Check to see if a thread is still alive.  */
562
563 #define target_thread_alive(pid) \
564         (*current_target.to_thread_alive) (pid)
565
566 /* Make target stop in a continuable fashion.  (For instance, under Unix, this
567    should act like SIGSTOP).  This function is normally used by GUIs to
568    implement a stop button.  */
569
570 #define target_stop() current_target.to_stop ()
571
572 /* Pointer to next target in the chain, e.g. a core file and an exec file.  */
573
574 #define target_next \
575         (current_target.to_next)
576
577 /* Does the target include all of memory, or only part of it?  This
578    determines whether we look up the target chain for other parts of
579    memory if this target can't satisfy a request.  */
580
581 #define target_has_all_memory   \
582         (current_target.to_has_all_memory)
583
584 /* Does the target include memory?  (Dummy targets don't.)  */
585
586 #define target_has_memory       \
587         (current_target.to_has_memory)
588
589 /* Does the target have a stack?  (Exec files don't, VxWorks doesn't, until
590    we start a process.)  */
591    
592 #define target_has_stack        \
593         (current_target.to_has_stack)
594
595 /* Does the target have registers?  (Exec files don't.)  */
596
597 #define target_has_registers    \
598         (current_target.to_has_registers)
599
600 /* Does the target have execution?  Can we make it jump (through
601    hoops), or pop its stack a few times?  FIXME: If this is to work that
602    way, it needs to check whether an inferior actually exists.
603    remote-udi.c and probably other targets can be the current target
604    when the inferior doesn't actually exist at the moment.  Right now
605    this just tells us whether this target is *capable* of execution.  */
606
607 #define target_has_execution    \
608         (current_target.to_has_execution)
609
610 extern void target_link PARAMS ((char *, CORE_ADDR *));
611
612 /* Converts a process id to a string.  Usually, the string just contains
613    `process xyz', but on some systems it may contain
614    `process xyz thread abc'.  */
615
616 #ifndef target_pid_to_str
617 #define target_pid_to_str(PID) \
618         normal_pid_to_str (PID)
619 extern char *normal_pid_to_str PARAMS ((int pid));
620 #endif
621
622 #ifndef target_new_objfile
623 #define target_new_objfile(OBJFILE)
624 #endif
625
626 /* Hook to call target-dependant code after reading in a new symbol table. */
627
628 #ifndef TARGET_SYMFILE_POSTREAD
629 #define TARGET_SYMFILE_POSTREAD(OBJFILE)
630 #endif
631
632 /* Hook to call target dependant code just after inferior target process has
633    started.  */
634
635 #ifndef TARGET_CREATE_INFERIOR_HOOK
636 #define TARGET_CREATE_INFERIOR_HOOK(PID)
637 #endif
638
639 /* Hardware watchpoint interfaces.  */
640
641 /* Returns non-zero if we were stopped by a hardware watchpoint (memory read or
642    write).  */
643
644 #ifndef STOPPED_BY_WATCHPOINT
645 #define STOPPED_BY_WATCHPOINT(w) 0
646 #endif
647
648 /* Provide defaults for systems that don't support hardware watchpoints. */
649
650 #ifndef TARGET_HAS_HARDWARE_WATCHPOINTS
651
652 /* Returns non-zero if we can set a hardware watchpoint of type TYPE.  TYPE is
653    one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint, or
654    bp_hardware_breakpoint.  CNT is the number of such watchpoints used so far
655    (including this one?).  OTHERTYPE is who knows what...  */
656
657 #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) 0
658
659 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes.  TYPE is 1
660    for read and 2 for read/write accesses.  Returns 0 for success, non-zero for
661    failure.  */
662
663 #define target_remove_watchpoint(ADDR,LEN,TYPE) -1
664 #define target_insert_watchpoint(ADDR,LEN,TYPE) -1
665
666 #endif /* TARGET_HAS_HARDWARE_WATCHPOINTS */
667
668 #ifndef target_insert_hw_breakpoint
669 #define target_remove_hw_breakpoint(ADDR,SHADOW) -1
670 #define target_insert_hw_breakpoint(ADDR,SHADOW) -1
671 #endif
672
673 #ifndef target_stopped_data_address
674 #define target_stopped_data_address() 0
675 #endif
676
677 /* If defined, then we need to decr pc by this much after a hardware break-
678    point.  Presumably this overrides DECR_PC_AFTER_BREAK...  */
679
680 #ifndef DECR_PC_AFTER_HW_BREAK
681 #define DECR_PC_AFTER_HW_BREAK 0
682 #endif
683
684 /* Routines for maintenance of the target structures...
685
686    add_target:   Add a target to the list of all possible targets.
687
688    push_target:  Make this target the top of the stack of currently used
689                  targets, within its particular stratum of the stack.  Result
690                  is 0 if now atop the stack, nonzero if not on top (maybe
691                  should warn user).
692
693    unpush_target: Remove this from the stack of currently used targets,
694                  no matter where it is on the list.  Returns 0 if no
695                  change, 1 if removed from stack.
696
697    pop_target:   Remove the top thing on the stack of current targets.  */
698
699 extern void
700 add_target PARAMS ((struct target_ops *));
701
702 extern int
703 push_target PARAMS ((struct target_ops *));
704
705 extern int
706 unpush_target PARAMS ((struct target_ops *));
707
708 extern void
709 target_preopen PARAMS ((int));
710
711 extern void
712 pop_target PARAMS ((void));
713
714 /* Struct section_table maps address ranges to file sections.  It is
715    mostly used with BFD files, but can be used without (e.g. for handling
716    raw disks, or files not in formats handled by BFD).  */
717
718 struct section_table {
719   CORE_ADDR addr;               /* Lowest address in section */
720   CORE_ADDR endaddr;            /* 1+highest address in section */
721
722   sec_ptr the_bfd_section;
723
724   bfd      *bfd;                /* BFD file pointer */
725 };
726
727 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
728    Returns 0 if OK, 1 on error.  */
729
730 extern int
731 build_section_table PARAMS ((bfd *, struct section_table **,
732                              struct section_table **));
733
734 /* From mem-break.c */
735
736 extern int
737 memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));
738
739 extern int
740 memory_insert_breakpoint PARAMS ((CORE_ADDR, char *));
741
742 /* From target.c */
743
744 void
745 noprocess PARAMS ((void));
746
747 void
748 find_default_attach PARAMS ((char *, int));
749
750 void
751 find_default_create_inferior PARAMS ((char *, char *, char **));
752
753 struct target_ops *
754 find_core_target PARAMS ((void));
755 \f
756 /* Stuff that should be shared among the various remote targets.  */
757
758 /* Debugging level.  0 is off, and non-zero values mean to print some debug
759    information (higher values, more information).  */
760 extern int remote_debug;
761
762 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
763 extern int baud_rate;
764 /* Timeout limit for response from target. */
765 extern int remote_timeout;
766 \f
767 /* Functions for helping to write a native target.  */
768
769 /* This is for native targets which use a unix/POSIX-style waitstatus.  */
770 extern void store_waitstatus PARAMS ((struct target_waitstatus *, int));
771
772 /* Convert between host signal numbers and enum target_signal's.  */
773 extern enum target_signal target_signal_from_host PARAMS ((int));
774 extern int target_signal_to_host PARAMS ((enum target_signal));
775
776 /* Convert from a number used in a GDB command to an enum target_signal.  */
777 extern enum target_signal target_signal_from_command PARAMS ((int));
778
779 #endif  /* !defined (TARGET_H) */