Date: Wed, 16 May 2007 12:02:17 +0200 From: Pietro Cerutti <gahr@gahr.ch> To: freebsd-hackers@freebsd.org Subject: GDB and memory violations Message-ID: <464AD6A9.8060805@gahr.ch>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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 GDB.
#include <string.h>
#include <stdio.h>
int main()
{
char *input1 = "Hello, World!";
char *tok;
tok = strtok(input1, " ");
if(tok) printf("%s\n", tok);
tok = 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 = "Hello, World!";
(gdb) next
10 tok = strtok(input1, " ");
(gdb)
11 if(tok) printf("%s\n", tok);
(gdb)
Hello,
13 tok = 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,
--
Pietro Cerutti
PGP Public Key ID:
http://gahr.ch/pgp
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)
iD8DBQFGStavwMJqmJVx944RCtXFAKCO1qd57c7BODIqbdXcIOOubBYwqACeNHWD
3RoWfiT6MII9UvqjoYUlOo4=
=5Bw8
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?464AD6A9.8060805>
