Message ID | 23c08fae-bc7c-9382-8b3c-dc13d21be14e@dronecode.org.uk |
---|---|
State | New, archived |
Headers |
Received: (qmail 84249 invoked by alias); 28 Mar 2019 15:46:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 84234 invoked by uid 89); 28 Mar 2019 15:46:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-13.4 required=5.0 tests=AWL, BAYES_00, BODY_8BITS, GARBLED_BODY, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=Page, ld, lx X-HELO: rgout01.bt.lon5.cpcloud.co.uk Received: from rgout0107.bt.lon5.cpcloud.co.uk (HELO rgout01.bt.lon5.cpcloud.co.uk) (65.20.0.127) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Mar 2019 15:46:24 +0000 X-OWM-Source-IP: 31.51.207.0 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-SNCR-VADESECURE: CLEAN Received: from [192.168.1.102] (31.51.207.0) by rgout01.bt.lon5.cpcloud.co.uk (9.0.019.26-1) (authenticated as jonturney@btinternet.com) id 5B321EA019843450; Thu, 28 Mar 2019 15:46:22 +0000 Subject: Re: [PATCH][PR gdb/24351] Fix wrong format specification in display_selector() To: =?UTF-8?B?0JLQu9Cw0LTQuNC80LjRgCDQnNCw0YDRgtGM0Y/QvdC+0LI=?= <vilgeforce@gmail.com> Cc: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org References: <CAL5iTPLqaE5gA+DpcjsBYVjV7e-xuTZHkag1YOnSZbC8Z_+dXg@mail.gmail.com> <b738500ea927e8734b2e312af2f59f6b@polymtl.ca> From: Jon Turney <jon.turney@dronecode.org.uk> Message-ID: <23c08fae-bc7c-9382-8b3c-dc13d21be14e@dronecode.org.uk> Date: Thu, 28 Mar 2019 15:46:19 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <b738500ea927e8734b2e312af2f59f6b@polymtl.ca> Content-Type: multipart/mixed; boundary="------------6D1369C7A1435561ACC25685" |
Commit Message
Jon Turney
March 28, 2019, 3:46 p.m. UTC
On 17/03/2019 18:44, Simon Marchi wrote: > On 2019-03-17 05:48, Владимир Мартьянов wrote: >> There are a wrong format strings in function display_selector() in >> file windows-nat.c. This leads to build error using Cygwin on Windows. >> LDT_ENTRY.HighWord is a DWORD, which is unsigned long int, so the >> format specification should be for long int, not simply int. >> >> gdb/ChangeLog: >> 2019-03-17 Vladimir Martyanov <vilgeforce@gmail.com> >> >> PR gdb/24351 >> * windows-nat.c (display_selector): Format specifications fixed >> >> Patch and changelog files are attached > > Thanks, this LGTM. I altavista'ed and it looks like this is the right > thing to do to print DWORDs. It also builds fine with > i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc on Linux. Thanks for looking at this. But did you test this with x86_64-pc-cygwin? It fails to build for me: > ../../gdb/windows-nat.c: In function ‘int display_selector(HANDLE, DWORD)’: > ../../gdb/windows-nat.c:1099:65: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘unsigned int’ [-Werror=format=] > printf_filtered ("Unknown type 0x%lx",info.HighWord.Bits.Type); > ~~~~~~~~~~~~~~~~~~~~~~~^ > ../../gdb/windows-nat.c:1106:74: error: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘unsigned int’ [-Werror=format=] > printf_filtered ("Priviledge level = %ld. ", info.HighWord.Bits.Dpl); I believe this is because, unfortunately, DWORD is not long on 64-bit Cygwin, because that is LP64 (See [1]). I think the only portable way to write this (short of introducing inttypes.h PRI_-style macros) is to explicitly cast DWORD type values to unsigned long or unsigned int, and use the appropriate format (e.g. see [2] for a similar patch I wrote for xserver) Patch attached. [1] https://cygwin.com/faq.html#faq.programming.64bitporting [2] https://cgit.freedesktop.org/xorg/xserver/commit/?id=aa83c61f510121da20b56e8f7de700193f7d16b5 From e4aba2d5248cd8d2390e9028aa0131174c1cdb6f Mon Sep 17 00:00:00 2001 From: Jon Turney <jon.turney@dronecode.org.uk> Date: Thu, 28 Mar 2019 14:02:25 +0000 Subject: [PATCH] Fix format specification in display_selector() (again) DWORD type is not a long on 64-bit Cygwin, because that it is LP64. Explicitly cast DWORD values to unsigned long and use an appropriate format. gdb/ChangeLog: 2019-03-28 Jon Turney <jon.turney@dronecode.org.uk> * windows-nat.c (display_selector): Fixed format specifications for 64-bit Cygwin. --- gdb/ChangeLog | 5 +++++ gdb/windows-nat.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
Comments
чт, 28 мар. 2019 г. в 18:46, Jon Turney <jon.turney@dronecode.org.uk>: > Thanks for looking at this. But did you test this with > x86_64-pc-cygwin? It fails to build for me: No, I didn't. I'm new to Cygwin and didn't know about this feature. I tested you patch with Cygwin-x86 and gdb was built without errors.
On 2019-03-28 11:46, Jon Turney wrote: > On 17/03/2019 18:44, Simon Marchi wrote: >> On 2019-03-17 05:48, Владимир Мартьянов wrote: >>> There are a wrong format strings in function display_selector() in >>> file windows-nat.c. This leads to build error using Cygwin on >>> Windows. >>> LDT_ENTRY.HighWord is a DWORD, which is unsigned long int, so the >>> format specification should be for long int, not simply int. >>> >>> gdb/ChangeLog: >>> 2019-03-17 Vladimir Martyanov <vilgeforce@gmail.com> >>> >>> PR gdb/24351 >>> * windows-nat.c (display_selector): Format specifications fixed >>> >>> Patch and changelog files are attached >> >> Thanks, this LGTM. I altavista'ed and it looks like this is the right >> thing to do to print DWORDs. It also builds fine with >> i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc on Linux. > > Thanks for looking at this. But did you test this with > x86_64-pc-cygwin? It fails to build for me: > >> ../../gdb/windows-nat.c: In function ‘int display_selector(HANDLE, >> DWORD)’: >> ../../gdb/windows-nat.c:1099:65: error: format ‘%lx’ expects argument >> of type ‘long unsigned int’, but argument 2 has type ‘unsigned int’ >> [-Werror=format=] >> printf_filtered ("Unknown type 0x%lx",info.HighWord.Bits.Type); >> ~~~~~~~~~~~~~~~~~~~~~~~^ >> ../../gdb/windows-nat.c:1106:74: error: format ‘%ld’ expects argument >> of type ‘long int’, but argument 2 has type ‘unsigned int’ >> [-Werror=format=] >> printf_filtered ("Priviledge level = %ld. ", >> info.HighWord.Bits.Dpl); > > I believe this is because, unfortunately, DWORD is not long on 64-bit > Cygwin, because that is LP64 (See [1]). > > I think the only portable way to write this (short of introducing > inttypes.h PRI_-style macros) is to explicitly cast DWORD type values > to unsigned long or unsigned int, and use the appropriate format (e.g. > see [2] for a similar patch I wrote for xserver) > > Patch attached. > > [1] https://cygwin.com/faq.html#faq.programming.64bitporting > [2] > https://cgit.freedesktop.org/xorg/xserver/commit/?id=aa83c61f510121da20b56e8f7de700193f7d16b5 Thanks for the patch, I pushed it. Simon
>>>>> "Jon" == Jon Turney <jon.turney@dronecode.org.uk> writes:
Jon> I believe this is because, unfortunately, DWORD is not long on 64-bit
Jon> Cygwin, because that is LP64 (See [1]).
Jon> I think the only portable way to write this (short of introducing
Jon> inttypes.h PRI_-style macros) is to explicitly cast DWORD type values
Jon> to unsigned long or unsigned int, and use the appropriate format
Jon> (e.g. see [2] for a similar patch I wrote for xserver)
Just FYI, a more typical way in gdb is to use "%s" along with something
like pulongest. What you did is fine, though, and I don't think
anything needs to be changed.
Tom
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index d38ade5855..47f6cbb541 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1096,14 +1096,16 @@ display_selector (HANDLE thread, DWORD sel) puts_filtered ("Code (Exec/Read, Conf"); break; default: - printf_filtered ("Unknown type 0x%lx",info.HighWord.Bits.Type); + printf_filtered ("Unknown type 0x%lx", + (unsigned long) info.HighWord.Bits.Type); } if ((info.HighWord.Bits.Type & 0x1) == 0) puts_filtered(", N.Acc"); puts_filtered (")\n"); if ((info.HighWord.Bits.Type & 0x10) == 0) puts_filtered("System selector "); - printf_filtered ("Priviledge level = %ld. ", info.HighWord.Bits.Dpl); + printf_filtered ("Priviledge level = %ld. ", + (unsigned long) info.HighWord.Bits.Dpl); if (info.HighWord.Bits.Granularity) puts_filtered ("Page granular.\n"); else