From patchwork Mon Jan 16 10:02:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 18915 Received: (qmail 54136 invoked by alias); 16 Jan 2017 10:03:33 -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 54059 invoked by uid 89); 16 Jan 2017 10:03:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=CATCH, *self, backs, Hx-spam-relays-external:74.125.83.68 X-HELO: mail-pg0-f68.google.com Received: from mail-pg0-f68.google.com (HELO mail-pg0-f68.google.com) (74.125.83.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jan 2017 10:03:20 +0000 Received: by mail-pg0-f68.google.com with SMTP id 194so5046683pgd.0 for ; Mon, 16 Jan 2017 02:03:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=a0YcdFQo01gDiD2tRnYAEPJZbJVv4xOhXzevAGXauow=; b=jM7Fyew7maRQ6zcLAz6Kleh4NSbeYQGb12Net8FrsffIX80JNyOn7jomlSC0badiKi ERIrFOqYXevKNXTrz7J8ZgSmDEmnAL5jzIHmxFFbmvJtPq2Q2c+gY//9l8mDp1jlRIrL adNJ/0KYfLzj71fEla9YXjUqOkDP/C49SUO+Y4zpDmE5mk0JFF1BVzvczKaz2LoXVpYO ZOSCibGr6zYEcLFZafsnRVV2LdmI0y4/1gaT71LxBe7h2SYfw5Ex0YEODgHQzPyzQFGV HqVup+doFUgrIZSwZ/J4hfPq/Nemvv5eefKwHHKzy5t9CBsG5/TjKa5tyYLioX/Vr7Hc xXkg== X-Gm-Message-State: AIkVDXIjxhHoyL6e5sTQcnxm23ibERkjHsMYxfSb7MekDv6iIXRUl6fDgakQJkFzBDQs2w== X-Received: by 10.99.215.5 with SMTP id d5mr4828919pgg.51.1484560998823; Mon, 16 Jan 2017 02:03:18 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id g28sm9695206pgn.3.2017.01.16.02.03.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Jan 2017 02:03:18 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 6/6] Don't throw exception in dis_asm_memory_error Date: Mon, 16 Jan 2017 10:02:57 +0000 Message-Id: <1484560977-8693-7-git-send-email-yao.qi@linaro.org> In-Reply-To: <1484560977-8693-1-git-send-email-yao.qi@linaro.org> References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> <1484560977-8693-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes Hi, GDB calls some APIs from opcodes to do disassembly and provide some call backs. This model makes troubles on C++ exception unwinding, because GDB is a C++ program, and opcodes is still compiled as C. As we can see, frame #10 and #12 are C++, while #frame 11 is C, #10 0x0000000000544228 in memory_error (err=TARGET_XFER_E_IO, memaddr=) at ../../binutils-gdb/gdb/corefile.c:237 #11 0x00000000006b0a54 in print_insn_aarch64 (pc=0, info=0xffffffffeeb0) at ../../binutils-gdb/opcodes/aarch64-dis.c:3185 #12 0x0000000000553590 in gdb_pretty_print_insn (gdbarch=gdbarch@entry=0xbbceb0, uiout=uiout@entry=0xbc73d0, di=di@entry=0xffffffffeeb0, insn=0xffffffffed40, insn@entry=0xffffffffed90, flags=flags@entry=0, C++ exception unwinder can't go across frame #11 unless it has unwind table. However, C program on many architectures doesn't have it in default. As a result, GDB aborts, which is described in PR 20939. This is not the first time we see this kind of problem. We've had a commit 89525768cd086a0798a504c81fdf7ebcd4c904e1 "Propagate GDB/C++ exceptions across readline using sj/lj-based TRY/CATCH". We can fix the disassembly bug in a similar way, this is the option one. Since opcodes is built with gdb, we fix this problem in a different way as we did for the same issue with readline. Instead of throwing exception in dis_asm_memory_error, we record the failed memory address, and throw exception when GDB returns from opcodes disassemblers. gdb: 2017-01-10 Yao Qi Pedro Alves PR gdb/20939 * disasm.c (gdb_disassembler::dis_asm_memory_error): Don't call memory_error, save memaddr instead. (gdb_disassembler::print_insn): If gdbarch_print_insn returns negative, cal memory_error. * disasm.h (gdb_disassembler) : New field. gdb/testsuite: 2017-01-10 Yao Qi * gdb.base/all-architectures.exp.in (do_arch_tests): Test disassemble on address 0. --- gdb/disasm.c | 13 +++++++++++-- gdb/disasm.h | 1 + gdb/testsuite/gdb.base/all-architectures.exp.in | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gdb/disasm.c b/gdb/disasm.c index f31d8d3..8c8c42e 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -135,7 +135,10 @@ void gdb_disassembler::dis_asm_memory_error (int err, bfd_vma memaddr, struct disassemble_info *info) { - memory_error (TARGET_XFER_E_IO, memaddr); + gdb_disassembler *self + = static_cast(info->application_data); + + self->m_err_memaddr = memaddr; } /* Like print_address with slightly different parameters. */ @@ -765,7 +768,8 @@ fprintf_disasm (void *stream, const char *format, ...) gdb_disassembler::gdb_disassembler (struct gdbarch *gdbarch, struct ui_file *file, di_read_memory_ftype read_memory_func) - : m_gdbarch (gdbarch) + : m_gdbarch (gdbarch), + m_err_memaddr (0) { init_disassemble_info (&m_di, file, fprintf_disasm); m_di.flavour = bfd_target_unknown_flavour; @@ -792,8 +796,13 @@ int gdb_disassembler::print_insn (CORE_ADDR memaddr, int *branch_delay_insns) { + m_err_memaddr = 0; + int length = gdbarch_print_insn (arch (), memaddr, &m_di); + if (length < 0) + memory_error (TARGET_XFER_E_IO, m_err_memaddr); + if (branch_delay_insns != NULL) { if (m_di.insn_info_valid) diff --git a/gdb/disasm.h b/gdb/disasm.h index 5122fa3..8e0b9f9 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -63,6 +63,7 @@ protected: private: struct gdbarch *m_gdbarch; struct disassemble_info m_di; + CORE_ADDR m_err_memaddr; static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len, diff --git a/gdb/testsuite/gdb.base/all-architectures.exp.in b/gdb/testsuite/gdb.base/all-architectures.exp.in index c7615ac..50a615c 100644 --- a/gdb/testsuite/gdb.base/all-architectures.exp.in +++ b/gdb/testsuite/gdb.base/all-architectures.exp.in @@ -152,6 +152,9 @@ proc print_floats {} { proc do_arch_tests {} { print_floats + + gdb_test_internal "disassemble 0x0,+4" \ + "Cannot access memory at address 0x0" } # Given we can't change arch, osabi, endianness, etc. atomically, we