1 /* Dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998-1999, Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
25 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
27 /* Just include everything in sight so that the every old definition
28 of macro is visible. */
29 #include "gdb_string.h"
34 #include "breakpoint.h"
39 #include "gdbthread.h"
41 #include "symfile.h" /* for overlay functions */
46 #include "floatformat.h"
48 /* Convenience macro for allocting typesafe memory. */
51 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
55 /* Use the program counter to determine the contents and size
56 of a breakpoint instruction. If no target-dependent macro
57 BREAKPOINT_FROM_PC has been defined to implement this function,
58 assume that the breakpoint doesn't depend on the PC, and
59 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
60 Return a pointer to a string of bytes that encode a breakpoint
61 instruction, stores the length of the string to *lenptr,
62 and optionally adjust the pc to point to the correct memory location
63 for inserting the breakpoint. */
66 legacy_breakpoint_from_pc (CORE_ADDR
* pcptr
, int *lenptr
)
68 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
69 breakpoint. On some machines, breakpoints are handled by the
70 target environment and we don't have to worry about them here. */
72 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
74 static unsigned char big_break_insn
[] = BIG_BREAKPOINT
;
75 *lenptr
= sizeof (big_break_insn
);
76 return big_break_insn
;
79 #ifdef LITTLE_BREAKPOINT
80 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
82 static unsigned char little_break_insn
[] = LITTLE_BREAKPOINT
;
83 *lenptr
= sizeof (little_break_insn
);
84 return little_break_insn
;
89 static unsigned char break_insn
[] = BREAKPOINT
;
90 *lenptr
= sizeof (break_insn
);
99 generic_frameless_function_invocation_not (struct frame_info
*fi
)
105 generic_return_value_on_stack_not (struct type
*type
)
111 legacy_register_name (int i
)
113 #ifdef REGISTER_NAMES
114 static char *names
[] = REGISTER_NAMES
;
115 if (i
< 0 || i
>= (sizeof (names
) / sizeof (*names
)))
120 internal_error ("legacy_register_name: called.");
125 #if defined (CALL_DUMMY)
126 LONGEST legacy_call_dummy_words
[] = CALL_DUMMY
;
128 LONGEST legacy_call_dummy_words
[1];
130 int legacy_sizeof_call_dummy_words
= sizeof (legacy_call_dummy_words
);
133 generic_remote_translate_xfer_address (CORE_ADDR gdb_addr
, int gdb_len
,
134 CORE_ADDR
* rem_addr
, int *rem_len
)
136 *rem_addr
= gdb_addr
;
141 generic_prologue_frameless_p (CORE_ADDR ip
)
143 #ifdef SKIP_PROLOGUE_FRAMELESS_P
144 return ip
== SKIP_PROLOGUE_FRAMELESS_P (ip
);
146 return ip
== SKIP_PROLOGUE (ip
);
151 /* Helper functions for INNER_THAN */
154 core_addr_lessthan (lhs
, rhs
)
162 core_addr_greaterthan (lhs
, rhs
)
170 /* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */
172 const struct floatformat
*
173 default_float_format (struct gdbarch
*gdbarch
)
176 int byte_order
= gdbarch_byte_order (gdbarch
);
178 int byte_order
= TARGET_BYTE_ORDER
;
183 return &floatformat_ieee_single_big
;
185 return &floatformat_ieee_single_little
;
187 internal_error ("default_float_format: bad byte order");
192 const struct floatformat
*
193 default_double_format (struct gdbarch
*gdbarch
)
196 int byte_order
= gdbarch_byte_order (gdbarch
);
198 int byte_order
= TARGET_BYTE_ORDER
;
203 return &floatformat_ieee_double_big
;
205 return &floatformat_ieee_double_little
;
207 internal_error ("default_double_format: bad byte order");
211 /* Misc helper functions for targets. */
214 frame_num_args_unknown (fi
)
215 struct frame_info
*fi
;
222 generic_register_convertible_not (num
)
229 /* Functions to manipulate the endianness of the target. */
231 #ifdef TARGET_BYTE_ORDER_SELECTABLE
232 /* compat - Catch old targets that expect a selectable byte-order to
233 default to BIG_ENDIAN */
234 #ifndef TARGET_BYTE_ORDER_DEFAULT
235 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
238 #if !TARGET_BYTE_ORDER_SELECTABLE_P
239 #ifndef TARGET_BYTE_ORDER_DEFAULT
240 /* compat - Catch old non byte-order selectable targets that do not
241 define TARGET_BYTE_ORDER_DEFAULT and instead expect
242 TARGET_BYTE_ORDER to be used as the default. For targets that
243 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
244 below will get a strange compiler warning. */
245 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
248 #ifndef TARGET_BYTE_ORDER_DEFAULT
249 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
251 /* ``target_byte_order'' is only used when non- multi-arch.
252 Multi-arch targets obtain the current byte order using
253 TARGET_BYTE_ORDER which is controlled by gdbarch.*. */
254 int target_byte_order
= TARGET_BYTE_ORDER_DEFAULT
;
255 int target_byte_order_auto
= 1;
257 static const char endian_big
[] = "big";
258 static const char endian_little
[] = "little";
259 static const char endian_auto
[] = "auto";
260 static const char *endian_enum
[] =
267 static const char *set_endian_string
;
269 /* Called by ``show endian''. */
272 show_endian (char *args
, int from_tty
)
274 if (TARGET_BYTE_ORDER_AUTO
)
275 printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n",
276 (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
278 printf_unfiltered ("The target is assumed to be %s endian\n",
279 (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
283 set_endian (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
285 if (!TARGET_BYTE_ORDER_SELECTABLE_P
)
287 printf_unfiltered ("Byte order is not selectable.");
289 else if (set_endian_string
== endian_auto
)
291 target_byte_order_auto
= 1;
293 else if (set_endian_string
== endian_little
)
295 target_byte_order_auto
= 0;
298 struct gdbarch_info info
;
299 memset (&info
, 0, sizeof info
);
300 info
.byte_order
= LITTLE_ENDIAN
;
301 gdbarch_update (info
);
305 target_byte_order
= LITTLE_ENDIAN
;
308 else if (set_endian_string
== endian_big
)
310 target_byte_order_auto
= 0;
313 struct gdbarch_info info
;
314 memset (&info
, 0, sizeof info
);
315 info
.byte_order
= BIG_ENDIAN
;
316 gdbarch_update (info
);
320 target_byte_order
= BIG_ENDIAN
;
324 internal_error ("set_endian: bad value");
325 show_endian (NULL
, from_tty
);
328 /* Set the endianness from a BFD. */
331 set_endian_from_file (bfd
*abfd
)
334 internal_error ("set_endian_from_file: not for multi-arch");
335 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
339 if (bfd_big_endian (abfd
))
342 want
= LITTLE_ENDIAN
;
343 if (TARGET_BYTE_ORDER_AUTO
)
344 target_byte_order
= want
;
345 else if (TARGET_BYTE_ORDER
!= want
)
346 warning ("%s endian file does not match %s endian target.",
347 want
== BIG_ENDIAN
? "big" : "little",
348 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
352 if (bfd_big_endian (abfd
)
353 ? TARGET_BYTE_ORDER
!= BIG_ENDIAN
354 : TARGET_BYTE_ORDER
== BIG_ENDIAN
)
355 warning ("%s endian file does not match %s endian target.",
356 bfd_big_endian (abfd
) ? "big" : "little",
357 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
362 /* Functions to manipulate the architecture of the target */
364 enum set_arch
{ set_arch_auto
, set_arch_manual
};
366 int target_architecture_auto
= 1;
368 const char *set_architecture_string
;
370 /* Old way of changing the current architecture. */
372 extern const struct bfd_arch_info bfd_default_arch_struct
;
373 const struct bfd_arch_info
*target_architecture
= &bfd_default_arch_struct
;
374 int (*target_architecture_hook
) (const struct bfd_arch_info
*ap
);
377 arch_ok (const struct bfd_arch_info
*arch
)
380 internal_error ("arch_ok: not multi-arched");
381 /* Should be performing the more basic check that the binary is
382 compatible with GDB. */
383 /* Check with the target that the architecture is valid. */
384 return (target_architecture_hook
== NULL
385 || target_architecture_hook (arch
));
389 set_arch (const struct bfd_arch_info
*arch
,
393 internal_error ("set_arch: not multi-arched");
398 warning ("Target may not support %s architecture",
399 arch
->printable_name
);
400 target_architecture
= arch
;
402 case set_arch_manual
:
405 printf_unfiltered ("Target does not support `%s' architecture.\n",
406 arch
->printable_name
);
410 target_architecture_auto
= 0;
411 target_architecture
= arch
;
416 gdbarch_dump (current_gdbarch
, gdb_stdlog
);
419 /* Set the architecture from arch/machine (deprecated) */
422 set_architecture_from_arch_mach (enum bfd_architecture arch
,
425 const struct bfd_arch_info
*wanted
= bfd_lookup_arch (arch
, mach
);
427 internal_error ("set_architecture_from_arch_mach: not multi-arched");
429 set_arch (wanted
, set_arch_manual
);
431 internal_error ("gdbarch: hardwired architecture/machine not reconized");
434 /* Set the architecture from a BFD (deprecated) */
437 set_architecture_from_file (bfd
*abfd
)
439 const struct bfd_arch_info
*wanted
= bfd_get_arch_info (abfd
);
441 internal_error ("set_architecture_from_file: not multi-arched");
442 if (target_architecture_auto
)
444 set_arch (wanted
, set_arch_auto
);
446 else if (wanted
!= target_architecture
)
448 warning ("%s architecture file may be incompatible with %s target.",
449 wanted
->printable_name
,
450 target_architecture
->printable_name
);
455 /* Called if the user enters ``show architecture'' without an
459 show_architecture (char *args
, int from_tty
)
462 arch
= TARGET_ARCHITECTURE
->printable_name
;
463 if (target_architecture_auto
)
464 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch
);
466 printf_filtered ("The target architecture is assumed to be %s\n", arch
);
470 /* Called if the user enters ``set architecture'' with or without an
474 set_architecture (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
476 if (strcmp (set_architecture_string
, "auto") == 0)
478 target_architecture_auto
= 1;
480 else if (GDB_MULTI_ARCH
)
482 struct gdbarch_info info
;
483 memset (&info
, 0, sizeof info
);
484 info
.bfd_arch_info
= bfd_scan_arch (set_architecture_string
);
485 if (info
.bfd_arch_info
== NULL
)
486 internal_error ("set_architecture: bfd_scan_arch failed");
487 if (gdbarch_update (info
))
488 target_architecture_auto
= 0;
490 printf_unfiltered ("Architecture `%s' not reconized.\n",
491 set_architecture_string
);
495 const struct bfd_arch_info
*arch
496 = bfd_scan_arch (set_architecture_string
);
498 internal_error ("set_architecture: bfd_scan_arch failed");
499 set_arch (arch
, set_arch_manual
);
501 show_architecture (NULL
, from_tty
);
504 /* Called if the user enters ``info architecture'' without an argument. */
507 info_architecture (char *args
, int from_tty
)
509 printf_filtered ("Available architectures are:\n");
512 const char **arches
= gdbarch_printable_names ();
514 for (arch
= arches
; *arch
!= NULL
; arch
++)
516 printf_filtered (" %s", *arch
);
522 enum bfd_architecture a
;
523 for (a
= bfd_arch_obscure
+ 1; a
< bfd_arch_last
; a
++)
525 const struct bfd_arch_info
*ap
;
526 for (ap
= bfd_lookup_arch (a
, 0);
530 printf_filtered (" %s", ap
->printable_name
);
535 printf_filtered ("\n");
538 /* Set the dynamic target-system-dependant parameters (architecture,
539 byte-order) using information found in the BFD */
542 set_gdbarch_from_file (abfd
)
547 struct gdbarch_info info
;
548 memset (&info
, 0, sizeof info
);
550 gdbarch_update (info
);
554 set_architecture_from_file (abfd
);
555 set_endian_from_file (abfd
);
559 /* Initialize the current architecture. Update the ``set
560 architecture'' command so that it specifies a list of valid
563 #ifdef DEFAULT_BFD_ARCH
564 extern const bfd_arch_info_type DEFAULT_BFD_ARCH
;
565 static const bfd_arch_info_type
*default_bfd_arch
= &DEFAULT_BFD_ARCH
;
567 static const bfd_arch_info_type
*default_bfd_arch
;
570 #ifdef DEFAULT_BFD_VEC
571 extern const bfd_target DEFAULT_BFD_VEC
;
572 static const bfd_target
*default_bfd_vec
= &DEFAULT_BFD_VEC
;
574 static const bfd_target
*default_bfd_vec
;
578 initialize_current_architecture (void)
580 const char **arches
= gdbarch_printable_names ();
582 /* determine a default architecture and byte order. */
583 struct gdbarch_info info
;
584 memset (&info
, 0, sizeof (info
));
586 /* Find a default architecture. */
587 if (info
.bfd_arch_info
== NULL
588 && default_bfd_arch
!= NULL
)
589 info
.bfd_arch_info
= default_bfd_arch
;
590 if (info
.bfd_arch_info
== NULL
)
592 /* Choose the architecture by taking the first one
594 const char *chosen
= arches
[0];
596 for (arch
= arches
; *arch
!= NULL
; arch
++)
598 if (strcmp (*arch
, chosen
) < 0)
602 internal_error ("initialize_current_architecture: No arch");
603 info
.bfd_arch_info
= bfd_scan_arch (chosen
);
604 if (info
.bfd_arch_info
== NULL
)
605 internal_error ("initialize_current_architecture: Arch not found");
608 /* take several guesses at a byte order. */
609 /* NB: can't use TARGET_BYTE_ORDER_DEFAULT as its definition is
611 if (info
.byte_order
== 0
612 && default_bfd_vec
!= NULL
)
614 /* Extract BFD's default vector's byte order. */
615 switch (default_bfd_vec
->byteorder
)
618 info
.byte_order
= BIG_ENDIAN
;
620 case BFD_ENDIAN_LITTLE
:
621 info
.byte_order
= LITTLE_ENDIAN
;
627 if (info
.byte_order
== 0)
629 /* look for ``*el-*'' in the target name. */
631 chp
= strchr (target_name
, '-');
633 && chp
- 2 >= target_name
634 && strncmp (chp
- 2, "el", 2) == 0)
635 info
.byte_order
= LITTLE_ENDIAN
;
637 if (info
.byte_order
== 0)
639 /* Wire it to big-endian!!! */
640 info
.byte_order
= BIG_ENDIAN
;
645 gdbarch_update (info
);
648 /* Create the ``set architecture'' command appending ``auto'' to the
649 list of architectures. */
651 struct cmd_list_element
*c
;
652 /* Append ``auto''. */
654 for (nr
= 0; arches
[nr
] != NULL
; nr
++);
655 arches
= xrealloc (arches
, sizeof (char*) * (nr
+ 2));
656 arches
[nr
+ 0] = "auto";
657 arches
[nr
+ 1] = NULL
;
658 /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead
659 of ``const char *''. We just happen to know that the casts are
661 c
= add_set_enum_cmd ("architecture", class_support
,
662 arches
, &set_architecture_string
,
663 "Set architecture of target.",
665 c
->function
.sfunc
= set_architecture
;
666 add_alias_cmd ("processor", "architecture", class_support
, 1, &setlist
);
667 /* Don't use set_from_show - need to print both auto/manual and
669 add_cmd ("architecture", class_support
, show_architecture
,
670 "Show the current target architecture", &showlist
);
671 c
= add_cmd ("architecture", class_support
, info_architecture
,
672 "List supported target architectures", &infolist
);
673 deprecate_cmd (c
, "set architecture");
680 extern initialize_file_ftype _initialize_gdbarch_utils
;
683 _initialize_gdbarch_utils (void)
685 struct cmd_list_element
*c
;
686 c
= add_set_enum_cmd ("endian", class_support
,
687 endian_enum
, &set_endian_string
,
688 "Set endianness of target.",
690 c
->function
.sfunc
= set_endian
;
691 /* Don't use set_from_show - need to print both auto/manual and
693 add_cmd ("endian", class_support
, show_endian
,
694 "Show the current byte-order", &showlist
);