Commit | Line | Data |
---|---|---|
c0e8c252 | 1 | /* Dynamic architecture support for GDB, the GNU debugger. |
f4f9705a | 2 | |
61baf725 | 3 | Copyright (C) 1998-2017 Free Software Foundation, Inc. |
c0e8c252 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c0e8c252 AC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c0e8c252 AC |
19 | |
20 | #include "defs.h" | |
21 | ||
fb6ecb0f | 22 | #include "arch-utils.h" |
192cb3d4 | 23 | #include "buildsym.h" |
c0e8c252 | 24 | #include "gdbcmd.h" |
0e2de366 | 25 | #include "inferior.h" /* enum CALL_DUMMY_LOCATION et al. */ |
45741a9c | 26 | #include "infrun.h" |
fbec36e2 | 27 | #include "regcache.h" |
4182591f | 28 | #include "sim-regno.h" |
750eb019 | 29 | #include "gdbcore.h" |
bf922ad9 | 30 | #include "osabi.h" |
424163ea | 31 | #include "target-descriptions.h" |
237fc4c9 | 32 | #include "objfiles.h" |
18648a37 | 33 | #include "language.h" |
3e29f34a | 34 | #include "symtab.h" |
bf922ad9 | 35 | |
1ba607ad AC |
36 | #include "version.h" |
37 | ||
f0d4cc9e AC |
38 | #include "floatformat.h" |
39 | ||
39503f82 | 40 | #include "dis-asm.h" |
1fd35568 | 41 | |
237fc4c9 PA |
42 | struct displaced_step_closure * |
43 | simple_displaced_step_copy_insn (struct gdbarch *gdbarch, | |
44 | CORE_ADDR from, CORE_ADDR to, | |
45 | struct regcache *regs) | |
46 | { | |
47 | size_t len = gdbarch_max_insn_length (gdbarch); | |
224c3ddb | 48 | gdb_byte *buf = (gdb_byte *) xmalloc (len); |
237fc4c9 PA |
49 | |
50 | read_memory (from, buf, len); | |
51 | write_memory (to, buf, len); | |
52 | ||
53 | if (debug_displaced) | |
54 | { | |
5af949e3 UW |
55 | fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", |
56 | paddress (gdbarch, from), paddress (gdbarch, to)); | |
237fc4c9 PA |
57 | displaced_step_dump_bytes (gdb_stdlog, buf, len); |
58 | } | |
59 | ||
60 | return (struct displaced_step_closure *) buf; | |
61 | } | |
62 | ||
99e40580 UW |
63 | int |
64 | default_displaced_step_hw_singlestep (struct gdbarch *gdbarch, | |
65 | struct displaced_step_closure *closure) | |
66 | { | |
67 | return !gdbarch_software_single_step_p (gdbarch); | |
68 | } | |
237fc4c9 PA |
69 | |
70 | CORE_ADDR | |
71 | displaced_step_at_entry_point (struct gdbarch *gdbarch) | |
72 | { | |
73 | CORE_ADDR addr; | |
74 | int bp_len; | |
75 | ||
76 | addr = entry_point_address (); | |
77 | ||
237fc4c9 PA |
78 | /* Inferior calls also use the entry point as a breakpoint location. |
79 | We don't want displaced stepping to interfere with those | |
80 | breakpoints, so leave space. */ | |
81 | gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len); | |
5931a2fa | 82 | addr += bp_len * 2; |
237fc4c9 PA |
83 | |
84 | return addr; | |
85 | } | |
86 | ||
4182591f | 87 | int |
e7faf938 | 88 | legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum) |
4182591f AC |
89 | { |
90 | /* Only makes sense to supply raw registers. */ | |
e7faf938 | 91 | gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); |
4182591f AC |
92 | /* NOTE: cagney/2002-05-13: The old code did it this way and it is |
93 | suspected that some GDB/SIM combinations may rely on this | |
94 | behavour. The default should be one2one_register_sim_regno | |
95 | (below). */ | |
e7faf938 MD |
96 | if (gdbarch_register_name (gdbarch, regnum) != NULL |
97 | && gdbarch_register_name (gdbarch, regnum)[0] != '\0') | |
4182591f AC |
98 | return regnum; |
99 | else | |
100 | return LEGACY_SIM_REGNO_IGNORE; | |
101 | } | |
102 | ||
bdcd319a | 103 | CORE_ADDR |
52f729a7 | 104 | generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) |
bdcd319a CV |
105 | { |
106 | return 0; | |
107 | } | |
108 | ||
dea0c52f | 109 | CORE_ADDR |
4c8c40e6 | 110 | generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) |
dea0c52f MK |
111 | { |
112 | return 0; | |
113 | } | |
114 | ||
d50355b6 | 115 | int |
e17a4113 | 116 | generic_in_solib_return_trampoline (struct gdbarch *gdbarch, |
2c02bd72 | 117 | CORE_ADDR pc, const char *name) |
d50355b6 MS |
118 | { |
119 | return 0; | |
120 | } | |
121 | ||
c12260ac | 122 | int |
c9cf6e20 | 123 | generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
c12260ac CV |
124 | { |
125 | return 0; | |
126 | } | |
127 | ||
7eb89530 YQ |
128 | int |
129 | default_code_of_frame_writable (struct gdbarch *gdbarch, | |
130 | struct frame_info *frame) | |
131 | { | |
132 | return 1; | |
133 | } | |
134 | ||
4d1e7dd1 | 135 | /* Helper functions for gdbarch_inner_than */ |
3339cf8b AC |
136 | |
137 | int | |
fba45db2 | 138 | core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs) |
3339cf8b AC |
139 | { |
140 | return (lhs < rhs); | |
141 | } | |
142 | ||
143 | int | |
fba45db2 | 144 | core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs) |
3339cf8b AC |
145 | { |
146 | return (lhs > rhs); | |
147 | } | |
148 | ||
0e2de366 | 149 | /* Misc helper functions for targets. */ |
193e3b1a | 150 | |
f517ea4e | 151 | CORE_ADDR |
24568a2c | 152 | core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr) |
f517ea4e PS |
153 | { |
154 | return addr; | |
155 | } | |
156 | ||
e2d0e7eb AC |
157 | CORE_ADDR |
158 | convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr, | |
159 | struct target_ops *targ) | |
160 | { | |
161 | return addr; | |
162 | } | |
163 | ||
88c72b7d | 164 | int |
d3f73121 | 165 | no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg) |
88c72b7d AC |
166 | { |
167 | return reg; | |
168 | } | |
169 | ||
a2cf933a | 170 | void |
3e29f34a | 171 | default_coff_make_msymbol_special (int val, struct minimal_symbol *msym) |
a2cf933a EZ |
172 | { |
173 | return; | |
174 | } | |
175 | ||
3e29f34a MR |
176 | /* See arch-utils.h. */ |
177 | ||
a2cf933a | 178 | void |
3e29f34a | 179 | default_make_symbol_special (struct symbol *sym, struct objfile *objfile) |
a2cf933a EZ |
180 | { |
181 | return; | |
182 | } | |
183 | ||
3e29f34a MR |
184 | /* See arch-utils.h. */ |
185 | ||
186 | CORE_ADDR | |
187 | default_adjust_dwarf2_addr (CORE_ADDR pc) | |
188 | { | |
189 | return pc; | |
190 | } | |
191 | ||
192 | /* See arch-utils.h. */ | |
193 | ||
194 | CORE_ADDR | |
195 | default_adjust_dwarf2_line (CORE_ADDR addr, int rel) | |
196 | { | |
197 | return addr; | |
198 | } | |
199 | ||
b41c5a85 JW |
200 | /* See arch-utils.h. */ |
201 | ||
202 | bool | |
203 | default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op, | |
204 | struct dwarf2_frame_state *fs) | |
205 | { | |
206 | return false; | |
207 | } | |
208 | ||
01fb7433 | 209 | int |
64a3914f | 210 | cannot_register_not (struct gdbarch *gdbarch, int regnum) |
01fb7433 AC |
211 | { |
212 | return 0; | |
213 | } | |
39d4ef09 AC |
214 | |
215 | /* Legacy version of target_virtual_frame_pointer(). Assumes that | |
0e2de366 MS |
216 | there is an gdbarch_deprecated_fp_regnum and that it is the same, |
217 | cooked or raw. */ | |
39d4ef09 AC |
218 | |
219 | void | |
a54fba4c MD |
220 | legacy_virtual_frame_pointer (struct gdbarch *gdbarch, |
221 | CORE_ADDR pc, | |
39d4ef09 AC |
222 | int *frame_regnum, |
223 | LONGEST *frame_offset) | |
224 | { | |
20bcf01c AC |
225 | /* FIXME: cagney/2002-09-13: This code is used when identifying the |
226 | frame pointer of the current PC. It is assuming that a single | |
227 | register and an offset can determine this. I think it should | |
228 | instead generate a byte code expression as that would work better | |
229 | with things like Dwarf2's CFI. */ | |
a54fba4c MD |
230 | if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0 |
231 | && gdbarch_deprecated_fp_regnum (gdbarch) | |
232 | < gdbarch_num_regs (gdbarch)) | |
233 | *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch); | |
234 | else if (gdbarch_sp_regnum (gdbarch) >= 0 | |
235 | && gdbarch_sp_regnum (gdbarch) | |
236 | < gdbarch_num_regs (gdbarch)) | |
237 | *frame_regnum = gdbarch_sp_regnum (gdbarch); | |
20bcf01c AC |
238 | else |
239 | /* Should this be an internal error? I guess so, it is reflecting | |
240 | an architectural limitation in the current design. */ | |
0e2de366 MS |
241 | internal_error (__FILE__, __LINE__, |
242 | _("No virtual frame pointer available")); | |
39d4ef09 AC |
243 | *frame_offset = 0; |
244 | } | |
46cd78fb | 245 | |
9b790ce7 UW |
246 | /* Return a floating-point format for a floating-point variable of |
247 | length LEN in bits. If non-NULL, NAME is the name of its type. | |
248 | If no suitable type is found, return NULL. */ | |
249 | ||
250 | const struct floatformat ** | |
251 | default_floatformat_for_type (struct gdbarch *gdbarch, | |
252 | const char *name, int len) | |
253 | { | |
254 | const struct floatformat **format = NULL; | |
255 | ||
256 | if (len == gdbarch_half_bit (gdbarch)) | |
257 | format = gdbarch_half_format (gdbarch); | |
258 | else if (len == gdbarch_float_bit (gdbarch)) | |
259 | format = gdbarch_float_format (gdbarch); | |
260 | else if (len == gdbarch_double_bit (gdbarch)) | |
261 | format = gdbarch_double_format (gdbarch); | |
262 | else if (len == gdbarch_long_double_bit (gdbarch)) | |
263 | format = gdbarch_long_double_format (gdbarch); | |
264 | /* On i386 the 'long double' type takes 96 bits, | |
265 | while the real number of used bits is only 80, | |
266 | both in processor and in memory. | |
267 | The code below accepts the real bit size. */ | |
268 | else if (gdbarch_long_double_format (gdbarch) != NULL | |
269 | && len == gdbarch_long_double_format (gdbarch)[0]->totalsize) | |
270 | format = gdbarch_long_double_format (gdbarch); | |
271 | ||
272 | return format; | |
273 | } | |
d7bd68ca | 274 | \f |
13d01224 | 275 | int |
76a8ddb9 UW |
276 | generic_convert_register_p (struct gdbarch *gdbarch, int regnum, |
277 | struct type *type) | |
13d01224 | 278 | { |
9730f241 | 279 | return 0; |
13d01224 AC |
280 | } |
281 | ||
192cb3d4 MK |
282 | int |
283 | default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type) | |
284 | { | |
192cb3d4 MK |
285 | return 0; |
286 | } | |
287 | ||
3ca64954 RC |
288 | int |
289 | generic_instruction_nullified (struct gdbarch *gdbarch, | |
290 | struct regcache *regcache) | |
291 | { | |
292 | return 0; | |
293 | } | |
294 | ||
123dc839 DJ |
295 | int |
296 | default_remote_register_number (struct gdbarch *gdbarch, | |
297 | int regno) | |
298 | { | |
299 | return regno; | |
300 | } | |
301 | ||
3437254d PA |
302 | /* See arch-utils.h. */ |
303 | ||
304 | int | |
305 | default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range) | |
306 | { | |
307 | return 0; | |
308 | } | |
309 | ||
01fb7433 | 310 | \f |
b4a20239 AC |
311 | /* Functions to manipulate the endianness of the target. */ |
312 | ||
f486487f | 313 | static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN; |
b4a20239 | 314 | |
53904c9e AC |
315 | static const char endian_big[] = "big"; |
316 | static const char endian_little[] = "little"; | |
317 | static const char endian_auto[] = "auto"; | |
40478521 | 318 | static const char *const endian_enum[] = |
b4a20239 AC |
319 | { |
320 | endian_big, | |
321 | endian_little, | |
322 | endian_auto, | |
323 | NULL, | |
324 | }; | |
53904c9e | 325 | static const char *set_endian_string; |
b4a20239 | 326 | |
b6d373df DJ |
327 | enum bfd_endian |
328 | selected_byte_order (void) | |
329 | { | |
e17c207e | 330 | return target_byte_order_user; |
b6d373df DJ |
331 | } |
332 | ||
b4a20239 AC |
333 | /* Called by ``show endian''. */ |
334 | ||
335 | static void | |
7ab04401 AC |
336 | show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c, |
337 | const char *value) | |
b4a20239 | 338 | { |
7b6b9e83 | 339 | if (target_byte_order_user == BFD_ENDIAN_UNKNOWN) |
e17c207e | 340 | if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG) |
7ab04401 AC |
341 | fprintf_unfiltered (file, _("The target endianness is set automatically " |
342 | "(currently big endian)\n")); | |
edefbb7c | 343 | else |
7ab04401 | 344 | fprintf_unfiltered (file, _("The target endianness is set automatically " |
3e43a32a | 345 | "(currently little endian)\n")); |
b4a20239 | 346 | else |
e17c207e | 347 | if (target_byte_order_user == BFD_ENDIAN_BIG) |
7ab04401 AC |
348 | fprintf_unfiltered (file, |
349 | _("The target is assumed to be big endian\n")); | |
350 | else | |
351 | fprintf_unfiltered (file, | |
352 | _("The target is assumed to be little endian\n")); | |
b4a20239 AC |
353 | } |
354 | ||
355 | static void | |
356 | set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c) | |
357 | { | |
7a107747 DJ |
358 | struct gdbarch_info info; |
359 | ||
360 | gdbarch_info_init (&info); | |
361 | ||
3fd3d7d2 | 362 | if (set_endian_string == endian_auto) |
b4a20239 | 363 | { |
7a107747 DJ |
364 | target_byte_order_user = BFD_ENDIAN_UNKNOWN; |
365 | if (! gdbarch_update_p (info)) | |
366 | internal_error (__FILE__, __LINE__, | |
367 | _("set_endian: architecture update failed")); | |
b4a20239 AC |
368 | } |
369 | else if (set_endian_string == endian_little) | |
370 | { | |
d90cf509 AC |
371 | info.byte_order = BFD_ENDIAN_LITTLE; |
372 | if (! gdbarch_update_p (info)) | |
edefbb7c | 373 | printf_unfiltered (_("Little endian target not supported by GDB\n")); |
7a107747 DJ |
374 | else |
375 | target_byte_order_user = BFD_ENDIAN_LITTLE; | |
b4a20239 AC |
376 | } |
377 | else if (set_endian_string == endian_big) | |
378 | { | |
d90cf509 AC |
379 | info.byte_order = BFD_ENDIAN_BIG; |
380 | if (! gdbarch_update_p (info)) | |
edefbb7c | 381 | printf_unfiltered (_("Big endian target not supported by GDB\n")); |
7a107747 DJ |
382 | else |
383 | target_byte_order_user = BFD_ENDIAN_BIG; | |
b4a20239 AC |
384 | } |
385 | else | |
8e65ff28 | 386 | internal_error (__FILE__, __LINE__, |
edefbb7c | 387 | _("set_endian: bad value")); |
7a107747 | 388 | |
7ab04401 | 389 | show_endian (gdb_stdout, from_tty, NULL, NULL); |
b4a20239 AC |
390 | } |
391 | ||
23181151 | 392 | /* Given SELECTED, a currently selected BFD architecture, and |
e35359c5 UW |
393 | TARGET_DESC, the current target description, return what |
394 | architecture to use. | |
395 | ||
396 | SELECTED may be NULL, in which case we return the architecture | |
397 | associated with TARGET_DESC. If SELECTED specifies a variant | |
398 | of the architecture associtated with TARGET_DESC, return the | |
399 | more specific of the two. | |
400 | ||
401 | If SELECTED is a different architecture, but it is accepted as | |
402 | compatible by the target, we can use the target architecture. | |
403 | ||
404 | If SELECTED is obviously incompatible, warn the user. */ | |
23181151 DJ |
405 | |
406 | static const struct bfd_arch_info * | |
e35359c5 UW |
407 | choose_architecture_for_target (const struct target_desc *target_desc, |
408 | const struct bfd_arch_info *selected) | |
23181151 | 409 | { |
e35359c5 | 410 | const struct bfd_arch_info *from_target = tdesc_architecture (target_desc); |
23181151 DJ |
411 | const struct bfd_arch_info *compat1, *compat2; |
412 | ||
413 | if (selected == NULL) | |
414 | return from_target; | |
415 | ||
416 | if (from_target == NULL) | |
417 | return selected; | |
418 | ||
419 | /* struct bfd_arch_info objects are singletons: that is, there's | |
420 | supposed to be exactly one instance for a given machine. So you | |
421 | can tell whether two are equivalent by comparing pointers. */ | |
422 | if (from_target == selected) | |
423 | return selected; | |
424 | ||
425 | /* BFD's 'A->compatible (A, B)' functions return zero if A and B are | |
426 | incompatible. But if they are compatible, it returns the 'more | |
427 | featureful' of the two arches. That is, if A can run code | |
428 | written for B, but B can't run code written for A, then it'll | |
429 | return A. | |
430 | ||
431 | Some targets (e.g. MIPS as of 2006-12-04) don't fully | |
432 | implement this, instead always returning NULL or the first | |
433 | argument. We detect that case by checking both directions. */ | |
434 | ||
435 | compat1 = selected->compatible (selected, from_target); | |
436 | compat2 = from_target->compatible (from_target, selected); | |
437 | ||
438 | if (compat1 == NULL && compat2 == NULL) | |
439 | { | |
0e2de366 MS |
440 | /* BFD considers the architectures incompatible. Check our |
441 | target description whether it accepts SELECTED as compatible | |
442 | anyway. */ | |
e35359c5 UW |
443 | if (tdesc_compatible_p (target_desc, selected)) |
444 | return from_target; | |
445 | ||
23181151 DJ |
446 | warning (_("Selected architecture %s is not compatible " |
447 | "with reported target architecture %s"), | |
448 | selected->printable_name, from_target->printable_name); | |
449 | return selected; | |
450 | } | |
451 | ||
452 | if (compat1 == NULL) | |
453 | return compat2; | |
454 | if (compat2 == NULL) | |
455 | return compat1; | |
456 | if (compat1 == compat2) | |
457 | return compat1; | |
458 | ||
0e2de366 MS |
459 | /* If the two didn't match, but one of them was a default |
460 | architecture, assume the more specific one is correct. This | |
461 | handles the case where an executable or target description just | |
462 | says "mips", but the other knows which MIPS variant. */ | |
23181151 DJ |
463 | if (compat1->the_default) |
464 | return compat2; | |
465 | if (compat2->the_default) | |
466 | return compat1; | |
467 | ||
468 | /* We have no idea which one is better. This is a bug, but not | |
469 | a critical problem; warn the user. */ | |
470 | warning (_("Selected architecture %s is ambiguous with " | |
471 | "reported target architecture %s"), | |
472 | selected->printable_name, from_target->printable_name); | |
473 | return selected; | |
474 | } | |
475 | ||
0e2de366 | 476 | /* Functions to manipulate the architecture of the target. */ |
b4a20239 AC |
477 | |
478 | enum set_arch { set_arch_auto, set_arch_manual }; | |
479 | ||
7a107747 | 480 | static const struct bfd_arch_info *target_architecture_user; |
b4a20239 | 481 | |
a8cf2722 AC |
482 | static const char *set_architecture_string; |
483 | ||
484 | const char * | |
485 | selected_architecture_name (void) | |
486 | { | |
7a107747 | 487 | if (target_architecture_user == NULL) |
a8cf2722 AC |
488 | return NULL; |
489 | else | |
490 | return set_architecture_string; | |
491 | } | |
b4a20239 | 492 | |
b4a20239 | 493 | /* Called if the user enters ``show architecture'' without an |
0e2de366 | 494 | argument. */ |
b4a20239 AC |
495 | |
496 | static void | |
7ab04401 AC |
497 | show_architecture (struct ui_file *file, int from_tty, |
498 | struct cmd_list_element *c, const char *value) | |
b4a20239 | 499 | { |
7a107747 | 500 | if (target_architecture_user == NULL) |
3e43a32a MS |
501 | fprintf_filtered (file, _("The target architecture is set " |
502 | "automatically (currently %s)\n"), | |
503 | gdbarch_bfd_arch_info (get_current_arch ())->printable_name); | |
b4a20239 | 504 | else |
3e43a32a MS |
505 | fprintf_filtered (file, _("The target architecture is assumed to be %s\n"), |
506 | set_architecture_string); | |
b4a20239 AC |
507 | } |
508 | ||
509 | ||
510 | /* Called if the user enters ``set architecture'' with or without an | |
0e2de366 | 511 | argument. */ |
b4a20239 AC |
512 | |
513 | static void | |
514 | set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c) | |
515 | { | |
7a107747 DJ |
516 | struct gdbarch_info info; |
517 | ||
518 | gdbarch_info_init (&info); | |
519 | ||
b4a20239 AC |
520 | if (strcmp (set_architecture_string, "auto") == 0) |
521 | { | |
7a107747 DJ |
522 | target_architecture_user = NULL; |
523 | if (!gdbarch_update_p (info)) | |
524 | internal_error (__FILE__, __LINE__, | |
525 | _("could not select an architecture automatically")); | |
b4a20239 | 526 | } |
d90cf509 | 527 | else |
b4a20239 | 528 | { |
b4a20239 AC |
529 | info.bfd_arch_info = bfd_scan_arch (set_architecture_string); |
530 | if (info.bfd_arch_info == NULL) | |
8e65ff28 | 531 | internal_error (__FILE__, __LINE__, |
edefbb7c | 532 | _("set_architecture: bfd_scan_arch failed")); |
16f33e29 | 533 | if (gdbarch_update_p (info)) |
7a107747 | 534 | target_architecture_user = info.bfd_arch_info; |
b4a20239 | 535 | else |
edefbb7c | 536 | printf_unfiltered (_("Architecture `%s' not recognized.\n"), |
b4a20239 AC |
537 | set_architecture_string); |
538 | } | |
7ab04401 | 539 | show_architecture (gdb_stdout, from_tty, NULL, NULL); |
b4a20239 AC |
540 | } |
541 | ||
ebdba546 | 542 | /* Try to select a global architecture that matches "info". Return |
0f9741f2 | 543 | non-zero if the attempt succeeds. */ |
ebdba546 AC |
544 | int |
545 | gdbarch_update_p (struct gdbarch_info info) | |
546 | { | |
a7f1256d UW |
547 | struct gdbarch *new_gdbarch; |
548 | ||
549 | /* Check for the current file. */ | |
550 | if (info.abfd == NULL) | |
551 | info.abfd = exec_bfd; | |
552 | if (info.abfd == NULL) | |
553 | info.abfd = core_bfd; | |
554 | ||
555 | /* Check for the current target description. */ | |
556 | if (info.target_desc == NULL) | |
557 | info.target_desc = target_current_description (); | |
558 | ||
559 | new_gdbarch = gdbarch_find_by_info (info); | |
ebdba546 AC |
560 | |
561 | /* If there no architecture by that name, reject the request. */ | |
562 | if (new_gdbarch == NULL) | |
563 | { | |
564 | if (gdbarch_debug) | |
565 | fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: " | |
566 | "Architecture not found\n"); | |
567 | return 0; | |
568 | } | |
569 | ||
570 | /* If it is the same old architecture, accept the request (but don't | |
571 | swap anything). */ | |
f5656ead | 572 | if (new_gdbarch == target_gdbarch ()) |
ebdba546 AC |
573 | { |
574 | if (gdbarch_debug) | |
575 | fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: " | |
e3cb3832 JB |
576 | "Architecture %s (%s) unchanged\n", |
577 | host_address_to_string (new_gdbarch), | |
ebdba546 AC |
578 | gdbarch_bfd_arch_info (new_gdbarch)->printable_name); |
579 | return 1; | |
580 | } | |
581 | ||
582 | /* It's a new architecture, swap it in. */ | |
583 | if (gdbarch_debug) | |
584 | fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: " | |
e3cb3832 JB |
585 | "New architecture %s (%s) selected\n", |
586 | host_address_to_string (new_gdbarch), | |
ebdba546 | 587 | gdbarch_bfd_arch_info (new_gdbarch)->printable_name); |
aff68abb | 588 | set_target_gdbarch (new_gdbarch); |
ebdba546 AC |
589 | |
590 | return 1; | |
591 | } | |
592 | ||
2b026650 MK |
593 | /* Return the architecture for ABFD. If no suitable architecture |
594 | could be find, return NULL. */ | |
595 | ||
596 | struct gdbarch * | |
597 | gdbarch_from_bfd (bfd *abfd) | |
b4a20239 | 598 | { |
d90cf509 AC |
599 | struct gdbarch_info info; |
600 | gdbarch_info_init (&info); | |
05c547f6 | 601 | |
d90cf509 | 602 | info.abfd = abfd; |
b60eb90d | 603 | return gdbarch_find_by_info (info); |
2b026650 MK |
604 | } |
605 | ||
606 | /* Set the dynamic target-system-dependent parameters (architecture, | |
607 | byte-order) using information found in the BFD */ | |
608 | ||
609 | void | |
610 | set_gdbarch_from_file (bfd *abfd) | |
611 | { | |
a7f1256d | 612 | struct gdbarch_info info; |
2b026650 MK |
613 | struct gdbarch *gdbarch; |
614 | ||
a7f1256d UW |
615 | gdbarch_info_init (&info); |
616 | info.abfd = abfd; | |
617 | info.target_desc = target_current_description (); | |
618 | gdbarch = gdbarch_find_by_info (info); | |
619 | ||
2b026650 | 620 | if (gdbarch == NULL) |
8a3fe4f8 | 621 | error (_("Architecture of file not recognized.")); |
aff68abb | 622 | set_target_gdbarch (gdbarch); |
b4a20239 AC |
623 | } |
624 | ||
625 | /* Initialize the current architecture. Update the ``set | |
626 | architecture'' command so that it specifies a list of valid | |
627 | architectures. */ | |
628 | ||
1ba607ad AC |
629 | #ifdef DEFAULT_BFD_ARCH |
630 | extern const bfd_arch_info_type DEFAULT_BFD_ARCH; | |
631 | static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH; | |
632 | #else | |
4b9b3959 | 633 | static const bfd_arch_info_type *default_bfd_arch; |
1ba607ad AC |
634 | #endif |
635 | ||
636 | #ifdef DEFAULT_BFD_VEC | |
637 | extern const bfd_target DEFAULT_BFD_VEC; | |
638 | static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC; | |
639 | #else | |
640 | static const bfd_target *default_bfd_vec; | |
641 | #endif | |
642 | ||
f486487f | 643 | static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN; |
7a107747 | 644 | |
b4a20239 AC |
645 | void |
646 | initialize_current_architecture (void) | |
647 | { | |
648 | const char **arches = gdbarch_printable_names (); | |
05c547f6 | 649 | struct gdbarch_info info; |
b4a20239 | 650 | |
0e2de366 | 651 | /* determine a default architecture and byte order. */ |
fb6ecb0f | 652 | gdbarch_info_init (&info); |
1ba607ad | 653 | |
0e2de366 | 654 | /* Find a default architecture. */ |
7a107747 | 655 | if (default_bfd_arch == NULL) |
b4a20239 | 656 | { |
1ba607ad | 657 | /* Choose the architecture by taking the first one |
0e2de366 | 658 | alphabetically. */ |
1ba607ad | 659 | const char *chosen = arches[0]; |
b4a20239 | 660 | const char **arch; |
b4a20239 AC |
661 | for (arch = arches; *arch != NULL; arch++) |
662 | { | |
b4a20239 AC |
663 | if (strcmp (*arch, chosen) < 0) |
664 | chosen = *arch; | |
665 | } | |
666 | if (chosen == NULL) | |
8e65ff28 | 667 | internal_error (__FILE__, __LINE__, |
edefbb7c | 668 | _("initialize_current_architecture: No arch")); |
7a107747 DJ |
669 | default_bfd_arch = bfd_scan_arch (chosen); |
670 | if (default_bfd_arch == NULL) | |
8e65ff28 | 671 | internal_error (__FILE__, __LINE__, |
edefbb7c | 672 | _("initialize_current_architecture: Arch not found")); |
1ba607ad AC |
673 | } |
674 | ||
7a107747 DJ |
675 | info.bfd_arch_info = default_bfd_arch; |
676 | ||
afe64c1a | 677 | /* Take several guesses at a byte order. */ |
7a107747 | 678 | if (default_byte_order == BFD_ENDIAN_UNKNOWN |
1ba607ad AC |
679 | && default_bfd_vec != NULL) |
680 | { | |
0e2de366 | 681 | /* Extract BFD's default vector's byte order. */ |
1ba607ad AC |
682 | switch (default_bfd_vec->byteorder) |
683 | { | |
684 | case BFD_ENDIAN_BIG: | |
7a107747 | 685 | default_byte_order = BFD_ENDIAN_BIG; |
1ba607ad AC |
686 | break; |
687 | case BFD_ENDIAN_LITTLE: | |
7a107747 | 688 | default_byte_order = BFD_ENDIAN_LITTLE; |
1ba607ad AC |
689 | break; |
690 | default: | |
691 | break; | |
692 | } | |
693 | } | |
7a107747 | 694 | if (default_byte_order == BFD_ENDIAN_UNKNOWN) |
1ba607ad | 695 | { |
0e2de366 | 696 | /* look for ``*el-*'' in the target name. */ |
1ba607ad AC |
697 | const char *chp; |
698 | chp = strchr (target_name, '-'); | |
699 | if (chp != NULL | |
700 | && chp - 2 >= target_name | |
61012eef | 701 | && startswith (chp - 2, "el")) |
7a107747 | 702 | default_byte_order = BFD_ENDIAN_LITTLE; |
1ba607ad | 703 | } |
7a107747 | 704 | if (default_byte_order == BFD_ENDIAN_UNKNOWN) |
1ba607ad AC |
705 | { |
706 | /* Wire it to big-endian!!! */ | |
7a107747 | 707 | default_byte_order = BFD_ENDIAN_BIG; |
1ba607ad AC |
708 | } |
709 | ||
7a107747 | 710 | info.byte_order = default_byte_order; |
9d4fde75 | 711 | info.byte_order_for_code = info.byte_order; |
7a107747 | 712 | |
d90cf509 AC |
713 | if (! gdbarch_update_p (info)) |
714 | internal_error (__FILE__, __LINE__, | |
edefbb7c AC |
715 | _("initialize_current_architecture: Selection of " |
716 | "initial architecture failed")); | |
b4a20239 | 717 | |
1ba607ad | 718 | /* Create the ``set architecture'' command appending ``auto'' to the |
0e2de366 | 719 | list of architectures. */ |
b4a20239 | 720 | { |
0e2de366 | 721 | /* Append ``auto''. */ |
b4a20239 AC |
722 | int nr; |
723 | for (nr = 0; arches[nr] != NULL; nr++); | |
224c3ddb | 724 | arches = XRESIZEVEC (const char *, arches, nr + 2); |
b4a20239 AC |
725 | arches[nr + 0] = "auto"; |
726 | arches[nr + 1] = NULL; | |
7ab04401 | 727 | add_setshow_enum_cmd ("architecture", class_support, |
3e43a32a MS |
728 | arches, &set_architecture_string, |
729 | _("Set architecture of target."), | |
730 | _("Show architecture of target."), NULL, | |
7ab04401 AC |
731 | set_architecture, show_architecture, |
732 | &setlist, &showlist); | |
b4a20239 | 733 | add_alias_cmd ("processor", "architecture", class_support, 1, &setlist); |
b4a20239 AC |
734 | } |
735 | } | |
736 | ||
737 | ||
fb6ecb0f AC |
738 | /* Initialize a gdbarch info to values that will be automatically |
739 | overridden. Note: Originally, this ``struct info'' was initialized | |
ce2826aa | 740 | using memset(0). Unfortunately, that ran into problems, namely |
fb6ecb0f AC |
741 | BFD_ENDIAN_BIG is zero. An explicit initialization function that |
742 | can explicitly set each field to a well defined value is used. */ | |
743 | ||
744 | void | |
745 | gdbarch_info_init (struct gdbarch_info *info) | |
746 | { | |
747 | memset (info, 0, sizeof (struct gdbarch_info)); | |
428721aa | 748 | info->byte_order = BFD_ENDIAN_UNKNOWN; |
9d4fde75 | 749 | info->byte_order_for_code = info->byte_order; |
4be87837 | 750 | info->osabi = GDB_OSABI_UNINITIALIZED; |
fb6ecb0f AC |
751 | } |
752 | ||
100bcc3f | 753 | /* Similar to init, but this time fill in the blanks. Information is |
7a107747 DJ |
754 | obtained from the global "set ..." options and explicitly |
755 | initialized INFO fields. */ | |
bf922ad9 AC |
756 | |
757 | void | |
7a107747 | 758 | gdbarch_info_fill (struct gdbarch_info *info) |
bf922ad9 AC |
759 | { |
760 | /* "(gdb) set architecture ...". */ | |
761 | if (info->bfd_arch_info == NULL | |
7a107747 DJ |
762 | && target_architecture_user) |
763 | info->bfd_arch_info = target_architecture_user; | |
424163ea | 764 | /* From the file. */ |
bf922ad9 AC |
765 | if (info->bfd_arch_info == NULL |
766 | && info->abfd != NULL | |
767 | && bfd_get_arch (info->abfd) != bfd_arch_unknown | |
768 | && bfd_get_arch (info->abfd) != bfd_arch_obscure) | |
769 | info->bfd_arch_info = bfd_get_arch_info (info->abfd); | |
23181151 DJ |
770 | /* From the target. */ |
771 | if (info->target_desc != NULL) | |
772 | info->bfd_arch_info = choose_architecture_for_target | |
e35359c5 | 773 | (info->target_desc, info->bfd_arch_info); |
7a107747 DJ |
774 | /* From the default. */ |
775 | if (info->bfd_arch_info == NULL) | |
776 | info->bfd_arch_info = default_bfd_arch; | |
bf922ad9 AC |
777 | |
778 | /* "(gdb) set byte-order ...". */ | |
779 | if (info->byte_order == BFD_ENDIAN_UNKNOWN | |
7a107747 DJ |
780 | && target_byte_order_user != BFD_ENDIAN_UNKNOWN) |
781 | info->byte_order = target_byte_order_user; | |
bf922ad9 AC |
782 | /* From the INFO struct. */ |
783 | if (info->byte_order == BFD_ENDIAN_UNKNOWN | |
784 | && info->abfd != NULL) | |
785 | info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG | |
7a107747 DJ |
786 | : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE |
787 | : BFD_ENDIAN_UNKNOWN); | |
788 | /* From the default. */ | |
789 | if (info->byte_order == BFD_ENDIAN_UNKNOWN) | |
790 | info->byte_order = default_byte_order; | |
9d4fde75 | 791 | info->byte_order_for_code = info->byte_order; |
bf922ad9 AC |
792 | |
793 | /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */ | |
08d16641 | 794 | /* From the manual override, or from file. */ |
bf922ad9 AC |
795 | if (info->osabi == GDB_OSABI_UNINITIALIZED) |
796 | info->osabi = gdbarch_lookup_osabi (info->abfd); | |
08d16641 PA |
797 | /* From the target. */ |
798 | if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL) | |
799 | info->osabi = tdesc_osabi (info->target_desc); | |
800 | /* From the configured default. */ | |
f4290e2a | 801 | #ifdef GDB_OSABI_DEFAULT |
08d16641 PA |
802 | if (info->osabi == GDB_OSABI_UNKNOWN) |
803 | info->osabi = GDB_OSABI_DEFAULT; | |
f4290e2a | 804 | #endif |
bf922ad9 AC |
805 | |
806 | /* Must have at least filled in the architecture. */ | |
807 | gdb_assert (info->bfd_arch_info != NULL); | |
808 | } | |
809 | ||
0e2de366 MS |
810 | /* Return "current" architecture. If the target is running, this is |
811 | the architecture of the selected frame. Otherwise, the "current" | |
812 | architecture defaults to the target architecture. | |
e17c207e | 813 | |
0e2de366 MS |
814 | This function should normally be called solely by the command |
815 | interpreter routines to determine the architecture to execute a | |
816 | command in. */ | |
e17c207e UW |
817 | struct gdbarch * |
818 | get_current_arch (void) | |
819 | { | |
820 | if (has_stack_frames ()) | |
821 | return get_frame_arch (get_selected_frame (NULL)); | |
822 | else | |
f5656ead | 823 | return target_gdbarch (); |
e17c207e UW |
824 | } |
825 | ||
6c95b8df PA |
826 | int |
827 | default_has_shared_address_space (struct gdbarch *gdbarch) | |
828 | { | |
829 | /* Simply say no. In most unix-like targets each inferior/process | |
830 | has its own address space. */ | |
831 | return 0; | |
832 | } | |
833 | ||
7a697b8d | 834 | int |
6b940e6a PL |
835 | default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr, |
836 | char **msg) | |
7a697b8d SS |
837 | { |
838 | /* We don't know if maybe the target has some way to do fast | |
839 | tracepoints that doesn't need gdbarch, so always say yes. */ | |
840 | if (msg) | |
841 | *msg = NULL; | |
842 | return 1; | |
843 | } | |
844 | ||
22f13eb8 YQ |
845 | const gdb_byte * |
846 | default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, | |
847 | int *lenptr) | |
848 | { | |
849 | int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr); | |
850 | ||
851 | return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr); | |
852 | } | |
833b7ab5 YQ |
853 | int |
854 | default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch, | |
855 | struct regcache *regcache, | |
856 | CORE_ADDR *pcptr) | |
857 | { | |
858 | return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr); | |
859 | } | |
860 | ||
22f13eb8 | 861 | |
6710bf39 SS |
862 | void |
863 | default_gen_return_address (struct gdbarch *gdbarch, | |
864 | struct agent_expr *ax, struct axs_value *value, | |
865 | CORE_ADDR scope) | |
866 | { | |
867 | error (_("This architecture has no method to collect a return address.")); | |
868 | } | |
869 | ||
18648a37 YQ |
870 | int |
871 | default_return_in_first_hidden_param_p (struct gdbarch *gdbarch, | |
872 | struct type *type) | |
873 | { | |
874 | /* Usually, the return value's address is stored the in the "first hidden" | |
875 | parameter if the return value should be passed by reference, as | |
876 | specified in ABI. */ | |
877 | return language_pass_by_reference (type); | |
878 | } | |
879 | ||
c2170eef MM |
880 | int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr) |
881 | { | |
882 | return 0; | |
883 | } | |
884 | ||
885 | int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr) | |
886 | { | |
887 | return 0; | |
888 | } | |
889 | ||
890 | int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr) | |
891 | { | |
892 | return 0; | |
893 | } | |
894 | ||
ae9bb220 PA |
895 | void |
896 | default_skip_permanent_breakpoint (struct regcache *regcache) | |
897 | { | |
898 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
899 | CORE_ADDR current_pc = regcache_read_pc (regcache); | |
ae9bb220 PA |
900 | int bp_len; |
901 | ||
ac298888 | 902 | gdbarch_breakpoint_from_pc (gdbarch, ¤t_pc, &bp_len); |
ae9bb220 PA |
903 | current_pc += bp_len; |
904 | regcache_write_pc (regcache, current_pc); | |
905 | } | |
c0e8c252 | 906 | |
f208eee0 JK |
907 | CORE_ADDR |
908 | default_infcall_mmap (CORE_ADDR size, unsigned prot) | |
909 | { | |
910 | error (_("This target does not support inferior memory allocation by mmap.")); | |
911 | } | |
912 | ||
7f361056 JK |
913 | void |
914 | default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size) | |
915 | { | |
916 | /* Memory reserved by inferior mmap is kept leaked. */ | |
917 | } | |
918 | ||
f208eee0 JK |
919 | /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be |
920 | created in inferior memory by GDB (normally it is set by ld.so). */ | |
921 | ||
922 | char * | |
923 | default_gcc_target_options (struct gdbarch *gdbarch) | |
924 | { | |
925 | return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch), | |
926 | gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : ""); | |
927 | } | |
928 | ||
ac04f72b TT |
929 | /* gdbarch gnu_triplet_regexp method. */ |
930 | ||
931 | const char * | |
932 | default_gnu_triplet_regexp (struct gdbarch *gdbarch) | |
933 | { | |
934 | return gdbarch_bfd_arch_info (gdbarch)->arch_name; | |
935 | } | |
936 | ||
3374165f SM |
937 | /* Default method for gdbarch_addressable_memory_unit_size. By default, a memory byte has |
938 | a size of 1 octet. */ | |
939 | ||
940 | int | |
941 | default_addressable_memory_unit_size (struct gdbarch *gdbarch) | |
942 | { | |
943 | return 1; | |
944 | } | |
945 | ||
5f034a78 MK |
946 | void |
947 | default_guess_tracepoint_registers (struct gdbarch *gdbarch, | |
948 | struct regcache *regcache, | |
949 | CORE_ADDR addr) | |
950 | { | |
951 | int pc_regno = gdbarch_pc_regnum (gdbarch); | |
952 | gdb_byte *regs; | |
953 | ||
954 | /* This guessing code below only works if the PC register isn't | |
955 | a pseudo-register. The value of a pseudo-register isn't stored | |
956 | in the (non-readonly) regcache -- instead it's recomputed | |
957 | (probably from some other cached raw register) whenever the | |
958 | register is read. In this case, a custom method implementation | |
959 | should be used by the architecture. */ | |
960 | if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch)) | |
961 | return; | |
962 | ||
963 | regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno)); | |
964 | store_unsigned_integer (regs, register_size (gdbarch, pc_regno), | |
965 | gdbarch_byte_order (gdbarch), addr); | |
966 | regcache_raw_supply (regcache, pc_regno, regs); | |
967 | } | |
968 | ||
39503f82 YQ |
969 | int |
970 | default_print_insn (bfd_vma memaddr, disassemble_info *info) | |
971 | { | |
972 | disassembler_ftype disassemble_fn; | |
973 | ||
39503f82 YQ |
974 | disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG, |
975 | info->mach, exec_bfd); | |
976 | ||
977 | gdb_assert (disassemble_fn != NULL); | |
978 | return (*disassemble_fn) (memaddr, info); | |
979 | } | |
980 | ||
46a62268 YQ |
981 | /* See arch-utils.h. */ |
982 | ||
983 | CORE_ADDR | |
984 | gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept | |
985 | { | |
986 | CORE_ADDR new_pc = pc; | |
987 | ||
988 | TRY | |
989 | { | |
990 | new_pc = gdbarch_skip_prologue (gdbarch, pc); | |
991 | } | |
992 | CATCH (ex, RETURN_MASK_ALL) | |
993 | {} | |
994 | END_CATCH | |
995 | ||
996 | return new_pc; | |
997 | } | |
998 | ||
3e43a32a MS |
999 | /* -Wmissing-prototypes */ |
1000 | extern initialize_file_ftype _initialize_gdbarch_utils; | |
c0e8c252 AC |
1001 | |
1002 | void | |
b4a20239 | 1003 | _initialize_gdbarch_utils (void) |
c0e8c252 | 1004 | { |
7ab04401 | 1005 | add_setshow_enum_cmd ("endian", class_support, |
3e43a32a MS |
1006 | endian_enum, &set_endian_string, |
1007 | _("Set endianness of target."), | |
1008 | _("Show endianness of target."), | |
1009 | NULL, set_endian, show_endian, | |
7ab04401 | 1010 | &setlist, &showlist); |
c0e8c252 | 1011 | } |