From owner-freebsd-bugs Wed Aug 2 23:10: 9 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 0120537B6FE for ; Wed, 2 Aug 2000 23:10:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id XAA08715; Wed, 2 Aug 2000 23:10:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from entoo.connect.com.au (entoo.connect.com.au [192.189.54.8]) by hub.freebsd.org (Postfix) with ESMTP id F148937B6FA for ; Wed, 2 Aug 2000 23:01:50 -0700 (PDT) (envelope-from andy@silverbrook.com.au) Received: from bebop.lan.silverbrook.com.au (CPE-144-132-228-195.nsw.bigpond.net.au [144.132.228.195]) by entoo.connect.com.au (Postfix) with ESMTP id A85A0DD1FE for ; Thu, 3 Aug 2000 16:01:47 +1000 (EST) Received: (from andy@localhost) by bebop.lan.silverbrook.com.au (8.9.3/8.9.3) id QAA20818; Thu, 3 Aug 2000 16:01:42 +1000 (EST) (envelope-from andy) Message-Id: <200008030601.QAA20818@bebop.lan.silverbrook.com.au> Date: Thu, 3 Aug 2000 16:01:42 +1000 (EST) From: Andy Newman Reply-To: andy@silverbrook.com.au To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/20373: Setting breakpoints in shared objects broken Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 20373 >Category: bin >Synopsis: Setting breakpoints in shared objects broken >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Aug 02 23:10:00 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Andy Newman >Release: FreeBSD 4.1-STABLE i386 >Organization: Silverbrook Research >Environment: Freshly CVSup'd 4.1-STABLE as of Aug. 3, 13:00 (GMT +10), $ uname -a FreeBSD bebop.lan.silverbrook.com.au 4.1-STABLE FreeBSD 4.1-STABLE #0: Thu Aug 3 13:29:45 EST 2000 toor@bebop.lan.silverbrook.com.au:/usr/obj/usr/src/sys/bebop i386 (i.e., cvsup & make buildworld approx. three hours prior to bug submission) Problem also occurs on a slighly older 4.0-STABLE (post-release CVSup) but *does not* occur on a 3.5-STABLE system. >Description: Setting a breakpoint in an run-time loaded object from a C or C++ program does not work as expected. The breakpoint appears to be set at the end of the function or at least the trap doesn't occur until function exit rather than at the breakpoint position. See following typscript of a debug session using the attached sample program which loads a shared object and calls a function. The sample is C++ (as that is where I first ran into the problem) but compiling it as C (with a couple of little mods) shows the same problem. This behaviour seems to have occurred *after* 4.0-RELEASE. Script started on Thu Aug 3 15:34:59 2000 : bebop; make clean all rm -f tst so.so c++ -g -o tst tst.cpp c++ -g -shared -o so.so so.cpp : bebop; gdb tst GNU gdb 4.18 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-unknown-freebsd"... (gdb) set environment LD_LIBRARY_PATH . (gdb) b dlopen Breakpoint 1 at 0x8048814 (gdb) r so.so func Starting program: /home/andy/tmp/bugs/c++-gdb-breakpoint/tst so.so func Breakpoint 1 at 0x280f7c4f Breakpoint 1 at 0x280520dd Breakpoint 1, 0x280520dd in dlopen () from /usr/libexec/ld-elf.so.1 (gdb) fin Run till exit from #0 0x280520dd in dlopen () from /usr/libexec/ld-elf.so.1 0x8048993 in main (argc=3, argv=0xbfbff308) at tst.cpp:14 14 if ((h = dlopen(argv[1], RTLD_NOW)) == NULL) (gdb) shared Symbols already loaded for /usr/lib/libstdc++.so.3 Symbols already loaded for /usr/lib/libm.so.2 Symbols already loaded for /usr/lib/libc.so.4 Symbols already loaded for /home/andy/tmp/bugs/c++-gdb-breakpoint/./so.so Symbols already loaded for /usr/libexec/ld-elf.so.1 (gdb) b func Breakpoint 2 at 0x281554be: file so.cpp, line 12. (gdb) c Continuing. Breakpoint 2, 0x281554be in func () at so.cpp:12 12 } <==== last line of func() (gdb) where #0 0x281554be in func () at so.cpp:12 #1 0x8048a0d in main (argc=3, argv=0xbfbff308) at tst.cpp:18 #2 0x80488f1 in _start () (gdb) step ... func() executes main (argc=3, argv=0xbfbff308) at tst.cpp:19 19 if (dlclose(h) == -1) (gdb) cont (deletia) Script done on Thu Aug 3 15:36:13 2000 >How-To-Repeat: See attached shar file. It has a simple test program that loads a shared object and calls a function in it. If you debug this, set a break point on dlopen and "fin" from it so the loaded object's symbols are loaded, then set a break point on "func" and continue. The break point doesn't occur until the function exits. # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # Makefile # so.cpp # tst.cpp # echo x - Makefile sed 's/^X//' >Makefile << 'END-of-Makefile' Xall: tst so.so X Xtst: tst.cpp X c++ -g -o $@ tst.cpp X Xso.so: so.cpp X c++ -g -shared -o $@ so.cpp X Xtest: X @LD_LIBRARY_PATH=`pwd` ./tst so.so func X Xclean: X rm -f tst so.so END-of-Makefile echo x - so.cpp sed 's/^X//' >so.cpp << 'END-of-so.cpp' X#include X Xextern "C" Xvoid Xfunc() X{ X for (int i = 0; i < 10; ++i) X printf("."); X printf("In function"); X for (int i = 0; i < 10; ++i) X printf("."); X printf("\n"); X} END-of-so.cpp echo x - tst.cpp sed 's/^X//' >tst.cpp << 'END-of-tst.cpp' X#include X#include X#include X Xint Xmain(int argc, char **argv) X{ X void *h; X void (*fn)(); X X if (argc != 3) X errx(1, "usage: %s so ident", argv[0]); X if ((h = dlopen(argv[1], RTLD_NOW)) == NULL) X errx(1, "can't dlopen %s: %s", argv[1], dlerror()); X if ((fn = (void (*)())dlsym(h, argv[2])) == NULL) X errx(2, "can't dlsym %s : %s", argv[2], dlerror()); X (*fn)(); X if (dlclose(h) == -1) X errx(3, "dlclose failed: %s", dlerror()); X return 0; X} END-of-tst.cpp exit >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message