* top.c (target_byte_order_auto): New static variable.

(set_endian): Mention that ``auto'' is permitted.
	(set_endian_auto): New static function.
	(show_endian): Change message based on target_byte_order_auto.
	(set_endian_from_file): New function.
	(init_main): Add command ``auto'' to endianlist.
	* exec.c (exec_file_command): Call set_endian_from_file.
	* defs.h (set_endian_from_file): Declare.
This commit is contained in:
Ian Lance Taylor
1994-10-07 16:20:21 +00:00
parent c9228cfe64
commit b83ed01952
3 changed files with 84 additions and 17 deletions

View File

@ -1,3 +1,14 @@
Fri Oct 7 12:17:17 1994 Ian Lance Taylor <ian@sanguine.cygnus.com>
* top.c (target_byte_order_auto): New static variable.
(set_endian): Mention that ``auto'' is permitted.
(set_endian_auto): New static function.
(show_endian): Change message based on target_byte_order_auto.
(set_endian_from_file): New function.
(init_main): Add command ``auto'' to endianlist.
* exec.c (exec_file_command): Call set_endian_from_file.
* defs.h (set_endian_from_file): Declare.
Thu Oct 6 18:10:41 1994 J.T. Conklin (jtc@phishhead.cygnus.com) Thu Oct 6 18:10:41 1994 J.T. Conklin (jtc@phishhead.cygnus.com)
* nlm/i386.c (flush_i_cache): New function, does nothing. * nlm/i386.c (flush_i_cache): New function, does nothing.

View File

@ -1,5 +1,5 @@
/* Work with executable files, for GDB. /* 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. This file is part of GDB.
@ -184,7 +184,7 @@ exec_file_command (args, from_tty)
text_start = ~(CORE_ADDR)0; text_start = ~(CORE_ADDR)0;
text_end = (CORE_ADDR)0; text_end = (CORE_ADDR)0;
for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) 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)) & (SEC_CODE | SEC_READONLY))
{ {
if (text_start > p->addr) if (text_start > p->addr)
@ -197,6 +197,8 @@ exec_file_command (args, from_tty)
validate_files (); validate_files ();
set_endian_from_file (exec_bfd);
push_target (&exec_ops); push_target (&exec_ops);
/* Tell display code (if any) about the changed file name. */ /* Tell display code (if any) about the changed file name. */
@ -242,7 +244,7 @@ add_to_section_table (abfd, asect, table_pp_char)
if (0 == bfd_section_size (abfd, asect)) if (0 == bfd_section_size (abfd, asect))
return; return;
(*table_pp)->bfd = abfd; (*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)->addr = bfd_section_vma (abfd, asect);
(*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect); (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
(*table_pp)++; (*table_pp)++;
@ -314,8 +316,8 @@ xfer_memory (memaddr, myaddr, len, write, target)
if (p->endaddr >= memend) if (p->endaddr >= memend)
{ {
/* Entire transfer is within this section. */ /* Entire transfer is within this section. */
res = xfer_fn (p->bfd, p->sec_ptr, myaddr, memaddr - p->addr, len); res = xfer_fn (p->bfd, p->the_bfd_section, myaddr, memaddr - p->addr, len);
return (res != false)? len: 0; return (res != 0) ? len : 0;
} }
else if (p->endaddr <= memaddr) else if (p->endaddr <= memaddr)
{ {
@ -326,8 +328,8 @@ xfer_memory (memaddr, myaddr, len, write, target)
{ {
/* This section overlaps the transfer. Just do half. */ /* This section overlaps the transfer. Just do half. */
len = p->endaddr - memaddr; len = p->endaddr - memaddr;
res = xfer_fn (p->bfd, p->sec_ptr, myaddr, memaddr - p->addr, len); res = xfer_fn (p->bfd, p->the_bfd_section, myaddr, memaddr - p->addr, len);
return (res != false)? len: 0; return (res != 0) ? len : 0;
} }
else if (p->addr < nextsectaddr) else if (p->addr < nextsectaddr)
nextsectaddr = p->addr; nextsectaddr = p->addr;
@ -364,9 +366,12 @@ print_section_info (t, abfd)
printf_filtered ("\t`%s', ", bfd_get_filename(abfd)); printf_filtered ("\t`%s', ", bfd_get_filename(abfd));
wrap_here (" "); wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target(abfd)); printf_filtered ("file type %s.\n", bfd_get_target(abfd));
if (abfd == exec_bfd)
{
printf_filtered ("\tEntry point: "); printf_filtered ("\tEntry point: ");
print_address_numeric (bfd_get_start_address (exec_bfd), gdb_stdout); print_address_numeric (bfd_get_start_address (abfd), 1, gdb_stdout);
printf_filtered ("\n"); printf_filtered ("\n");
}
for (p = t->to_sections; p < t->to_sections_end; p++) for (p = t->to_sections; p < t->to_sections_end; p++)
{ {
/* FIXME-32x64 need a print_address_numeric with field width */ /* FIXME-32x64 need a print_address_numeric with field width */
@ -374,8 +379,8 @@ print_section_info (t, abfd)
printf_filtered (" - %s", local_hex_string_custom ((unsigned long) p->endaddr, "08l")); printf_filtered (" - %s", local_hex_string_custom ((unsigned long) p->endaddr, "08l"));
if (info_verbose) if (info_verbose)
printf_filtered (" @ %s", printf_filtered (" @ %s",
local_hex_string_custom ((unsigned long) p->sec_ptr->filepos, "08l")); local_hex_string_custom ((unsigned long) p->the_bfd_section->filepos, "08l"));
printf_filtered (" is %s", bfd_section_name (p->bfd, p->sec_ptr)); printf_filtered (" is %s", bfd_section_name (p->bfd, p->the_bfd_section));
if (p->bfd != abfd) if (p->bfd != abfd)
{ {
printf_filtered (" in %s", bfd_get_filename (p->bfd)); printf_filtered (" in %s", bfd_get_filename (p->bfd));
@ -414,8 +419,8 @@ set_section_command (args, from_tty)
secaddr = parse_and_eval_address (args); secaddr = parse_and_eval_address (args);
for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) { 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) if (!strncmp (secname, bfd_section_name (exec_bfd, p->the_bfd_section), seclen)
&& bfd_section_name (exec_bfd, p->sec_ptr)[seclen] == '\0') { && bfd_section_name (exec_bfd, p->the_bfd_section)[seclen] == '\0') {
offset = secaddr - p->addr; offset = secaddr - p->addr;
p->addr += offset; p->addr += offset;
p->endaddr += offset; p->endaddr += offset;

View File

@ -100,6 +100,8 @@ static void set_endian_big PARAMS ((char *, int));
static void set_endian_little PARAMS ((char *, int)); static void set_endian_little PARAMS ((char *, int));
static void set_endian_auto PARAMS ((char *, int));
static void show_endian PARAMS ((char *, int)); static void show_endian PARAMS ((char *, int));
#endif #endif
@ -2654,13 +2656,15 @@ echo_command (text, from_tty)
int target_byte_order = TARGET_BYTE_ORDER_DEFAULT; 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. */ /* Called if the user enters ``set endian'' without an argument. */
static void static void
set_endian (args, from_tty) set_endian (args, from_tty)
char *args; char *args;
int from_tty; 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); show_endian (args, from_tty);
} }
@ -2671,6 +2675,7 @@ set_endian_big (args, from_tty)
int from_tty; int from_tty;
{ {
target_byte_order = BIG_ENDIAN; target_byte_order = BIG_ENDIAN;
target_byte_order_auto = 0;
} }
/* Called by ``set endian little''. */ /* Called by ``set endian little''. */
@ -2680,6 +2685,16 @@ set_endian_little (args, from_tty)
int from_tty; int from_tty;
{ {
target_byte_order = LITTLE_ENDIAN; 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''. */ /* Called by ``show endian''. */
@ -2688,11 +2703,45 @@ show_endian (args, from_tty)
char *args; char *args;
int from_tty; int from_tty;
{ {
printf_unfiltered ("The target is assumed to be %s endian.\n", const char *msg =
TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"); (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) */ #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) */
}
/* Functions to manipulate command line editing control variables. */ /* Functions to manipulate command line editing control variables. */
@ -2925,6 +2974,8 @@ init_main ()
"Set target as being big endian.", &endianlist); "Set target as being big endian.", &endianlist);
add_cmd ("little", class_support, set_endian_little, add_cmd ("little", class_support, set_endian_little,
"Set target as being little endian.", &endianlist); "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, add_cmd ("endian", class_support, show_endian,
"Show endianness of target.", &showlist); "Show endianness of target.", &showlist);