* gdbtypes.c (build_gdbtypes): New function.
[deliverable/binutils-gdb.git] / gdb / gdbarch.c
CommitLineData
f7e85b1b
AC
1/* Semi-dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "bfd.h"
22#include "gdbcmd.h"
23
24
5036d102
AC
25/* Non-zero if we want to trace architecture code. */
26
27#ifndef GDBARCH_DEBUG
28#define GDBARCH_DEBUG 1
29#endif
30int gdbarch_debug = GDBARCH_DEBUG;
31
32
f7e85b1b
AC
33/* Functions to manipulate the endianness of the target. */
34
35#ifdef TARGET_BYTE_ORDER_SELECTABLE
36/* compat - Catch old targets that expect a selectable byte-order to
37 default to BIG_ENDIAN */
38#ifndef TARGET_BYTE_ORDER_DEFAULT
39#define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
40#endif
41#endif
42#ifndef TARGET_BYTE_ORDER_DEFAULT
43/* compat - Catch old non byte-order selectable targets that do not
44 define TARGET_BYTE_ORDER_DEFAULT and instead expect
45 TARGET_BYTE_ORDER to be used as the default. For targets that
46 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
47 below will get a strange compiler warning. */
48#define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
49#endif
50int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
51int target_byte_order_auto = 1;
52
53/* Chain containing the \"set endian\" commands. */
54static struct cmd_list_element *endianlist = NULL;
55
56/* Called by ``show endian''. */
57static void show_endian PARAMS ((char *, int));
58static void
59show_endian (args, from_tty)
60 char *args;
61 int from_tty;
62{
63 char *msg =
64 (TARGET_BYTE_ORDER_AUTO
65 ? "The target endianness is set automatically (currently %s endian)\n"
66 : "The target is assumed to be %s endian\n");
67 printf_unfiltered (msg, (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
68}
69
70/* Called if the user enters ``set endian'' without an argument. */
71static void set_endian PARAMS ((char *, int));
72static void
73set_endian (args, from_tty)
74 char *args;
75 int from_tty;
76{
77 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
78 show_endian (args, from_tty);
79}
80
81/* Called by ``set endian big''. */
82static void set_endian_big PARAMS ((char *, int));
83static void
84set_endian_big (args, from_tty)
85 char *args;
86 int from_tty;
87{
88 if (TARGET_BYTE_ORDER_SELECTABLE_P)
89 {
90 target_byte_order = BIG_ENDIAN;
91 target_byte_order_auto = 0;
92 }
93 else
94 {
95 printf_unfiltered ("Byte order is not selectable.");
96 show_endian (args, from_tty);
97 }
98}
99
100/* Called by ``set endian little''. */
101static void set_endian_little PARAMS ((char *, int));
102static void
103set_endian_little (args, from_tty)
104 char *args;
105 int from_tty;
106{
107 if (TARGET_BYTE_ORDER_SELECTABLE_P)
108 {
109 target_byte_order = LITTLE_ENDIAN;
110 target_byte_order_auto = 0;
111 }
112 else
113 {
114 printf_unfiltered ("Byte order is not selectable.");
115 show_endian (args, from_tty);
116 }
117}
118
119/* Called by ``set endian auto''. */
120static void set_endian_auto PARAMS ((char *, int));
121static void
122set_endian_auto (args, from_tty)
123 char *args;
124 int from_tty;
125{
126 if (TARGET_BYTE_ORDER_SELECTABLE_P)
127 {
128 target_byte_order_auto = 1;
129 }
130 else
131 {
132 printf_unfiltered ("Byte order is not selectable.");
133 show_endian (args, from_tty);
134 }
135}
136
137/* Set the endianness from a BFD. */
138static void set_endian_from_file PARAMS ((bfd *));
139static void
140set_endian_from_file (abfd)
141 bfd *abfd;
142{
143 if (TARGET_BYTE_ORDER_SELECTABLE_P)
144 {
145 int want;
146
147 if (bfd_big_endian (abfd))
148 want = BIG_ENDIAN;
149 else
150 want = LITTLE_ENDIAN;
151 if (TARGET_BYTE_ORDER_AUTO)
152 target_byte_order = want;
153 else if (TARGET_BYTE_ORDER != want)
154 warning ("%s endian file does not match %s endian target.",
155 want == BIG_ENDIAN ? "big" : "little",
156 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
157 }
158 else
159 {
160 if (bfd_big_endian (abfd)
161 ? TARGET_BYTE_ORDER != BIG_ENDIAN
162 : TARGET_BYTE_ORDER == BIG_ENDIAN)
163 warning ("%s endian file does not match %s endian target.",
164 bfd_big_endian (abfd) ? "big" : "little",
165 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
166 }
167}
168
169
170
171/* Functions to manipulate the architecture of the target */
172
173int target_architecture_auto = 1;
5036d102
AC
174extern const struct bfd_arch_info bfd_default_arch_struct;
175const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
176int (*target_architecture_hook) PARAMS ((const struct bfd_arch_info *ap));
f7e85b1b
AC
177
178/* Do the real work of changing the current architecture */
179static void
180set_arch (arch)
5036d102 181 const struct bfd_arch_info *arch;
f7e85b1b
AC
182{
183 /* FIXME: Is it compatible with gdb? */
184 /* Check with the target on the setting */
185 if (target_architecture_hook != NULL
186 && !target_architecture_hook (arch))
187 printf_unfiltered ("Target does not support `%s' architecture.\n",
188 arch->printable_name);
189 else
190 {
191 target_architecture_auto = 0;
192 target_architecture = arch;
193 }
194}
195
196/* Called if the user enters ``show architecture'' without an argument. */
197static void show_architecture PARAMS ((char *, int));
198static void
199show_architecture (args, from_tty)
200 char *args;
201 int from_tty;
202{
203 const char *arch;
5036d102 204 arch = TARGET_ARCHITECTURE->printable_name;
f7e85b1b
AC
205 if (target_architecture_auto)
206 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
207 else
208 printf_filtered ("The target architecture is assumed to be %s\n", arch);
209}
210
211/* Called if the user enters ``set architecture'' with or without an
212 argument. */
213static void set_architecture PARAMS ((char *, int));
214static void
215set_architecture (args, from_tty)
216 char *args;
217 int from_tty;
218{
219 if (args == NULL)
220 {
221 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
222 }
223 else if (strcmp (args, "auto") == 0)
224 {
225 target_architecture_auto = 1;
226 }
227 else
228 {
5036d102 229 const struct bfd_arch_info *arch = bfd_scan_arch (args);
f7e85b1b
AC
230 if (arch != NULL)
231 set_arch (arch);
232 else
233 printf_unfiltered ("Architecture `%s' not reconized.\n", args);
234 }
235}
236
237/* Called if the user enters ``info architecture'' without an argument. */
238static void info_architecture PARAMS ((char *, int));
239static void
240info_architecture (args, from_tty)
241 char *args;
242 int from_tty;
243{
244 enum bfd_architecture a;
245 printf_filtered ("Available architectures are:\n");
246 for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
247 {
5036d102 248 const struct bfd_arch_info *ap = bfd_lookup_arch (a, 0);
f7e85b1b
AC
249 if (ap != NULL)
250 {
251 do
252 {
253 printf_filtered (" %s", ap->printable_name);
254 ap = ap->next;
255 }
256 while (ap != NULL);
257 printf_filtered ("\n");
258 }
259 }
260}
261
262/* Set the architecture from arch/machine */
263void
264set_architecture_from_arch_mach (arch, mach)
265 enum bfd_architecture arch;
266 unsigned long mach;
267{
5036d102 268 const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
f7e85b1b
AC
269 if (wanted != NULL)
270 set_arch (wanted);
271 else
272 fatal ("hardwired architecture/machine not reconized");
273}
274
275/* Set the architecture from a BFD */
276static void set_architecture_from_file PARAMS ((bfd *));
277static void
278set_architecture_from_file (abfd)
279 bfd *abfd;
280{
5036d102 281 const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
f7e85b1b
AC
282 if (target_architecture_auto)
283 {
284 if (target_architecture_hook != NULL
285 && !target_architecture_hook (wanted))
286 warning ("Target may not support %s architecture",
287 wanted->printable_name);
288 target_architecture = wanted;
289 }
290 else if (wanted != target_architecture)
291 {
292 warning ("%s architecture file may be incompatible with %s target.",
293 wanted->printable_name,
294 target_architecture->printable_name);
295 }
296}
297
298
299
300/* Disassembler */
301
302/* Pointer to the target-dependent disassembly function. */
303int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
304disassemble_info tm_print_insn_info;
305
306
307
308/* Set the dynamic target-system-dependant parameters (architecture,
309 byte-order) using information found in the BFD */
310
311void
312set_gdbarch_from_file (abfd)
313 bfd *abfd;
314{
315 set_architecture_from_file (abfd);
316 set_endian_from_file (abfd);
317}
318
319
320extern void _initialize_gdbarch PARAMS ((void));
321void
322_initialize_gdbarch ()
323{
324 add_prefix_cmd ("endian", class_support, set_endian,
325 "Set endianness of target.",
326 &endianlist, "set endian ", 0, &setlist);
327 add_cmd ("big", class_support, set_endian_big,
328 "Set target as being big endian.", &endianlist);
329 add_cmd ("little", class_support, set_endian_little,
330 "Set target as being little endian.", &endianlist);
331 add_cmd ("auto", class_support, set_endian_auto,
332 "Select target endianness automatically.", &endianlist);
333 add_cmd ("endian", class_support, show_endian,
334 "Show endianness of target.", &showlist);
335
336 add_cmd ("architecture", class_support, set_architecture,
337 "Set architecture of target.", &setlist);
338 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
339 add_cmd ("architecture", class_support, show_architecture,
340 "Show architecture of target.", &showlist);
341 add_cmd ("architecture", class_support, info_architecture,
342 "List supported target architectures", &infolist);
343
344 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
345 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
346 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
347 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
348 tm_print_insn_info.print_address_func = dis_asm_print_address;
5036d102
AC
349
350#ifdef MAINTENANCE_CMDS
351 add_show_from_set (add_set_cmd ("archdebug",
352 class_maintenance,
353 var_zinteger,
354 (char *)&gdbarch_debug,
355 "Set architecture debugging.\n\
356When non-zero, architecture debugging is enabled.", &setlist),
357 &showlist);
358#endif
f7e85b1b 359}
This page took 0.036023 seconds and 4 git commands to generate.