From 73c13fe69a4275433544533a610275861346ef44 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 29 Aug 2018 11:37:42 -0600 Subject: [PATCH] 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. --- gdb/ChangeLog | 8 ++++++++ gdb/windows-nat.c | 20 +++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e89fbec7ba..981ee1405e 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 Jim Wilson * riscv-linux-nat.c: Include elf/common.h instead of elf.h. diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index aea502638e..da663496e5 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; }