From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30936 invoked by alias); 21 Oct 2003 22:23:00 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 30911 invoked from network); 21 Oct 2003 22:22:59 -0000 Received: from unknown (HELO zenia.home) (12.223.225.216) by sources.redhat.com with SMTP; 21 Oct 2003 22:22:59 -0000 Received: by zenia.home (Postfix, from userid 5433) id 8243120766; Tue, 21 Oct 2003 17:22:55 -0500 (EST) To: gdb-patches@sources.redhat.com Cc: Kris Warkentin , Daniel Jacobowitz Subject: RFA: osabi: correct test for compatible handlers From: Jim Blandy Date: Tue, 21 Oct 2003 22:23:00 -0000 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-10/txt/msg00648.txt.bz2 I think I've found the answer to the question Kris and Daniel were discussing back in June: http://sources.redhat.com/ml/gdb/2003-06/msg00323.html The following patch would, I believe, fix Kris's problem, but the comments also explain why the patch he proposed isn't the right fix. The effect of the patch is to change the existing test: arch_info->compatible (arch_info, handler->arch_info) == handler->arch_info to: arch_info == handler->arch_info || arch_info->compatible (arch_info, handler->arch_info) == arch_info but it's wrapped up and commented in a way that makes it clearer why that is correct. 2003-10-21 Jim Blandy * osabi.c (gdbarch_init_osabi): A handler is okay if it's for an architecture the current arch can run code for --- but not if it's a superset. (can_run_code_for): New function. Index: gdb/osabi.c =================================================================== RCS file: /cvs/src/src/gdb/osabi.c,v retrieving revision 1.17 diff -c -r1.17 osabi.c *** gdb/osabi.c 24 Aug 2003 11:47:18 -0000 1.17 --- gdb/osabi.c 21 Oct 2003 22:15:18 -0000 *************** *** 283,293 **** return match; } void gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) { const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch); - const struct bfd_arch_info *compatible; struct gdb_osabi_handler *handler; if (info.osabi == GDB_OSABI_UNKNOWN) --- 283,311 ---- return match; } + + /* Return non-zero if architecture A can run code written for + architecture B. */ + static int + can_run_code_for (const struct bfd_arch_info *a, const struct bfd_arch_info *b) + { + /* BFD's 'A->compatible (A, B)' functions return zero if A and B are + incompatible. But if they are compatible, it returns the 'more + featureful' of the two arches. That is, if A can run code + written for B, but B can't run code written for A, then it'll + return A. + + struct bfd_arch_info objects are atoms: that is, there's supposed + to be exactly one instance for a given machine. So you can tell + whether two are equivalent by comparing pointers. */ + return (a == b || a->compatible (a, b) == a); + } + + void gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) { const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch); struct gdb_osabi_handler *handler; if (info.osabi == GDB_OSABI_UNKNOWN) *************** *** 303,318 **** if (handler->osabi != info.osabi) continue; ! /* Check whether the machine type and architecture of the ! handler are compatible with the desired machine type and ! architecture. ! NOTE: kettenis/20021027: There may be more than one machine type that is compatible with the desired machine type. Right now we simply return the first match, which is fine for now. However, we might want to do something smarter in the future. */ ! compatible = arch_info->compatible (arch_info, handler->arch_info); ! if (compatible == handler->arch_info) { (*handler->init_osabi) (info, gdbarch); return; --- 321,339 ---- if (handler->osabi != info.osabi) continue; ! /* If the architecture described by ARCH_INFO can run code for ! the architcture we registered the handler for, then the ! handler is applicable. Note, though, that if the handler is ! for an architecture that is a superset of ARCH_INFO, we can't ! use that --- it would be perfectly correct for it to install ! gdbarch methods that refer to registers / instructions / ! other facilities ARCH_INFO doesn't have. ! NOTE: kettenis/20021027: There may be more than one machine type that is compatible with the desired machine type. Right now we simply return the first match, which is fine for now. However, we might want to do something smarter in the future. */ ! if (can_run_code_for (arch_info, handler->arch_info)) { (*handler->init_osabi) (info, gdbarch); return;