diff options
author | Tom de Vries <tdevries@suse.de> | 2024-08-08 23:52:00 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-08-08 23:52:00 +0200 |
commit | c45c3b4162148077765e94fd17d4481f18d6d44c (patch) | |
tree | 44d21a529dbe4bcee20f4fdf53a721a23096a03f /gdb/arch-utils.c | |
parent | 5b84cbc35ad574483781e62b7fddbcbf73cf2ad3 (diff) | |
download | binutils-c45c3b4162148077765e94fd17d4481f18d6d44c.zip binutils-c45c3b4162148077765e94fd17d4481f18d6d44c.tar.gz binutils-c45c3b4162148077765e94fd17d4481f18d6d44c.tar.bz2 |
[gdb] Handle ^C during disassembly
In PR gdb/32025, a fatal error was reported when sending a SIGINT to gdb while
disassembling.
I managed to reproduce this on aarch64-linux in a Leap 15.5 container using
this trigger patch:
...
gdb_disassembler_memory_reader::dis_asm_read_memory
(bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
struct disassemble_info *info) noexcept
{
+ set_quit_flag ();
return target_read_code (memaddr, myaddr, len);
}
...
and a simple gdb command line calling the disassemble command:
...
$ gdb -q -batch a.out -ex "disassemble main"
...
The following scenario leads to the fatal error:
- the disassemble command is executed,
- set_quit_flag is called in
gdb_disassembler_memory_reader::dis_asm_read_memory, pretending that a
user pressed ^C,
- target_read_code calls QUIT, which throws a
gdb_exception_quit,
- the exception propagation mechanism reaches c code in libopcodes and a fatal
error triggers because the c code is not compiled with -fexception.
Fix this by:
- wrapping the body of gdb_disassembler_memory_reader::dis_asm_read_memory in
catch_exceptions (which consequently needs moving to a header file), and
- reraising the caught exception in default_print_insn using QUIT.
Tested on aarch64-linux.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32025
Diffstat (limited to 'gdb/arch-utils.c')
-rw-r--r-- | gdb/arch-utils.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 13984eb..3247c36 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -37,6 +37,7 @@ #include "auxv.h" #include "observable.h" #include "solib-target.h" +#include "event-top.h" #include "gdbsupport/version.h" @@ -1040,7 +1041,11 @@ default_print_insn (bfd_vma memaddr, disassemble_info *info) info->mach, current_program_space->exec_bfd ()); gdb_assert (disassemble_fn != NULL); - return (*disassemble_fn) (memaddr, info); + int res = (*disassemble_fn) (memaddr, info); + + QUIT; + + return res; } /* See arch-utils.h. */ |