Fix gdb.trace/entry-values.exp for thumb mode
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
CommitLineData
c0e8c252 1/* Dynamic architecture support for GDB, the GNU debugger.
f4f9705a 2
ecd75fc8 3 Copyright (C) 1998-2014 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"
0e9f083f 27#include <string.h>
fbec36e2 28#include "regcache.h"
39d4ef09 29#include "gdb_assert.h"
4182591f 30#include "sim-regno.h"
750eb019 31#include "gdbcore.h"
bf922ad9 32#include "osabi.h"
424163ea 33#include "target-descriptions.h"
237fc4c9 34#include "objfiles.h"
18648a37 35#include "language.h"
bf922ad9 36
1ba607ad
AC
37#include "version.h"
38
f0d4cc9e
AC
39#include "floatformat.h"
40
1fd35568 41
237fc4c9
PA
42struct displaced_step_closure *
43simple_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);
48 gdb_byte *buf = xmalloc (len);
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
63
64void
65simple_displaced_step_free_closure (struct gdbarch *gdbarch,
66 struct displaced_step_closure *closure)
67{
68 xfree (closure);
69}
70
99e40580
UW
71int
72default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
73 struct displaced_step_closure *closure)
74{
75 return !gdbarch_software_single_step_p (gdbarch);
76}
237fc4c9
PA
77
78CORE_ADDR
79displaced_step_at_entry_point (struct gdbarch *gdbarch)
80{
81 CORE_ADDR addr;
82 int bp_len;
83
84 addr = entry_point_address ();
85
237fc4c9
PA
86 /* Inferior calls also use the entry point as a breakpoint location.
87 We don't want displaced stepping to interfere with those
88 breakpoints, so leave space. */
89 gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
5931a2fa 90 addr += bp_len * 2;
237fc4c9
PA
91
92 return addr;
93}
94
4182591f 95int
e7faf938 96legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
4182591f
AC
97{
98 /* Only makes sense to supply raw registers. */
e7faf938 99 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
4182591f
AC
100 /* NOTE: cagney/2002-05-13: The old code did it this way and it is
101 suspected that some GDB/SIM combinations may rely on this
102 behavour. The default should be one2one_register_sim_regno
103 (below). */
e7faf938
MD
104 if (gdbarch_register_name (gdbarch, regnum) != NULL
105 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
4182591f
AC
106 return regnum;
107 else
108 return LEGACY_SIM_REGNO_IGNORE;
109}
110
bdcd319a 111CORE_ADDR
52f729a7 112generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
bdcd319a
CV
113{
114 return 0;
115}
116
dea0c52f 117CORE_ADDR
4c8c40e6 118generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
dea0c52f
MK
119{
120 return 0;
121}
122
d50355b6 123int
e17a4113 124generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
2c02bd72 125 CORE_ADDR pc, const char *name)
d50355b6
MS
126{
127 return 0;
128}
129
c12260ac
CV
130int
131generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
132{
133 return 0;
134}
135
4d1e7dd1 136/* Helper functions for gdbarch_inner_than */
3339cf8b
AC
137
138int
fba45db2 139core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
140{
141 return (lhs < rhs);
142}
143
144int
fba45db2 145core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
146{
147 return (lhs > rhs);
148}
149
0e2de366 150/* Misc helper functions for targets. */
193e3b1a 151
f517ea4e 152CORE_ADDR
24568a2c 153core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
f517ea4e
PS
154{
155 return addr;
156}
157
e2d0e7eb
AC
158CORE_ADDR
159convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
160 struct target_ops *targ)
161{
162 return addr;
163}
164
88c72b7d 165int
d3f73121 166no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
88c72b7d
AC
167{
168 return reg;
169}
170
a2cf933a
EZ
171void
172default_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
173{
174 return;
175}
176
177void
178default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
179{
180 return;
181}
182
01fb7433 183int
64a3914f 184cannot_register_not (struct gdbarch *gdbarch, int regnum)
01fb7433
AC
185{
186 return 0;
187}
39d4ef09
AC
188
189/* Legacy version of target_virtual_frame_pointer(). Assumes that
0e2de366
MS
190 there is an gdbarch_deprecated_fp_regnum and that it is the same,
191 cooked or raw. */
39d4ef09
AC
192
193void
a54fba4c
MD
194legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
195 CORE_ADDR pc,
39d4ef09
AC
196 int *frame_regnum,
197 LONGEST *frame_offset)
198{
20bcf01c
AC
199 /* FIXME: cagney/2002-09-13: This code is used when identifying the
200 frame pointer of the current PC. It is assuming that a single
201 register and an offset can determine this. I think it should
202 instead generate a byte code expression as that would work better
203 with things like Dwarf2's CFI. */
a54fba4c
MD
204 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
205 && gdbarch_deprecated_fp_regnum (gdbarch)
206 < gdbarch_num_regs (gdbarch))
207 *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
208 else if (gdbarch_sp_regnum (gdbarch) >= 0
209 && gdbarch_sp_regnum (gdbarch)
210 < gdbarch_num_regs (gdbarch))
211 *frame_regnum = gdbarch_sp_regnum (gdbarch);
20bcf01c
AC
212 else
213 /* Should this be an internal error? I guess so, it is reflecting
214 an architectural limitation in the current design. */
0e2de366
MS
215 internal_error (__FILE__, __LINE__,
216 _("No virtual frame pointer available"));
39d4ef09
AC
217 *frame_offset = 0;
218}
46cd78fb 219
d7bd68ca 220\f
13d01224 221int
76a8ddb9
UW
222generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
223 struct type *type)
13d01224 224{
9730f241 225 return 0;
13d01224
AC
226}
227
192cb3d4
MK
228int
229default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
230{
192cb3d4
MK
231 return 0;
232}
233
3ca64954
RC
234int
235generic_instruction_nullified (struct gdbarch *gdbarch,
236 struct regcache *regcache)
237{
238 return 0;
239}
240
123dc839
DJ
241int
242default_remote_register_number (struct gdbarch *gdbarch,
243 int regno)
244{
245 return regno;
246}
247
01fb7433 248\f
b4a20239
AC
249/* Functions to manipulate the endianness of the target. */
250
7a107747 251static int target_byte_order_user = BFD_ENDIAN_UNKNOWN;
b4a20239 252
53904c9e
AC
253static const char endian_big[] = "big";
254static const char endian_little[] = "little";
255static const char endian_auto[] = "auto";
40478521 256static const char *const endian_enum[] =
b4a20239
AC
257{
258 endian_big,
259 endian_little,
260 endian_auto,
261 NULL,
262};
53904c9e 263static const char *set_endian_string;
b4a20239 264
b6d373df
DJ
265enum bfd_endian
266selected_byte_order (void)
267{
e17c207e 268 return target_byte_order_user;
b6d373df
DJ
269}
270
b4a20239
AC
271/* Called by ``show endian''. */
272
273static void
7ab04401
AC
274show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
275 const char *value)
b4a20239 276{
7b6b9e83 277 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
e17c207e 278 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
7ab04401
AC
279 fprintf_unfiltered (file, _("The target endianness is set automatically "
280 "(currently big endian)\n"));
edefbb7c 281 else
7ab04401 282 fprintf_unfiltered (file, _("The target endianness is set automatically "
3e43a32a 283 "(currently little endian)\n"));
b4a20239 284 else
e17c207e 285 if (target_byte_order_user == BFD_ENDIAN_BIG)
7ab04401
AC
286 fprintf_unfiltered (file,
287 _("The target is assumed to be big endian\n"));
288 else
289 fprintf_unfiltered (file,
290 _("The target is assumed to be little endian\n"));
b4a20239
AC
291}
292
293static void
294set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
295{
7a107747
DJ
296 struct gdbarch_info info;
297
298 gdbarch_info_init (&info);
299
3fd3d7d2 300 if (set_endian_string == endian_auto)
b4a20239 301 {
7a107747
DJ
302 target_byte_order_user = BFD_ENDIAN_UNKNOWN;
303 if (! gdbarch_update_p (info))
304 internal_error (__FILE__, __LINE__,
305 _("set_endian: architecture update failed"));
b4a20239
AC
306 }
307 else if (set_endian_string == endian_little)
308 {
d90cf509
AC
309 info.byte_order = BFD_ENDIAN_LITTLE;
310 if (! gdbarch_update_p (info))
edefbb7c 311 printf_unfiltered (_("Little endian target not supported by GDB\n"));
7a107747
DJ
312 else
313 target_byte_order_user = BFD_ENDIAN_LITTLE;
b4a20239
AC
314 }
315 else if (set_endian_string == endian_big)
316 {
d90cf509
AC
317 info.byte_order = BFD_ENDIAN_BIG;
318 if (! gdbarch_update_p (info))
edefbb7c 319 printf_unfiltered (_("Big endian target not supported by GDB\n"));
7a107747
DJ
320 else
321 target_byte_order_user = BFD_ENDIAN_BIG;
b4a20239
AC
322 }
323 else
8e65ff28 324 internal_error (__FILE__, __LINE__,
edefbb7c 325 _("set_endian: bad value"));
7a107747 326
7ab04401 327 show_endian (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
328}
329
23181151 330/* Given SELECTED, a currently selected BFD architecture, and
e35359c5
UW
331 TARGET_DESC, the current target description, return what
332 architecture to use.
333
334 SELECTED may be NULL, in which case we return the architecture
335 associated with TARGET_DESC. If SELECTED specifies a variant
336 of the architecture associtated with TARGET_DESC, return the
337 more specific of the two.
338
339 If SELECTED is a different architecture, but it is accepted as
340 compatible by the target, we can use the target architecture.
341
342 If SELECTED is obviously incompatible, warn the user. */
23181151
DJ
343
344static const struct bfd_arch_info *
e35359c5
UW
345choose_architecture_for_target (const struct target_desc *target_desc,
346 const struct bfd_arch_info *selected)
23181151 347{
e35359c5 348 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
23181151
DJ
349 const struct bfd_arch_info *compat1, *compat2;
350
351 if (selected == NULL)
352 return from_target;
353
354 if (from_target == NULL)
355 return selected;
356
357 /* struct bfd_arch_info objects are singletons: that is, there's
358 supposed to be exactly one instance for a given machine. So you
359 can tell whether two are equivalent by comparing pointers. */
360 if (from_target == selected)
361 return selected;
362
363 /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
364 incompatible. But if they are compatible, it returns the 'more
365 featureful' of the two arches. That is, if A can run code
366 written for B, but B can't run code written for A, then it'll
367 return A.
368
369 Some targets (e.g. MIPS as of 2006-12-04) don't fully
370 implement this, instead always returning NULL or the first
371 argument. We detect that case by checking both directions. */
372
373 compat1 = selected->compatible (selected, from_target);
374 compat2 = from_target->compatible (from_target, selected);
375
376 if (compat1 == NULL && compat2 == NULL)
377 {
0e2de366
MS
378 /* BFD considers the architectures incompatible. Check our
379 target description whether it accepts SELECTED as compatible
380 anyway. */
e35359c5
UW
381 if (tdesc_compatible_p (target_desc, selected))
382 return from_target;
383
23181151
DJ
384 warning (_("Selected architecture %s is not compatible "
385 "with reported target architecture %s"),
386 selected->printable_name, from_target->printable_name);
387 return selected;
388 }
389
390 if (compat1 == NULL)
391 return compat2;
392 if (compat2 == NULL)
393 return compat1;
394 if (compat1 == compat2)
395 return compat1;
396
0e2de366
MS
397 /* If the two didn't match, but one of them was a default
398 architecture, assume the more specific one is correct. This
399 handles the case where an executable or target description just
400 says "mips", but the other knows which MIPS variant. */
23181151
DJ
401 if (compat1->the_default)
402 return compat2;
403 if (compat2->the_default)
404 return compat1;
405
406 /* We have no idea which one is better. This is a bug, but not
407 a critical problem; warn the user. */
408 warning (_("Selected architecture %s is ambiguous with "
409 "reported target architecture %s"),
410 selected->printable_name, from_target->printable_name);
411 return selected;
412}
413
0e2de366 414/* Functions to manipulate the architecture of the target. */
b4a20239
AC
415
416enum set_arch { set_arch_auto, set_arch_manual };
417
7a107747 418static const struct bfd_arch_info *target_architecture_user;
b4a20239 419
a8cf2722
AC
420static const char *set_architecture_string;
421
422const char *
423selected_architecture_name (void)
424{
7a107747 425 if (target_architecture_user == NULL)
a8cf2722
AC
426 return NULL;
427 else
428 return set_architecture_string;
429}
b4a20239 430
b4a20239 431/* Called if the user enters ``show architecture'' without an
0e2de366 432 argument. */
b4a20239
AC
433
434static void
7ab04401
AC
435show_architecture (struct ui_file *file, int from_tty,
436 struct cmd_list_element *c, const char *value)
b4a20239 437{
7a107747 438 if (target_architecture_user == NULL)
3e43a32a
MS
439 fprintf_filtered (file, _("The target architecture is set "
440 "automatically (currently %s)\n"),
441 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
b4a20239 442 else
3e43a32a
MS
443 fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
444 set_architecture_string);
b4a20239
AC
445}
446
447
448/* Called if the user enters ``set architecture'' with or without an
0e2de366 449 argument. */
b4a20239
AC
450
451static void
452set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
453{
7a107747
DJ
454 struct gdbarch_info info;
455
456 gdbarch_info_init (&info);
457
b4a20239
AC
458 if (strcmp (set_architecture_string, "auto") == 0)
459 {
7a107747
DJ
460 target_architecture_user = NULL;
461 if (!gdbarch_update_p (info))
462 internal_error (__FILE__, __LINE__,
463 _("could not select an architecture automatically"));
b4a20239 464 }
d90cf509 465 else
b4a20239 466 {
b4a20239
AC
467 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
468 if (info.bfd_arch_info == NULL)
8e65ff28 469 internal_error (__FILE__, __LINE__,
edefbb7c 470 _("set_architecture: bfd_scan_arch failed"));
16f33e29 471 if (gdbarch_update_p (info))
7a107747 472 target_architecture_user = info.bfd_arch_info;
b4a20239 473 else
edefbb7c 474 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
b4a20239
AC
475 set_architecture_string);
476 }
7ab04401 477 show_architecture (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
478}
479
ebdba546 480/* Try to select a global architecture that matches "info". Return
0f9741f2 481 non-zero if the attempt succeeds. */
ebdba546
AC
482int
483gdbarch_update_p (struct gdbarch_info info)
484{
a7f1256d
UW
485 struct gdbarch *new_gdbarch;
486
487 /* Check for the current file. */
488 if (info.abfd == NULL)
489 info.abfd = exec_bfd;
490 if (info.abfd == NULL)
491 info.abfd = core_bfd;
492
493 /* Check for the current target description. */
494 if (info.target_desc == NULL)
495 info.target_desc = target_current_description ();
496
497 new_gdbarch = gdbarch_find_by_info (info);
ebdba546
AC
498
499 /* If there no architecture by that name, reject the request. */
500 if (new_gdbarch == NULL)
501 {
502 if (gdbarch_debug)
503 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
504 "Architecture not found\n");
505 return 0;
506 }
507
508 /* If it is the same old architecture, accept the request (but don't
509 swap anything). */
f5656ead 510 if (new_gdbarch == target_gdbarch ())
ebdba546
AC
511 {
512 if (gdbarch_debug)
513 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
e3cb3832
JB
514 "Architecture %s (%s) unchanged\n",
515 host_address_to_string (new_gdbarch),
ebdba546
AC
516 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
517 return 1;
518 }
519
520 /* It's a new architecture, swap it in. */
521 if (gdbarch_debug)
522 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
e3cb3832
JB
523 "New architecture %s (%s) selected\n",
524 host_address_to_string (new_gdbarch),
ebdba546 525 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
aff68abb 526 set_target_gdbarch (new_gdbarch);
ebdba546
AC
527
528 return 1;
529}
530
2b026650
MK
531/* Return the architecture for ABFD. If no suitable architecture
532 could be find, return NULL. */
533
534struct gdbarch *
535gdbarch_from_bfd (bfd *abfd)
b4a20239 536{
d90cf509
AC
537 struct gdbarch_info info;
538 gdbarch_info_init (&info);
05c547f6 539
d90cf509 540 info.abfd = abfd;
b60eb90d 541 return gdbarch_find_by_info (info);
2b026650
MK
542}
543
544/* Set the dynamic target-system-dependent parameters (architecture,
545 byte-order) using information found in the BFD */
546
547void
548set_gdbarch_from_file (bfd *abfd)
549{
a7f1256d 550 struct gdbarch_info info;
2b026650
MK
551 struct gdbarch *gdbarch;
552
a7f1256d
UW
553 gdbarch_info_init (&info);
554 info.abfd = abfd;
555 info.target_desc = target_current_description ();
556 gdbarch = gdbarch_find_by_info (info);
557
2b026650 558 if (gdbarch == NULL)
8a3fe4f8 559 error (_("Architecture of file not recognized."));
aff68abb 560 set_target_gdbarch (gdbarch);
b4a20239
AC
561}
562
563/* Initialize the current architecture. Update the ``set
564 architecture'' command so that it specifies a list of valid
565 architectures. */
566
1ba607ad
AC
567#ifdef DEFAULT_BFD_ARCH
568extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
569static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
570#else
4b9b3959 571static const bfd_arch_info_type *default_bfd_arch;
1ba607ad
AC
572#endif
573
574#ifdef DEFAULT_BFD_VEC
575extern const bfd_target DEFAULT_BFD_VEC;
576static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
577#else
578static const bfd_target *default_bfd_vec;
579#endif
580
7a107747
DJ
581static int default_byte_order = BFD_ENDIAN_UNKNOWN;
582
b4a20239
AC
583void
584initialize_current_architecture (void)
585{
586 const char **arches = gdbarch_printable_names ();
05c547f6 587 struct gdbarch_info info;
b4a20239 588
0e2de366 589 /* determine a default architecture and byte order. */
fb6ecb0f 590 gdbarch_info_init (&info);
1ba607ad 591
0e2de366 592 /* Find a default architecture. */
7a107747 593 if (default_bfd_arch == NULL)
b4a20239 594 {
1ba607ad 595 /* Choose the architecture by taking the first one
0e2de366 596 alphabetically. */
1ba607ad 597 const char *chosen = arches[0];
b4a20239 598 const char **arch;
b4a20239
AC
599 for (arch = arches; *arch != NULL; arch++)
600 {
b4a20239
AC
601 if (strcmp (*arch, chosen) < 0)
602 chosen = *arch;
603 }
604 if (chosen == NULL)
8e65ff28 605 internal_error (__FILE__, __LINE__,
edefbb7c 606 _("initialize_current_architecture: No arch"));
7a107747
DJ
607 default_bfd_arch = bfd_scan_arch (chosen);
608 if (default_bfd_arch == NULL)
8e65ff28 609 internal_error (__FILE__, __LINE__,
edefbb7c 610 _("initialize_current_architecture: Arch not found"));
1ba607ad
AC
611 }
612
7a107747
DJ
613 info.bfd_arch_info = default_bfd_arch;
614
afe64c1a 615 /* Take several guesses at a byte order. */
7a107747 616 if (default_byte_order == BFD_ENDIAN_UNKNOWN
1ba607ad
AC
617 && default_bfd_vec != NULL)
618 {
0e2de366 619 /* Extract BFD's default vector's byte order. */
1ba607ad
AC
620 switch (default_bfd_vec->byteorder)
621 {
622 case BFD_ENDIAN_BIG:
7a107747 623 default_byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
624 break;
625 case BFD_ENDIAN_LITTLE:
7a107747 626 default_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad
AC
627 break;
628 default:
629 break;
630 }
631 }
7a107747 632 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad 633 {
0e2de366 634 /* look for ``*el-*'' in the target name. */
1ba607ad
AC
635 const char *chp;
636 chp = strchr (target_name, '-');
637 if (chp != NULL
638 && chp - 2 >= target_name
639 && strncmp (chp - 2, "el", 2) == 0)
7a107747 640 default_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad 641 }
7a107747 642 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad
AC
643 {
644 /* Wire it to big-endian!!! */
7a107747 645 default_byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
646 }
647
7a107747 648 info.byte_order = default_byte_order;
9d4fde75 649 info.byte_order_for_code = info.byte_order;
7a107747 650
d90cf509
AC
651 if (! gdbarch_update_p (info))
652 internal_error (__FILE__, __LINE__,
edefbb7c
AC
653 _("initialize_current_architecture: Selection of "
654 "initial architecture failed"));
b4a20239 655
1ba607ad 656 /* Create the ``set architecture'' command appending ``auto'' to the
0e2de366 657 list of architectures. */
b4a20239 658 {
0e2de366 659 /* Append ``auto''. */
b4a20239
AC
660 int nr;
661 for (nr = 0; arches[nr] != NULL; nr++);
662 arches = xrealloc (arches, sizeof (char*) * (nr + 2));
663 arches[nr + 0] = "auto";
664 arches[nr + 1] = NULL;
7ab04401 665 add_setshow_enum_cmd ("architecture", class_support,
3e43a32a
MS
666 arches, &set_architecture_string,
667 _("Set architecture of target."),
668 _("Show architecture of target."), NULL,
7ab04401
AC
669 set_architecture, show_architecture,
670 &setlist, &showlist);
b4a20239 671 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
b4a20239
AC
672 }
673}
674
675
fb6ecb0f
AC
676/* Initialize a gdbarch info to values that will be automatically
677 overridden. Note: Originally, this ``struct info'' was initialized
ce2826aa 678 using memset(0). Unfortunately, that ran into problems, namely
fb6ecb0f
AC
679 BFD_ENDIAN_BIG is zero. An explicit initialization function that
680 can explicitly set each field to a well defined value is used. */
681
682void
683gdbarch_info_init (struct gdbarch_info *info)
684{
685 memset (info, 0, sizeof (struct gdbarch_info));
428721aa 686 info->byte_order = BFD_ENDIAN_UNKNOWN;
9d4fde75 687 info->byte_order_for_code = info->byte_order;
4be87837 688 info->osabi = GDB_OSABI_UNINITIALIZED;
fb6ecb0f
AC
689}
690
100bcc3f 691/* Similar to init, but this time fill in the blanks. Information is
7a107747
DJ
692 obtained from the global "set ..." options and explicitly
693 initialized INFO fields. */
bf922ad9
AC
694
695void
7a107747 696gdbarch_info_fill (struct gdbarch_info *info)
bf922ad9
AC
697{
698 /* "(gdb) set architecture ...". */
699 if (info->bfd_arch_info == NULL
7a107747
DJ
700 && target_architecture_user)
701 info->bfd_arch_info = target_architecture_user;
424163ea 702 /* From the file. */
bf922ad9
AC
703 if (info->bfd_arch_info == NULL
704 && info->abfd != NULL
705 && bfd_get_arch (info->abfd) != bfd_arch_unknown
706 && bfd_get_arch (info->abfd) != bfd_arch_obscure)
707 info->bfd_arch_info = bfd_get_arch_info (info->abfd);
23181151
DJ
708 /* From the target. */
709 if (info->target_desc != NULL)
710 info->bfd_arch_info = choose_architecture_for_target
e35359c5 711 (info->target_desc, info->bfd_arch_info);
7a107747
DJ
712 /* From the default. */
713 if (info->bfd_arch_info == NULL)
714 info->bfd_arch_info = default_bfd_arch;
bf922ad9
AC
715
716 /* "(gdb) set byte-order ...". */
717 if (info->byte_order == BFD_ENDIAN_UNKNOWN
7a107747
DJ
718 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
719 info->byte_order = target_byte_order_user;
bf922ad9
AC
720 /* From the INFO struct. */
721 if (info->byte_order == BFD_ENDIAN_UNKNOWN
722 && info->abfd != NULL)
723 info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
7a107747
DJ
724 : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
725 : BFD_ENDIAN_UNKNOWN);
726 /* From the default. */
727 if (info->byte_order == BFD_ENDIAN_UNKNOWN)
728 info->byte_order = default_byte_order;
9d4fde75 729 info->byte_order_for_code = info->byte_order;
bf922ad9
AC
730
731 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
08d16641 732 /* From the manual override, or from file. */
bf922ad9
AC
733 if (info->osabi == GDB_OSABI_UNINITIALIZED)
734 info->osabi = gdbarch_lookup_osabi (info->abfd);
08d16641
PA
735 /* From the target. */
736 if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
737 info->osabi = tdesc_osabi (info->target_desc);
738 /* From the configured default. */
f4290e2a 739#ifdef GDB_OSABI_DEFAULT
08d16641
PA
740 if (info->osabi == GDB_OSABI_UNKNOWN)
741 info->osabi = GDB_OSABI_DEFAULT;
f4290e2a 742#endif
bf922ad9
AC
743
744 /* Must have at least filled in the architecture. */
745 gdb_assert (info->bfd_arch_info != NULL);
746}
747
0e2de366
MS
748/* Return "current" architecture. If the target is running, this is
749 the architecture of the selected frame. Otherwise, the "current"
750 architecture defaults to the target architecture.
e17c207e 751
0e2de366
MS
752 This function should normally be called solely by the command
753 interpreter routines to determine the architecture to execute a
754 command in. */
e17c207e
UW
755struct gdbarch *
756get_current_arch (void)
757{
758 if (has_stack_frames ())
759 return get_frame_arch (get_selected_frame (NULL));
760 else
f5656ead 761 return target_gdbarch ();
e17c207e
UW
762}
763
6c95b8df
PA
764int
765default_has_shared_address_space (struct gdbarch *gdbarch)
766{
767 /* Simply say no. In most unix-like targets each inferior/process
768 has its own address space. */
769 return 0;
770}
771
7a697b8d
SS
772int
773default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
774 CORE_ADDR addr, int *isize, char **msg)
775{
776 /* We don't know if maybe the target has some way to do fast
777 tracepoints that doesn't need gdbarch, so always say yes. */
778 if (msg)
779 *msg = NULL;
780 return 1;
781}
782
a1dcb23a
DJ
783void
784default_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
785 int *kindptr)
786{
787 gdbarch_breakpoint_from_pc (gdbarch, pcptr, kindptr);
788}
789
6710bf39
SS
790void
791default_gen_return_address (struct gdbarch *gdbarch,
792 struct agent_expr *ax, struct axs_value *value,
793 CORE_ADDR scope)
794{
795 error (_("This architecture has no method to collect a return address."));
796}
797
18648a37
YQ
798int
799default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
800 struct type *type)
801{
802 /* Usually, the return value's address is stored the in the "first hidden"
803 parameter if the return value should be passed by reference, as
804 specified in ABI. */
805 return language_pass_by_reference (type);
806}
807
c2170eef
MM
808int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
809{
810 return 0;
811}
812
813int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
814{
815 return 0;
816}
817
818int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
819{
820 return 0;
821}
822
c0e8c252
AC
823/* */
824
3e43a32a
MS
825/* -Wmissing-prototypes */
826extern initialize_file_ftype _initialize_gdbarch_utils;
c0e8c252
AC
827
828void
b4a20239 829_initialize_gdbarch_utils (void)
c0e8c252 830{
7ab04401 831 add_setshow_enum_cmd ("endian", class_support,
3e43a32a
MS
832 endian_enum, &set_endian_string,
833 _("Set endianness of target."),
834 _("Show endianness of target."),
835 NULL, set_endian, show_endian,
7ab04401 836 &setlist, &showlist);
c0e8c252 837}
This page took 0.951879 seconds and 4 git commands to generate.