This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch] Fix gdbarch update logic


Hello,

The attatched patch fixes the logic used to select a new architecture. 
It should fix two bugs:

Given the situtation:

	gdb executable core

where bfd couldn't recognize the core, multi-arch was trying to switch 
the architecture to ``unknown'' instead of just retaining the 
architecture identified in ``executable''.

Given a user entering a command like:

	(gdb) set architecture foo
   or	(gdb) set byte-order big

multi-arch, was for some situtations, ignoring this and instead using 
the architecture supplied by the INFO struct.


This patch changes the logic selecting an architecture so it uses the 
selection sequence:

	Hard wired by (gdb) set ....

	Privided by the INFO struct

	The previous architecture

Andrew
2001-05-12  Andrew Cagney  <ac131313@redhat.com>

	* gdbarch.sh (struct gdbarch_info): Delete field bfd_architecture.
	(gdbarch_update_p): Rewrite logic filling in INFO struct.  Use
	user specified values when available.
	* rs6000-tdep.c (rs6000_gdbarch_init): Update.  Get the
	architecture from info.bfd_arch_info.
	* gdbarch.c, gdbarch.h: Regenerate.

Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.61
diff -p -r1.61 gdbarch.sh
*** gdbarch.sh	2001/05/04 04:15:24	1.61
--- gdbarch.sh	2001/05/14 16:27:00
*************** struct gdbarch_list
*** 838,846 ****
  
  struct gdbarch_info
  {
-   /* Use default: bfd_arch_unknown (ZERO). */
-   enum bfd_architecture bfd_architecture;
- 
    /* Use default: NULL (ZERO). */
    const struct bfd_arch_info *bfd_arch_info;
  
--- 838,843 ----
*************** extern struct gdbarch *gdbarch_alloc (co
*** 893,916 ****
  
  extern void gdbarch_free (struct gdbarch *);
  
  
! /* Helper function. Force an update of the current architecture.  Used
!    by legacy targets that have added their own target specific
!    architecture manipulation commands.
! 
!    The INFO parameter shall be fully initialized (\`\`memset (&INFO,
!    sizeof (info), 0)'' set relevant fields) before gdbarch_update_p()
!    is called.  gdbarch_update_p() shall initialize any \`\`default''
!    fields using information obtained from the previous architecture or
!    INFO.ABFD (if specified) before calling the corresponding
!    architectures INIT function.
  
     Returns non-zero if the update succeeds */
  
  extern int gdbarch_update_p (struct gdbarch_info info);
  
  
 
  /* Register per-architecture data-pointer.
  
     Reserve space for a per-architecture data-pointer.  An identifier
--- 890,908 ----
  
  extern void gdbarch_free (struct gdbarch *);
  
+ 
+ /* Helper function. Force an update of the current architecture.
  
!    The actual architecture selected is determined by INFO, \`\`(gdb) set
!    architecture'' et.al., the existing architecture and BFD's default
!    architecture.  INFO should be initialized to zero and then selected
!    fields should be updated.
  
     Returns non-zero if the update succeeds */
  
  extern int gdbarch_update_p (struct gdbarch_info info);
  
  
  /* Register per-architecture data-pointer.
  
     Reserve space for a per-architecture data-pointer.  An identifier
*************** gdbarch_update_p (struct gdbarch_info in
*** 1945,2017 ****
    struct gdbarch_list **list;
    struct gdbarch_registration *rego;
  
!   /* Fill in any missing bits. Most important is the bfd_architecture
!      which is used to select the target architecture. */
!   if (info.bfd_architecture == bfd_arch_unknown)
!     {
!       if (info.bfd_arch_info != NULL)
! 	info.bfd_architecture = info.bfd_arch_info->arch;
!       else if (info.abfd != NULL)
! 	info.bfd_architecture = bfd_get_arch (info.abfd);
!       /* FIXME - should query BFD for its default architecture. */
!       else
! 	info.bfd_architecture = current_gdbarch->bfd_arch_info->arch;
!     }
    if (info.bfd_arch_info == NULL)
!     {
!       if (target_architecture_auto && info.abfd != NULL)
! 	info.bfd_arch_info = bfd_get_arch_info (info.abfd);
!       else
! 	info.bfd_arch_info = current_gdbarch->bfd_arch_info;
!     }
    if (info.byte_order == 0)
!     {
!       if (target_byte_order_auto && info.abfd != NULL)
! 	info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
! 			   : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
! 			   : 0);
!       else
! 	info.byte_order = current_gdbarch->byte_order;
!       /* FIXME - should query BFD for its default byte-order. */
!     }
!   /* A default for abfd? */
  
!   /* Find the target that knows about this architecture. */
!   for (rego = gdbarch_registry;
!        rego != NULL;
!        rego = rego->next)
!     if (rego->bfd_architecture == info.bfd_architecture)
!       break;
!   if (rego == NULL)
!     {
!       if (gdbarch_debug)
! 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\\n");
!       return 0;
!     }
  
    if (gdbarch_debug)
      {
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.bfd_architecture %d (%s)\\n",
! 			  info.bfd_architecture,
! 			  bfd_lookup_arch (info.bfd_architecture, 0)->printable_name);
!       fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.bfd_arch_info %s\\n",
  			  (info.bfd_arch_info != NULL
  			   ? info.bfd_arch_info->printable_name
  			   : "(null)"));
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.byte_order %d (%s)\\n",
  			  info.byte_order,
  			  (info.byte_order == BIG_ENDIAN ? "big"
  			   : info.byte_order == LITTLE_ENDIAN ? "little"
  			   : "default"));
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.abfd 0x%lx\\n",
  			  (long) info.abfd);
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.tdep_info 0x%lx\\n",
  			  (long) info.tdep_info);
      }
  
    /* Ask the target for a replacement architecture. */
