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 (CORE_ADDR lhs
, CORE_ADDR rhs
)
160 core_addr_greaterthan (CORE_ADDR lhs
, CORE_ADDR rhs
)
166 /* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */
168 const struct floatformat
*
169 default_float_format (struct gdbarch
*gdbarch
)
172 int byte_order
= gdbarch_byte_order (gdbarch
);
174 int byte_order
= TARGET_BYTE_ORDER
;
179 return &floatformat_ieee_single_big
;
181 return &floatformat_ieee_single_little
;
183 internal_error ("default_float_format: bad byte order");
188 const struct floatformat
*
189 default_double_format (struct gdbarch
*gdbarch
)
192 int byte_order
= gdbarch_byte_order (gdbarch
);
194 int byte_order
= TARGET_BYTE_ORDER
;
199 return &floatformat_ieee_double_big
;
201 return &floatformat_ieee_double_little
;
203 internal_error ("default_double_format: bad byte order");
207 /* Misc helper functions for targets. */
210 frame_num_args_unknown (struct frame_info
*fi
)
217 generic_register_convertible_not (int num
)
223 /* Functions to manipulate the endianness of the target. */
225 #ifdef TARGET_BYTE_ORDER_SELECTABLE
226 /* compat - Catch old targets that expect a selectable byte-order to
227 default to BIG_ENDIAN */
228 #ifndef TARGET_BYTE_ORDER_DEFAULT
229 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
232 #if !TARGET_BYTE_ORDER_SELECTABLE_P
233 #ifndef TARGET_BYTE_ORDER_DEFAULT
234 /* compat - Catch old non byte-order selectable targets that do not
235 define TARGET_BYTE_ORDER_DEFAULT and instead expect
236 TARGET_BYTE_ORDER to be used as the default. For targets that
237 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
238 below will get a strange compiler warning. */
239 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
242 #ifndef TARGET_BYTE_ORDER_DEFAULT
243 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
245 /* ``target_byte_order'' is only used when non- multi-arch.
246 Multi-arch targets obtain the current byte order using
247 TARGET_BYTE_ORDER which is controlled by gdbarch.*. */
248 int target_byte_order
= TARGET_BYTE_ORDER_DEFAULT
;
249 int target_byte_order_auto
= 1;
251 static const char endian_big
[] = "big";
252 static const char endian_little
[] = "little";
253 static const char endian_auto
[] = "auto";
254 static const char *endian_enum
[] =
261 static const char *set_endian_string
;
263 /* Called by ``show endian''. */
266 show_endian (char *args
, int from_tty
)
268 if (TARGET_BYTE_ORDER_AUTO
)
269 printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n",
270 (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
272 printf_unfiltered ("The target is assumed to be %s endian\n",
273 (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
277 set_endian (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
279 if (!TARGET_BYTE_ORDER_SELECTABLE_P
)
281 printf_unfiltered ("Byte order is not selectable.");
283 else if (set_endian_string
== endian_auto
)
285 target_byte_order_auto
= 1;
287 else if (set_endian_string
== endian_little
)
289 target_byte_order_auto
= 0;
292 struct gdbarch_info info
;
293 memset (&info
, 0, sizeof info
);
294 info
.byte_order
= LITTLE_ENDIAN
;
295 gdbarch_update (info
);
299 target_byte_order
= LITTLE_ENDIAN
;
302 else if (set_endian_string
== endian_big
)
304 target_byte_order_auto
= 0;
307 struct gdbarch_info info
;
308 memset (&info
, 0, sizeof info
);
309 info
.byte_order
= BIG_ENDIAN
;
310 gdbarch_update (info
);
314 target_byte_order
= BIG_ENDIAN
;
318 internal_error ("set_endian: bad value");
319 show_endian (NULL
, from_tty
);
322 /* Set the endianness from a BFD. */
325 set_endian_from_file (bfd
*abfd
)
328 internal_error ("set_endian_from_file: not for multi-arch");
329 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
333 if (bfd_big_endian (abfd
))
336 want
= LITTLE_ENDIAN
;
337 if (TARGET_BYTE_ORDER_AUTO
)
338 target_byte_order
= want
;
339 else if (TARGET_BYTE_ORDER
!= want
)
340 warning ("%s endian file does not match %s endian target.",
341 want
== BIG_ENDIAN
? "big" : "little",
342 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
346 if (bfd_big_endian (abfd
)
347 ? TARGET_BYTE_ORDER
!= BIG_ENDIAN
348 : TARGET_BYTE_ORDER
== BIG_ENDIAN
)
349 warning ("%s endian file does not match %s endian target.",
350 bfd_big_endian (abfd
) ? "big" : "little",
351 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
356 /* Functions to manipulate the architecture of the target */
358 enum set_arch
{ set_arch_auto
, set_arch_manual
};
360 int target_architecture_auto
= 1;
362 const char *set_architecture_string
;
364 /* Old way of changing the current architecture. */
366 extern const struct bfd_arch_info bfd_default_arch_struct
;
367 const struct bfd_arch_info
*target_architecture
= &bfd_default_arch_struct
;
368 int (*target_architecture_hook
) (const struct bfd_arch_info
*ap
);
371 arch_ok (const struct bfd_arch_info
*arch
)
374 internal_error ("arch_ok: not multi-arched");
375 /* Should be performing the more basic check that the binary is
376 compatible with GDB. */
377 /* Check with the target that the architecture is valid. */
378 return (target_architecture_hook
== NULL
379 || target_architecture_hook (arch
));
383 set_arch (const struct bfd_arch_info
*arch
,
387 internal_error ("set_arch: not multi-arched");
392 warning ("Target may not support %s architecture",
393 arch
->printable_name
);
394 target_architecture
= arch
;
396 case set_arch_manual
:
399 printf_unfiltered ("Target does not support `%s' architecture.\n",
400 arch
->printable_name
);
404 target_architecture_auto
= 0;
405 target_architecture
= arch
;
410 gdbarch_dump (current_gdbarch
, gdb_stdlog
);
413 /* Set the architecture from arch/machine (deprecated) */
416 set_architecture_from_arch_mach (enum bfd_architecture arch
,
419 const struct bfd_arch_info
*wanted
= bfd_lookup_arch (arch
, mach
);
421 internal_error ("set_architecture_from_arch_mach: not multi-arched");
423 set_arch (wanted
, set_arch_manual
);
425 internal_error ("gdbarch: hardwired architecture/machine not reconized");
428 /* Set the architecture from a BFD (deprecated) */
431 set_architecture_from_file (bfd
*abfd
)
433 const struct bfd_arch_info
*wanted
= bfd_get_arch_info (abfd
);
435 internal_error ("set_architecture_from_file: not multi-arched");
436 if (target_architecture_auto
)
438 set_arch (wanted
, set_arch_auto
);
440 else if (wanted
!= target_architecture
)
442 warning ("%s architecture file may be incompatible with %s target.",
443 wanted
->printable_name
,
444 target_architecture
->printable_name
);
449 /* Called if the user enters ``show architecture'' without an
453 show_architecture (char *args
, int from_tty
)
456 arch
= TARGET_ARCHITECTURE
->printable_name
;
457 if (target_architecture_auto
)
458 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch
);
460 printf_filtered ("The target architecture is assumed to be %s\n", arch
);
464 /* Called if the user enters ``set architecture'' with or without an
468 set_architecture (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
470 if (strcmp (set_architecture_string
, "auto") == 0)
472 target_architecture_auto
= 1;
474 else if (GDB_MULTI_ARCH
)
476 struct gdbarch_info info
;
477 memset (&info
, 0, sizeof info
);
478 info
.bfd_arch_info
= bfd_scan_arch (set_architecture_string
);
479 if (info
.bfd_arch_info
== NULL
)
480 internal_error ("set_architecture: bfd_scan_arch failed");
481 if (gdbarch_update (info
))
482 target_architecture_auto
= 0;
484 printf_unfiltered ("Architecture `%s' not reconized.\n",
485 set_architecture_string
);
489 const struct bfd_arch_info
*arch
490 = bfd_scan_arch (set_architecture_string
);
492 internal_error ("set_architecture: bfd_scan_arch failed");
493 set_arch (arch
, set_arch_manual
);
495 show_architecture (NULL
, from_tty
);
498 /* Called if the user enters ``info architecture'' without an argument. */
501 info_architecture (char *args
, int from_tty
)
503 printf_filtered ("Available architectures are:\n");
506 const char **arches
= gdbarch_printable_names ();
508 for (arch
= arches
; *arch
!= NULL
; arch
++)
510 printf_filtered (" %s", *arch
);
516 enum bfd_architecture a
;
517 for (a
= bfd_arch_obscure
+ 1; a
< bfd_arch_last
; a
++)
519 const struct bfd_arch_info
*ap
;
520 for (ap
= bfd_lookup_arch (a
, 0);
524 printf_filtered (" %s", ap
->printable_name
);
529 printf_filtered ("\n");
532 /* Set the dynamic target-system-dependant parameters (architecture,
533 byte-order) using information found in the BFD */
536 set_gdbarch_from_file (bfd
*abfd
)
540 struct gdbarch_info info
;
541 memset (&info
, 0, sizeof info
);
543 gdbarch_update (info
);
547 set_architecture_from_file (abfd
);
548 set_endian_from_file (abfd
);
552 /* Initialize the current architecture. Update the ``set
553 architecture'' command so that it specifies a list of valid
556 #ifdef DEFAULT_BFD_ARCH
557 extern const bfd_arch_info_type DEFAULT_BFD_ARCH
;
558 static const bfd_arch_info_type
*default_bfd_arch
= &DEFAULT_BFD_ARCH
;
560 static const bfd_arch_info_type
*default_bfd_arch
;
563 #ifdef DEFAULT_BFD_VEC
564 extern const bfd_target DEFAULT_BFD_VEC
;
565 static const bfd_target
*default_bfd_vec
= &DEFAULT_BFD_VEC
;
567 static const bfd_target
*default_bfd_vec
;
571 initialize_current_architecture (void)
573 const char **arches
= gdbarch_printable_names ();
575 /* determine a default architecture and byte order. */
576 struct gdbarch_info info
;
577 memset (&info
, 0, sizeof (info
));
579 /* Find a default architecture. */
580 if (info
.bfd_arch_info
== NULL
581 && default_bfd_arch
!= NULL
)
582 info
.bfd_arch_info
= default_bfd_arch
;
583 if (info
.bfd_arch_info
== NULL
)
585 /* Choose the architecture by taking the first one
587 const char *chosen
= arches
[0];
589 for (arch
= arches
; *arch
!= NULL
; arch
++)
591 if (strcmp (*arch
, chosen
) < 0)
595 internal_error ("initialize_current_architecture: No arch");
596 info
.bfd_arch_info
= bfd_scan_arch (chosen
);
597 if (info
.bfd_arch_info
== NULL
)
598 internal_error ("initialize_current_architecture: Arch not found");
601 /* take several guesses at a byte order. */
602 /* NB: can't use TARGET_BYTE_ORDER_DEFAULT as its definition is
604 if (info
.byte_order
== 0
605 && default_bfd_vec
!= NULL
)
607 /* Extract BFD's default vector's byte order. */
608 switch (default_bfd_vec
->byteorder
)
611 info
.byte_order
= BIG_ENDIAN
;
613 case BFD_ENDIAN_LITTLE
:
614 info
.byte_order
= LITTLE_ENDIAN
;
620 if (info
.byte_order
== 0)
622 /* look for ``*el-*'' in the target name. */
624 chp
= strchr (target_name
, '-');
626 && chp
- 2 >= target_name
627 && strncmp (chp
- 2, "el", 2) == 0)
628 info
.byte_order
= LITTLE_ENDIAN
;
630 if (info
.byte_order
== 0)
632 /* Wire it to big-endian!!! */
633 info
.byte_order
= BIG_ENDIAN
;
638 gdbarch_update (info
);
641 /* Create the ``set architecture'' command appending ``auto'' to the
642 list of architectures. */
644 struct cmd_list_element
*c
;
645 /* Append ``auto''. */
647 for (nr
= 0; arches
[nr
] != NULL
; nr
++);
648 arches
= xrealloc (arches
, sizeof (char*) * (nr
+ 2));
649 arches
[nr
+ 0] = "auto";
650 arches
[nr
+ 1] = NULL
;
651 /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead
652 of ``const char *''. We just happen to know that the casts are
654 c
= add_set_enum_cmd ("architecture", class_support
,
655 arches
, &set_architecture_string
,
656 "Set architecture of target.",
658 c
->function
.sfunc
= set_architecture
;
659 add_alias_cmd ("processor", "architecture", class_support
, 1, &setlist
);
660 /* Don't use set_from_show - need to print both auto/manual and
662 add_cmd ("architecture", class_support
, show_architecture
,
663 "Show the current target architecture", &showlist
);
664 c
= add_cmd ("architecture", class_support
, info_architecture
,
665 "List supported target architectures", &infolist
);
666 deprecate_cmd (c
, "set architecture");
673 extern initialize_file_ftype _initialize_gdbarch_utils
;
676 _initialize_gdbarch_utils (void)
678 struct cmd_list_element
*c
;
679 c
= add_set_enum_cmd ("endian", class_support
,
680 endian_enum
, &set_endian_string
,
681 "Set endianness of target.",
683 c
->function
.sfunc
= set_endian
;
684 /* Don't use set_from_show - need to print both auto/manual and
686 add_cmd ("endian", class_support
, show_endian
,
687 "Show the current byte-order", &showlist
);