From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70695 invoked by alias); 11 Jan 2017 21:15:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 70678 invoked by uid 89); 11 Jan 2017 21:15:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=H*f:sk:1484051, Hx-languages-length:2379 X-Spam-User: qpsmtpd, 2 recipients X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jan 2017 21:15:16 +0000 Received: by simark.ca (Postfix, from userid 33) id 0206F1E851; Wed, 11 Jan 2017 16:15:13 -0500 (EST) To: Yao Qi Subject: Re: [PATCH 3/8] Disassembly unit test: disassemble one instruction X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 11 Jan 2017 21:15:00 -0000 From: Simon Marchi Cc: binutils@sourceware.org, gdb-patches@sourceware.org In-Reply-To: <1484051178-16013-4-git-send-email-yao.qi@linaro.org> References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> <1484051178-16013-4-git-send-email-yao.qi@linaro.org> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.3 X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00199.txt.bz2 On 2017-01-10 07:26, Yao Qi wrote: > @@ -290,6 +294,139 @@ gdb_disassembler::pretty_print_insn (struct > ui_out *uiout, > return size; > } > > +#if GDB_SELF_TEST > + > +namespace selftests { > + > +/* Test disassembly one instruction. */ I'd say either /* Test disassembly of one instruction. */ or /* Test disassembling one instruction. */ > + > +static void > +gdb_disassembler_print_one_insn_test (struct gdbarch *gdbarch) > +{ > + int len = -1; > + const gdb_byte *insn = NULL; > + > + switch (gdbarch_bfd_arch_info (gdbarch)->arch) > + { > + case bfd_arch_bfin: > + /* M3.L = 0xe117 */ > + insn = (const gdb_byte[]) {0x17, 0xe1, 0xff, 0xff}; > + len = 4; > + break; > + case bfd_arch_arm: > + /* mov r0, #0 */ > + insn = (const gdb_byte[]) {0x0, 0x0, 0xa0, 0xe3}; > + len = 4; > + break; > + case bfd_arch_ia64: > + case bfd_arch_mep: > + case bfd_arch_mips: > + case bfd_arch_tic6x: > + case bfd_arch_xtensa: > + return; > + case bfd_arch_s390: > + /* nopr %r7 */ > + insn = (const gdb_byte[]) {0x07, 0x07}; > + len = 2; > + break; > + case bfd_arch_xstormy16: > + /* nop */ > + insn = (const gdb_byte[]) {0x0, 0x0}; > + len = 2; > + break; > + case bfd_arch_arc: > + { > + /* PR 21003 */ > + if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_arc_arc601) > + return; > + } > + case bfd_arch_nios2: > + case bfd_arch_score: > + insn = gdbarch_sw_breakpoint_from_kind (gdbarch, 4, &len); > + break; > + case bfd_arch_sh: > + insn = gdbarch_sw_breakpoint_from_kind (gdbarch, 2, &len); > + break; Is there a reason why these two can't fall in the default case? If so, maybe add a comment explaining why? > + private: > + const gdb_byte *m_insn; > + > + static int read_memory (bfd_vma memaddr, gdb_byte *myaddr, > + unsigned int len, struct disassemble_info *info) > + { > + gdb_disassembler_test *self > + = static_cast(info->application_data); > + > + memcpy (myaddr, self->m_insn, len); Would this break if the disassembler decided to do a memory read at memaddr != 0? I suppose it doesn't happen in practice now since the test passes, but it might some day, like if we make a test that disassembles more than one instruction. I'd suggest either putting some kind of assert here that memaddr == 0, or consider memaddr in the copy, ideally with some bounds checking.