Wed Dec 16 16:17:22 1998 Dave Brolley <brolley@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / gdbarch.c
1 /* Semi-dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "defs.h"
21 #include "bfd.h"
22 #include "gdbcmd.h"
23
24
25 /* start-sanitize-carp start-sanitize-vr4xxx */
26 /* Convenience macro for allocting memory. */
27
28 #ifndef XMALLOC
29 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
30 #endif
31
32 /* end-sanitize-carp end-sanitize-vr4xxx */
33
34 /* Non-zero if we want to trace architecture code. */
35
36 #ifndef GDBARCH_DEBUG
37 #define GDBARCH_DEBUG 0
38 #endif
39 int gdbarch_debug = GDBARCH_DEBUG;
40
41 /* start-sanitize-carp start-sanitize-vr4xxx */
42
43 /* Maintain the struct gdbarch object */
44
45 struct gdbarch
46 {
47 /* basic architectural information */
48 const struct bfd_arch_info *bfd_arch_info;
49 int byte_order;
50
51 /* target specific vector. */
52 struct gdbarch_tdep *tdep;
53
54 /* per-architecture data-pointers */
55 int nr_data;
56 void **data;
57
58 /* per-architecture swap-regions */
59 struct gdbarch_swap *swap;
60
61 /* Multi-arch values.
62
63 When adding to the below you must also: declare/define set/get
64 value functions; override the corresponding macro in gdbarch.h;
65 initialize the value in gdbarch_alloc() (if zero is an unsuitable
66 default); confirm that the target updated the value correctly in
67 verify_gdbarch(); add a fprintf_unfiltered call to
68 gdbarch_update() so that the new field is dumped out; append an
69 initial value to the static variable DEFAULT_GDBARCH (base values
70 on the host's c-type system). */
71
72 int long_bit;
73 int long_long_bit;
74 int ptr_bit;
75
76 };
77
78
79 struct gdbarch_tdep *
80 gdbarch_tdep (gdbarch)
81 struct gdbarch *gdbarch;
82 {
83 return gdbarch->tdep;
84 }
85
86 const struct bfd_arch_info *
87 gdbarch_bfd_arch_info (gdbarch)
88 struct gdbarch *gdbarch;
89 {
90 return gdbarch->bfd_arch_info;
91 }
92
93 int
94 gdbarch_byte_order (gdbarch)
95 struct gdbarch *gdbarch;
96 {
97 return gdbarch->byte_order;
98 }
99
100 int
101 gdbarch_long_bit (gdbarch)
102 struct gdbarch *gdbarch;
103 {
104 return gdbarch->long_bit;
105 }
106
107 void
108 set_gdbarch_long_bit (gdbarch, long_bit)
109 struct gdbarch *gdbarch;
110 int long_bit;
111 {
112 gdbarch->long_bit = long_bit;
113 }
114
115 int
116 gdbarch_long_long_bit (gdbarch)
117 struct gdbarch *gdbarch;
118 {
119 return gdbarch->long_long_bit;
120 }
121
122 void
123 set_gdbarch_long_long_bit (gdbarch, long_long_bit)
124 struct gdbarch *gdbarch;
125 int long_long_bit;
126 {
127 gdbarch->long_long_bit = long_long_bit;
128 }
129
130 int
131 gdbarch_ptr_bit (gdbarch)
132 struct gdbarch *gdbarch;
133 {
134 return gdbarch->ptr_bit;
135 }
136
137 void
138 set_gdbarch_ptr_bit (gdbarch, ptr_bit)
139 struct gdbarch *gdbarch;
140 int ptr_bit;
141 {
142 gdbarch->ptr_bit = ptr_bit;
143 }
144
145
146 /* Ensure that all values in a GDBARCH are reasonable. XXX - should
147 this instead return a success/fail indication? */
148
149 static void
150 verify_gdbarch (gdbarch)
151 struct gdbarch *gdbarch;
152 {
153 /* fundamental */
154 if (gdbarch->byte_order == 0)
155 fatal ("verify_gdbarch: byte-order unset");
156 if (gdbarch->bfd_arch_info == NULL)
157 fatal ("verify_gdbarch: bfd_arch_info unset");
158 /* more general */
159 if (gdbarch->long_bit == 0)
160 fatal ("verify_gdbarch: long_bit invalid");
161 if (gdbarch->long_long_bit == 0)
162 fatal ("verify_gdbarch: long_long_bit invalid");
163 if (gdbarch->ptr_bit == 0)
164 fatal ("verify_gdbarch: ptr_bit invalid");
165 }
166
167
168 /* Keep a registrary of per-architecture data-pointers required by GDB
169 modules. */
170
171 struct gdbarch_data
172 {
173 int index;
174 };
175
176 struct gdbarch_data_registration
177 {
178 gdbarch_data_ftype *init;
179 struct gdbarch_data *data;
180 struct gdbarch_data_registration *next;
181 };
182
183 struct gdbarch_data_registrary
184 {
185 int nr;
186 struct gdbarch_data_registration *registrations;
187 };
188
189 struct gdbarch_data_registrary gdbarch_data_registrary =
190 {
191 0, NULL,
192 };
193
194 struct gdbarch_data *
195 register_gdbarch_data (init)
196 gdbarch_data_ftype *init;
197 {
198 struct gdbarch_data_registration **curr;
199 for (curr = &gdbarch_data_registrary.registrations;
200 (*curr) != NULL;
201 curr = &(*curr)->next);
202 (*curr) = XMALLOC (struct gdbarch_data_registration);
203 (*curr)->next = NULL;
204 (*curr)->init = init;
205 (*curr)->data = XMALLOC (struct gdbarch_data);
206 (*curr)->data->index = gdbarch_data_registrary.nr++;
207 return (*curr)->data;
208 }
209
210
211 /* Walk through all the registered users initializing each in turn. */
212
213 static void init_gdbarch_data PARAMS ((struct gdbarch *));
214 static void
215 init_gdbarch_data (gdbarch)
216 struct gdbarch *gdbarch;
217 {
218 struct gdbarch_data_registration *rego;
219 gdbarch->nr_data = gdbarch_data_registrary.nr + 1;
220 gdbarch->data = xmalloc (sizeof (void*) * gdbarch->nr_data);
221 for (rego = gdbarch_data_registrary.registrations;
222 rego != NULL;
223 rego = rego->next)
224 {
225 if (rego->data->index < gdbarch->nr_data)
226 gdbarch->data[rego->data->index] = rego->init ();
227 }
228 }
229
230
231 /* Return the current value of the specified per-architecture
232 data-pointer. */
233
234 void *
235 gdbarch_data (data)
236 struct gdbarch_data *data;
237 {
238 if (data->index >= current_gdbarch->nr_data)
239 fatal ("gdbarch_data: request for non-existant data.");
240 return current_gdbarch->data[data->index];
241 }
242
243
244
245 /* Keep a registrary of swaped data required by GDB modules. */
246
247 struct gdbarch_swap
248 {
249 void *swap;
250 struct gdbarch_swap_registration *source;
251 struct gdbarch_swap *next;
252 };
253
254 struct gdbarch_swap_registration
255 {
256 void *data;
257 unsigned long sizeof_data;
258 gdbarch_swap_ftype *init;
259 struct gdbarch_swap_registration *next;
260 };
261
262 struct gdbarch_swap_registrary
263 {
264 int nr;
265 struct gdbarch_swap_registration *registrations;
266 };
267
268 struct gdbarch_swap_registrary gdbarch_swap_registrary =
269 {
270 0, NULL,
271 };
272
273 void
274 register_gdbarch_swap (data, sizeof_data, init)
275 void *data;
276 unsigned long sizeof_data;
277 gdbarch_swap_ftype *init;
278 {
279 struct gdbarch_swap_registration **rego;
280 for (rego = &gdbarch_swap_registrary.registrations;
281 (*rego) != NULL;
282 rego = &(*rego)->next);
283 (*rego) = XMALLOC (struct gdbarch_swap_registration);
284 (*rego)->next = NULL;
285 (*rego)->init = init;
286 (*rego)->data = data;
287 (*rego)->sizeof_data = sizeof_data;
288 }
289
290
291 static void init_gdbarch_swap PARAMS ((struct gdbarch *));
292 static void
293 init_gdbarch_swap (gdbarch)
294 struct gdbarch *gdbarch;
295 {
296 struct gdbarch_swap_registration *rego;
297 struct gdbarch_swap **curr = &gdbarch->swap;
298 for (rego = gdbarch_swap_registrary.registrations;
299 rego != NULL;
300 rego = rego->next)
301 {
302 if (rego->data != NULL)
303 {
304 (*curr) = XMALLOC (struct gdbarch_swap);
305 (*curr)->source = rego;
306 (*curr)->swap = xmalloc (rego->sizeof_data);
307 (*curr)->next = NULL;
308 memset (rego->data, 0, rego->sizeof_data);
309 curr = &(*curr)->next;
310 }
311 if (rego->init != NULL)
312 rego->init ();
313 }
314 }
315
316 static void swapout_gdbarch_swap PARAMS ((struct gdbarch *));
317 static void
318 swapout_gdbarch_swap (gdbarch)
319 struct gdbarch *gdbarch;
320 {
321 struct gdbarch_swap *curr;
322 for (curr = gdbarch->swap;
323 curr != NULL;
324 curr = curr->next)
325 memcpy (curr->swap, curr->source->data, curr->source->sizeof_data);
326 }
327
328 static void swapin_gdbarch_swap PARAMS ((struct gdbarch *));
329 static void
330 swapin_gdbarch_swap (gdbarch)
331 struct gdbarch *gdbarch;
332 {
333 struct gdbarch_swap *curr;
334 for (curr = gdbarch->swap;
335 curr != NULL;
336 curr = curr->next)
337 memcpy (curr->source->data, curr->swap, curr->source->sizeof_data);
338 }
339
340
341 /* Keep a registrary of the architectures known by GDB. */
342
343 struct gdbarch_init_registration
344 {
345 enum bfd_architecture bfd_architecture;
346 gdbarch_init_ftype *init;
347 struct gdbarch_list *arches;
348 struct gdbarch_init_registration *next;
349 };
350
351 static struct gdbarch_init_registration *gdbarch_init_registrary = NULL;
352
353 void
354 register_gdbarch_init (bfd_architecture, init)
355 enum bfd_architecture bfd_architecture;
356 gdbarch_init_ftype *init;
357 {
358 struct gdbarch_init_registration **curr;
359 const struct bfd_arch_info *bfd_arch_info;
360 /* Check that BFD reconizes this architecture */
361 bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
362 if (bfd_arch_info == NULL)
363 {
364 fatal ("Attempt to register unknown architecture (%d)", bfd_architecture);
365 }
366 /* Check that we haven't seen this architecture before */
367 for (curr = &gdbarch_init_registrary;
368 (*curr) != NULL;
369 curr = &(*curr)->next)
370 {
371 if (bfd_architecture == (*curr)->bfd_architecture)
372 fatal ("Duplicate registraration of architecture (%s)",
373 bfd_arch_info->printable_name);
374 }
375 /* log it */
376 if (gdbarch_debug)
377 fprintf_unfiltered (stderr, "register_gdbarch_init (%s, 0x%08lx)\n",
378 bfd_arch_info->printable_name,
379 (long) init);
380 /* Append it */
381 (*curr) = XMALLOC (struct gdbarch_init_registration);
382 (*curr)->bfd_architecture = bfd_architecture;
383 (*curr)->init = init;
384 (*curr)->arches = NULL;
385 (*curr)->next = NULL;
386 }
387
388
389
390 /* Look for an architecture using gdbarch_info. Base search on only
391 BFD_ARCH_INFO and BYTE_ORDER. */
392
393 struct gdbarch_list *
394 gdbarch_list_lookup_by_info (arches, info)
395 struct gdbarch_list *arches;
396 const struct gdbarch_info *info;
397 {
398 for (; arches != NULL; arches = arches->next)
399 {
400 if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
401 continue;
402 if (info->byte_order != arches->gdbarch->byte_order)
403 continue;
404 return arches;
405 }
406 return NULL;
407 }
408
409
410 /* Create a new ``struct gdbarch'' based in information provied by
411 ``struct gdbarch_info'' */
412
413 struct gdbarch *
414 gdbarch_alloc (info, tdep)
415 const struct gdbarch_info *info;
416 struct gdbarch_tdep *tdep;
417 {
418 struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
419 memset (gdbarch, 0, sizeof (*gdbarch));
420
421 gdbarch->tdep = tdep;
422
423 gdbarch->bfd_arch_info = info->bfd_arch_info;
424 gdbarch->byte_order = info->byte_order;
425
426 return gdbarch;
427 }
428
429 /* Update the current architecture. Return ZERO if the update request
430 failed. */
431
432 int
433 gdbarch_update (info)
434 struct gdbarch_info info;
435 {
436 struct gdbarch *new_gdbarch;
437 struct gdbarch_list **list;
438 struct gdbarch_init_registration *rego;
439
440 /* Fill in any missing bits. Most important is the bfd_architecture
441 which is used to select the target architecture. */
442 if (info.bfd_architecture == bfd_arch_unknown)
443 {
444 if (info.bfd_arch_info != NULL)
445 info.bfd_architecture = info.bfd_arch_info->arch;
446 else if (info.abfd != NULL)
447 info.bfd_architecture = bfd_get_arch (info.abfd);
448 /* FIXME - should query BFD for its default architecture. */
449 else
450 info.bfd_architecture = current_gdbarch->bfd_arch_info->arch;
451 }
452 if (info.bfd_arch_info == NULL)
453 {
454 if (target_architecture_auto && info.abfd != NULL)
455 info.bfd_arch_info = bfd_get_arch_info (info.abfd);
456 else
457 info.bfd_arch_info = current_gdbarch->bfd_arch_info;
458 }
459 if (info.byte_order == 0)
460 {
461 if (target_byte_order_auto && info.abfd != NULL)
462 info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
463 : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
464 : 0);
465 else
466 info.byte_order = current_gdbarch->byte_order;
467 }
468 /* A default for abfd? */
469
470 /* Find the target that knows about this architecture. */
471 for (rego = gdbarch_init_registrary;
472 rego != NULL && rego->bfd_architecture != info.bfd_architecture;
473 rego = rego->next);
474 if (rego == NULL)
475 {
476 if (gdbarch_debug)
477 fprintf_unfiltered (stderr, "gdbarch_update: No matching architecture\n");
478 return 0;
479 }
480
481 /* Ask the target for a replacement architecture. */
482 new_gdbarch = rego->init (&info, rego->arches);
483
484 /* Did the target like it? No. Reject the change. */
485 if (new_gdbarch == NULL)
486 {
487 if (gdbarch_debug)
488 fprintf_unfiltered (stderr, "gdbarch_update: Target rejected architecture\n");
489 return 0;
490 }
491
492 /* Did the architecture change? No. Do nothing. */
493 if (current_gdbarch == new_gdbarch)
494 {
495 if (gdbarch_debug)
496 fprintf_unfiltered (stderr, "gdbarch_update: Architecture 0x%08lx (%s) unchanged\n",
497 (long) new_gdbarch,
498 new_gdbarch->bfd_arch_info->printable_name);
499 return 1;
500 }
501
502 /* Swap all data belonging to the old target out */
503 swapout_gdbarch_swap (current_gdbarch);
504
505 /* Is this a pre-existing architecture? Yes. Swap it in. */
506 for (list = &rego->arches;
507 (*list) != NULL;
508 list = &(*list)->next)
509 {
510 if ((*list)->gdbarch == new_gdbarch)
511 {
512 if (gdbarch_debug)
513 fprintf_unfiltered (stderr, "gdbarch_update: Previous architecture 0x%08lx (%s) selected\n",
514 (long) new_gdbarch,
515 new_gdbarch->bfd_arch_info->printable_name);
516 current_gdbarch = new_gdbarch;
517 swapin_gdbarch_swap (new_gdbarch);
518 return 1;
519 }
520 }
521
522 /* Append this new architecture to this targets list. */
523 (*list) = XMALLOC (struct gdbarch_list);
524 (*list)->next = NULL;
525 (*list)->gdbarch = new_gdbarch;
526
527 /* Switch to this new architecture. Dump it out. */
528 current_gdbarch = new_gdbarch;
529 if (gdbarch_debug)
530 {
531 fprintf_unfiltered (stderr, "gdbarch_update: New architecture 0x%08lx (%s) selected\n",
532 (long) new_gdbarch,
533 new_gdbarch->bfd_arch_info->printable_name);
534 fprintf_unfiltered (stderr, "TARGET_BYTE_ORDER = %d\n", TARGET_BYTE_ORDER);
535 fprintf_unfiltered (stderr, "TARGET_LONG_BIT = %d\n", TARGET_LONG_BIT);
536 fprintf_unfiltered (stderr, "TARGET_LONG_LONG_BIT = %d\n", TARGET_LONG_LONG_BIT);
537 fprintf_unfiltered (stderr, "TARGET_PTR_BIT = %d\n", TARGET_PTR_BIT);
538 }
539
540 /* Check that the newly installed architecture is valid. */
541 verify_gdbarch (new_gdbarch);
542
543 /* Initialize the per-architecture memory (swap) areas.
544 CURRENT_GDBARCH must be update before these modules are
545 called. */
546 init_gdbarch_swap (new_gdbarch);
547
548 /* Initialize the per-architecture data-pointer of all parties that
549 registered an interest in this architecture. CURRENT_GDBARCH
550 must be updated before these modules are called. */
551 init_gdbarch_data (new_gdbarch);
552
553 return 1;
554 }
555
556
557 /* end-sanitize-carp end-sanitize-vr4xxx */
558
559 /* Functions to manipulate the endianness of the target. */
560
561 #ifdef TARGET_BYTE_ORDER_SELECTABLE
562 /* compat - Catch old targets that expect a selectable byte-order to
563 default to BIG_ENDIAN */
564 #ifndef TARGET_BYTE_ORDER_DEFAULT
565 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
566 #endif
567 #endif
568 #ifndef TARGET_BYTE_ORDER_DEFAULT
569 /* compat - Catch old non byte-order selectable targets that do not
570 define TARGET_BYTE_ORDER_DEFAULT and instead expect
571 TARGET_BYTE_ORDER to be used as the default. For targets that
572 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
573 below will get a strange compiler warning. */
574 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
575 #endif
576 int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
577 int target_byte_order_auto = 1;
578
579 /* Chain containing the \"set endian\" commands. */
580 static struct cmd_list_element *endianlist = NULL;
581
582 /* Called by ``show endian''. */
583 static void show_endian PARAMS ((char *, int));
584 static void
585 show_endian (args, from_tty)
586 char *args;
587 int from_tty;
588 {
589 char *msg =
590 (TARGET_BYTE_ORDER_AUTO
591 ? "The target endianness is set automatically (currently %s endian)\n"
592 : "The target is assumed to be %s endian\n");
593 printf_unfiltered (msg, (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
594 }
595
596 /* Called if the user enters ``set endian'' without an argument. */
597 static void set_endian PARAMS ((char *, int));
598 static void
599 set_endian (args, from_tty)
600 char *args;
601 int from_tty;
602 {
603 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
604 show_endian (args, from_tty);
605 }
606
607 /* Called by ``set endian big''. */
608 static void set_endian_big PARAMS ((char *, int));
609 static void
610 set_endian_big (args, from_tty)
611 char *args;
612 int from_tty;
613 {
614 if (TARGET_BYTE_ORDER_SELECTABLE_P)
615 {
616 target_byte_order = BIG_ENDIAN;
617 target_byte_order_auto = 0;
618 /* start-sanitize-carp start-sanitize-vr4xxx */
619 if (GDB_MULTI_ARCH)
620 {
621 struct gdbarch_info info;
622 memset (&info, 0, sizeof info);
623 info.byte_order = BIG_ENDIAN;
624 gdbarch_update (info);
625 }
626 /* end-sanitize-carp end-sanitize-vr4xxx */
627 }
628 else
629 {
630 printf_unfiltered ("Byte order is not selectable.");
631 show_endian (args, from_tty);
632 }
633 }
634
635 /* Called by ``set endian little''. */
636 static void set_endian_little PARAMS ((char *, int));
637 static void
638 set_endian_little (args, from_tty)
639 char *args;
640 int from_tty;
641 {
642 if (TARGET_BYTE_ORDER_SELECTABLE_P)
643 {
644 target_byte_order = LITTLE_ENDIAN;
645 target_byte_order_auto = 0;
646 /* start-sanitize-carp start-sanitize-vr4xxx */
647 if (GDB_MULTI_ARCH)
648 {
649 struct gdbarch_info info;
650 memset (&info, 0, sizeof info);
651 info.byte_order = LITTLE_ENDIAN;
652 gdbarch_update (info);
653 }
654 /* end-sanitize-carp end-sanitize-vr4xxx */
655 }
656 else
657 {
658 printf_unfiltered ("Byte order is not selectable.");
659 show_endian (args, from_tty);
660 }
661 }
662
663 /* Called by ``set endian auto''. */
664 static void set_endian_auto PARAMS ((char *, int));
665 static void
666 set_endian_auto (args, from_tty)
667 char *args;
668 int from_tty;
669 {
670 if (TARGET_BYTE_ORDER_SELECTABLE_P)
671 {
672 target_byte_order_auto = 1;
673 }
674 else
675 {
676 printf_unfiltered ("Byte order is not selectable.");
677 show_endian (args, from_tty);
678 }
679 }
680
681 /* Set the endianness from a BFD. */
682 static void set_endian_from_file PARAMS ((bfd *));
683 static void
684 set_endian_from_file (abfd)
685 bfd *abfd;
686 {
687 if (TARGET_BYTE_ORDER_SELECTABLE_P)
688 {
689 int want;
690
691 if (bfd_big_endian (abfd))
692 want = BIG_ENDIAN;
693 else
694 want = LITTLE_ENDIAN;
695 if (TARGET_BYTE_ORDER_AUTO)
696 target_byte_order = want;
697 else if (TARGET_BYTE_ORDER != want)
698 warning ("%s endian file does not match %s endian target.",
699 want == BIG_ENDIAN ? "big" : "little",
700 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
701 }
702 else
703 {
704 if (bfd_big_endian (abfd)
705 ? TARGET_BYTE_ORDER != BIG_ENDIAN
706 : TARGET_BYTE_ORDER == BIG_ENDIAN)
707 warning ("%s endian file does not match %s endian target.",
708 bfd_big_endian (abfd) ? "big" : "little",
709 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
710 }
711 }
712
713
714
715 /* Functions to manipulate the architecture of the target */
716
717 int target_architecture_auto = 1;
718 extern const struct bfd_arch_info bfd_default_arch_struct;
719 const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
720 int (*target_architecture_hook) PARAMS ((const struct bfd_arch_info *ap));
721
722 /* Do the real work of changing the current architecture */
723 static void
724 set_arch (arch)
725 const struct bfd_arch_info *arch;
726 {
727 /* FIXME: Is it compatible with gdb? */
728 /* Check with the target on the setting */
729 if (target_architecture_hook != NULL
730 && !target_architecture_hook (arch))
731 printf_unfiltered ("Target does not support `%s' architecture.\n",
732 arch->printable_name);
733 else
734 {
735 target_architecture_auto = 0;
736 target_architecture = arch;
737 }
738 }
739
740 /* Called if the user enters ``show architecture'' without an argument. */
741 static void show_architecture PARAMS ((char *, int));
742 static void
743 show_architecture (args, from_tty)
744 char *args;
745 int from_tty;
746 {
747 const char *arch;
748 arch = TARGET_ARCHITECTURE->printable_name;
749 if (target_architecture_auto)
750 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
751 else
752 printf_filtered ("The target architecture is assumed to be %s\n", arch);
753 }
754
755 /* Called if the user enters ``set architecture'' with or without an
756 argument. */
757 static void set_architecture PARAMS ((char *, int));
758 static void
759 set_architecture (args, from_tty)
760 char *args;
761 int from_tty;
762 {
763 if (args == NULL)
764 {
765 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
766 }
767 else if (strcmp (args, "auto") == 0)
768 {
769 target_architecture_auto = 1;
770 }
771 /* start-sanitize-carp start-sanitize-vr4xxx */
772 else if (GDB_MULTI_ARCH)
773 {
774 const struct bfd_arch_info *arch = bfd_scan_arch (args);
775 if (arch == NULL)
776 printf_unfiltered ("Architecture `%s' not reconized.\n", args);
777 else
778 {
779 struct gdbarch_info info;
780 memset (&info, 0, sizeof info);
781 info.bfd_arch_info = arch;
782 if (gdbarch_update (info))
783 target_architecture_auto = 0;
784 else
785 printf_unfiltered ("Architecture `%s' not reconized.\n", args);
786 }
787 }
788 /* end-sanitize-carp end-sanitize-vr4xxx */
789 else
790 {
791 const struct bfd_arch_info *arch = bfd_scan_arch (args);
792 if (arch != NULL)
793 set_arch (arch);
794 else
795 printf_unfiltered ("Architecture `%s' not reconized.\n", args);
796 }
797 }
798
799 /* Called if the user enters ``info architecture'' without an argument. */
800 static void info_architecture PARAMS ((char *, int));
801 static void
802 info_architecture (args, from_tty)
803 char *args;
804 int from_tty;
805 {
806 enum bfd_architecture a;
807 /* start-sanitize-carp start-sanitize-vr4xxx */
808 if (GDB_MULTI_ARCH)
809 {
810 if (gdbarch_init_registrary != NULL)
811 {
812 struct gdbarch_init_registration *rego;
813 printf_filtered ("Available architectures are:\n");
814 for (rego = gdbarch_init_registrary;
815 rego != NULL;
816 rego = rego->next)
817 {
818 const struct bfd_arch_info *ap;
819 ap = bfd_lookup_arch (rego->bfd_architecture, 0);
820 if (ap != NULL)
821 {
822 do
823 {
824 printf_filtered (" %s", ap->printable_name);
825 ap = ap->next;
826 }
827 while (ap != NULL);
828 printf_filtered ("\n");
829 }
830 }
831 }
832 else
833 {
834 printf_filtered ("There are no available architectures.\n");
835 }
836 return;
837 }
838 /* end-sanitize-carp end-sanitize-vr4xxx */
839 printf_filtered ("Available architectures are:\n");
840 for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
841 {
842 const struct bfd_arch_info *ap = bfd_lookup_arch (a, 0);
843 if (ap != NULL)
844 {
845 do
846 {
847 printf_filtered (" %s", ap->printable_name);
848 ap = ap->next;
849 }
850 while (ap != NULL);
851 printf_filtered ("\n");
852 }
853 }
854 }
855
856 /* Set the architecture from arch/machine */
857 void
858 set_architecture_from_arch_mach (arch, mach)
859 enum bfd_architecture arch;
860 unsigned long mach;
861 {
862 const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
863 if (wanted != NULL)
864 set_arch (wanted);
865 else
866 fatal ("hardwired architecture/machine not reconized");
867 }
868
869 /* Set the architecture from a BFD */
870 static void set_architecture_from_file PARAMS ((bfd *));
871 static void
872 set_architecture_from_file (abfd)
873 bfd *abfd;
874 {
875 const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
876 if (target_architecture_auto)
877 {
878 if (target_architecture_hook != NULL
879 && !target_architecture_hook (wanted))
880 warning ("Target may not support %s architecture",
881 wanted->printable_name);
882 target_architecture = wanted;
883 }
884 else if (wanted != target_architecture)
885 {
886 warning ("%s architecture file may be incompatible with %s target.",
887 wanted->printable_name,
888 target_architecture->printable_name);
889 }
890 }
891
892
893
894 /* Disassembler */
895
896 /* Pointer to the target-dependent disassembly function. */
897 int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
898 disassemble_info tm_print_insn_info;
899
900
901
902 /* Set the dynamic target-system-dependant parameters (architecture,
903 byte-order) using information found in the BFD */
904
905 void
906 set_gdbarch_from_file (abfd)
907 bfd *abfd;
908 {
909 /* start-sanitize-carp start-sanitize-vr4xxx */
910 if (GDB_MULTI_ARCH)
911 {
912 struct gdbarch_info info;
913 memset (&info, 0, sizeof info);
914 info.abfd = abfd;
915 gdbarch_update (info);
916 return;
917 }
918 /* end-sanitize-carp end-sanitize-vr4xxx */
919 set_architecture_from_file (abfd);
920 set_endian_from_file (abfd);
921 }
922
923 /* start-sanitize-carp start-sanitize-vr4xxx */
924
925 /* The default architecture uses host values (for want of a better
926 choice). */
927
928 struct gdbarch default_gdbarch = {
929 /* basic architecture information */
930 &bfd_default_arch_struct,
931 TARGET_BYTE_ORDER_DEFAULT,
932 /* target specific vector */
933 NULL,
934 /*per-architecture data-pointers and swap regions */
935 0, NULL, NULL,
936 /* Multi-arch values */
937 8 * sizeof (long), /* long */
938 8 * sizeof (LONGEST), /* long long */
939 8 * sizeof (void*), /* ptr */
940 };
941 struct gdbarch *current_gdbarch = &default_gdbarch;
942
943 /* end-sanitize-carp end-sanitize-vr4xxx */
944
945 extern void _initialize_gdbarch PARAMS ((void));
946 void
947 _initialize_gdbarch ()
948 {
949 add_prefix_cmd ("endian", class_support, set_endian,
950 "Set endianness of target.",
951 &endianlist, "set endian ", 0, &setlist);
952 add_cmd ("big", class_support, set_endian_big,
953 "Set target as being big endian.", &endianlist);
954 add_cmd ("little", class_support, set_endian_little,
955 "Set target as being little endian.", &endianlist);
956 add_cmd ("auto", class_support, set_endian_auto,
957 "Select target endianness automatically.", &endianlist);
958 add_cmd ("endian", class_support, show_endian,
959 "Show endianness of target.", &showlist);
960
961 add_cmd ("architecture", class_support, set_architecture,
962 "Set architecture of target.", &setlist);
963 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
964 add_cmd ("architecture", class_support, show_architecture,
965 "Show architecture of target.", &showlist);
966 add_cmd ("architecture", class_support, info_architecture,
967 "List supported target architectures", &infolist);
968
969 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
970 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
971 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
972 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
973 tm_print_insn_info.print_address_func = dis_asm_print_address;
974
975 #ifdef MAINTENANCE_CMDS
976 add_show_from_set (add_set_cmd ("archdebug",
977 class_maintenance,
978 var_zinteger,
979 (char *)&gdbarch_debug,
980 "Set architecture debugging.\n\
981 When non-zero, architecture debugging is enabled.", &setlist),
982 &showlist);
983 #endif
984 }
This page took 0.049778 seconds and 4 git commands to generate.