Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado <lgustavo@codesourcery.com>
To: Yao Qi <qiyaoltc@gmail.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH 6/6] Don't throw exception in dis_asm_memory_error
Date: Tue, 17 Jan 2017 14:42:00 -0000	[thread overview]
Message-ID: <f1c19cca-134b-ed43-4262-7a5ce4c07fa1@codesourcery.com> (raw)
In-Reply-To: <1484560977-8693-7-git-send-email-yao.qi@linaro.org>

On 01/16/2017 04:02 AM, Yao Qi wrote:
> 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=<optimized out>) 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  <yao.qi@linaro.org>
> 	    Pedro Alves  <palves@redhat.com>
>
> 	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) <m_err_memaddr>: New field.
>
> gdb/testsuite:
>
> 2017-01-10  Yao Qi  <yao.qi@linaro.org>
>
> 	* 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<gdb_disassembler *>(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"

I think you missed the comment you had proposed?

# GDB can't access any memory because there is no live inferior.

I take it we have no loaded executable as well? Otherwise we could 
eventually read data from the executable file, which wouldn't yield an 
error.

>  }
>
>  # Given we can't change arch, osabi, endianness, etc. atomically, we
>


  reply	other threads:[~2017-01-17 14:42 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 12:26 [PATCH 0/8] Handle memory error on disassemble 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: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 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: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 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-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-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 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 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 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 [this message]
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 2/6] Refactor disassembly code Yao Qi
2017-01-25  8:38     ` [PATCH 4/6] Disassembly unit test: disassemble one instruction 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 6/6] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-25  8:38     ` [PATCH 1/6] New function null_stream Yao Qi
2017-01-25  8:38     ` [PATCH 5/6] Disassembly unit test: memory error 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f1c19cca-134b-ed43-4262-7a5ce4c07fa1@codesourcery.com \
    --to=lgustavo@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox