aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-10-24 18:35:41 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-11-28 19:23:30 +0000
commit8eb7d135e32ad6b7cdcfeffe486b195058206cdb (patch)
treefaf2c2287bad79cc9f4bc1d0af8187de0d6b48c9 /gdb/python
parent65639fcc54226c0621d4312efac702c92ddde324 (diff)
downloadgdb-8eb7d135e32ad6b7cdcfeffe486b195058206cdb.zip
gdb-8eb7d135e32ad6b7cdcfeffe486b195058206cdb.tar.gz
gdb-8eb7d135e32ad6b7cdcfeffe486b195058206cdb.tar.bz2
gdb/disasm: mark functions passed to the disassembler noexcept
While working on another patch, Simon pointed out that GDB could be improved by marking the functions passed to the disassembler as noexcept. https://sourceware.org/pipermail/gdb-patches/2022-October/193084.html The reason this is important is the on some hosts, libopcodes, being C code, will not be compiled with support for handling exceptions. As such, an attempt to throw an exception over libopcodes code will cause GDB to terminate. See bug gdb/29712 for an example of when this happened. In this commit all the functions that are passed to the disassembler, and which might be used as callbacks by libopcodes are marked noexcept. Ideally, I would have liked to change these typedefs: using read_memory_ftype = decltype (disassemble_info::read_memory_func); using memory_error_ftype = decltype (disassemble_info::memory_error_func); using print_address_ftype = decltype (disassemble_info::print_address_func); using fprintf_ftype = decltype (disassemble_info::fprintf_func); using fprintf_styled_ftype = decltype (disassemble_info::fprintf_styled_func); which are declared in disasm.h, as including the noexcept keyword. However, when I tried this, I ran into this warning/error: In file included from ../../src/gdb/disasm.c:25: ../../src/gdb/disasm.h: In constructor ‘gdb_printing_disassembler::gdb_printing_disassembler(gdbarch*, ui_file*, gdb_disassemble_info::read_memory_ftype, gdb_disassemble_info::memory_error_ftype, gdb_disassemble_info::print_address_ftype)’: ../../src/gdb/disasm.h:116:3: error: mangled name for ‘gdb_printing_disassembler::gdb_printing_disassembler(gdbarch*, ui_file*, gdb_disassemble_info::read_memory_ftype, gdb_disassemble_info::memory_error_ftype, gdb_disassemble_info::print_address_ftype)’ will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type] 116 | gdb_printing_disassembler (struct gdbarch *gdbarch, | ^~~~~~~~~~~~~~~~~~~~~~~~~ So I've left that change out. This does mean that if somebody adds a new use of the disassembler classes in the future, and forgets to mark the callbacks as noexcept, this will compile fine. We'll just have to manually check for that during review.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-disasm.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 1d46099..a25252b 100644
--- a/gdb/python/py-disasm.c
+++ b/gdb/python/py-disasm.c
@@ -101,12 +101,12 @@ struct gdbpy_disassembler : public gdb_printing_disassembler
/* Callbacks used by disassemble_info. */
static void memory_error_func (int status, bfd_vma memaddr,
- struct disassemble_info *info);
+ struct disassemble_info *info) noexcept;
static void print_address_func (bfd_vma addr,
- struct disassemble_info *info);
+ struct disassemble_info *info) noexcept;
static int read_memory_func (bfd_vma memaddr, gdb_byte *buff,
unsigned int len,
- struct disassemble_info *info);
+ struct disassemble_info *info) noexcept;
/* Return a reference to an optional that contains the address at which a
memory error occurred. The optional will only have a value if a
@@ -513,7 +513,7 @@ disasmpy_info_progspace (PyObject *self, void *closure)
int
gdbpy_disassembler::read_memory_func (bfd_vma memaddr, gdb_byte *buff,
unsigned int len,
- struct disassemble_info *info)
+ struct disassemble_info *info) noexcept
{
gdbpy_disassembler *dis
= static_cast<gdbpy_disassembler *> (info->application_data);
@@ -658,7 +658,7 @@ disasmpy_result_init (PyObject *self, PyObject *args, PyObject *kwargs)
void
gdbpy_disassembler::memory_error_func (int status, bfd_vma memaddr,
- struct disassemble_info *info)
+ struct disassemble_info *info) noexcept
{
gdbpy_disassembler *dis
= static_cast<gdbpy_disassembler *> (info->application_data);
@@ -669,7 +669,7 @@ gdbpy_disassembler::memory_error_func (int status, bfd_vma memaddr,
void
gdbpy_disassembler::print_address_func (bfd_vma addr,
- struct disassemble_info *info)
+ struct disassemble_info *info) noexcept
{
gdbpy_disassembler *dis
= static_cast<gdbpy_disassembler *> (info->application_data);