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