*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
1 /* Dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, 1999, 2000, 2001 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,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22
23 #if GDB_MULTI_ARCH
24 #include "arch-utils.h"
25 #include "gdbcmd.h"
26 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
27 #else
28 /* Just include everything in sight so that the every old definition
29 of macro is visible. */
30 #include "gdb_string.h"
31 #include "symtab.h"
32 #include "frame.h"
33 #include "inferior.h"
34 #include "breakpoint.h"
35 #include "gdb_wait.h"
36 #include "gdbcore.h"
37 #include "gdbcmd.h"
38 #include "target.h"
39 #include "annotate.h"
40 #endif
41 #include "regcache.h"
42 #include "gdb_assert.h"
43
44 #include "version.h"
45
46 #include "floatformat.h"
47
48 /* Use the program counter to determine the contents and size
49 of a breakpoint instruction. If no target-dependent macro
50 BREAKPOINT_FROM_PC has been defined to implement this function,
51 assume that the breakpoint doesn't depend on the PC, and
52 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
53 Return a pointer to a string of bytes that encode a breakpoint
54 instruction, stores the length of the string to *lenptr,
55 and optionally adjust the pc to point to the correct memory location
56 for inserting the breakpoint. */
57
58 unsigned char *
59 legacy_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
60 {
61 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
62 breakpoint. On some machines, breakpoints are handled by the
63 target environment and we don't have to worry about them here. */
64 #ifdef BIG_BREAKPOINT
65 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
66 {
67 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
68 *lenptr = sizeof (big_break_insn);
69 return big_break_insn;
70 }
71 #endif
72 #ifdef LITTLE_BREAKPOINT
73 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
74 {
75 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
76 *lenptr = sizeof (little_break_insn);
77 return little_break_insn;
78 }
79 #endif
80 #ifdef BREAKPOINT
81 {
82 static unsigned char break_insn[] = BREAKPOINT;
83 *lenptr = sizeof (break_insn);
84 return break_insn;
85 }
86 #endif
87 *lenptr = 0;
88 return NULL;
89 }
90
91 int
92 generic_frameless_function_invocation_not (struct frame_info *fi)
93 {
94 return 0;
95 }
96
97 int
98 generic_return_value_on_stack_not (struct type *type)
99 {
100 return 0;
101 }
102
103 CORE_ADDR
104 generic_skip_trampoline_code (CORE_ADDR pc)
105 {
106 return 0;
107 }
108
109 int
110 generic_in_solib_call_trampoline (CORE_ADDR pc, char *name)
111 {
112 return 0;
113 }
114
115 int
116 generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
117 {
118 return 0;
119 }
120
121 char *
122 legacy_register_name (int i)
123 {
124 #ifdef REGISTER_NAMES
125 static char *names[] = REGISTER_NAMES;
126 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
127 return NULL;
128 else
129 return names[i];
130 #else
131 internal_error (__FILE__, __LINE__,
132 "legacy_register_name: called.");
133 return NULL;
134 #endif
135 }
136
137 #if defined (CALL_DUMMY)
138 LONGEST legacy_call_dummy_words[] = CALL_DUMMY;
139 #else
140 LONGEST legacy_call_dummy_words[1];
141 #endif
142 int legacy_sizeof_call_dummy_words = sizeof (legacy_call_dummy_words);
143
144 void
145 generic_remote_translate_xfer_address (CORE_ADDR gdb_addr, int gdb_len,
146 CORE_ADDR * rem_addr, int *rem_len)
147 {
148 *rem_addr = gdb_addr;
149 *rem_len = gdb_len;
150 }
151
152 int
153 generic_prologue_frameless_p (CORE_ADDR ip)
154 {
155 #ifdef SKIP_PROLOGUE_FRAMELESS_P
156 return ip == SKIP_PROLOGUE_FRAMELESS_P (ip);
157 #else
158 return ip == SKIP_PROLOGUE (ip);
159 #endif
160 }
161
162 /* New/multi-arched targets should use the correct gdbarch field
163 instead of using this global pointer. */
164 int
165 legacy_print_insn (bfd_vma vma, disassemble_info *info)
166 {
167 return (*tm_print_insn) (vma, info);
168 }
169
170 /* Helper functions for INNER_THAN */
171
172 int
173 core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
174 {
175 return (lhs < rhs);
176 }
177
178 int
179 core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
180 {
181 return (lhs > rhs);
182 }
183
184
185 /* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */
186
187 const struct floatformat *
188 default_float_format (struct gdbarch *gdbarch)
189 {
190 #if GDB_MULTI_ARCH
191 int byte_order = gdbarch_byte_order (gdbarch);
192 #else
193 int byte_order = TARGET_BYTE_ORDER;
194 #endif
195 switch (byte_order)
196 {
197 case BFD_ENDIAN_BIG:
198 return &floatformat_ieee_single_big;
199 case BFD_ENDIAN_LITTLE:
200 return &floatformat_ieee_single_little;
201 default:
202 internal_error (__FILE__, __LINE__,
203 "default_float_format: bad byte order");
204 }
205 }
206
207
208 const struct floatformat *
209 default_double_format (struct gdbarch *gdbarch)
210 {
211 #if GDB_MULTI_ARCH
212 int byte_order = gdbarch_byte_order (gdbarch);
213 #else
214 int byte_order = TARGET_BYTE_ORDER;
215 #endif
216 switch (byte_order)
217 {
218 case BFD_ENDIAN_BIG:
219 return &floatformat_ieee_double_big;
220 case BFD_ENDIAN_LITTLE:
221 return &floatformat_ieee_double_little;
222 default:
223 internal_error (__FILE__, __LINE__,
224 "default_double_format: bad byte order");
225 }
226 }
227
228 /* Misc helper functions for targets. */
229
230 int
231 frame_num_args_unknown (struct frame_info *fi)
232 {
233 return -1;
234 }
235
236
237 int
238 generic_register_convertible_not (int num)
239 {
240 return 0;
241 }
242
243
244 /* Under some ABI's that specify the `struct convention' for returning
245 structures by value, by the time we've returned from the function,
246 the return value is sitting there in the caller's buffer, but GDB
247 has no way to find the address of that buffer.
248
249 On such architectures, use this function as your
250 extract_struct_value_address method. When asked to a struct
251 returned by value in this fashion, GDB will print a nice error
252 message, instead of garbage. */
253 CORE_ADDR
254 generic_cannot_extract_struct_value_address (char *dummy)
255 {
256 return 0;
257 }
258
259 int
260 default_register_sim_regno (int num)
261 {
262 return num;
263 }
264
265
266 CORE_ADDR
267 core_addr_identity (CORE_ADDR addr)
268 {
269 return addr;
270 }
271
272 int
273 no_op_reg_to_regnum (int reg)
274 {
275 return reg;
276 }
277
278 /* For use by frame_args_address and frame_locals_address. */
279 CORE_ADDR
280 default_frame_address (struct frame_info *fi)
281 {
282 return fi->frame;
283 }
284
285 /* Default prepare_to_procced(). */
286 int
287 default_prepare_to_proceed (int select_it)
288 {
289 return 0;
290 }
291
292 /* Generic prepare_to_proceed(). This one should be suitable for most
293 targets that support threads. */
294 int
295 generic_prepare_to_proceed (int select_it)
296 {
297 ptid_t wait_ptid;
298 struct target_waitstatus wait_status;
299
300 /* Get the last target status returned by target_wait(). */
301 get_last_target_status (&wait_ptid, &wait_status);
302
303 /* Make sure we were stopped either at a breakpoint, or because
304 of a Ctrl-C. */
305 if (wait_status.kind != TARGET_WAITKIND_STOPPED
306 || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
307 wait_status.value.sig != TARGET_SIGNAL_INT))
308 {
309 return 0;
310 }
311
312 if (!ptid_equal (wait_ptid, minus_one_ptid)
313 && !ptid_equal (inferior_ptid, wait_ptid))
314 {
315 /* Switched over from WAIT_PID. */
316 CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
317
318 if (wait_pc != read_pc ())
319 {
320 if (select_it)
321 {
322 /* Switch back to WAIT_PID thread. */
323 inferior_ptid = wait_ptid;
324
325 /* FIXME: This stuff came from switch_to_thread() in
326 thread.c (which should probably be a public function). */
327 flush_cached_frames ();
328 registers_changed ();
329 stop_pc = wait_pc;
330 select_frame (get_current_frame (), 0);
331 }
332 /* We return 1 to indicate that there is a breakpoint here,
333 so we need to step over it before continuing to avoid
334 hitting it straight away. */
335 if (breakpoint_here_p (wait_pc))
336 {
337 return 1;
338 }
339 }
340 }
341 return 0;
342
343 }
344
345 void
346 init_frame_pc_noop (int fromleaf, struct frame_info *prev)
347 {
348 return;
349 }
350
351 void
352 init_frame_pc_default (int fromleaf, struct frame_info *prev)
353 {
354 if (fromleaf)
355 prev->pc = SAVED_PC_AFTER_CALL (prev->next);
356 else if (prev->next != NULL)
357 prev->pc = FRAME_SAVED_PC (prev->next);
358 else
359 prev->pc = read_pc ();
360 }
361
362 int
363 cannot_register_not (int regnum)
364 {
365 return 0;
366 }
367
368 /* Legacy version of target_virtual_frame_pointer(). Assumes that
369 there is an FP_REGNUM and that it is the same, cooked or raw. */
370
371 void
372 legacy_virtual_frame_pointer (CORE_ADDR pc,
373 int *frame_regnum,
374 LONGEST *frame_offset)
375 {
376 gdb_assert (FP_REGNUM >= 0);
377 *frame_regnum = FP_REGNUM;
378 *frame_offset = 0;
379 }
380
381 /* Assume the world is flat. Every register is large enough to fit a
382 target integer. */
383
384 int
385 generic_register_raw_size (int regnum)
386 {
387 gdb_assert (regnum >= 0 && regnum < NUM_REGS + NUM_PSEUDO_REGS);
388 return TARGET_INT_BIT / HOST_CHAR_BIT;
389 }
390
391 /* Assume the virtual size corresponds to the virtual type. */
392
393 int
394 generic_register_virtual_size (int regnum)
395 {
396 return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (regnum));
397 }
398
399 \f
400 /* Functions to manipulate the endianness of the target. */
401
402 #ifdef TARGET_BYTE_ORDER_SELECTABLE
403 /* compat - Catch old targets that expect a selectable byte-order to
404 default to BFD_ENDIAN_BIG */
405 #ifndef TARGET_BYTE_ORDER_DEFAULT
406 #define TARGET_BYTE_ORDER_DEFAULT BFD_ENDIAN_BIG
407 #endif
408 #endif
409 #if !TARGET_BYTE_ORDER_SELECTABLE_P
410 #ifndef TARGET_BYTE_ORDER_DEFAULT
411 /* compat - Catch old non byte-order selectable targets that do not
412 define TARGET_BYTE_ORDER_DEFAULT and instead expect
413 TARGET_BYTE_ORDER to be used as the default. For targets that
414 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
415 below will get a strange compiler warning. */
416 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
417 #endif
418 #endif
419 #ifndef TARGET_BYTE_ORDER_DEFAULT
420 #define TARGET_BYTE_ORDER_DEFAULT BFD_ENDIAN_BIG /* arbitrary */
421 #endif
422 /* ``target_byte_order'' is only used when non- multi-arch.
423 Multi-arch targets obtain the current byte order using
424 TARGET_BYTE_ORDER which is controlled by gdbarch.*. */
425 int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
426 int target_byte_order_auto = 1;
427
428 static const char endian_big[] = "big";
429 static const char endian_little[] = "little";
430 static const char endian_auto[] = "auto";
431 static const char *endian_enum[] =
432 {
433 endian_big,
434 endian_little,
435 endian_auto,
436 NULL,
437 };
438 static const char *set_endian_string;
439
440 /* Called by ``show endian''. */
441
442 static void
443 show_endian (char *args, int from_tty)
444 {
445 if (TARGET_BYTE_ORDER_AUTO)
446 printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n",
447 (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little"));
448 else
449 printf_unfiltered ("The target is assumed to be %s endian\n",
450 (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little"));
451 }
452
453 static void
454 set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
455 {
456 if (!TARGET_BYTE_ORDER_SELECTABLE_P)
457 {
458 printf_unfiltered ("Byte order is not selectable.");
459 }
460 else if (set_endian_string == endian_auto)
461 {
462 target_byte_order_auto = 1;
463 }
464 else if (set_endian_string == endian_little)
465 {
466 target_byte_order_auto = 0;
467 if (GDB_MULTI_ARCH)
468 {
469 struct gdbarch_info info;
470 gdbarch_info_init (&info);
471 info.byte_order = BFD_ENDIAN_LITTLE;
472 if (! gdbarch_update_p (info))
473 {
474 printf_unfiltered ("Little endian target not supported by GDB\n");
475 }
476 }
477 else
478 {
479 target_byte_order = BFD_ENDIAN_LITTLE;
480 }
481 }
482 else if (set_endian_string == endian_big)
483 {
484 target_byte_order_auto = 0;
485 if (GDB_MULTI_ARCH)
486 {
487 struct gdbarch_info info;
488 gdbarch_info_init (&info);
489 info.byte_order = BFD_ENDIAN_BIG;
490 if (! gdbarch_update_p (info))
491 {
492 printf_unfiltered ("Big endian target not supported by GDB\n");
493 }
494 }
495 else
496 {
497 target_byte_order = BFD_ENDIAN_BIG;
498 }
499 }
500 else
501 internal_error (__FILE__, __LINE__,
502 "set_endian: bad value");
503 show_endian (NULL, from_tty);
504 }
505
506 /* Set the endianness from a BFD. */
507
508 static void
509 set_endian_from_file (bfd *abfd)
510 {
511 if (GDB_MULTI_ARCH)
512 internal_error (__FILE__, __LINE__,
513 "set_endian_from_file: not for multi-arch");
514 if (TARGET_BYTE_ORDER_SELECTABLE_P)
515 {
516 int want;
517
518 if (bfd_big_endian (abfd))
519 want = BFD_ENDIAN_BIG;
520 else
521 want = BFD_ENDIAN_LITTLE;
522 if (TARGET_BYTE_ORDER_AUTO)
523 target_byte_order = want;
524 else if (TARGET_BYTE_ORDER != want)
525 warning ("%s endian file does not match %s endian target.",
526 want == BFD_ENDIAN_BIG ? "big" : "little",
527 TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little");
528 }
529 else
530 {
531 if (bfd_big_endian (abfd)
532 ? TARGET_BYTE_ORDER != BFD_ENDIAN_BIG
533 : TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
534 warning ("%s endian file does not match %s endian target.",
535 bfd_big_endian (abfd) ? "big" : "little",
536 TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little");
537 }
538 }
539
540
541 /* Functions to manipulate the architecture of the target */
542
543 enum set_arch { set_arch_auto, set_arch_manual };
544
545 int target_architecture_auto = 1;
546
547 const char *set_architecture_string;
548
549 /* Old way of changing the current architecture. */
550
551 extern const struct bfd_arch_info bfd_default_arch_struct;
552 const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
553 int (*target_architecture_hook) (const struct bfd_arch_info *ap);
554
555 static int
556 arch_ok (const struct bfd_arch_info *arch)
557 {
558 if (GDB_MULTI_ARCH)
559 internal_error (__FILE__, __LINE__,
560 "arch_ok: not multi-arched");
561 /* Should be performing the more basic check that the binary is
562 compatible with GDB. */
563 /* Check with the target that the architecture is valid. */
564 return (target_architecture_hook == NULL
565 || target_architecture_hook (arch));
566 }
567
568 static void
569 set_arch (const struct bfd_arch_info *arch,
570 enum set_arch type)
571 {
572 if (GDB_MULTI_ARCH)
573 internal_error (__FILE__, __LINE__,
574 "set_arch: not multi-arched");
575 switch (type)
576 {
577 case set_arch_auto:
578 if (!arch_ok (arch))
579 warning ("Target may not support %s architecture",
580 arch->printable_name);
581 target_architecture = arch;
582 break;
583 case set_arch_manual:
584 if (!arch_ok (arch))
585 {
586 printf_unfiltered ("Target does not support `%s' architecture.\n",
587 arch->printable_name);
588 }
589 else
590 {
591 target_architecture_auto = 0;
592 target_architecture = arch;
593 }
594 break;
595 }
596 if (gdbarch_debug)
597 gdbarch_dump (current_gdbarch, gdb_stdlog);
598 }
599
600 /* Set the architecture from arch/machine (deprecated) */
601
602 void
603 set_architecture_from_arch_mach (enum bfd_architecture arch,
604 unsigned long mach)
605 {
606 const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
607 if (GDB_MULTI_ARCH)
608 internal_error (__FILE__, __LINE__,
609 "set_architecture_from_arch_mach: not multi-arched");
610 if (wanted != NULL)
611 set_arch (wanted, set_arch_manual);
612 else
613 internal_error (__FILE__, __LINE__,
614 "gdbarch: hardwired architecture/machine not recognized");
615 }
616
617 /* Set the architecture from a BFD (deprecated) */
618
619 static void
620 set_architecture_from_file (bfd *abfd)
621 {
622 const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
623 if (GDB_MULTI_ARCH)
624 internal_error (__FILE__, __LINE__,
625 "set_architecture_from_file: not multi-arched");
626 if (target_architecture_auto)
627 {
628 set_arch (wanted, set_arch_auto);
629 }
630 else if (wanted != target_architecture)
631 {
632 warning ("%s architecture file may be incompatible with %s target.",
633 wanted->printable_name,
634 target_architecture->printable_name);
635 }
636 }
637
638
639 /* Called if the user enters ``show architecture'' without an
640 argument. */
641
642 static void
643 show_architecture (char *args, int from_tty)
644 {
645 const char *arch;
646 arch = TARGET_ARCHITECTURE->printable_name;
647 if (target_architecture_auto)
648 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
649 else
650 printf_filtered ("The target architecture is assumed to be %s\n", arch);
651 }
652
653
654 /* Called if the user enters ``set architecture'' with or without an
655 argument. */
656
657 static void
658 set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
659 {
660 if (strcmp (set_architecture_string, "auto") == 0)
661 {
662 target_architecture_auto = 1;
663 }
664 else if (GDB_MULTI_ARCH)
665 {
666 struct gdbarch_info info;
667 gdbarch_info_init (&info);
668 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
669 if (info.bfd_arch_info == NULL)
670 internal_error (__FILE__, __LINE__,
671 "set_architecture: bfd_scan_arch failed");
672 if (gdbarch_update_p (info))
673 target_architecture_auto = 0;
674 else
675 printf_unfiltered ("Architecture `%s' not recognized.\n",
676 set_architecture_string);
677 }
678 else
679 {
680 const struct bfd_arch_info *arch
681 = bfd_scan_arch (set_architecture_string);
682 if (arch == NULL)
683 internal_error (__FILE__, __LINE__,
684 "set_architecture: bfd_scan_arch failed");
685 set_arch (arch, set_arch_manual);
686 }
687 show_architecture (NULL, from_tty);
688 }
689
690 /* Set the dynamic target-system-dependent parameters (architecture,
691 byte-order) using information found in the BFD */
692
693 void
694 set_gdbarch_from_file (bfd *abfd)
695 {
696 if (GDB_MULTI_ARCH)
697 {
698 struct gdbarch_info info;
699 gdbarch_info_init (&info);
700 info.abfd = abfd;
701 if (! gdbarch_update_p (info))
702 error ("Architecture of file not recognized.\n");
703 }
704 else
705 {
706 set_architecture_from_file (abfd);
707 set_endian_from_file (abfd);
708 }
709 }
710
711 /* Initialize the current architecture. Update the ``set
712 architecture'' command so that it specifies a list of valid
713 architectures. */
714
715 #ifdef DEFAULT_BFD_ARCH
716 extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
717 static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
718 #else
719 static const bfd_arch_info_type *default_bfd_arch;
720 #endif
721
722 #ifdef DEFAULT_BFD_VEC
723 extern const bfd_target DEFAULT_BFD_VEC;
724 static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
725 #else
726 static const bfd_target *default_bfd_vec;
727 #endif
728
729 void
730 initialize_current_architecture (void)
731 {
732 const char **arches = gdbarch_printable_names ();
733
734 /* determine a default architecture and byte order. */
735 struct gdbarch_info info;
736 gdbarch_info_init (&info);
737
738 /* Find a default architecture. */
739 if (info.bfd_arch_info == NULL
740 && default_bfd_arch != NULL)
741 info.bfd_arch_info = default_bfd_arch;
742 if (info.bfd_arch_info == NULL)
743 {
744 /* Choose the architecture by taking the first one
745 alphabetically. */
746 const char *chosen = arches[0];
747 const char **arch;
748 for (arch = arches; *arch != NULL; arch++)
749 {
750 if (strcmp (*arch, chosen) < 0)
751 chosen = *arch;
752 }
753 if (chosen == NULL)
754 internal_error (__FILE__, __LINE__,
755 "initialize_current_architecture: No arch");
756 info.bfd_arch_info = bfd_scan_arch (chosen);
757 if (info.bfd_arch_info == NULL)
758 internal_error (__FILE__, __LINE__,
759 "initialize_current_architecture: Arch not found");
760 }
761
762 /* take several guesses at a byte order. */
763 /* NB: can't use TARGET_BYTE_ORDER_DEFAULT as its definition is
764 forced above. */
765 if (info.byte_order == BFD_ENDIAN_UNKNOWN
766 && default_bfd_vec != NULL)
767 {
768 /* Extract BFD's default vector's byte order. */
769 switch (default_bfd_vec->byteorder)
770 {
771 case BFD_ENDIAN_BIG:
772 info.byte_order = BFD_ENDIAN_BIG;
773 break;
774 case BFD_ENDIAN_LITTLE:
775 info.byte_order = BFD_ENDIAN_LITTLE;
776 break;
777 default:
778 break;
779 }
780 }
781 if (info.byte_order == BFD_ENDIAN_UNKNOWN)
782 {
783 /* look for ``*el-*'' in the target name. */
784 const char *chp;
785 chp = strchr (target_name, '-');
786 if (chp != NULL
787 && chp - 2 >= target_name
788 && strncmp (chp - 2, "el", 2) == 0)
789 info.byte_order = BFD_ENDIAN_LITTLE;
790 }
791 if (info.byte_order == BFD_ENDIAN_UNKNOWN)
792 {
793 /* Wire it to big-endian!!! */
794 info.byte_order = BFD_ENDIAN_BIG;
795 }
796
797 if (GDB_MULTI_ARCH)
798 {
799 if (! gdbarch_update_p (info))
800 {
801 internal_error (__FILE__, __LINE__,
802 "initialize_current_architecture: Selection of initial architecture failed");
803 }
804 }
805 else
806 initialize_non_multiarch ();
807
808 /* Create the ``set architecture'' command appending ``auto'' to the
809 list of architectures. */
810 {
811 struct cmd_list_element *c;
812 /* Append ``auto''. */
813 int nr;
814 for (nr = 0; arches[nr] != NULL; nr++);
815 arches = xrealloc (arches, sizeof (char*) * (nr + 2));
816 arches[nr + 0] = "auto";
817 arches[nr + 1] = NULL;
818 /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead
819 of ``const char *''. We just happen to know that the casts are
820 safe. */
821 c = add_set_enum_cmd ("architecture", class_support,
822 arches, &set_architecture_string,
823 "Set architecture of target.",
824 &setlist);
825 c->function.sfunc = set_architecture;
826 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
827 /* Don't use set_from_show - need to print both auto/manual and
828 current setting. */
829 add_cmd ("architecture", class_support, show_architecture,
830 "Show the current target architecture", &showlist);
831 }
832 }
833
834
835 /* Initialize a gdbarch info to values that will be automatically
836 overridden. Note: Originally, this ``struct info'' was initialized
837 using memset(0). Unfortunatly, that ran into problems, namely
838 BFD_ENDIAN_BIG is zero. An explicit initialization function that
839 can explicitly set each field to a well defined value is used. */
840
841 void
842 gdbarch_info_init (struct gdbarch_info *info)
843 {
844 memset (info, 0, sizeof (struct gdbarch_info));
845 info->byte_order = BFD_ENDIAN_UNKNOWN;
846 }
847
848 /* */
849
850 extern initialize_file_ftype _initialize_gdbarch_utils;
851
852 void
853 _initialize_gdbarch_utils (void)
854 {
855 struct cmd_list_element *c;
856 c = add_set_enum_cmd ("endian", class_support,
857 endian_enum, &set_endian_string,
858 "Set endianness of target.",
859 &setlist);
860 c->function.sfunc = set_endian;
861 /* Don't use set_from_show - need to print both auto/manual and
862 current setting. */
863 add_cmd ("endian", class_support, show_endian,
864 "Show the current byte-order", &showlist);
865 }
This page took 0.059707 seconds and 4 git commands to generate.