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