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