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