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