* sunos.c (sunos_add_one_symbol): Treat a common symbol from a
[deliverable/binutils-gdb.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., 675 Mass Ave, Cambridge, MA 02139, 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 process_stratum /* Executing processes */
50 };
51
52 /* Stuff for target_wait. */
53
54 /* Generally, what has the program done? */
55 enum target_waitkind {
56 /* The program has exited. The exit status is in value.integer. */
57 TARGET_WAITKIND_EXITED,
58
59 /* The program has stopped with a signal. Which signal is in value.sig. */
60 TARGET_WAITKIND_STOPPED,
61
62 /* The program has terminated with a signal. Which signal is in
63 value.sig. */
64 TARGET_WAITKIND_SIGNALLED,
65
66 /* The program is letting us know that it dynamically loaded something
67 (e.g. it called load(2) on AIX). */
68 TARGET_WAITKIND_LOADED,
69
70 /* Nothing happened, but we stopped anyway. This perhaps should be handled
71 within target_wait, but I'm not sure target_wait should be resuming the
72 inferior. */
73 TARGET_WAITKIND_SPURIOUS
74 };
75
76 /* The numbering of these signals is chosen to match traditional unix
77 signals (insofar as various unices use the same numbers, anyway).
78 It is also the numbering of the GDB remote protocol. Other remote
79 protocols, if they use a different numbering, should make sure to
80 translate appropriately. */
81
82 /* This is based strongly on Unix/POSIX signals for several reasons:
83 (1) This set of signals represents a widely-accepted attempt to
84 represent events of this sort in a portable fashion, (2) we want a
85 signal to make it from wait to child_wait to the user intact, (3) many
86 remote protocols use a similar encoding. However, it is
87 recognized that this set of signals has limitations (such as not
88 distinguishing between various kinds of SIGSEGV, or not
89 distinguishing hitting a breakpoint from finishing a single step).
90 So in the future we may get around this either by adding additional
91 signals for breakpoint, single-step, etc., or by adding signal
92 codes; the latter seems more in the spirit of what BSD, System V,
93 etc. are doing to address these issues. */
94
95 /* For an explanation of what each signal means, see
96 target_signal_to_string. */
97
98 enum target_signal {
99 /* Used some places (e.g. stop_signal) to record the concept that
100 there is no signal. */
101 TARGET_SIGNAL_0 = 0,
102 TARGET_SIGNAL_FIRST = 0,
103 TARGET_SIGNAL_HUP = 1,
104 TARGET_SIGNAL_INT = 2,
105 TARGET_SIGNAL_QUIT = 3,
106 TARGET_SIGNAL_ILL = 4,
107 TARGET_SIGNAL_TRAP = 5,
108 TARGET_SIGNAL_ABRT = 6,
109 TARGET_SIGNAL_EMT = 7,
110 TARGET_SIGNAL_FPE = 8,
111 TARGET_SIGNAL_KILL = 9,
112 TARGET_SIGNAL_BUS = 10,
113 TARGET_SIGNAL_SEGV = 11,
114 TARGET_SIGNAL_SYS = 12,
115 TARGET_SIGNAL_PIPE = 13,
116 TARGET_SIGNAL_ALRM = 14,
117 TARGET_SIGNAL_TERM = 15,
118 TARGET_SIGNAL_URG = 16,
119 TARGET_SIGNAL_STOP = 17,
120 TARGET_SIGNAL_TSTP = 18,
121 TARGET_SIGNAL_CONT = 19,
122 TARGET_SIGNAL_CHLD = 20,
123 TARGET_SIGNAL_TTIN = 21,
124 TARGET_SIGNAL_TTOU = 22,
125 TARGET_SIGNAL_IO = 23,
126 TARGET_SIGNAL_XCPU = 24,
127 TARGET_SIGNAL_XFSZ = 25,
128 TARGET_SIGNAL_VTALRM = 26,
129 TARGET_SIGNAL_PROF = 27,
130 TARGET_SIGNAL_WINCH = 28,
131 TARGET_SIGNAL_LOST = 29,
132 TARGET_SIGNAL_USR1 = 30,
133 TARGET_SIGNAL_USR2 = 31,
134 TARGET_SIGNAL_PWR = 32,
135 /* Similar to SIGIO. Perhaps they should have the same number. */
136 TARGET_SIGNAL_POLL = 33,
137 TARGET_SIGNAL_WIND = 34,
138 TARGET_SIGNAL_PHONE = 35,
139 TARGET_SIGNAL_WAITING = 36,
140 TARGET_SIGNAL_LWP = 37,
141 TARGET_SIGNAL_DANGER = 38,
142 TARGET_SIGNAL_GRANT = 39,
143 TARGET_SIGNAL_RETRACT = 40,
144 TARGET_SIGNAL_MSG = 41,
145 TARGET_SIGNAL_SOUND = 42,
146 TARGET_SIGNAL_SAK = 43,
147
148 /* Some signal we don't know about. */
149 TARGET_SIGNAL_UNKNOWN,
150
151 /* Use whatever signal we use when one is not specifically specified
152 (for passing to proceed and so on). */
153 TARGET_SIGNAL_DEFAULT,
154
155 /* Last and unused enum value, for sizing arrays, etc. */
156 TARGET_SIGNAL_LAST
157 };
158
159 struct target_waitstatus {
160 enum target_waitkind kind;
161
162 /* Exit status or signal number. */
163 union {
164 int integer;
165 enum target_signal sig;
166 } value;
167 };
168
169 /* Return the string for a signal. */
170 extern char *target_signal_to_string PARAMS ((enum target_signal));
171
172 /* Return the name (SIGHUP, etc.) for a signal. */
173 extern char *target_signal_to_name PARAMS ((enum target_signal));
174
175 /* Given a name (SIGHUP, etc.), return its signal. */
176 enum target_signal target_signal_from_name PARAMS ((char *));
177 \f
178 struct target_ops
179 {
180 char *to_shortname; /* Name this target type */
181 char *to_longname; /* Name for printing */
182 char *to_doc; /* Documentation. Does not include trailing
183 newline, and starts with a one-line descrip-
184 tion (probably similar to to_longname). */
185 void (*to_open) PARAMS ((char *, int));
186 void (*to_close) PARAMS ((int));
187 void (*to_attach) PARAMS ((char *, int));
188 void (*to_detach) PARAMS ((char *, int));
189 void (*to_resume) PARAMS ((int, int, enum target_signal));
190 int (*to_wait) PARAMS ((int, struct target_waitstatus *));
191 void (*to_fetch_registers) PARAMS ((int));
192 void (*to_store_registers) PARAMS ((int));
193 void (*to_prepare_to_store) PARAMS ((void));
194
195 /* Transfer LEN bytes of memory between GDB address MYADDR and
196 target address MEMADDR. If WRITE, transfer them to the target, else
197 transfer them from the target. TARGET is the target from which we
198 get this function.
199
200 Return value, N, is one of the following:
201
202 0 means that we can't handle this. If errno has been set, it is the
203 error which prevented us from doing it (FIXME: What about bfd_error?).
204
205 positive (call it N) means that we have transferred N bytes
206 starting at MEMADDR. We might be able to handle more bytes
207 beyond this length, but no promises.
208
209 negative (call its absolute value N) means that we cannot
210 transfer right at MEMADDR, but we could transfer at least
211 something at MEMADDR + N. */
212
213 int (*to_xfer_memory) PARAMS ((CORE_ADDR memaddr, char *myaddr,
214 int len, int write,
215 struct target_ops * target));
216
217 #if 0
218 /* Enable this after 4.12. */
219
220 /* Search target memory. Start at STARTADDR and take LEN bytes of
221 target memory, and them with MASK, and compare to DATA. If they
222 match, set *ADDR_FOUND to the address we found it at, store the data
223 we found at LEN bytes starting at DATA_FOUND, and return. If
224 not, add INCREMENT to the search address and keep trying until
225 the search address is outside of the range [LORANGE,HIRANGE).
226
227 If we don't find anything, set *ADDR_FOUND to (CORE_ADDR)0 and return. */
228 void (*to_search) PARAMS ((int len, char *data, char *mask,
229 CORE_ADDR startaddr, int increment,
230 CORE_ADDR lorange, CORE_ADDR hirange,
231 CORE_ADDR *addr_found, char *data_found));
232
233 #define target_search(len, data, mask, startaddr, increment, lorange, hirange, addr_found, data_found) \
234 (*current_target->to_search) (len, data, mask, startaddr, increment, \
235 lorange, hirange, addr_found, data_found)
236 #endif /* 0 */
237
238 void (*to_files_info) PARAMS ((struct target_ops *));
239 int (*to_insert_breakpoint) PARAMS ((CORE_ADDR, char *));
240 int (*to_remove_breakpoint) PARAMS ((CORE_ADDR, char *));
241 void (*to_terminal_init) PARAMS ((void));
242 void (*to_terminal_inferior) PARAMS ((void));
243 void (*to_terminal_ours_for_output) PARAMS ((void));
244 void (*to_terminal_ours) PARAMS ((void));
245 void (*to_terminal_info) PARAMS ((char *, int));
246 void (*to_kill) PARAMS ((void));
247 void (*to_load) PARAMS ((char *, int));
248 int (*to_lookup_symbol) PARAMS ((char *, CORE_ADDR *));
249 void (*to_create_inferior) PARAMS ((char *, char *, char **));
250 void (*to_mourn_inferior) PARAMS ((void));
251 int (*to_can_run) PARAMS ((void));
252 void (*to_notice_signals) PARAMS ((int pid));
253 enum strata to_stratum;
254 struct target_ops
255 *to_next;
256 int to_has_all_memory;
257 int to_has_memory;
258 int to_has_stack;
259 int to_has_registers;
260 int to_has_execution;
261 struct section_table
262 *to_sections;
263 struct section_table
264 *to_sections_end;
265 int to_magic;
266 /* Need sub-structure for target machine related rather than comm related? */
267 };
268
269 /* Magic number for checking ops size. If a struct doesn't end with this
270 number, somebody changed the declaration but didn't change all the
271 places that initialize one. */
272
273 #define OPS_MAGIC 3840
274
275 /* The ops structure for our "current" target process. This should
276 never be NULL. If there is no target, it points to the dummy_target. */
277
278 extern struct target_ops *current_target;
279
280 /* Define easy words for doing these operations on our current target. */
281
282 #define target_shortname (current_target->to_shortname)
283 #define target_longname (current_target->to_longname)
284
285 /* The open routine takes the rest of the parameters from the command,
286 and (if successful) pushes a new target onto the stack.
287 Targets should supply this routine, if only to provide an error message. */
288 #define target_open(name, from_tty) \
289 (*current_target->to_open) (name, from_tty)
290
291 /* Does whatever cleanup is required for a target that we are no longer
292 going to be calling. Argument says whether we are quitting gdb and
293 should not get hung in case of errors, or whether we want a clean
294 termination even if it takes a while. This routine is automatically
295 always called just before a routine is popped off the target stack.
296 Closing file descriptors and freeing memory are typical things it should
297 do. */
298
299 #define target_close(quitting) \
300 (*current_target->to_close) (quitting)
301
302 /* Attaches to a process on the target side. Arguments are as passed
303 to the `attach' command by the user. This routine can be called
304 when the target is not on the target-stack, if the target_can_run
305 routine returns 1; in that case, it must push itself onto the stack.
306 Upon exit, the target should be ready for normal operations, and
307 should be ready to deliver the status of the process immediately
308 (without waiting) to an upcoming target_wait call. */
309
310 #define target_attach(args, from_tty) \
311 (*current_target->to_attach) (args, from_tty)
312
313 /* Takes a program previously attached to and detaches it.
314 The program may resume execution (some targets do, some don't) and will
315 no longer stop on signals, etc. We better not have left any breakpoints
316 in the program or it'll die when it hits one. ARGS is arguments
317 typed by the user (e.g. a signal to send the process). FROM_TTY
318 says whether to be verbose or not. */
319
320 extern void
321 target_detach PARAMS ((char *, int));
322
323 /* Resume execution of the target process PID. STEP says whether to
324 single-step or to run free; SIGGNAL is the signal to be given to
325 the target, or TARGET_SIGNAL_0 for no signal. The caller may not
326 pass TARGET_SIGNAL_DEFAULT. */
327
328 #define target_resume(pid, step, siggnal) \
329 (*current_target->to_resume) (pid, step, siggnal)
330
331 /* Wait for process pid to do something. Pid = -1 to wait for any pid
332 to do something. Return pid of child, or -1 in case of error;
333 store status through argument pointer STATUS. Note that it is
334 *not* OK to return_to_top_level out of target_wait without popping
335 the debugging target from the stack; GDB isn't prepared to get back
336 to the prompt with a debugging target but without the frame cache,
337 stop_pc, etc., set up. */
338
339 #define target_wait(pid, status) \
340 (*current_target->to_wait) (pid, status)
341
342 /* Fetch register REGNO, or all regs if regno == -1. No result. */
343
344 #define target_fetch_registers(regno) \
345 (*current_target->to_fetch_registers) (regno)
346
347 /* Store at least register REGNO, or all regs if REGNO == -1.
348 It can store as many registers as it wants to, so target_prepare_to_store
349 must have been previously called. Calls error() if there are problems. */
350
351 #define target_store_registers(regs) \
352 (*current_target->to_store_registers) (regs)
353
354 /* Get ready to modify the registers array. On machines which store
355 individual registers, this doesn't need to do anything. On machines
356 which store all the registers in one fell swoop, this makes sure
357 that REGISTERS contains all the registers from the program being
358 debugged. */
359
360 #define target_prepare_to_store() \
361 (*current_target->to_prepare_to_store) ()
362
363 extern int target_read_string PARAMS ((CORE_ADDR, char **, int, int *));
364
365 extern int
366 target_read_memory PARAMS ((CORE_ADDR, char *, int));
367
368 extern int
369 target_read_memory_partial PARAMS ((CORE_ADDR, char *, int, int *));
370
371 extern int
372 target_write_memory PARAMS ((CORE_ADDR, char *, int));
373
374 extern int
375 xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
376
377 extern int
378 child_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
379
380 /* Transfer LEN bytes between target address MEMADDR and GDB address MYADDR.
381 Returns 0 for success, errno code for failure (which includes partial
382 transfers--if you want a more useful response to partial transfers, try
383 target_read_memory_partial). */
384
385 extern int target_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
386 int len, int write));
387
388 /* From exec.c */
389
390 extern void
391 print_section_info PARAMS ((struct target_ops *, bfd *));
392
393 /* Print a line about the current target. */
394
395 #define target_files_info() \
396 (*current_target->to_files_info) (current_target)
397
398 /* Insert a breakpoint at address ADDR in the target machine.
399 SAVE is a pointer to memory allocated for saving the
400 target contents. It is guaranteed by the caller to be long enough
401 to save "sizeof BREAKPOINT" bytes. Result is 0 for success, or
402 an errno value. */
403
404 #define target_insert_breakpoint(addr, save) \
405 (*current_target->to_insert_breakpoint) (addr, save)
406
407 /* Remove a breakpoint at address ADDR in the target machine.
408 SAVE is a pointer to the same save area
409 that was previously passed to target_insert_breakpoint.
410 Result is 0 for success, or an errno value. */
411
412 #define target_remove_breakpoint(addr, save) \
413 (*current_target->to_remove_breakpoint) (addr, save)
414
415 /* Initialize the terminal settings we record for the inferior,
416 before we actually run the inferior. */
417
418 #define target_terminal_init() \
419 (*current_target->to_terminal_init) ()
420
421 /* Put the inferior's terminal settings into effect.
422 This is preparation for starting or resuming the inferior. */
423
424 #define target_terminal_inferior() \
425 (*current_target->to_terminal_inferior) ()
426
427 /* Put some of our terminal settings into effect,
428 enough to get proper results from our output,
429 but do not change into or out of RAW mode
430 so that no input is discarded.
431
432 After doing this, either terminal_ours or terminal_inferior
433 should be called to get back to a normal state of affairs. */
434
435 #define target_terminal_ours_for_output() \
436 (*current_target->to_terminal_ours_for_output) ()
437
438 /* Put our terminal settings into effect.
439 First record the inferior's terminal settings
440 so they can be restored properly later. */
441
442 #define target_terminal_ours() \
443 (*current_target->to_terminal_ours) ()
444
445 /* Print useful information about our terminal status, if such a thing
446 exists. */
447
448 #define target_terminal_info(arg, from_tty) \
449 (*current_target->to_terminal_info) (arg, from_tty)
450
451 /* Kill the inferior process. Make it go away. */
452
453 #define target_kill() \
454 (*current_target->to_kill) ()
455
456 /* Load an executable file into the target process. This is expected to
457 not only bring new code into the target process, but also to update
458 GDB's symbol tables to match. */
459
460 #define target_load(arg, from_tty) \
461 (*current_target->to_load) (arg, from_tty)
462
463 /* Look up a symbol in the target's symbol table. NAME is the symbol
464 name. ADDRP is a CORE_ADDR * pointing to where the value of the symbol
465 should be returned. The result is 0 if successful, nonzero if the
466 symbol does not exist in the target environment. This function should
467 not call error() if communication with the target is interrupted, since
468 it is called from symbol reading, but should return nonzero, possibly
469 doing a complain(). */
470
471 #define target_lookup_symbol(name, addrp) \
472 (*current_target->to_lookup_symbol) (name, addrp)
473
474 /* Start an inferior process and set inferior_pid to its pid.
475 EXEC_FILE is the file to run.
476 ALLARGS is a string containing the arguments to the program.
477 ENV is the environment vector to pass. Errors reported with error().
478 On VxWorks and various standalone systems, we ignore exec_file. */
479
480 #define target_create_inferior(exec_file, args, env) \
481 (*current_target->to_create_inferior) (exec_file, args, env)
482
483 /* The inferior process has died. Do what is right. */
484
485 #define target_mourn_inferior() \
486 (*current_target->to_mourn_inferior) ()
487
488 /* Does target have enough data to do a run or attach command? */
489
490 #define target_can_run(t) \
491 ((t)->to_can_run) ()
492
493 /* post process changes to signal handling in the inferior. */
494
495 #define target_notice_signals(pid) \
496 (*current_target->to_notice_signals) (pid)
497
498 /* Pointer to next target in the chain, e.g. a core file and an exec file. */
499
500 #define target_next \
501 (current_target->to_next)
502
503 /* Does the target include all of memory, or only part of it? This
504 determines whether we look up the target chain for other parts of
505 memory if this target can't satisfy a request. */
506
507 #define target_has_all_memory \
508 (current_target->to_has_all_memory)
509
510 /* Does the target include memory? (Dummy targets don't.) */
511
512 #define target_has_memory \
513 (current_target->to_has_memory)
514
515 /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
516 we start a process.) */
517
518 #define target_has_stack \
519 (current_target->to_has_stack)
520
521 /* Does the target have registers? (Exec files don't.) */
522
523 #define target_has_registers \
524 (current_target->to_has_registers)
525
526 /* Does the target have execution? Can we make it jump (through
527 hoops), or pop its stack a few times? FIXME: If this is to work that
528 way, it needs to check whether an inferior actually exists.
529 remote-udi.c and probably other targets can be the current target
530 when the inferior doesn't actually exist at the moment. Right now
531 this just tells us whether this target is *capable* of execution. */
532
533 #define target_has_execution \
534 (current_target->to_has_execution)
535
536 extern void target_link PARAMS ((char *, CORE_ADDR *));
537
538 /* Converts a process id to a string. Usually, the string just contains
539 `process xyz', but on some systems it may contain
540 `process xyz thread abc'. */
541
542 #ifndef target_pid_to_str
543 #define target_pid_to_str(PID) \
544 normal_pid_to_str (PID)
545 extern char *normal_pid_to_str PARAMS ((int pid));
546 #endif
547
548 /* Routines for maintenance of the target structures...
549
550 add_target: Add a target to the list of all possible targets.
551
552 push_target: Make this target the top of the stack of currently used
553 targets, within its particular stratum of the stack. Result
554 is 0 if now atop the stack, nonzero if not on top (maybe
555 should warn user).
556
557 unpush_target: Remove this from the stack of currently used targets,
558 no matter where it is on the list. Returns 0 if no
559 change, 1 if removed from stack.
560
561 pop_target: Remove the top thing on the stack of current targets. */
562
563 extern void
564 add_target PARAMS ((struct target_ops *));
565
566 extern int
567 push_target PARAMS ((struct target_ops *));
568
569 extern int
570 unpush_target PARAMS ((struct target_ops *));
571
572 extern void
573 target_preopen PARAMS ((int));
574
575 extern void
576 pop_target PARAMS ((void));
577
578 /* Struct section_table maps address ranges to file sections. It is
579 mostly used with BFD files, but can be used without (e.g. for handling
580 raw disks, or files not in formats handled by BFD). */
581
582 struct section_table {
583 CORE_ADDR addr; /* Lowest address in section */
584 CORE_ADDR endaddr; /* 1+highest address in section */
585
586 sec_ptr the_bfd_section;
587
588 bfd *bfd; /* BFD file pointer */
589 };
590
591 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
592 Returns 0 if OK, 1 on error. */
593
594 extern int
595 build_section_table PARAMS ((bfd *, struct section_table **,
596 struct section_table **));
597
598 /* From mem-break.c */
599
600 extern int
601 memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));
602
603 extern int
604 memory_insert_breakpoint PARAMS ((CORE_ADDR, char *));
605
606 /* From target.c */
607
608 void
609 noprocess PARAMS ((void));
610
611 void
612 find_default_attach PARAMS ((char *, int));
613
614 void
615 find_default_create_inferior PARAMS ((char *, char *, char **));
616
617 struct target_ops *
618 find_core_target PARAMS ((void));
619 \f
620 /* Stuff that should be shared among the various remote targets. */
621
622 /* Debugging level. 0 is off, and non-zero values mean to print some debug
623 information (higher values, more information). */
624 extern int remote_debug;
625
626 /* Speed in bits per second, or -1 which means don't mess with the speed. */
627 extern int baud_rate;
628 \f
629 /* Functions for helping to write a native target. */
630
631 /* This is for native targets which use a unix/POSIX-style waitstatus. */
632 extern void store_waitstatus PARAMS ((struct target_waitstatus *, int));
633
634 /* Convert between host signal numbers and enum target_signal's. */
635 extern enum target_signal target_signal_from_host PARAMS ((int));
636 extern int target_signal_to_host PARAMS ((enum target_signal));
637
638 #endif /* !defined (TARGET_H) */
This page took 0.049794 seconds and 4 git commands to generate.