1 /* Dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, 1999, 2000, 2001 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"
33 #include "breakpoint.h"
43 #include "floatformat.h"
45 /* Use the program counter to determine the contents and size
46 of a breakpoint instruction. If no target-dependent macro
47 BREAKPOINT_FROM_PC has been defined to implement this function,
48 assume that the breakpoint doesn't depend on the PC, and
49 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
50 Return a pointer to a string of bytes that encode a breakpoint
51 instruction, stores the length of the string to *lenptr,
52 and optionally adjust the pc to point to the correct memory location
53 for inserting the breakpoint. */
56 legacy_breakpoint_from_pc (CORE_ADDR
* pcptr
, int *lenptr
)
58 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
59 breakpoint. On some machines, breakpoints are handled by the
60 target environment and we don't have to worry about them here. */
62 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
64 static unsigned char big_break_insn
[] = BIG_BREAKPOINT
;
65 *lenptr
= sizeof (big_break_insn
);
66 return big_break_insn
;
69 #ifdef LITTLE_BREAKPOINT
70 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
72 static unsigned char little_break_insn
[] = LITTLE_BREAKPOINT
;
73 *lenptr
= sizeof (little_break_insn
);
74 return little_break_insn
;
79 static unsigned char break_insn
[] = BREAKPOINT
;
80 *lenptr
= sizeof (break_insn
);
89 generic_frameless_function_invocation_not (struct frame_info
*fi
)
95 generic_return_value_on_stack_not (struct type
*type
)
101 legacy_register_name (int i
)
103 #ifdef REGISTER_NAMES
104 static char *names
[] = REGISTER_NAMES
;
105 if (i
< 0 || i
>= (sizeof (names
) / sizeof (*names
)))
110 internal_error (__FILE__
, __LINE__
,
111 "legacy_register_name: called.");
116 #if defined (CALL_DUMMY)
117 LONGEST legacy_call_dummy_words
[] = CALL_DUMMY
;
119 LONGEST legacy_call_dummy_words
[1];
121 int legacy_sizeof_call_dummy_words
= sizeof (legacy_call_dummy_words
);
124 generic_remote_translate_xfer_address (CORE_ADDR gdb_addr
, int gdb_len
,
125 CORE_ADDR
* rem_addr
, int *rem_len
)
127 *rem_addr
= gdb_addr
;
132 generic_prologue_frameless_p (CORE_ADDR ip
)
134 #ifdef SKIP_PROLOGUE_FRAMELESS_P
135 return ip
== SKIP_PROLOGUE_FRAMELESS_P (ip
);
137 return ip
== SKIP_PROLOGUE (ip
);
142 /* Helper functions for INNER_THAN */
145 core_addr_lessthan (CORE_ADDR lhs
, CORE_ADDR rhs
)
151 core_addr_greaterthan (CORE_ADDR lhs
, CORE_ADDR rhs
)
157 /* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */
159 const struct floatformat
*
160 default_float_format (struct gdbarch
*gdbarch
)
163 int byte_order
= gdbarch_byte_order (gdbarch
);
165 int byte_order
= TARGET_BYTE_ORDER
;
170 return &floatformat_ieee_single_big
;
172 return &floatformat_ieee_single_little
;
174 internal_error (__FILE__
, __LINE__
,
175 "default_float_format: bad byte order");
180 const struct floatformat
*
181 default_double_format (struct gdbarch
*gdbarch
)
184 int byte_order
= gdbarch_byte_order (gdbarch
);
186 int byte_order
= TARGET_BYTE_ORDER
;
191 return &floatformat_ieee_double_big
;
193 return &floatformat_ieee_double_little
;
195 internal_error (__FILE__
, __LINE__
,
196 "default_double_format: bad byte order");
200 /* Misc helper functions for targets. */
203 frame_num_args_unknown (struct frame_info
*fi
)
210 generic_register_convertible_not (int num
)
217 default_register_sim_regno (int num
)
224 default_convert_from_func_ptr_addr (CORE_ADDR addr
)
230 no_op_reg_to_regnum (int reg
)
235 /* For use by frame_args_address and frame_locals_address. */
237 default_frame_address (struct frame_info
*fi
)
242 /* Functions to manipulate the endianness of the target. */
244 #ifdef TARGET_BYTE_ORDER_SELECTABLE
245 /* compat - Catch old targets that expect a selectable byte-order to
246 default to BIG_ENDIAN */
247 #ifndef TARGET_BYTE_ORDER_DEFAULT
248 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
251 #if !TARGET_BYTE_ORDER_SELECTABLE_P
252 #ifndef TARGET_BYTE_ORDER_DEFAULT
253 /* compat - Catch old non byte-order selectable targets that do not
254 define TARGET_BYTE_ORDER_DEFAULT and instead expect
255 TARGET_BYTE_ORDER to be used as the default. For targets that
256 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
257 below will get a strange compiler warning. */
258 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
261 #ifndef TARGET_BYTE_ORDER_DEFAULT
262 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
264 /* ``target_byte_order'' is only used when non- multi-arch.
265 Multi-arch targets obtain the current byte order using
266 TARGET_BYTE_ORDER which is controlled by gdbarch.*. */
267 int target_byte_order
= TARGET_BYTE_ORDER_DEFAULT
;
268 int target_byte_order_auto
= 1;
270 static const char endian_big
[] = "big";
271 static const char endian_little
[] = "little";
272 static const char endian_auto
[] = "auto";
273 static const char *endian_enum
[] =
280 static const char *set_endian_string
;
282 /* Called by ``show endian''. */
285 show_endian (char *args
, int from_tty
)
287 if (TARGET_BYTE_ORDER_AUTO
)
288 printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n",
289 (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
291 printf_unfiltered ("The target is assumed to be %s endian\n",
292 (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
296 set_endian (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
298 if (!TARGET_BYTE_ORDER_SELECTABLE_P
)
300 printf_unfiltered ("Byte order is not selectable.");
302 else if (set_endian_string
== endian_auto
)
304 target_byte_order_auto
= 1;
306 else if (set_endian_string
== endian_little
)
308 target_byte_order_auto
= 0;
311 struct gdbarch_info info
;
312 memset (&info
, 0, sizeof info
);
313 info
.byte_order
= LITTLE_ENDIAN
;
314 if (! gdbarch_update_p (info
))
316 printf_unfiltered ("Little endian target not supported by GDB\n");
321 target_byte_order
= LITTLE_ENDIAN
;
324 else if (set_endian_string
== endian_big
)
326 target_byte_order_auto
= 0;
329 struct gdbarch_info info
;
330 memset (&info
, 0, sizeof info
);
331 info
.byte_order
= BIG_ENDIAN
;
332 if (! gdbarch_update_p (info
))
334 printf_unfiltered ("Big endian target not supported by GDB\n");
339 target_byte_order
= BIG_ENDIAN
;
343 internal_error (__FILE__
, __LINE__
,
344 "set_endian: bad value");
345 show_endian (NULL
, from_tty
);
348 /* Set the endianness from a BFD. */
351 set_endian_from_file (bfd
*abfd
)
354 internal_error (__FILE__
, __LINE__
,
355 "set_endian_from_file: not for multi-arch");
356 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
360 if (bfd_big_endian (abfd
))
363 want
= LITTLE_ENDIAN
;
364 if (TARGET_BYTE_ORDER_AUTO
)
365 target_byte_order
= want
;
366 else if (TARGET_BYTE_ORDER
!= want
)
367 warning ("%s endian file does not match %s endian target.",
368 want
== BIG_ENDIAN
? "big" : "little",
369 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
373 if (bfd_big_endian (abfd
)
374 ? TARGET_BYTE_ORDER
!= BIG_ENDIAN
375 : TARGET_BYTE_ORDER
== BIG_ENDIAN
)
376 warning ("%s endian file does not match %s endian target.",
377 bfd_big_endian (abfd
) ? "big" : "little",
378 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
383 /* Functions to manipulate the architecture of the target */
385 enum set_arch
{ set_arch_auto
, set_arch_manual
};
387 int target_architecture_auto
= 1;
389 const char *set_architecture_string
;
391 /* Old way of changing the current architecture. */
393 extern const struct bfd_arch_info bfd_default_arch_struct
;
394 const struct bfd_arch_info
*target_architecture
= &bfd_default_arch_struct
;
395 int (*target_architecture_hook
) (const struct bfd_arch_info
*ap
);
398 arch_ok (const struct bfd_arch_info
*arch
)
401 internal_error (__FILE__
, __LINE__
,
402 "arch_ok: not multi-arched");
403 /* Should be performing the more basic check that the binary is
404 compatible with GDB. */
405 /* Check with the target that the architecture is valid. */
406 return (target_architecture_hook
== NULL
407 || target_architecture_hook (arch
));
411 set_arch (const struct bfd_arch_info
*arch
,
415 internal_error (__FILE__
, __LINE__
,
416 "set_arch: not multi-arched");
421 warning ("Target may not support %s architecture",
422 arch
->printable_name
);
423 target_architecture
= arch
;
425 case set_arch_manual
:
428 printf_unfiltered ("Target does not support `%s' architecture.\n",
429 arch
->printable_name
);
433 target_architecture_auto
= 0;
434 target_architecture
= arch
;
439 gdbarch_dump (current_gdbarch
, gdb_stdlog
);
442 /* Set the architecture from arch/machine (deprecated) */
445 set_architecture_from_arch_mach (enum bfd_architecture arch
,
448 const struct bfd_arch_info
*wanted
= bfd_lookup_arch (arch
, mach
);
450 internal_error (__FILE__
, __LINE__
,
451 "set_architecture_from_arch_mach: not multi-arched");
453 set_arch (wanted
, set_arch_manual
);
455 internal_error (__FILE__
, __LINE__
,
456 "gdbarch: hardwired architecture/machine not recognized");
459 /* Set the architecture from a BFD (deprecated) */
462 set_architecture_from_file (bfd
*abfd
)
464 const struct bfd_arch_info
*wanted
= bfd_get_arch_info (abfd
);
466 internal_error (__FILE__
, __LINE__
,
467 "set_architecture_from_file: not multi-arched");
468 if (target_architecture_auto
)
470 set_arch (wanted
, set_arch_auto
);
472 else if (wanted
!= target_architecture
)
474 warning ("%s architecture file may be incompatible with %s target.",
475 wanted
->printable_name
,
476 target_architecture
->printable_name
);
481 /* Called if the user enters ``show architecture'' without an
485 show_architecture (char *args
, int from_tty
)
488 arch
= TARGET_ARCHITECTURE
->printable_name
;
489 if (target_architecture_auto
)
490 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch
);
492 printf_filtered ("The target architecture is assumed to be %s\n", arch
);
496 /* Called if the user enters ``set architecture'' with or without an
500 set_architecture (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
502 if (strcmp (set_architecture_string
, "auto") == 0)
504 target_architecture_auto
= 1;
506 else if (GDB_MULTI_ARCH
)
508 struct gdbarch_info info
;
509 memset (&info
, 0, sizeof info
);
510 info
.bfd_arch_info
= bfd_scan_arch (set_architecture_string
);
511 if (info
.bfd_arch_info
== NULL
)
512 internal_error (__FILE__
, __LINE__
,
513 "set_architecture: bfd_scan_arch failed");
514 if (gdbarch_update_p (info
))
515 target_architecture_auto
= 0;
517 printf_unfiltered ("Architecture `%s' not recognized.\n",
518 set_architecture_string
);
522 const struct bfd_arch_info
*arch
523 = bfd_scan_arch (set_architecture_string
);
525 internal_error (__FILE__
, __LINE__
,
526 "set_architecture: bfd_scan_arch failed");
527 set_arch (arch
, set_arch_manual
);
529 show_architecture (NULL
, from_tty
);
532 /* Called if the user enters ``info architecture'' without an argument. */
535 info_architecture (char *args
, int from_tty
)
537 printf_filtered ("Available architectures are:\n");
540 const char **arches
= gdbarch_printable_names ();
542 for (arch
= arches
; *arch
!= NULL
; arch
++)
544 printf_filtered (" %s", *arch
);
550 enum bfd_architecture a
;
551 for (a
= bfd_arch_obscure
+ 1; a
< bfd_arch_last
; a
++)
553 const struct bfd_arch_info
*ap
;
554 for (ap
= bfd_lookup_arch (a
, 0);
558 printf_filtered (" %s", ap
->printable_name
);
563 printf_filtered ("\n");
566 /* Set the dynamic target-system-dependent parameters (architecture,
567 byte-order) using information found in the BFD */
570 set_gdbarch_from_file (bfd
*abfd
)
574 struct gdbarch_info info
;
575 memset (&info
, 0, sizeof info
);
577 if (! gdbarch_update_p (info
))
578 error ("Architecture of file not recognized.\n");
582 set_architecture_from_file (abfd
);
583 set_endian_from_file (abfd
);
587 /* Initialize the current architecture. Update the ``set
588 architecture'' command so that it specifies a list of valid
591 #ifdef DEFAULT_BFD_ARCH
592 extern const bfd_arch_info_type DEFAULT_BFD_ARCH
;
593 static const bfd_arch_info_type
*default_bfd_arch
= &DEFAULT_BFD_ARCH
;
595 static const bfd_arch_info_type
*default_bfd_arch
;
598 #ifdef DEFAULT_BFD_VEC
599 extern const bfd_target DEFAULT_BFD_VEC
;
600 static const bfd_target
*default_bfd_vec
= &DEFAULT_BFD_VEC
;
602 static const bfd_target
*default_bfd_vec
;
606 initialize_current_architecture (void)
608 const char **arches
= gdbarch_printable_names ();
610 /* determine a default architecture and byte order. */
611 struct gdbarch_info info
;
612 memset (&info
, 0, sizeof (info
));
614 /* Find a default architecture. */
615 if (info
.bfd_arch_info
== NULL
616 && default_bfd_arch
!= NULL
)
617 info
.bfd_arch_info
= default_bfd_arch
;
618 if (info
.bfd_arch_info
== NULL
)
620 /* Choose the architecture by taking the first one
622 const char *chosen
= arches
[0];
624 for (arch
= arches
; *arch
!= NULL
; arch
++)
626 if (strcmp (*arch
, chosen
) < 0)
630 internal_error (__FILE__
, __LINE__
,
631 "initialize_current_architecture: No arch");
632 info
.bfd_arch_info
= bfd_scan_arch (chosen
);
633 if (info
.bfd_arch_info
== NULL
)
634 internal_error (__FILE__
, __LINE__
,
635 "initialize_current_architecture: Arch not found");
638 /* take several guesses at a byte order. */
639 /* NB: can't use TARGET_BYTE_ORDER_DEFAULT as its definition is
641 if (info
.byte_order
== 0
642 && default_bfd_vec
!= NULL
)
644 /* Extract BFD's default vector's byte order. */
645 switch (default_bfd_vec
->byteorder
)
648 info
.byte_order
= BIG_ENDIAN
;
650 case BFD_ENDIAN_LITTLE
:
651 info
.byte_order
= LITTLE_ENDIAN
;
657 if (info
.byte_order
== 0)
659 /* look for ``*el-*'' in the target name. */
661 chp
= strchr (target_name
, '-');
663 && chp
- 2 >= target_name
664 && strncmp (chp
- 2, "el", 2) == 0)
665 info
.byte_order
= LITTLE_ENDIAN
;
667 if (info
.byte_order
== 0)
669 /* Wire it to big-endian!!! */
670 info
.byte_order
= BIG_ENDIAN
;
675 if (! gdbarch_update_p (info
))
677 internal_error (__FILE__
, __LINE__
,
678 "initialize_current_architecture: Selection of initial architecture failed");
682 /* Create the ``set architecture'' command appending ``auto'' to the
683 list of architectures. */
685 struct cmd_list_element
*c
;
686 /* Append ``auto''. */
688 for (nr
= 0; arches
[nr
] != NULL
; nr
++);
689 arches
= xrealloc (arches
, sizeof (char*) * (nr
+ 2));
690 arches
[nr
+ 0] = "auto";
691 arches
[nr
+ 1] = NULL
;
692 /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead
693 of ``const char *''. We just happen to know that the casts are
695 c
= add_set_enum_cmd ("architecture", class_support
,
696 arches
, &set_architecture_string
,
697 "Set architecture of target.",
699 c
->function
.sfunc
= set_architecture
;
700 add_alias_cmd ("processor", "architecture", class_support
, 1, &setlist
);
701 /* Don't use set_from_show - need to print both auto/manual and
703 add_cmd ("architecture", class_support
, show_architecture
,
704 "Show the current target architecture", &showlist
);
705 c
= add_cmd ("architecture", class_support
, info_architecture
,
706 "List supported target architectures", &infolist
);
707 deprecate_cmd (c
, "set architecture");
714 extern initialize_file_ftype _initialize_gdbarch_utils
;
717 _initialize_gdbarch_utils (void)
719 struct cmd_list_element
*c
;
720 c
= add_set_enum_cmd ("endian", class_support
,
721 endian_enum
, &set_endian_string
,
722 "Set endianness of target.",
724 c
->function
.sfunc
= set_endian
;
725 /* Don't use set_from_show - need to print both auto/manual and
727 add_cmd ("endian", class_support
, show_endian
,
728 "Show the current byte-order", &showlist
);