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