Message ID | 83019a6f-ad2e-0ecf-0c07-8fc479e46b7b@redhat.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 95409 invoked by alias); 2 Feb 2017 16:46:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95379 invoked by uid 89); 2 Feb 2017 16:46:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:L, cris, 102, 12, 10212 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Feb 2017 16:46:26 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8CEA3A76B9; Thu, 2 Feb 2017 16:46:25 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12GkONv011873; Thu, 2 Feb 2017 11:46:25 -0500 Subject: Re: [PATCH 4/6] Disassembly unit test: disassemble one instruction To: Yao Qi <qiyaoltc@gmail.com> References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> <1484560977-8693-1-git-send-email-yao.qi@linaro.org> <1484560977-8693-5-git-send-email-yao.qi@linaro.org> <620db0ef-5e3d-3b93-5596-33d24a78f6a9@redhat.com> <20170124152326.GR28060@E107787-LIN> Cc: gdb-patches@sourceware.org From: Pedro Alves <palves@redhat.com> Message-ID: <83019a6f-ad2e-0ecf-0c07-8fc479e46b7b@redhat.com> Date: Thu, 2 Feb 2017 16:46:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170124152326.GR28060@E107787-LIN> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit |
Commit Message
Pedro Alves
Feb. 2, 2017, 4:46 p.m. UTC
On 01/24/2017 03:23 PM, Yao Qi wrote: > On 17-01-20 00:03:48, Pedro Alves wrote: >>> + /* Test gdb_disassembler for a given gdbarch by reading data from a >>> + pre-allocated buffer. If you want to see the disassembled >>> + instruction printed to gdb_stdout, set DISASSEMBLER_TEST_VERBOSE >>> + to true. */ >>> + >>> + class gdb_disassembler_test : public gdb_disassembler >>> + { >>> + public: >>> + >>> + const bool DISASSEMBLER_TEST_VERBOSE = false; >> >> static. We give macros long unique names in order to >> avoid naming conflicts, but if this is no longer a macro, >> the name could be shortened, to e.g., just: >> >> static const bool verbose = false; >> > > gdb_disassembler_test is a local class, so it can't have a static data > member. The end result is broken then, unfortunately. I didn't realize it either until I saw a spurious fail in the gdb.base/unittest.exp test today. Running gdb -ex "maintenance selftest" manually I see: ~~~ Type "apropos word" to search for commands related to "word". warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default ARC600 settings. .long 0x256f003fwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default ARC600 settings. .long 0x256f003fwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default A6 settings. .long 0x256f003fwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default ARC601 settings. warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default ARC700 settings. brkwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default A7 settings. brkwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default ARCv2 settings. brkwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default EM settings. brkwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default HS settings. brkmov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0mov r0, #0breakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakM3.L = 0xffff;/* ( -1) M3=0x0xffff(65535) */break 8break 8warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default cris:common_v10_v32 settings. ~~~ etc. (this is what shows up in the gdb.log too). Note the odd bits of instructions printed. They appear because here: class gdb_disassembler_test : public gdb_disassembler { public: const bool verbose = false; explicit gdb_disassembler_test (struct gdbarch *gdbarch, const gdb_byte *insn, size_t len) : gdb_disassembler (gdbarch, (verbose ? gdb_stdout : &null_stream), gdb_disassembler_test::read_memory), specifically in this line: (verbose ? gdb_stdout : &null_stream), "verbose" has not been initialized yet, because the order of initialization is always base classes first. I.e. "verbose" is only initialized after the base constructor is called. Since the gdb_disassembler_test object is created on the stack, "verbose" has garbage at that point, and thus we end up with the stream incorrectly pointing to gdb_stdout. I was surprised that GCC doesn't warn about this. I filed a GCC bug here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79345 I'm not sure whether this was the reason for the unittest.exp random failure, but I suspect so. (I failed to save the log, and also forgot to check whether all selftests had passed.) The patchlet below fixes the spurious insn printing. OK?
Comments
On Thu, Feb 2, 2017 at 4:46 PM, Pedro Alves <palves@redhat.com> wrote: > > I'm not sure whether this was the reason for the unittest.exp > random failure, but I suspect so. (I failed to save the log, > and also forgot to check whether all selftests had passed.) > > The patchlet below fixes the spurious insn printing. OK? > Yes.
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c index 7d0b006..9eb80b4 100644 --- a/gdb/disasm-selftests.c +++ b/gdb/disasm-selftests.c @@ -102,13 +102,12 @@ print_one_insn_test (struct gdbarch *gdbarch) /* Test gdb_disassembler for a given gdbarch by reading data from a pre-allocated buffer. If you want to see the disassembled instruction printed to gdb_stdout, set verbose to true. */ + static const bool verbose = false; class gdb_disassembler_test : public gdb_disassembler { public: - const bool verbose = false; - explicit gdb_disassembler_test (struct gdbarch *gdbarch, const gdb_byte *insn, size_t len)