]>
Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Interface between GDB and target environments, including files and processes |
2 | Copyright 1990, 1991 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. Written by John Gilmore. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | GDB 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 1, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GDB 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 GDB; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* This include file defines the interface between the main part | |
22 | of the debugger, and the part which is target-specific, or | |
23 | specific to the communications interface between us and the | |
24 | target. | |
25 | ||
26 | A TARGET is an interface between the debugger and a particular | |
27 | kind of file or process. Targets can be STACKED in STRATA, | |
28 | so that more than one target can potentially respond to a request. | |
29 | In particular, memory accesses will walk down the stack of targets | |
30 | until they find a target that is interested in handling that particular | |
31 | address. STRATA are artificial boundaries on the stack, within | |
32 | which particular kinds of targets live. Strata exist so that | |
33 | people don't get confused by pushing e.g. a process target and then | |
34 | a file target, and wondering why they can't see the current values | |
35 | of variables any more (the file target is handling them and they | |
36 | never get to the process target). So when you push a file target, | |
37 | it goes into the file stratum, which is always below the process | |
38 | stratum. */ | |
39 | ||
40 | enum strata { | |
41 | dummy_stratum, /* The lowest of the low */ | |
42 | file_stratum, /* Executable files, etc */ | |
43 | core_stratum, /* Core dump files */ | |
44 | process_stratum, /* Executing processes */ | |
45 | }; | |
46 | ||
47 | struct target_ops { | |
48 | char *to_shortname; /* Name this target type */ | |
49 | char *to_longname; /* Name for printing */ | |
9136fe49 JK |
50 | /* Documentation. Does not include trailing newline, and |
51 | starts with a one-line description (probably similar to | |
52 | to_longname). */ | |
53 | char *to_doc; | |
bd5635a1 RP |
54 | #ifdef __STDC__ |
55 | void (*to_open) (char *name, int from_tty); | |
56 | void (*to_close) (int quitting); | |
57 | void (*to_attach) (char *name, int from_tty); | |
58 | void (*to_detach) (char *args, int from_tty); | |
59 | void (*to_resume) (int step, int siggnal); | |
60 | int (*to_wait) (int *status); | |
61 | int (*to_fetch_registers) (int regno); | |
62 | int (*to_store_registers) (int regno); | |
63 | void (*to_prepare_to_store) (); | |
64 | void (*to_convert_to_virtual) (int regnum, char *from, char *to); | |
65 | void (*to_convert_from_virtual) (int regnum, char *from, char *to); | |
66 | int (*to_xfer_memory) (CORE_ADDR memaddr, char *myaddr, int len, int w); | |
67 | void (*to_files_info) (); | |
68 | int (*to_insert_breakpoint) (CORE_ADDR addr, char *save); | |
69 | int (*to_remove_breakpoint) (CORE_ADDR addr, char *save); | |
70 | void (*to_terminal_init) (); | |
71 | void (*to_terminal_inferior) (); | |
72 | void (*to_terminal_ours_for_output) (); | |
73 | void (*to_terminal_ours) (); | |
74 | void (*to_terminal_info) (char *arg, int from_tty); | |
75 | void (*to_kill) (char *arg, int from_tty); | |
76 | void (*to_load) (char *arg, int from_tty); | |
77 | void (*to_add_syms) (char *arg, int from_tty); | |
78 | struct value *(*to_call_function) (struct value *function, | |
79 | int nargs, struct value **args); | |
80 | int (*to_lookup_symbol) (char *name, CORE_ADDR *addrp); | |
81 | void (*to_create_inferior) (char *exec, char *args, char **env); | |
82 | void (*to_mourn_inferior) (); | |
83 | enum strata to_stratum; | |
84 | struct target_ops *to_next; | |
85 | int to_has_all_memory; | |
86 | int to_has_memory; | |
87 | int to_has_stack; | |
88 | int to_has_registers; | |
89 | int to_has_execution; | |
90 | int to_magic; | |
91 | /* Need sub-structure for target machine related rather than comm related? */ | |
92 | #else /* STDC */ | |
93 | void (*to_open) (); | |
94 | void (*to_close) (); | |
95 | void (*to_attach) (); | |
96 | void (*to_detach) (); | |
97 | void (*to_resume) (); | |
98 | int (*to_wait) (); | |
99 | int (*to_fetch_registers) (); | |
100 | int (*to_store_registers) (); | |
101 | void (*to_prepare_to_store) (); | |
102 | void (*to_convert_to_virtual) (); | |
103 | void (*to_convert_from_virtual) (); | |
104 | int (*to_xfer_memory) (); | |
105 | void (*to_files_info) (); | |
106 | int (*to_insert_breakpoint) (); | |
107 | int (*to_remove_breakpoint) (); | |
108 | void (*to_terminal_init) (); | |
109 | void (*to_terminal_inferior) (); | |
110 | void (*to_terminal_ours_for_output) (); | |
111 | void (*to_terminal_ours) (); | |
112 | void (*to_terminal_info) (); | |
113 | void (*to_kill) (); | |
114 | void (*to_load) (); | |
115 | void (*to_add_syms) (); | |
116 | struct value *(*to_call_function) (); | |
117 | int (*to_lookup_symbol) (); | |
118 | void (*to_create_inferior) (); | |
119 | void (*to_mourn_inferior) (); | |
120 | enum strata to_stratum; | |
121 | struct target_ops *to_next; | |
122 | int to_has_all_memory; | |
123 | int to_has_memory; | |
124 | int to_has_stack; | |
125 | int to_has_registers; | |
126 | int to_has_execution; | |
127 | int to_magic; | |
128 | /* Need sub-structure for target machine related rather than comm related? */ | |
129 | #endif | |
130 | }; | |
131 | ||
132 | /* Magic number for checking ops size. If a struct doesn't end with this | |
133 | number, somebody changed the declaration but didn't change all the | |
134 | places that initialize one. */ | |
135 | ||
136 | #define OPS_MAGIC 3840 | |
137 | ||
138 | /* The ops structure for our "current" target process. */ | |
139 | ||
140 | extern struct target_ops *current_target; | |
141 | ||
142 | /* Define easy words for doing these operations on our current target. */ | |
143 | ||
144 | #define target_shortname (current_target->to_shortname) | |
145 | #define target_longname (current_target->to_longname) | |
146 | ||
9136fe49 JK |
147 | /* The open routine takes the rest of the parameters from the command, |
148 | and (if successful) pushes a new target onto the stack. | |
149 | Targets should supply this routine, if only to provide an error message. */ | |
bd5635a1 RP |
150 | #define target_open(name, from_tty) \ |
151 | (*current_target->to_open) (name, from_tty) | |
152 | ||
153 | /* Does whatever cleanup is required for a target that we are no longer | |
154 | going to be calling. Argument says whether we are quitting gdb and | |
155 | should not get hung in case of errors, or whether we want a clean | |
156 | termination even if it takes a while. This routine is automatically | |
157 | always called just before a routine is popped off the target stack. | |
158 | Closing file descriptors and freeing memory are typical things it should | |
159 | do. */ | |
160 | ||
161 | #define target_close(quitting) \ | |
162 | (*current_target->to_close) (quitting) | |
163 | ||
164 | /* Attaches to a process on the target side. */ | |
165 | ||
166 | #define target_attach(args, from_tty) \ | |
167 | (*current_target->to_attach) (args, from_tty) | |
168 | ||
169 | /* Takes a program previously attached to and detaches it. | |
170 | The program may resume execution (some targets do, some don't) and will | |
171 | no longer stop on signals, etc. We better not have left any breakpoints | |
172 | in the program or it'll die when it hits one. ARGS is arguments | |
173 | typed by the user (e.g. a signal to send the process). FROM_TTY | |
174 | says whether to be verbose or not. */ | |
175 | ||
176 | #define target_detach(args, from_tty) \ | |
177 | (*current_target->to_detach) (args, from_tty) | |
178 | ||
179 | /* Resume execution of the target process. STEP says whether to single-step | |
180 | or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given | |
181 | to the target, or zero for no signal. */ | |
182 | ||
183 | #define target_resume(step, siggnal) \ | |
184 | (*current_target->to_resume) (step, siggnal) | |
185 | ||
186 | /* Wait for inferior process to do something. Return pid of child, | |
187 | or -1 in case of error; store status through argument pointer STATUS. */ | |
188 | ||
189 | #define target_wait(status) \ | |
190 | (*current_target->to_wait) (status) | |
191 | ||
192 | /* Fetch register REGNO, or all regs if regno == -1. Result is 0 | |
193 | for success, -1 for problems. */ | |
194 | ||
195 | #define target_fetch_registers(regno) \ | |
196 | (*current_target->to_fetch_registers) (regno) | |
197 | ||
198 | /* Store at least register REGNO, or all regs if REGNO == -1. | |
199 | It can store as many registers as it wants to, so the entire registers | |
200 | array must be valid. Result is 0 for success, -1 for problems. */ | |
201 | ||
202 | #define target_store_registers(regs) \ | |
203 | (*current_target->to_store_registers) (regs) | |
204 | ||
205 | /* Get ready to modify the registers array. On machines which store | |
206 | individual registers, this doesn't need to do anything. On machines | |
207 | which store all the registers in one fell swoop, this makes sure | |
208 | that REGISTERS contains all the registers from the program being | |
209 | debugged. */ | |
210 | ||
211 | #define target_prepare_to_store() \ | |
212 | (*current_target->to_prepare_to_store) () | |
213 | ||
214 | /* Convert data from raw format for register REGNUM | |
215 | to virtual format for register REGNUM. */ | |
216 | ||
217 | #define target_convert_to_virtual(regnum, from, to) \ | |
218 | (*current_target->to_convert_to_virtual) (regnum, from, to) | |
219 | ||
220 | /* Convert data from virtual format for register REGNUM | |
221 | to raw format for register REGNUM. */ | |
222 | ||
223 | #define target_convert_from_virtual(regnum, from, to) \ | |
224 | (*current_target->to_convert_from_virtual) (regnum, from, to) | |
225 | ||
226 | /* Reading and writing memory actually happens through a glue | |
227 | function which iterates across the various targets. Result is | |
228 | 0 for success, or an errno value. */ | |
229 | ||
230 | #ifdef __STDC__ | |
231 | /* Needs defs.h for CORE_ADDR */ | |
232 | extern int target_read_memory(CORE_ADDR memaddr, char *myaddr, int len); | |
233 | extern int target_write_memory(CORE_ADDR memaddr, char *myaddr, int len); | |
234 | extern int target_xfer_memory(CORE_ADDR memaddr, char *myaddr, int len, | |
235 | int write); | |
236 | #else | |
237 | extern int target_read_memory(); | |
238 | extern int target_write_memory(); | |
239 | extern int target_xfer_memory(); | |
240 | #endif | |
241 | ||
242 | /* Print a line about the current target. */ | |
243 | ||
244 | #define target_files_info() \ | |
245 | (*current_target->to_files_info) () | |
246 | ||
247 | /* Insert a breakpoint at address ADDR in the target machine. | |
248 | SAVE is a pointer to memory allocated for saving the | |
249 | target contents. It is guaranteed by the caller to be long enough | |
250 | to save "sizeof BREAKPOINT" bytes. Result is 0 for success, or | |
251 | an errno value. */ | |
252 | ||
253 | #define target_insert_breakpoint(addr, save) \ | |
254 | (*current_target->to_insert_breakpoint) (addr, save) | |
255 | ||
256 | /* Remove a breakpoint at address ADDR in the target machine. | |
257 | SAVE is a pointer to the same save area | |
258 | that was previously passed to target_insert_breakpoint. | |
259 | Result is 0 for success, or an errno value. */ | |
260 | ||
261 | #define target_remove_breakpoint(addr, save) \ | |
262 | (*current_target->to_remove_breakpoint) (addr, save) | |
263 | ||
264 | /* Initialize the terminal settings we record for the inferior, | |
265 | before we actually run the inferior. */ | |
266 | ||
267 | #define target_terminal_init() \ | |
268 | (*current_target->to_terminal_init) () | |
269 | ||
270 | /* Put the inferior's terminal settings into effect. | |
271 | This is preparation for starting or resuming the inferior. */ | |
272 | ||
273 | #define target_terminal_inferior() \ | |
274 | (*current_target->to_terminal_inferior) () | |
275 | ||
276 | /* Put some of our terminal settings into effect, | |
277 | enough to get proper results from our output, | |
278 | but do not change into or out of RAW mode | |
279 | so that no input is discarded. | |
280 | ||
281 | After doing this, either terminal_ours or terminal_inferior | |
282 | should be called to get back to a normal state of affairs. */ | |
283 | ||
284 | #define target_terminal_ours_for_output() \ | |
285 | (*current_target->to_terminal_ours_for_output) () | |
286 | ||
287 | /* Put our terminal settings into effect. | |
288 | First record the inferior's terminal settings | |
289 | so they can be restored properly later. */ | |
290 | ||
291 | #define target_terminal_ours() \ | |
292 | (*current_target->to_terminal_ours) () | |
293 | ||
294 | /* Print useful information about our terminal status, if such a thing | |
295 | exists. */ | |
296 | ||
297 | #define target_terminal_info(arg, from_tty) \ | |
298 | (*current_target->to_terminal_info) (arg, from_tty) | |
299 | ||
300 | /* Kill the inferior process. Make it go away. */ | |
301 | ||
302 | #define target_kill(arg, from_tty) \ | |
303 | (*current_target->to_kill) (arg, from_tty) | |
304 | ||
305 | /* Load an executable file into the target process. This is expected to | |
306 | not only bring new code into the target process, but also to update | |
307 | GDB's symbol tables to match. */ | |
308 | ||
309 | #define target_load(arg, from_tty) \ | |
310 | (*current_target->to_load) (arg, from_tty) | |
311 | ||
312 | /* Add the symbols from an executable file into GDB's symbol table, as if | |
313 | the file had been loaded at a particular address (or set of addresses). | |
314 | This does not change any state in the target system, only in GDB. */ | |
315 | ||
316 | #define target_add_syms(arg, from_tty) \ | |
317 | (*current_target->to_add_syms) (arg, from_tty) | |
318 | ||
319 | /* Perform a function call in the inferior. | |
320 | ARGS is a vector of values of arguments (NARGS of them). | |
321 | FUNCTION is a value, the function to be called. | |
322 | Returns a value representing what the function returned. | |
323 | May fail to return, if a breakpoint or signal is hit | |
324 | during the execution of the function. */ | |
325 | ||
326 | #define target_call_function(function, nargs, args) \ | |
327 | (*current_target->to_call_function) (function, nargs, args) | |
328 | ||
329 | /* Look up a symbol in the target's symbol table. NAME is the symbol | |
330 | name. ADDRP is a CORE_ADDR * pointing to where the value of the symbol | |
331 | should be returned. The result is 0 if successful, nonzero if the | |
332 | symbol does not exist in the target environment. This function should | |
333 | not call error() if communication with the target is interrupted, since | |
334 | it is called from symbol reading, but should return nonzero, possibly | |
335 | doing a complain(). */ | |
336 | ||
337 | #define target_lookup_symbol(name, addrp) \ | |
338 | (*current_target->to_lookup_symbol) (name, addrp) | |
339 | ||
340 | /* Start an inferior process and set inferior_pid to its pid. | |
341 | EXEC_FILE is the file to run. | |
342 | ALLARGS is a string containing the arguments to the program. | |
343 | ENV is the environment vector to pass. Errors reported with error(). | |
344 | On VxWorks and various standalone systems, we ignore exec_file. */ | |
345 | ||
346 | #define target_create_inferior(exec_file, args, env) \ | |
347 | (*current_target->to_create_inferior) (exec_file, args, env) | |
348 | ||
349 | /* The inferior process has died. Do what is right. */ | |
350 | ||
351 | #define target_mourn_inferior() \ | |
352 | (*current_target->to_mourn_inferior) () | |
353 | ||
354 | /* Pointer to next target in the chain, e.g. a core file and an exec file. */ | |
355 | ||
356 | #define target_next \ | |
357 | (current_target->to_next) | |
358 | ||
359 | /* Does the target include all of memory, or only part of it? This | |
360 | determines whether we look up the target chain for other parts of | |
361 | memory if this target can't satisfy a request. */ | |
362 | ||
363 | #define target_has_all_memory \ | |
364 | (current_target->to_has_all_memory) | |
365 | ||
366 | /* Does the target include memory? (Dummy targets don't.) */ | |
367 | ||
368 | #define target_has_memory \ | |
369 | (current_target->to_has_memory) | |
370 | ||
371 | /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until | |
372 | we start a process.) */ | |
373 | ||
374 | #define target_has_stack \ | |
375 | (current_target->to_has_stack) | |
376 | ||
377 | /* Does the target have registers? (Exec files don't.) */ | |
378 | ||
379 | #define target_has_registers \ | |
380 | (current_target->to_has_registers) | |
381 | ||
382 | /* Does the target have execution? Can we make it jump (through hoops), | |
383 | or pop its stack a few times, or set breakpoints? */ | |
384 | ||
385 | #define target_has_execution \ | |
386 | (current_target->to_has_execution) | |
387 | ||
388 | /* Routines for maintenance of the target structures... | |
389 | ||
390 | add_target: Add a target to the list of all possible targets. | |
391 | ||
392 | push_target: Make this target the top of the stack of currently used | |
393 | targets, within its particular stratum of the stack. Result | |
394 | is 0 if now atop the stack, nonzero if not on top (maybe | |
395 | should warn user). | |
396 | ||
397 | unpush_target: Remove this from the stack of currently used targets, | |
398 | no matter where it is on the list. Returns 0 if no | |
399 | change, 1 if removed from stack. | |
400 | ||
401 | pop_target: Remove the top thing on the stack of current targets. */ | |
402 | ||
403 | #ifdef __STDC__ | |
404 | void add_target (struct target_ops *); | |
405 | int push_target (struct target_ops *); | |
406 | int unpush_target (struct target_ops *); | |
9136fe49 JK |
407 | void target_preopen (int); |
408 | void pop_target (void); | |
bd5635a1 RP |
409 | #else |
410 | void add_target (); | |
411 | int push_target (); | |
412 | int unpush_target (); | |
9136fe49 | 413 | void target_preopen (); |
bd5635a1 RP |
414 | void pop_target (); |
415 | #endif |