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