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