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