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