From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89511 invoked by alias); 10 Jan 2017 12:26:38 -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 89470 invoked by uid 89); 10 Jan 2017 12:26:37 -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=H*RU:209.85.192.193, Hx-spam-relays-external:209.85.192.193, foreign, HERE X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-pf0-f193.google.com Received: from mail-pf0-f193.google.com (HELO mail-pf0-f193.google.com) (209.85.192.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jan 2017 12:26:27 +0000 Received: by mail-pf0-f193.google.com with SMTP id f144so9892589pfa.2; Tue, 10 Jan 2017 04:26:27 -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; bh=fiGNP9YOk46RX0PwCSkbEPAUvot4K+DKFV+IFzm8Vqg=; b=QA727OkU9WAqmlRhcIAON90n73wO8LXJx9NZKDWhcpNZrzGH/9Ff/vD3VSLo7oJI4A 6uhCllfZ0XhZLn0CTWn0gV5B9iZVR1H8XV++ox1RzdI/0wGNb/Z58937WfZB1rDI0cbZ gZTWiSOuFWNjpvXWG2hwz03NoC6wpdzlk+cJGN8N4BjxD42KmELZJRDmY/tAPXArlIU6 /kgx/qAxpK8xuT/0auqvAY9mq1iMe+Cnp2q1zSiBkefPiQ36VvkgAv2TTEIjvRhy16oe iLVf+KOiKwEdTyFuzLB93eMdH5l52VwHirV0Z5gCtTizRGobBk0V8MUmnGHP+O1ybEVK w1Dw== X-Gm-Message-State: AIkVDXIfxQ15JuI0ONiOJHjmj14PP67AlaVaOnclP4+ts5+aYCUZSGYd2F24z+CKdUiE+Q== X-Received: by 10.84.195.228 with SMTP id j91mr4520939pld.88.1484051186225; Tue, 10 Jan 2017 04:26:26 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id r26sm5450661pgd.42.2017.01.10.04.26.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Jan 2017 04:26:25 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: [PATCH 0/8] Handle memory error on disassemble Date: Tue, 10 Jan 2017 12:26:00 -0000 Message-Id: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00146.txt.bz2 Hi, Nowadays, we can set function pointer disassemble_info.memory_error_func to throw error or exception when disassembler gets an error, and the caller can/may catch the exception. Both gdb and objdump use this interface for many years. After GDB is switched to C++, this stops working due to the "foreign frame" from opcodes. That is to say, a C++ program calls a C function (print_insn_XXX from opcodes) and this function calls a C++ code which throws exception. DW2 C++ exception unwinder can unwind across the C function frame, unless the C code is compiled with -fexceptions. As a result, GDB aborts on memory error during disassembly on some hosts. See PR 20939 and patch #8 for more details. This patch series fix this problem by stopping throwing exception in disassemble_info.memory_error_func from gdb, but record the failed memory address. Exception is thrown when it is returned from opcodes function and return value is -1. Fortunately, most of disassemblers in opcodes follow this convention except msp430 and m68k. Patch 4, 5 and 6 fix these disassmblers in opcodes. (Note that during the work in opcodes, I find include/dis-asm.h exposes print_ins_$ARCH for each arch, which is not necessary, because they can be got via disassemble.c:disassembler by objdump and gdb. This will be done in a follow-up series.) Patch 1 is a refactor patch, to rewrite GDB disassemble in C++, so that 1) we can record the failed memory address during disassebly, 2) easier to do unit tests. Patch 8 does the change in GDB to stop throwing exception in disassemble_info.memory_error_func. In order to make sure such change doesn't cause any regression, patch 3 and 7 are the unit test to GDB disassembler on normal case and error case. Note that PR 20939 needs to be fixed on GDB 7.12 branch, which still can be built as a C program, so I probably need to rewrite the patch using C for 7.12 branch. Tested binutils with all targets enabled on x86_64-linux. Tested gdb for {x86_64, aarch64}-linux and arm-linux (on aarch64-linux). *** BLURB HERE *** Yao Qi (8): Refactor disassembly code Call print_insn_mep in mep_gdb_print_insn Disassembly unit test: disassemble one instruction Return -1 on memory error in print_insn_msp430 Remove magic numbers in m68k-dis.c:print_insn_arg Return -1 on memory error in print_insn_m68k Disassembly unit test: memory error Don't throw exception in dis_asm_memory_error gdb/arm-tdep.c | 5 +- gdb/disasm.c | 365 +++++++++++++++++++----- gdb/disasm.h | 56 +++- gdb/guile/scm-disasm.c | 77 ++--- gdb/mep-tdep.c | 8 +- gdb/mips-tdep.c | 5 +- gdb/record-btrace.c | 5 +- gdb/selftest.c | 55 ++++ gdb/selftest.h | 3 + gdb/spu-tdep.c | 20 +- gdb/testsuite/gdb.base/all-architectures.exp.in | 3 + opcodes/m68k-dis.c | 114 +++++--- opcodes/msp430-dis.c | 85 +++++- 13 files changed, 580 insertions(+), 221 deletions(-) -- 1.9.1