Date: Mon, 2 Jul 2001 11:34:25 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: current@freebsd.org Subject: funny strlen defines in sys/alpha/alpha/alpha-gdbstub.c Message-ID: <20010702113423.B7023@hades.hell.gr>
next in thread | raw e-mail | index | archive | help
--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");
/* $<packet info>#<checksum>. */
@@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010702113423.B7023>
