From patchwork Mon Oct 24 17:45:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 59364 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFBE23857B89 for ; Mon, 24 Oct 2022 17:46:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFBE23857B89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666633575; bh=i4Jp25x1yVWB+cmlQVNvr+TYC93RxhC+NKD56hMYz88=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jzYCPa2QHhK7bq+G+oAcVX3z+1IXwSYp723cxn1CtgflqaAgJTeEom4rSAzMkAvs4 qusUtiLTiSfijc2ZZJEDSy3+L37MWg9odD2QX0bSJU0D9dEPdIIlxP1ExLLNlp7fRE /2YMaxFqgnT0YXl02vJWGsfveCnulMkGrDroL6ks= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9C2C73858403 for ; Mon, 24 Oct 2022 17:45:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C2C73858403 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-482-DIdCEXlBMq2ZJwALiG7FuA-1; Mon, 24 Oct 2022 13:45:43 -0400 X-MC-Unique: DIdCEXlBMq2ZJwALiG7FuA-1 Received: by mail-qk1-f198.google.com with SMTP id u7-20020a05620a0c4700b006ee526183fcso9459717qki.8 for ; Mon, 24 Oct 2022 10:45:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:to:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=IeYquJeLgCcWYaEqk0AvLn+0EjdqgtGRkYwPfoypIoA=; b=PKl9lwowYOaPVljRy5A4BrJzFaozbkOAMiRxqXXoGZSTqxKTNgSq6cfyDKiHRdiWHq nBEb1QFzhjjazU62qpABG+I8ZTsUgdXb9yS+VvWH0laLNdFOix4kdJuSpVQLrzlF4LpY h5krmYed1zNrtwnl4FbBG7KCwmjBl8rc6eWQi5jDmWf1F1vDbX3plnd1+mOm56DrJEqn o6Xk1np8Jfw+ZfI06NKF9aUMAN/luasdU8EhGBFmZtPvD+pigR9XNVhtuIC/q0mbsBpm +jkXtaOmfk3SdoEI2N1ee3Ed3Y5GYSsW1iA/d9tGpzywlIgS7SVOKul1AGpWiIsI8aMb +jnQ== X-Gm-Message-State: ACrzQf2E3kTjoz8wpLdnkytJjJOtlmOABuAu5Bmnp6S+3ATWFpZqUR4h qpzUtph1WGlanDNi6pxYX9cO/VmqyzGGo+/NC7JamMaWOOQmLnPZGdEZvsyfYkD67yvcGkO5x4r E4EBUBcw8ETfBrizrvLh4kw== X-Received: by 2002:a0c:e352:0:b0:4bb:825d:a803 with SMTP id a18-20020a0ce352000000b004bb825da803mr2240537qvm.9.1666633542546; Mon, 24 Oct 2022 10:45:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63xv/zkFHXYyvC5rEpdEDSwe07s56gl673Am9Kk/9cUY0gULM6SqRDFXT7Dtyna/1DhRCw5Q== X-Received: by 2002:a0c:e352:0:b0:4bb:825d:a803 with SMTP id a18-20020a0ce352000000b004bb825da803mr2240510qvm.9.1666633542148; Mon, 24 Oct 2022 10:45:42 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id k7-20020ac80747000000b00398313f286dsm279795qth.40.2022.10.24.10.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 10:45:41 -0700 (PDT) To: Simon Marchi , gdb-patches@sourceware.org Subject: [PATCH] gdb/disasm: mark functions passed to the disassembler noexcept In-Reply-To: <87r0yx6sr7.fsf@redhat.com> References: <20221024125016.2823862-1-aburgess@redhat.com> <499ecf26-0f57-2376-a617-9b6214319b4a@simark.ca> <87r0yx6sr7.fsf@redhat.com> Date: Mon, 24 Oct 2022 18:45:39 +0100 Message-ID: <87mt9l6rp8.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I realise I made a bit of a mess, including the updated patch in the previous email. I should have just posted both of these as a new V2 series. Oh well! The patch below applies on top of the first patch (in the parent email), and adds the noexcept keyword in a few places. Thanks, Andrew --- commit b1e3243296084566baf443d9c5280918a9d784f3 Author: Andrew Burgess Date: Mon Oct 24 18:35:41 2022 +0100 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. diff --git a/gdb/disasm.c b/gdb/disasm.c index de44aac3263..da2fb89e5c3 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -191,7 +191,7 @@ line_has_code_p (htab_t table, struct symtab *symtab, int line) int gdb_disassembler_memory_reader::dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len, - struct disassemble_info *info) + struct disassemble_info *info) noexcept { return target_read_code (memaddr, myaddr, len); } @@ -199,8 +199,8 @@ gdb_disassembler_memory_reader::dis_asm_read_memory /* Wrapper of memory_error. */ void -gdb_disassembler::dis_asm_memory_error (int err, bfd_vma memaddr, - struct disassemble_info *info) +gdb_disassembler::dis_asm_memory_error + (int err, bfd_vma memaddr, struct disassemble_info *info) noexcept { gdb_disassembler *self = static_cast(info->application_data); @@ -211,8 +211,8 @@ gdb_disassembler::dis_asm_memory_error (int err, bfd_vma memaddr, /* Wrapper of print_address. */ void -gdb_disassembler::dis_asm_print_address (bfd_vma addr, - struct disassemble_info *info) +gdb_disassembler::dis_asm_print_address + (bfd_vma addr, struct disassemble_info *info) noexcept { gdb_disassembler *self = static_cast(info->application_data); @@ -256,7 +256,7 @@ gdb_printing_disassembler::stream_from_gdb_disassemble_info (void *dis_info) int gdb_printing_disassembler::fprintf_func (void *dis_info, - const char *format, ...) + const char *format, ...) noexcept { ui_file *stream = stream_from_gdb_disassemble_info (dis_info); @@ -272,9 +272,9 @@ gdb_printing_disassembler::fprintf_func (void *dis_info, /* See disasm.h. */ int -gdb_printing_disassembler::fprintf_styled_func (void *dis_info, - enum disassembler_style style, - const char *format, ...) +gdb_printing_disassembler::fprintf_styled_func + (void *dis_info, enum disassembler_style style, + const char *format, ...) noexcept { ui_file *stream = stream_from_gdb_disassemble_info (dis_info); gdb_printing_disassembler *dis = (gdb_printing_disassembler *) dis_info; @@ -1220,8 +1220,8 @@ gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr) /* See disasm.h. */ int -gdb_non_printing_disassembler::null_fprintf_func (void *stream, - const char *format, ...) +gdb_non_printing_disassembler::null_fprintf_func + (void *stream, const char *format, ...) noexcept { return 0; } @@ -1230,7 +1230,8 @@ gdb_non_printing_disassembler::null_fprintf_func (void *stream, int gdb_non_printing_disassembler::null_fprintf_styled_func - (void *stream, enum disassembler_style style, const char *format, ...) + (void *stream, enum disassembler_style style, + const char *format, ...) noexcept { return 0; } diff --git a/gdb/disasm.h b/gdb/disasm.h index b7d16744c20..989f287c9e1 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -127,7 +127,7 @@ struct gdb_printing_disassembler : public gdb_disassemble_info /* Callback used as the disassemble_info's fprintf_func callback. The DIS_INFO pointer is a pointer to a gdb_printing_disassembler object. Content is written to the m_stream extracted from DIS_INFO. */ - static int fprintf_func (void *dis_info, const char *format, ...) + static int fprintf_func (void *dis_info, const char *format, ...) noexcept ATTRIBUTE_PRINTF(2,3); /* Callback used as the disassemble_info's fprintf_styled_func callback. @@ -135,7 +135,7 @@ struct gdb_printing_disassembler : public gdb_disassemble_info object. Content is written to the m_stream extracted from DIS_INFO. */ static int fprintf_styled_func (void *dis_info, enum disassembler_style style, - const char *format, ...) + const char *format, ...) noexcept ATTRIBUTE_PRINTF(3,4); /* Return true if the disassembler is considered inside a comment, false @@ -187,14 +187,14 @@ struct gdb_non_printing_disassembler : public gdb_disassemble_info /* Callback used as the disassemble_info's fprintf_func callback, this doesn't write anything to STREAM, but just returns 0. */ - static int null_fprintf_func (void *stream, const char *format, ...) + static int null_fprintf_func (void *stream, const char *format, ...) noexcept ATTRIBUTE_PRINTF(2,3); /* Callback used as the disassemble_info's fprintf_styled_func callback, , this doesn't write anything to STREAM, but just returns 0. */ static int null_fprintf_styled_func (void *stream, enum disassembler_style style, - const char *format, ...) + const char *format, ...) noexcept ATTRIBUTE_PRINTF(3,4); }; @@ -208,7 +208,7 @@ struct gdb_disassembler_memory_reader /* Implements the read_memory_func disassemble_info callback. */ static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len, - struct disassemble_info *info); + struct disassemble_info *info) noexcept; }; /* A non-printing disassemble_info management class. The disassemble_info @@ -281,9 +281,9 @@ struct gdb_disassembler : public gdb_printing_disassembler, static bool use_ext_lang_colorization_p; static void dis_asm_memory_error (int err, bfd_vma memaddr, - struct disassemble_info *info); + struct disassemble_info *info) noexcept; static void dis_asm_print_address (bfd_vma addr, - struct disassemble_info *info); + struct disassemble_info *info) noexcept; /* Return true if we should use the extension language to apply disassembler styling. This requires disassembler styling to be on diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c index 1d460997831..a25252b4306 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 (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 (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 (info->application_data);