From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21248 invoked by alias); 25 Jul 2010 12:25:03 -0000 Received: (qmail 21196 invoked by uid 22791); 25 Jul 2010 12:25:01 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM X-Spam-Check-By: sourceware.org Received: from mail-fx0-f41.google.com (HELO mail-fx0-f41.google.com) (209.85.161.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 25 Jul 2010 12:24:52 +0000 Received: by fxm20 with SMTP id 20so6333606fxm.0 for ; Sun, 25 Jul 2010 05:24:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.189.10 with SMTP id r10mr975573mup.70.1280060690123; Sun, 25 Jul 2010 05:24:50 -0700 (PDT) Received: by 10.103.1.17 with HTTP; Sun, 25 Jul 2010 05:24:50 -0700 (PDT) In-Reply-To: References: <1278528582.10151.23.camel@localhost.localdomain> Date: Sun, 25 Jul 2010 12:25:00 -0000 Message-ID: Subject: Re: impossible to resolve symbols in same binary loaded twice with dlmopen From: Mathieu Lacage To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-07/txt/msg00386.txt.bz2 On Tue, Jul 20, 2010 at 9:38 PM, Tom Tromey wrote: > Mathieu> I do not believe that gdb can do this and I could file a bug but= it's > Mathieu> probably going to be hard to fix (beyond my own abilities). > > Yeah, that is ok -- please file it anyway. http://sourceware.org/bugzilla/show_bug.cgi?id=3D11839 > Actually I am curious about failures even with your loader. > > Can you set breakpoints on all instances of a function? =C2=A0Does printi= ng a > global variable defined in a dlmopen()d .so always work properly? =C2=A0I > would guess that you could construct a case where it does not, something > like: ahhh. Good point. It works nicely for _static_ variables, but not for global variables (which I never use). > File x.c defines a function, file y.c defines a global. =C2=A0Compile int= o a > shared library. =C2=A0Have the main program dlmopen the library twice and > call the function in each one. =C2=A0Then, step into each instance of the > function and print the address of the global. (gdb) b main Breakpoint 1 at 0x400602: file test.c, line 14. (gdb) r Starting program: /home/mathieu/code/elf-loader/t Breakpoint 1, main (argc=3D1, argv=3D0x7fffffffe128) at test.c:14 14 void *a =3D dlmopen (LM_ID_NEWLM, "./libtest.so", RTLD_LAZY); (gdb) n 15 void *b =3D dlmopen (LM_ID_NEWLM, "./libtest.so", RTLD_LAZY); (gdb) 17 call (a, "foo"); (gdb) info sharedlibrary >From To Syms Read Shared Object Library 0x00007ffff7de8a50 0x00007ffff7df824f Yes ./ldso 0x00007ffff7be6ad0 0x00007ffff7be6cef Yes ./libvdl.so 0x00000037fa81e860 0x00000037fa9262fc Yes (*) /lib64/libc.so.6 0x00007ffff79e52e4 0x00007ffff79e52fa Yes ././libtest.so 0x00007ffff77e42e4 0x00007ffff77e42fa Yes ././libtest.so (*): Shared library is missing debugging information. (gdb) b foo Breakpoint 2 at 0x7ffff79e52e8: file libtest.c, line 5. (2 locations) (gdb) c Continuing. Breakpoint 2, foo () at libtest.c:5 5 return 0; (gdb) p &g_global $4 =3D (int *) 0x7ffff7be543c (gdb) p &g_static $5 =3D (int *) 0x7ffff7be5438 (gdb) c Continuing. Breakpoint 2, foo () at libtest.c:5 5 return 0; (gdb) p &g_global $6 =3D (int *) 0x7ffff7be543c (gdb) p &g_static $7 =3D (int *) 0x7ffff79e4438 (gdb) > The reason I think this will fail is that I am not sure that gdb will do > the symbol search properly. =C2=A0I suspect it will always find the first > instance of the global, not the one in the current objfile. > > Maybe I'm wrong about this, though :-) Indeed. Shall I file a bug ? Maybe you can also give me a hint on where I can fix it ? It might be a nice change from writing the thesis. > Anyway, AFAICT, your patch won't break anything, and it is a step in the > right direction. =C2=A0So, please check it in. I don't have commit rights, and, really, it's better for you if I don't :) Mathieu --=20 Mathieu Lacage