This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 0/6 v2] Handle memory error on disassemble


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.

This is the V2 of the patch series, and V1 can be found
https://sourceware.org/ml/gdb-patches/2017-01/msg00146.html
All opcodes patches are already committed, and V2 addressed
all the comments from the review.

Patch 1 and 2 are refactor patch.  Patch 4 and 5 add unit
tests to disassembly.  Patch 6 fixes PR 20939 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.

Note that PR 20939 needs to be fixed on GDB 7.12 branch, which still
can be built as a C program, so I need to rewrite the patch using C
for 7.12 branch in next step.

Tested gdb for {x86_64, aarch64}-linux.

Yao Qi (6):
  New function null_stream
  Refactor disassembly code
  Call print_insn_mep in mep_gdb_print_insn
  Disassembly unit test: disassemble one instruction
  Disassembly unit test: memory error
  Don't throw exception in dis_asm_memory_error

 gdb/Makefile.in                                 |   5 +
 gdb/arm-tdep.c                                  |   5 +-
 gdb/disasm-selftests.c                          | 221 ++++++++++++++++++++++++
 gdb/disasm.c                                    | 177 ++++++++++---------
 gdb/disasm.h                                    |  54 ++++--
 gdb/guile/scm-disasm.c                          |  77 +++------
 gdb/mep-tdep.c                                  |  10 +-
 gdb/mips-tdep.c                                 |   5 +-
 gdb/record-btrace.c                             |   5 +-
 gdb/selftest-arch.c                             | 103 +++++++++++
 gdb/selftest-arch.h                             |  26 +++
 gdb/spu-tdep.c                                  |  20 +--
 gdb/testsuite/gdb.base/all-architectures.exp.in |   3 +
 gdb/utils.c                                     |  13 ++
 gdb/utils.h                                     |   4 +
 15 files changed, 551 insertions(+), 177 deletions(-)
 create mode 100644 gdb/disasm-selftests.c
 create mode 100644 gdb/selftest-arch.c
 create mode 100644 gdb/selftest-arch.h

-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]