--- 1937,2006 ----
    struct gdbarch_list **list;
    struct gdbarch_registration *rego;
  
!   /* Fill in missing parts of the INFO struct using a number of
!      sources: \`\`set ...''; INFOabfd supplied; existing target.  */
! 
!   /* \`\`(gdb) set architecture ...'' */
!   if (info.bfd_arch_info == NULL
!       && !TARGET_ARCHITECTURE_AUTO)
!     info.bfd_arch_info = TARGET_ARCHITECTURE;
!   if (info.bfd_arch_info == NULL
!       && info.abfd != NULL
!       && bfd_get_arch (info.abfd) != bfd_arch_unknown
!       && bfd_get_arch (info.abfd) != bfd_arch_obscure)
!     info.bfd_arch_info = bfd_get_arch_info (info.abfd);
    if (info.bfd_arch_info == NULL)
!     info.bfd_arch_info = TARGET_ARCHITECTURE;
! 
!   /* \`\`(gdb) set byte-order ...'' */
!   if (info.byte_order == 0
!       && !TARGET_BYTE_ORDER_AUTO)
!     info.byte_order = TARGET_BYTE_ORDER;
!   /* From the INFO struct. */
!   if (info.byte_order == 0
!       && info.abfd != NULL)
!     info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
! 		       : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
! 		       : 0);
!   /* From the current target. */
    if (info.byte_order == 0)
!     info.byte_order = TARGET_BYTE_ORDER;
  
!   /* Must have found some sort of architecture. */
!   gdb_assert (info.bfd_arch_info != NULL);
  
    if (gdbarch_debug)
      {
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.bfd_arch_info %s\n",
  			  (info.bfd_arch_info != NULL
  			   ? info.bfd_arch_info->printable_name
  			   : "(null)"));
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.byte_order %d (%s)\n",
  			  info.byte_order,
  			  (info.byte_order == BIG_ENDIAN ? "big"
  			   : info.byte_order == LITTLE_ENDIAN ? "little"
  			   : "default"));
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.abfd 0x%lx\n",
  			  (long) info.abfd);
        fprintf_unfiltered (gdb_stdlog,
! 			  "gdbarch_update: info.tdep_info 0x%lx\n",
  			  (long) info.tdep_info);
+     }
+ 
+   /* Find the target that knows about this architecture. */
+   for (rego = gdbarch_registry;
+        rego != NULL;
+        rego = rego->next)
+     if (rego->bfd_architecture == info.bfd_arch_info->arch)
+       break;
+   if (rego == NULL)
+     {
+       if (gdbarch_debug)
+ 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\\n");
+       return 0;
      }
  
    /* Ask the target for a replacement architecture. */
Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.22
diff -p -r1.22 rs6000-tdep.c
*** rs6000-tdep.c	2001/05/01 19:36:11	1.22
--- rs6000-tdep.c	2001/05/14 16:27:01
*************** rs6000_gdbarch_init (struct gdbarch_info
*** 2210,2216 ****
  
    if (!from_xcoff_exec)
      {
!       arch = info.bfd_architecture;
        mach = info.bfd_arch_info->mach;
      }
    else
--- 2210,2216 ----
  
    if (!from_xcoff_exec)
      {
!       arch = info.bfd_arch_info->arch;
        mach = info.bfd_arch_info->mach;
      }
    else
Index: doc/gdbint.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdbint.texinfo,v
retrieving revision 1.26
diff -p -r1.26 gdbint.texinfo
*** gdbint.texinfo	2001/05/10 10:29:37	1.26
--- gdbint.texinfo	2001/05/14 16:27:03
*************** status words, and other special register
*** 2667,2673 ****
  @value{GDBN} will assume that all registers may be written.
  
  @item DO_DEFERRED_STORES
! @itemx CLEAR_DEFERRED_STORES@item
  @findex CLEAR_DEFERRED_STORES
  @findex DO_DEFERRED_STORES
  Define this to execute any deferred stores of registers into the inferior,
--- 2667,2673 ----
  @value{GDBN} will assume that all registers may be written.
  
  @item DO_DEFERRED_STORES
! @itemx CLEAR_DEFERRED_STORES
  @findex CLEAR_DEFERRED_STORES
  @findex DO_DEFERRED_STORES
  Define this to execute any deferred stores of registers into the inferior,
*************** Define this to an expression that return
*** 2791,2797 ****
  represented by @var{fi} does not have a stack frame associated with it.
  Otherwise return 0.
  
! @item FRAME_ARGS_ADDRESS_CORRECT@item
  @findex FRAME_ARGS_ADDRESS_CORRECT
  See @file{stack.c}.
  
--- 2791,2797 ----
  represented by @var{fi} does not have a stack frame associated with it.
  Otherwise return 0.
  
! @item FRAME_ARGS_ADDRESS_CORRECT
  @findex FRAME_ARGS_ADDRESS_CORRECT
  See @file{stack.c}.
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]