From patchwork Mon Oct 17 15:15:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 16578 Received: (qmail 123173 invoked by alias); 17 Oct 2016 15:15:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 123152 invoked by uid 89); 17 Oct 2016 15:15:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=Protection, 20161005, 2016-10-05, upcoming X-HELO: mailapp01.imgtec.com Received: from mailapp02.imgtec.com (HELO mailapp01.imgtec.com) (217.156.133.132) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Oct 2016 15:15:47 +0000 Received: from HHMAIL03.hh.imgtec.org (unknown [10.44.0.21]) by Forcepoint Email with ESMTPS id 9F9D626B28476; Mon, 17 Oct 2016 16:15:40 +0100 (IST) Received: from HHMAIL01.hh.imgtec.org (10.100.10.19) by HHMAIL03.hh.imgtec.org (10.44.0.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 17 Oct 2016 16:15:43 +0100 Received: from [10.20.78.147] (10.20.78.147) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server id 14.3.294.0; Mon, 17 Oct 2016 16:15:42 +0100 Date: Mon, 17 Oct 2016 16:15:33 +0100 From: "Maciej W. Rozycki" To: CC: Mark Kettenis Subject: [PATCH] i386-tdep: Verify architecture before proceeding with `set/show mpx' Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Make sure the architecture is `bfd_arch_i386' before handling the `set mpx' and `show mpx' commands, avoiding the issue with `i386_mpx_enabled' interpreting `gdbarch->tdep' according to the `struct gdbarch_tdep' definition in i386-tdep.h while indeed in a multi-target configuration it may have a different layout and cause GDB to crash or at least misbehave. gdb/ * i386-tdep.c (i386_mpx_info_bounds): Make sure the architecture is `bfd_arch_i386' before proceeding. (i386_mpx_set_bounds): Likewise. --- Hi, Noticed in `mips-mti-linux-gnu' `--enable-targets=all' regression testing with an upcoming change which modifies the mips-tdep.h definition of `struct gdbarch_tdep', showing up as: (gdb) PASS: gdb.base/default.exp: info stack info set ada print-signatures: Whether the output of formal and return types for functions in the overloads selection menu is activated is on. [...] mipsfpu: The MIPS floating-point coprocessor is set automatically (currently double-precision) ERROR: Process no longer exists UNRESOLVED: gdb.base/default.exp: info set which is a segfault due to the retrieved numerical value of `tdep->tdesc' being 4 in `i386_mpx_enabled'. With the change in place, the test case now passes, with the expected message produced: (gdb) PASS: gdb.base/default.exp: info stack info set ada print-signatures: Whether the output of formal and return types for functions in the overloads selection menu is activated is on. [...] mipsfpu: The MIPS floating-point coprocessor is set automatically (currently double-precision) mpx bound: Intel Memory Protection Extensions not supported on this target. multiple-symbols: How the debugger handles ambiguities in expressions is "all". [...] write: Writing into executable and core files is off. (gdb) PASS: gdb.base/default.exp: info set I've decided to quit from `i386_mpx_info_bounds' and `i386_mpx_set_bounds' right away for code clarity rather than burying the condition within `i386_mpx_enabled'. OK to apply? Maciej gdb-i386-mpx-arch.diff Index: binutils/gdb/i386-tdep.c =================================================================== --- binutils.orig/gdb/i386-tdep.c 2016-10-05 00:58:08.000000000 +0100 +++ binutils/gdb/i386-tdep.c 2016-10-17 06:28:19.719738724 +0100 @@ -8857,7 +8857,8 @@ i386_mpx_info_bounds (char *args, int fr struct gdbarch *gdbarch = get_current_arch (); struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr; - if (!i386_mpx_enabled ()) + if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_i386 + || !i386_mpx_enabled ()) { printf_unfiltered (_("Intel Memory Protection Extensions not " "supported on this target.\n")); @@ -8900,7 +8901,8 @@ i386_mpx_set_bounds (char *args, int fro enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr; - if (!i386_mpx_enabled ()) + if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_i386 + || !i386_mpx_enabled ()) error (_("Intel Memory Protection Extensions not supported\ on this target."));