Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/8] Handle memory error on disassemble
@ 2017-01-10 12:26 Yao Qi
  2017-01-10 12:26 ` [PATCH 3/8] Disassembly unit test: disassemble one instruction Yao Qi
                   ` (8 more replies)
  0 siblings, 9 replies; 79+ messages in thread
From: Yao Qi @ 2017-01-10 12:26 UTC (permalink / raw)
  To: binutils, gdb-patches

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


^ permalink raw reply	[flat|nested] 79+ messages in thread

end of thread, other threads:[~2017-02-02 23:39 UTC | newest]

Thread overview: 79+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-10 12:26 [PATCH 0/8] Handle memory error on disassemble Yao Qi
2017-01-10 12:26 ` [PATCH 3/8] Disassembly unit test: disassemble one instruction Yao Qi
2017-01-11 21:15   ` Simon Marchi
2017-01-12 13:06   ` Pedro Alves
2017-01-12 17:03     ` Yao Qi
2017-01-12 17:43       ` Pedro Alves
2017-01-12 21:04         ` Yao Qi
2017-01-12 14:35   ` Pedro Alves
2017-01-12 15:15   ` Pedro Alves
2017-01-12 15:35     ` Yao Qi
2017-01-12 15:44       ` Pedro Alves
2017-01-12 16:06     ` Pedro Alves
2017-01-10 12:26 ` [PATCH 5/8] Remove magic numbers in m68k-dis.c:print_insn_arg Yao Qi
2017-01-11 22:14   ` Alan Modra
2017-01-13 12:23     ` Yao Qi
2017-01-10 12:26 ` [PATCH 7/8] Disassembly unit test: memory error Yao Qi
2017-01-10 12:26 ` [PATCH 6/8] Return -1 on memory error in print_insn_m68k Yao Qi
2017-01-11 22:15   ` Alan Modra
2017-01-12 11:50     ` Yao Qi
2017-01-12 14:38       ` Alan Modra
2017-01-12 14:52         ` Yao Qi
2017-01-13  1:54           ` Alan Modra
2017-01-13 12:29             ` Yao Qi
2017-01-10 12:26 ` [PATCH 4/8] Return -1 on memory error in print_insn_msp430 Yao Qi
2017-01-11 21:54   ` Alan Modra
2017-01-12  9:43     ` Yao Qi
2017-01-10 12:27 ` [PATCH 1/8] Refactor disassembly code Yao Qi
2017-01-11 20:43   ` Simon Marchi
2017-01-12 12:19     ` Yao Qi
2017-01-12 12:36       ` Pedro Alves
2017-01-12 15:29         ` Simon Marchi
2017-01-10 12:27 ` [PATCH 8/8] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-12 16:40   ` Pedro Alves
2017-01-12 21:09     ` Yao Qi
2017-01-10 12:27 ` [PATCH 2/8] Call print_insn_mep in mep_gdb_print_insn Yao Qi
2017-01-11 20:50   ` Simon Marchi
2017-01-12 12:21     ` Yao Qi
2017-01-16 10:03 ` [PATCH 0/6 v2] Handle memory error on disassemble Yao Qi
2017-01-16 10:03   ` [PATCH 4/6] Disassembly unit test: disassemble one instruction Yao Qi
2017-01-20  0:04     ` Pedro Alves
2017-01-24 15:23       ` Yao Qi
2017-02-02 16:46         ` Pedro Alves
2017-02-02 22:12           ` Yao Qi
2017-02-02 23:39             ` [pushed] Fix "maintenance selftest" printing stray instructions (Re: [PATCH 4/6] Disassembly unit test: disassemble one instruction) Pedro Alves
2017-01-16 10:03   ` [PATCH 5/6] Disassembly unit test: memory error Yao Qi
2017-01-17 14:38     ` Luis Machado
2017-01-24 15:33       ` Yao Qi
2017-01-20  0:08     ` Pedro Alves
2017-01-16 10:03   ` [PATCH 1/6] New function null_stream Yao Qi
2017-01-17 13:49     ` Luis Machado
2017-01-18 14:45       ` Yao Qi
2017-01-18 14:53         ` Luis Machado
2017-01-18 14:57           ` Simon Marchi
2017-01-18 15:02             ` Luis Machado
2017-01-18 15:18               ` Simon Marchi
2017-01-18 15:29                 ` Luis Machado
2017-01-18 15:54                   ` Simon Marchi
2017-01-18 16:36                     ` Luis Machado
2017-01-16 10:03   ` [PATCH 2/6] Refactor disassembly code Yao Qi
2017-01-17 14:14     ` Luis Machado
2017-01-18 16:34       ` Yao Qi
2017-01-18 16:53         ` Luis Machado
2017-01-16 10:03   ` [PATCH 3/6] Call print_insn_mep in mep_gdb_print_insn Yao Qi
2017-01-17 14:19     ` Luis Machado
2017-01-24 10:08       ` Yao Qi
2017-01-24 13:41         ` Luis Machado
2017-01-16 10:03   ` [PATCH 6/6] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-17 14:42     ` Luis Machado
2017-01-18 14:54       ` Yao Qi
2017-01-18 14:58         ` Luis Machado
2017-01-25  8:38   ` [PATCH 0/6 v3] Handle memory error on disassembly Yao Qi
2017-01-25  8:38     ` [PATCH 5/6] Disassembly unit test: memory error Yao Qi
2017-01-25  8:38     ` [PATCH 1/6] New function null_stream Yao Qi
2017-01-25  8:38     ` [PATCH 4/6] Disassembly unit test: disassemble one instruction Yao Qi
2017-01-25  8:38     ` [PATCH 6/6] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-25  8:38     ` [PATCH 3/6] Call print_insn_mep in mep_gdb_print_insn Yao Qi
2017-01-25  8:38     ` [PATCH 2/6] Refactor disassembly code Yao Qi
2017-01-26 11:34     ` [PATCH 0/6 v3] Handle memory error on disassembly Pedro Alves
2017-01-26 15:00       ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox