From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21224 invoked by alias); 12 Apr 2013 10:18:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 21214 invoked by uid 89); 12 Apr 2013 10:18:12 -0000 X-Spam-SWARE-Status: No, score=-8.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 12 Apr 2013 10:18:11 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3CAI9Qs017231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Apr 2013 06:18:10 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3CAI7g8029700 for ; Fri, 12 Apr 2013 06:18:08 -0400 Message-ID: <5167DF5F.8060701@redhat.com> Date: Fri, 12 Apr 2013 14:55:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [PATCH 13/26] serial_write: change prototype to take a void-pointer buffer. References: <20130411225847.16791.29283.stgit@brno.lan> <20130411230030.16791.28557.stgit@brno.lan> In-Reply-To: <20130411230030.16791.28557.stgit@brno.lan> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-04/txt/msg00377.txt.bz2 On 04/12/2013 12:00 AM, Pedro Alves wrote: > +static int dos_write (struct serial *scb, const void *buf, int count); > static int > -dos_write (struct serial *scb, const char *str, int len) > +dos_write (struct serial *scb, const void *buf, int count) > { Bah. Re-reading this with a fresher head, I notice I failed to change int -> size_t here. This results in a little cascade of updates to other variables (mainly to avoid signed/unsigned comparisons). I've merged this into the patch: diff --git i/gdb/ser-go32.c w/gdb/ser-go32.c index 76a2f4f..9b321df 100644 --- i/gdb/ser-go32.c +++ w/gdb/ser-go32.c @@ -148,7 +148,7 @@ typedef unsigned long u_long; #define NCNT 20 static int intrcnt; -static int cnts[NCNT]; +static size_t cnts[NCNT]; static char *cntnames[NCNT] = { /* h/w interrupt counts. */ @@ -230,7 +230,7 @@ static int dos_open (struct serial *scb, const char *name); static void dos_raw (struct serial *scb); static int dos_readchar (struct serial *scb, int timeout); static int dos_setbaudrate (struct serial *scb, int rate); -static int dos_write (struct serial *scb, const void *buf, int count); +static int dos_write (struct serial *scb, const void *buf, size_t count); static void dos_close (struct serial *scb); static serial_ttystate dos_get_tty_state (struct serial *scb); static int dos_set_tty_state (struct serial *scb, serial_ttystate state); @@ -787,12 +787,12 @@ dos_setstopbits (struct serial *scb, int num) } static int -dos_write (struct serial *scb, const void *buf, int count) +dos_write (struct serial *scb, const void *buf, size_t count) { volatile struct dos_ttystate *port = &ports[scb->fd]; - int fifosize = port->fifo ? 16 : 1; + size_t fifosize = port->fifo ? 16 : 1; long then; - int cnt; + size_t cnt; const char *str = buf; while (count > 0) @@ -905,7 +905,7 @@ dos_info (char *arg, int from_tty) printf_filtered ("\nTotal interrupts: %d\n", intrcnt); for (i = 0; i < NCNT; i++) if (cnts[i]) - printf_filtered ("%s:\t%d\n", cntnames[i], cnts[i]); + printf_filtered ("%s:\t%lu\n", cntnames[i], (unsigned long) cnts[i]); #endif } New version of full patch follows. I've also updated the github branch. --------------- serial_write: change prototype to take a void-pointer buffer. While remote.c works with "char *" buffers most of the time, other remote targets have binary-ish-er protocols, and choose to use "unsigned char" throughout, like e.g., remote-mips.c or remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those targets, unless we add casts in calls to serial_write. Since serial_write is only concerned about sending raw host bytes out, and serial_ops->write_prim already works with "void *"/"size_t", a similar interface to the "write" or "send" system calls, I find it natural to change serial_write's prototype accordingly, avoiding the need for casts. Tested on x86_64 Fedora 17, and also by building a x86_64-mingw32 -hosted gdb. I don't have a set up for testing DJGPP/go32. gdb/ 2013-04-12 Pedro Alves * ser-base.c (ser_base_write): Change prototype -- take 'void *' buffer and size_t size. Adjust. * ser-base.h (ser_base_write): Adjust. * ser-go32.c (cnts): Change type to size_t. (dos_write): Change prototype -- take 'void *' buffer and size_t size. Adjust. (dos_info): Print elements of 'cnts' as unsigned long. * serial.c (serial_write): Likewise. * serial.h (serial_write): Adjust. (struct serial_ops) : Change prototype -- take 'void *' buffer and size_t size. Adjust. --- gdb/ser-base.c | 9 +++++---- gdb/ser-base.h | 2 +- gdb/ser-go32.c | 21 +++++++++++---------- gdb/serial.c | 16 +++++++++------- gdb/serial.h | 6 +++--- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/gdb/ser-base.c b/gdb/ser-base.c index c602650..52c5726 100644 --- a/gdb/ser-base.c +++ b/gdb/ser-base.c @@ -440,17 +440,18 @@ ser_base_readchar (struct serial *scb, int timeout) } int -ser_base_write (struct serial *scb, const char *str, int len) +ser_base_write (struct serial *scb, const void *buf, size_t count) { + const char *str = buf; int cc; - while (len > 0) + while (count > 0) { - cc = scb->ops->write_prim (scb, str, len); + cc = scb->ops->write_prim (scb, str, count); if (cc < 0) return 1; - len -= cc; + count -= cc; str += cc; } return 0; diff --git a/gdb/ser-base.h b/gdb/ser-base.h index 175bf20..e5fe9e1 100644 --- a/gdb/ser-base.h +++ b/gdb/ser-base.h @@ -45,7 +45,7 @@ extern int ser_base_setbaudrate (struct serial *scb, int rate); extern int ser_base_setstopbits (struct serial *scb, int rate); extern int ser_base_drain_output (struct serial *scb); -extern int ser_base_write (struct serial *scb, const char *str, int len); +extern int ser_base_write (struct serial *scb, const void *buf, size_t count); extern void ser_base_async (struct serial *scb, int async_p); extern int ser_base_readchar (struct serial *scb, int timeout); diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c index 7d76720..9b321df 100644 --- a/gdb/ser-go32.c +++ b/gdb/ser-go32.c @@ -148,7 +148,7 @@ typedef unsigned long u_long; #define NCNT 20 static int intrcnt; -static int cnts[NCNT]; +static size_t cnts[NCNT]; static char *cntnames[NCNT] = { /* h/w interrupt counts. */ @@ -230,7 +230,7 @@ static int dos_open (struct serial *scb, const char *name); static void dos_raw (struct serial *scb); static int dos_readchar (struct serial *scb, int timeout); static int dos_setbaudrate (struct serial *scb, int rate); -static int dos_write (struct serial *scb, const char *str, int len); +static int dos_write (struct serial *scb, const void *buf, size_t count); static void dos_close (struct serial *scb); static serial_ttystate dos_get_tty_state (struct serial *scb); static int dos_set_tty_state (struct serial *scb, serial_ttystate state); @@ -787,26 +787,27 @@ dos_setstopbits (struct serial *scb, int num) } static int -dos_write (struct serial *scb, const char *str, int len) +dos_write (struct serial *scb, const void *buf, size_t count) { volatile struct dos_ttystate *port = &ports[scb->fd]; - int fifosize = port->fifo ? 16 : 1; + size_t fifosize = port->fifo ? 16 : 1; long then; - int cnt; + size_t cnt; + const char *str = buf; - while (len > 0) + while (count > 0) { /* Send the data, fifosize bytes at a time. */ - cnt = fifosize > len ? len : fifosize; + cnt = fifosize > count ? count : fifosize; port->txbusy = 1; /* Francisco Pastor says OUTSB messes up the communications with UARTs with FIFOs. */ #ifdef UART_FIFO_WORKS outportsb (port->base + com_data, str, cnt); str += cnt; - len -= cnt; + count -= cnt; #else - for ( ; cnt > 0; cnt--, len--) + for ( ; cnt > 0; cnt--, count--) outportb (port->base + com_data, *str++); #endif #ifdef DOS_STATS @@ -904,7 +905,7 @@ dos_info (char *arg, int from_tty) printf_filtered ("\nTotal interrupts: %d\n", intrcnt); for (i = 0; i < NCNT; i++) if (cnts[i]) - printf_filtered ("%s:\t%d\n", cntnames[i], cnts[i]); + printf_filtered ("%s:\t%lu\n", cntnames[i], (unsigned long) cnts[i]); #endif } diff --git a/gdb/serial.c b/gdb/serial.c index 3202b0f..ee3f1ea 100644 --- a/gdb/serial.c +++ b/gdb/serial.c @@ -398,14 +398,15 @@ serial_readchar (struct serial *scb, int timeout) } int -serial_write (struct serial *scb, const char *str, int len) +serial_write (struct serial *scb, const void *buf, size_t count) { if (serial_logfp != NULL) { - int count; + const char *str = buf; + size_t c; - for (count = 0; count < len; count++) - serial_logchar (serial_logfp, 'w', str[count] & 0xff, 0); + for (c = 0; c < count; c++) + serial_logchar (serial_logfp, 'w', str[c] & 0xff, 0); /* Make sure that the log file is as up-to-date as possible, in case we are getting ready to dump core or something. */ @@ -413,9 +414,10 @@ serial_write (struct serial *scb, const char *str, int len) } if (serial_debug_p (scb)) { - int count; + const char *str = buf; + size_t c; - for (count = 0; count < len; count++) + for (c = 0; c < count; c++) { fprintf_unfiltered (gdb_stdlog, "["); serial_logchar (gdb_stdlog, 'w', str[count] & 0xff, 0); @@ -424,7 +426,7 @@ serial_write (struct serial *scb, const char *str, int len) gdb_flush (gdb_stdlog); } - return (scb->ops->write (scb, str, len)); + return (scb->ops->write (scb, buf, count)); } void diff --git a/gdb/serial.h b/gdb/serial.h index a91c8b8..7a97e28 100644 --- a/gdb/serial.h +++ b/gdb/serial.h @@ -104,10 +104,10 @@ enum serial_rc { extern int serial_readchar (struct serial *scb, int timeout); -/* Write LEN chars from STRING to the port SCB. Returns 0 for +/* Write COUNT bytes from BUF to the port SCB. Returns 0 for success, non-zero for failure. */ -extern int serial_write (struct serial *scb, const char *str, int len); +extern int serial_write (struct serial *scb, const void *buf, size_t count); /* Write a printf style string onto the serial port. */ @@ -256,7 +256,7 @@ struct serial_ops void (*close) (struct serial *); int (*fdopen) (struct serial *, int fd); int (*readchar) (struct serial *, int timeout); - int (*write) (struct serial *, const char *str, int len); + int (*write) (struct serial *, const void *buf, size_t count); /* Discard pending output */ int (*flush_output) (struct serial *); /* Discard pending input */