A question on debugging libraries
Hi, I'm not sure if this is a bug or something I have misunderstood about the debugging libraries. I want to show an example of debugging a libc call, so just simply overflowed a buffer with strcpy. --- #include stdio.h #include string.h char *b = A long string; int main(void) { char a[1]; strcpy(a, b); } --- Which when I run on i386 under GDB with LD_LIBRARY_PATH=/usr/lib/debug I get --- gdb output on i386 --- $ gcc -g -o test test.c $ echo $LD_LIBRARY_PATH /usr/lib/debug $ gdb ./test GNU gdb 6.0 (etc) (gdb) r Starting program: /home/ianw/test Program received signal SIGSEGV, Segmentation fault. 0x74732067 in ?? () (gdb) back #0 0x74732067 in ?? () #1 0x676e6972 in ?? () #2 0xba00 in ?? () #3 0xba0c in ?? () #4 0x40016c20 in ?? () from /lib/ld-linux.so.2 #5 0x0001 in ?? () #6 0x080482a0 in ?? () --- I don't belive the strcpy has been inlined, for example it shows up in ltrace $ ltrace ./test __libc_start_main(0x08048364, 1, 0xba04, 0x08048390, 0x080483f0 unfinished ... strcpy(0xb9b7, A long string) = 0xb9b7 --- SIGSEGV (Segmentation fault) --- +++ killed by SIGSEGV +++ I would have expected that this would give me a good backtrace. Is this wrong? -i [EMAIL PROTECTED] http://www.gelato.unsw.edu.au pgp0.pgp Description: PGP signature
Re: A question on debugging libraries
On Tue, Feb 10, 2004 at 11:39:31AM +1100, Ian Wienand wrote: Hi, I'm not sure if this is a bug or something I have misunderstood about the debugging libraries. I want to show an example of debugging a libc call, so just simply overflowed a buffer with strcpy. There's your problem. You are trying to get a backtrace. A walk up the stack frame, yes? So you generated a crash by overwriting the stack; naturally we can not backtrace. #0 0x74732067 in ?? () #1 0x676e6972 in ?? () If the top frames are lost, then there is nothing you can expect from the below frames. Besides, you're in main; there is only one or at most two frames on the stack anyway. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
A question on debugging libraries
Hi, I'm not sure if this is a bug or something I have misunderstood about the debugging libraries. I want to show an example of debugging a libc call, so just simply overflowed a buffer with strcpy. --- #include stdio.h #include string.h char *b = A long string; int main(void) { char a[1]; strcpy(a, b); } --- Which when I run on i386 under GDB with LD_LIBRARY_PATH=/usr/lib/debug I get --- gdb output on i386 --- $ gcc -g -o test test.c $ echo $LD_LIBRARY_PATH /usr/lib/debug $ gdb ./test GNU gdb 6.0 (etc) (gdb) r Starting program: /home/ianw/test Program received signal SIGSEGV, Segmentation fault. 0x74732067 in ?? () (gdb) back #0 0x74732067 in ?? () #1 0x676e6972 in ?? () #2 0xba00 in ?? () #3 0xba0c in ?? () #4 0x40016c20 in ?? () from /lib/ld-linux.so.2 #5 0x0001 in ?? () #6 0x080482a0 in ?? () --- I don't belive the strcpy has been inlined, for example it shows up in ltrace $ ltrace ./test __libc_start_main(0x08048364, 1, 0xba04, 0x08048390, 0x080483f0 unfinished ... strcpy(0xb9b7, A long string) = 0xb9b7 --- SIGSEGV (Segmentation fault) --- +++ killed by SIGSEGV +++ I would have expected that this would give me a good backtrace. Is this wrong? -i [EMAIL PROTECTED] http://www.gelato.unsw.edu.au pgpVMksDxYvrr.pgp Description: PGP signature
Re: A question on debugging libraries
On Tue, Feb 10, 2004 at 11:39:31AM +1100, Ian Wienand wrote: Hi, I'm not sure if this is a bug or something I have misunderstood about the debugging libraries. I want to show an example of debugging a libc call, so just simply overflowed a buffer with strcpy. There's your problem. You are trying to get a backtrace. A walk up the stack frame, yes? So you generated a crash by overwriting the stack; naturally we can not backtrace. #0 0x74732067 in ?? () #1 0x676e6972 in ?? () If the top frames are lost, then there is nothing you can expect from the below frames. Besides, you're in main; there is only one or at most two frames on the stack anyway. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer
Re: A question on debugging libraries
On Mon, Feb 09, 2004 at 07:49:53PM -0500, Daniel Jacobowitz wrote: You are trying to get a backtrace. A walk up the stack frame, yes? So you generated a crash by overwriting the stack; naturally we can not backtrace. doh, you are of course right. Just for the archives, don't use a stack variable and try something like --- new program --- #include stdio.h #include string.h char *b = A long string; char *a; int main(void) { strcpy(a, b); } --- and you'll correctly be able to debug it Program received signal SIGSEGV, Segmentation fault. strcpy (dest=0x0, src=0x80484a4 A long string) at ../sysdeps/generic/strcpy.c:40 40 ../sysdeps/generic/strcpy.c: No such file or directory. in ../sysdeps/generic/strcpy.c (gdb) info args dest = 0x0 src = 0x80484a4 A long string (gdb) -i pgp8EdOt5jnAR.pgp Description: PGP signature