Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Select target systems and architectures at runtime for GDB. |
7998dfc3 | 2 | |
6aba47ca | 3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
4c38e0a4 | 4 | 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
f6519ebc | 5 | Free Software Foundation, Inc. |
7998dfc3 | 6 | |
c906108c SS |
7 | Contributed by Cygnus Support. |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 14 | (at your option) any later version. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b | 21 | You should have received a copy of the GNU General Public License |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
23 | |
24 | #include "defs.h" | |
25 | #include <errno.h> | |
c906108c SS |
26 | #include "gdb_string.h" |
27 | #include "target.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "symtab.h" | |
30 | #include "inferior.h" | |
31 | #include "bfd.h" | |
32 | #include "symfile.h" | |
33 | #include "objfiles.h" | |
03f2053f | 34 | #include "gdb_wait.h" |
4930751a | 35 | #include "dcache.h" |
c906108c | 36 | #include <signal.h> |
4e052eda | 37 | #include "regcache.h" |
0088c768 | 38 | #include "gdb_assert.h" |
b6591e8b | 39 | #include "gdbcore.h" |
9e35dae4 | 40 | #include "exceptions.h" |
424163ea | 41 | #include "target-descriptions.h" |
e1ac3328 | 42 | #include "gdbthread.h" |
b9db4ced | 43 | #include "solib.h" |
07b82ea5 | 44 | #include "exec.h" |
edb3359d | 45 | #include "inline-frame.h" |
2f4d8875 | 46 | #include "tracepoint.h" |
c906108c | 47 | |
a14ed312 | 48 | static void target_info (char *, int); |
c906108c | 49 | |
a14ed312 | 50 | static void default_terminal_info (char *, int); |
c906108c | 51 | |
5009afc5 AS |
52 | static int default_watchpoint_addr_within_range (struct target_ops *, |
53 | CORE_ADDR, CORE_ADDR, int); | |
54 | ||
e0d24f8d WZ |
55 | static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int); |
56 | ||
a14ed312 | 57 | static int nosymbol (char *, CORE_ADDR *); |
c906108c | 58 | |
c25c4a8b | 59 | static void tcomplain (void) ATTRIBUTE_NORETURN; |
c906108c | 60 | |
a14ed312 | 61 | static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *); |
c906108c | 62 | |
a14ed312 | 63 | static int return_zero (void); |
c906108c | 64 | |
a14ed312 | 65 | static int return_one (void); |
c906108c | 66 | |
ccaa32c7 GS |
67 | static int return_minus_one (void); |
68 | ||
a14ed312 | 69 | void target_ignore (void); |
c906108c | 70 | |
a14ed312 | 71 | static void target_command (char *, int); |
c906108c | 72 | |
a14ed312 | 73 | static struct target_ops *find_default_run_target (char *); |
c906108c | 74 | |
4b8a223f | 75 | static LONGEST default_xfer_partial (struct target_ops *ops, |
0088c768 | 76 | enum target_object object, |
1b0ba102 AC |
77 | const char *annex, gdb_byte *readbuf, |
78 | const gdb_byte *writebuf, | |
8aa91c1e | 79 | ULONGEST offset, LONGEST len); |
0088c768 | 80 | |
cf7a04e8 DJ |
81 | static LONGEST current_xfer_partial (struct target_ops *ops, |
82 | enum target_object object, | |
83 | const char *annex, gdb_byte *readbuf, | |
84 | const gdb_byte *writebuf, | |
85 | ULONGEST offset, LONGEST len); | |
c906108c | 86 | |
cf7a04e8 DJ |
87 | static LONGEST target_xfer_partial (struct target_ops *ops, |
88 | enum target_object object, | |
89 | const char *annex, | |
90 | void *readbuf, const void *writebuf, | |
91 | ULONGEST offset, LONGEST len); | |
c906108c | 92 | |
c2250ad1 UW |
93 | static struct gdbarch *default_thread_architecture (struct target_ops *ops, |
94 | ptid_t ptid); | |
95 | ||
a14ed312 | 96 | static void init_dummy_target (void); |
c906108c | 97 | |
aa869812 AC |
98 | static struct target_ops debug_target; |
99 | ||
a14ed312 | 100 | static void debug_to_open (char *, int); |
c906108c | 101 | |
316f2060 | 102 | static void debug_to_prepare_to_store (struct regcache *); |
c906108c | 103 | |
a14ed312 | 104 | static void debug_to_files_info (struct target_ops *); |
c906108c | 105 | |
a6d9a66e UW |
106 | static int debug_to_insert_breakpoint (struct gdbarch *, |
107 | struct bp_target_info *); | |
c906108c | 108 | |
a6d9a66e UW |
109 | static int debug_to_remove_breakpoint (struct gdbarch *, |
110 | struct bp_target_info *); | |
c906108c | 111 | |
ccaa32c7 GS |
112 | static int debug_to_can_use_hw_breakpoint (int, int, int); |
113 | ||
a6d9a66e UW |
114 | static int debug_to_insert_hw_breakpoint (struct gdbarch *, |
115 | struct bp_target_info *); | |
ccaa32c7 | 116 | |
a6d9a66e UW |
117 | static int debug_to_remove_hw_breakpoint (struct gdbarch *, |
118 | struct bp_target_info *); | |
ccaa32c7 GS |
119 | |
120 | static int debug_to_insert_watchpoint (CORE_ADDR, int, int); | |
121 | ||
122 | static int debug_to_remove_watchpoint (CORE_ADDR, int, int); | |
123 | ||
124 | static int debug_to_stopped_by_watchpoint (void); | |
125 | ||
4aa7a7f5 | 126 | static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *); |
ccaa32c7 | 127 | |
5009afc5 AS |
128 | static int debug_to_watchpoint_addr_within_range (struct target_ops *, |
129 | CORE_ADDR, CORE_ADDR, int); | |
130 | ||
e0d24f8d WZ |
131 | static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, int); |
132 | ||
a14ed312 | 133 | static void debug_to_terminal_init (void); |
c906108c | 134 | |
a14ed312 | 135 | static void debug_to_terminal_inferior (void); |
c906108c | 136 | |
a14ed312 | 137 | static void debug_to_terminal_ours_for_output (void); |
c906108c | 138 | |
a790ad35 SC |
139 | static void debug_to_terminal_save_ours (void); |
140 | ||
a14ed312 | 141 | static void debug_to_terminal_ours (void); |
c906108c | 142 | |
a14ed312 | 143 | static void debug_to_terminal_info (char *, int); |
c906108c | 144 | |
a14ed312 | 145 | static void debug_to_load (char *, int); |
c906108c | 146 | |
a14ed312 | 147 | static int debug_to_lookup_symbol (char *, CORE_ADDR *); |
c906108c | 148 | |
a14ed312 | 149 | static int debug_to_can_run (void); |
c906108c | 150 | |
39f77062 | 151 | static void debug_to_notice_signals (ptid_t); |
c906108c | 152 | |
94cc34af | 153 | static void debug_to_stop (ptid_t); |
c906108c | 154 | |
5ac10fd1 AC |
155 | /* NOTE: cagney/2004-09-29: Many targets reference this variable in |
156 | wierd and mysterious ways. Putting the variable here lets those | |
157 | wierd and mysterious ways keep building while they are being | |
158 | converted to the inferior inheritance structure. */ | |
1df84f13 | 159 | struct target_ops deprecated_child_ops; |
5ac10fd1 | 160 | |
c906108c | 161 | /* Pointer to array of target architecture structures; the size of the |
2bc416ba | 162 | array; the current index into the array; the allocated size of the |
c906108c SS |
163 | array. */ |
164 | struct target_ops **target_structs; | |
165 | unsigned target_struct_size; | |
166 | unsigned target_struct_index; | |
167 | unsigned target_struct_allocsize; | |
168 | #define DEFAULT_ALLOCSIZE 10 | |
169 | ||
170 | /* The initial current target, so that there is always a semi-valid | |
171 | current target. */ | |
172 | ||
173 | static struct target_ops dummy_target; | |
174 | ||
175 | /* Top of target stack. */ | |
176 | ||
258b763a | 177 | static struct target_ops *target_stack; |
c906108c SS |
178 | |
179 | /* The target structure we are currently using to talk to a process | |
180 | or file or whatever "inferior" we have. */ | |
181 | ||
182 | struct target_ops current_target; | |
183 | ||
184 | /* Command list for target. */ | |
185 | ||
186 | static struct cmd_list_element *targetlist = NULL; | |
187 | ||
cf7a04e8 DJ |
188 | /* Nonzero if we should trust readonly sections from the |
189 | executable when reading memory. */ | |
190 | ||
191 | static int trust_readonly = 0; | |
192 | ||
8defab1a DJ |
193 | /* Nonzero if we should show true memory content including |
194 | memory breakpoint inserted by gdb. */ | |
195 | ||
196 | static int show_memory_breakpoints = 0; | |
197 | ||
d914c394 SS |
198 | /* These globals control whether GDB attempts to perform these |
199 | operations; they are useful for targets that need to prevent | |
200 | inadvertant disruption, such as in non-stop mode. */ | |
201 | ||
202 | int may_write_registers = 1; | |
203 | ||
204 | int may_write_memory = 1; | |
205 | ||
206 | int may_insert_breakpoints = 1; | |
207 | ||
208 | int may_insert_tracepoints = 1; | |
209 | ||
210 | int may_insert_fast_tracepoints = 1; | |
211 | ||
212 | int may_stop = 1; | |
213 | ||
c906108c SS |
214 | /* Non-zero if we want to see trace of target level stuff. */ |
215 | ||
216 | static int targetdebug = 0; | |
920d2a44 AC |
217 | static void |
218 | show_targetdebug (struct ui_file *file, int from_tty, | |
219 | struct cmd_list_element *c, const char *value) | |
220 | { | |
221 | fprintf_filtered (file, _("Target debugging is %s.\n"), value); | |
222 | } | |
c906108c | 223 | |
a14ed312 | 224 | static void setup_target_debug (void); |
c906108c | 225 | |
4e5d721f DE |
226 | /* The option sets this. */ |
227 | static int stack_cache_enabled_p_1 = 1; | |
228 | /* And set_stack_cache_enabled_p updates this. | |
229 | The reason for the separation is so that we don't flush the cache for | |
230 | on->on transitions. */ | |
231 | static int stack_cache_enabled_p = 1; | |
232 | ||
233 | /* This is called *after* the stack-cache has been set. | |
234 | Flush the cache for off->on and on->off transitions. | |
235 | There's no real need to flush the cache for on->off transitions, | |
236 | except cleanliness. */ | |
237 | ||
238 | static void | |
239 | set_stack_cache_enabled_p (char *args, int from_tty, | |
240 | struct cmd_list_element *c) | |
241 | { | |
242 | if (stack_cache_enabled_p != stack_cache_enabled_p_1) | |
243 | target_dcache_invalidate (); | |
244 | ||
245 | stack_cache_enabled_p = stack_cache_enabled_p_1; | |
246 | } | |
247 | ||
248 | static void | |
249 | show_stack_cache_enabled_p (struct ui_file *file, int from_tty, | |
250 | struct cmd_list_element *c, const char *value) | |
251 | { | |
252 | fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value); | |
253 | } | |
254 | ||
255 | /* Cache of memory operations, to speed up remote access. */ | |
256 | static DCACHE *target_dcache; | |
257 | ||
258 | /* Invalidate the target dcache. */ | |
259 | ||
260 | void | |
261 | target_dcache_invalidate (void) | |
262 | { | |
263 | dcache_invalidate (target_dcache); | |
264 | } | |
4930751a | 265 | |
c906108c SS |
266 | /* The user just typed 'target' without the name of a target. */ |
267 | ||
c906108c | 268 | static void |
fba45db2 | 269 | target_command (char *arg, int from_tty) |
c906108c SS |
270 | { |
271 | fputs_filtered ("Argument required (target name). Try `help target'\n", | |
272 | gdb_stdout); | |
273 | } | |
274 | ||
c35b1492 PA |
275 | /* Default target_has_* methods for process_stratum targets. */ |
276 | ||
277 | int | |
278 | default_child_has_all_memory (struct target_ops *ops) | |
279 | { | |
280 | /* If no inferior selected, then we can't read memory here. */ | |
281 | if (ptid_equal (inferior_ptid, null_ptid)) | |
282 | return 0; | |
283 | ||
284 | return 1; | |
285 | } | |
286 | ||
287 | int | |
288 | default_child_has_memory (struct target_ops *ops) | |
289 | { | |
290 | /* If no inferior selected, then we can't read memory here. */ | |
291 | if (ptid_equal (inferior_ptid, null_ptid)) | |
292 | return 0; | |
293 | ||
294 | return 1; | |
295 | } | |
296 | ||
297 | int | |
298 | default_child_has_stack (struct target_ops *ops) | |
299 | { | |
300 | /* If no inferior selected, there's no stack. */ | |
301 | if (ptid_equal (inferior_ptid, null_ptid)) | |
302 | return 0; | |
303 | ||
304 | return 1; | |
305 | } | |
306 | ||
307 | int | |
308 | default_child_has_registers (struct target_ops *ops) | |
309 | { | |
310 | /* Can't read registers from no inferior. */ | |
311 | if (ptid_equal (inferior_ptid, null_ptid)) | |
312 | return 0; | |
313 | ||
314 | return 1; | |
315 | } | |
316 | ||
317 | int | |
318 | default_child_has_execution (struct target_ops *ops) | |
319 | { | |
320 | /* If there's no thread selected, then we can't make it run through | |
321 | hoops. */ | |
322 | if (ptid_equal (inferior_ptid, null_ptid)) | |
323 | return 0; | |
324 | ||
325 | return 1; | |
326 | } | |
327 | ||
328 | ||
329 | int | |
330 | target_has_all_memory_1 (void) | |
331 | { | |
332 | struct target_ops *t; | |
333 | ||
334 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
335 | if (t->to_has_all_memory (t)) | |
336 | return 1; | |
337 | ||
338 | return 0; | |
339 | } | |
340 | ||
341 | int | |
342 | target_has_memory_1 (void) | |
343 | { | |
344 | struct target_ops *t; | |
345 | ||
346 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
347 | if (t->to_has_memory (t)) | |
348 | return 1; | |
349 | ||
350 | return 0; | |
351 | } | |
352 | ||
353 | int | |
354 | target_has_stack_1 (void) | |
355 | { | |
356 | struct target_ops *t; | |
357 | ||
358 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
359 | if (t->to_has_stack (t)) | |
360 | return 1; | |
361 | ||
362 | return 0; | |
363 | } | |
364 | ||
365 | int | |
366 | target_has_registers_1 (void) | |
367 | { | |
368 | struct target_ops *t; | |
369 | ||
370 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
371 | if (t->to_has_registers (t)) | |
372 | return 1; | |
373 | ||
374 | return 0; | |
375 | } | |
376 | ||
377 | int | |
378 | target_has_execution_1 (void) | |
379 | { | |
380 | struct target_ops *t; | |
381 | ||
382 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
383 | if (t->to_has_execution (t)) | |
384 | return 1; | |
385 | ||
386 | return 0; | |
387 | } | |
388 | ||
c906108c SS |
389 | /* Add a possible target architecture to the list. */ |
390 | ||
391 | void | |
fba45db2 | 392 | add_target (struct target_ops *t) |
c906108c | 393 | { |
0088c768 | 394 | /* Provide default values for all "must have" methods. */ |
0b603eba AC |
395 | if (t->to_xfer_partial == NULL) |
396 | t->to_xfer_partial = default_xfer_partial; | |
0088c768 | 397 | |
c35b1492 PA |
398 | if (t->to_has_all_memory == NULL) |
399 | t->to_has_all_memory = (int (*) (struct target_ops *)) return_zero; | |
400 | ||
401 | if (t->to_has_memory == NULL) | |
402 | t->to_has_memory = (int (*) (struct target_ops *)) return_zero; | |
403 | ||
404 | if (t->to_has_stack == NULL) | |
405 | t->to_has_stack = (int (*) (struct target_ops *)) return_zero; | |
406 | ||
407 | if (t->to_has_registers == NULL) | |
408 | t->to_has_registers = (int (*) (struct target_ops *)) return_zero; | |
409 | ||
410 | if (t->to_has_execution == NULL) | |
411 | t->to_has_execution = (int (*) (struct target_ops *)) return_zero; | |
412 | ||
c906108c SS |
413 | if (!target_structs) |
414 | { | |
415 | target_struct_allocsize = DEFAULT_ALLOCSIZE; | |
416 | target_structs = (struct target_ops **) xmalloc | |
417 | (target_struct_allocsize * sizeof (*target_structs)); | |
418 | } | |
419 | if (target_struct_size >= target_struct_allocsize) | |
420 | { | |
421 | target_struct_allocsize *= 2; | |
422 | target_structs = (struct target_ops **) | |
c5aa993b JM |
423 | xrealloc ((char *) target_structs, |
424 | target_struct_allocsize * sizeof (*target_structs)); | |
c906108c SS |
425 | } |
426 | target_structs[target_struct_size++] = t; | |
c906108c SS |
427 | |
428 | if (targetlist == NULL) | |
1bedd215 AC |
429 | add_prefix_cmd ("target", class_run, target_command, _("\ |
430 | Connect to a target machine or process.\n\ | |
c906108c SS |
431 | The first argument is the type or protocol of the target machine.\n\ |
432 | Remaining arguments are interpreted by the target protocol. For more\n\ | |
433 | information on the arguments for a particular protocol, type\n\ | |
1bedd215 | 434 | `help target ' followed by the protocol name."), |
c906108c SS |
435 | &targetlist, "target ", 0, &cmdlist); |
436 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); | |
437 | } | |
438 | ||
439 | /* Stub functions */ | |
440 | ||
441 | void | |
fba45db2 | 442 | target_ignore (void) |
c906108c SS |
443 | { |
444 | } | |
445 | ||
7d85a9c0 JB |
446 | void |
447 | target_kill (void) | |
448 | { | |
449 | struct target_ops *t; | |
450 | ||
451 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
452 | if (t->to_kill != NULL) | |
453 | { | |
454 | if (targetdebug) | |
455 | fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); | |
456 | ||
457 | t->to_kill (t); | |
458 | return; | |
459 | } | |
460 | ||
461 | noprocess (); | |
462 | } | |
463 | ||
11cf8741 JM |
464 | void |
465 | target_load (char *arg, int from_tty) | |
466 | { | |
4e5d721f | 467 | target_dcache_invalidate (); |
11cf8741 JM |
468 | (*current_target.to_load) (arg, from_tty); |
469 | } | |
470 | ||
947b8855 PA |
471 | void |
472 | target_create_inferior (char *exec_file, char *args, | |
473 | char **env, int from_tty) | |
136d6dae VP |
474 | { |
475 | struct target_ops *t; | |
5d502164 | 476 | |
136d6dae VP |
477 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
478 | { | |
479 | if (t->to_create_inferior != NULL) | |
480 | { | |
481 | t->to_create_inferior (t, exec_file, args, env, from_tty); | |
947b8855 PA |
482 | if (targetdebug) |
483 | fprintf_unfiltered (gdb_stdlog, | |
484 | "target_create_inferior (%s, %s, xxx, %d)\n", | |
485 | exec_file, args, from_tty); | |
136d6dae VP |
486 | return; |
487 | } | |
488 | } | |
489 | ||
490 | internal_error (__FILE__, __LINE__, | |
491 | "could not find a target to create inferior"); | |
492 | } | |
493 | ||
d9d2d8b6 PA |
494 | void |
495 | target_terminal_inferior (void) | |
496 | { | |
497 | /* A background resume (``run&'') should leave GDB in control of the | |
ba7f6c64 VP |
498 | terminal. Use target_can_async_p, not target_is_async_p, since at |
499 | this point the target is not async yet. However, if sync_execution | |
500 | is not set, we know it will become async prior to resume. */ | |
501 | if (target_can_async_p () && !sync_execution) | |
d9d2d8b6 PA |
502 | return; |
503 | ||
504 | /* If GDB is resuming the inferior in the foreground, install | |
505 | inferior's terminal modes. */ | |
506 | (*current_target.to_terminal_inferior) (); | |
507 | } | |
136d6dae | 508 | |
c906108c | 509 | static int |
fba45db2 KB |
510 | nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
511 | struct target_ops *t) | |
c906108c | 512 | { |
c5aa993b JM |
513 | errno = EIO; /* Can't read/write this location */ |
514 | return 0; /* No bytes handled */ | |
c906108c SS |
515 | } |
516 | ||
517 | static void | |
fba45db2 | 518 | tcomplain (void) |
c906108c | 519 | { |
8a3fe4f8 | 520 | error (_("You can't do that when your target is `%s'"), |
c906108c SS |
521 | current_target.to_shortname); |
522 | } | |
523 | ||
524 | void | |
fba45db2 | 525 | noprocess (void) |
c906108c | 526 | { |
8a3fe4f8 | 527 | error (_("You can't do that without a process to debug.")); |
c906108c SS |
528 | } |
529 | ||
c906108c | 530 | static int |
fba45db2 | 531 | nosymbol (char *name, CORE_ADDR *addrp) |
c906108c | 532 | { |
c5aa993b | 533 | return 1; /* Symbol does not exist in target env */ |
c906108c SS |
534 | } |
535 | ||
c906108c | 536 | static void |
fba45db2 | 537 | default_terminal_info (char *args, int from_tty) |
c906108c | 538 | { |
a3f17187 | 539 | printf_unfiltered (_("No saved terminal information.\n")); |
c906108c SS |
540 | } |
541 | ||
0ef643c8 JB |
542 | /* A default implementation for the to_get_ada_task_ptid target method. |
543 | ||
544 | This function builds the PTID by using both LWP and TID as part of | |
545 | the PTID lwp and tid elements. The pid used is the pid of the | |
546 | inferior_ptid. */ | |
547 | ||
2c0b251b | 548 | static ptid_t |
0ef643c8 JB |
549 | default_get_ada_task_ptid (long lwp, long tid) |
550 | { | |
551 | return ptid_build (ptid_get_pid (inferior_ptid), lwp, tid); | |
552 | } | |
553 | ||
7998dfc3 AC |
554 | /* Go through the target stack from top to bottom, copying over zero |
555 | entries in current_target, then filling in still empty entries. In | |
556 | effect, we are doing class inheritance through the pushed target | |
557 | vectors. | |
558 | ||
559 | NOTE: cagney/2003-10-17: The problem with this inheritance, as it | |
560 | is currently implemented, is that it discards any knowledge of | |
561 | which target an inherited method originally belonged to. | |
562 | Consequently, new new target methods should instead explicitly and | |
563 | locally search the target stack for the target that can handle the | |
564 | request. */ | |
c906108c SS |
565 | |
566 | static void | |
7998dfc3 | 567 | update_current_target (void) |
c906108c | 568 | { |
7998dfc3 AC |
569 | struct target_ops *t; |
570 | ||
08d8bcd7 | 571 | /* First, reset current's contents. */ |
7998dfc3 AC |
572 | memset (¤t_target, 0, sizeof (current_target)); |
573 | ||
574 | #define INHERIT(FIELD, TARGET) \ | |
575 | if (!current_target.FIELD) \ | |
576 | current_target.FIELD = (TARGET)->FIELD | |
577 | ||
578 | for (t = target_stack; t; t = t->beneath) | |
579 | { | |
580 | INHERIT (to_shortname, t); | |
581 | INHERIT (to_longname, t); | |
582 | INHERIT (to_doc, t); | |
b52323fa UW |
583 | /* Do not inherit to_open. */ |
584 | /* Do not inherit to_close. */ | |
136d6dae | 585 | /* Do not inherit to_attach. */ |
7998dfc3 | 586 | INHERIT (to_post_attach, t); |
dc177b7a | 587 | INHERIT (to_attach_no_wait, t); |
136d6dae | 588 | /* Do not inherit to_detach. */ |
597320e7 | 589 | /* Do not inherit to_disconnect. */ |
28439f5e | 590 | /* Do not inherit to_resume. */ |
117de6a9 | 591 | /* Do not inherit to_wait. */ |
28439f5e PA |
592 | /* Do not inherit to_fetch_registers. */ |
593 | /* Do not inherit to_store_registers. */ | |
7998dfc3 | 594 | INHERIT (to_prepare_to_store, t); |
c8e73a31 | 595 | INHERIT (deprecated_xfer_memory, t); |
7998dfc3 AC |
596 | INHERIT (to_files_info, t); |
597 | INHERIT (to_insert_breakpoint, t); | |
598 | INHERIT (to_remove_breakpoint, t); | |
599 | INHERIT (to_can_use_hw_breakpoint, t); | |
600 | INHERIT (to_insert_hw_breakpoint, t); | |
601 | INHERIT (to_remove_hw_breakpoint, t); | |
602 | INHERIT (to_insert_watchpoint, t); | |
603 | INHERIT (to_remove_watchpoint, t); | |
604 | INHERIT (to_stopped_data_address, t); | |
74174d2e | 605 | INHERIT (to_have_steppable_watchpoint, t); |
7998dfc3 | 606 | INHERIT (to_have_continuable_watchpoint, t); |
5009afc5 AS |
607 | INHERIT (to_stopped_by_watchpoint, t); |
608 | INHERIT (to_watchpoint_addr_within_range, t); | |
e0d24f8d | 609 | INHERIT (to_region_ok_for_hw_watchpoint, t); |
7998dfc3 AC |
610 | INHERIT (to_terminal_init, t); |
611 | INHERIT (to_terminal_inferior, t); | |
612 | INHERIT (to_terminal_ours_for_output, t); | |
613 | INHERIT (to_terminal_ours, t); | |
614 | INHERIT (to_terminal_save_ours, t); | |
615 | INHERIT (to_terminal_info, t); | |
7d85a9c0 | 616 | /* Do not inherit to_kill. */ |
7998dfc3 AC |
617 | INHERIT (to_load, t); |
618 | INHERIT (to_lookup_symbol, t); | |
136d6dae | 619 | /* Do no inherit to_create_inferior. */ |
7998dfc3 AC |
620 | INHERIT (to_post_startup_inferior, t); |
621 | INHERIT (to_acknowledge_created_inferior, t); | |
622 | INHERIT (to_insert_fork_catchpoint, t); | |
623 | INHERIT (to_remove_fork_catchpoint, t); | |
624 | INHERIT (to_insert_vfork_catchpoint, t); | |
625 | INHERIT (to_remove_vfork_catchpoint, t); | |
ee057212 | 626 | /* Do not inherit to_follow_fork. */ |
7998dfc3 AC |
627 | INHERIT (to_insert_exec_catchpoint, t); |
628 | INHERIT (to_remove_exec_catchpoint, t); | |
a96d9b2e | 629 | INHERIT (to_set_syscall_catchpoint, t); |
7998dfc3 | 630 | INHERIT (to_has_exited, t); |
82892036 | 631 | /* Do not inherit to_mourn_inferior. */ |
7998dfc3 AC |
632 | INHERIT (to_can_run, t); |
633 | INHERIT (to_notice_signals, t); | |
28439f5e PA |
634 | /* Do not inherit to_thread_alive. */ |
635 | /* Do not inherit to_find_new_threads. */ | |
117de6a9 | 636 | /* Do not inherit to_pid_to_str. */ |
7998dfc3 AC |
637 | INHERIT (to_extra_thread_info, t); |
638 | INHERIT (to_stop, t); | |
4b8a223f | 639 | /* Do not inherit to_xfer_partial. */ |
7998dfc3 | 640 | INHERIT (to_rcmd, t); |
7998dfc3 | 641 | INHERIT (to_pid_to_exec_file, t); |
49d03eab | 642 | INHERIT (to_log_command, t); |
7998dfc3 | 643 | INHERIT (to_stratum, t); |
c35b1492 PA |
644 | /* Do not inherit to_has_all_memory */ |
645 | /* Do not inherit to_has_memory */ | |
646 | /* Do not inherit to_has_stack */ | |
647 | /* Do not inherit to_has_registers */ | |
648 | /* Do not inherit to_has_execution */ | |
7998dfc3 | 649 | INHERIT (to_has_thread_control, t); |
7998dfc3 AC |
650 | INHERIT (to_can_async_p, t); |
651 | INHERIT (to_is_async_p, t); | |
652 | INHERIT (to_async, t); | |
b84876c2 | 653 | INHERIT (to_async_mask, t); |
7998dfc3 AC |
654 | INHERIT (to_find_memory_regions, t); |
655 | INHERIT (to_make_corefile_notes, t); | |
6b04bdb7 MS |
656 | INHERIT (to_get_bookmark, t); |
657 | INHERIT (to_goto_bookmark, t); | |
117de6a9 | 658 | /* Do not inherit to_get_thread_local_address. */ |
b2175913 | 659 | INHERIT (to_can_execute_reverse, t); |
c2250ad1 | 660 | INHERIT (to_thread_architecture, t); |
424163ea | 661 | /* Do not inherit to_read_description. */ |
0ef643c8 | 662 | INHERIT (to_get_ada_task_ptid, t); |
08388c79 | 663 | /* Do not inherit to_search_memory. */ |
8a305172 | 664 | INHERIT (to_supports_multi_process, t); |
35b1e5cc SS |
665 | INHERIT (to_trace_init, t); |
666 | INHERIT (to_download_tracepoint, t); | |
667 | INHERIT (to_download_trace_state_variable, t); | |
668 | INHERIT (to_trace_set_readonly_regions, t); | |
669 | INHERIT (to_trace_start, t); | |
670 | INHERIT (to_get_trace_status, t); | |
671 | INHERIT (to_trace_stop, t); | |
672 | INHERIT (to_trace_find, t); | |
673 | INHERIT (to_get_trace_state_variable_value, t); | |
00bf0b85 SS |
674 | INHERIT (to_save_trace_data, t); |
675 | INHERIT (to_upload_tracepoints, t); | |
676 | INHERIT (to_upload_trace_state_variables, t); | |
677 | INHERIT (to_get_raw_trace_data, t); | |
35b1e5cc | 678 | INHERIT (to_set_disconnected_tracing, t); |
4daf5ac0 | 679 | INHERIT (to_set_circular_trace_buffer, t); |
711e434b | 680 | INHERIT (to_get_tib_address, t); |
d914c394 | 681 | INHERIT (to_set_permissions, t); |
7998dfc3 | 682 | INHERIT (to_magic, t); |
fd79ecee | 683 | /* Do not inherit to_memory_map. */ |
a76d924d DJ |
684 | /* Do not inherit to_flash_erase. */ |
685 | /* Do not inherit to_flash_done. */ | |
7998dfc3 AC |
686 | } |
687 | #undef INHERIT | |
688 | ||
689 | /* Clean up a target struct so it no longer has any zero pointers in | |
0088c768 AC |
690 | it. Some entries are defaulted to a method that print an error, |
691 | others are hard-wired to a standard recursive default. */ | |
c906108c SS |
692 | |
693 | #define de_fault(field, value) \ | |
7998dfc3 AC |
694 | if (!current_target.field) \ |
695 | current_target.field = value | |
0d06e24b | 696 | |
2bc416ba DJ |
697 | de_fault (to_open, |
698 | (void (*) (char *, int)) | |
0d06e24b | 699 | tcomplain); |
2bc416ba DJ |
700 | de_fault (to_close, |
701 | (void (*) (int)) | |
0d06e24b | 702 | target_ignore); |
2bc416ba DJ |
703 | de_fault (to_post_attach, |
704 | (void (*) (int)) | |
0d06e24b | 705 | target_ignore); |
2bc416ba | 706 | de_fault (to_prepare_to_store, |
316f2060 | 707 | (void (*) (struct regcache *)) |
0d06e24b | 708 | noprocess); |
2bc416ba DJ |
709 | de_fault (deprecated_xfer_memory, |
710 | (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *)) | |
0d06e24b | 711 | nomemory); |
2bc416ba DJ |
712 | de_fault (to_files_info, |
713 | (void (*) (struct target_ops *)) | |
0d06e24b | 714 | target_ignore); |
2bc416ba | 715 | de_fault (to_insert_breakpoint, |
0d06e24b | 716 | memory_insert_breakpoint); |
2bc416ba | 717 | de_fault (to_remove_breakpoint, |
0d06e24b | 718 | memory_remove_breakpoint); |
ccaa32c7 GS |
719 | de_fault (to_can_use_hw_breakpoint, |
720 | (int (*) (int, int, int)) | |
721 | return_zero); | |
722 | de_fault (to_insert_hw_breakpoint, | |
a6d9a66e | 723 | (int (*) (struct gdbarch *, struct bp_target_info *)) |
ccaa32c7 GS |
724 | return_minus_one); |
725 | de_fault (to_remove_hw_breakpoint, | |
a6d9a66e | 726 | (int (*) (struct gdbarch *, struct bp_target_info *)) |
ccaa32c7 GS |
727 | return_minus_one); |
728 | de_fault (to_insert_watchpoint, | |
729 | (int (*) (CORE_ADDR, int, int)) | |
730 | return_minus_one); | |
731 | de_fault (to_remove_watchpoint, | |
732 | (int (*) (CORE_ADDR, int, int)) | |
733 | return_minus_one); | |
734 | de_fault (to_stopped_by_watchpoint, | |
735 | (int (*) (void)) | |
736 | return_zero); | |
737 | de_fault (to_stopped_data_address, | |
4aa7a7f5 | 738 | (int (*) (struct target_ops *, CORE_ADDR *)) |
ccaa32c7 | 739 | return_zero); |
5009afc5 AS |
740 | de_fault (to_watchpoint_addr_within_range, |
741 | default_watchpoint_addr_within_range); | |
e0d24f8d WZ |
742 | de_fault (to_region_ok_for_hw_watchpoint, |
743 | default_region_ok_for_hw_watchpoint); | |
2bc416ba DJ |
744 | de_fault (to_terminal_init, |
745 | (void (*) (void)) | |
0d06e24b | 746 | target_ignore); |
2bc416ba DJ |
747 | de_fault (to_terminal_inferior, |
748 | (void (*) (void)) | |
0d06e24b | 749 | target_ignore); |
2bc416ba DJ |
750 | de_fault (to_terminal_ours_for_output, |
751 | (void (*) (void)) | |
0d06e24b | 752 | target_ignore); |
2bc416ba DJ |
753 | de_fault (to_terminal_ours, |
754 | (void (*) (void)) | |
0d06e24b | 755 | target_ignore); |
2bc416ba DJ |
756 | de_fault (to_terminal_save_ours, |
757 | (void (*) (void)) | |
a790ad35 | 758 | target_ignore); |
2bc416ba | 759 | de_fault (to_terminal_info, |
0d06e24b | 760 | default_terminal_info); |
2bc416ba DJ |
761 | de_fault (to_load, |
762 | (void (*) (char *, int)) | |
0d06e24b | 763 | tcomplain); |
2bc416ba DJ |
764 | de_fault (to_lookup_symbol, |
765 | (int (*) (char *, CORE_ADDR *)) | |
0d06e24b | 766 | nosymbol); |
2bc416ba DJ |
767 | de_fault (to_post_startup_inferior, |
768 | (void (*) (ptid_t)) | |
0d06e24b | 769 | target_ignore); |
2bc416ba DJ |
770 | de_fault (to_acknowledge_created_inferior, |
771 | (void (*) (int)) | |
0d06e24b | 772 | target_ignore); |
2bc416ba DJ |
773 | de_fault (to_insert_fork_catchpoint, |
774 | (void (*) (int)) | |
0d06e24b | 775 | tcomplain); |
2bc416ba DJ |
776 | de_fault (to_remove_fork_catchpoint, |
777 | (int (*) (int)) | |
0d06e24b | 778 | tcomplain); |
2bc416ba DJ |
779 | de_fault (to_insert_vfork_catchpoint, |
780 | (void (*) (int)) | |
0d06e24b | 781 | tcomplain); |
2bc416ba DJ |
782 | de_fault (to_remove_vfork_catchpoint, |
783 | (int (*) (int)) | |
0d06e24b | 784 | tcomplain); |
2bc416ba DJ |
785 | de_fault (to_insert_exec_catchpoint, |
786 | (void (*) (int)) | |
0d06e24b | 787 | tcomplain); |
2bc416ba DJ |
788 | de_fault (to_remove_exec_catchpoint, |
789 | (int (*) (int)) | |
0d06e24b | 790 | tcomplain); |
a96d9b2e SDJ |
791 | de_fault (to_set_syscall_catchpoint, |
792 | (int (*) (int, int, int, int, int *)) | |
793 | tcomplain); | |
2bc416ba DJ |
794 | de_fault (to_has_exited, |
795 | (int (*) (int, int, int *)) | |
0d06e24b | 796 | return_zero); |
2bc416ba | 797 | de_fault (to_can_run, |
0d06e24b | 798 | return_zero); |
2bc416ba DJ |
799 | de_fault (to_notice_signals, |
800 | (void (*) (ptid_t)) | |
0d06e24b | 801 | target_ignore); |
2bc416ba DJ |
802 | de_fault (to_extra_thread_info, |
803 | (char *(*) (struct thread_info *)) | |
0d06e24b | 804 | return_zero); |
2bc416ba | 805 | de_fault (to_stop, |
94cc34af | 806 | (void (*) (ptid_t)) |
0d06e24b | 807 | target_ignore); |
cf7a04e8 | 808 | current_target.to_xfer_partial = current_xfer_partial; |
2bc416ba DJ |
809 | de_fault (to_rcmd, |
810 | (void (*) (char *, struct ui_file *)) | |
0d06e24b | 811 | tcomplain); |
2bc416ba DJ |
812 | de_fault (to_pid_to_exec_file, |
813 | (char *(*) (int)) | |
0d06e24b | 814 | return_zero); |
2bc416ba DJ |
815 | de_fault (to_async, |
816 | (void (*) (void (*) (enum inferior_event_type, void*), void*)) | |
0d06e24b | 817 | tcomplain); |
b84876c2 PA |
818 | de_fault (to_async_mask, |
819 | (int (*) (int)) | |
820 | return_one); | |
c2250ad1 UW |
821 | de_fault (to_thread_architecture, |
822 | default_thread_architecture); | |
424163ea | 823 | current_target.to_read_description = NULL; |
0ef643c8 JB |
824 | de_fault (to_get_ada_task_ptid, |
825 | (ptid_t (*) (long, long)) | |
826 | default_get_ada_task_ptid); | |
8a305172 PA |
827 | de_fault (to_supports_multi_process, |
828 | (int (*) (void)) | |
829 | return_zero); | |
35b1e5cc SS |
830 | de_fault (to_trace_init, |
831 | (void (*) (void)) | |
832 | tcomplain); | |
833 | de_fault (to_download_tracepoint, | |
834 | (void (*) (struct breakpoint *)) | |
835 | tcomplain); | |
836 | de_fault (to_download_trace_state_variable, | |
837 | (void (*) (struct trace_state_variable *)) | |
838 | tcomplain); | |
839 | de_fault (to_trace_set_readonly_regions, | |
840 | (void (*) (void)) | |
841 | tcomplain); | |
842 | de_fault (to_trace_start, | |
843 | (void (*) (void)) | |
844 | tcomplain); | |
845 | de_fault (to_get_trace_status, | |
00bf0b85 | 846 | (int (*) (struct trace_status *)) |
35b1e5cc SS |
847 | return_minus_one); |
848 | de_fault (to_trace_stop, | |
849 | (void (*) (void)) | |
850 | tcomplain); | |
851 | de_fault (to_trace_find, | |
852 | (int (*) (enum trace_find_type, int, ULONGEST, ULONGEST, int *)) | |
4136fdd2 | 853 | return_minus_one); |
35b1e5cc SS |
854 | de_fault (to_get_trace_state_variable_value, |
855 | (int (*) (int, LONGEST *)) | |
856 | return_zero); | |
00bf0b85 | 857 | de_fault (to_save_trace_data, |
011aacb0 | 858 | (int (*) (const char *)) |
00bf0b85 SS |
859 | tcomplain); |
860 | de_fault (to_upload_tracepoints, | |
861 | (int (*) (struct uploaded_tp **)) | |
862 | return_zero); | |
863 | de_fault (to_upload_trace_state_variables, | |
864 | (int (*) (struct uploaded_tsv **)) | |
865 | return_zero); | |
866 | de_fault (to_get_raw_trace_data, | |
867 | (LONGEST (*) (gdb_byte *, ULONGEST, LONGEST)) | |
868 | tcomplain); | |
35b1e5cc SS |
869 | de_fault (to_set_disconnected_tracing, |
870 | (void (*) (int)) | |
4daf5ac0 SS |
871 | target_ignore); |
872 | de_fault (to_set_circular_trace_buffer, | |
873 | (void (*) (int)) | |
874 | target_ignore); | |
711e434b PM |
875 | de_fault (to_get_tib_address, |
876 | (int (*) (ptid_t, CORE_ADDR *)) | |
877 | tcomplain); | |
d914c394 SS |
878 | de_fault (to_set_permissions, |
879 | (void (*) (void)) | |
880 | target_ignore); | |
c906108c | 881 | #undef de_fault |
c906108c | 882 | |
7998dfc3 AC |
883 | /* Finally, position the target-stack beneath the squashed |
884 | "current_target". That way code looking for a non-inherited | |
885 | target method can quickly and simply find it. */ | |
886 | current_target.beneath = target_stack; | |
b4b61fdb DJ |
887 | |
888 | if (targetdebug) | |
889 | setup_target_debug (); | |
c906108c SS |
890 | } |
891 | ||
892 | /* Push a new target type into the stack of the existing target accessors, | |
893 | possibly superseding some of the existing accessors. | |
894 | ||
c906108c SS |
895 | Rather than allow an empty stack, we always have the dummy target at |
896 | the bottom stratum, so we can call the function vectors without | |
897 | checking them. */ | |
898 | ||
b26a4dcb | 899 | void |
fba45db2 | 900 | push_target (struct target_ops *t) |
c906108c | 901 | { |
258b763a | 902 | struct target_ops **cur; |
c906108c SS |
903 | |
904 | /* Check magic number. If wrong, it probably means someone changed | |
905 | the struct definition, but not all the places that initialize one. */ | |
906 | if (t->to_magic != OPS_MAGIC) | |
907 | { | |
c5aa993b JM |
908 | fprintf_unfiltered (gdb_stderr, |
909 | "Magic number of %s target struct wrong\n", | |
910 | t->to_shortname); | |
e2e0b3e5 | 911 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
912 | } |
913 | ||
258b763a AC |
914 | /* Find the proper stratum to install this target in. */ |
915 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) | |
c906108c | 916 | { |
258b763a | 917 | if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum) |
c906108c SS |
918 | break; |
919 | } | |
920 | ||
258b763a | 921 | /* If there's already targets at this stratum, remove them. */ |
88c231eb | 922 | /* FIXME: cagney/2003-10-15: I think this should be popping all |
258b763a AC |
923 | targets to CUR, and not just those at this stratum level. */ |
924 | while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum) | |
925 | { | |
926 | /* There's already something at this stratum level. Close it, | |
927 | and un-hook it from the stack. */ | |
928 | struct target_ops *tmp = (*cur); | |
5d502164 | 929 | |
258b763a AC |
930 | (*cur) = (*cur)->beneath; |
931 | tmp->beneath = NULL; | |
f1c07ab0 | 932 | target_close (tmp, 0); |
258b763a | 933 | } |
c906108c SS |
934 | |
935 | /* We have removed all targets in our stratum, now add the new one. */ | |
258b763a AC |
936 | t->beneath = (*cur); |
937 | (*cur) = t; | |
c906108c SS |
938 | |
939 | update_current_target (); | |
c906108c SS |
940 | } |
941 | ||
2bc416ba | 942 | /* Remove a target_ops vector from the stack, wherever it may be. |
c906108c SS |
943 | Return how many times it was removed (0 or 1). */ |
944 | ||
945 | int | |
fba45db2 | 946 | unpush_target (struct target_ops *t) |
c906108c | 947 | { |
258b763a AC |
948 | struct target_ops **cur; |
949 | struct target_ops *tmp; | |
c906108c | 950 | |
c8d104ad PA |
951 | if (t->to_stratum == dummy_stratum) |
952 | internal_error (__FILE__, __LINE__, | |
953 | "Attempt to unpush the dummy target"); | |
954 | ||
c906108c SS |
955 | /* Look for the specified target. Note that we assume that a target |
956 | can only occur once in the target stack. */ | |
957 | ||
258b763a AC |
958 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) |
959 | { | |
960 | if ((*cur) == t) | |
961 | break; | |
962 | } | |
c906108c | 963 | |
258b763a | 964 | if ((*cur) == NULL) |
c906108c SS |
965 | return 0; /* Didn't find target_ops, quit now */ |
966 | ||
5269965e AC |
967 | /* NOTE: cagney/2003-12-06: In '94 the close call was made |
968 | unconditional by moving it to before the above check that the | |
969 | target was in the target stack (something about "Change the way | |
970 | pushing and popping of targets work to support target overlays | |
971 | and inheritance"). This doesn't make much sense - only open | |
972 | targets should be closed. */ | |
973 | target_close (t, 0); | |
974 | ||
c906108c | 975 | /* Unchain the target */ |
258b763a AC |
976 | tmp = (*cur); |
977 | (*cur) = (*cur)->beneath; | |
978 | tmp->beneath = NULL; | |
c906108c SS |
979 | |
980 | update_current_target (); | |
c906108c SS |
981 | |
982 | return 1; | |
983 | } | |
984 | ||
985 | void | |
fba45db2 | 986 | pop_target (void) |
c906108c | 987 | { |
b52323fa | 988 | target_close (target_stack, 0); /* Let it clean up */ |
258b763a | 989 | if (unpush_target (target_stack) == 1) |
c906108c SS |
990 | return; |
991 | ||
c5aa993b JM |
992 | fprintf_unfiltered (gdb_stderr, |
993 | "pop_target couldn't find target %s\n", | |
994 | current_target.to_shortname); | |
5d502164 MS |
995 | internal_error (__FILE__, __LINE__, |
996 | _("failed internal consistency check")); | |
c906108c SS |
997 | } |
998 | ||
aa76d38d | 999 | void |
87ab71f0 | 1000 | pop_all_targets_above (enum strata above_stratum, int quitting) |
aa76d38d | 1001 | { |
87ab71f0 | 1002 | while ((int) (current_target.to_stratum) > (int) above_stratum) |
aa76d38d | 1003 | { |
b52323fa | 1004 | target_close (target_stack, quitting); |
aa76d38d PA |
1005 | if (!unpush_target (target_stack)) |
1006 | { | |
1007 | fprintf_unfiltered (gdb_stderr, | |
1008 | "pop_all_targets couldn't find target %s\n", | |
b52323fa | 1009 | target_stack->to_shortname); |
aa76d38d PA |
1010 | internal_error (__FILE__, __LINE__, |
1011 | _("failed internal consistency check")); | |
1012 | break; | |
1013 | } | |
1014 | } | |
1015 | } | |
1016 | ||
87ab71f0 PA |
1017 | void |
1018 | pop_all_targets (int quitting) | |
1019 | { | |
1020 | pop_all_targets_above (dummy_stratum, quitting); | |
1021 | } | |
1022 | ||
72f5cf0e | 1023 | /* Using the objfile specified in OBJFILE, find the address for the |
9e35dae4 DJ |
1024 | current thread's thread-local storage with offset OFFSET. */ |
1025 | CORE_ADDR | |
1026 | target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) | |
1027 | { | |
1028 | volatile CORE_ADDR addr = 0; | |
117de6a9 PA |
1029 | struct target_ops *target; |
1030 | ||
1031 | for (target = current_target.beneath; | |
1032 | target != NULL; | |
1033 | target = target->beneath) | |
1034 | { | |
1035 | if (target->to_get_thread_local_address != NULL) | |
1036 | break; | |
1037 | } | |
9e35dae4 | 1038 | |
117de6a9 | 1039 | if (target != NULL |
1cf3db46 | 1040 | && gdbarch_fetch_tls_load_module_address_p (target_gdbarch)) |
9e35dae4 DJ |
1041 | { |
1042 | ptid_t ptid = inferior_ptid; | |
1043 | volatile struct gdb_exception ex; | |
1044 | ||
1045 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1046 | { | |
1047 | CORE_ADDR lm_addr; | |
1048 | ||
1049 | /* Fetch the load module address for this objfile. */ | |
1cf3db46 | 1050 | lm_addr = gdbarch_fetch_tls_load_module_address (target_gdbarch, |
9e35dae4 DJ |
1051 | objfile); |
1052 | /* If it's 0, throw the appropriate exception. */ | |
1053 | if (lm_addr == 0) | |
1054 | throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR, | |
1055 | _("TLS load module not found")); | |
1056 | ||
117de6a9 | 1057 | addr = target->to_get_thread_local_address (target, ptid, lm_addr, offset); |
9e35dae4 DJ |
1058 | } |
1059 | /* If an error occurred, print TLS related messages here. Otherwise, | |
1060 | throw the error to some higher catcher. */ | |
1061 | if (ex.reason < 0) | |
1062 | { | |
1063 | int objfile_is_library = (objfile->flags & OBJF_SHARED); | |
1064 | ||
1065 | switch (ex.error) | |
1066 | { | |
1067 | case TLS_NO_LIBRARY_SUPPORT_ERROR: | |
1068 | error (_("Cannot find thread-local variables in this thread library.")); | |
1069 | break; | |
1070 | case TLS_LOAD_MODULE_NOT_FOUND_ERROR: | |
1071 | if (objfile_is_library) | |
1072 | error (_("Cannot find shared library `%s' in dynamic" | |
1073 | " linker's load module list"), objfile->name); | |
1074 | else | |
1075 | error (_("Cannot find executable file `%s' in dynamic" | |
1076 | " linker's load module list"), objfile->name); | |
1077 | break; | |
1078 | case TLS_NOT_ALLOCATED_YET_ERROR: | |
1079 | if (objfile_is_library) | |
1080 | error (_("The inferior has not yet allocated storage for" | |
1081 | " thread-local variables in\n" | |
1082 | "the shared library `%s'\n" | |
1083 | "for %s"), | |
1084 | objfile->name, target_pid_to_str (ptid)); | |
1085 | else | |
1086 | error (_("The inferior has not yet allocated storage for" | |
1087 | " thread-local variables in\n" | |
1088 | "the executable `%s'\n" | |
1089 | "for %s"), | |
1090 | objfile->name, target_pid_to_str (ptid)); | |
1091 | break; | |
1092 | case TLS_GENERIC_ERROR: | |
1093 | if (objfile_is_library) | |
1094 | error (_("Cannot find thread-local storage for %s, " | |
1095 | "shared library %s:\n%s"), | |
1096 | target_pid_to_str (ptid), | |
1097 | objfile->name, ex.message); | |
1098 | else | |
1099 | error (_("Cannot find thread-local storage for %s, " | |
1100 | "executable file %s:\n%s"), | |
1101 | target_pid_to_str (ptid), | |
1102 | objfile->name, ex.message); | |
1103 | break; | |
1104 | default: | |
1105 | throw_exception (ex); | |
1106 | break; | |
1107 | } | |
1108 | } | |
1109 | } | |
1110 | /* It wouldn't be wrong here to try a gdbarch method, too; finding | |
1111 | TLS is an ABI-specific thing. But we don't do that yet. */ | |
1112 | else | |
1113 | error (_("Cannot find thread-local variables on this target")); | |
1114 | ||
1115 | return addr; | |
1116 | } | |
1117 | ||
c906108c SS |
1118 | #undef MIN |
1119 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) | |
1120 | ||
1121 | /* target_read_string -- read a null terminated string, up to LEN bytes, | |
1122 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. | |
1123 | Set *STRING to a pointer to malloc'd memory containing the data; the caller | |
1124 | is responsible for freeing it. Return the number of bytes successfully | |
1125 | read. */ | |
1126 | ||
1127 | int | |
fba45db2 | 1128 | target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) |
c906108c SS |
1129 | { |
1130 | int tlen, origlen, offset, i; | |
1b0ba102 | 1131 | gdb_byte buf[4]; |
c906108c SS |
1132 | int errcode = 0; |
1133 | char *buffer; | |
1134 | int buffer_allocated; | |
1135 | char *bufptr; | |
1136 | unsigned int nbytes_read = 0; | |
1137 | ||
6217bf3e MS |
1138 | gdb_assert (string); |
1139 | ||
c906108c SS |
1140 | /* Small for testing. */ |
1141 | buffer_allocated = 4; | |
1142 | buffer = xmalloc (buffer_allocated); | |
1143 | bufptr = buffer; | |
1144 | ||
1145 | origlen = len; | |
1146 | ||
1147 | while (len > 0) | |
1148 | { | |
1149 | tlen = MIN (len, 4 - (memaddr & 3)); | |
1150 | offset = memaddr & 3; | |
1151 | ||
1b0ba102 | 1152 | errcode = target_read_memory (memaddr & ~3, buf, sizeof buf); |
c906108c SS |
1153 | if (errcode != 0) |
1154 | { | |
1155 | /* The transfer request might have crossed the boundary to an | |
1156 | unallocated region of memory. Retry the transfer, requesting | |
1157 | a single byte. */ | |
1158 | tlen = 1; | |
1159 | offset = 0; | |
b8eb5af0 | 1160 | errcode = target_read_memory (memaddr, buf, 1); |
c906108c SS |
1161 | if (errcode != 0) |
1162 | goto done; | |
1163 | } | |
1164 | ||
1165 | if (bufptr - buffer + tlen > buffer_allocated) | |
1166 | { | |
1167 | unsigned int bytes; | |
5d502164 | 1168 | |
c906108c SS |
1169 | bytes = bufptr - buffer; |
1170 | buffer_allocated *= 2; | |
1171 | buffer = xrealloc (buffer, buffer_allocated); | |
1172 | bufptr = buffer + bytes; | |
1173 | } | |
1174 | ||
1175 | for (i = 0; i < tlen; i++) | |
1176 | { | |
1177 | *bufptr++ = buf[i + offset]; | |
1178 | if (buf[i + offset] == '\000') | |
1179 | { | |
1180 | nbytes_read += i + 1; | |
1181 | goto done; | |
1182 | } | |
1183 | } | |
1184 | ||
1185 | memaddr += tlen; | |
1186 | len -= tlen; | |
1187 | nbytes_read += tlen; | |
1188 | } | |
c5aa993b | 1189 | done: |
6217bf3e | 1190 | *string = buffer; |
c906108c SS |
1191 | if (errnop != NULL) |
1192 | *errnop = errcode; | |
c906108c SS |
1193 | return nbytes_read; |
1194 | } | |
1195 | ||
07b82ea5 PA |
1196 | struct target_section_table * |
1197 | target_get_section_table (struct target_ops *target) | |
1198 | { | |
1199 | struct target_ops *t; | |
1200 | ||
1201 | if (targetdebug) | |
1202 | fprintf_unfiltered (gdb_stdlog, "target_get_section_table ()\n"); | |
1203 | ||
1204 | for (t = target; t != NULL; t = t->beneath) | |
1205 | if (t->to_get_section_table != NULL) | |
1206 | return (*t->to_get_section_table) (t); | |
1207 | ||
1208 | return NULL; | |
1209 | } | |
1210 | ||
8db32d44 | 1211 | /* Find a section containing ADDR. */ |
07b82ea5 | 1212 | |
0542c86d | 1213 | struct target_section * |
8db32d44 AC |
1214 | target_section_by_addr (struct target_ops *target, CORE_ADDR addr) |
1215 | { | |
07b82ea5 | 1216 | struct target_section_table *table = target_get_section_table (target); |
0542c86d | 1217 | struct target_section *secp; |
07b82ea5 PA |
1218 | |
1219 | if (table == NULL) | |
1220 | return NULL; | |
1221 | ||
1222 | for (secp = table->sections; secp < table->sections_end; secp++) | |
8db32d44 AC |
1223 | { |
1224 | if (addr >= secp->addr && addr < secp->endaddr) | |
1225 | return secp; | |
1226 | } | |
1227 | return NULL; | |
1228 | } | |
1229 | ||
7f79c47e DE |
1230 | /* Perform a partial memory transfer. |
1231 | For docs see target.h, to_xfer_partial. */ | |
cf7a04e8 DJ |
1232 | |
1233 | static LONGEST | |
4e5d721f DE |
1234 | memory_xfer_partial (struct target_ops *ops, enum target_object object, |
1235 | void *readbuf, const void *writebuf, ULONGEST memaddr, | |
1236 | LONGEST len) | |
0779438d | 1237 | { |
cf7a04e8 DJ |
1238 | LONGEST res; |
1239 | int reg_len; | |
1240 | struct mem_region *region; | |
4e5d721f | 1241 | struct inferior *inf; |
cf7a04e8 DJ |
1242 | |
1243 | /* Zero length requests are ok and require no work. */ | |
1244 | if (len == 0) | |
1245 | return 0; | |
1246 | ||
07b82ea5 PA |
1247 | /* For accesses to unmapped overlay sections, read directly from |
1248 | files. Must do this first, as MEMADDR may need adjustment. */ | |
1249 | if (readbuf != NULL && overlay_debugging) | |
1250 | { | |
1251 | struct obj_section *section = find_pc_overlay (memaddr); | |
5d502164 | 1252 | |
07b82ea5 PA |
1253 | if (pc_in_unmapped_range (memaddr, section)) |
1254 | { | |
1255 | struct target_section_table *table | |
1256 | = target_get_section_table (ops); | |
1257 | const char *section_name = section->the_bfd_section->name; | |
5d502164 | 1258 | |
07b82ea5 PA |
1259 | memaddr = overlay_mapped_address (memaddr, section); |
1260 | return section_table_xfer_memory_partial (readbuf, writebuf, | |
1261 | memaddr, len, | |
1262 | table->sections, | |
1263 | table->sections_end, | |
1264 | section_name); | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | /* Try the executable files, if "trust-readonly-sections" is set. */ | |
cf7a04e8 DJ |
1269 | if (readbuf != NULL && trust_readonly) |
1270 | { | |
0542c86d | 1271 | struct target_section *secp; |
07b82ea5 | 1272 | struct target_section_table *table; |
cf7a04e8 DJ |
1273 | |
1274 | secp = target_section_by_addr (ops, memaddr); | |
1275 | if (secp != NULL | |
1276 | && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) | |
1277 | & SEC_READONLY)) | |
07b82ea5 PA |
1278 | { |
1279 | table = target_get_section_table (ops); | |
1280 | return section_table_xfer_memory_partial (readbuf, writebuf, | |
1281 | memaddr, len, | |
1282 | table->sections, | |
1283 | table->sections_end, | |
1284 | NULL); | |
1285 | } | |
98646950 UW |
1286 | } |
1287 | ||
cf7a04e8 DJ |
1288 | /* Try GDB's internal data cache. */ |
1289 | region = lookup_mem_region (memaddr); | |
4b5752d0 VP |
1290 | /* region->hi == 0 means there's no upper bound. */ |
1291 | if (memaddr + len < region->hi || region->hi == 0) | |
cf7a04e8 DJ |
1292 | reg_len = len; |
1293 | else | |
1294 | reg_len = region->hi - memaddr; | |
1295 | ||
1296 | switch (region->attrib.mode) | |
1297 | { | |
1298 | case MEM_RO: | |
1299 | if (writebuf != NULL) | |
1300 | return -1; | |
1301 | break; | |
1302 | ||
1303 | case MEM_WO: | |
1304 | if (readbuf != NULL) | |
1305 | return -1; | |
1306 | break; | |
a76d924d DJ |
1307 | |
1308 | case MEM_FLASH: | |
1309 | /* We only support writing to flash during "load" for now. */ | |
1310 | if (writebuf != NULL) | |
1311 | error (_("Writing to flash memory forbidden in this context")); | |
1312 | break; | |
4b5752d0 VP |
1313 | |
1314 | case MEM_NONE: | |
1315 | return -1; | |
cf7a04e8 DJ |
1316 | } |
1317 | ||
6c95b8df PA |
1318 | if (!ptid_equal (inferior_ptid, null_ptid)) |
1319 | inf = find_inferior_pid (ptid_get_pid (inferior_ptid)); | |
1320 | else | |
1321 | inf = NULL; | |
4e5d721f DE |
1322 | |
1323 | if (inf != NULL | |
2f4d8875 PA |
1324 | /* The dcache reads whole cache lines; that doesn't play well |
1325 | with reading from a trace buffer, because reading outside of | |
1326 | the collected memory range fails. */ | |
1327 | && get_traceframe_number () == -1 | |
4e5d721f DE |
1328 | && (region->attrib.cache |
1329 | || (stack_cache_enabled_p && object == TARGET_OBJECT_STACK_MEMORY))) | |
cf7a04e8 | 1330 | { |
cf7a04e8 | 1331 | if (readbuf != NULL) |
25f122dc | 1332 | res = dcache_xfer_memory (ops, target_dcache, memaddr, readbuf, |
cf7a04e8 DJ |
1333 | reg_len, 0); |
1334 | else | |
1335 | /* FIXME drow/2006-08-09: If we're going to preserve const | |
1336 | correctness dcache_xfer_memory should take readbuf and | |
1337 | writebuf. */ | |
25f122dc | 1338 | res = dcache_xfer_memory (ops, target_dcache, memaddr, |
cf7a04e8 DJ |
1339 | (void *) writebuf, |
1340 | reg_len, 1); | |
1341 | if (res <= 0) | |
1342 | return -1; | |
1343 | else | |
8defab1a DJ |
1344 | { |
1345 | if (readbuf && !show_memory_breakpoints) | |
1346 | breakpoint_restore_shadows (readbuf, memaddr, reg_len); | |
1347 | return res; | |
1348 | } | |
cf7a04e8 DJ |
1349 | } |
1350 | ||
1351 | /* If none of those methods found the memory we wanted, fall back | |
1352 | to a target partial transfer. Normally a single call to | |
1353 | to_xfer_partial is enough; if it doesn't recognize an object | |
1354 | it will call the to_xfer_partial of the next target down. | |
1355 | But for memory this won't do. Memory is the only target | |
1356 | object which can be read from more than one valid target. | |
1357 | A core file, for instance, could have some of memory but | |
1358 | delegate other bits to the target below it. So, we must | |
1359 | manually try all targets. */ | |
1360 | ||
1361 | do | |
1362 | { | |
1363 | res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL, | |
4b5752d0 | 1364 | readbuf, writebuf, memaddr, reg_len); |
cf7a04e8 | 1365 | if (res > 0) |
8defab1a | 1366 | break; |
cf7a04e8 | 1367 | |
5ad3a4ca DJ |
1368 | /* We want to continue past core files to executables, but not |
1369 | past a running target's memory. */ | |
c35b1492 | 1370 | if (ops->to_has_all_memory (ops)) |
8defab1a | 1371 | break; |
5ad3a4ca | 1372 | |
cf7a04e8 DJ |
1373 | ops = ops->beneath; |
1374 | } | |
1375 | while (ops != NULL); | |
1376 | ||
8defab1a DJ |
1377 | if (readbuf && !show_memory_breakpoints) |
1378 | breakpoint_restore_shadows (readbuf, memaddr, reg_len); | |
1379 | ||
41dcd03f DE |
1380 | /* Make sure the cache gets updated no matter what - if we are writing |
1381 | to the stack. Even if this write is not tagged as such, we still need | |
1382 | to update the cache. */ | |
1383 | ||
1384 | if (res > 0 | |
1385 | && inf != NULL | |
1386 | && writebuf != NULL | |
1387 | && !region->attrib.cache | |
1388 | && stack_cache_enabled_p | |
1389 | && object != TARGET_OBJECT_STACK_MEMORY) | |
1390 | { | |
7d4f32d3 | 1391 | dcache_update (target_dcache, memaddr, (void *) writebuf, res); |
41dcd03f DE |
1392 | } |
1393 | ||
cf7a04e8 DJ |
1394 | /* If we still haven't got anything, return the last error. We |
1395 | give up. */ | |
1396 | return res; | |
0779438d AC |
1397 | } |
1398 | ||
8defab1a DJ |
1399 | static void |
1400 | restore_show_memory_breakpoints (void *arg) | |
1401 | { | |
1402 | show_memory_breakpoints = (uintptr_t) arg; | |
1403 | } | |
1404 | ||
1405 | struct cleanup * | |
1406 | make_show_memory_breakpoints_cleanup (int show) | |
1407 | { | |
1408 | int current = show_memory_breakpoints; | |
8defab1a | 1409 | |
5d502164 | 1410 | show_memory_breakpoints = show; |
8defab1a DJ |
1411 | return make_cleanup (restore_show_memory_breakpoints, |
1412 | (void *) (uintptr_t) current); | |
1413 | } | |
1414 | ||
7f79c47e DE |
1415 | /* For docs see target.h, to_xfer_partial. */ |
1416 | ||
27394598 AC |
1417 | static LONGEST |
1418 | target_xfer_partial (struct target_ops *ops, | |
1419 | enum target_object object, const char *annex, | |
1420 | void *readbuf, const void *writebuf, | |
1421 | ULONGEST offset, LONGEST len) | |
1422 | { | |
1423 | LONGEST retval; | |
1424 | ||
1425 | gdb_assert (ops->to_xfer_partial != NULL); | |
cf7a04e8 | 1426 | |
d914c394 SS |
1427 | if (writebuf && !may_write_memory) |
1428 | error (_("Writing to memory is not allowed (addr %s, len %s)"), | |
1429 | core_addr_to_string_nz (offset), plongest (len)); | |
1430 | ||
cf7a04e8 DJ |
1431 | /* If this is a memory transfer, let the memory-specific code |
1432 | have a look at it instead. Memory transfers are more | |
1433 | complicated. */ | |
4e5d721f DE |
1434 | if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY) |
1435 | retval = memory_xfer_partial (ops, object, readbuf, | |
1436 | writebuf, offset, len); | |
cf7a04e8 DJ |
1437 | else |
1438 | { | |
1439 | enum target_object raw_object = object; | |
1440 | ||
1441 | /* If this is a raw memory transfer, request the normal | |
1442 | memory object from other layers. */ | |
1443 | if (raw_object == TARGET_OBJECT_RAW_MEMORY) | |
1444 | raw_object = TARGET_OBJECT_MEMORY; | |
1445 | ||
1446 | retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf, | |
1447 | writebuf, offset, len); | |
1448 | } | |
1449 | ||
27394598 AC |
1450 | if (targetdebug) |
1451 | { | |
1452 | const unsigned char *myaddr = NULL; | |
1453 | ||
1454 | fprintf_unfiltered (gdb_stdlog, | |
53b71562 | 1455 | "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s", |
27394598 AC |
1456 | ops->to_shortname, |
1457 | (int) object, | |
1458 | (annex ? annex : "(null)"), | |
53b71562 JB |
1459 | host_address_to_string (readbuf), |
1460 | host_address_to_string (writebuf), | |
0b1553bc UW |
1461 | core_addr_to_string_nz (offset), |
1462 | plongest (len), plongest (retval)); | |
27394598 AC |
1463 | |
1464 | if (readbuf) | |
1465 | myaddr = readbuf; | |
1466 | if (writebuf) | |
1467 | myaddr = writebuf; | |
1468 | if (retval > 0 && myaddr != NULL) | |
1469 | { | |
1470 | int i; | |
2bc416ba | 1471 | |
27394598 AC |
1472 | fputs_unfiltered (", bytes =", gdb_stdlog); |
1473 | for (i = 0; i < retval; i++) | |
1474 | { | |
53b71562 | 1475 | if ((((intptr_t) &(myaddr[i])) & 0xf) == 0) |
27394598 AC |
1476 | { |
1477 | if (targetdebug < 2 && i > 0) | |
1478 | { | |
1479 | fprintf_unfiltered (gdb_stdlog, " ..."); | |
1480 | break; | |
1481 | } | |
1482 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
1483 | } | |
2bc416ba | 1484 | |
27394598 AC |
1485 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
1486 | } | |
1487 | } | |
2bc416ba | 1488 | |
27394598 AC |
1489 | fputc_unfiltered ('\n', gdb_stdlog); |
1490 | } | |
1491 | return retval; | |
1492 | } | |
1493 | ||
c906108c SS |
1494 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in |
1495 | GDB's memory at MYADDR. Returns either 0 for success or an errno value | |
1496 | if any error occurs. | |
1497 | ||
1498 | If an error occurs, no guarantee is made about the contents of the data at | |
1499 | MYADDR. In particular, the caller should not depend upon partial reads | |
1500 | filling the buffer with good data. There is no way for the caller to know | |
1501 | how much good data might have been transfered anyway. Callers that can | |
cf7a04e8 DJ |
1502 | deal with partial reads should call target_read (which will retry until |
1503 | it makes no progress, and then return how much was transferred). */ | |
c906108c SS |
1504 | |
1505 | int | |
fc1a4b47 | 1506 | target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len) |
c906108c | 1507 | { |
c35b1492 PA |
1508 | /* Dispatch to the topmost target, not the flattened current_target. |
1509 | Memory accesses check target->to_has_(all_)memory, and the | |
1510 | flattened target doesn't inherit those. */ | |
1511 | if (target_read (current_target.beneath, TARGET_OBJECT_MEMORY, NULL, | |
cf7a04e8 DJ |
1512 | myaddr, memaddr, len) == len) |
1513 | return 0; | |
0779438d | 1514 | else |
cf7a04e8 | 1515 | return EIO; |
c906108c SS |
1516 | } |
1517 | ||
4e5d721f DE |
1518 | /* Like target_read_memory, but specify explicitly that this is a read from |
1519 | the target's stack. This may trigger different cache behavior. */ | |
1520 | ||
1521 | int | |
1522 | target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, int len) | |
1523 | { | |
1524 | /* Dispatch to the topmost target, not the flattened current_target. | |
1525 | Memory accesses check target->to_has_(all_)memory, and the | |
1526 | flattened target doesn't inherit those. */ | |
1527 | ||
1528 | if (target_read (current_target.beneath, TARGET_OBJECT_STACK_MEMORY, NULL, | |
1529 | myaddr, memaddr, len) == len) | |
1530 | return 0; | |
1531 | else | |
1532 | return EIO; | |
1533 | } | |
1534 | ||
7f79c47e DE |
1535 | /* Write LEN bytes from MYADDR to target memory at address MEMADDR. |
1536 | Returns either 0 for success or an errno value if any error occurs. | |
1537 | If an error occurs, no guarantee is made about how much data got written. | |
1538 | Callers that can deal with partial writes should call target_write. */ | |
1539 | ||
c906108c | 1540 | int |
fc1a4b47 | 1541 | target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len) |
c906108c | 1542 | { |
c35b1492 PA |
1543 | /* Dispatch to the topmost target, not the flattened current_target. |
1544 | Memory accesses check target->to_has_(all_)memory, and the | |
1545 | flattened target doesn't inherit those. */ | |
1546 | if (target_write (current_target.beneath, TARGET_OBJECT_MEMORY, NULL, | |
cf7a04e8 DJ |
1547 | myaddr, memaddr, len) == len) |
1548 | return 0; | |
0779438d | 1549 | else |
cf7a04e8 | 1550 | return EIO; |
c906108c | 1551 | } |
c5aa993b | 1552 | |
fd79ecee DJ |
1553 | /* Fetch the target's memory map. */ |
1554 | ||
1555 | VEC(mem_region_s) * | |
1556 | target_memory_map (void) | |
1557 | { | |
1558 | VEC(mem_region_s) *result; | |
1559 | struct mem_region *last_one, *this_one; | |
1560 | int ix; | |
1561 | struct target_ops *t; | |
1562 | ||
1563 | if (targetdebug) | |
1564 | fprintf_unfiltered (gdb_stdlog, "target_memory_map ()\n"); | |
1565 | ||
1566 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1567 | if (t->to_memory_map != NULL) | |
1568 | break; | |
1569 | ||
1570 | if (t == NULL) | |
1571 | return NULL; | |
1572 | ||
1573 | result = t->to_memory_map (t); | |
1574 | if (result == NULL) | |
1575 | return NULL; | |
1576 | ||
1577 | qsort (VEC_address (mem_region_s, result), | |
1578 | VEC_length (mem_region_s, result), | |
1579 | sizeof (struct mem_region), mem_region_cmp); | |
1580 | ||
1581 | /* Check that regions do not overlap. Simultaneously assign | |
1582 | a numbering for the "mem" commands to use to refer to | |
1583 | each region. */ | |
1584 | last_one = NULL; | |
1585 | for (ix = 0; VEC_iterate (mem_region_s, result, ix, this_one); ix++) | |
1586 | { | |
1587 | this_one->number = ix; | |
1588 | ||
1589 | if (last_one && last_one->hi > this_one->lo) | |
1590 | { | |
1591 | warning (_("Overlapping regions in memory map: ignoring")); | |
1592 | VEC_free (mem_region_s, result); | |
1593 | return NULL; | |
1594 | } | |
1595 | last_one = this_one; | |
1596 | } | |
1597 | ||
1598 | return result; | |
1599 | } | |
1600 | ||
a76d924d DJ |
1601 | void |
1602 | target_flash_erase (ULONGEST address, LONGEST length) | |
1603 | { | |
1604 | struct target_ops *t; | |
1605 | ||
1606 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1607 | if (t->to_flash_erase != NULL) | |
5d502164 MS |
1608 | { |
1609 | if (targetdebug) | |
1610 | fprintf_unfiltered (gdb_stdlog, "target_flash_erase (%s, %s)\n", | |
1611 | hex_string (address), phex (length, 0)); | |
1612 | t->to_flash_erase (t, address, length); | |
1613 | return; | |
1614 | } | |
a76d924d DJ |
1615 | |
1616 | tcomplain (); | |
1617 | } | |
1618 | ||
1619 | void | |
1620 | target_flash_done (void) | |
1621 | { | |
1622 | struct target_ops *t; | |
1623 | ||
1624 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1625 | if (t->to_flash_done != NULL) | |
5d502164 MS |
1626 | { |
1627 | if (targetdebug) | |
1628 | fprintf_unfiltered (gdb_stdlog, "target_flash_done\n"); | |
1629 | t->to_flash_done (t); | |
1630 | return; | |
1631 | } | |
a76d924d DJ |
1632 | |
1633 | tcomplain (); | |
1634 | } | |
1635 | ||
920d2a44 AC |
1636 | static void |
1637 | show_trust_readonly (struct ui_file *file, int from_tty, | |
1638 | struct cmd_list_element *c, const char *value) | |
1639 | { | |
1640 | fprintf_filtered (file, _("\ | |
1641 | Mode for reading from readonly sections is %s.\n"), | |
1642 | value); | |
1643 | } | |
3a11626d | 1644 | |
1e3ff5ad AC |
1645 | /* More generic transfers. */ |
1646 | ||
0088c768 | 1647 | static LONGEST |
8aa91c1e | 1648 | default_xfer_partial (struct target_ops *ops, enum target_object object, |
2bc416ba | 1649 | const char *annex, gdb_byte *readbuf, |
1b0ba102 | 1650 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) |
0088c768 AC |
1651 | { |
1652 | if (object == TARGET_OBJECT_MEMORY | |
c8e73a31 AC |
1653 | && ops->deprecated_xfer_memory != NULL) |
1654 | /* If available, fall back to the target's | |
1655 | "deprecated_xfer_memory" method. */ | |
0088c768 | 1656 | { |
4b8a223f | 1657 | int xfered = -1; |
5d502164 | 1658 | |
0088c768 | 1659 | errno = 0; |
4b8a223f AC |
1660 | if (writebuf != NULL) |
1661 | { | |
1662 | void *buffer = xmalloc (len); | |
1663 | struct cleanup *cleanup = make_cleanup (xfree, buffer); | |
5d502164 | 1664 | |
4b8a223f | 1665 | memcpy (buffer, writebuf, len); |
c8e73a31 AC |
1666 | xfered = ops->deprecated_xfer_memory (offset, buffer, len, |
1667 | 1/*write*/, NULL, ops); | |
4b8a223f AC |
1668 | do_cleanups (cleanup); |
1669 | } | |
1670 | if (readbuf != NULL) | |
244e85c8 MS |
1671 | xfered = ops->deprecated_xfer_memory (offset, readbuf, len, |
1672 | 0/*read*/, NULL, ops); | |
0088c768 AC |
1673 | if (xfered > 0) |
1674 | return xfered; | |
1675 | else if (xfered == 0 && errno == 0) | |
c8e73a31 AC |
1676 | /* "deprecated_xfer_memory" uses 0, cross checked against |
1677 | ERRNO as one indication of an error. */ | |
0088c768 AC |
1678 | return 0; |
1679 | else | |
1680 | return -1; | |
1681 | } | |
1682 | else if (ops->beneath != NULL) | |
cf7a04e8 DJ |
1683 | return ops->beneath->to_xfer_partial (ops->beneath, object, annex, |
1684 | readbuf, writebuf, offset, len); | |
1685 | else | |
1686 | return -1; | |
1687 | } | |
1688 | ||
1689 | /* The xfer_partial handler for the topmost target. Unlike the default, | |
1690 | it does not need to handle memory specially; it just passes all | |
1691 | requests down the stack. */ | |
1692 | ||
1693 | static LONGEST | |
1694 | current_xfer_partial (struct target_ops *ops, enum target_object object, | |
1695 | const char *annex, gdb_byte *readbuf, | |
1696 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) | |
1697 | { | |
1698 | if (ops->beneath != NULL) | |
1699 | return ops->beneath->to_xfer_partial (ops->beneath, object, annex, | |
1700 | readbuf, writebuf, offset, len); | |
0088c768 AC |
1701 | else |
1702 | return -1; | |
1703 | } | |
1704 | ||
7f79c47e | 1705 | /* Target vector read/write partial wrapper functions. */ |
0088c768 | 1706 | |
13547ab6 | 1707 | static LONGEST |
1e3ff5ad AC |
1708 | target_read_partial (struct target_ops *ops, |
1709 | enum target_object object, | |
1b0ba102 | 1710 | const char *annex, gdb_byte *buf, |
1e3ff5ad AC |
1711 | ULONGEST offset, LONGEST len) |
1712 | { | |
27394598 | 1713 | return target_xfer_partial (ops, object, annex, buf, NULL, offset, len); |
1e3ff5ad AC |
1714 | } |
1715 | ||
13547ab6 | 1716 | static LONGEST |
1e3ff5ad AC |
1717 | target_write_partial (struct target_ops *ops, |
1718 | enum target_object object, | |
1b0ba102 | 1719 | const char *annex, const gdb_byte *buf, |
1e3ff5ad AC |
1720 | ULONGEST offset, LONGEST len) |
1721 | { | |
27394598 | 1722 | return target_xfer_partial (ops, object, annex, NULL, buf, offset, len); |
1e3ff5ad AC |
1723 | } |
1724 | ||
1725 | /* Wrappers to perform the full transfer. */ | |
7f79c47e DE |
1726 | |
1727 | /* For docs on target_read see target.h. */ | |
1728 | ||
1e3ff5ad AC |
1729 | LONGEST |
1730 | target_read (struct target_ops *ops, | |
1731 | enum target_object object, | |
1b0ba102 | 1732 | const char *annex, gdb_byte *buf, |
1e3ff5ad AC |
1733 | ULONGEST offset, LONGEST len) |
1734 | { | |
1735 | LONGEST xfered = 0; | |
5d502164 | 1736 | |
1e3ff5ad AC |
1737 | while (xfered < len) |
1738 | { | |
0088c768 | 1739 | LONGEST xfer = target_read_partial (ops, object, annex, |
fc1a4b47 | 1740 | (gdb_byte *) buf + xfered, |
0088c768 | 1741 | offset + xfered, len - xfered); |
5d502164 | 1742 | |
1e3ff5ad | 1743 | /* Call an observer, notifying them of the xfer progress? */ |
13547ab6 DJ |
1744 | if (xfer == 0) |
1745 | return xfered; | |
1746 | if (xfer < 0) | |
0088c768 | 1747 | return -1; |
1e3ff5ad AC |
1748 | xfered += xfer; |
1749 | QUIT; | |
1750 | } | |
1751 | return len; | |
1752 | } | |
1753 | ||
d5086790 VP |
1754 | LONGEST |
1755 | target_read_until_error (struct target_ops *ops, | |
1756 | enum target_object object, | |
1757 | const char *annex, gdb_byte *buf, | |
1758 | ULONGEST offset, LONGEST len) | |
1759 | { | |
1760 | LONGEST xfered = 0; | |
5d502164 | 1761 | |
d5086790 VP |
1762 | while (xfered < len) |
1763 | { | |
1764 | LONGEST xfer = target_read_partial (ops, object, annex, | |
1765 | (gdb_byte *) buf + xfered, | |
1766 | offset + xfered, len - xfered); | |
5d502164 | 1767 | |
d5086790 VP |
1768 | /* Call an observer, notifying them of the xfer progress? */ |
1769 | if (xfer == 0) | |
1770 | return xfered; | |
1771 | if (xfer < 0) | |
1772 | { | |
1773 | /* We've got an error. Try to read in smaller blocks. */ | |
1774 | ULONGEST start = offset + xfered; | |
1775 | ULONGEST remaining = len - xfered; | |
1776 | ULONGEST half; | |
1777 | ||
1778 | /* If an attempt was made to read a random memory address, | |
1779 | it's likely that the very first byte is not accessible. | |
1780 | Try reading the first byte, to avoid doing log N tries | |
1781 | below. */ | |
1782 | xfer = target_read_partial (ops, object, annex, | |
1783 | (gdb_byte *) buf + xfered, start, 1); | |
1784 | if (xfer <= 0) | |
1785 | return xfered; | |
1786 | start += 1; | |
1787 | remaining -= 1; | |
1788 | half = remaining/2; | |
1789 | ||
1790 | while (half > 0) | |
1791 | { | |
1792 | xfer = target_read_partial (ops, object, annex, | |
1793 | (gdb_byte *) buf + xfered, | |
1794 | start, half); | |
1795 | if (xfer == 0) | |
1796 | return xfered; | |
1797 | if (xfer < 0) | |
1798 | { | |
1799 | remaining = half; | |
1800 | } | |
1801 | else | |
1802 | { | |
1803 | /* We have successfully read the first half. So, the | |
1804 | error must be in the second half. Adjust start and | |
1805 | remaining to point at the second half. */ | |
1806 | xfered += xfer; | |
1807 | start += xfer; | |
1808 | remaining -= xfer; | |
1809 | } | |
1810 | half = remaining/2; | |
1811 | } | |
1812 | ||
1813 | return xfered; | |
1814 | } | |
1815 | xfered += xfer; | |
1816 | QUIT; | |
1817 | } | |
1818 | return len; | |
1819 | } | |
1820 | ||
cf7a04e8 DJ |
1821 | /* An alternative to target_write with progress callbacks. */ |
1822 | ||
1e3ff5ad | 1823 | LONGEST |
cf7a04e8 DJ |
1824 | target_write_with_progress (struct target_ops *ops, |
1825 | enum target_object object, | |
1826 | const char *annex, const gdb_byte *buf, | |
1827 | ULONGEST offset, LONGEST len, | |
1828 | void (*progress) (ULONGEST, void *), void *baton) | |
1e3ff5ad AC |
1829 | { |
1830 | LONGEST xfered = 0; | |
a76d924d DJ |
1831 | |
1832 | /* Give the progress callback a chance to set up. */ | |
1833 | if (progress) | |
1834 | (*progress) (0, baton); | |
1835 | ||
1e3ff5ad AC |
1836 | while (xfered < len) |
1837 | { | |
1838 | LONGEST xfer = target_write_partial (ops, object, annex, | |
fc1a4b47 | 1839 | (gdb_byte *) buf + xfered, |
1e3ff5ad | 1840 | offset + xfered, len - xfered); |
cf7a04e8 | 1841 | |
13547ab6 DJ |
1842 | if (xfer == 0) |
1843 | return xfered; | |
1844 | if (xfer < 0) | |
0088c768 | 1845 | return -1; |
cf7a04e8 DJ |
1846 | |
1847 | if (progress) | |
1848 | (*progress) (xfer, baton); | |
1849 | ||
1e3ff5ad AC |
1850 | xfered += xfer; |
1851 | QUIT; | |
1852 | } | |
1853 | return len; | |
1854 | } | |
1855 | ||
7f79c47e DE |
1856 | /* For docs on target_write see target.h. */ |
1857 | ||
cf7a04e8 DJ |
1858 | LONGEST |
1859 | target_write (struct target_ops *ops, | |
1860 | enum target_object object, | |
1861 | const char *annex, const gdb_byte *buf, | |
1862 | ULONGEST offset, LONGEST len) | |
1863 | { | |
1864 | return target_write_with_progress (ops, object, annex, buf, offset, len, | |
1865 | NULL, NULL); | |
1866 | } | |
1867 | ||
159f81f3 DJ |
1868 | /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return |
1869 | the size of the transferred data. PADDING additional bytes are | |
1870 | available in *BUF_P. This is a helper function for | |
1871 | target_read_alloc; see the declaration of that function for more | |
1872 | information. */ | |
13547ab6 | 1873 | |
159f81f3 DJ |
1874 | static LONGEST |
1875 | target_read_alloc_1 (struct target_ops *ops, enum target_object object, | |
1876 | const char *annex, gdb_byte **buf_p, int padding) | |
13547ab6 DJ |
1877 | { |
1878 | size_t buf_alloc, buf_pos; | |
1879 | gdb_byte *buf; | |
1880 | LONGEST n; | |
1881 | ||
1882 | /* This function does not have a length parameter; it reads the | |
1883 | entire OBJECT). Also, it doesn't support objects fetched partly | |
1884 | from one target and partly from another (in a different stratum, | |
1885 | e.g. a core file and an executable). Both reasons make it | |
1886 | unsuitable for reading memory. */ | |
1887 | gdb_assert (object != TARGET_OBJECT_MEMORY); | |
1888 | ||
1889 | /* Start by reading up to 4K at a time. The target will throttle | |
1890 | this number down if necessary. */ | |
1891 | buf_alloc = 4096; | |
1892 | buf = xmalloc (buf_alloc); | |
1893 | buf_pos = 0; | |
1894 | while (1) | |
1895 | { | |
1896 | n = target_read_partial (ops, object, annex, &buf[buf_pos], | |
159f81f3 | 1897 | buf_pos, buf_alloc - buf_pos - padding); |
13547ab6 DJ |
1898 | if (n < 0) |
1899 | { | |
1900 | /* An error occurred. */ | |
1901 | xfree (buf); | |
1902 | return -1; | |
1903 | } | |
1904 | else if (n == 0) | |
1905 | { | |
1906 | /* Read all there was. */ | |
1907 | if (buf_pos == 0) | |
1908 | xfree (buf); | |
1909 | else | |
1910 | *buf_p = buf; | |
1911 | return buf_pos; | |
1912 | } | |
1913 | ||
1914 | buf_pos += n; | |
1915 | ||
1916 | /* If the buffer is filling up, expand it. */ | |
1917 | if (buf_alloc < buf_pos * 2) | |
1918 | { | |
1919 | buf_alloc *= 2; | |
1920 | buf = xrealloc (buf, buf_alloc); | |
1921 | } | |
1922 | ||
1923 | QUIT; | |
1924 | } | |
1925 | } | |
1926 | ||
159f81f3 DJ |
1927 | /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return |
1928 | the size of the transferred data. See the declaration in "target.h" | |
1929 | function for more information about the return value. */ | |
1930 | ||
1931 | LONGEST | |
1932 | target_read_alloc (struct target_ops *ops, enum target_object object, | |
1933 | const char *annex, gdb_byte **buf_p) | |
1934 | { | |
1935 | return target_read_alloc_1 (ops, object, annex, buf_p, 0); | |
1936 | } | |
1937 | ||
1938 | /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and | |
1939 | returned as a string, allocated using xmalloc. If an error occurs | |
1940 | or the transfer is unsupported, NULL is returned. Empty objects | |
1941 | are returned as allocated but empty strings. A warning is issued | |
1942 | if the result contains any embedded NUL bytes. */ | |
1943 | ||
1944 | char * | |
1945 | target_read_stralloc (struct target_ops *ops, enum target_object object, | |
1946 | const char *annex) | |
1947 | { | |
1948 | gdb_byte *buffer; | |
1949 | LONGEST transferred; | |
1950 | ||
1951 | transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1); | |
1952 | ||
1953 | if (transferred < 0) | |
1954 | return NULL; | |
1955 | ||
1956 | if (transferred == 0) | |
1957 | return xstrdup (""); | |
1958 | ||
1959 | buffer[transferred] = 0; | |
1960 | if (strlen (buffer) < transferred) | |
1961 | warning (_("target object %d, annex %s, " | |
1962 | "contained unexpected null characters"), | |
1963 | (int) object, annex ? annex : "(none)"); | |
1964 | ||
1965 | return (char *) buffer; | |
1966 | } | |
1967 | ||
b6591e8b AC |
1968 | /* Memory transfer methods. */ |
1969 | ||
1970 | void | |
1b0ba102 | 1971 | get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf, |
b6591e8b AC |
1972 | LONGEST len) |
1973 | { | |
07b82ea5 PA |
1974 | /* This method is used to read from an alternate, non-current |
1975 | target. This read must bypass the overlay support (as symbols | |
1976 | don't match this target), and GDB's internal cache (wrong cache | |
1977 | for this target). */ | |
1978 | if (target_read (ops, TARGET_OBJECT_RAW_MEMORY, NULL, buf, addr, len) | |
b6591e8b AC |
1979 | != len) |
1980 | memory_error (EIO, addr); | |
1981 | } | |
1982 | ||
1983 | ULONGEST | |
5d502164 MS |
1984 | get_target_memory_unsigned (struct target_ops *ops, CORE_ADDR addr, |
1985 | int len, enum bfd_endian byte_order) | |
b6591e8b | 1986 | { |
f6519ebc | 1987 | gdb_byte buf[sizeof (ULONGEST)]; |
b6591e8b AC |
1988 | |
1989 | gdb_assert (len <= sizeof (buf)); | |
1990 | get_target_memory (ops, addr, buf, len); | |
e17a4113 | 1991 | return extract_unsigned_integer (buf, len, byte_order); |
b6591e8b AC |
1992 | } |
1993 | ||
d914c394 SS |
1994 | int |
1995 | target_insert_breakpoint (struct gdbarch *gdbarch, | |
1996 | struct bp_target_info *bp_tgt) | |
1997 | { | |
1998 | if (!may_insert_breakpoints) | |
1999 | { | |
2000 | warning (_("May not insert breakpoints")); | |
2001 | return 1; | |
2002 | } | |
2003 | ||
2004 | return (*current_target.to_insert_breakpoint) (gdbarch, bp_tgt); | |
2005 | } | |
2006 | ||
2007 | int | |
2008 | target_remove_breakpoint (struct gdbarch *gdbarch, | |
2009 | struct bp_target_info *bp_tgt) | |
2010 | { | |
2011 | /* This is kind of a weird case to handle, but the permission might | |
2012 | have been changed after breakpoints were inserted - in which case | |
2013 | we should just take the user literally and assume that any | |
2014 | breakpoints should be left in place. */ | |
2015 | if (!may_insert_breakpoints) | |
2016 | { | |
2017 | warning (_("May not remove breakpoints")); | |
2018 | return 1; | |
2019 | } | |
2020 | ||
2021 | return (*current_target.to_remove_breakpoint) (gdbarch, bp_tgt); | |
2022 | } | |
2023 | ||
c906108c | 2024 | static void |
fba45db2 | 2025 | target_info (char *args, int from_tty) |
c906108c SS |
2026 | { |
2027 | struct target_ops *t; | |
c906108c | 2028 | int has_all_mem = 0; |
c5aa993b | 2029 | |
c906108c | 2030 | if (symfile_objfile != NULL) |
a3f17187 | 2031 | printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile->name); |
c906108c | 2032 | |
258b763a | 2033 | for (t = target_stack; t != NULL; t = t->beneath) |
c906108c | 2034 | { |
c35b1492 | 2035 | if (!(*t->to_has_memory) (t)) |
c906108c SS |
2036 | continue; |
2037 | ||
c5aa993b | 2038 | if ((int) (t->to_stratum) <= (int) dummy_stratum) |
c906108c SS |
2039 | continue; |
2040 | if (has_all_mem) | |
a3f17187 | 2041 | printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n")); |
c5aa993b JM |
2042 | printf_unfiltered ("%s:\n", t->to_longname); |
2043 | (t->to_files_info) (t); | |
c35b1492 | 2044 | has_all_mem = (*t->to_has_all_memory) (t); |
c906108c SS |
2045 | } |
2046 | } | |
2047 | ||
fd79ecee DJ |
2048 | /* This function is called before any new inferior is created, e.g. |
2049 | by running a program, attaching, or connecting to a target. | |
2050 | It cleans up any state from previous invocations which might | |
2051 | change between runs. This is a subset of what target_preopen | |
2052 | resets (things which might change between targets). */ | |
2053 | ||
2054 | void | |
2055 | target_pre_inferior (int from_tty) | |
2056 | { | |
b9db4ced UW |
2057 | /* Clear out solib state. Otherwise the solib state of the previous |
2058 | inferior might have survived and is entirely wrong for the new | |
2059 | target. This has been observed on GNU/Linux using glibc 2.3. How | |
2060 | to reproduce: | |
2061 | ||
2062 | bash$ ./foo& | |
2063 | [1] 4711 | |
2064 | bash$ ./foo& | |
2065 | [1] 4712 | |
2066 | bash$ gdb ./foo | |
2067 | [...] | |
2068 | (gdb) attach 4711 | |
2069 | (gdb) detach | |
2070 | (gdb) attach 4712 | |
2071 | Cannot access memory at address 0xdeadbeef | |
2072 | */ | |
b9db4ced | 2073 | |
50c71eaf PA |
2074 | /* In some OSs, the shared library list is the same/global/shared |
2075 | across inferiors. If code is shared between processes, so are | |
2076 | memory regions and features. */ | |
2077 | if (!gdbarch_has_global_solist (target_gdbarch)) | |
2078 | { | |
2079 | no_shared_libraries (NULL, from_tty); | |
2080 | ||
2081 | invalidate_target_mem_regions (); | |
424163ea | 2082 | |
50c71eaf PA |
2083 | target_clear_description (); |
2084 | } | |
fd79ecee DJ |
2085 | } |
2086 | ||
b8fa0bfa PA |
2087 | /* Callback for iterate_over_inferiors. Gets rid of the given |
2088 | inferior. */ | |
2089 | ||
2090 | static int | |
2091 | dispose_inferior (struct inferior *inf, void *args) | |
2092 | { | |
2093 | struct thread_info *thread; | |
2094 | ||
2095 | thread = any_thread_of_process (inf->pid); | |
2096 | if (thread) | |
2097 | { | |
2098 | switch_to_thread (thread->ptid); | |
2099 | ||
2100 | /* Core inferiors actually should be detached, not killed. */ | |
2101 | if (target_has_execution) | |
2102 | target_kill (); | |
2103 | else | |
2104 | target_detach (NULL, 0); | |
2105 | } | |
2106 | ||
2107 | return 0; | |
2108 | } | |
2109 | ||
c906108c SS |
2110 | /* This is to be called by the open routine before it does |
2111 | anything. */ | |
2112 | ||
2113 | void | |
fba45db2 | 2114 | target_preopen (int from_tty) |
c906108c | 2115 | { |
c5aa993b | 2116 | dont_repeat (); |
c906108c | 2117 | |
b8fa0bfa | 2118 | if (have_inferiors ()) |
c5aa993b | 2119 | { |
adf40b2e | 2120 | if (!from_tty |
b8fa0bfa PA |
2121 | || !have_live_inferiors () |
2122 | || query (_("A program is being debugged already. Kill it? "))) | |
2123 | iterate_over_inferiors (dispose_inferior, NULL); | |
c906108c | 2124 | else |
8a3fe4f8 | 2125 | error (_("Program not killed.")); |
c906108c SS |
2126 | } |
2127 | ||
2128 | /* Calling target_kill may remove the target from the stack. But if | |
2129 | it doesn't (which seems like a win for UDI), remove it now. */ | |
87ab71f0 PA |
2130 | /* Leave the exec target, though. The user may be switching from a |
2131 | live process to a core of the same program. */ | |
2132 | pop_all_targets_above (file_stratum, 0); | |
fd79ecee DJ |
2133 | |
2134 | target_pre_inferior (from_tty); | |
c906108c SS |
2135 | } |
2136 | ||
2137 | /* Detach a target after doing deferred register stores. */ | |
2138 | ||
2139 | void | |
fba45db2 | 2140 | target_detach (char *args, int from_tty) |
c906108c | 2141 | { |
136d6dae VP |
2142 | struct target_ops* t; |
2143 | ||
2567c7d9 | 2144 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2145 | /* Don't remove global breakpoints here. They're removed on |
2146 | disconnection from the target. */ | |
2147 | ; | |
2148 | else | |
2149 | /* If we're in breakpoints-always-inserted mode, have to remove | |
2150 | them before detaching. */ | |
6c95b8df | 2151 | remove_breakpoints_pid (PIDGET (inferior_ptid)); |
74960c60 | 2152 | |
24291992 PA |
2153 | prepare_for_detach (); |
2154 | ||
136d6dae VP |
2155 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
2156 | { | |
2157 | if (t->to_detach != NULL) | |
2158 | { | |
2159 | t->to_detach (t, args, from_tty); | |
947b8855 PA |
2160 | if (targetdebug) |
2161 | fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", | |
2162 | args, from_tty); | |
136d6dae VP |
2163 | return; |
2164 | } | |
2165 | } | |
2166 | ||
2167 | internal_error (__FILE__, __LINE__, "could not find a target to detach"); | |
c906108c SS |
2168 | } |
2169 | ||
6ad8ae5c DJ |
2170 | void |
2171 | target_disconnect (char *args, int from_tty) | |
2172 | { | |
597320e7 DJ |
2173 | struct target_ops *t; |
2174 | ||
50c71eaf PA |
2175 | /* If we're in breakpoints-always-inserted mode or if breakpoints |
2176 | are global across processes, we have to remove them before | |
2177 | disconnecting. */ | |
74960c60 VP |
2178 | remove_breakpoints (); |
2179 | ||
597320e7 DJ |
2180 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
2181 | if (t->to_disconnect != NULL) | |
2182 | { | |
2183 | if (targetdebug) | |
2184 | fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n", | |
2185 | args, from_tty); | |
2186 | t->to_disconnect (t, args, from_tty); | |
2187 | return; | |
2188 | } | |
2189 | ||
2190 | tcomplain (); | |
6ad8ae5c DJ |
2191 | } |
2192 | ||
117de6a9 | 2193 | ptid_t |
47608cb1 | 2194 | target_wait (ptid_t ptid, struct target_waitstatus *status, int options) |
117de6a9 PA |
2195 | { |
2196 | struct target_ops *t; | |
2197 | ||
2198 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
2199 | { | |
2200 | if (t->to_wait != NULL) | |
2201 | { | |
47608cb1 | 2202 | ptid_t retval = (*t->to_wait) (t, ptid, status, options); |
117de6a9 PA |
2203 | |
2204 | if (targetdebug) | |
2205 | { | |
2206 | char *status_string; | |
2207 | ||
2208 | status_string = target_waitstatus_to_string (status); | |
2209 | fprintf_unfiltered (gdb_stdlog, | |
2210 | "target_wait (%d, status) = %d, %s\n", | |
2211 | PIDGET (ptid), PIDGET (retval), | |
2212 | status_string); | |
2213 | xfree (status_string); | |
2214 | } | |
2215 | ||
2216 | return retval; | |
2217 | } | |
2218 | } | |
2219 | ||
2220 | noprocess (); | |
2221 | } | |
2222 | ||
2223 | char * | |
2224 | target_pid_to_str (ptid_t ptid) | |
2225 | { | |
2226 | struct target_ops *t; | |
2227 | ||
2228 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
2229 | { | |
2230 | if (t->to_pid_to_str != NULL) | |
2231 | return (*t->to_pid_to_str) (t, ptid); | |
2232 | } | |
2233 | ||
2234 | return normal_pid_to_str (ptid); | |
2235 | } | |
2236 | ||
e1ac3328 VP |
2237 | void |
2238 | target_resume (ptid_t ptid, int step, enum target_signal signal) | |
2239 | { | |
28439f5e PA |
2240 | struct target_ops *t; |
2241 | ||
4e5d721f | 2242 | target_dcache_invalidate (); |
28439f5e PA |
2243 | |
2244 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
2245 | { | |
2246 | if (t->to_resume != NULL) | |
2247 | { | |
2248 | t->to_resume (t, ptid, step, signal); | |
2249 | if (targetdebug) | |
2250 | fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", | |
2251 | PIDGET (ptid), | |
2252 | step ? "step" : "continue", | |
2253 | target_signal_to_name (signal)); | |
2254 | ||
e66408ed | 2255 | registers_changed_ptid (ptid); |
28439f5e PA |
2256 | set_executing (ptid, 1); |
2257 | set_running (ptid, 1); | |
edb3359d | 2258 | clear_inline_frame_state (ptid); |
28439f5e PA |
2259 | return; |
2260 | } | |
2261 | } | |
2262 | ||
2263 | noprocess (); | |
e1ac3328 | 2264 | } |
ee057212 DJ |
2265 | /* Look through the list of possible targets for a target that can |
2266 | follow forks. */ | |
2267 | ||
2268 | int | |
2269 | target_follow_fork (int follow_child) | |
2270 | { | |
2271 | struct target_ops *t; | |
2272 | ||
2273 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
2274 | { | |
2275 | if (t->to_follow_fork != NULL) | |
2276 | { | |
2277 | int retval = t->to_follow_fork (t, follow_child); | |
5d502164 | 2278 | |
ee057212 DJ |
2279 | if (targetdebug) |
2280 | fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n", | |
2281 | follow_child, retval); | |
2282 | return retval; | |
2283 | } | |
2284 | } | |
2285 | ||
2286 | /* Some target returned a fork event, but did not know how to follow it. */ | |
2287 | internal_error (__FILE__, __LINE__, | |
2288 | "could not find a target to follow fork"); | |
2289 | } | |
2290 | ||
136d6dae VP |
2291 | void |
2292 | target_mourn_inferior (void) | |
2293 | { | |
2294 | struct target_ops *t; | |
5d502164 | 2295 | |
136d6dae VP |
2296 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
2297 | { | |
2298 | if (t->to_mourn_inferior != NULL) | |
2299 | { | |
2300 | t->to_mourn_inferior (t); | |
947b8855 PA |
2301 | if (targetdebug) |
2302 | fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n"); | |
efbd6e75 JB |
2303 | |
2304 | /* We no longer need to keep handles on any of the object files. | |
2305 | Make sure to release them to avoid unnecessarily locking any | |
2306 | of them while we're not actually debugging. */ | |
2307 | bfd_cache_close_all (); | |
2308 | ||
136d6dae VP |
2309 | return; |
2310 | } | |
2311 | } | |
2312 | ||
2313 | internal_error (__FILE__, __LINE__, | |
82892036 | 2314 | "could not find a target to follow mourn inferior"); |
136d6dae VP |
2315 | } |
2316 | ||
424163ea DJ |
2317 | /* Look for a target which can describe architectural features, starting |
2318 | from TARGET. If we find one, return its description. */ | |
2319 | ||
2320 | const struct target_desc * | |
2321 | target_read_description (struct target_ops *target) | |
2322 | { | |
2323 | struct target_ops *t; | |
2324 | ||
2325 | for (t = target; t != NULL; t = t->beneath) | |
2326 | if (t->to_read_description != NULL) | |
2327 | { | |
2328 | const struct target_desc *tdesc; | |
2329 | ||
2330 | tdesc = t->to_read_description (t); | |
2331 | if (tdesc) | |
2332 | return tdesc; | |
2333 | } | |
2334 | ||
2335 | return NULL; | |
2336 | } | |
2337 | ||
08388c79 DE |
2338 | /* The default implementation of to_search_memory. |
2339 | This implements a basic search of memory, reading target memory and | |
2340 | performing the search here (as opposed to performing the search in on the | |
2341 | target side with, for example, gdbserver). */ | |
2342 | ||
2343 | int | |
2344 | simple_search_memory (struct target_ops *ops, | |
2345 | CORE_ADDR start_addr, ULONGEST search_space_len, | |
2346 | const gdb_byte *pattern, ULONGEST pattern_len, | |
2347 | CORE_ADDR *found_addrp) | |
2348 | { | |
2349 | /* NOTE: also defined in find.c testcase. */ | |
2350 | #define SEARCH_CHUNK_SIZE 16000 | |
2351 | const unsigned chunk_size = SEARCH_CHUNK_SIZE; | |
2352 | /* Buffer to hold memory contents for searching. */ | |
2353 | gdb_byte *search_buf; | |
2354 | unsigned search_buf_size; | |
2355 | struct cleanup *old_cleanups; | |
2356 | ||
2357 | search_buf_size = chunk_size + pattern_len - 1; | |
2358 | ||
2359 | /* No point in trying to allocate a buffer larger than the search space. */ | |
2360 | if (search_space_len < search_buf_size) | |
2361 | search_buf_size = search_space_len; | |
2362 | ||
2363 | search_buf = malloc (search_buf_size); | |
2364 | if (search_buf == NULL) | |
5e1471f5 | 2365 | error (_("Unable to allocate memory to perform the search.")); |
08388c79 DE |
2366 | old_cleanups = make_cleanup (free_current_contents, &search_buf); |
2367 | ||
2368 | /* Prime the search buffer. */ | |
2369 | ||
2370 | if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, | |
2371 | search_buf, start_addr, search_buf_size) != search_buf_size) | |
2372 | { | |
5e1471f5 | 2373 | warning (_("Unable to access target memory at %s, halting search."), |
08388c79 DE |
2374 | hex_string (start_addr)); |
2375 | do_cleanups (old_cleanups); | |
2376 | return -1; | |
2377 | } | |
2378 | ||
2379 | /* Perform the search. | |
2380 | ||
2381 | The loop is kept simple by allocating [N + pattern-length - 1] bytes. | |
2382 | When we've scanned N bytes we copy the trailing bytes to the start and | |
2383 | read in another N bytes. */ | |
2384 | ||
2385 | while (search_space_len >= pattern_len) | |
2386 | { | |
2387 | gdb_byte *found_ptr; | |
2388 | unsigned nr_search_bytes = min (search_space_len, search_buf_size); | |
2389 | ||
2390 | found_ptr = memmem (search_buf, nr_search_bytes, | |
2391 | pattern, pattern_len); | |
2392 | ||
2393 | if (found_ptr != NULL) | |
2394 | { | |
2395 | CORE_ADDR found_addr = start_addr + (found_ptr - search_buf); | |
5d502164 | 2396 | |
08388c79 DE |
2397 | *found_addrp = found_addr; |
2398 | do_cleanups (old_cleanups); | |
2399 | return 1; | |
2400 | } | |
2401 | ||
2402 | /* Not found in this chunk, skip to next chunk. */ | |
2403 | ||
2404 | /* Don't let search_space_len wrap here, it's unsigned. */ | |
2405 | if (search_space_len >= chunk_size) | |
2406 | search_space_len -= chunk_size; | |
2407 | else | |
2408 | search_space_len = 0; | |
2409 | ||
2410 | if (search_space_len >= pattern_len) | |
2411 | { | |
2412 | unsigned keep_len = search_buf_size - chunk_size; | |
8a35fb51 | 2413 | CORE_ADDR read_addr = start_addr + chunk_size + keep_len; |
08388c79 DE |
2414 | int nr_to_read; |
2415 | ||
2416 | /* Copy the trailing part of the previous iteration to the front | |
2417 | of the buffer for the next iteration. */ | |
2418 | gdb_assert (keep_len == pattern_len - 1); | |
2419 | memcpy (search_buf, search_buf + chunk_size, keep_len); | |
2420 | ||
2421 | nr_to_read = min (search_space_len - keep_len, chunk_size); | |
2422 | ||
2423 | if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, | |
2424 | search_buf + keep_len, read_addr, | |
2425 | nr_to_read) != nr_to_read) | |
2426 | { | |
5e1471f5 | 2427 | warning (_("Unable to access target memory at %s, halting search."), |
08388c79 DE |
2428 | hex_string (read_addr)); |
2429 | do_cleanups (old_cleanups); | |
2430 | return -1; | |
2431 | } | |
2432 | ||
2433 | start_addr += chunk_size; | |
2434 | } | |
2435 | } | |
2436 | ||
2437 | /* Not found. */ | |
2438 | ||
2439 | do_cleanups (old_cleanups); | |
2440 | return 0; | |
2441 | } | |
2442 | ||
2443 | /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the | |
2444 | sequence of bytes in PATTERN with length PATTERN_LEN. | |
2445 | ||
2446 | The result is 1 if found, 0 if not found, and -1 if there was an error | |
2447 | requiring halting of the search (e.g. memory read error). | |
2448 | If the pattern is found the address is recorded in FOUND_ADDRP. */ | |
2449 | ||
2450 | int | |
2451 | target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len, | |
2452 | const gdb_byte *pattern, ULONGEST pattern_len, | |
2453 | CORE_ADDR *found_addrp) | |
2454 | { | |
2455 | struct target_ops *t; | |
2456 | int found; | |
2457 | ||
2458 | /* We don't use INHERIT to set current_target.to_search_memory, | |
2459 | so we have to scan the target stack and handle targetdebug | |
2460 | ourselves. */ | |
2461 | ||
2462 | if (targetdebug) | |
2463 | fprintf_unfiltered (gdb_stdlog, "target_search_memory (%s, ...)\n", | |
2464 | hex_string (start_addr)); | |
2465 | ||
2466 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
2467 | if (t->to_search_memory != NULL) | |
2468 | break; | |
2469 | ||
2470 | if (t != NULL) | |
2471 | { | |
2472 | found = t->to_search_memory (t, start_addr, search_space_len, | |
2473 | pattern, pattern_len, found_addrp); | |
2474 | } | |
2475 | else | |
2476 | { | |
2477 | /* If a special version of to_search_memory isn't available, use the | |
2478 | simple version. */ | |
c35b1492 | 2479 | found = simple_search_memory (current_target.beneath, |
08388c79 DE |
2480 | start_addr, search_space_len, |
2481 | pattern, pattern_len, found_addrp); | |
2482 | } | |
2483 | ||
2484 | if (targetdebug) | |
2485 | fprintf_unfiltered (gdb_stdlog, " = %d\n", found); | |
2486 | ||
2487 | return found; | |
2488 | } | |
2489 | ||
8edfe269 DJ |
2490 | /* Look through the currently pushed targets. If none of them will |
2491 | be able to restart the currently running process, issue an error | |
2492 | message. */ | |
2493 | ||
2494 | void | |
2495 | target_require_runnable (void) | |
2496 | { | |
2497 | struct target_ops *t; | |
2498 | ||
2499 | for (t = target_stack; t != NULL; t = t->beneath) | |
2500 | { | |
2501 | /* If this target knows how to create a new program, then | |
2502 | assume we will still be able to after killing the current | |
2503 | one. Either killing and mourning will not pop T, or else | |
2504 | find_default_run_target will find it again. */ | |
2505 | if (t->to_create_inferior != NULL) | |
2506 | return; | |
2507 | ||
2508 | /* Do not worry about thread_stratum targets that can not | |
2509 | create inferiors. Assume they will be pushed again if | |
2510 | necessary, and continue to the process_stratum. */ | |
85e747d2 UW |
2511 | if (t->to_stratum == thread_stratum |
2512 | || t->to_stratum == arch_stratum) | |
8edfe269 DJ |
2513 | continue; |
2514 | ||
2515 | error (_("\ | |
2516 | The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."), | |
2517 | t->to_shortname); | |
2518 | } | |
2519 | ||
2520 | /* This function is only called if the target is running. In that | |
2521 | case there should have been a process_stratum target and it | |
2522 | should either know how to create inferiors, or not... */ | |
2523 | internal_error (__FILE__, __LINE__, "No targets found"); | |
2524 | } | |
2525 | ||
c906108c SS |
2526 | /* Look through the list of possible targets for a target that can |
2527 | execute a run or attach command without any other data. This is | |
2528 | used to locate the default process stratum. | |
2529 | ||
5f667f2d PA |
2530 | If DO_MESG is not NULL, the result is always valid (error() is |
2531 | called for errors); else, return NULL on error. */ | |
c906108c SS |
2532 | |
2533 | static struct target_ops * | |
fba45db2 | 2534 | find_default_run_target (char *do_mesg) |
c906108c SS |
2535 | { |
2536 | struct target_ops **t; | |
2537 | struct target_ops *runable = NULL; | |
2538 | int count; | |
2539 | ||
2540 | count = 0; | |
2541 | ||
2542 | for (t = target_structs; t < target_structs + target_struct_size; | |
2543 | ++t) | |
2544 | { | |
c5aa993b | 2545 | if ((*t)->to_can_run && target_can_run (*t)) |
c906108c SS |
2546 | { |
2547 | runable = *t; | |
2548 | ++count; | |
2549 | } | |
2550 | } | |
2551 | ||
2552 | if (count != 1) | |
5f667f2d PA |
2553 | { |
2554 | if (do_mesg) | |
2555 | error (_("Don't know how to %s. Try \"help target\"."), do_mesg); | |
2556 | else | |
2557 | return NULL; | |
2558 | } | |
c906108c SS |
2559 | |
2560 | return runable; | |
2561 | } | |
2562 | ||
2563 | void | |
136d6dae | 2564 | find_default_attach (struct target_ops *ops, char *args, int from_tty) |
c906108c SS |
2565 | { |
2566 | struct target_ops *t; | |
2567 | ||
c5aa993b | 2568 | t = find_default_run_target ("attach"); |
136d6dae | 2569 | (t->to_attach) (t, args, from_tty); |
c906108c SS |
2570 | return; |
2571 | } | |
2572 | ||
c906108c | 2573 | void |
136d6dae VP |
2574 | find_default_create_inferior (struct target_ops *ops, |
2575 | char *exec_file, char *allargs, char **env, | |
c27cda74 | 2576 | int from_tty) |
c906108c SS |
2577 | { |
2578 | struct target_ops *t; | |
2579 | ||
c5aa993b | 2580 | t = find_default_run_target ("run"); |
136d6dae | 2581 | (t->to_create_inferior) (t, exec_file, allargs, env, from_tty); |
c906108c SS |
2582 | return; |
2583 | } | |
2584 | ||
2c0b251b | 2585 | static int |
b84876c2 PA |
2586 | find_default_can_async_p (void) |
2587 | { | |
2588 | struct target_ops *t; | |
2589 | ||
5f667f2d PA |
2590 | /* This may be called before the target is pushed on the stack; |
2591 | look for the default process stratum. If there's none, gdb isn't | |
2592 | configured with a native debugger, and target remote isn't | |
2593 | connected yet. */ | |
2594 | t = find_default_run_target (NULL); | |
2595 | if (t && t->to_can_async_p) | |
b84876c2 PA |
2596 | return (t->to_can_async_p) (); |
2597 | return 0; | |
2598 | } | |
2599 | ||
2c0b251b | 2600 | static int |
b84876c2 PA |
2601 | find_default_is_async_p (void) |
2602 | { | |
2603 | struct target_ops *t; | |
2604 | ||
5f667f2d PA |
2605 | /* This may be called before the target is pushed on the stack; |
2606 | look for the default process stratum. If there's none, gdb isn't | |
2607 | configured with a native debugger, and target remote isn't | |
2608 | connected yet. */ | |
2609 | t = find_default_run_target (NULL); | |
2610 | if (t && t->to_is_async_p) | |
b84876c2 PA |
2611 | return (t->to_is_async_p) (); |
2612 | return 0; | |
2613 | } | |
2614 | ||
2c0b251b | 2615 | static int |
9908b566 VP |
2616 | find_default_supports_non_stop (void) |
2617 | { | |
2618 | struct target_ops *t; | |
2619 | ||
2620 | t = find_default_run_target (NULL); | |
2621 | if (t && t->to_supports_non_stop) | |
2622 | return (t->to_supports_non_stop) (); | |
2623 | return 0; | |
2624 | } | |
2625 | ||
2626 | int | |
2c0b251b | 2627 | target_supports_non_stop (void) |
9908b566 VP |
2628 | { |
2629 | struct target_ops *t; | |
5d502164 | 2630 | |
9908b566 VP |
2631 | for (t = ¤t_target; t != NULL; t = t->beneath) |
2632 | if (t->to_supports_non_stop) | |
2633 | return t->to_supports_non_stop (); | |
2634 | ||
2635 | return 0; | |
2636 | } | |
2637 | ||
2638 | ||
07e059b5 VP |
2639 | char * |
2640 | target_get_osdata (const char *type) | |
2641 | { | |
07e059b5 VP |
2642 | struct target_ops *t; |
2643 | ||
739ef7fb PA |
2644 | /* If we're already connected to something that can get us OS |
2645 | related data, use it. Otherwise, try using the native | |
2646 | target. */ | |
2647 | if (current_target.to_stratum >= process_stratum) | |
6d097e65 | 2648 | t = current_target.beneath; |
739ef7fb PA |
2649 | else |
2650 | t = find_default_run_target ("get OS data"); | |
07e059b5 VP |
2651 | |
2652 | if (!t) | |
2653 | return NULL; | |
2654 | ||
6d097e65 | 2655 | return target_read_stralloc (t, TARGET_OBJECT_OSDATA, type); |
07e059b5 VP |
2656 | } |
2657 | ||
6c95b8df PA |
2658 | /* Determine the current address space of thread PTID. */ |
2659 | ||
2660 | struct address_space * | |
2661 | target_thread_address_space (ptid_t ptid) | |
2662 | { | |
c0694254 | 2663 | struct address_space *aspace; |
6c95b8df | 2664 | struct inferior *inf; |
c0694254 PA |
2665 | struct target_ops *t; |
2666 | ||
2667 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
2668 | { | |
2669 | if (t->to_thread_address_space != NULL) | |
2670 | { | |
2671 | aspace = t->to_thread_address_space (t, ptid); | |
2672 | gdb_assert (aspace); | |
6c95b8df | 2673 | |
c0694254 PA |
2674 | if (targetdebug) |
2675 | fprintf_unfiltered (gdb_stdlog, | |
2676 | "target_thread_address_space (%s) = %d\n", | |
2677 | target_pid_to_str (ptid), | |
2678 | address_space_num (aspace)); | |
2679 | return aspace; | |
2680 | } | |
2681 | } | |
6c95b8df PA |
2682 | |
2683 | /* Fall-back to the "main" address space of the inferior. */ | |
2684 | inf = find_inferior_pid (ptid_get_pid (ptid)); | |
2685 | ||
2686 | if (inf == NULL || inf->aspace == NULL) | |
2687 | internal_error (__FILE__, __LINE__, "\ | |
2688 | Can't determine the current address space of thread %s\n", | |
2689 | target_pid_to_str (ptid)); | |
2690 | ||
2691 | return inf->aspace; | |
2692 | } | |
2693 | ||
e0d24f8d WZ |
2694 | static int |
2695 | default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
2696 | { | |
ffe5a37e | 2697 | return (len <= gdbarch_ptr_bit (target_gdbarch) / TARGET_CHAR_BIT); |
ccaa32c7 GS |
2698 | } |
2699 | ||
5009afc5 AS |
2700 | static int |
2701 | default_watchpoint_addr_within_range (struct target_ops *target, | |
2702 | CORE_ADDR addr, | |
2703 | CORE_ADDR start, int length) | |
2704 | { | |
2705 | return addr >= start && addr < start + length; | |
2706 | } | |
2707 | ||
c2250ad1 UW |
2708 | static struct gdbarch * |
2709 | default_thread_architecture (struct target_ops *ops, ptid_t ptid) | |
2710 | { | |
2711 | return target_gdbarch; | |
2712 | } | |
2713 | ||
c906108c | 2714 | static int |
fba45db2 | 2715 | return_zero (void) |
c906108c SS |
2716 | { |
2717 | return 0; | |
2718 | } | |
2719 | ||
2720 | static int | |
fba45db2 | 2721 | return_one (void) |
c906108c SS |
2722 | { |
2723 | return 1; | |
2724 | } | |
2725 | ||
ccaa32c7 GS |
2726 | static int |
2727 | return_minus_one (void) | |
2728 | { | |
2729 | return -1; | |
2730 | } | |
2731 | ||
7a292a7a SS |
2732 | /* Find a single runnable target in the stack and return it. If for |
2733 | some reason there is more than one, return NULL. */ | |
2734 | ||
2735 | struct target_ops * | |
fba45db2 | 2736 | find_run_target (void) |
7a292a7a SS |
2737 | { |
2738 | struct target_ops **t; | |
2739 | struct target_ops *runable = NULL; | |
2740 | int count; | |
c5aa993b | 2741 | |
7a292a7a | 2742 | count = 0; |
c5aa993b | 2743 | |
7a292a7a SS |
2744 | for (t = target_structs; t < target_structs + target_struct_size; ++t) |
2745 | { | |
c5aa993b | 2746 | if ((*t)->to_can_run && target_can_run (*t)) |
7a292a7a SS |
2747 | { |
2748 | runable = *t; | |
2749 | ++count; | |
2750 | } | |
2751 | } | |
c5aa993b | 2752 | |
7a292a7a SS |
2753 | return (count == 1 ? runable : NULL); |
2754 | } | |
2755 | ||
ed9a39eb JM |
2756 | /* Find a single core_stratum target in the list of targets and return it. |
2757 | If for some reason there is more than one, return NULL. */ | |
2758 | ||
c906108c | 2759 | struct target_ops * |
fba45db2 | 2760 | find_core_target (void) |
c906108c SS |
2761 | { |
2762 | struct target_ops **t; | |
2763 | struct target_ops *runable = NULL; | |
2764 | int count; | |
c5aa993b | 2765 | |
c906108c | 2766 | count = 0; |
c5aa993b | 2767 | |
c906108c SS |
2768 | for (t = target_structs; t < target_structs + target_struct_size; |
2769 | ++t) | |
2770 | { | |
2771 | if ((*t)->to_stratum == core_stratum) | |
2772 | { | |
2773 | runable = *t; | |
2774 | ++count; | |
2775 | } | |
2776 | } | |
c5aa993b JM |
2777 | |
2778 | return (count == 1 ? runable : NULL); | |
c906108c | 2779 | } |
ed9a39eb JM |
2780 | |
2781 | /* | |
2782 | * Find the next target down the stack from the specified target. | |
2783 | */ | |
2784 | ||
2785 | struct target_ops * | |
fba45db2 | 2786 | find_target_beneath (struct target_ops *t) |
ed9a39eb | 2787 | { |
258b763a | 2788 | return t->beneath; |
ed9a39eb JM |
2789 | } |
2790 | ||
c906108c SS |
2791 | \f |
2792 | /* The inferior process has died. Long live the inferior! */ | |
2793 | ||
2794 | void | |
fba45db2 | 2795 | generic_mourn_inferior (void) |
c906108c | 2796 | { |
7f9f62ba | 2797 | ptid_t ptid; |
c906108c | 2798 | |
7f9f62ba | 2799 | ptid = inferior_ptid; |
39f77062 | 2800 | inferior_ptid = null_ptid; |
7f9f62ba PA |
2801 | |
2802 | if (!ptid_equal (ptid, null_ptid)) | |
2803 | { | |
2804 | int pid = ptid_get_pid (ptid); | |
6c95b8df | 2805 | exit_inferior (pid); |
7f9f62ba PA |
2806 | } |
2807 | ||
c906108c SS |
2808 | breakpoint_init_inferior (inf_exited); |
2809 | registers_changed (); | |
2810 | ||
c906108c SS |
2811 | reopen_exec_file (); |
2812 | reinit_frame_cache (); | |
2813 | ||
9a4105ab AC |
2814 | if (deprecated_detach_hook) |
2815 | deprecated_detach_hook (); | |
c906108c SS |
2816 | } |
2817 | \f | |
8807d78b | 2818 | /* Helper function for child_wait and the derivatives of child_wait. |
c906108c SS |
2819 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our |
2820 | translation of that in OURSTATUS. */ | |
2821 | void | |
fba45db2 | 2822 | store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus) |
c906108c | 2823 | { |
c906108c SS |
2824 | if (WIFEXITED (hoststatus)) |
2825 | { | |
2826 | ourstatus->kind = TARGET_WAITKIND_EXITED; | |
2827 | ourstatus->value.integer = WEXITSTATUS (hoststatus); | |
2828 | } | |
2829 | else if (!WIFSTOPPED (hoststatus)) | |
2830 | { | |
2831 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
2832 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); | |
2833 | } | |
2834 | else | |
2835 | { | |
2836 | ourstatus->kind = TARGET_WAITKIND_STOPPED; | |
2837 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); | |
2838 | } | |
2839 | } | |
2840 | \f | |
fd0a2a6f MK |
2841 | /* Convert a normal process ID to a string. Returns the string in a |
2842 | static buffer. */ | |
c906108c SS |
2843 | |
2844 | char * | |
39f77062 | 2845 | normal_pid_to_str (ptid_t ptid) |
c906108c | 2846 | { |
fd0a2a6f | 2847 | static char buf[32]; |
c906108c | 2848 | |
5fff8fc0 | 2849 | xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid)); |
c906108c SS |
2850 | return buf; |
2851 | } | |
2852 | ||
2c0b251b | 2853 | static char * |
117de6a9 PA |
2854 | dummy_pid_to_str (struct target_ops *ops, ptid_t ptid) |
2855 | { | |
2856 | return normal_pid_to_str (ptid); | |
2857 | } | |
2858 | ||
9b4eba8e HZ |
2859 | /* Error-catcher for target_find_memory_regions. */ |
2860 | static int | |
2861 | dummy_find_memory_regions (int (*ignore1) (), void *ignore2) | |
be4d1333 | 2862 | { |
9b4eba8e | 2863 | error (_("Command not implemented for this target.")); |
be4d1333 MS |
2864 | return 0; |
2865 | } | |
2866 | ||
9b4eba8e HZ |
2867 | /* Error-catcher for target_make_corefile_notes. */ |
2868 | static char * | |
2869 | dummy_make_corefile_notes (bfd *ignore1, int *ignore2) | |
be4d1333 | 2870 | { |
9b4eba8e | 2871 | error (_("Command not implemented for this target.")); |
be4d1333 MS |
2872 | return NULL; |
2873 | } | |
2874 | ||
6b04bdb7 MS |
2875 | /* Error-catcher for target_get_bookmark. */ |
2876 | static gdb_byte * | |
2877 | dummy_get_bookmark (char *ignore1, int ignore2) | |
2878 | { | |
2879 | tcomplain (); | |
2880 | return NULL; | |
2881 | } | |
2882 | ||
2883 | /* Error-catcher for target_goto_bookmark. */ | |
2884 | static void | |
2885 | dummy_goto_bookmark (gdb_byte *ignore, int from_tty) | |
2886 | { | |
2887 | tcomplain (); | |
2888 | } | |
2889 | ||
c906108c SS |
2890 | /* Set up the handful of non-empty slots needed by the dummy target |
2891 | vector. */ | |
2892 | ||
2893 | static void | |
fba45db2 | 2894 | init_dummy_target (void) |
c906108c SS |
2895 | { |
2896 | dummy_target.to_shortname = "None"; | |
2897 | dummy_target.to_longname = "None"; | |
2898 | dummy_target.to_doc = ""; | |
2899 | dummy_target.to_attach = find_default_attach; | |
136d6dae VP |
2900 | dummy_target.to_detach = |
2901 | (void (*)(struct target_ops *, char *, int))target_ignore; | |
c906108c | 2902 | dummy_target.to_create_inferior = find_default_create_inferior; |
b84876c2 PA |
2903 | dummy_target.to_can_async_p = find_default_can_async_p; |
2904 | dummy_target.to_is_async_p = find_default_is_async_p; | |
9908b566 | 2905 | dummy_target.to_supports_non_stop = find_default_supports_non_stop; |
117de6a9 | 2906 | dummy_target.to_pid_to_str = dummy_pid_to_str; |
c906108c | 2907 | dummy_target.to_stratum = dummy_stratum; |
be4d1333 MS |
2908 | dummy_target.to_find_memory_regions = dummy_find_memory_regions; |
2909 | dummy_target.to_make_corefile_notes = dummy_make_corefile_notes; | |
6b04bdb7 MS |
2910 | dummy_target.to_get_bookmark = dummy_get_bookmark; |
2911 | dummy_target.to_goto_bookmark = dummy_goto_bookmark; | |
0b603eba | 2912 | dummy_target.to_xfer_partial = default_xfer_partial; |
c35b1492 PA |
2913 | dummy_target.to_has_all_memory = (int (*) (struct target_ops *)) return_zero; |
2914 | dummy_target.to_has_memory = (int (*) (struct target_ops *)) return_zero; | |
2915 | dummy_target.to_has_stack = (int (*) (struct target_ops *)) return_zero; | |
2916 | dummy_target.to_has_registers = (int (*) (struct target_ops *)) return_zero; | |
2917 | dummy_target.to_has_execution = (int (*) (struct target_ops *)) return_zero; | |
7155de5a HZ |
2918 | dummy_target.to_stopped_by_watchpoint = return_zero; |
2919 | dummy_target.to_stopped_data_address = | |
2920 | (int (*) (struct target_ops *, CORE_ADDR *)) return_zero; | |
c906108c SS |
2921 | dummy_target.to_magic = OPS_MAGIC; |
2922 | } | |
c906108c | 2923 | \f |
c906108c | 2924 | static void |
fba45db2 | 2925 | debug_to_open (char *args, int from_tty) |
c906108c SS |
2926 | { |
2927 | debug_target.to_open (args, from_tty); | |
2928 | ||
96baa820 | 2929 | fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty); |
c906108c SS |
2930 | } |
2931 | ||
f1c07ab0 AC |
2932 | void |
2933 | target_close (struct target_ops *targ, int quitting) | |
2934 | { | |
2935 | if (targ->to_xclose != NULL) | |
2936 | targ->to_xclose (targ, quitting); | |
2937 | else if (targ->to_close != NULL) | |
2938 | targ->to_close (quitting); | |
947b8855 PA |
2939 | |
2940 | if (targetdebug) | |
2941 | fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting); | |
f1c07ab0 AC |
2942 | } |
2943 | ||
136d6dae VP |
2944 | void |
2945 | target_attach (char *args, int from_tty) | |
2946 | { | |
2947 | struct target_ops *t; | |
5d502164 | 2948 | |
136d6dae VP |
2949 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
2950 | { | |
2951 | if (t->to_attach != NULL) | |
2952 | { | |
2953 | t->to_attach (t, args, from_tty); | |
947b8855 PA |
2954 | if (targetdebug) |
2955 | fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", | |
2956 | args, from_tty); | |
136d6dae VP |
2957 | return; |
2958 | } | |
2959 | } | |
2960 | ||
2961 | internal_error (__FILE__, __LINE__, | |
2962 | "could not find a target to attach"); | |
2963 | } | |
2964 | ||
28439f5e PA |
2965 | int |
2966 | target_thread_alive (ptid_t ptid) | |
c906108c | 2967 | { |
28439f5e | 2968 | struct target_ops *t; |
5d502164 | 2969 | |
28439f5e PA |
2970 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
2971 | { | |
2972 | if (t->to_thread_alive != NULL) | |
2973 | { | |
2974 | int retval; | |
c906108c | 2975 | |
28439f5e PA |
2976 | retval = t->to_thread_alive (t, ptid); |
2977 | if (targetdebug) | |
2978 | fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n", | |
2979 | PIDGET (ptid), retval); | |
2980 | ||
2981 | return retval; | |
2982 | } | |
2983 | } | |
2984 | ||
2985 | return 0; | |
2986 | } | |
2987 | ||
2988 | void | |
2989 | target_find_new_threads (void) | |
2990 | { | |
2991 | struct target_ops *t; | |
5d502164 | 2992 | |
28439f5e PA |
2993 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
2994 | { | |
2995 | if (t->to_find_new_threads != NULL) | |
2996 | { | |
2997 | t->to_find_new_threads (t); | |
2998 | if (targetdebug) | |
2999 | fprintf_unfiltered (gdb_stdlog, "target_find_new_threads ()\n"); | |
3000 | ||
3001 | return; | |
3002 | } | |
3003 | } | |
c906108c SS |
3004 | } |
3005 | ||
d914c394 SS |
3006 | void |
3007 | target_stop (ptid_t ptid) | |
3008 | { | |
3009 | if (!may_stop) | |
3010 | { | |
3011 | warning (_("May not interrupt or stop the target, ignoring attempt")); | |
3012 | return; | |
3013 | } | |
3014 | ||
3015 | (*current_target.to_stop) (ptid); | |
3016 | } | |
3017 | ||
c906108c | 3018 | static void |
28439f5e | 3019 | debug_to_post_attach (int pid) |
c906108c | 3020 | { |
28439f5e | 3021 | debug_target.to_post_attach (pid); |
c906108c | 3022 | |
28439f5e | 3023 | fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid); |
c906108c SS |
3024 | } |
3025 | ||
f00150c9 DE |
3026 | /* Return a pretty printed form of target_waitstatus. |
3027 | Space for the result is malloc'd, caller must free. */ | |
c906108c | 3028 | |
f00150c9 DE |
3029 | char * |
3030 | target_waitstatus_to_string (const struct target_waitstatus *ws) | |
3031 | { | |
3032 | const char *kind_str = "status->kind = "; | |
c906108c | 3033 | |
f00150c9 | 3034 | switch (ws->kind) |
c906108c SS |
3035 | { |
3036 | case TARGET_WAITKIND_EXITED: | |
f00150c9 DE |
3037 | return xstrprintf ("%sexited, status = %d", |
3038 | kind_str, ws->value.integer); | |
c906108c | 3039 | case TARGET_WAITKIND_STOPPED: |
f00150c9 DE |
3040 | return xstrprintf ("%sstopped, signal = %s", |
3041 | kind_str, target_signal_to_name (ws->value.sig)); | |
c906108c | 3042 | case TARGET_WAITKIND_SIGNALLED: |
f00150c9 DE |
3043 | return xstrprintf ("%ssignalled, signal = %s", |
3044 | kind_str, target_signal_to_name (ws->value.sig)); | |
c906108c | 3045 | case TARGET_WAITKIND_LOADED: |
f00150c9 | 3046 | return xstrprintf ("%sloaded", kind_str); |
c906108c | 3047 | case TARGET_WAITKIND_FORKED: |
f00150c9 | 3048 | return xstrprintf ("%sforked", kind_str); |
c906108c | 3049 | case TARGET_WAITKIND_VFORKED: |
f00150c9 | 3050 | return xstrprintf ("%svforked", kind_str); |
c906108c | 3051 | case TARGET_WAITKIND_EXECD: |
f00150c9 DE |
3052 | return xstrprintf ("%sexecd", kind_str); |
3053 | case TARGET_WAITKIND_SYSCALL_ENTRY: | |
a96d9b2e | 3054 | return xstrprintf ("%sentered syscall", kind_str); |
f00150c9 | 3055 | case TARGET_WAITKIND_SYSCALL_RETURN: |
a96d9b2e | 3056 | return xstrprintf ("%sexited syscall", kind_str); |
c906108c | 3057 | case TARGET_WAITKIND_SPURIOUS: |
f00150c9 DE |
3058 | return xstrprintf ("%sspurious", kind_str); |
3059 | case TARGET_WAITKIND_IGNORE: | |
3060 | return xstrprintf ("%signore", kind_str); | |
3061 | case TARGET_WAITKIND_NO_HISTORY: | |
3062 | return xstrprintf ("%sno-history", kind_str); | |
c906108c | 3063 | default: |
f00150c9 | 3064 | return xstrprintf ("%sunknown???", kind_str); |
c906108c | 3065 | } |
f00150c9 DE |
3066 | } |
3067 | ||
bf0c5130 | 3068 | static void |
56be3814 UW |
3069 | debug_print_register (const char * func, |
3070 | struct regcache *regcache, int regno) | |
bf0c5130 | 3071 | { |
f8d29908 | 3072 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
5d502164 | 3073 | |
bf0c5130 | 3074 | fprintf_unfiltered (gdb_stdlog, "%s ", func); |
f8d29908 | 3075 | if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) |
f8d29908 UW |
3076 | && gdbarch_register_name (gdbarch, regno) != NULL |
3077 | && gdbarch_register_name (gdbarch, regno)[0] != '\0') | |
3078 | fprintf_unfiltered (gdb_stdlog, "(%s)", | |
3079 | gdbarch_register_name (gdbarch, regno)); | |
bf0c5130 AC |
3080 | else |
3081 | fprintf_unfiltered (gdb_stdlog, "(%d)", regno); | |
0ff58721 | 3082 | if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) |
bf0c5130 | 3083 | { |
e17a4113 | 3084 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
f8d29908 | 3085 | int i, size = register_size (gdbarch, regno); |
d9d9c31f | 3086 | unsigned char buf[MAX_REGISTER_SIZE]; |
5d502164 | 3087 | |
0ff58721 | 3088 | regcache_raw_collect (regcache, regno, buf); |
bf0c5130 | 3089 | fprintf_unfiltered (gdb_stdlog, " = "); |
81c4a259 | 3090 | for (i = 0; i < size; i++) |
bf0c5130 AC |
3091 | { |
3092 | fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); | |
3093 | } | |
81c4a259 | 3094 | if (size <= sizeof (LONGEST)) |
bf0c5130 | 3095 | { |
e17a4113 | 3096 | ULONGEST val = extract_unsigned_integer (buf, size, byte_order); |
5d502164 | 3097 | |
0b1553bc UW |
3098 | fprintf_unfiltered (gdb_stdlog, " %s %s", |
3099 | core_addr_to_string_nz (val), plongest (val)); | |
bf0c5130 AC |
3100 | } |
3101 | } | |
3102 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3103 | } | |
3104 | ||
28439f5e PA |
3105 | void |
3106 | target_fetch_registers (struct regcache *regcache, int regno) | |
c906108c | 3107 | { |
28439f5e | 3108 | struct target_ops *t; |
5d502164 | 3109 | |
28439f5e PA |
3110 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
3111 | { | |
3112 | if (t->to_fetch_registers != NULL) | |
3113 | { | |
3114 | t->to_fetch_registers (t, regcache, regno); | |
3115 | if (targetdebug) | |
3116 | debug_print_register ("target_fetch_registers", regcache, regno); | |
3117 | return; | |
3118 | } | |
3119 | } | |
c906108c SS |
3120 | } |
3121 | ||
28439f5e PA |
3122 | void |
3123 | target_store_registers (struct regcache *regcache, int regno) | |
c906108c | 3124 | { |
28439f5e | 3125 | struct target_ops *t; |
5d502164 | 3126 | |
d914c394 SS |
3127 | if (!may_write_registers) |
3128 | error (_("Writing to registers is not allowed (regno %d)"), regno); | |
3129 | ||
28439f5e PA |
3130 | for (t = current_target.beneath; t != NULL; t = t->beneath) |
3131 | { | |
3132 | if (t->to_store_registers != NULL) | |
3133 | { | |
3134 | t->to_store_registers (t, regcache, regno); | |
3135 | if (targetdebug) | |
3136 | { | |
3137 | debug_print_register ("target_store_registers", regcache, regno); | |
3138 | } | |
3139 | return; | |
3140 | } | |
3141 | } | |
3142 | ||
3143 | noprocess (); | |
c906108c SS |
3144 | } |
3145 | ||
dc146f7c VP |
3146 | int |
3147 | target_core_of_thread (ptid_t ptid) | |
3148 | { | |
3149 | struct target_ops *t; | |
3150 | ||
3151 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
3152 | { | |
3153 | if (t->to_core_of_thread != NULL) | |
3154 | { | |
3155 | int retval = t->to_core_of_thread (t, ptid); | |
5d502164 | 3156 | |
dc146f7c VP |
3157 | if (targetdebug) |
3158 | fprintf_unfiltered (gdb_stdlog, "target_core_of_thread (%d) = %d\n", | |
3159 | PIDGET (ptid), retval); | |
3160 | return retval; | |
3161 | } | |
3162 | } | |
3163 | ||
3164 | return -1; | |
3165 | } | |
3166 | ||
4a5e7a5b PA |
3167 | int |
3168 | target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size) | |
3169 | { | |
3170 | struct target_ops *t; | |
3171 | ||
3172 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
3173 | { | |
3174 | if (t->to_verify_memory != NULL) | |
3175 | { | |
3176 | int retval = t->to_verify_memory (t, data, memaddr, size); | |
5d502164 | 3177 | |
4a5e7a5b PA |
3178 | if (targetdebug) |
3179 | fprintf_unfiltered (gdb_stdlog, "target_verify_memory (%s, %s) = %d\n", | |
3180 | paddress (target_gdbarch, memaddr), | |
3181 | pulongest (size), | |
3182 | retval); | |
3183 | return retval; | |
3184 | } | |
3185 | } | |
3186 | ||
3187 | tcomplain (); | |
3188 | } | |
3189 | ||
c906108c | 3190 | static void |
316f2060 | 3191 | debug_to_prepare_to_store (struct regcache *regcache) |
c906108c | 3192 | { |
316f2060 | 3193 | debug_target.to_prepare_to_store (regcache); |
c906108c | 3194 | |
96baa820 | 3195 | fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n"); |
c906108c SS |
3196 | } |
3197 | ||
3198 | static int | |
961cb7b5 | 3199 | deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len, |
c8e73a31 AC |
3200 | int write, struct mem_attrib *attrib, |
3201 | struct target_ops *target) | |
c906108c SS |
3202 | { |
3203 | int retval; | |
3204 | ||
c8e73a31 AC |
3205 | retval = debug_target.deprecated_xfer_memory (memaddr, myaddr, len, write, |
3206 | attrib, target); | |
c906108c | 3207 | |
96baa820 | 3208 | fprintf_unfiltered (gdb_stdlog, |
53b71562 | 3209 | "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d", |
5af949e3 UW |
3210 | paddress (target_gdbarch, memaddr), len, |
3211 | write ? "write" : "read", retval); | |
c906108c | 3212 | |
c906108c SS |
3213 | if (retval > 0) |
3214 | { | |
3215 | int i; | |
3216 | ||
96baa820 | 3217 | fputs_unfiltered (", bytes =", gdb_stdlog); |
c906108c SS |
3218 | for (i = 0; i < retval; i++) |
3219 | { | |
53b71562 | 3220 | if ((((intptr_t) &(myaddr[i])) & 0xf) == 0) |
333dabeb DJ |
3221 | { |
3222 | if (targetdebug < 2 && i > 0) | |
3223 | { | |
3224 | fprintf_unfiltered (gdb_stdlog, " ..."); | |
3225 | break; | |
3226 | } | |
3227 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3228 | } | |
2bc416ba | 3229 | |
96baa820 | 3230 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
c906108c SS |
3231 | } |
3232 | } | |
3233 | ||
96baa820 | 3234 | fputc_unfiltered ('\n', gdb_stdlog); |
c906108c SS |
3235 | |
3236 | return retval; | |
3237 | } | |
3238 | ||
3239 | static void | |
fba45db2 | 3240 | debug_to_files_info (struct target_ops *target) |
c906108c SS |
3241 | { |
3242 | debug_target.to_files_info (target); | |
3243 | ||
96baa820 | 3244 | fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n"); |
c906108c SS |
3245 | } |
3246 | ||
3247 | static int | |
a6d9a66e UW |
3248 | debug_to_insert_breakpoint (struct gdbarch *gdbarch, |
3249 | struct bp_target_info *bp_tgt) | |
c906108c SS |
3250 | { |
3251 | int retval; | |
3252 | ||
a6d9a66e | 3253 | retval = debug_target.to_insert_breakpoint (gdbarch, bp_tgt); |
c906108c | 3254 | |
96baa820 | 3255 | fprintf_unfiltered (gdb_stdlog, |
104c1213 | 3256 | "target_insert_breakpoint (0x%lx, xxx) = %ld\n", |
8181d85f | 3257 | (unsigned long) bp_tgt->placed_address, |
104c1213 | 3258 | (unsigned long) retval); |
c906108c SS |
3259 | return retval; |
3260 | } | |
3261 | ||
3262 | static int | |
a6d9a66e UW |
3263 | debug_to_remove_breakpoint (struct gdbarch *gdbarch, |
3264 | struct bp_target_info *bp_tgt) | |
c906108c SS |
3265 | { |
3266 | int retval; | |
3267 | ||
a6d9a66e | 3268 | retval = debug_target.to_remove_breakpoint (gdbarch, bp_tgt); |
c906108c | 3269 | |
96baa820 | 3270 | fprintf_unfiltered (gdb_stdlog, |
104c1213 | 3271 | "target_remove_breakpoint (0x%lx, xxx) = %ld\n", |
8181d85f | 3272 | (unsigned long) bp_tgt->placed_address, |
104c1213 | 3273 | (unsigned long) retval); |
c906108c SS |
3274 | return retval; |
3275 | } | |
3276 | ||
ccaa32c7 GS |
3277 | static int |
3278 | debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty) | |
3279 | { | |
3280 | int retval; | |
3281 | ||
3282 | retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty); | |
3283 | ||
3284 | fprintf_unfiltered (gdb_stdlog, | |
3285 | "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n", | |
3286 | (unsigned long) type, | |
3287 | (unsigned long) cnt, | |
3288 | (unsigned long) from_tty, | |
3289 | (unsigned long) retval); | |
3290 | return retval; | |
3291 | } | |
3292 | ||
e0d24f8d WZ |
3293 | static int |
3294 | debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
3295 | { | |
3296 | CORE_ADDR retval; | |
3297 | ||
3298 | retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len); | |
3299 | ||
3300 | fprintf_unfiltered (gdb_stdlog, | |
d92524f1 | 3301 | "target_region_ok_for_hw_watchpoint (%ld, %ld) = 0x%lx\n", |
e0d24f8d WZ |
3302 | (unsigned long) addr, |
3303 | (unsigned long) len, | |
3304 | (unsigned long) retval); | |
3305 | return retval; | |
3306 | } | |
3307 | ||
ccaa32c7 GS |
3308 | static int |
3309 | debug_to_stopped_by_watchpoint (void) | |
3310 | { | |
3311 | int retval; | |
3312 | ||
3313 | retval = debug_target.to_stopped_by_watchpoint (); | |
3314 | ||
3315 | fprintf_unfiltered (gdb_stdlog, | |
d92524f1 | 3316 | "target_stopped_by_watchpoint () = %ld\n", |
ccaa32c7 GS |
3317 | (unsigned long) retval); |
3318 | return retval; | |
3319 | } | |
3320 | ||
4aa7a7f5 JJ |
3321 | static int |
3322 | debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr) | |
ccaa32c7 | 3323 | { |
4aa7a7f5 | 3324 | int retval; |
ccaa32c7 | 3325 | |
4aa7a7f5 | 3326 | retval = debug_target.to_stopped_data_address (target, addr); |
ccaa32c7 GS |
3327 | |
3328 | fprintf_unfiltered (gdb_stdlog, | |
4aa7a7f5 JJ |
3329 | "target_stopped_data_address ([0x%lx]) = %ld\n", |
3330 | (unsigned long)*addr, | |
3331 | (unsigned long)retval); | |
ccaa32c7 GS |
3332 | return retval; |
3333 | } | |
3334 | ||
5009afc5 AS |
3335 | static int |
3336 | debug_to_watchpoint_addr_within_range (struct target_ops *target, | |
3337 | CORE_ADDR addr, | |
3338 | CORE_ADDR start, int length) | |
3339 | { | |
3340 | int retval; | |
3341 | ||
3342 | retval = debug_target.to_watchpoint_addr_within_range (target, addr, | |
3343 | start, length); | |
3344 | ||
3345 | fprintf_filtered (gdb_stdlog, | |
3346 | "target_watchpoint_addr_within_range (0x%lx, 0x%lx, %d) = %d\n", | |
3347 | (unsigned long) addr, (unsigned long) start, length, | |
3348 | retval); | |
3349 | return retval; | |
3350 | } | |
3351 | ||
ccaa32c7 | 3352 | static int |
a6d9a66e UW |
3353 | debug_to_insert_hw_breakpoint (struct gdbarch *gdbarch, |
3354 | struct bp_target_info *bp_tgt) | |
ccaa32c7 GS |
3355 | { |
3356 | int retval; | |
3357 | ||
a6d9a66e | 3358 | retval = debug_target.to_insert_hw_breakpoint (gdbarch, bp_tgt); |
ccaa32c7 GS |
3359 | |
3360 | fprintf_unfiltered (gdb_stdlog, | |
3361 | "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
8181d85f | 3362 | (unsigned long) bp_tgt->placed_address, |
ccaa32c7 GS |
3363 | (unsigned long) retval); |
3364 | return retval; | |
3365 | } | |
3366 | ||
3367 | static int | |
a6d9a66e UW |
3368 | debug_to_remove_hw_breakpoint (struct gdbarch *gdbarch, |
3369 | struct bp_target_info *bp_tgt) | |
ccaa32c7 GS |
3370 | { |
3371 | int retval; | |
3372 | ||
a6d9a66e | 3373 | retval = debug_target.to_remove_hw_breakpoint (gdbarch, bp_tgt); |
ccaa32c7 GS |
3374 | |
3375 | fprintf_unfiltered (gdb_stdlog, | |
3376 | "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
8181d85f | 3377 | (unsigned long) bp_tgt->placed_address, |
ccaa32c7 GS |
3378 | (unsigned long) retval); |
3379 | return retval; | |
3380 | } | |
3381 | ||
3382 | static int | |
3383 | debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type) | |
3384 | { | |
3385 | int retval; | |
3386 | ||
3387 | retval = debug_target.to_insert_watchpoint (addr, len, type); | |
3388 | ||
3389 | fprintf_unfiltered (gdb_stdlog, | |
3390 | "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n", | |
3391 | (unsigned long) addr, len, type, (unsigned long) retval); | |
3392 | return retval; | |
3393 | } | |
3394 | ||
3395 | static int | |
3396 | debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type) | |
3397 | { | |
3398 | int retval; | |
3399 | ||
ecde4882 | 3400 | retval = debug_target.to_remove_watchpoint (addr, len, type); |
ccaa32c7 GS |
3401 | |
3402 | fprintf_unfiltered (gdb_stdlog, | |
ecde4882 | 3403 | "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n", |
ccaa32c7 GS |
3404 | (unsigned long) addr, len, type, (unsigned long) retval); |
3405 | return retval; | |
3406 | } | |
3407 | ||
c906108c | 3408 | static void |
fba45db2 | 3409 | debug_to_terminal_init (void) |
c906108c SS |
3410 | { |
3411 | debug_target.to_terminal_init (); | |
3412 | ||
96baa820 | 3413 | fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n"); |
c906108c SS |
3414 | } |
3415 | ||
3416 | static void | |
fba45db2 | 3417 | debug_to_terminal_inferior (void) |
c906108c SS |
3418 | { |
3419 | debug_target.to_terminal_inferior (); | |
3420 | ||
96baa820 | 3421 | fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n"); |
c906108c SS |
3422 | } |
3423 | ||
3424 | static void | |
fba45db2 | 3425 | debug_to_terminal_ours_for_output (void) |
c906108c SS |
3426 | { |
3427 | debug_target.to_terminal_ours_for_output (); | |
3428 | ||
96baa820 | 3429 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n"); |
c906108c SS |
3430 | } |
3431 | ||
3432 | static void | |
fba45db2 | 3433 | debug_to_terminal_ours (void) |
c906108c SS |
3434 | { |
3435 | debug_target.to_terminal_ours (); | |
3436 | ||
96baa820 | 3437 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n"); |
c906108c SS |
3438 | } |
3439 | ||
a790ad35 SC |
3440 | static void |
3441 | debug_to_terminal_save_ours (void) | |
3442 | { | |
3443 | debug_target.to_terminal_save_ours (); | |
3444 | ||
3445 | fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n"); | |
3446 | } | |
3447 | ||
c906108c | 3448 | static void |
fba45db2 | 3449 | debug_to_terminal_info (char *arg, int from_tty) |
c906108c SS |
3450 | { |
3451 | debug_target.to_terminal_info (arg, from_tty); | |
3452 | ||
96baa820 | 3453 | fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg, |
c906108c SS |
3454 | from_tty); |
3455 | } | |
3456 | ||
c906108c | 3457 | static void |
fba45db2 | 3458 | debug_to_load (char *args, int from_tty) |
c906108c SS |
3459 | { |
3460 | debug_target.to_load (args, from_tty); | |
3461 | ||
96baa820 | 3462 | fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty); |
c906108c SS |
3463 | } |
3464 | ||
3465 | static int | |
fba45db2 | 3466 | debug_to_lookup_symbol (char *name, CORE_ADDR *addrp) |
c906108c SS |
3467 | { |
3468 | int retval; | |
3469 | ||
3470 | retval = debug_target.to_lookup_symbol (name, addrp); | |
3471 | ||
96baa820 | 3472 | fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name); |
c906108c SS |
3473 | |
3474 | return retval; | |
3475 | } | |
3476 | ||
c906108c | 3477 | static void |
39f77062 | 3478 | debug_to_post_startup_inferior (ptid_t ptid) |
c906108c | 3479 | { |
39f77062 | 3480 | debug_target.to_post_startup_inferior (ptid); |
c906108c | 3481 | |
96baa820 | 3482 | fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n", |
39f77062 | 3483 | PIDGET (ptid)); |
c906108c SS |
3484 | } |
3485 | ||
3486 | static void | |
fba45db2 | 3487 | debug_to_acknowledge_created_inferior (int pid) |
c906108c SS |
3488 | { |
3489 | debug_target.to_acknowledge_created_inferior (pid); | |
3490 | ||
96baa820 | 3491 | fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n", |
c906108c SS |
3492 | pid); |
3493 | } | |
3494 | ||
fa113d1a | 3495 | static void |
fba45db2 | 3496 | debug_to_insert_fork_catchpoint (int pid) |
c906108c | 3497 | { |
fa113d1a | 3498 | debug_target.to_insert_fork_catchpoint (pid); |
c906108c | 3499 | |
fa113d1a AC |
3500 | fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n", |
3501 | pid); | |
c906108c SS |
3502 | } |
3503 | ||
3504 | static int | |
fba45db2 | 3505 | debug_to_remove_fork_catchpoint (int pid) |
c906108c | 3506 | { |
c5aa993b | 3507 | int retval; |
c906108c SS |
3508 | |
3509 | retval = debug_target.to_remove_fork_catchpoint (pid); | |
3510 | ||
96baa820 | 3511 | fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n", |
c5aa993b | 3512 | pid, retval); |
c906108c SS |
3513 | |
3514 | return retval; | |
3515 | } | |
3516 | ||
fa113d1a | 3517 | static void |
fba45db2 | 3518 | debug_to_insert_vfork_catchpoint (int pid) |
c906108c | 3519 | { |
fa113d1a | 3520 | debug_target.to_insert_vfork_catchpoint (pid); |
c906108c | 3521 | |
fa113d1a AC |
3522 | fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n", |
3523 | pid); | |
c906108c SS |
3524 | } |
3525 | ||
3526 | static int | |
fba45db2 | 3527 | debug_to_remove_vfork_catchpoint (int pid) |
c906108c | 3528 | { |
c5aa993b | 3529 | int retval; |
c906108c SS |
3530 | |
3531 | retval = debug_target.to_remove_vfork_catchpoint (pid); | |
3532 | ||
96baa820 | 3533 | fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n", |
c5aa993b | 3534 | pid, retval); |
c906108c SS |
3535 | |
3536 | return retval; | |
3537 | } | |
3538 | ||
fa113d1a | 3539 | static void |
fba45db2 | 3540 | debug_to_insert_exec_catchpoint (int pid) |
c906108c | 3541 | { |
fa113d1a | 3542 | debug_target.to_insert_exec_catchpoint (pid); |
c906108c | 3543 | |
fa113d1a AC |
3544 | fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n", |
3545 | pid); | |
c906108c SS |
3546 | } |
3547 | ||
3548 | static int | |
fba45db2 | 3549 | debug_to_remove_exec_catchpoint (int pid) |
c906108c | 3550 | { |
c5aa993b | 3551 | int retval; |
c906108c SS |
3552 | |
3553 | retval = debug_target.to_remove_exec_catchpoint (pid); | |
3554 | ||
96baa820 | 3555 | fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n", |
c5aa993b | 3556 | pid, retval); |
c906108c SS |
3557 | |
3558 | return retval; | |
3559 | } | |
3560 | ||
c906108c | 3561 | static int |
fba45db2 | 3562 | debug_to_has_exited (int pid, int wait_status, int *exit_status) |
c906108c | 3563 | { |
c5aa993b | 3564 | int has_exited; |
c906108c SS |
3565 | |
3566 | has_exited = debug_target.to_has_exited (pid, wait_status, exit_status); | |
3567 | ||
96baa820 | 3568 | fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n", |
c5aa993b | 3569 | pid, wait_status, *exit_status, has_exited); |
c906108c SS |
3570 | |
3571 | return has_exited; | |
3572 | } | |
3573 | ||
c906108c | 3574 | static int |
fba45db2 | 3575 | debug_to_can_run (void) |
c906108c SS |
3576 | { |
3577 | int retval; | |
3578 | ||
3579 | retval = debug_target.to_can_run (); | |
3580 | ||
96baa820 | 3581 | fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval); |
c906108c SS |
3582 | |
3583 | return retval; | |
3584 | } | |
3585 | ||
3586 | static void | |
39f77062 | 3587 | debug_to_notice_signals (ptid_t ptid) |
c906108c | 3588 | { |
39f77062 | 3589 | debug_target.to_notice_signals (ptid); |
c906108c | 3590 | |
39f77062 KB |
3591 | fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", |
3592 | PIDGET (ptid)); | |
c906108c SS |
3593 | } |
3594 | ||
c2250ad1 UW |
3595 | static struct gdbarch * |
3596 | debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid) | |
3597 | { | |
3598 | struct gdbarch *retval; | |
3599 | ||
3600 | retval = debug_target.to_thread_architecture (ops, ptid); | |
3601 | ||
67e5d36c PM |
3602 | fprintf_unfiltered (gdb_stdlog, "target_thread_architecture (%s) = %s [%s]\n", |
3603 | target_pid_to_str (ptid), host_address_to_string (retval), | |
c2250ad1 UW |
3604 | gdbarch_bfd_arch_info (retval)->printable_name); |
3605 | return retval; | |
3606 | } | |
3607 | ||
c906108c | 3608 | static void |
94cc34af | 3609 | debug_to_stop (ptid_t ptid) |
c906108c | 3610 | { |
94cc34af | 3611 | debug_target.to_stop (ptid); |
c906108c | 3612 | |
94cc34af PA |
3613 | fprintf_unfiltered (gdb_stdlog, "target_stop (%s)\n", |
3614 | target_pid_to_str (ptid)); | |
c906108c SS |
3615 | } |
3616 | ||
96baa820 JM |
3617 | static void |
3618 | debug_to_rcmd (char *command, | |
d9fcf2fb | 3619 | struct ui_file *outbuf) |
96baa820 JM |
3620 | { |
3621 | debug_target.to_rcmd (command, outbuf); | |
3622 | fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command); | |
3623 | } | |
3624 | ||
c906108c | 3625 | static char * |
fba45db2 | 3626 | debug_to_pid_to_exec_file (int pid) |
c906108c | 3627 | { |
c5aa993b | 3628 | char *exec_file; |
c906108c SS |
3629 | |
3630 | exec_file = debug_target.to_pid_to_exec_file (pid); | |
3631 | ||
96baa820 | 3632 | fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n", |
c5aa993b | 3633 | pid, exec_file); |
c906108c SS |
3634 | |
3635 | return exec_file; | |
3636 | } | |
3637 | ||
c906108c | 3638 | static void |
fba45db2 | 3639 | setup_target_debug (void) |
c906108c SS |
3640 | { |
3641 | memcpy (&debug_target, ¤t_target, sizeof debug_target); | |
3642 | ||
3643 | current_target.to_open = debug_to_open; | |
c906108c | 3644 | current_target.to_post_attach = debug_to_post_attach; |
c906108c | 3645 | current_target.to_prepare_to_store = debug_to_prepare_to_store; |
c8e73a31 | 3646 | current_target.deprecated_xfer_memory = deprecated_debug_xfer_memory; |
c906108c SS |
3647 | current_target.to_files_info = debug_to_files_info; |
3648 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; | |
3649 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; | |
ccaa32c7 GS |
3650 | current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint; |
3651 | current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint; | |
3652 | current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint; | |
3653 | current_target.to_insert_watchpoint = debug_to_insert_watchpoint; | |
3654 | current_target.to_remove_watchpoint = debug_to_remove_watchpoint; | |
3655 | current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint; | |
3656 | current_target.to_stopped_data_address = debug_to_stopped_data_address; | |
5009afc5 | 3657 | current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range; |
e0d24f8d | 3658 | current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint; |
c906108c SS |
3659 | current_target.to_terminal_init = debug_to_terminal_init; |
3660 | current_target.to_terminal_inferior = debug_to_terminal_inferior; | |
3661 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; | |
3662 | current_target.to_terminal_ours = debug_to_terminal_ours; | |
a790ad35 | 3663 | current_target.to_terminal_save_ours = debug_to_terminal_save_ours; |
c906108c | 3664 | current_target.to_terminal_info = debug_to_terminal_info; |
c906108c SS |
3665 | current_target.to_load = debug_to_load; |
3666 | current_target.to_lookup_symbol = debug_to_lookup_symbol; | |
c906108c SS |
3667 | current_target.to_post_startup_inferior = debug_to_post_startup_inferior; |
3668 | current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior; | |
c906108c SS |
3669 | current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint; |
3670 | current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint; | |
3671 | current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint; | |
3672 | current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint; | |
c906108c SS |
3673 | current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint; |
3674 | current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint; | |
c906108c | 3675 | current_target.to_has_exited = debug_to_has_exited; |
c906108c SS |
3676 | current_target.to_can_run = debug_to_can_run; |
3677 | current_target.to_notice_signals = debug_to_notice_signals; | |
c906108c | 3678 | current_target.to_stop = debug_to_stop; |
96baa820 | 3679 | current_target.to_rcmd = debug_to_rcmd; |
c906108c | 3680 | current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file; |
c2250ad1 | 3681 | current_target.to_thread_architecture = debug_to_thread_architecture; |
c906108c | 3682 | } |
c906108c | 3683 | \f |
c5aa993b JM |
3684 | |
3685 | static char targ_desc[] = | |
3686 | "Names of targets and files being debugged.\n\ | |
c906108c SS |
3687 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
3688 | core-file, and process, if any), as well as the symbol file name."; | |
3689 | ||
96baa820 JM |
3690 | static void |
3691 | do_monitor_command (char *cmd, | |
3692 | int from_tty) | |
3693 | { | |
2b5fe715 AC |
3694 | if ((current_target.to_rcmd |
3695 | == (void (*) (char *, struct ui_file *)) tcomplain) | |
96baa820 | 3696 | || (current_target.to_rcmd == debug_to_rcmd |
2b5fe715 AC |
3697 | && (debug_target.to_rcmd |
3698 | == (void (*) (char *, struct ui_file *)) tcomplain))) | |
8a3fe4f8 | 3699 | error (_("\"monitor\" command not supported by this target.")); |
96baa820 JM |
3700 | target_rcmd (cmd, gdb_stdtarg); |
3701 | } | |
3702 | ||
87680a14 JB |
3703 | /* Print the name of each layers of our target stack. */ |
3704 | ||
3705 | static void | |
3706 | maintenance_print_target_stack (char *cmd, int from_tty) | |
3707 | { | |
3708 | struct target_ops *t; | |
3709 | ||
3710 | printf_filtered (_("The current target stack is:\n")); | |
3711 | ||
3712 | for (t = target_stack; t != NULL; t = t->beneath) | |
3713 | { | |
3714 | printf_filtered (" - %s (%s)\n", t->to_shortname, t->to_longname); | |
3715 | } | |
3716 | } | |
3717 | ||
c6ebd6cf VP |
3718 | /* Controls if async mode is permitted. */ |
3719 | int target_async_permitted = 0; | |
3720 | ||
3721 | /* The set command writes to this variable. If the inferior is | |
3722 | executing, linux_nat_async_permitted is *not* updated. */ | |
3723 | static int target_async_permitted_1 = 0; | |
3724 | ||
3725 | static void | |
3726 | set_maintenance_target_async_permitted (char *args, int from_tty, | |
3727 | struct cmd_list_element *c) | |
3728 | { | |
c35b1492 | 3729 | if (have_live_inferiors ()) |
c6ebd6cf VP |
3730 | { |
3731 | target_async_permitted_1 = target_async_permitted; | |
3732 | error (_("Cannot change this setting while the inferior is running.")); | |
3733 | } | |
3734 | ||
3735 | target_async_permitted = target_async_permitted_1; | |
3736 | } | |
3737 | ||
3738 | static void | |
3739 | show_maintenance_target_async_permitted (struct ui_file *file, int from_tty, | |
3740 | struct cmd_list_element *c, | |
3741 | const char *value) | |
3742 | { | |
3743 | fprintf_filtered (file, _("\ | |
3744 | Controlling the inferior in asynchronous mode is %s.\n"), value); | |
3745 | } | |
3746 | ||
d914c394 SS |
3747 | /* Temporary copies of permission settings. */ |
3748 | ||
3749 | static int may_write_registers_1 = 1; | |
3750 | static int may_write_memory_1 = 1; | |
3751 | static int may_insert_breakpoints_1 = 1; | |
3752 | static int may_insert_tracepoints_1 = 1; | |
3753 | static int may_insert_fast_tracepoints_1 = 1; | |
3754 | static int may_stop_1 = 1; | |
3755 | ||
3756 | /* Make the user-set values match the real values again. */ | |
3757 | ||
3758 | void | |
3759 | update_target_permissions (void) | |
3760 | { | |
3761 | may_write_registers_1 = may_write_registers; | |
3762 | may_write_memory_1 = may_write_memory; | |
3763 | may_insert_breakpoints_1 = may_insert_breakpoints; | |
3764 | may_insert_tracepoints_1 = may_insert_tracepoints; | |
3765 | may_insert_fast_tracepoints_1 = may_insert_fast_tracepoints; | |
3766 | may_stop_1 = may_stop; | |
3767 | } | |
3768 | ||
3769 | /* The one function handles (most of) the permission flags in the same | |
3770 | way. */ | |
3771 | ||
3772 | static void | |
3773 | set_target_permissions (char *args, int from_tty, | |
3774 | struct cmd_list_element *c) | |
3775 | { | |
3776 | if (target_has_execution) | |
3777 | { | |
3778 | update_target_permissions (); | |
3779 | error (_("Cannot change this setting while the inferior is running.")); | |
3780 | } | |
3781 | ||
3782 | /* Make the real values match the user-changed values. */ | |
3783 | may_write_registers = may_write_registers_1; | |
3784 | may_insert_breakpoints = may_insert_breakpoints_1; | |
3785 | may_insert_tracepoints = may_insert_tracepoints_1; | |
3786 | may_insert_fast_tracepoints = may_insert_fast_tracepoints_1; | |
3787 | may_stop = may_stop_1; | |
3788 | update_observer_mode (); | |
3789 | } | |
3790 | ||
3791 | /* Set memory write permission independently of observer mode. */ | |
3792 | ||
3793 | static void | |
3794 | set_write_memory_permission (char *args, int from_tty, | |
3795 | struct cmd_list_element *c) | |
3796 | { | |
3797 | /* Make the real values match the user-changed values. */ | |
3798 | may_write_memory = may_write_memory_1; | |
3799 | update_observer_mode (); | |
3800 | } | |
3801 | ||
3802 | ||
c906108c | 3803 | void |
fba45db2 | 3804 | initialize_targets (void) |
c906108c SS |
3805 | { |
3806 | init_dummy_target (); | |
3807 | push_target (&dummy_target); | |
3808 | ||
3809 | add_info ("target", target_info, targ_desc); | |
3810 | add_info ("files", target_info, targ_desc); | |
3811 | ||
85c07804 AC |
3812 | add_setshow_zinteger_cmd ("target", class_maintenance, &targetdebug, _("\ |
3813 | Set target debugging."), _("\ | |
3814 | Show target debugging."), _("\ | |
333dabeb DJ |
3815 | When non-zero, target debugging is enabled. Higher numbers are more\n\ |
3816 | verbose. Changes do not take effect until the next \"run\" or \"target\"\n\ | |
85c07804 AC |
3817 | command."), |
3818 | NULL, | |
920d2a44 | 3819 | show_targetdebug, |
85c07804 | 3820 | &setdebuglist, &showdebuglist); |
3a11626d | 3821 | |
2bc416ba | 3822 | add_setshow_boolean_cmd ("trust-readonly-sections", class_support, |
7915a72c AC |
3823 | &trust_readonly, _("\ |
3824 | Set mode for reading from readonly sections."), _("\ | |
3825 | Show mode for reading from readonly sections."), _("\ | |
3a11626d MS |
3826 | When this mode is on, memory reads from readonly sections (such as .text)\n\ |
3827 | will be read from the object file instead of from the target. This will\n\ | |
7915a72c | 3828 | result in significant performance improvement for remote targets."), |
2c5b56ce | 3829 | NULL, |
920d2a44 | 3830 | show_trust_readonly, |
e707bbc2 | 3831 | &setlist, &showlist); |
96baa820 JM |
3832 | |
3833 | add_com ("monitor", class_obscure, do_monitor_command, | |
1bedd215 | 3834 | _("Send a command to the remote monitor (remote targets only).")); |
96baa820 | 3835 | |
87680a14 JB |
3836 | add_cmd ("target-stack", class_maintenance, maintenance_print_target_stack, |
3837 | _("Print the name of each layer of the internal target stack."), | |
3838 | &maintenanceprintlist); | |
3839 | ||
c6ebd6cf VP |
3840 | add_setshow_boolean_cmd ("target-async", no_class, |
3841 | &target_async_permitted_1, _("\ | |
3842 | Set whether gdb controls the inferior in asynchronous mode."), _("\ | |
3843 | Show whether gdb controls the inferior in asynchronous mode."), _("\ | |
3844 | Tells gdb whether to control the inferior in asynchronous mode."), | |
3845 | set_maintenance_target_async_permitted, | |
3846 | show_maintenance_target_async_permitted, | |
3847 | &setlist, | |
3848 | &showlist); | |
3849 | ||
4e5d721f | 3850 | add_setshow_boolean_cmd ("stack-cache", class_support, |
9cf1b572 | 3851 | &stack_cache_enabled_p_1, _("\ |
4e5d721f DE |
3852 | Set cache use for stack access."), _("\ |
3853 | Show cache use for stack access."), _("\ | |
3854 | When on, use the data cache for all stack access, regardless of any\n\ | |
3855 | configured memory regions. This improves remote performance significantly.\n\ | |
3856 | By default, caching for stack access is on."), | |
3857 | set_stack_cache_enabled_p, | |
3858 | show_stack_cache_enabled_p, | |
3859 | &setlist, &showlist); | |
3860 | ||
d914c394 SS |
3861 | add_setshow_boolean_cmd ("may-write-registers", class_support, |
3862 | &may_write_registers_1, _("\ | |
3863 | Set permission to write into registers."), _("\ | |
3864 | Show permission to write into registers."), _("\ | |
3865 | When this permission is on, GDB may write into the target's registers.\n\ | |
3866 | Otherwise, any sort of write attempt will result in an error."), | |
3867 | set_target_permissions, NULL, | |
3868 | &setlist, &showlist); | |
3869 | ||
3870 | add_setshow_boolean_cmd ("may-write-memory", class_support, | |
3871 | &may_write_memory_1, _("\ | |
3872 | Set permission to write into target memory."), _("\ | |
3873 | Show permission to write into target memory."), _("\ | |
3874 | When this permission is on, GDB may write into the target's memory.\n\ | |
3875 | Otherwise, any sort of write attempt will result in an error."), | |
3876 | set_write_memory_permission, NULL, | |
3877 | &setlist, &showlist); | |
3878 | ||
3879 | add_setshow_boolean_cmd ("may-insert-breakpoints", class_support, | |
3880 | &may_insert_breakpoints_1, _("\ | |
3881 | Set permission to insert breakpoints in the target."), _("\ | |
3882 | Show permission to insert breakpoints in the target."), _("\ | |
3883 | When this permission is on, GDB may insert breakpoints in the program.\n\ | |
3884 | Otherwise, any sort of insertion attempt will result in an error."), | |
3885 | set_target_permissions, NULL, | |
3886 | &setlist, &showlist); | |
3887 | ||
3888 | add_setshow_boolean_cmd ("may-insert-tracepoints", class_support, | |
3889 | &may_insert_tracepoints_1, _("\ | |
3890 | Set permission to insert tracepoints in the target."), _("\ | |
3891 | Show permission to insert tracepoints in the target."), _("\ | |
3892 | When this permission is on, GDB may insert tracepoints in the program.\n\ | |
3893 | Otherwise, any sort of insertion attempt will result in an error."), | |
3894 | set_target_permissions, NULL, | |
3895 | &setlist, &showlist); | |
3896 | ||
3897 | add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support, | |
3898 | &may_insert_fast_tracepoints_1, _("\ | |
3899 | Set permission to insert fast tracepoints in the target."), _("\ | |
3900 | Show permission to insert fast tracepoints in the target."), _("\ | |
3901 | When this permission is on, GDB may insert fast tracepoints.\n\ | |
3902 | Otherwise, any sort of insertion attempt will result in an error."), | |
3903 | set_target_permissions, NULL, | |
3904 | &setlist, &showlist); | |
3905 | ||
3906 | add_setshow_boolean_cmd ("may-interrupt", class_support, | |
3907 | &may_stop_1, _("\ | |
3908 | Set permission to interrupt or signal the target."), _("\ | |
3909 | Show permission to interrupt or signal the target."), _("\ | |
3910 | When this permission is on, GDB may interrupt/stop the target's execution.\n\ | |
3911 | Otherwise, any attempt to interrupt or stop will be ignored."), | |
3912 | set_target_permissions, NULL, | |
3913 | &setlist, &showlist); | |
3914 | ||
3915 | ||
8add0441 | 3916 | target_dcache = dcache_init (); |
c906108c | 3917 | } |