Commit | Line | Data |
---|---|---|
c0e8c252 AC |
1 | /* Dynamic architecture support for GDB, the GNU debugger. |
2 | Copyright 1998-1999, Free Software Foundation, Inc. | |
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" | |
30 | #include <ctype.h> | |
31 | #include "symtab.h" | |
32 | #include "frame.h" | |
33 | #include "inferior.h" | |
34 | #include "breakpoint.h" | |
35 | #include "gdb_wait.h" | |
36 | #include "gdbcore.h" | |
37 | #include "gdbcmd.h" | |
38 | #include "target.h" | |
39 | #include "gdbthread.h" | |
40 | #include "annotate.h" | |
41 | #include "symfile.h" /* for overlay functions */ | |
42 | #endif | |
43 | ||
1ba607ad AC |
44 | #include "version.h" |
45 | ||
f0d4cc9e AC |
46 | #include "floatformat.h" |
47 | ||
c0e8c252 AC |
48 | /* Convenience macro for allocting typesafe memory. */ |
49 | ||
50 | #ifndef XMALLOC | |
51 | #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE)) | |
52 | #endif | |
53 | ||
54 | ||
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. */ | |
64 | ||
65 | unsigned char * | |
66 | legacy_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr) | |
67 | { | |
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. */ | |
71 | #ifdef BIG_BREAKPOINT | |
72 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
73 | { | |
74 | static unsigned char big_break_insn[] = BIG_BREAKPOINT; | |
75 | *lenptr = sizeof (big_break_insn); | |
76 | return big_break_insn; | |
77 | } | |
78 | #endif | |
79 | #ifdef LITTLE_BREAKPOINT | |
80 | if (TARGET_BYTE_ORDER != BIG_ENDIAN) | |
81 | { | |
82 | static unsigned char little_break_insn[] = LITTLE_BREAKPOINT; | |
83 | *lenptr = sizeof (little_break_insn); | |
84 | return little_break_insn; | |
85 | } | |
86 | #endif | |
87 | #ifdef BREAKPOINT | |
88 | { | |
89 | static unsigned char break_insn[] = BREAKPOINT; | |
90 | *lenptr = sizeof (break_insn); | |
91 | return break_insn; | |
92 | } | |
93 | #endif | |
94 | *lenptr = 0; | |
95 | return NULL; | |
96 | } | |
97 | ||
98 | int | |
99 | generic_frameless_function_invocation_not (struct frame_info *fi) | |
100 | { | |
101 | return 0; | |
102 | } | |
103 | ||
71a9f22e JB |
104 | int |
105 | generic_return_value_on_stack_not (struct type *type) | |
106 | { | |
107 | return 0; | |
108 | } | |
109 | ||
c0e8c252 AC |
110 | char * |
111 | legacy_register_name (int i) | |
112 | { | |
113 | #ifdef REGISTER_NAMES | |
114 | static char *names[] = REGISTER_NAMES; | |
115 | if (i < 0 || i >= (sizeof (names) / sizeof (*names))) | |
116 | return NULL; | |
117 | else | |
118 | return names[i]; | |
119 | #else | |
120 | internal_error ("legacy_register_name: called."); | |
121 | return NULL; | |
122 | #endif | |
123 | } | |
124 | ||
125 | #if defined (CALL_DUMMY) | |
126 | LONGEST legacy_call_dummy_words[] = CALL_DUMMY; | |
127 | #else | |
128 | LONGEST legacy_call_dummy_words[1]; | |
129 | #endif | |
130 | int legacy_sizeof_call_dummy_words = sizeof (legacy_call_dummy_words); | |
131 | ||
132 | void | |
133 | generic_remote_translate_xfer_address (CORE_ADDR gdb_addr, int gdb_len, | |
134 | CORE_ADDR * rem_addr, int *rem_len) | |
135 | { | |
136 | *rem_addr = gdb_addr; | |
137 | *rem_len = gdb_len; | |
138 | } | |
139 | ||
dad41f9a AC |
140 | int |
141 | generic_prologue_frameless_p (CORE_ADDR ip) | |
142 | { | |
143 | #ifdef SKIP_PROLOGUE_FRAMELESS_P | |
144 | return ip == SKIP_PROLOGUE_FRAMELESS_P (ip); | |
145 | #else | |
146 | return ip == SKIP_PROLOGUE (ip); | |
147 | #endif | |
148 | } | |
149 | ||
150 | ||
3339cf8b AC |
151 | /* Helper functions for INNER_THAN */ |
152 | ||
153 | int | |
fba45db2 | 154 | core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs) |
3339cf8b AC |
155 | { |
156 | return (lhs < rhs); | |
157 | } | |
158 | ||
159 | int | |
fba45db2 | 160 | core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs) |
3339cf8b AC |
161 | { |
162 | return (lhs > rhs); | |
163 | } | |
164 | ||
165 | ||
f0d4cc9e AC |
166 | /* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */ |
167 | ||
168 | const struct floatformat * | |
169 | default_float_format (struct gdbarch *gdbarch) | |
170 | { | |
171 | #if GDB_MULTI_ARCH | |
172 | int byte_order = gdbarch_byte_order (gdbarch); | |
173 | #else | |
174 | int byte_order = TARGET_BYTE_ORDER; | |
175 | #endif | |
176 | switch (byte_order) | |
177 | { | |
178 | case BIG_ENDIAN: | |
179 | return &floatformat_ieee_single_big; | |
180 | case LITTLE_ENDIAN: | |
181 | return &floatformat_ieee_single_little; | |
182 | default: | |
183 | internal_error ("default_float_format: bad byte order"); | |
184 | } | |
185 | } | |
186 | ||
187 | ||
188 | const struct floatformat * | |
189 | default_double_format (struct gdbarch *gdbarch) | |
190 | { | |
191 | #if GDB_MULTI_ARCH | |
192 | int byte_order = gdbarch_byte_order (gdbarch); | |
193 | #else | |
194 | int byte_order = TARGET_BYTE_ORDER; | |
195 | #endif | |
196 | switch (byte_order) | |
197 | { | |
198 | case BIG_ENDIAN: | |
199 | return &floatformat_ieee_double_big; | |
200 | case LITTLE_ENDIAN: | |
201 | return &floatformat_ieee_double_little; | |
202 | default: | |
203 | internal_error ("default_double_format: bad byte order"); | |
204 | } | |
205 | } | |
206 | ||
193e3b1a AC |
207 | /* Misc helper functions for targets. */ |
208 | ||
209 | int | |
fba45db2 | 210 | frame_num_args_unknown (struct frame_info *fi) |
193e3b1a AC |
211 | { |
212 | return -1; | |
213 | } | |
214 | ||
215 | ||
216 | int | |
fba45db2 | 217 | generic_register_convertible_not (int num) |
193e3b1a AC |
218 | { |
219 | return 0; | |
220 | } | |
221 | ||
b4a20239 | 222 | |
7c7651b2 AC |
223 | int |
224 | default_register_sim_regno (int num) | |
225 | { | |
226 | return num; | |
227 | } | |
228 | ||
f517ea4e PS |
229 | |
230 | CORE_ADDR | |
231 | default_convert_from_func_ptr_addr (CORE_ADDR addr) | |
232 | { | |
233 | return addr; | |
234 | } | |
235 | ||
b4a20239 AC |
236 | /* Functions to manipulate the endianness of the target. */ |
237 | ||
238 | #ifdef TARGET_BYTE_ORDER_SELECTABLE | |
239 | /* compat - Catch old targets that expect a selectable byte-order to | |
240 | default to BIG_ENDIAN */ | |
241 | #ifndef TARGET_BYTE_ORDER_DEFAULT | |
242 | #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN | |
243 | #endif | |
244 | #endif | |
245 | #if !TARGET_BYTE_ORDER_SELECTABLE_P | |
246 | #ifndef TARGET_BYTE_ORDER_DEFAULT | |
247 | /* compat - Catch old non byte-order selectable targets that do not | |
248 | define TARGET_BYTE_ORDER_DEFAULT and instead expect | |
249 | TARGET_BYTE_ORDER to be used as the default. For targets that | |
250 | defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the | |
251 | below will get a strange compiler warning. */ | |
252 | #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER | |
253 | #endif | |
254 | #endif | |
255 | #ifndef TARGET_BYTE_ORDER_DEFAULT | |
256 | #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */ | |
257 | #endif | |
1ba607ad AC |
258 | /* ``target_byte_order'' is only used when non- multi-arch. |
259 | Multi-arch targets obtain the current byte order using | |
260 | TARGET_BYTE_ORDER which is controlled by gdbarch.*. */ | |
b4a20239 AC |
261 | int target_byte_order = TARGET_BYTE_ORDER_DEFAULT; |
262 | int target_byte_order_auto = 1; | |
263 | ||
53904c9e AC |
264 | static const char endian_big[] = "big"; |
265 | static const char endian_little[] = "little"; | |
266 | static const char endian_auto[] = "auto"; | |
267 | static const char *endian_enum[] = | |
b4a20239 AC |
268 | { |
269 | endian_big, | |
270 | endian_little, | |
271 | endian_auto, | |
272 | NULL, | |
273 | }; | |
53904c9e | 274 | static const char *set_endian_string; |
b4a20239 AC |
275 | |
276 | /* Called by ``show endian''. */ | |
277 | ||
278 | static void | |
279 | show_endian (char *args, int from_tty) | |
280 | { | |
281 | if (TARGET_BYTE_ORDER_AUTO) | |
282 | printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n", | |
283 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little")); | |
284 | else | |
285 | printf_unfiltered ("The target is assumed to be %s endian\n", | |
286 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little")); | |
287 | } | |
288 | ||
289 | static void | |
290 | set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c) | |
291 | { | |
292 | if (!TARGET_BYTE_ORDER_SELECTABLE_P) | |
293 | { | |
294 | printf_unfiltered ("Byte order is not selectable."); | |
295 | } | |
296 | else if (set_endian_string == endian_auto) | |
297 | { | |
298 | target_byte_order_auto = 1; | |
299 | } | |
300 | else if (set_endian_string == endian_little) | |
301 | { | |
b4a20239 AC |
302 | target_byte_order_auto = 0; |
303 | if (GDB_MULTI_ARCH) | |
304 | { | |
305 | struct gdbarch_info info; | |
306 | memset (&info, 0, sizeof info); | |
307 | info.byte_order = LITTLE_ENDIAN; | |
16f33e29 AC |
308 | if (! gdbarch_update_p (info)) |
309 | { | |
310 | printf_unfiltered ("Little endian target not supported by GDB\n"); | |
311 | } | |
b4a20239 | 312 | } |
1ba607ad AC |
313 | else |
314 | { | |
315 | target_byte_order = LITTLE_ENDIAN; | |
316 | } | |
b4a20239 AC |
317 | } |
318 | else if (set_endian_string == endian_big) | |
319 | { | |
b4a20239 AC |
320 | target_byte_order_auto = 0; |
321 | if (GDB_MULTI_ARCH) | |
322 | { | |
323 | struct gdbarch_info info; | |
324 | memset (&info, 0, sizeof info); | |
325 | info.byte_order = BIG_ENDIAN; | |
16f33e29 AC |
326 | if (! gdbarch_update_p (info)) |
327 | { | |
328 | printf_unfiltered ("Big endian target not supported by GDB\n"); | |
329 | } | |
b4a20239 | 330 | } |
1ba607ad AC |
331 | else |
332 | { | |
333 | target_byte_order = BIG_ENDIAN; | |
334 | } | |
b4a20239 AC |
335 | } |
336 | else | |
337 | internal_error ("set_endian: bad value"); | |
338 | show_endian (NULL, from_tty); | |
339 | } | |
340 | ||
341 | /* Set the endianness from a BFD. */ | |
342 | ||
343 | static void | |
344 | set_endian_from_file (bfd *abfd) | |
345 | { | |
1ba607ad AC |
346 | if (GDB_MULTI_ARCH) |
347 | internal_error ("set_endian_from_file: not for multi-arch"); | |
b4a20239 AC |
348 | if (TARGET_BYTE_ORDER_SELECTABLE_P) |
349 | { | |
350 | int want; | |
351 | ||
352 | if (bfd_big_endian (abfd)) | |
353 | want = BIG_ENDIAN; | |
354 | else | |
355 | want = LITTLE_ENDIAN; | |
356 | if (TARGET_BYTE_ORDER_AUTO) | |
357 | target_byte_order = want; | |
358 | else if (TARGET_BYTE_ORDER != want) | |
359 | warning ("%s endian file does not match %s endian target.", | |
360 | want == BIG_ENDIAN ? "big" : "little", | |
361 | TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"); | |
362 | } | |
363 | else | |
364 | { | |
365 | if (bfd_big_endian (abfd) | |
366 | ? TARGET_BYTE_ORDER != BIG_ENDIAN | |
367 | : TARGET_BYTE_ORDER == BIG_ENDIAN) | |
368 | warning ("%s endian file does not match %s endian target.", | |
369 | bfd_big_endian (abfd) ? "big" : "little", | |
370 | TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"); | |
371 | } | |
372 | } | |
373 | ||
374 | ||
375 | /* Functions to manipulate the architecture of the target */ | |
376 | ||
377 | enum set_arch { set_arch_auto, set_arch_manual }; | |
378 | ||
379 | int target_architecture_auto = 1; | |
380 | ||
53904c9e | 381 | const char *set_architecture_string; |
b4a20239 AC |
382 | |
383 | /* Old way of changing the current architecture. */ | |
384 | ||
385 | extern const struct bfd_arch_info bfd_default_arch_struct; | |
386 | const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct; | |
387 | int (*target_architecture_hook) (const struct bfd_arch_info *ap); | |
388 | ||
389 | static int | |
390 | arch_ok (const struct bfd_arch_info *arch) | |
391 | { | |
392 | if (GDB_MULTI_ARCH) | |
393 | internal_error ("arch_ok: not multi-arched"); | |
394 | /* Should be performing the more basic check that the binary is | |
395 | compatible with GDB. */ | |
396 | /* Check with the target that the architecture is valid. */ | |
397 | return (target_architecture_hook == NULL | |
398 | || target_architecture_hook (arch)); | |
399 | } | |
400 | ||
401 | static void | |
402 | set_arch (const struct bfd_arch_info *arch, | |
403 | enum set_arch type) | |
404 | { | |
405 | if (GDB_MULTI_ARCH) | |
406 | internal_error ("set_arch: not multi-arched"); | |
407 | switch (type) | |
408 | { | |
409 | case set_arch_auto: | |
410 | if (!arch_ok (arch)) | |
411 | warning ("Target may not support %s architecture", | |
412 | arch->printable_name); | |
413 | target_architecture = arch; | |
414 | break; | |
415 | case set_arch_manual: | |
416 | if (!arch_ok (arch)) | |
417 | { | |
418 | printf_unfiltered ("Target does not support `%s' architecture.\n", | |
419 | arch->printable_name); | |
420 | } | |
421 | else | |
422 | { | |
423 | target_architecture_auto = 0; | |
424 | target_architecture = arch; | |
425 | } | |
426 | break; | |
427 | } | |
428 | if (gdbarch_debug) | |
4b9b3959 | 429 | gdbarch_dump (current_gdbarch, gdb_stdlog); |
b4a20239 AC |
430 | } |
431 | ||
432 | /* Set the architecture from arch/machine (deprecated) */ | |
433 | ||
434 | void | |
435 | set_architecture_from_arch_mach (enum bfd_architecture arch, | |
436 | unsigned long mach) | |
437 | { | |
438 | const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach); | |
439 | if (GDB_MULTI_ARCH) | |
440 | internal_error ("set_architecture_from_arch_mach: not multi-arched"); | |
441 | if (wanted != NULL) | |
442 | set_arch (wanted, set_arch_manual); | |
443 | else | |
ec3d358c | 444 | internal_error ("gdbarch: hardwired architecture/machine not recognized"); |
b4a20239 AC |
445 | } |
446 | ||
447 | /* Set the architecture from a BFD (deprecated) */ | |
448 | ||
449 | static void | |
450 | set_architecture_from_file (bfd *abfd) | |
451 | { | |
452 | const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd); | |
453 | if (GDB_MULTI_ARCH) | |
454 | internal_error ("set_architecture_from_file: not multi-arched"); | |
455 | if (target_architecture_auto) | |
456 | { | |
457 | set_arch (wanted, set_arch_auto); | |
458 | } | |
459 | else if (wanted != target_architecture) | |
460 | { | |
461 | warning ("%s architecture file may be incompatible with %s target.", | |
462 | wanted->printable_name, | |
463 | target_architecture->printable_name); | |
464 | } | |
465 | } | |
466 | ||
467 | ||
468 | /* Called if the user enters ``show architecture'' without an | |
469 | argument. */ | |
470 | ||
471 | static void | |
472 | show_architecture (char *args, int from_tty) | |
473 | { | |
474 | const char *arch; | |
475 | arch = TARGET_ARCHITECTURE->printable_name; | |
476 | if (target_architecture_auto) | |
477 | printf_filtered ("The target architecture is set automatically (currently %s)\n", arch); | |
478 | else | |
479 | printf_filtered ("The target architecture is assumed to be %s\n", arch); | |
480 | } | |
481 | ||
482 | ||
483 | /* Called if the user enters ``set architecture'' with or without an | |
484 | argument. */ | |
485 | ||
486 | static void | |
487 | set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c) | |
488 | { | |
489 | if (strcmp (set_architecture_string, "auto") == 0) | |
490 | { | |
491 | target_architecture_auto = 1; | |
492 | } | |
493 | else if (GDB_MULTI_ARCH) | |
494 | { | |
495 | struct gdbarch_info info; | |
496 | memset (&info, 0, sizeof info); | |
497 | info.bfd_arch_info = bfd_scan_arch (set_architecture_string); | |
498 | if (info.bfd_arch_info == NULL) | |
499 | internal_error ("set_architecture: bfd_scan_arch failed"); | |
16f33e29 | 500 | if (gdbarch_update_p (info)) |
b4a20239 AC |
501 | target_architecture_auto = 0; |
502 | else | |
ec3d358c | 503 | printf_unfiltered ("Architecture `%s' not recognized.\n", |
b4a20239 AC |
504 | set_architecture_string); |
505 | } | |
506 | else | |
507 | { | |
508 | const struct bfd_arch_info *arch | |
509 | = bfd_scan_arch (set_architecture_string); | |
510 | if (arch == NULL) | |
511 | internal_error ("set_architecture: bfd_scan_arch failed"); | |
512 | set_arch (arch, set_arch_manual); | |
513 | } | |
514 | show_architecture (NULL, from_tty); | |
515 | } | |
516 | ||
517 | /* Called if the user enters ``info architecture'' without an argument. */ | |
518 | ||
519 | static void | |
520 | info_architecture (char *args, int from_tty) | |
521 | { | |
522 | printf_filtered ("Available architectures are:\n"); | |
523 | if (GDB_MULTI_ARCH) | |
524 | { | |
525 | const char **arches = gdbarch_printable_names (); | |
526 | const char **arch; | |
527 | for (arch = arches; *arch != NULL; arch++) | |
528 | { | |
529 | printf_filtered (" %s", *arch); | |
530 | } | |
531 | free (arches); | |
532 | } | |
533 | else | |
534 | { | |
535 | enum bfd_architecture a; | |
536 | for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++) | |
537 | { | |
538 | const struct bfd_arch_info *ap; | |
539 | for (ap = bfd_lookup_arch (a, 0); | |
540 | ap != NULL; | |
541 | ap = ap->next) | |
542 | { | |
543 | printf_filtered (" %s", ap->printable_name); | |
544 | ap = ap->next; | |
545 | } | |
546 | } | |
547 | } | |
548 | printf_filtered ("\n"); | |
549 | } | |
550 | ||
b7d6b182 | 551 | /* Set the dynamic target-system-dependent parameters (architecture, |
b4a20239 AC |
552 | byte-order) using information found in the BFD */ |
553 | ||
554 | void | |
fba45db2 | 555 | set_gdbarch_from_file (bfd *abfd) |
b4a20239 AC |
556 | { |
557 | if (GDB_MULTI_ARCH) | |
558 | { | |
559 | struct gdbarch_info info; | |
560 | memset (&info, 0, sizeof info); | |
561 | info.abfd = abfd; | |
16f33e29 | 562 | if (! gdbarch_update_p (info)) |
ec3d358c | 563 | error ("Architecture of file not recognized.\n"); |
b4a20239 AC |
564 | } |
565 | else | |
566 | { | |
567 | set_architecture_from_file (abfd); | |
568 | set_endian_from_file (abfd); | |
569 | } | |
570 | } | |
571 | ||
572 | /* Initialize the current architecture. Update the ``set | |
573 | architecture'' command so that it specifies a list of valid | |
574 | architectures. */ | |
575 | ||
1ba607ad AC |
576 | #ifdef DEFAULT_BFD_ARCH |
577 | extern const bfd_arch_info_type DEFAULT_BFD_ARCH; | |
578 | static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH; | |
579 | #else | |
4b9b3959 | 580 | static const bfd_arch_info_type *default_bfd_arch; |
1ba607ad AC |
581 | #endif |
582 | ||
583 | #ifdef DEFAULT_BFD_VEC | |
584 | extern const bfd_target DEFAULT_BFD_VEC; | |
585 | static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC; | |
586 | #else | |
587 | static const bfd_target *default_bfd_vec; | |
588 | #endif | |
589 | ||
b4a20239 AC |
590 | void |
591 | initialize_current_architecture (void) | |
592 | { | |
593 | const char **arches = gdbarch_printable_names (); | |
b4a20239 | 594 | |
1ba607ad AC |
595 | /* determine a default architecture and byte order. */ |
596 | struct gdbarch_info info; | |
597 | memset (&info, 0, sizeof (info)); | |
598 | ||
599 | /* Find a default architecture. */ | |
600 | if (info.bfd_arch_info == NULL | |
601 | && default_bfd_arch != NULL) | |
602 | info.bfd_arch_info = default_bfd_arch; | |
603 | if (info.bfd_arch_info == NULL) | |
b4a20239 | 604 | { |
1ba607ad AC |
605 | /* Choose the architecture by taking the first one |
606 | alphabetically. */ | |
607 | const char *chosen = arches[0]; | |
b4a20239 | 608 | const char **arch; |
b4a20239 AC |
609 | for (arch = arches; *arch != NULL; arch++) |
610 | { | |
b4a20239 AC |
611 | if (strcmp (*arch, chosen) < 0) |
612 | chosen = *arch; | |
613 | } | |
614 | if (chosen == NULL) | |
615 | internal_error ("initialize_current_architecture: No arch"); | |
b4a20239 AC |
616 | info.bfd_arch_info = bfd_scan_arch (chosen); |
617 | if (info.bfd_arch_info == NULL) | |
618 | internal_error ("initialize_current_architecture: Arch not found"); | |
1ba607ad AC |
619 | } |
620 | ||
621 | /* take several guesses at a byte order. */ | |
622 | /* NB: can't use TARGET_BYTE_ORDER_DEFAULT as its definition is | |
623 | forced above. */ | |
624 | if (info.byte_order == 0 | |
625 | && default_bfd_vec != NULL) | |
626 | { | |
627 | /* Extract BFD's default vector's byte order. */ | |
628 | switch (default_bfd_vec->byteorder) | |
629 | { | |
630 | case BFD_ENDIAN_BIG: | |
631 | info.byte_order = BIG_ENDIAN; | |
632 | break; | |
633 | case BFD_ENDIAN_LITTLE: | |
634 | info.byte_order = LITTLE_ENDIAN; | |
635 | break; | |
636 | default: | |
637 | break; | |
638 | } | |
639 | } | |
640 | if (info.byte_order == 0) | |
641 | { | |
642 | /* look for ``*el-*'' in the target name. */ | |
643 | const char *chp; | |
644 | chp = strchr (target_name, '-'); | |
645 | if (chp != NULL | |
646 | && chp - 2 >= target_name | |
647 | && strncmp (chp - 2, "el", 2) == 0) | |
648 | info.byte_order = LITTLE_ENDIAN; | |
649 | } | |
650 | if (info.byte_order == 0) | |
651 | { | |
652 | /* Wire it to big-endian!!! */ | |
653 | info.byte_order = BIG_ENDIAN; | |
654 | } | |
655 | ||
656 | if (GDB_MULTI_ARCH) | |
657 | { | |
16f33e29 AC |
658 | if (! gdbarch_update_p (info)) |
659 | { | |
660 | internal_error ("initialize_current_architecture: Selection of initial architecture failed"); | |
661 | } | |
b4a20239 AC |
662 | } |
663 | ||
1ba607ad AC |
664 | /* Create the ``set architecture'' command appending ``auto'' to the |
665 | list of architectures. */ | |
b4a20239 AC |
666 | { |
667 | struct cmd_list_element *c; | |
668 | /* Append ``auto''. */ | |
669 | int nr; | |
670 | for (nr = 0; arches[nr] != NULL; nr++); | |
671 | arches = xrealloc (arches, sizeof (char*) * (nr + 2)); | |
672 | arches[nr + 0] = "auto"; | |
673 | arches[nr + 1] = NULL; | |
674 | /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead | |
675 | of ``const char *''. We just happen to know that the casts are | |
676 | safe. */ | |
677 | c = add_set_enum_cmd ("architecture", class_support, | |
53904c9e | 678 | arches, &set_architecture_string, |
b4a20239 AC |
679 | "Set architecture of target.", |
680 | &setlist); | |
681 | c->function.sfunc = set_architecture; | |
682 | add_alias_cmd ("processor", "architecture", class_support, 1, &setlist); | |
683 | /* Don't use set_from_show - need to print both auto/manual and | |
684 | current setting. */ | |
685 | add_cmd ("architecture", class_support, show_architecture, | |
686 | "Show the current target architecture", &showlist); | |
687 | c = add_cmd ("architecture", class_support, info_architecture, | |
688 | "List supported target architectures", &infolist); | |
689 | deprecate_cmd (c, "set architecture"); | |
690 | } | |
691 | } | |
692 | ||
693 | ||
c0e8c252 AC |
694 | /* */ |
695 | ||
b4a20239 | 696 | extern initialize_file_ftype _initialize_gdbarch_utils; |
c0e8c252 AC |
697 | |
698 | void | |
b4a20239 | 699 | _initialize_gdbarch_utils (void) |
c0e8c252 | 700 | { |
b4a20239 AC |
701 | struct cmd_list_element *c; |
702 | c = add_set_enum_cmd ("endian", class_support, | |
703 | endian_enum, &set_endian_string, | |
704 | "Set endianness of target.", | |
705 | &setlist); | |
706 | c->function.sfunc = set_endian; | |
707 | /* Don't use set_from_show - need to print both auto/manual and | |
708 | current setting. */ | |
709 | add_cmd ("endian", class_support, show_endian, | |
710 | "Show the current byte-order", &showlist); | |
c0e8c252 | 711 | } |