From owner-freebsd-current Mon Jul 2 4:16:56 2001 Delivered-To: freebsd-current@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id CCB9D37B401 for ; Mon, 2 Jul 2001 04:16:48 -0700 (PDT) (envelope-from keramida@ceid.upatras.gr) Received: from hades.hell.gr (patr530-b101.otenet.gr [195.167.121.229]) by mailsrv.otenet.gr (8.11.1/8.11.1) with ESMTP id f62BGjK03249 for ; Mon, 2 Jul 2001 14:16:45 +0300 (EEST) Received: (from charon@localhost) by hades.hell.gr (8.11.4/8.11.3) id f628YRq07312; Mon, 2 Jul 2001 11:34:27 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Mon, 2 Jul 2001 11:34:25 +0300 From: Giorgos Keramidas To: current@freebsd.org Subject: funny strlen defines in sys/alpha/alpha/alpha-gdbstub.c Message-ID: <20010702113423.B7023@hades.hell.gr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline User-Agent: Mutt/1.2.5i X-PGP-Fingerprint: 3A 75 52 EB F1 58 56 0D - C5 B8 21 B6 1B 5E 4A C2 X-URL: http://students.ceid.upatras.gr/~keramida/index.html Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Close to the top of sys/alpha/alpha/alpha-gdbstub.c i found out this, as i was randomly browsing the kernel sources today: 1 /* $FreeBSD: src/sys/alpha/alpha/alpha-gdbstub.c,v 1.11 2001/03/28 01:54:05 jhb Exp $ */ ... 130 #define strlen gdb_strlen 131 #define strcpy gdb_strcpy ... 133 static int 134 strlen (const char *s) 135 { ... 143 static char * 144 strcpy (char *dst, const char *src) 145 { ... wondering what happens when this file is fed to the preprocessor, it seems that all occurences of strlen() and strcpy() are replaced with gdb_strlen() and gdb_strcpy() in this file. Is it really necessary to do this funny thing with the #defines? I mean, why not replace the calls with gdb_XXX() ourselves and be done with it? After all it only occurs in a handful of places, and the functions are static. % fgrep strlen alpha-gdbstub.c | wc -l 8 % fgrep strcpy alpha-gdbstub.c | wc -l 11 As I dont have an Alpha around, I can't actually test the attached patch, but I'm looking forward to your comments. -giorgos --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="alpha-gdbstub.diff" Index: alpha/alpha/alpha-gdbstub.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/alpha/alpha-gdbstub.c,v retrieving revision 1.11 diff -c -u -r1.11 alpha-gdbstub.c --- alpha/alpha/alpha-gdbstub.c 2001/03/28 01:54:05 1.11 +++ alpha/alpha/alpha-gdbstub.c 2001/07/02 08:25:34 @@ -119,19 +119,8 @@ /* at least NUMREGBYTES*2 are needed for register packets */ #define BUFMAX 1500 -/* Create private copies of common functions used by the stub. This prevents - nasty interactions between app code and the stub (for instance if user steps - into strlen, etc..) */ -/* XXX this is fairly bogus. strlen() and strcpy() should be reentrant, - and are reentrant under FreeBSD. In any case, our versions should not - be named the same as the standard versions, so that the address `strlen' - is unambiguous... */ - -#define strlen gdb_strlen -#define strcpy gdb_strcpy - static int -strlen (const char *s) +gdb_strlen (const char *s) { const char *s1 = s; @@ -141,7 +130,7 @@ } static char * -strcpy (char *dst, const char *src) +gdb_strcpy (char *dst, const char *src) { char *retval = dst; @@ -230,7 +219,7 @@ /* remove sequence chars from buffer */ - count = strlen (buffer); + count = gdb_strlen (buffer); for (i=3; i <= count; i++) buffer[i-3] = buffer[i]; } @@ -239,7 +228,7 @@ } while (checksum != xmitcsum); - if (strlen(buffer) >= BUFMAX) + if (gdb_strlen(buffer) >= BUFMAX) panic("kgdb: buffer overflow"); } @@ -252,7 +241,7 @@ int count; unsigned char ch; - if (strlen(buffer) >= BUFMAX) + if (gdb_strlen(buffer) >= BUFMAX) panic("kgdb: buffer overflow"); /* $#. */ @@ -655,7 +644,7 @@ case 'G': /* set the value of the CPU registers - return OK */ hex2mem (&remcomInBuffer[1], (vm_offset_t)®isters, NUMREGBYTES); - strcpy (remcomOutBuffer, "OK"); + gdb_strcpy (remcomOutBuffer, "OK"); break; case 'P': /* Set the value of one register */ @@ -669,10 +658,10 @@ && regno < NUM_REGS) { hex2mem (ptr, (vm_offset_t)®isters + regno * 8, 8); - strcpy(remcomOutBuffer,"OK"); + gdb_strcpy(remcomOutBuffer,"OK"); } else - strcpy (remcomOutBuffer, "P01"); + gdb_strcpy (remcomOutBuffer, "P01"); break; } case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ @@ -685,11 +674,11 @@ && hexToInt (&ptr, &length)) { if (mem2hex((vm_offset_t) addr, remcomOutBuffer, length) == NULL) - strcpy (remcomOutBuffer, "E03"); + gdb_strcpy (remcomOutBuffer, "E03"); break; } else - strcpy (remcomOutBuffer, "E01"); + gdb_strcpy (remcomOutBuffer, "E01"); break; case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ @@ -704,12 +693,12 @@ && *(ptr++) == ':') { if (hex2mem(ptr, (vm_offset_t) addr, length) == NULL) - strcpy (remcomOutBuffer, "E03"); + gdb_strcpy (remcomOutBuffer, "E03"); else - strcpy (remcomOutBuffer, "OK"); + gdb_strcpy (remcomOutBuffer, "OK"); } else - strcpy (remcomOutBuffer, "E02"); + gdb_strcpy (remcomOutBuffer, "E02"); break; /* cAA..AA Continue at address AA..AA(optional) */ --17pEHd4RhPHOinZp-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message