From owner-freebsd-hackers@FreeBSD.ORG Wed May 16 10:35:26 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EBEAF16A402 for ; Wed, 16 May 2007 10:35:26 +0000 (UTC) (envelope-from gahr@gahr.ch) Received: from cpanel03.rubas-s03.net (cpanel03.rubas-s03.net [195.182.222.73]) by mx1.freebsd.org (Postfix) with ESMTP id 82FEC13C458 for ; Wed, 16 May 2007 10:35:26 +0000 (UTC) (envelope-from gahr@gahr.ch) Received: from gahrtop.bfh.ch ([147.87.108.12] helo=gahrtop.localhost) by cpanel03.rubas-s03.net with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1HoGKx-0001v2-Cx for freebsd-hackers@freebsd.org; Wed, 16 May 2007 12:02:27 +0200 Message-ID: <464AD6A9.8060805@gahr.ch> Date: Wed, 16 May 2007 12:02:17 +0200 From: Pietro Cerutti User-Agent: Thunderbird 2.0.0.0 (X11/20070509) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org X-Enigmail-Version: 0.95.0 OpenPGP: id=9571F78E; url=http://www.gahr.ch/pgp Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig2553F160283B5B63818C8D92" X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel03.rubas-s03.net X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - gahr.ch X-Source: X-Source-Args: X-Source-Dir: Subject: GDB and memory violations X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 May 2007 10:35:27 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2553F160283B5B63818C8D92 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi list, I haven't investigated yet, but it seems that FreeBSD's version of GDB stores string literals in read/write memory, and not on read-only memory, as I prove below. Is this behavior known/wanted/erroneous ? Try to run this code from the command line and from inside GDB. strtok(3) segfaults when run on the command line, because it tries to modify the string literal input1, while the program exits normally from G= DB. #include #include int main() { char *input1 =3D "Hello, World!"; char *tok; tok =3D strtok(input1, " "); if(tok) printf("%s\n", tok); tok =3D strtok(NULL, " "); if(tok) printf("%s\n", tok); return(0); } $ gcc -ggdb -Wall -o strtok strtok.c $ ./strtok Bus error (core dumped) Exit 138 $ gdb ./strtok GNU gdb 6.1.1 [FreeBSD] [snip]GDB copyright and bla bla[/snip] (gdb) break main Breakpoint 1 at 0x8048570: file strtok.c, line 6. (gdb) run Starting program: /home/piter/strtok Breakpoint 1, main () at strtok.c:6 6 char *input1 =3D "Hello, World!"; (gdb) next 10 tok =3D strtok(input1, " "); (gdb) 11 if(tok) printf("%s\n", tok); (gdb) Hello, 13 tok =3D strtok(NULL, " "); (gdb) 14 if(tok) printf("%s\n", tok); (gdb) World! 16 return(0); (gdb) 18 } (gdb) 0x08048485 in _start () (gdb) Single stepping until exit from function _start, which has no line number information. Program exited normally. (gdb) Tnx, --=20 Pietro Cerutti PGP Public Key ID: http://gahr.ch/pgp --------------enig2553F160283B5B63818C8D92 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGStavwMJqmJVx944RCtXFAKCO1qd57c7BODIqbdXcIOOubBYwqACeNHWD 3RoWfiT6MII9UvqjoYUlOo4= =5Bw8 -----END PGP SIGNATURE----- --------------enig2553F160283B5B63818C8D92--