From patchwork Wed Aug 29 19:31:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29112 Received: (qmail 48508 invoked by alias); 29 Aug 2018 19:31:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 48487 invoked by uid 89); 29 Aug 2018 19:31:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:us X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Aug 2018 19:31:30 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway31.websitewelcome.com (Postfix) with ESMTP id AB6449F671 for ; Wed, 29 Aug 2018 14:31:28 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id v6BDfJp1RBcCXv6BSfnyul; Wed, 29 Aug 2018 14:31:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lpZ0cM9cqGCYgrmP6+u3i5Jd/0mDH5DFVZasyKVfZQI=; b=tdQXhdg/3oIB6dkqP5DiOmqodK lWQV5owKcAvyXmr9YtGUNoSmTG+eKWQ6AVzeJpwUGCNtJ5A6CiHsbqX9XP80inHTC0rDBHln7mA9q pyHmOjEs2tw3OoJmMBlfAXvmM; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:53174 helo=pokyo) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fv6BC-003IwG-KU; Wed, 29 Aug 2018 14:31:02 -0500 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH] Fix windows-nat.c for -Wnarrowing References: <20180829174253.18507-1-tom@tromey.com> <88f0fbca-f10a-9139-f96a-7934e10a937c@redhat.com> <87in3t3sqb.fsf@tromey.com> <87efeh3snr.fsf@tromey.com> <25d1c3af-a52c-121c-de5c-bbce67471376@redhat.com> Date: Wed, 29 Aug 2018 13:31:01 -0600 In-Reply-To: <25d1c3af-a52c-121c-de5c-bbce67471376@redhat.com> (Pedro Alves's message of "Wed, 29 Aug 2018 20:09:29 +0100") Message-ID: <875zzt3r7u.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 >>>>> "Pedro" == Pedro Alves writes: Pedro> If you're going to fix it, I'd go with my earlier suggestion: Pedro> It'd be easily fixable by removing that terminator Pedro> entry and using range-for in the other #if 0 block. Ok, I know you said not to bother, but ... Here's what I plan to checkin. Tom commit dbf105c6d25c16dee30af67f70bc468afffe6249 Author: Tom Tromey Date: Wed Aug 29 11:37:42 2018 -0600 Fix windows-nat.c for -Wnarrowing Sergio pointed out that the Windows builder was failing due to the -Wnarrowing patch, with: ../../binutils-gdb/gdb/windows-nat.c:301:27: error: narrowing conversion of '3221225477' from 'DWORD {aka long unsigned int}' to 'int' inside { } [-Wnarrowing] {-1, GDB_SIGNAL_UNKNOWN}}; ^ ../../binutils-gdb/gdb/windows-nat.c:301:27: error: narrowing conversion of '3221225725' from 'DWORD {aka long unsigned int}' to 'int' inside { } [-Wnarrowing] ../../binutils-gdb/gdb/windows-nat.c:301:27: error: narrowing conversion of '2147483651' from 'DWORD {aka long unsigned int}' to 'int' inside { } [-Wnarrowing] ../../binutils-gdb/gdb/windows-nat.c:301:27: error: narrowing conversion of '2147483652' from 'DWORD {aka long unsigned int}' to 'int' inside { } [-Wnarrowing] ../../binutils-gdb/gdb/windows-nat.c:301:27: error: narrowing conversion of '3221225614' from 'DWORD {aka long unsigned int}' to 'int' inside { } [-Wnarrowing] Looking into this, I found two things. First, in struct xlate_exception, it is better to have "them" be of type DWORD, as that's the type actually in use. Second, struct xlate_exception and xlate are not used in this file, because the code in windows_nat_target::resume is #if'd out. This patch changes the type of "them", but also similarly #if's out this object. In order to avoid a narrowing warning from the -1 entry, at Pedro's suggestion I have removed this and changed windows_nat_target::resume to use ranged for. Tested by rebuilding using the mingw toolchain on x86-64 Fedora 28. I also tested it by temporarily removing the "#if 0"s and rebuilding. gdb/ChangeLog 2018-08-29 Tom Tromey * windows-nat.c (struct xlate_exception) : Change type to DWORD. (xlate): Fix formatting. Remove last entry. (struct xlate_exception, xlate): Comment out. (windows_nat_target::resume): Use ranged for. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a30dacee4a3..f7e8922cdcd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-08-29 Tom Tromey + + * windows-nat.c (struct xlate_exception) : Change type to + DWORD. + (xlate): Fix formatting. Remove last entry. + (struct xlate_exception, xlate): Comment out. + (windows_nat_target::resume): Use ranged for. + 2018-08-29 Sergio Durigan Junior PR gdb/23555 diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index aea502638e0..da663496e5a 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -280,26 +280,29 @@ static const int *mappings; a segment register or not. */ static segment_register_p_ftype *segment_register_p; +/* See windows_nat_target::resume to understand why this is commented + out. */ +#if 0 /* This vector maps the target's idea of an exception (extracted from the DEBUG_EVENT structure) to GDB's idea. */ struct xlate_exception { - int them; + DWORD them; enum gdb_signal us; }; -static const struct xlate_exception - xlate[] = +static const struct xlate_exception xlate[] = { {EXCEPTION_ACCESS_VIOLATION, GDB_SIGNAL_SEGV}, {STATUS_STACK_OVERFLOW, GDB_SIGNAL_SEGV}, {EXCEPTION_BREAKPOINT, GDB_SIGNAL_TRAP}, {DBG_CONTROL_C, GDB_SIGNAL_INT}, {EXCEPTION_SINGLE_STEP, GDB_SIGNAL_TRAP}, - {STATUS_FLOAT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE}, - {-1, GDB_SIGNAL_UNKNOWN}}; + {STATUS_FLOAT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE} +}; +#endif /* 0 */ struct windows_nat_target final : public x86_nat_target { @@ -1408,12 +1411,11 @@ windows_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) structure when passing the exception to the inferior. Note that this seems possible in the exception handler itself. */ { - int i; - for (i = 0; xlate[i].them != -1; i++) - if (xlate[i].us == sig) + for (const xlate_exception &x : xlate) + if (x.us == sig) { current_event.u.Exception.ExceptionRecord.ExceptionCode - = xlate[i].them; + = x.them; continue_status = DBG_EXCEPTION_NOT_HANDLED; break; }