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