/* Work with executable files, for GDB.
- Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
+ Copyright 1988, 1989, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This file is part of GDB.
text_start = ~(CORE_ADDR)0;
text_end = (CORE_ADDR)0;
for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++)
- if (bfd_get_section_flags (p->bfd, p->sec_ptr)
+ if (bfd_get_section_flags (p->bfd, p->the_bfd_section)
& (SEC_CODE | SEC_READONLY))
{
if (text_start > p->addr)
validate_files ();
+ set_endian_from_file (exec_bfd);
+
push_target (&exec_ops);
/* Tell display code (if any) about the changed file name. */
if (0 == bfd_section_size (abfd, asect))
return;
(*table_pp)->bfd = abfd;
- (*table_pp)->sec_ptr = asect;
+ (*table_pp)->the_bfd_section = asect;
(*table_pp)->addr = bfd_section_vma (abfd, asect);
(*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
(*table_pp)++;
if (p->endaddr >= memend)
{
/* Entire transfer is within this section. */
- res = xfer_fn (p->bfd, p->sec_ptr, myaddr, memaddr - p->addr, len);
- return (res != false)? len: 0;
+ res = xfer_fn (p->bfd, p->the_bfd_section, myaddr, memaddr - p->addr, len);
+ return (res != 0) ? len : 0;
}
else if (p->endaddr <= memaddr)
{
{
/* This section overlaps the transfer. Just do half. */
len = p->endaddr - memaddr;
- res = xfer_fn (p->bfd, p->sec_ptr, myaddr, memaddr - p->addr, len);
- return (res != false)? len: 0;
+ res = xfer_fn (p->bfd, p->the_bfd_section, myaddr, memaddr - p->addr, len);
+ return (res != 0) ? len : 0;
}
else if (p->addr < nextsectaddr)
nextsectaddr = p->addr;
printf_filtered ("\t`%s', ", bfd_get_filename(abfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target(abfd));
- printf_filtered ("\tEntry point: ");
- print_address_numeric (bfd_get_start_address (exec_bfd), gdb_stdout);
- printf_filtered ("\n");
+ if (abfd == exec_bfd)
+ {
+ printf_filtered ("\tEntry point: ");
+ print_address_numeric (bfd_get_start_address (abfd), 1, gdb_stdout);
+ printf_filtered ("\n");
+ }
for (p = t->to_sections; p < t->to_sections_end; p++)
{
/* FIXME-32x64 need a print_address_numeric with field width */
printf_filtered (" - %s", local_hex_string_custom ((unsigned long) p->endaddr, "08l"));
if (info_verbose)
printf_filtered (" @ %s",
- local_hex_string_custom ((unsigned long) p->sec_ptr->filepos, "08l"));
- printf_filtered (" is %s", bfd_section_name (p->bfd, p->sec_ptr));
+ local_hex_string_custom ((unsigned long) p->the_bfd_section->filepos, "08l"));
+ printf_filtered (" is %s", bfd_section_name (p->bfd, p->the_bfd_section));
if (p->bfd != abfd)
{
printf_filtered (" in %s", bfd_get_filename (p->bfd));
secaddr = parse_and_eval_address (args);
for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) {
- if (!strncmp (secname, bfd_section_name (exec_bfd, p->sec_ptr), seclen)
- && bfd_section_name (exec_bfd, p->sec_ptr)[seclen] == '\0') {
+ if (!strncmp (secname, bfd_section_name (exec_bfd, p->the_bfd_section), seclen)
+ && bfd_section_name (exec_bfd, p->the_bfd_section)[seclen] == '\0') {
offset = secaddr - p->addr;
p->addr += offset;
p->endaddr += offset;
static void set_endian_little PARAMS ((char *, int));
+static void set_endian_auto PARAMS ((char *, int));
+
static void show_endian PARAMS ((char *, int));
#endif
int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
+static int target_byte_order_auto = 1;
+
/* Called if the user enters ``set endian'' without an argument. */
static void
set_endian (args, from_tty)
char *args;
int from_tty;
{
- printf_unfiltered ("\"set endian\" must be followed by \"big\" or \"little\".\n");
+ printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
show_endian (args, from_tty);
}
int from_tty;
{
target_byte_order = BIG_ENDIAN;
+ target_byte_order_auto = 0;
}
/* Called by ``set endian little''. */
int from_tty;
{
target_byte_order = LITTLE_ENDIAN;
+ target_byte_order_auto = 0;
+}
+
+/* Called by ``set endian auto''. */
+static void
+set_endian_auto (args, from_tty)
+ char *args;
+ int from_tty;
+{
+ target_byte_order_auto = 1;
}
/* Called by ``show endian''. */
char *args;
int from_tty;
{
- printf_unfiltered ("The target is assumed to be %s endian.\n",
- TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+ const char *msg =
+ (target_byte_order_auto
+ ? "The target endianness is set automatically (currently %s endian)\n"
+ : "The target is assumed to be %s endian\n");
+ printf_unfiltered (msg, TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
}
#endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
+
+/* Set the endianness from a BFD. */
+void
+set_endian_from_file (abfd)
+ bfd *abfd;
+{
+#ifdef TARGET_BYTE_ORDER_SELECTABLE
+ int want;
+
+ if (abfd->xvec->byteorder_big_p)
+ want = BIG_ENDIAN;
+ else
+ want = LITTLE_ENDIAN;
+ if (target_byte_order_auto)
+ target_byte_order = want;
+ else if (target_byte_order != want)
+ warning ("%s endian file does not match %s endian target.",
+ want == BIG_ENDIAN ? "big" : "little",
+ TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+
+#else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
+
+ if (abfd->xvec->byteorder_big_p
+ ? TARGET_BYTE_ORDER != BIG_ENDIAN
+ : TARGET_BYTE_ORDER == BIG_ENDIAN)
+ warning ("%s endian file does not match %s endian target.",
+ want == BIG_ENDIAN ? "big" : "little",
+ TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+
+#endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
+}
\f
/* Functions to manipulate command line editing control variables. */
"Set target as being big endian.", &endianlist);
add_cmd ("little", class_support, set_endian_little,
"Set target as being little endian.", &endianlist);
+ add_cmd ("auto", class_support, set_endian_auto,
+ "Select target endianness automatically.", &endianlist);
add_cmd ("endian", class_support, show_endian,
"Show endianness of target.", &showlist);