]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Interface between GDB and target environments, including files and processes |
75af490b | 2 | Copyright 1990, 1991, 1992 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | Contributed by Cygnus Support. Written by John Gilmore. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
75af490b | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
75af490b JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
75af490b | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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 | |
75af490b JG |
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 | |
bd5635a1 RP |
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 | ||
75af490b JG |
43 | #include "bfd.h" |
44 | ||
bd5635a1 RP |
45 | enum strata { |
46 | dummy_stratum, /* The lowest of the low */ | |
47 | file_stratum, /* Executable files, etc */ | |
48 | core_stratum, /* Core dump files */ | |
75af490b | 49 | process_stratum /* Executing processes */ |
bd5635a1 RP |
50 | }; |
51 | ||
75af490b JG |
52 | struct target_ops |
53 | { | |
54 | char *to_shortname; /* Name this target type */ | |
55 | char *to_longname; /* Name for printing */ | |
56 | char *to_doc; /* Documentation. Does not include trailing | |
57 | newline, and starts with a one-line descrip- | |
58 | tion (probably similar to to_longname). */ | |
59 | void (*to_open) PARAMS ((char *, int)); | |
60 | void (*to_close) PARAMS ((int)); | |
61 | void (*to_attach) PARAMS ((char *, int)); | |
62 | void (*to_detach) PARAMS ((char *, int)); | |
f1e7bafc | 63 | void (*to_resume) PARAMS ((int, int, int)); |
75af490b JG |
64 | int (*to_wait) PARAMS ((int *)); |
65 | void (*to_fetch_registers) PARAMS ((int)); | |
66 | void (*to_store_registers) PARAMS ((int)); | |
67 | void (*to_prepare_to_store) PARAMS ((void)); | |
f1e7bafc JK |
68 | |
69 | /* Transfer LEN bytes of memory between GDB address MYADDR and | |
70 | target address MEMADDR. If WRITE, transfer them to the target, else | |
71 | transfer them from the target. TARGET is the target from which we | |
72 | get this function. | |
73 | ||
74 | Return value, N, is one of the following: | |
75 | ||
76 | 0 means that we can't handle this. If errno has been set, it is the | |
77 | error which prevented us from doing it (FIXME: What about bfd_error?). | |
78 | ||
79 | positive (call it N) means that we have transferred N bytes | |
80 | starting at MEMADDR. We might be able to handle more bytes | |
81 | beyond this length, but no promises. | |
82 | ||
83 | negative (call its absolute value N) means that we cannot | |
84 | transfer right at MEMADDR, but we could transfer at least | |
85 | something at MEMADDR + N. */ | |
86 | ||
87 | int (*to_xfer_memory) PARAMS ((CORE_ADDR memaddr, char *myaddr, | |
88 | int len, int write, | |
89 | struct target_ops * target)); | |
90 | ||
75af490b JG |
91 | void (*to_files_info) PARAMS ((struct target_ops *)); |
92 | int (*to_insert_breakpoint) PARAMS ((CORE_ADDR, char *)); | |
93 | int (*to_remove_breakpoint) PARAMS ((CORE_ADDR, char *)); | |
94 | void (*to_terminal_init) PARAMS ((void)); | |
95 | void (*to_terminal_inferior) PARAMS ((void)); | |
96 | void (*to_terminal_ours_for_output) PARAMS ((void)); | |
97 | void (*to_terminal_ours) PARAMS ((void)); | |
98 | void (*to_terminal_info) PARAMS ((char *, int)); | |
99 | void (*to_kill) PARAMS ((void)); | |
100 | void (*to_load) PARAMS ((char *, int)); | |
101 | int (*to_lookup_symbol) PARAMS ((char *, CORE_ADDR *)); | |
102 | void (*to_create_inferior) PARAMS ((char *, char *, char **)); | |
103 | void (*to_mourn_inferior) PARAMS ((void)); | |
836e343b | 104 | int (*to_can_run) PARAMS ((void)); |
f1e7bafc | 105 | void (*to_notice_signals) PARAMS ((void)); |
75af490b JG |
106 | enum strata to_stratum; |
107 | struct target_ops | |
108 | *to_next; | |
109 | int to_has_all_memory; | |
110 | int to_has_memory; | |
111 | int to_has_stack; | |
112 | int to_has_registers; | |
113 | int to_has_execution; | |
114 | struct section_table | |
115 | *to_sections; | |
116 | struct section_table | |
117 | *to_sections_end; | |
118 | int to_magic; | |
119 | /* Need sub-structure for target machine related rather than comm related? */ | |
bd5635a1 RP |
120 | }; |
121 | ||
122 | /* Magic number for checking ops size. If a struct doesn't end with this | |
123 | number, somebody changed the declaration but didn't change all the | |
124 | places that initialize one. */ | |
125 | ||
126 | #define OPS_MAGIC 3840 | |
127 | ||
f1e7bafc JK |
128 | /* The ops structure for our "current" target process. This should |
129 | never be NULL. If there is no target, it points to the dummy_target. */ | |
bd5635a1 RP |
130 | |
131 | extern struct target_ops *current_target; | |
132 | ||
133 | /* Define easy words for doing these operations on our current target. */ | |
134 | ||
135 | #define target_shortname (current_target->to_shortname) | |
136 | #define target_longname (current_target->to_longname) | |
137 | ||
9136fe49 JK |
138 | /* The open routine takes the rest of the parameters from the command, |
139 | and (if successful) pushes a new target onto the stack. | |
140 | Targets should supply this routine, if only to provide an error message. */ | |
bd5635a1 RP |
141 | #define target_open(name, from_tty) \ |
142 | (*current_target->to_open) (name, from_tty) | |
143 | ||
144 | /* Does whatever cleanup is required for a target that we are no longer | |
145 | going to be calling. Argument says whether we are quitting gdb and | |
146 | should not get hung in case of errors, or whether we want a clean | |
147 | termination even if it takes a while. This routine is automatically | |
148 | always called just before a routine is popped off the target stack. | |
149 | Closing file descriptors and freeing memory are typical things it should | |
150 | do. */ | |
151 | ||
152 | #define target_close(quitting) \ | |
153 | (*current_target->to_close) (quitting) | |
154 | ||
836e343b JG |
155 | /* Attaches to a process on the target side. Arguments are as passed |
156 | to the `attach' command by the user. This routine can be called | |
157 | when the target is not on the target-stack, if the target_can_run | |
158 | routine returns 1; in that case, it must push itself onto the stack. | |
159 | Upon exit, the target should be ready for normal operations, and | |
160 | should be ready to deliver the status of the process immediately | |
161 | (without waiting) to an upcoming target_wait call. */ | |
bd5635a1 RP |
162 | |
163 | #define target_attach(args, from_tty) \ | |
164 | (*current_target->to_attach) (args, from_tty) | |
165 | ||
166 | /* Takes a program previously attached to and detaches it. | |
167 | The program may resume execution (some targets do, some don't) and will | |
168 | no longer stop on signals, etc. We better not have left any breakpoints | |
169 | in the program or it'll die when it hits one. ARGS is arguments | |
170 | typed by the user (e.g. a signal to send the process). FROM_TTY | |
171 | says whether to be verbose or not. */ | |
172 | ||
f1e7bafc JK |
173 | extern void |
174 | target_detach PARAMS ((char *, int)); | |
bd5635a1 | 175 | |
f1e7bafc JK |
176 | /* Resume execution of the target process PID. STEP says whether to |
177 | single-step or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be | |
178 | given to the target, or zero for no signal. */ | |
bd5635a1 | 179 | |
f1e7bafc JK |
180 | #define target_resume(pid, step, siggnal) \ |
181 | (*current_target->to_resume) (pid, step, siggnal) | |
bd5635a1 RP |
182 | |
183 | /* Wait for inferior process to do something. Return pid of child, | |
184 | or -1 in case of error; store status through argument pointer STATUS. */ | |
185 | ||
186 | #define target_wait(status) \ | |
187 | (*current_target->to_wait) (status) | |
188 | ||
75af490b | 189 | /* Fetch register REGNO, or all regs if regno == -1. No result. */ |
bd5635a1 RP |
190 | |
191 | #define target_fetch_registers(regno) \ | |
192 | (*current_target->to_fetch_registers) (regno) | |
193 | ||
194 | /* Store at least register REGNO, or all regs if REGNO == -1. | |
f1e7bafc JK |
195 | It can store as many registers as it wants to, so target_prepare_to_store |
196 | must have been previously called. Calls error() if there are problems. */ | |
bd5635a1 RP |
197 | |
198 | #define target_store_registers(regs) \ | |
199 | (*current_target->to_store_registers) (regs) | |
200 | ||
201 | /* Get ready to modify the registers array. On machines which store | |
202 | individual registers, this doesn't need to do anything. On machines | |
203 | which store all the registers in one fell swoop, this makes sure | |
204 | that REGISTERS contains all the registers from the program being | |
205 | debugged. */ | |
206 | ||
207 | #define target_prepare_to_store() \ | |
208 | (*current_target->to_prepare_to_store) () | |
209 | ||
75af490b JG |
210 | extern int |
211 | target_read_string PARAMS ((CORE_ADDR, char *, int)); | |
212 | ||
213 | extern int | |
214 | target_read_memory PARAMS ((CORE_ADDR, char *, int)); | |
215 | ||
f1e7bafc JK |
216 | extern int |
217 | target_read_memory_partial PARAMS ((CORE_ADDR, char *, int, int *)); | |
218 | ||
75af490b JG |
219 | extern int |
220 | target_write_memory PARAMS ((CORE_ADDR, char *, int)); | |
221 | ||
222 | extern int | |
223 | xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *)); | |
224 | ||
225 | extern int | |
226 | child_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *)); | |
227 | ||
f1e7bafc JK |
228 | /* Transfer LEN bytes between target address MEMADDR and GDB address MYADDR. |
229 | Returns 0 for success, errno code for failure (which includes partial | |
230 | transfers--if you want a more useful response to partial transfers, try | |
231 | target_read_memory_partial). */ | |
232 | ||
233 | extern int target_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, | |
234 | int len, int write)); | |
75af490b JG |
235 | |
236 | /* From exec.c */ | |
237 | ||
238 | extern void | |
239 | print_section_info PARAMS ((struct target_ops *, bfd *)); | |
bd5635a1 RP |
240 | |
241 | /* Print a line about the current target. */ | |
242 | ||
243 | #define target_files_info() \ | |
75af490b | 244 | (*current_target->to_files_info) (current_target) |
bd5635a1 RP |
245 | |
246 | /* Insert a breakpoint at address ADDR in the target machine. | |
247 | SAVE is a pointer to memory allocated for saving the | |
248 | target contents. It is guaranteed by the caller to be long enough | |
249 | to save "sizeof BREAKPOINT" bytes. Result is 0 for success, or | |
250 | an errno value. */ | |
251 | ||
252 | #define target_insert_breakpoint(addr, save) \ | |
253 | (*current_target->to_insert_breakpoint) (addr, save) | |
254 | ||
255 | /* Remove a breakpoint at address ADDR in the target machine. | |
256 | SAVE is a pointer to the same save area | |
257 | that was previously passed to target_insert_breakpoint. | |
258 | Result is 0 for success, or an errno value. */ | |
259 | ||
260 | #define target_remove_breakpoint(addr, save) \ | |
261 | (*current_target->to_remove_breakpoint) (addr, save) | |
262 | ||
263 | /* Initialize the terminal settings we record for the inferior, | |
264 | before we actually run the inferior. */ | |
265 | ||
266 | #define target_terminal_init() \ | |
267 | (*current_target->to_terminal_init) () | |
f1e7bafc | 268 | |
bd5635a1 RP |
269 | /* Put the inferior's terminal settings into effect. |
270 | This is preparation for starting or resuming the inferior. */ | |
271 | ||
272 | #define target_terminal_inferior() \ | |
273 | (*current_target->to_terminal_inferior) () | |
274 | ||
275 | /* Put some of our terminal settings into effect, | |
276 | enough to get proper results from our output, | |
277 | but do not change into or out of RAW mode | |
278 | so that no input is discarded. | |
279 | ||
280 | After doing this, either terminal_ours or terminal_inferior | |
281 | should be called to get back to a normal state of affairs. */ | |
282 | ||
283 | #define target_terminal_ours_for_output() \ | |
284 | (*current_target->to_terminal_ours_for_output) () | |
285 | ||
286 | /* Put our terminal settings into effect. | |
287 | First record the inferior's terminal settings | |
288 | so they can be restored properly later. */ | |
289 | ||
290 | #define target_terminal_ours() \ | |
291 | (*current_target->to_terminal_ours) () | |
292 | ||
293 | /* Print useful information about our terminal status, if such a thing | |
294 | exists. */ | |
295 | ||
296 | #define target_terminal_info(arg, from_tty) \ | |
297 | (*current_target->to_terminal_info) (arg, from_tty) | |
298 | ||
299 | /* Kill the inferior process. Make it go away. */ | |
300 | ||
75af490b JG |
301 | #define target_kill() \ |
302 | (*current_target->to_kill) () | |
bd5635a1 RP |
303 | |
304 | /* Load an executable file into the target process. This is expected to | |
305 | not only bring new code into the target process, but also to update | |
306 | GDB's symbol tables to match. */ | |
307 | ||
308 | #define target_load(arg, from_tty) \ | |
309 | (*current_target->to_load) (arg, from_tty) | |
310 | ||
bd5635a1 RP |
311 | /* Look up a symbol in the target's symbol table. NAME is the symbol |
312 | name. ADDRP is a CORE_ADDR * pointing to where the value of the symbol | |
313 | should be returned. The result is 0 if successful, nonzero if the | |
314 | symbol does not exist in the target environment. This function should | |
315 | not call error() if communication with the target is interrupted, since | |
316 | it is called from symbol reading, but should return nonzero, possibly | |
317 | doing a complain(). */ | |
318 | ||
319 | #define target_lookup_symbol(name, addrp) \ | |
320 | (*current_target->to_lookup_symbol) (name, addrp) | |
321 | ||
322 | /* Start an inferior process and set inferior_pid to its pid. | |
323 | EXEC_FILE is the file to run. | |
324 | ALLARGS is a string containing the arguments to the program. | |
325 | ENV is the environment vector to pass. Errors reported with error(). | |
326 | On VxWorks and various standalone systems, we ignore exec_file. */ | |
327 | ||
328 | #define target_create_inferior(exec_file, args, env) \ | |
329 | (*current_target->to_create_inferior) (exec_file, args, env) | |
330 | ||
331 | /* The inferior process has died. Do what is right. */ | |
332 | ||
333 | #define target_mourn_inferior() \ | |
334 | (*current_target->to_mourn_inferior) () | |
335 | ||
836e343b JG |
336 | /* Does target have enough data to do a run or attach command? */ |
337 | ||
338 | #define target_can_run(t) \ | |
339 | ((t)->to_can_run) () | |
340 | ||
f1e7bafc JK |
341 | /* post process changes to signal handling in the inferior. */ |
342 | ||
343 | #define target_notice_signals() \ | |
344 | (*current_target->to_notice_signals) () | |
345 | ||
bd5635a1 RP |
346 | /* Pointer to next target in the chain, e.g. a core file and an exec file. */ |
347 | ||
348 | #define target_next \ | |
349 | (current_target->to_next) | |
350 | ||
351 | /* Does the target include all of memory, or only part of it? This | |
352 | determines whether we look up the target chain for other parts of | |
353 | memory if this target can't satisfy a request. */ | |
354 | ||
355 | #define target_has_all_memory \ | |
356 | (current_target->to_has_all_memory) | |
357 | ||
358 | /* Does the target include memory? (Dummy targets don't.) */ | |
359 | ||
360 | #define target_has_memory \ | |
361 | (current_target->to_has_memory) | |
362 | ||
363 | /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until | |
364 | we start a process.) */ | |
365 | ||
366 | #define target_has_stack \ | |
367 | (current_target->to_has_stack) | |
368 | ||
369 | /* Does the target have registers? (Exec files don't.) */ | |
370 | ||
371 | #define target_has_registers \ | |
372 | (current_target->to_has_registers) | |
373 | ||
f1e7bafc JK |
374 | /* Does the target have execution? Can we make it jump (through |
375 | hoops), or pop its stack a few times? FIXME: If this is to work that | |
376 | way, it needs to check whether an inferior actually exists. | |
377 | remote-udi.c and probably other targets can be the current target | |
378 | when the inferior doesn't actually exist at the moment. Right now | |
379 | this just tells us whether this target is *capable* of execution. */ | |
bd5635a1 RP |
380 | |
381 | #define target_has_execution \ | |
382 | (current_target->to_has_execution) | |
383 | ||
f1e7bafc JK |
384 | /* Converts a process id to a string. Usually, the string just contains |
385 | `process xyz', but on some systems it may contain | |
386 | `process xyz thread abc'. */ | |
387 | ||
388 | #ifndef target_pid_to_str | |
389 | #define target_pid_to_str(PID) \ | |
390 | normal_pid_to_str (PID) | |
391 | extern char *normal_pid_to_str PARAMS ((int pid)); | |
392 | #endif | |
393 | ||
bd5635a1 RP |
394 | /* Routines for maintenance of the target structures... |
395 | ||
396 | add_target: Add a target to the list of all possible targets. | |
397 | ||
398 | push_target: Make this target the top of the stack of currently used | |
399 | targets, within its particular stratum of the stack. Result | |
400 | is 0 if now atop the stack, nonzero if not on top (maybe | |
401 | should warn user). | |
402 | ||
403 | unpush_target: Remove this from the stack of currently used targets, | |
404 | no matter where it is on the list. Returns 0 if no | |
405 | change, 1 if removed from stack. | |
406 | ||
407 | pop_target: Remove the top thing on the stack of current targets. */ | |
408 | ||
75af490b JG |
409 | extern void |
410 | add_target PARAMS ((struct target_ops *)); | |
411 | ||
412 | extern int | |
413 | push_target PARAMS ((struct target_ops *)); | |
414 | ||
415 | extern int | |
416 | unpush_target PARAMS ((struct target_ops *)); | |
417 | ||
418 | extern void | |
419 | target_preopen PARAMS ((int)); | |
420 | ||
421 | extern void | |
422 | pop_target PARAMS ((void)); | |
423 | ||
424 | /* Struct section_table maps address ranges to file sections. It is | |
425 | mostly used with BFD files, but can be used without (e.g. for handling | |
426 | raw disks, or files not in formats handled by BFD). */ | |
427 | ||
428 | struct section_table { | |
429 | CORE_ADDR addr; /* Lowest address in section */ | |
430 | CORE_ADDR endaddr; /* 1+highest address in section */ | |
431 | sec_ptr sec_ptr; /* BFD section pointer */ | |
432 | bfd *bfd; /* BFD file pointer */ | |
433 | }; | |
434 | ||
435 | /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR. | |
436 | Returns 0 if OK, 1 on error. */ | |
437 | ||
438 | extern int | |
439 | build_section_table PARAMS ((bfd *, struct section_table **, | |
440 | struct section_table **)); | |
441 | ||
75af490b JG |
442 | /* From mem-break.c */ |
443 | ||
444 | extern int | |
445 | memory_remove_breakpoint PARAMS ((CORE_ADDR, char *)); | |
446 | ||
447 | extern int | |
448 | memory_insert_breakpoint PARAMS ((CORE_ADDR, char *)); | |
449 | ||
dcc8abce JG |
450 | /* From target.c */ |
451 | ||
452 | void | |
453 | noprocess PARAMS ((void)); | |
454 | ||
836e343b JG |
455 | void |
456 | find_default_attach PARAMS ((char *, int)); | |
457 | ||
458 | void | |
459 | find_default_create_inferior PARAMS ((char *, char *, char **)); | |
460 | ||
f1e7bafc JK |
461 | struct target_ops * |
462 | find_core_target PARAMS ((void)); | |
463 | \f | |
75af490b | 464 | #endif /* !defined (TARGET_H) */ |